- New course: Default HCP values are odd for front nine, and even for
authorSakari Poussa <spoussa@gmail.com>
Tue, 13 Jul 2010 13:31:52 +0000 (16:31 +0300)
committerSakari Poussa <spoussa@gmail.com>
Tue, 13 Jul 2010 13:31:52 +0000 (16:31 +0300)
  back nine. Also +/- jumps two up or down. Also HCP editing jumps from
  front to back to correct line.

TODO
maemo/scorecard.conf
src/course-dialog.cpp
src/score-dialog.cpp

diff --git a/TODO b/TODO
index c50b0d0..6e36f11 100644 (file)
--- a/TODO
+++ b/TODO
@@ -1,4 +1,5 @@
 TOP Items
+- Bug: New club/score with more than one comma (e.g xxx, yyy, zzz) does not work
 
 TODO General:
 - New score dialog should be the same as main view (f.ex showing
index 3371696..6ae4c42 100644 (file)
@@ -3,6 +3,6 @@
     <location type="file"
               category="settings" auto="true">/home/user/.config/garage/ScoreCard.conf</location>
     <location type="dir"
-              category="documents">/home/user/.scorecard</location>
+              category="documents">/home/user/MyDocs/.scorecard</location>
   </locations>
 </backup-configuration>
index d8192ea..5e81bf0 100644 (file)
@@ -66,65 +66,65 @@ void CourseWindow::setup(Course *course)
 ////////////////////////////////////////////////////////////////////////////////
 CourseSelectDialog::CourseSelectDialog(QWidget *parent) : QDialog(parent)
 {
-  QWidget *centralWidget = new QWidget(this);
-  createLayout(centralWidget);
+    QWidget *centralWidget = new QWidget(this);
+    createLayout(centralWidget);
 
-  setWindowTitle(tr("ScoreCard: New Club and Course"));
+    setWindowTitle(tr("ScoreCard: New Club and Course"));
 }
 
 void CourseSelectDialog::createLayout(QWidget *parent)
 {
-  labelClub = new QLabel(tr("Club"));
-  labelCourse = new QLabel(tr("Course"));
-  lineEditClub = new QLineEdit;
-  lineEditCourse = new QLineEdit;
-  pushButtonNext = new QPushButton(tr("Next"));
+    labelClub = new QLabel(tr("Club"));
+    labelCourse = new QLabel(tr("Course"));
+    lineEditClub = new QLineEdit;
+    lineEditCourse = new QLineEdit;
+    pushButtonNext = new QPushButton(tr("Next"));
 
-  connect(pushButtonNext, SIGNAL(clicked()), this, SLOT(next()));
+    connect(pushButtonNext, SIGNAL(clicked()), this, SLOT(next()));
 
-  QDialogButtonBox * buttonBox = new QDialogButtonBox(Qt::Vertical);
-  buttonBox->addButton(pushButtonNext, QDialogButtonBox::ActionRole);
+    QDialogButtonBox * buttonBox = new QDialogButtonBox(Qt::Vertical);
+    buttonBox->addButton(pushButtonNext, QDialogButtonBox::ActionRole);
 
-  leftLayout = new QVBoxLayout;
-  leftLayout->addWidget(lineEditClub);
-  leftLayout->addWidget(lineEditCourse);
+    leftLayout = new QVBoxLayout;
+    leftLayout->addWidget(lineEditClub);
+    leftLayout->addWidget(lineEditCourse);
 
-  rightLayout = new QVBoxLayout;
-  rightLayout->addStretch();
-  rightLayout->addWidget(buttonBox);
+    rightLayout = new QVBoxLayout;
+    rightLayout->addStretch();
+    rightLayout->addWidget(buttonBox);
 
-  QHBoxLayout *mainLayout = new QHBoxLayout(parent);
-  mainLayout->addLayout(leftLayout);
-  mainLayout->addLayout(rightLayout);
+    QHBoxLayout *mainLayout = new QHBoxLayout(parent);
+    mainLayout->addLayout(leftLayout);
+    mainLayout->addLayout(rightLayout);
 
-  setLayout(mainLayout);
+    setLayout(mainLayout);
 }
 
 void CourseSelectDialog::results(QString &club, 
                                 QString &course)
 {  
-  club = lineEditClub->text();
-  course = lineEditCourse->text();
+    club = lineEditClub->text();
+    course = lineEditCourse->text();
 }
 
 bool CourseSelectDialog::validate(void)
 {
-  QString str1 = lineEditClub->text();
-  QString str2 = lineEditCourse->text();
+    QString str1 = lineEditClub->text();
+    QString str2 = lineEditCourse->text();
 
-  if (str1.isEmpty() || str2.isEmpty())
-    return false;
+    if (str1.isEmpty() || str2.isEmpty())
+        return false;
   
-  return true;
+    return true;
 }
 
 void CourseSelectDialog::next(void)
 {
-  if (validate())
-    done(1);
-  else {
-    qDebug() << "CourseDialog: invalid data, cancel or correct";
-  }
+    if (validate())
+        done(1);
+    else {
+        qDebug() << "CourseDialog: invalid data, cancel or correct";
+    }
 }
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -132,221 +132,242 @@ void CourseSelectDialog::next(void)
 ////////////////////////////////////////////////////////////////////////////////
 CourseDialog::CourseDialog(QWidget *parent) : QDialog(parent)
 {
-  resize(800, 400);
+    resize(800, 400);
 
-  QWidget *centralWidget = new QWidget(this);
+    QWidget *centralWidget = new QWidget(this);
 
-  createTable();
-  createButton();
+    createTable();
+    createButton();
 
-  createLayout(centralWidget);
+    createLayout(centralWidget);
 }
 
 void CourseDialog::createLayout(QWidget *parent)
 {
-  leftLayout = new QVBoxLayout;
-  leftLayout->addWidget(table);
-
-  QDialogButtonBox * buttonBoxUp = new QDialogButtonBox(Qt::Vertical);
-  buttonBoxUp->addButton(pushButtonUp, QDialogButtonBox::ActionRole);
-  buttonBoxUp->addButton(pushButtonDown, QDialogButtonBox::ActionRole);
-  buttonBoxUp->addButton(pushButtonNext, QDialogButtonBox::ActionRole);
-
-  QDialogButtonBox * buttonBoxDown = new QDialogButtonBox(Qt::Vertical);
-  buttonBoxDown->addButton(pushButtonFinish, QDialogButtonBox::ActionRole);
-
-  rightLayout = new QVBoxLayout;
-  rightLayout->addWidget(buttonBoxUp);
-  rightLayout->addStretch();
-  rightLayout->addWidget(buttonBoxDown);
-
-  QHBoxLayout *mainLayout = new QHBoxLayout(parent);
-  mainLayout->addLayout(leftLayout);
-  mainLayout->addLayout(rightLayout);
-  setLayout(mainLayout);
+    leftLayout = new QVBoxLayout;
+    leftLayout->addWidget(table);
+
+    QDialogButtonBox * buttonBoxUp = new QDialogButtonBox(Qt::Vertical);
+    buttonBoxUp->addButton(pushButtonUp, QDialogButtonBox::ActionRole);
+    buttonBoxUp->addButton(pushButtonDown, QDialogButtonBox::ActionRole);
+    buttonBoxUp->addButton(pushButtonNext, QDialogButtonBox::ActionRole);
+
+    QDialogButtonBox * buttonBoxDown = new QDialogButtonBox(Qt::Vertical);
+    buttonBoxDown->addButton(pushButtonFinish, QDialogButtonBox::ActionRole);
+
+    rightLayout = new QVBoxLayout;
+    rightLayout->addWidget(buttonBoxUp);
+    rightLayout->addStretch();
+    rightLayout->addWidget(buttonBoxDown);
+
+    QHBoxLayout *mainLayout = new QHBoxLayout(parent);
+    mainLayout->addLayout(leftLayout);
+    mainLayout->addLayout(rightLayout);
+    setLayout(mainLayout);
 }
 
 void CourseDialog::createButton(QWidget *parent)
 {
-  Q_UNUSED(parent);
-  pushButtonUp = new QPushButton(tr("+"));
-  connect(pushButtonUp, SIGNAL(clicked()), this, SLOT(up()));
+    Q_UNUSED(parent);
+    pushButtonUp = new QPushButton(tr("+"));
+    connect(pushButtonUp, SIGNAL(clicked()), this, SLOT(up()));
 
-  pushButtonDown = new QPushButton(tr("-"));
-  connect(pushButtonDown, SIGNAL(clicked()), this, SLOT(down()));
+    pushButtonDown = new QPushButton(tr("-"));
+    connect(pushButtonDown, SIGNAL(clicked()), this, SLOT(down()));
 
-  pushButtonNext = new QPushButton(tr("Next"));
-  connect(pushButtonNext, SIGNAL(clicked()), this, SLOT(next()));
+    pushButtonNext = new QPushButton(tr("Next"));
+    connect(pushButtonNext, SIGNAL(clicked()), this, SLOT(next()));
 
-  pushButtonFinish = new QPushButton(tr("Finish"));
-  connect(pushButtonFinish, SIGNAL(clicked()), this, SLOT(finish()));
+    pushButtonFinish = new QPushButton(tr("Finish"));
+    connect(pushButtonFinish, SIGNAL(clicked()), this, SLOT(finish()));
 }
 
 void CourseDialog::createTable(QWidget *parent)
 {
-  table = new QTableWidget(ROWS, COLS, parent);
-
-  QStringList headers;
-  headers << "" << "Par" << "HCP" << "Len" << "" << "Par" << "HCP" << "Len";
-  table->setVerticalHeaderLabels(headers);
-  table->horizontalHeader()->hide();
-  table->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
-  table->verticalHeader()->setResizeMode(QHeaderView::Stretch);
-  table->setStyleSheet(defaultStyleSheet);
+    table = new QTableWidget(ROWS, COLS, parent);
+
+    QStringList headers;
+    headers << "" << "Par" << "HCP" << "Len" << "" << "Par" << "HCP" << "Len";
+    table->setVerticalHeaderLabels(headers);
+    table->horizontalHeader()->hide();
+    table->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
+    table->verticalHeader()->setResizeMode(QHeaderView::Stretch);
+    table->setStyleSheet(defaultStyleSheet);
 }
 
 void CourseDialog::init(Course *course)
 {
-  QTableWidgetItem *par, *hcp;
-
-  for (int i=0; i<18; i++) {
-    if (course) {
-      par = new QTableWidgetItem(course->getPar(i));
-      hcp = new QTableWidgetItem(course->getHcp(i));
-    }
-    else {
-      par = new QTableWidgetItem("4");
-      hcp = new QTableWidgetItem("9");
-    }
-    QTableWidgetItem *len = new QTableWidgetItem("");
-
-    QTableWidgetItem *holeNum = new QTableWidgetItem(QString::number(i+1));
-    holeNum->setForeground(ScoreColor::holeBg());
-    holeNum->setFlags(Qt::NoItemFlags);
-
-    holeNum->setTextAlignment(Qt::AlignCenter);
-    par->setTextAlignment(Qt::AlignCenter);
-    hcp->setTextAlignment(Qt::AlignCenter);
-    len->setTextAlignment(Qt::AlignCenter);
-    // len is not in use - here just to confuse ;(
-    len->setFlags(Qt::NoItemFlags);
+    QTableWidgetItem *par, *hcp;
+
+    for (int i=0; i<18; i++) {
+        if (course) {
+            // TODO: del or allocate statically...
+            par = new QTableWidgetItem(course->getPar(i));
+            hcp = new QTableWidgetItem(course->getHcp(i));
+        }
+        else {
+            par = new QTableWidgetItem("4");
+            if (i < 9)
+                hcp = new QTableWidgetItem("9");
+            else
+                hcp = new QTableWidgetItem("10");
+        }
+        QTableWidgetItem *len = new QTableWidgetItem("");
+
+        QTableWidgetItem *holeNum = new QTableWidgetItem(QString::number(i+1));
+        holeNum->setForeground(ScoreColor::holeBg());
+        holeNum->setFlags(Qt::NoItemFlags);
+
+        holeNum->setTextAlignment(Qt::AlignCenter);
+        par->setTextAlignment(Qt::AlignCenter);
+        hcp->setTextAlignment(Qt::AlignCenter);
+        len->setTextAlignment(Qt::AlignCenter);
+        // len is not in use - here just to confuse ;(
+        len->setFlags(Qt::NoItemFlags);
     
-    if (i < 9) {
-      table->setItem(0, i, holeNum);
-      table->setItem(1, i, par);
-      table->setItem(2, i, hcp);
-      table->setItem(3, i, len);
+        if (i < 9) {
+            table->setItem(0, i, holeNum);
+            table->setItem(1, i, par);
+            table->setItem(2, i, hcp);
+            table->setItem(3, i, len);
+        }
+        else {
+            table->setItem(4, i-9, holeNum);
+            table->setItem(5, i-9, par);
+            table->setItem(6, i-9, hcp);
+            table->setItem(7, i-9, len);
+        }
     }
-    else {
-      table->setItem(4, i-9, holeNum);
-      table->setItem(5, i-9, par);
-      table->setItem(6, i-9, hcp);
-      table->setItem(7, i-9, len);
-    }
-  }
-  table->setCurrentCell(1, 0);
+    table->setCurrentCell(1, 0);
 }
 
 void CourseDialog::up(void)
 {
-  QTableWidgetItem *item = table->currentItem();
+    QVariant value;
+    QTableWidgetItem *item = table->currentItem();
+
+    if (!item)
+        return;
 
-  if (!item)
-    return;
+    int i = (item->text()).toInt();
+    if (item->row() == ROW_HCP || item->row() == ROW_HCP_2)
+        value.setValue(i+2);
+    else
+        value.setValue(i+1);
 
-  int i = (item->text()).toInt();
-  QVariant value(i+1);
-  item->setData(Qt::DisplayRole, value);
+    item->setData(Qt::DisplayRole, value);
 }
 
 void CourseDialog::down(void)
 {
-  QTableWidgetItem *item = table->currentItem();
+    QVariant value;
+    QTableWidgetItem *item = table->currentItem();
+
+    if (!item)
+        return;
 
-  if (!item)
-    return;
+    int i = (item->text()).toInt();
+    if (item->row() == ROW_HCP || item->row() == ROW_HCP_2)
+        value.setValue(i-2);
+    else
+        value.setValue(i-1);
 
-  int i = (item->text()).toInt();
-  QVariant value(i-1);
-  item->setData(Qt::DisplayRole, value);
+    item->setData(Qt::DisplayRole, value);
 }
 
 void CourseDialog::next(void)
 {
-  if (table) {
-    QTableWidgetItem *item = table->currentItem();
-    moveToNextCell(item);
-    //setDefaultScore(table);
-  }
+    if (table) {
+        QTableWidgetItem *item = table->currentItem();
+        moveToNextCell(item);
+        //setDefaultScore(table);
+    }
 }
 
 void CourseDialog::moveToNextCell(QTableWidgetItem *item)
 {
-  if (!item)
-    return;
-
-  QTableWidget *table = item->tableWidget();
-
-  if (!table)
-    return;
-
-  int row = table->currentRow();
-  int col = table->currentColumn();
-
-  if (col < (COLS-1)) {
-    col++;
-  }
-  else if (col == (COLS-1)) {
-    col = 0;
-    row = (row == ROW_PAR_2) ? ROW_PAR : ROW_PAR_2;
-  }
-  //qDebug() << "new cell: " << row << "/" << col;
-  table->setCurrentCell(row, col);
+    if (!item)
+        return;
+
+    QTableWidget *table = item->tableWidget();
+
+    if (!table)
+        return;
+
+    int row = table->currentRow();
+    int col = table->currentColumn();
+
+    if (col < (COLS-1)) {
+        col++;
+    }
+    else if (col == (COLS-1)) {
+        col = 0;
+        if (row == ROW_PAR)
+            row = ROW_PAR_2;
+        else if (row == ROW_PAR_2)
+            row = ROW_PAR;
+        else if (row == ROW_HCP_2)
+            row = ROW_HCP;
+        else if (row == ROW_HCP)
+            row = ROW_HCP_2;
+    }
+    //qDebug() << "new cell: " << row << "/" << col;
+    table->setCurrentCell(row, col);
 }
 
 void CourseDialog::results(QVector<QString> &par,
-                         QVector<QString> &hcp,
-                         QVector<QString> &len)
+                           QVector<QString> &hcp,
+                           QVector<QString> &len)
 {
-  for (int i = 0; i < 9; i++) {
-    QTableWidgetItem *frontPar = table->item(ROW_PAR, i);
-    QTableWidgetItem *backPar = table->item(ROW_PAR_2, i);
-    QTableWidgetItem *frontHcp = table->item(ROW_HCP, i);
-    QTableWidgetItem *backHcp = table->item(ROW_HCP_2, i);
-    QTableWidgetItem *frontLen = table->item(ROW_LEN, i);
-    QTableWidgetItem *backLen = table->item(ROW_LEN_2, i);
-
-    if (frontPar)
-      par[i] = frontPar->text();
-    if (backPar)
-      par[i+9] = backPar->text();
-    if (frontHcp)
-      hcp[i] = frontHcp->text();
-    if (backHcp)
-      hcp[i+9] = backHcp->text();
-    if (frontLen)
-      len[i] = frontLen->text();
-    if (backLen)
-      len[i+9] = backLen->text();
-  }
+    for (int i = 0; i < 9; i++) {
+        QTableWidgetItem *frontPar = table->item(ROW_PAR, i);
+        QTableWidgetItem *backPar = table->item(ROW_PAR_2, i);
+        QTableWidgetItem *frontHcp = table->item(ROW_HCP, i);
+        QTableWidgetItem *backHcp = table->item(ROW_HCP_2, i);
+        QTableWidgetItem *frontLen = table->item(ROW_LEN, i);
+        QTableWidgetItem *backLen = table->item(ROW_LEN_2, i);
+
+        if (frontPar)
+            par[i] = frontPar->text();
+        if (backPar)
+            par[i+9] = backPar->text();
+        if (frontHcp)
+            hcp[i] = frontHcp->text();
+        if (backHcp)
+            hcp[i+9] = backHcp->text();
+        if (frontLen)
+            len[i] = frontLen->text();
+        if (backLen)
+            len[i+9] = backLen->text();
+    }
 }
 
 // Only par is mandatory
 bool CourseDialog::validate(void)
 {
-  for (int i = 0; i < 9; i++) {
-    QTableWidgetItem *frontItem = table->item(ROW_PAR, i);
-    QTableWidgetItem *backItem = table->item(ROW_PAR_2, i);
+    for (int i = 0; i < 9; i++) {
+        QTableWidgetItem *frontItem = table->item(ROW_PAR, i);
+        QTableWidgetItem *backItem = table->item(ROW_PAR_2, i);
     
-    if (!frontItem || !backItem)
-      return false;
+        if (!frontItem || !backItem)
+            return false;
     
-    QString str1 = frontItem->text();
-    QString str2 = backItem->text();
+        QString str1 = frontItem->text();
+        QString str2 = backItem->text();
     
-    if (str1.isEmpty() || str2.isEmpty())
-      return false;
-  }
-  return true;
+        if (str1.isEmpty() || str2.isEmpty())
+            return false;
+    }
+    return true;
 }
 
 void CourseDialog::finish(void)
 {
-  if (validate())
-    done(1);
-  else {
-    qDebug() << "CourseDialog: invalid data, cancel or correct";
-  }
+    if (validate())
+        done(1);
+    else {
+        qDebug() << "CourseDialog: invalid data, cancel or correct";
+    }
 }
 
 
index 29b018c..20b839b 100644 (file)
@@ -61,7 +61,7 @@ ScoreWindow::~ScoreWindow()
 void ScoreWindow::setup(Score *score, Course *course)
 {
     TRACE;
-    QString title = QString("Score: %1, %2 - %3").arg(score->getClubName()).arg(score->getCourseName()).arg(score->getDate());
+    QString title = QString("%1, %2 - %3").arg(score->getClubName()).arg(score->getCourseName()).arg(score->getDate());
     setWindowTitle(title);
     model->set(score, course);
 }