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)
{
}
// 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();
createMenus();
createListView(scoreList, clubList);
- updateTitleBar();
createLayoutList(centralWidget);
}
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);
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()
menu->addActions(filterGroup->actions());
}
-void MainWindow::updateTitleBar()
+void MainWindow::updateTitleBar(QString & msg)
{
- QString title("ScoreCard");
- setWindowTitle(title);
+ setWindowTitle(msg);
}
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 ¤t,
- const QModelIndex &previous)
-{
- qDebug() << "Current: " << current;
-}
void MainWindow::newCourse()
{
}
// Save it
saveClubFile(clubFile, clubList);
- // TODO: update on live
- //courseListModel->update(courseList);
+ courseListModel->update(clubList);
list->update();
}
}
}
}
-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());