Use QListWidget instead of comboboxes
[scorecard] / src / course-dialog.cpp
index 463718c..2ea1d05 100644 (file)
@@ -13,7 +13,7 @@ CourseSelectDialog::CourseSelectDialog(QWidget *parent) : QDialog(parent)
   QWidget *centralWidget = new QWidget(this);
   createLayout(centralWidget);
 
-  setWindowTitle(tr("ScoreCard: New Club and/or Course"));
+  setWindowTitle(tr("ScoreCard: New Club and Course"));
 }
 
 void CourseSelectDialog::createLayout(QWidget *parent)
@@ -48,9 +48,24 @@ void CourseSelectDialog::results(QString &club,
   course = lineEditCourse->text();
 }
 
+bool CourseSelectDialog::validate(void)
+{
+  QString str1 = lineEditClub->text();
+  QString str2 = lineEditCourse->text();
+
+  if (str1.isEmpty() || str2.isEmpty())
+    return false;
+  
+  return true;
+}
+
 void CourseSelectDialog::next(void)
 {
-  done(1);
+  if (validate())
+    done(1);
+  else {
+    qDebug() << "CourseDialog: invalid data, cancel or correct";
+  }
 }
 
 CourseDialog::CourseDialog(QWidget *parent) : QDialog(parent)
@@ -61,17 +76,16 @@ CourseDialog::CourseDialog(QWidget *parent) : QDialog(parent)
   createLabel();
 
   createLayout(this);
-
 }
 
 void CourseDialog::createLayout(QWidget *parent)
 {
-  leftLayout = new QVBoxLayout;
+  leftLayout = new QVBoxLayout(parent);
   leftLayout->addWidget(table);
 
-  rightLayout = new QVBoxLayout;
+  rightLayout = new QVBoxLayout(parent);
   rightLayout->addStretch();
-  rightLayout->addWidget(pushButtonFinnish);
+  rightLayout->addWidget(pushButtonFinish);
 
   QHBoxLayout *mainLayout = new QHBoxLayout(parent);
   mainLayout->addLayout(leftLayout);
@@ -87,16 +101,16 @@ void CourseDialog::createLabel(QWidget *parent)
   clubEdit = new QLineEdit;
   courseEdit = new QLineEdit;
 
-  pushButtonFinnish = new QPushButton(tr("Finnish"));
-  connect(pushButtonFinnish, SIGNAL(clicked()), this, SLOT(finnish()));
+  pushButtonFinish = new QPushButton(tr("Finish"));
+  connect(pushButtonFinish, SIGNAL(clicked()), this, SLOT(finish()));
 }
 
 void CourseDialog::createTable(QWidget *parent)
 {
-  table = new QTableWidget(rows, cols);
+  table = new QTableWidget(rows, cols, parent);
 
   QStringList headers;
-  headers << "Hole" << "Par" << "HCP" << "Len" << "Hole" << "Par" << "HCP" << "Len";
+  headers << "" << "Par" << "HCP" << "Len" << "" << "Par" << "HCP" << "Len";
   table->setVerticalHeaderLabels(headers);
   table->horizontalHeader()->hide();
 
@@ -133,44 +147,6 @@ void CourseDialog::createTable(QWidget *parent)
       table->setItem(7, i-9, len);
     }
   }
-
-  //connect(table, SIGNAL(itemChanged(QTableWidgetItem *)), this, SLOT(itemChanged(QTableWidgetItem *)));
-
-}
-
-void CourseDialog::itemChanged(QTableWidgetItem *item)
-{
-  qDebug() << "itemChanged";
-
-  int row = table->currentRow();
-  int col = table->currentColumn();
-
-  col++;
-  if (col == cols) {
-    col = 0;
-    row++;
-    if (row == separator_row)
-      row++;
-  }
-  table->setCurrentCell(row, col);
-}
-
-void CourseDialog::nextCell(QObject *obj)
-{
-#if 0
-  int row = table->currentRow();
-  int col = table->currentColumn();
-  QTableWidgetItem *item = table->item(row, col);
-
-  qDebug() << "next Cell " << obj;
-  qDebug() << "item " << item << "row=" << row << " col=" << col;
-
-  table->setItem(row, col, item);
-
-
-  table->currentIndex();
-  table->setCurrentCell(2,2);
-#endif
 }
 
 void CourseDialog::results(QVector<QString> &par,
@@ -219,7 +195,7 @@ bool CourseDialog::validate(void)
   return true;
 }
 
-void CourseDialog::finnish(void)
+void CourseDialog::finish(void)
 {
   if (validate())
     done(1);