From a57b610e16aa2bfd82a96e3ce3dc31e87e4cdf27 Mon Sep 17 00:00:00 2001 From: Sakari Poussa Date: Fri, 28 May 2010 03:22:16 +0300 Subject: [PATCH] Use Home Club setting in new score dialog --- src/data.cpp | 3 + src/data.h | 3 + src/main-window.cpp | 52 ++++++---- src/main-window.h | 1 + src/score-common.h | 2 +- src/score-dialog.cpp | 261 ++++++++++++++++++++++++++------------------------ src/score-dialog.h | 2 +- src/table-model.cpp | 7 +- 8 files changed, 182 insertions(+), 149 deletions(-) diff --git a/src/data.cpp b/src/data.cpp index 19e52f0..120f317 100644 --- a/src/data.cpp +++ b/src/data.cpp @@ -330,18 +330,21 @@ void Course::dump() { Club::Club(const QXmlAttributes &attrs, bool readOnly) : m_readOnly(readOnly) { + m_homeClub = false; name = attrs.value("name"); } Club::Club(const QDomElement node, bool readOnly) : m_readOnly(readOnly) { + m_homeClub = false; name = node.attribute("name", ""); } Club::Club(QString &name, bool readOnly) : m_readOnly(readOnly) { + m_homeClub = false; this->name = name; } diff --git a/src/data.h b/src/data.h index 01d01ef..c05c6c3 100644 --- a/src/data.h +++ b/src/data.h @@ -108,11 +108,14 @@ public: Course *getCourse(const QString &courseName); bool isEmpty(); bool isReadOnly(); + void setHomeClub(bool value) { m_homeClub = value; } + bool isHomeClub() { return m_homeClub; } QList getCourseList() { return courseList; } // HACK: fixme private: bool m_readOnly; + bool m_homeClub; QList courseList; QString name; }; diff --git a/src/main-window.cpp b/src/main-window.cpp index c3c3f01..93c5f08 100644 --- a/src/main-window.cpp +++ b/src/main-window.cpp @@ -141,37 +141,52 @@ void MainWindow::flushReadOnlyItems() } } +void MainWindow::markHomeClub() +{ + TRACE; + QListIterator i(clubList); + Club *c; + + while (i.hasNext()) { + c = i.next(); + if (c->getName() == conf.homeClub) + c->setHomeClub(true); + else + c->setHomeClub(false); + } +} MainWindow::MainWindow(QMainWindow *parent): QMainWindow(parent) { - resize(800, 480); + resize(800, 480); #ifdef Q_WS_MAEMO_5 - setAttribute(Qt::WA_Maemo5StackedWindow); + setAttribute(Qt::WA_Maemo5StackedWindow); #endif - loadSettings(); + loadSettings(); - centralWidget = new QWidget(this); + centralWidget = new QWidget(this); - setCentralWidget(centralWidget); + setCentralWidget(centralWidget); - loadScoreFile(scoreFile, scoreList); - if (conf.defaultCourses == "Yes") - loadClubFile(masterFile, clubList, true); - loadClubFile(clubFile, clubList); + loadScoreFile(scoreFile, scoreList); + if (conf.defaultCourses == "Yes") + loadClubFile(masterFile, clubList, true); + loadClubFile(clubFile, clubList); + markHomeClub(); - // Sort the scores based on dates - qSort(scoreList.begin(), scoreList.end(), dateMoreThan); - createActions(); - createMenus(); + // Sort the scores based on dates + qSort(scoreList.begin(), scoreList.end(), dateMoreThan); + createActions(); + createMenus(); - createListView(scoreList, clubList); + createListView(scoreList, clubList); - createLayoutList(centralWidget); + createLayoutList(centralWidget); - scoreWindow = new ScoreWindow(this); - courseWindow = new CourseWindow(this); + scoreWindow = new ScoreWindow(this); + courseWindow = new CourseWindow(this); } void MainWindow::loadSettings(void) @@ -660,8 +675,6 @@ void MainWindow::viewSettings() QString newValue = conf.defaultCourses.toString(); saveSettings(); - qDebug() << "Settings:" << oldValue << "->" << newValue; - // Reload club list, or drop r/o courses from list if (oldValue == "Yes" && newValue == "No") { flushReadOnlyItems(); @@ -673,6 +686,7 @@ void MainWindow::viewSettings() courseListModel->update(clubList); list->update(); } + markHomeClub(); } } diff --git a/src/main-window.h b/src/main-window.h index b4ff965..bd39659 100644 --- a/src/main-window.h +++ b/src/main-window.h @@ -68,6 +68,7 @@ private: Score * currentScore(); Score * findScore(QString & clubName, QString & courseName); void flushReadOnlyItems(); + void markHomeClub(); void showNote(QString msg); void getStat(QTextEdit *); diff --git a/src/score-common.h b/src/score-common.h index a2dad65..52dc8c6 100644 --- a/src/score-common.h +++ b/src/score-common.h @@ -42,7 +42,7 @@ class ScoreColor static QColor doubleBogey() { return Qt::red; } static QColor bad() { return Qt::red; } static QColor subTotal() { return Qt::white; } - static QColor total() { return Qt::magenta; } + static QColor total() { return Qt::white; } }; static QString statStyleSheet("QTableView {color : white;}"); diff --git a/src/score-dialog.cpp b/src/score-dialog.cpp index faa8d82..29b018c 100644 --- a/src/score-dialog.cpp +++ b/src/score-dialog.cpp @@ -72,121 +72,128 @@ void ScoreWindow::setup(Score *score, Course *course) //////////////////////////////////////////////////////////////////////////////// SelectDialog::SelectDialog(QWidget *parent) : QDialog(parent) { - resize(800, 350); + resize(800, 350); - QWidget *centralWidget = new QWidget(this); - createLayout(centralWidget); + QWidget *centralWidget = new QWidget(this); + createLayout(centralWidget); - setWindowTitle(tr("ScoreCard: Select Course and Date")); + setWindowTitle(tr("ScoreCard: Select Course and Date")); } void SelectDialog::createLayout(QWidget *parent) { - listClub = new QListWidget(parent); - pushButtonNext = new QPushButton(tr("Next")); + listWidgetClub = new QListWidget(parent); + 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(listClub); + leftLayout = new QVBoxLayout; + leftLayout->addWidget(listWidgetClub); #ifdef Q_WS_MAEMO_5 - dateButton = new QMaemo5ValueButton(); - dateButton->setValueLayout(QMaemo5ValueButton::ValueUnderText); - dateButton->setPickSelector(new QMaemo5DatePickSelector()); - dateButton->setText(QString::fromUtf8("Date")); - leftLayout->addWidget(dateButton); + dateButton = new QMaemo5ValueButton(); + dateButton->setValueLayout(QMaemo5ValueButton::ValueUnderText); + dateButton->setPickSelector(new QMaemo5DatePickSelector()); + dateButton->setText(QString::fromUtf8("Date")); + leftLayout->addWidget(dateButton); #else - QDate today(QDate::currentDate()); - lineEditDate = new QLineEdit; - lineEditDate->setText(today.toString("yyyy-MM-dd")); - date = new QDateEdit; - leftLayout->addWidget(date); - leftLayout->addWidget(lineEditDate); + QDate today(QDate::currentDate()); + lineEditDate = new QLineEdit; + lineEditDate->setText(today.toString("yyyy-MM-dd")); + date = new QDateEdit; + leftLayout->addWidget(date); + leftLayout->addWidget(lineEditDate); #endif - 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 SelectDialog::init(QList &list) { - clubList = list; - - QListIterator i(clubList); - int index = 0; + TRACE; + clubList = list; - while (i.hasNext()) { - Club *club = i.next(); + QListIterator i(clubList); + int index = 0; + bool markedFlag = false; - QList courseList = club->getCourseList(); + while (i.hasNext()) { + Club *club = i.next(); - QListIterator j(courseList); - while (j.hasNext()) { - Course *course = j.next(); + QList courseList = club->getCourseList(); - QListWidgetItem *newItem = new QListWidgetItem; + QListIterator j(courseList); + while (j.hasNext()) { + Course *course = j.next(); - QString entry = club->getName() + ", " + course->getName(); + QListWidgetItem *newItem = new QListWidgetItem; + + QString entry = club->getName() + ", " + course->getName(); - newItem->setText(entry); - listClub->insertItem(index, newItem); + newItem->setText(entry); + listWidgetClub->insertItem(index, newItem); - index++; + if (!markedFlag & club->isHomeClub()) { + listWidgetClub->setCurrentRow(index); + // Mark the 1st course of the home club the selection + markedFlag = true; + } + index++; + } } - } } void SelectDialog::results(QString &club, QString &course, QString &date) { - QListWidgetItem *current = listClub->currentItem(); + QListWidgetItem *current = listWidgetClub->currentItem(); - if (current) { - QString tmp = current->text(); + if (current) { + QString tmp = current->text(); - QStringList stringList = tmp.split(", "); - club = stringList[0]; - course = stringList[1]; + QStringList stringList = tmp.split(", "); + club = stringList[0]; + course = stringList[1]; #ifdef Q_WS_MAEMO_5 - QMaemo5DatePickSelector *sel = (QMaemo5DatePickSelector *)dateButton->pickSelector(); - QDate d = sel->currentDate(); - // TODO: change to QDate - date = d.toString(Qt::ISODate); + QMaemo5DatePickSelector *sel = (QMaemo5DatePickSelector *)dateButton->pickSelector(); + QDate d = sel->currentDate(); + // TODO: change to QDate + date = d.toString(Qt::ISODate); #else - date = lineEditDate->text(); + date = lineEditDate->text(); #endif - } + } } bool SelectDialog::validate(void) { - return true; + return true; } void SelectDialog::next(void) { - if (validate()) - done(1); - else { - qDebug() << "SelectDialog: invalid data, cancel or correct"; - } + if (validate()) + done(1); + else { + qDebug() << "SelectDialog: invalid data, cancel or correct"; + } } void SelectDialog::reject(void) { - done(0); + done(0); } //////////////////////////////////////////////////////////////////////////////// @@ -329,82 +336,82 @@ void ScoreDialog::init(Course *course, Score *score) // Set default score to par if not set void ScoreDialog::setDefaultScore(QTableWidget *table) { - int row = table->currentRow(); - int col = table->currentColumn(); + int row = table->currentRow(); + int col = table->currentColumn(); - if (row == ROW_SCORE) - row = ROW_PAR; - else if (row == ROW_SCORE_2) - row = ROW_PAR_2; - else { - qDebug() << "ERROR: unknown row in default score"; - return; - } - QTableWidgetItem *par = table->item(row, col); - QTableWidgetItem *score = table->item(row + 2, col); - - if (par && score && score->text() == "") { - QVariant value(par->text()); - score->setData(Qt::DisplayRole, value); - } + if (row == ROW_SCORE) + row = ROW_PAR; + else if (row == ROW_SCORE_2) + row = ROW_PAR_2; + else { + qDebug() << "ERROR: unknown row in default score"; + return; + } + QTableWidgetItem *par = table->item(row, col); + QTableWidgetItem *score = table->item(row + 2, col); + + if (par && score && score->text() == "") { + QVariant value(par->text()); + score->setData(Qt::DisplayRole, value); + } } void ScoreDialog::up(void) { - QTableWidgetItem *item = table->currentItem(); + QTableWidgetItem *item = table->currentItem(); - if (!item) { - qWarning() << "ERROR: no current item"; - return; - } + if (!item) { + qWarning() << "ERROR: no current item"; + return; + } - int i = (item->text()).toInt(); - QVariant value(i+1); - item->setData(Qt::DisplayRole, value); + int i = (item->text()).toInt(); + QVariant value(i+1); + item->setData(Qt::DisplayRole, value); } void ScoreDialog::down(void) { - QTableWidgetItem *item = table->currentItem(); + QTableWidgetItem *item = table->currentItem(); - if (!item) - return; + if (!item) + return; - int i = (item->text()).toInt(); - QVariant value(i-1); - item->setData(Qt::DisplayRole, value); + int i = (item->text()).toInt(); + QVariant value(i-1); + item->setData(Qt::DisplayRole, value); } void ScoreDialog::next(void) { - if (table) { - QTableWidgetItem *item = table->currentItem(); - moveToNextCell(item); - setDefaultScore(table); - } + if (table) { + QTableWidgetItem *item = table->currentItem(); + moveToNextCell(item); + setDefaultScore(table); + } } void ScoreDialog::moveToNextCell(QTableWidgetItem *item) { - if (!item) - return; + if (!item) + return; - QTableWidget *table = item->tableWidget(); + QTableWidget *table = item->tableWidget(); - if (!table) - return; + if (!table) + return; - int row = table->currentRow(); - int col = table->currentColumn(); + int row = table->currentRow(); + int col = table->currentColumn(); - if (col < (COLS-1)) { - col++; - } - else if (col == (COLS-1)) { - col = 0; - row = (row == ROW_SCORE_2) ? ROW_SCORE : ROW_SCORE_2; - } - table->setCurrentCell(row, col); + if (col < (COLS-1)) { + col++; + } + else if (col == (COLS-1)) { + col = 0; + row = (row == ROW_SCORE_2) ? ROW_SCORE : ROW_SCORE_2; + } + table->setCurrentCell(row, col); } void ScoreDialog::results(QVector &scores) @@ -424,20 +431,20 @@ void ScoreDialog::results(QVector &scores) bool ScoreDialog::validate(void) { - for (int i=0; i<9; i++) { - QTableWidgetItem *frontItem = table->item(ROW_SCORE, i); - QTableWidgetItem *backItem = table->item(ROW_SCORE_2, i); + for (int i=0; i<9; i++) { + QTableWidgetItem *frontItem = table->item(ROW_SCORE, i); + QTableWidgetItem *backItem = table->item(ROW_SCORE_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 ScoreDialog::finish(void) @@ -451,7 +458,7 @@ void ScoreDialog::finish(void) void ScoreDialog::reject(void) { - done(0); + done(0); } void ScoreDialog::showNote(QString msg) diff --git a/src/score-dialog.h b/src/score-dialog.h index 2e35bfb..80a3d67 100644 --- a/src/score-dialog.h +++ b/src/score-dialog.h @@ -63,7 +63,7 @@ private: void createLayout(QWidget *parent = 0); // Widgets - QListWidget *listClub; + QListWidget *listWidgetClub; #ifdef Q_WS_MAEMO_5 QMaemo5ValueButton *dateButton; #else diff --git a/src/table-model.cpp b/src/table-model.cpp index 43a0afd..562dd62 100644 --- a/src/table-model.cpp +++ b/src/table-model.cpp @@ -124,7 +124,12 @@ QVariant ScoreTableModel::data(const QModelIndex &index, int role) const // if (role == Qt::FontRole) { QFont font; - font.setPointSize(fontSize); + if (col == (COLS+1) && row == ROW_SCORE_2) { + font.setBold(true); + font.setPointSize(fontSize+4); + } + else + font.setPointSize(fontSize); if (row == ROW_HOLE || row == ROW_HOLE_2) { font.setBold(true); } -- 1.7.9.5