<hole num="17" shots="5"/>
<hole num="18" shots="4"/>
</score>
-<score club="Master" course="Forest" date="2008-10-11">
+<score club="Master" course="Forest" date="2004-10-11">
<hole num="1" shots="6"/>
<hole num="2" shots="4"/>
<hole num="3" shots="8"/>
-TARGET = bin/scorecard
+TARGET = scorecard
DESTDIR = bin
MOC_DIR = moc
OBJECTS_DIR = obj
holeList << iHole;
}
-QString Score::getScore(int i) {
+QString Score::getScore(int i) const
+{
if (i >= 0 && i < holeList.size())
return holeList.at(i)->getShots();
else
return QString("-");
}
-QString Score::getTotal(int what) {
+QString Score::getTotal(int what) const
+{
int tot = 0;
if (what == Total)
return QString("%1").arg(tot);
}
-QString& Score::getClubName() {
+const QString& Score::getClubName() const
+{
return club;
}
-QString& Score::getCourseName() {
+const QString& Score::getCourseName() const
+{
return course;
}
-QString& Score::getDate() {
+const QString& Score::getDate() const
+{
return date;
}
-void Score::dump() {
+void Score::dump()
+{
qDebug() << club << " " << course << " " << date ;
for (int i=0; i<holeList.size(); i++)
holeList.at(i)->dump();
return courseList.at(pos);
}
-Course *Club::getCourse(QString &courseName)
+Course *Club::getCourse(const QString &courseName)
{
QListIterator<Course *> i(courseList);
Course *c = 0;
Score(const QDomElement node);
Score(QVector<QString> scores, QString &club, QString &course, QString &date);
+ bool operator< (const Score& val) const
+ {
+ return date < val.getDate();
+ }
+
QDomElement toElement(QDomDocument doc);
void addHole(Hole *iHole);
- QString getScore(int i);
- QString getTotal(int what);
- QString& getClubName();
- QString& getCourseName();
- QString& getDate();
+ QString getScore(int i) const;
+ QString getTotal(int what) const;
+ const QString& getClubName() const;
+ const QString& getCourseName() const;
+ const QString& getDate() const;
void dump();
private:
QList <Hole *> holeList;
QString club, course, date;
-
};
class Course {
void dump();
QString& getName();
Course *getCourse(int pos);
- Course *getCourse(QString &courseName);
+ Course *getCourse(const QString &courseName);
QList <Course *> getCourseList() { return courseList; } // HACK: fixme
#include "xml-parser.h"
#include "xml-dom-parser.h"
+QString appName("scorecard");
QString topDir("/opt/scorecard");
QString mmcDir("/media/mmc1/scorecard");
QString dataDirName("/data/");
QString clubFile;
QString logFile("/tmp/scorecard.log");
+bool dateLessThan(const Score *s1, const Score *s2)
+{
+ return (*s1) < (*s2);
+}
+
MainWindow::MainWindow(QMainWindow *parent) : QMainWindow(parent)
{
resize(800, 480);
loadScoreFile(scoreFile, scoreList);
loadClubFile(clubFile, clubList);
-#ifdef TEST
- saveScoreFile(scoreFileWr, scoreList);
- saveClubFile(clubFileWr, clubList);
-#endif
+ // Sort the scores based on dates
+ qSort(scoreList.begin(), scoreList.end(), dateLessThan);
createTableView(scoreList, clubList);
//createTreeView(scoreList, parent);
Score *score = new Score(scores, clubName, courseName, date);
scoreList << score;
+ // 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);
- lastButtonClicked();
+ scoreTableModel->setScore(scoreList, score);
+ updateStatusBar();
}
}
}
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)
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)
QDate today(QDate::currentDate());
lineEditDate->setText(today.toString("yyyy-MM-dd"));
+ date = new QDateEdit(parent);
+
connect(pushButtonNext, SIGNAL(clicked()), this, SLOT(next()));
leftLayout = new QVBoxLayout;
leftLayout->addWidget(listClub);
+ leftLayout->addWidget(date);
leftLayout->addWidget(lineEditDate);
rightLayout = new QVBoxLayout;
#include <QComboBox>
#include <QLabel>
#include <QPushButton>
+#include <QDateEdit>
#include <QLayout>
#include "data.h"
// Widgets
QListWidget *listClub;
QLineEdit *lineEditDate;
+ QDateEdit *date;
QLabel *labelClub;
QLabel *labelCourse;
QPushButton *pushButtonNext;
return Qt::NoItemFlags;
}
-void ScoreTableModel::setScore(QList<Score *> &sList)
+// Assign the 'sList' to internal 'scoreList'. Set the current score
+// to 'currentScore', or to 's'.
+void ScoreTableModel::setScore(QList<Score *> &sList, Score *s)
{
scoreList = sList;
- if (scoreList.size() > 0)
+ if (scoreList.size() > 0) {
+ if (s) {
+ currentScore = scoreList.indexOf(s);
+ if (currentScore == -1)
+ currentScore = 0;
+ }
score = scoreList.at(currentScore); // NOTE: assumes non-empty list
+ }
}
void ScoreTableModel::setClub(QList<Club *> &cList)
return str;
}
-Course *ScoreTableModel::findCourse(QString &clubName, QString &courseName)
+Course *ScoreTableModel::findCourse(const QString &clubName,
+ const QString &courseName)
{
QListIterator<Club *> i(clubList);
Club *c;
course = 0;
}
Qt::ItemFlags flags ( const QModelIndex & index );
- void setScore(QList<Score *> &sList);
+ void setScore(QList<Score *> &sList, Score *score = 0);
void setClub(QList<Club *> &cList);
- Course *findCourse(QString &clubName, QString &courseName);
+ Course *findCourse(const QString &clubName, const QString &courseName);
int rowCount(const QModelIndex & parent) const;
int columnCount(const QModelIndex & parent) const;
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;