X-Git-Url: http://git.maemo.org/git/?a=blobdiff_plain;f=src%2Fmain-window.cpp;h=6ca8d3a889e2b226eba194e8be224f313247eb0a;hb=1362d51e8c026dd31200a9934a13e017b19a327b;hp=c2356054b4ff8c0d79a952d52cc84eb58d47de90;hpb=ddd5f3a00f4f60bde20023883780ab31e1468ddc;p=scorecard diff --git a/src/main-window.cpp b/src/main-window.cpp index c235605..6ca8d3a 100644 --- a/src/main-window.cpp +++ b/src/main-window.cpp @@ -11,6 +11,7 @@ #include "xml-parser.h" #include "xml-dom-parser.h" +QString appName("scorecard"); QString topDir("/opt/scorecard"); QString mmcDir("/media/mmc1/scorecard"); QString dataDirName("/data/"); @@ -22,6 +23,11 @@ QString clubFileName("club.xml"); 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); @@ -39,10 +45,8 @@ MainWindow::MainWindow(QMainWindow *parent) : QMainWindow(parent) 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); @@ -350,11 +354,14 @@ void MainWindow::newScore() 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(); } } } @@ -364,7 +371,7 @@ void MainWindow::loadScoreFile(QString &fileName, QList &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 &list) @@ -383,7 +390,7 @@ void MainWindow::loadClubFile(QString &fileName, QList &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 &list)