- 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
return shots;
}
+void Hole::setShots(QString& s) {
+ shots = s;
+}
+
QString Hole::getHcp() {
return hcp;
}
return node;
}
+int Score::update(QVector<QString> scores)
+{
+ for (int i = 0; i < scores.size(); i++) {
+ Hole *hole = holeList.at(i);
+ if (hole->getShots() != scores[i])
+ hole->setShots(scores[i]);
+ }
+ return 0;
+}
+
void Score::addHole(Hole *iHole) {
holeList << iHole;
}
Hole(int num, QString &par, QString &hcp);
QDomElement toElement(QDomDocument doc);
QString getShots();
+ void setShots(QString& shots);
QString getHcp();
QString getPar();
void dump();
}
QDomElement toElement(QDomDocument doc);
+ int update(QVector<QString> scores);
void addHole(Hole *iHole);
QString getScore(int i) const;
QString getTotal(int what) const;
return (*s1) < (*s2);
}
-MainWindow::MainWindow(QMainWindow *parent) : QMainWindow(parent)
+MainWindow::MainWindow(QMainWindow *parent): QMainWindow(parent)
{
resize(800, 480);
QWidget *centralWidget = new QWidget(this);
- // TODO: move to proper function
- table = new QTableView(centralWidget);
-
setCentralWidget(centralWidget);
loadScoreFile(scoreFile, scoreList);
// Setup 'score' tab view
void MainWindow::createTableView(QList<Score *> &scoreList, QList <Club *> &clubList)
{
+ table = new QTableView;
+
nextButton = new QPushButton(tr(">"));
prevButton = new QPushButton(tr("<"));
firstButton = new QPushButton(tr("<<"));
table->setModel(scoreTableModel);
- // Flag model items which one belongs to front and back nines
- table->setRootIndex(scoreTableModel->index(0, 1));
-
// Fill out all the space with the tables
table->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
table->verticalHeader()->setResizeMode(QHeaderView::Stretch);
void MainWindow::createActions()
{
- newScoreAct = new QAction(tr("&New Score"), this);
+ newScoreAct = new QAction(tr("New Score"), this);
connect(newScoreAct, SIGNAL(triggered()), this, SLOT(newScore()));
- newCourseAct = new QAction(tr("&New Course"), this);
+ newCourseAct = new QAction(tr("New Course"), this);
connect(newCourseAct, SIGNAL(triggered()), this, SLOT(newCourse()));
+ editScoreAct = new QAction(tr("Edit Score"), this);
+ connect(editScoreAct, SIGNAL(triggered()), this, SLOT(editScore()));
+
#if 0
viewScoreAct = new QAction(tr("&View Scores"), this);
connect(viewScoreAct, SIGNAL(triggered()), this, SLOT(viewScore()));
#endif
menu->addAction(newScoreAct);
menu->addAction(newCourseAct);
+ menu->addAction(editScoreAct);
}
void MainWindow::updateStatusBar()
CourseDialog *courseDialog = new CourseDialog(this);
- QString title = "New Course : " + clubName + "," + courseName;
+ QString title = "New Course: " + clubName + "," + courseName;
courseDialog->setWindowTitle(title);
int result = courseDialog->exec();
selectDialog->results(clubName, courseName, date);
ScoreDialog *scoreDialog = new ScoreDialog(this);
- QString title = "New Score : " + courseName + ", " + date;
+ QString title = "New Score: " + courseName + ", " + date;
scoreDialog->setWindowTitle(title);
Club *club = findClub(clubName);
}
}
+void MainWindow::editScore()
+{
+ Course *course = scoreTableModel->getCourse();
+ Score *score = scoreTableModel->getScore();
+ QString date = score->getDate();
+
+ ScoreDialog *scoreDialog = new ScoreDialog(this);
+
+ QString title = "Edit Score: " + course->getName() + ", " + date;
+ scoreDialog->setWindowTitle(title);
+
+ scoreDialog->init(course, score);
+
+ int result = scoreDialog->exec();
+
+ if (result) {
+ QVector<QString> scores(18);
+
+ scoreDialog->results(scores);
+
+ score->update(scores);
+
+ // Sort the scores based on dates
+ qSort(scoreList.begin(), scoreList.end(), dateLessThan);
+ // Save it
+ saveScoreFile(scoreFile, scoreList);
+
+ // TODO: does this really work? No mem leaks?
+ scoreTableModel->setScore(scoreList, score);
+ updateStatusBar();
+ }
+}
+
void MainWindow::loadScoreFile(QString &fileName, QList<Score *> &list)
{
ScoreXmlHandler handler(list);
if (handler.parse(fileName))
- qDebug() << "File loaded: " << fileName << " entries : " << list.size();
+ qDebug() << "File loaded: " << fileName << " entries: " << list.size();
}
void MainWindow::saveScoreFile(QString &fileName, QList<Score *> &list)
if (handler.save(fileName))
// TODO: banner
- qDebug() << "File saved : " << fileName << " entries : " << list.size();
+ qDebug() << "File saved: " << fileName << " entries: " << list.size();
else
- qDebug() << "Unable to save : " << fileName;
+ qDebug() << "Unable to save: " << fileName;
}
void MainWindow::loadClubFile(QString &fileName, QList<Club *> &list)
ClubXmlHandler handler(list);
if (handler.parse(fileName))
- qDebug() << "File loaded: " << fileName << " entries : " << list.size();
+ qDebug() << "File loaded: " << fileName << " entries: " << list.size();
}
void MainWindow::saveClubFile(QString &fileName, QList<Club *> &list)
if (handler.save(fileName))
// TODO: banner
- qDebug() << "File saved : " << fileName << " entries : " << list.size();
+ qDebug() << "File saved: " << fileName << " entries: " << list.size();
else
- qDebug() << "Unable to save : " << fileName;
+ qDebug() << "Unable to save: " << fileName;
}
void updateTreeView(const QModelIndex & index);
void newScore();
void newCourse();
+ void editScore();
private:
// Actions
QAction *newScoreAct;
QAction *newCourseAct;
+ QAction *editScoreAct;
QAction *viewScoreAct;
QAction *viewCourseAct;
QAction *viewStatisticAct;
connect(pushButtonFinish, SIGNAL(clicked()), this, SLOT(finish()));
}
-void ScoreDialog::init(Course *course)
+void ScoreDialog::init(Course *course, Score *score)
{
- QTableWidgetItem *par, *hcp, *score, *holeNum;
+ QTableWidgetItem *par, *hcp, *scoreItem, *holeNum;
QColor bgColor(Qt::gray);
for (int i = 0; i < 18; i++) {
par = new QTableWidgetItem(course->getPar(i));
hcp = new QTableWidgetItem(course->getHcp(i));
- score = new QTableWidgetItem("");
+ if (score)
+ scoreItem = new QTableWidgetItem(score->getScore(i));
+ else
+ scoreItem = new QTableWidgetItem("");
holeNum = new QTableWidgetItem(QString::number(i+1));
holeNum->setBackgroundColor(bgColor);
par->setTextAlignment(Qt::AlignCenter);
hcp->setTextAlignment(Qt::AlignCenter);
- score->setTextAlignment(Qt::AlignCenter);
+ scoreItem->setTextAlignment(Qt::AlignCenter);
holeNum->setTextAlignment(Qt::AlignCenter);
if (i < 9) {
table->setItem(ROW_HOLE, i, holeNum);
table->setItem(ROW_PAR, i, par);
table->setItem(ROW_HCP, i, hcp);
- table->setItem(ROW_SCORE, i, score);
+ table->setItem(ROW_SCORE, i, scoreItem);
}
else {
table->setItem(ROW_HOLE_2, i-9, holeNum);
table->setItem(ROW_PAR_2, i-9, par);
table->setItem(ROW_HCP_2, i-9, hcp);
- table->setItem(ROW_SCORE_2, i-9, score);
+ table->setItem(ROW_SCORE_2, i-9, scoreItem);
}
}
// Set focus to 1st cell
table->setCurrentCell(ROW_SCORE, 0);
- setDefaultScore(table);
+ if (!score)
+ setDefaultScore(table);
}
// Set default score to par if not set
public:
ScoreDialog(QWidget *parent = 0);
- void init(Course *course);
+ void init(Course *course, Score *score = 0);
void results(QVector<QString> &scores);
bool validate(void);
Qt::ItemFlags ScoreTableModel::flags ( const QModelIndex & index )
{
- return Qt::NoItemFlags;
+ Qt::ItemFlags flags = QAbstractItemModel::flags(index);
+ qDebug() << "flags " << currentMode;
+
+ return flags;
+}
+
+void ScoreTableModel::setMode(int m)
+{
+ currentMode = m;
+}
+
+int ScoreTableModel::mode(void)
+{
+ return currentMode;
}
// Assign the 'sList' to internal 'scoreList'. Set the current score
return str;
}
+QString& ScoreTableModel::clubName(void)
+{
+ QString str("");
+
+ if (club)
+ str = club->getName();
+
+ return str;
+}
+
+QString& ScoreTableModel::courseName(void)
+{
+ QString str("");
+
+ if (course)
+ str = course->getName();
+
+ return str;
+}
+
Course *ScoreTableModel::findCourse(const QString &clubName,
const QString &courseName)
{
return 0;
}
+Club *ScoreTableModel::getClub(void)
+{
+ return club;
+}
+
+Course *ScoreTableModel::getCourse(void)
+{
+ return course;
+}
+
+Score *ScoreTableModel::getScore(void)
+{
+ return score;
+}
+
void ScoreTableModel::first()
{
if (score && course) {
Q_OBJECT
public:
+ enum { ViewMode = 0, EditMode = 1 };
ScoreTableModel(QObject *parent = 0) : QAbstractTableModel(parent)
{
score = 0;
club = 0;
course = 0;
+ currentMode = ViewMode;
}
Qt::ItemFlags flags ( const QModelIndex & index );
+ void setMode(int m);
+ int mode(void);
void setScore(QList<Score *> &sList, Score *score = 0);
+ Score *getScore(void);
void setClub(QList<Club *> &cList);
+ Club *getClub(void);
+ Course *getCourse(void);
+
Course *findCourse(const QString &clubName, const QString &courseName);
+ QString& clubName(void);
+ QString& courseName(void);
int rowCount(const QModelIndex & parent) const;
int columnCount(const QModelIndex & parent) const;
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
void last();
private:
+ int currentMode;
enum { ROWS = 8, COLS = 9 };
enum { ROW_HOLE = 0, ROW_PAR = 1, ROW_HCP = 2, ROW_SCORE = 3,
ROW_HOLE_2 = 4, ROW_PAR_2 = 5, ROW_HCP_2 = 6, ROW_SCORE_2 = 7};