Main window displayed correctly when no data
authorSakari Poussa <sakari.poussa@nokia.com>
Wed, 28 Oct 2009 21:28:07 +0000 (23:28 +0200)
committerSakari Poussa <sakari.poussa@nokia.com>
Wed, 28 Oct 2009 21:28:07 +0000 (23:28 +0200)
No selections in main window

TODO
src/course-dialog.cpp
src/main-window.cpp
src/score-dialog.cpp
src/table-model.cpp

diff --git a/TODO b/TODO
index 6ab9d04..a3f9cfe 100644 (file)
--- a/TODO
+++ b/TODO
@@ -1,6 +1,4 @@
-TOP
-- If no data files, the hole numbers are missing from main-window
-- Disable selection from the main-window
+TOP Items
 
 TODO General:
 - Statistics view (BIG)
index ef05e30..e51e335 100644 (file)
@@ -132,6 +132,8 @@ void CourseDialog::createTable(QWidget *parent)
 void CourseDialog::init(Course *course)
 {
   QTableWidgetItem *par, *hcp;
+  QColor fgColor(Qt::white);
+  QColor bgColor(Qt::black);
 
   for (int i=0; i<18; i++) {
     if (course) {
@@ -145,7 +147,7 @@ void CourseDialog::init(Course *course)
     QTableWidgetItem *len = new QTableWidgetItem("");
 
     QTableWidgetItem *holeNum = new QTableWidgetItem(QString::number(i+1));
-    QColor bgColor(Qt::gray);
+    holeNum->setTextColor(fgColor);
     holeNum->setBackgroundColor(bgColor);
 
     holeNum->setTextAlignment(Qt::AlignCenter);
@@ -166,7 +168,6 @@ void CourseDialog::init(Course *course)
       table->setItem(7, i-9, len);
     }
   }
-
 }
 
 void CourseDialog::up(void)
index 750b600..624d43e 100644 (file)
@@ -52,7 +52,6 @@ MainWindow::MainWindow(QMainWindow *parent): QMainWindow(parent)
   createStatusBar();
 
   createLayout(centralWidget);
-
 }
 
 void MainWindow::loadSettings(void)
@@ -120,12 +119,15 @@ void MainWindow::createTableView(QList<Score *> &scoreList, QList <Club *> &club
   connect(lastButton, SIGNAL(clicked()), this, SLOT(lastButtonClicked()));
 
   scoreTableModel = new ScoreTableModel();
-  scoreTableModel->setScore(scoreList);
-  scoreTableModel->setClub(clubList);
 
   table->showGrid();
 
   table->setModel(scoreTableModel);
+  QItemSelectionModel selectionModel();
+  table->setSelectionMode(QAbstractItemView::NoSelection);
+
+  scoreTableModel->setScore(scoreList);
+  scoreTableModel->setClub(clubList);
 
   // Fill out all the space with the tables
   table->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
@@ -321,6 +323,7 @@ void MainWindow::newCourse()
        }
       }
       else {
+       // New club and course
        club = new Club(clubName);
        course = new Course(courseName, par, hcp);
        club->addCourse(course);
@@ -330,7 +333,6 @@ void MainWindow::newCourse()
 
       // TODO: does this really work? No mem leaks?
       scoreTableModel->setClub(clubList);
-
     }
   }
 }
index bea330d..78b3be1 100644 (file)
@@ -167,7 +167,8 @@ void ScoreDialog::createButton(QWidget *parent)
 void ScoreDialog::init(Course *course, Score *score)
 {
   QTableWidgetItem *par, *hcp, *scoreItem, *holeNum;
-  QColor bgColor(Qt::gray);
+  QColor fgColor(Qt::white);
+  QColor bgColor(Qt::black);
 
   for (int i = 0; i < 18; i++) {
     par = new QTableWidgetItem(course->getPar(i));
@@ -178,6 +179,7 @@ void ScoreDialog::init(Course *course, Score *score)
       scoreItem = new QTableWidgetItem("");
     holeNum = new QTableWidgetItem(QString::number(i+1));
 
+    holeNum->setTextColor(fgColor);
     holeNum->setBackgroundColor(bgColor);
 
     par->setTextAlignment(Qt::AlignCenter);
index 0064e8b..077ca02 100644 (file)
@@ -179,10 +179,18 @@ QModelIndex ScoreTableModel::index(int row, int column, const QModelIndex &paren
 
 QVariant ScoreTableModel::data(const QModelIndex &index, int role) const
 {
-  if (!index.isValid())
-    return QVariant();
+  // TODO: move away from the stack
+  QColor colorHoleBg(Qt::black);
+  QColor colorHoleFg(Qt::white);
+  QColor colorBirdie(Qt::yellow);
+  QColor colorPar(Qt::green);
+  QColor colorBogey(Qt::darkGreen);
+  QColor colorDoubleBogey(Qt::cyan);
+  QColor colorBad(Qt::white);
+  QColor colorSubTotal(Qt::lightGray);
+  QColor colorTotal(Qt::gray);
 
-  if (!course || !score)
+  if (!index.isValid())
     return QVariant();
 
   int row = index.row();
@@ -201,16 +209,6 @@ QVariant ScoreTableModel::data(const QModelIndex &index, int role) const
   //
   // COLORS
   //
-  QColor colorHoleBg(Qt::black);
-  QColor colorHoleFg(Qt::white);
-  QColor colorBirdie(Qt::yellow);
-  QColor colorPar(Qt::green);
-  QColor colorBogey(Qt::darkGreen);
-  QColor colorDoubleBogey(Qt::cyan);
-  QColor colorBad(Qt::white);
-  QColor colorSubTotal(Qt::lightGray);
-  QColor colorTotal(Qt::gray);
-
   if (role == Qt::ForegroundRole) {
     if (row == ROW_HOLE || row == ROW_HOLE_2) {
        QBrush brush(colorHoleFg);
@@ -224,7 +222,7 @@ QVariant ScoreTableModel::data(const QModelIndex &index, int role) const
        return brush;
     }
 
-    if (row == ROW_SCORE || row == ROW_SCORE_2) {
+    if (score && course && (row == ROW_SCORE || row == ROW_SCORE_2)) {
       int par;
       int shots;
       if (row == ROW_SCORE) {
@@ -294,15 +292,15 @@ QVariant ScoreTableModel::data(const QModelIndex &index, int role) const
        return QString("In");
 
       // In/Out for par
-      if (row == ROW_PAR)
+      if (score && course && row == ROW_PAR)
        return course->getTotal(TotalOut);
-      if (row == ROW_PAR_2)
+      if (score && course && row == ROW_PAR_2)
        return course->getTotal(TotalIn);
 
       // In/Out for score
-      if (row == ROW_SCORE)
+      if (score && row == ROW_SCORE)
        return score->getTotal(TotalOut);
-      if (row == ROW_SCORE_2)
+      if (score && row == ROW_SCORE_2)
        return score->getTotal(TotalIn);
       
     }
@@ -311,9 +309,9 @@ QVariant ScoreTableModel::data(const QModelIndex &index, int role) const
       if (row == ROW_HOLE_2)
        return QString("Tot");
       // Total score
-      if (row == ROW_PAR_2)
+      if (score && course && row == ROW_PAR_2)
        return course->getTotal(Total);
-      if (row == ROW_SCORE_2)
+      if (score && row == ROW_SCORE_2)
        return score->getTotal(Total);
     }
     else {
@@ -324,17 +322,23 @@ QVariant ScoreTableModel::data(const QModelIndex &index, int role) const
       case ROW_HOLE_2:
        return col + 10;
       case ROW_PAR:
-       return course->getPar(col); 
+       if (score && course)
+         return course->getPar(col); 
       case ROW_PAR_2:
-       return course->getPar(col + 9); 
+       if (score && course)
+         return course->getPar(col + 9); 
       case ROW_HCP: 
-       return course->getHcp(col); 
-      case ROW_HCP_2: 
-       return course->getHcp(col + 9);
-      case ROW_SCORE: 
-       return score->getScore(col);
+       if (score && course)
+         return course->getHcp(col); 
+      case ROW_HCP_2:
+       if (score && course)
+         return course->getHcp(col + 9);
+      case ROW_SCORE:
+       if (score)
+         return score->getScore(col);
       case ROW_SCORE_2: 
-       return score->getScore(col + 9);
+       if (score)
+         return score->getScore(col + 9);
       }
     }
   }