- Fixed course delete crashes
authorSakari Poussa <spoussa@gmail.com>
Tue, 27 Apr 2010 03:24:11 +0000 (06:24 +0300)
committerSakari Poussa <spoussa@gmail.com>
Tue, 27 Apr 2010 03:24:11 +0000 (06:24 +0300)
- Text alignment correct in list view
- Make list view selections correctly
- Color tuning

debian/control
scorecard.pro
src/data.cpp
src/data.h
src/list-model.cpp
src/main-window.cpp
src/main-window.h
src/score-common.h

index 3d762a5..70807c2 100644 (file)
@@ -7,7 +7,7 @@ Standards-Version: 3.7.2
 
 Package: scorecard
 Architecture: any
-Depends: libqt4-gui (>= 4.5.3~git20090723) 
+Depends: libqt4-gui (>= 4.6.2~git20100310) 
 Description: Simple golf score card application for N900 to keep track of your golf scores
  .
  Further Information: http://scorecard.garage.maemo.org 
index 2fd2cd9..9a8dac3 100644 (file)
@@ -50,7 +50,6 @@ unix {
     target.path =$$BINDIR
 
     data.path = $$DATADIR
-    data.files += data/club.xml
 
     desktop.path = $$MAEMODIR
     desktop.files += maemo/scorecard.desktop
index 6ff2d98..ad0813c 100644 (file)
@@ -242,6 +242,11 @@ Club * Course::parent()
     return club;
 }
 
+void Course::setParent(Club *parent)
+{
+    club = parent;
+}
+
 QDomElement Course::toElement(QDomDocument doc)
 {
   QDomElement node = doc.createElement("course");
@@ -337,6 +342,7 @@ Club::Club(QString &name)
 
 void Club::addCourse(Course *iCourse) {
   courseList << iCourse;
+  iCourse->setParent(this);
 }
 
 void Club::delCourse(Course * course) {
index 5709416..4ab4e61 100644 (file)
@@ -86,6 +86,7 @@ class Course {
   QString getTotal(int what);
   void dump();
   Club * parent();
+  void setParent(Club *parent);
 
  private:
   QList <Hole *> holeList;
index 76e42d4..5c3e8be 100644 (file)
@@ -53,13 +53,13 @@ QVariant ScoreListModel::data(const QModelIndex &index, int role) const
       QString tabs;
 
       int len = s.length();
-      if (len > 40)
+      if (len >= 40)
           tabs = "\t";
-      else if (len > 32)
+      else if (len >= 32)
           tabs = "\t\t";
-      else if (len > 24)
+      else if (len >= 24)
           tabs = "\t\t\t";
-      else if (len > 16)
+      else if (len >= 16)
           tabs = "\t\t\t\t";
       else
           tabs = "\t\t\t\t\t";
index 42c6b44..deda9ef 100644 (file)
@@ -29,6 +29,8 @@ QString scoreFile;
 QString clubFileName("club.xml");
 QString clubFile;
 QString logFile("/tmp/scorecard.log");
+QString titleScores("ScoreCard - Scores");
+QString titleCourses("ScoreCard - Courses");
 
 bool dateLessThan(const Score *s1, const Score *s2)
 {
@@ -85,6 +87,7 @@ Course *MainWindow::findCourse(const QString &clubName,
 }
 
 // Find course based on current selection on the list
+// TODO: make sure this is only called when course list is the model...
 Course *MainWindow::findCourse()
 {
     QModelIndex index = selectionModel->currentIndex();
@@ -122,7 +125,6 @@ MainWindow::MainWindow(QMainWindow *parent): QMainWindow(parent)
   createMenus();
 
   createListView(scoreList, clubList);
-  updateTitleBar();
 
   createLayoutList(centralWidget);
 }
@@ -173,7 +175,7 @@ void MainWindow::createLayoutList(QWidget *parent)
 void MainWindow::createListView(QList<Score *> &scoreList, 
                                 QList <Club *> &clubList)
 {
-    list = new QListView;
+    list = new QListView(this);
 
     scoreListModel = new ScoreListModel(scoreList, clubList);
     courseListModel = new CourseListModel(clubList);
@@ -181,25 +183,27 @@ void MainWindow::createListView(QList<Score *> &scoreList,
     list->setStyleSheet(ScoreStyle::style());
 
     list->setSelectionMode(QAbstractItemView::SingleSelection);
+    list->setProperty("FingerScrolling", true);
 
     // Initial view
     listScores();
+
+    connect(list, SIGNAL(clicked(QModelIndex)),
+            this, SLOT(clickedList(QModelIndex)));
 }
 
 void MainWindow::listScores()
 {
     list->setModel(scoreListModel);
     selectionModel = list->selectionModel();
-    connect(selectionModel, SIGNAL(selectionChanged (const QItemSelection &, const QItemSelection &)),
-            this, SLOT(scoreSelectionChanged(const QItemSelection &, const QItemSelection &)));
+    updateTitleBar(titleScores);
 }
 
 void MainWindow::listCourses()
 {
     list->setModel(courseListModel);
     selectionModel = list->selectionModel();
-    connect(selectionModel, SIGNAL(selectionChanged (const QItemSelection &, const QItemSelection &)),
-            this, SLOT(courseSelectionChanged(const QItemSelection &, const QItemSelection &)));
+    updateTitleBar(titleCourses);
 }
 
 void MainWindow::createActions()
@@ -241,10 +245,9 @@ void MainWindow::createMenus()
     menu->addActions(filterGroup->actions());
 }
 
-void MainWindow::updateTitleBar()
+void MainWindow::updateTitleBar(QString & msg)
 {
-    QString title("ScoreCard");
-    setWindowTitle(title);
+    setWindowTitle(msg);
 }
 
 void MainWindow::showNote(QString msg)
@@ -256,42 +259,31 @@ void MainWindow::showNote(QString msg)
 #endif
 }
 
-void MainWindow::scoreSelectionChanged(const QItemSelection &selected,
-                                       const QItemSelection &deselected)
+void MainWindow::clickedList(const QModelIndex &index)
 {
-    QModelIndexList list = selected.indexes();
-
-    int row = list.at(0).row();
+    int row = index.row();
 
-    Score * score = scoreList.at(row);
-    Course * course = findCourse(score->getClubName(), score->getCourseName());
-    viewScore(score, course);
-}
-
-void MainWindow::courseSelectionChanged(const QItemSelection &selected,
-                                        const QItemSelection &deselected)
-{
-    QModelIndexList indexes = selected.indexes();
-
-    int row = indexes.at(0).row();
-
-    QString str = courseListModel->data(indexes.at(0), Qt::DisplayRole).toString();
-
-    QStringList strList = str.split(",");
+    const QAbstractItemModel *m = index.model();
+    if (m == scoreListModel) {
+        if (row < scoreList.count()) {
+            Score * score = scoreList.at(row);
+            Course * course = findCourse(score->getClubName(), score->getCourseName());
+            viewScore(score, course);
+        }
+    }
+    else if (m == courseListModel) {
+        QString str = courseListModel->data(index, Qt::DisplayRole).toString();
+        QStringList strList = str.split(",");
 
-    if (strList.count() != 2) {
-        showNote(QString("Invalid course selection"));
-        return;
+        if (strList.count() != 2) {
+            showNote(QString("Invalid course selection"));
+            return;
+        }
+        Course * course = findCourse(strList.at(0), strList.at(1));
+        viewCourse(course);
     }
-    Course * course = findCourse(strList.at(0), strList.at(1));
-    viewCourse(course);
 }
 
-void MainWindow::changeCurrent(const QModelIndex &current,
-                               const QModelIndex &previous)
-{
-    qDebug() << "Current: " << current;
-}
 
 void MainWindow::newCourse()
 {
@@ -340,8 +332,7 @@ void MainWindow::newCourse()
             }
             // Save it
             saveClubFile(clubFile, clubList);
-            // TODO: update on live
-            //courseListModel->update(courseList);
+            courseListModel->update(clubList);
             list->update();
         }
     }
@@ -503,8 +494,7 @@ void MainWindow::editScore()
     }
 }
 
-void MainWindow::viewScore(Score * score, 
-                           Course * course)
+void MainWindow::viewScore(Score * score, Course * course)
 {
     scoreWin = new QMainWindow(this);
     QString title = QString("Score: %1, %2 - %3").arg(score->getClubName()).arg(score->getCourseName()).arg(score->getDate());
index 94129cc..c552f2d 100644 (file)
@@ -31,7 +31,7 @@ public:
   void createLayoutTable(QWidget *parent = 0);
   void createLayoutList(QWidget *parent = 0);
   void createListView(QList<Score *> &, QList <Club *> &);
-  void updateTitleBar();
+  void updateTitleBar(QString & msg);
   void loadScoreFile(QString &fileName, QList<Score *> &scoreList);
   void loadClubFile(QString &fileName, QList<Club *> &clubList);
   void saveScoreFile(QString &fileName, QList<Score *> &scoreList);
@@ -41,12 +41,8 @@ signals:
   void dataChanged();
 
 private slots:
-  void scoreSelectionChanged(const QItemSelection &selected,
-                             const QItemSelection &deselected);
-  void courseSelectionChanged(const QItemSelection &selected,
-                              const QItemSelection &deselected);
-  void changeCurrent(const QModelIndex &current,
-                     const QModelIndex &previous);
+  void clickedList(const QModelIndex &index);
+
   void newScore();
   void deleteScore();
   void editScore();
index 2b28aaa..08ce96f 100644 (file)
@@ -38,9 +38,9 @@ class ScoreColor
     static QColor holeFg()      { return Qt::yellow;               }
     static QColor birdie()      { return Qt::yellow;               }
     static QColor par()         { return Qt::green;                }
-    static QColor bogey()       { return QColor(0x20, 0x4a, 0x87); }
-    static QColor doubleBogey() { return QColor(0x34, 0x65, 0xa4); }
-    static QColor bad()         { return QColor(0x72, 0x9f, 0xcf); }
+    static QColor bogey()       { return Qt::cyan;                 }
+    static QColor doubleBogey() { return Qt::red;                  }
+    static QColor bad()         { return Qt::red;                  }
     static QColor subTotal()    { return Qt::white;                }
     static QColor total()       { return Qt::white;                }
 }; 
@@ -51,7 +51,7 @@ public:
     {
         return QString("QTableView {"
                          "background-color: white;"
-                         "color : red;"
+                         "color : gray;"
                          "border: solid green;"
                          "font-size : 20px;"
                          "font-style : italic;"