From: Sakari Poussa Date: Sun, 25 Oct 2009 16:20:51 +0000 (+0200) Subject: Added edit course functionality X-Git-Url: http://vcs.maemo.org/git/?a=commitdiff_plain;h=acb94b998de0b01debe02293730beb1717820b98;p=scorecard Added edit course functionality --- diff --git a/TODO b/TODO index 4bd1beb..a05f84e 100644 --- a/TODO +++ b/TODO @@ -1,29 +1,17 @@ TODO General: - -for 0.1 -- New score - first entry does not update - - Seems to be bug in the Qt/Maemo - -for 0.2 -- Date picker button (widget is missing) -- Course view - sort menu buttons -- Edit course -- Edit score +- Statistics view (BIG) - Delete score - Delete course - -for 0.3 -- Stat view - Settings +- New score - first entry does not update + - Seems to be bug in the Qt/Maemo +- Date picker button (widget is missing) TODO Hildon 2.2 - -- Date picker for the score dialog - Replace LineEdit w/ HildonEntry TODO Arch - move scorelist (and all data handling) to table-model - Know issues - Data on MMC does not work diff --git a/src/course-dialog.cpp b/src/course-dialog.cpp index 781c1cb..ef05e30 100644 --- a/src/course-dialog.cpp +++ b/src/course-dialog.cpp @@ -125,16 +125,23 @@ void CourseDialog::createTable(QWidget *parent) headers << "" << "Par" << "HCP" << "Len" << "" << "Par" << "HCP" << "Len"; table->setVerticalHeaderLabels(headers); table->horizontalHeader()->hide(); - - //CellDelegate *cellDelegate = new CellDelegate(this); - //table->setItemDelegate(cellDelegate); - table->horizontalHeader()->setResizeMode(QHeaderView::Stretch); table->verticalHeader()->setResizeMode(QHeaderView::Stretch); +} + +void CourseDialog::init(Course *course) +{ + QTableWidgetItem *par, *hcp; for (int i=0; i<18; i++) { - QTableWidgetItem *par = new QTableWidgetItem("4"); - QTableWidgetItem *hcp = new QTableWidgetItem("9"); + 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)); @@ -159,6 +166,7 @@ void CourseDialog::createTable(QWidget *parent) table->setItem(7, i-9, len); } } + } void CourseDialog::up(void) diff --git a/src/course-dialog.h b/src/course-dialog.h index c983088..3a13112 100644 --- a/src/course-dialog.h +++ b/src/course-dialog.h @@ -9,6 +9,8 @@ #include #include +#include "data.h" + QT_BEGIN_NAMESPACE class QTableWidget; class QTableWidgetItem; @@ -50,6 +52,7 @@ class CourseDialog: public QDialog CourseDialog(QWidget *w); void results(QVector &, QVector &, QVector &); bool validate(); + void init(Course *course = 0); private slots: void up(void); diff --git a/src/data.cpp b/src/data.cpp index edfff01..782f3da 100644 --- a/src/data.cpp +++ b/src/data.cpp @@ -73,10 +73,18 @@ QString Hole::getHcp() { return hcp; } +void Hole::setHcp(QString& s) { + hcp = s; +} + QString Hole::getPar() { return par; } +void Hole::setPar(QString& s) { + par = s; +} + void Hole::dump() { qDebug() << num << "(" << par << ") : " << shots << "/" << putts ; } @@ -132,7 +140,7 @@ QDomElement Score::toElement(QDomDocument doc) return node; } -int Score::update(QVector scores) +int Score::update(QVector &scores) { for (int i = 0; i < scores.size(); i++) { Hole *hole = holeList.at(i); @@ -232,6 +240,20 @@ QDomElement Course::toElement(QDomDocument doc) return node; } +int Course::update(QVector &par, + QVector &hcp, + QVector &len) +{ + for (int i = 0; i < par.size(); i++) { + Hole *hole = holeList.at(i); + if (hole->getPar() != par[i]) + hole->setPar(par[i]); + if (hole->getHcp() != hcp[i]) + hole->setHcp(hcp[i]); + } + return 0; +} + void Course::addHole(Hole *iHole) { holeList << iHole; } diff --git a/src/data.h b/src/data.h index 0dabb10..957c8e2 100644 --- a/src/data.h +++ b/src/data.h @@ -20,7 +20,9 @@ class Hole { QString getShots(); void setShots(QString& shots); QString getHcp(); + void setHcp(QString& shots); QString getPar(); + void setPar(QString& shots); void dump(); private: @@ -41,7 +43,7 @@ class Score { } QDomElement toElement(QDomDocument doc); - int update(QVector scores); + int update(QVector &scores); void addHole(Hole *iHole); QString getScore(int i) const; QString getTotal(int what) const; @@ -61,6 +63,7 @@ class Course { Course(const QDomElement node); Course(QString &name, QVector &, QVector &); QDomElement toElement(QDomDocument doc); + int update(QVector &, QVector &, QVector &); void addHole(Hole *iHole); QString getPar(int i); QString getHcp(int i); @@ -71,7 +74,6 @@ class Course { private: QList holeList; QString name; - }; class Club { diff --git a/src/main-window.cpp b/src/main-window.cpp index 34958fa..101b335 100644 --- a/src/main-window.cpp +++ b/src/main-window.cpp @@ -187,6 +187,9 @@ void MainWindow::createActions() editScoreAct = new QAction(tr("Edit Score"), this); connect(editScoreAct, SIGNAL(triggered()), this, SLOT(editScore())); + editCourseAct = new QAction(tr("Edit Course"), this); + connect(editCourseAct, SIGNAL(triggered()), this, SLOT(editCourse())); + #if 0 viewScoreAct = new QAction(tr("&View Scores"), this); connect(viewScoreAct, SIGNAL(triggered()), this, SLOT(viewScore())); @@ -210,6 +213,7 @@ void MainWindow::createMenus() menu->addAction(newScoreAct); menu->addAction(newCourseAct); menu->addAction(editScoreAct); + menu->addAction(editCourseAct); } void MainWindow::updateStatusBar() @@ -268,6 +272,7 @@ void MainWindow::newCourse() selectDialog->results(clubName, courseName); CourseDialog *courseDialog = new CourseDialog(this); + courseDialog->init(); QString title = "New Course: " + clubName + "," + courseName; courseDialog->setWindowTitle(title); @@ -308,6 +313,29 @@ void MainWindow::newCourse() } } +void MainWindow::editCourse() +{ + Course *course = scoreTableModel->getCourse(); + + CourseDialog *courseDialog = new CourseDialog(this); + courseDialog->init(course); + + QString title = "Edit Course: " + course->getName(); + courseDialog->setWindowTitle(title); + + int result = courseDialog->exec(); + if (result) { + QVector par(18); + QVector hcp(18); + QVector len(18); + + courseDialog->results(par, hcp, len); + + course->update(par, hcp, len); + saveClubFile(clubFile, clubList); + } +} + void MainWindow::newScore() { SelectDialog *selectDialog = new SelectDialog(this); @@ -336,11 +364,8 @@ void MainWindow::newScore() qDebug() << "Error: no such course: " << courseName; return; } - scoreDialog->init(course); - result = scoreDialog->exec(); - if (result) { QVector scores(18); diff --git a/src/main-window.h b/src/main-window.h index 7fdce84..3013222 100644 --- a/src/main-window.h +++ b/src/main-window.h @@ -19,8 +19,8 @@ public: MainWindow(QMainWindow *parent = 0); void createLayout(QWidget *parent = 0); void createStatusBar(); - void createTableView(QList &scoreList, QList &clubList); - void createTreeView(QList &scoreList, QObject *parent); + void createTableView(QList &, QList &); + void createTreeView(QList &, QObject *parent = 0); void updateStatusBar(); void loadScoreFile(QString &fileName, QList &scoreList); void loadClubFile(QString &fileName, QList &clubList); @@ -38,8 +38,9 @@ private slots: void updateTreeView(const QModelIndex & index); void newScore(); - void newCourse(); void editScore(); + void newCourse(); + void editCourse(); private: @@ -72,8 +73,10 @@ private: // Actions QAction *newScoreAct; - QAction *newCourseAct; QAction *editScoreAct; + QAction *newCourseAct; + QAction *editCourseAct; + QAction *viewScoreAct; QAction *viewCourseAct; QAction *viewStatisticAct;