Behave correctly if score contains unknown course
[scorecard] / src / main-window.cpp
index f028e39..ad85c04 100644 (file)
@@ -34,10 +34,6 @@ QString masterFile;
 QString logFile("/tmp/scorecard.log");
 QString titleScores("ScoreCard - Scores");
 QString titleCourses("ScoreCard - Courses");
-QString settingsGroup("Settings");
-QString settingsHcp("hcp");
-QString settingsHomeClub("home-club");
-QString settingsDefaultCourses("default-courses");
 
 bool dateLessThan(const Score *s1, const Score *s2)
 {
@@ -145,37 +141,52 @@ void MainWindow::flushReadOnlyItems()
     }
 }
 
+void MainWindow::markHomeClub()
+{
+    TRACE;
+    QListIterator<Club *> i(clubList);
+    Club *c;
+
+    while (i.hasNext()) {
+        c = i.next();
+        if (c->getName() == conf.homeClub)
+            c->setHomeClub(true);
+        else
+            c->setHomeClub(false);
+    }
+}
 
 MainWindow::MainWindow(QMainWindow *parent): QMainWindow(parent)
 {
-  resize(800, 480);
+    resize(800, 480);
 
 #ifdef Q_WS_MAEMO_5
-  setAttribute(Qt::WA_Maemo5StackedWindow);
+    setAttribute(Qt::WA_Maemo5StackedWindow);
 #endif
 
-  loadSettings();
+    loadSettings();
 
-  centralWidget = new QWidget(this);
+    centralWidget = new QWidget(this);
 
-  setCentralWidget(centralWidget);
+    setCentralWidget(centralWidget);
 
-  loadScoreFile(scoreFile, scoreList);
-  if (conf.defaultCourses == "Yes")
-      loadClubFile(masterFile, clubList, true);
-  loadClubFile(clubFile, clubList);
+    loadScoreFile(scoreFile, scoreList);
+    if (conf.defaultCourses == "Yes")
+        loadClubFile(masterFile, clubList, true);
+    loadClubFile(clubFile, clubList);
+    markHomeClub();
 
-  // Sort the scores based on dates
-  qSort(scoreList.begin(), scoreList.end(), dateMoreThan); 
-  createActions();
-  createMenus();
+    // Sort the scores based on dates
+    qSort(scoreList.begin(), scoreList.end(), dateMoreThan); 
+    createActions();
+    createMenus();
 
-  createListView(scoreList, clubList);
+    createListView(scoreList, clubList);
 
-  createLayoutList(centralWidget);
+    createLayoutList(centralWidget);
 
-  scoreWindow = new ScoreWindow(this);
-  courseWindow = new CourseWindow(this);
+    scoreWindow = new ScoreWindow(this);
+    courseWindow = new CourseWindow(this);
 }
 
 void MainWindow::loadSettings(void)
@@ -258,7 +269,7 @@ void MainWindow::createListView(QList<Score *> &scoreList,
     scoreListModel = new ScoreListModel(scoreList, clubList);
     courseListModel = new CourseListModel(clubList);
 
-    list->setStyleSheet(ScoreStyle::style());
+    list->setStyleSheet(defaultStyleSheet);
 
     list->setSelectionMode(QAbstractItemView::SingleSelection);
     list->setProperty("FingerScrolling", true);
@@ -375,6 +386,7 @@ void MainWindow::clickedList(const QModelIndex &index)
 void MainWindow::viewScore(Score * score, Course * course)
 {
     TRACE;
+    qDebug() << score << course;
     scoreWindow->setup(score, course);
     scoreWindow->show();
 }
@@ -627,7 +639,7 @@ void MainWindow::viewStatistics()
     QTableView *table = new QTableView;
     table->showGrid();
     table->setSelectionMode(QAbstractItemView::NoSelection);
-    table->setStyleSheet(ScoreStyle::style());
+    table->setStyleSheet(statStyleSheet);
     table->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
     table->verticalHeader()->setResizeMode(QHeaderView::Stretch);
     table->verticalHeader()->setAutoFillBackground(true);
@@ -664,8 +676,6 @@ void MainWindow::viewSettings()
         QString newValue = conf.defaultCourses.toString();
         saveSettings();
 
-        qDebug() << "Settings:" << oldValue << "->" << newValue;
-
         // Reload club list, or drop r/o courses from list
         if (oldValue == "Yes" && newValue == "No") {
             flushReadOnlyItems();
@@ -677,6 +687,7 @@ void MainWindow::viewSettings()
             courseListModel->update(clubList);
             list->update();
         }
+        markHomeClub();
     }
 }