<hole num="18" par="4" hcp="9" />
</course>
</club>
+ <club name="crash" >
+ <course name="1" >
+ <hole num="1" par="4" hcp="9" />
+ <hole num="2" par="4" hcp="9" />
+ <hole num="3" par="4" hcp="9" />
+ <hole num="4" par="4" hcp="9" />
+ <hole num="5" par="4" hcp="9" />
+ <hole num="6" par="4" hcp="9" />
+ <hole num="7" par="4" hcp="9" />
+ <hole num="8" par="4" hcp="9" />
+ <hole num="9" par="4" hcp="9" />
+ <hole num="10" par="4" hcp="9" />
+ <hole num="11" par="4" hcp="9" />
+ <hole num="12" par="4" hcp="9" />
+ <hole num="13" par="4" hcp="9" />
+ <hole num="14" par="4" hcp="9" />
+ <hole num="15" par="4" hcp="9" />
+ <hole num="16" par="4" hcp="9" />
+ <hole num="17" par="4" hcp="9" />
+ <hole num="18" par="4" hcp="9" />
+ </course>
+ </club>
+ <club name="foo" >
+ <course name="bar" >
+ <hole num="1" par="4" hcp="9" />
+ <hole num="2" par="4" hcp="9" />
+ <hole num="3" par="4" hcp="9" />
+ <hole num="4" par="4" hcp="9" />
+ <hole num="5" par="4" hcp="9" />
+ <hole num="6" par="4" hcp="9" />
+ <hole num="7" par="4" hcp="9" />
+ <hole num="8" par="4" hcp="9" />
+ <hole num="9" par="4" hcp="9" />
+ <hole num="10" par="4" hcp="9" />
+ <hole num="11" par="4" hcp="9" />
+ <hole num="12" par="4" hcp="9" />
+ <hole num="13" par="4" hcp="9" />
+ <hole num="14" par="4" hcp="9" />
+ <hole num="15" par="4" hcp="9" />
+ <hole num="16" par="4" hcp="9" />
+ <hole num="17" par="4" hcp="9" />
+ <hole num="18" par="4" hcp="9" />
+ </course>
+ </club>
+ <club name="ggg" >
+ <course name="ggg" >
+ <hole num="1" par="4" hcp="9" />
+ <hole num="2" par="4" hcp="9" />
+ <hole num="3" par="4" hcp="9" />
+ <hole num="4" par="4" hcp="9" />
+ <hole num="5" par="4" hcp="9" />
+ <hole num="6" par="4" hcp="9" />
+ <hole num="7" par="4" hcp="9" />
+ <hole num="8" par="4" hcp="9" />
+ <hole num="9" par="4" hcp="9" />
+ <hole num="10" par="4" hcp="9" />
+ <hole num="11" par="4" hcp="9" />
+ <hole num="12" par="4" hcp="9" />
+ <hole num="13" par="4" hcp="9" />
+ <hole num="14" par="4" hcp="9" />
+ <hole num="15" par="4" hcp="9" />
+ <hole num="16" par="4" hcp="9" />
+ <hole num="17" par="4" hcp="9" />
+ <hole num="18" par="4" hcp="9" />
+ </course>
+ </club>
</data>
<hole num="17" shots="4" />
<hole num="18" shots="4" />
</score>
+ <score club="crash" course="1" date="2009-10-15" >
+ <hole num="1" shots="4" />
+ <hole num="2" shots="4" />
+ <hole num="3" shots="4" />
+ <hole num="4" shots="4" />
+ <hole num="5" shots="4" />
+ <hole num="6" shots="4" />
+ <hole num="7" shots="4" />
+ <hole num="8" shots="4" />
+ <hole num="9" shots="4" />
+ <hole num="10" shots="4" />
+ <hole num="11" shots="4" />
+ <hole num="12" shots="4" />
+ <hole num="13" shots="4" />
+ <hole num="14" shots="4" />
+ <hole num="15" shots="4" />
+ <hole num="16" shots="4" />
+ <hole num="17" shots="4" />
+ <hole num="18" shots="4" />
+ </score>
+ <score club="crash" course="1" date="2009-10-15" >
+ <hole num="1" shots="4" />
+ <hole num="2" shots="4" />
+ <hole num="3" shots="4" />
+ <hole num="4" shots="4" />
+ <hole num="5" shots="4" />
+ <hole num="6" shots="4" />
+ <hole num="7" shots="4" />
+ <hole num="8" shots="4" />
+ <hole num="9" shots="4" />
+ <hole num="10" shots="4" />
+ <hole num="11" shots="4" />
+ <hole num="12" shots="4" />
+ <hole num="13" shots="4" />
+ <hole num="14" shots="4" />
+ <hole num="15" shots="4" />
+ <hole num="16" shots="4" />
+ <hole num="17" shots="4" />
+ <hole num="18" shots="4" />
+ </score>
+ <score club="foo" course="bar" date="2009-10-15" >
+ <hole num="1" shots="4" />
+ <hole num="2" shots="4" />
+ <hole num="3" shots="4" />
+ <hole num="4" shots="4" />
+ <hole num="5" shots="4" />
+ <hole num="6" shots="4" />
+ <hole num="7" shots="4" />
+ <hole num="8" shots="4" />
+ <hole num="9" shots="4" />
+ <hole num="10" shots="4" />
+ <hole num="11" shots="4" />
+ <hole num="12" shots="4" />
+ <hole num="13" shots="4" />
+ <hole num="14" shots="4" />
+ <hole num="15" shots="4" />
+ <hole num="16" shots="4" />
+ <hole num="17" shots="4" />
+ <hole num="18" shots="4" />
+ </score>
+ <score club="ggg" course="ggg" date="2009-10-15" >
+ <hole num="1" shots="4" />
+ <hole num="2" shots="4" />
+ <hole num="3" shots="4" />
+ <hole num="4" shots="4" />
+ <hole num="5" shots="4" />
+ <hole num="6" shots="4" />
+ <hole num="7" shots="4" />
+ <hole num="8" shots="4" />
+ <hole num="9" shots="4" />
+ <hole num="10" shots="4" />
+ <hole num="11" shots="4" />
+ <hole num="12" shots="4" />
+ <hole num="13" shots="4" />
+ <hole num="14" shots="4" />
+ <hole num="15" shots="4" />
+ <hole num="16" shots="4" />
+ <hole num="17" shots="4" />
+ <hole num="18" shots="4" />
+ </score>
</data>
QString date;
selectDialog->results(clubName, courseName);
- qDebug() << "club=" << clubName;
- qDebug() << "course=" << courseName;
CourseDialog *courseDialog = new CourseDialog(this);
clubList << club;
}
saveClubFile(clubFile, clubList);
+
+ // TODO: does this really work? No mem leaks?
+ scoreTableModel->setClub(clubList);
+
}
}
}
ScoreXmlHandler handler(list);
if (handler.parse(fileName))
- qDebug() << "Score loaded : " << fileName <<
- " entries : " << list.size();
+ qDebug() << "Score loaded : " << fileName;
+ qDebug() << "Score entries : " << list.size();
}
void MainWindow::saveScoreFile(QString &fileName, QList<Score *> &list)
ClubXmlHandler handler(list);
if (handler.parse(fileName))
- qDebug() << "Club loaded: " << fileName <<
- " entries : " << list.size();
+ qDebug() << "Club loaded: " << fileName;
+ qDebug() << "Club entries : " << list.size();
}
void MainWindow::saveClubFile(QString &fileName, QList<Club *> &list)
void ScoreTableModel::setScore(QList<Score *> &sList)
{
scoreList = sList;
- score = scoreList.at(currentScore); // NOTE: assumes non-empty list
+ if (scoreList.size() > 0)
+ score = scoreList.at(currentScore); // NOTE: assumes non-empty list
}
void ScoreTableModel::setClub(QList<Club *> &cList)
{
clubList = cList;
- club = clubList.at(0);
- course = club->getCourse(0);
+
+ if (clubList.size() > 0)
+ club = clubList.at(0);
+
+ if (club)
+ course = club->getCourse(0);
}
QString ScoreTableModel::getInfoText()
{
- QString str = QString("%1, %2 / [%3/%4]").arg(score->getCourseName()).arg(score->getDate()).arg(currentScore+1).arg(scoreList.count());
+ QString str("");
+
+ if (score)
+ str = QString("%1, %2 / [%3/%4]").arg(score->getCourseName()).arg(score->getDate()).arg(currentScore+1).arg(scoreList.count());
+
return str;
}
void ScoreTableModel::first()
{
- currentScore = 0;
- score = scoreList.at(currentScore);
- course = findCourse(score->getClubName(), score->getCourseName());
- emit dataChanged(createIndex(0, 0), createIndex(ROW_COUNT-1, COL_COUNT-1));
+ if (score && course) {
+ currentScore = 0;
+ score = scoreList.at(currentScore);
+ course = findCourse(score->getClubName(), score->getCourseName());
+ emit dataChanged(createIndex(0, 0), createIndex(ROW_COUNT-1, COL_COUNT-1));
+ }
}
void ScoreTableModel::last()
{
- currentScore = scoreList.size() - 1;
- score = scoreList.at(currentScore);
- course = findCourse(score->getClubName(), score->getCourseName());
- emit dataChanged(createIndex(0, 0), createIndex(ROW_COUNT-1, COL_COUNT-1));
+ if (score && course) {
+ currentScore = scoreList.size() - 1;
+ score = scoreList.at(currentScore);
+ course = findCourse(score->getClubName(), score->getCourseName());
+ emit dataChanged(createIndex(0, 0), createIndex(ROW_COUNT-1, COL_COUNT-1));
+ }
}
void ScoreTableModel::next()
{
- if (currentScore < (scoreList.size() - 1)) {
- currentScore++;
- score = scoreList.at(currentScore);
- course = findCourse(score->getClubName(), score->getCourseName());
- emit dataChanged(createIndex(0, 0), createIndex(ROW_COUNT-1, COL_COUNT-1));
+ if (score && course) {
+ if (currentScore < (scoreList.size() - 1)) {
+ currentScore++;
+ score = scoreList.at(currentScore);
+ course = findCourse(score->getClubName(), score->getCourseName());
+ emit dataChanged(createIndex(0, 0), createIndex(ROW_COUNT-1, COL_COUNT-1));
+ }
}
}
void ScoreTableModel::prev()
{
- if (currentScore > 0) {
- currentScore--;
- score = scoreList.at(currentScore);
- course = findCourse(score->getClubName(), score->getCourseName());
- emit dataChanged(createIndex(0, 0), createIndex(ROW_COUNT-1, COL_COUNT-1));
+ if (score && course) {
+ if (currentScore > 0) {
+ currentScore--;
+ score = scoreList.at(currentScore);
+ course = findCourse(score->getClubName(), score->getCourseName());
+ emit dataChanged(createIndex(0, 0), createIndex(ROW_COUNT-1, COL_COUNT-1));
+ }
}
}
if (!index.isValid())
return QVariant();
+ if (!course || !score)
+ return QVariant();
+
int row = index.row();
int col = index.column();
ScoreTableModel(QObject *parent = 0) : QAbstractTableModel(parent)
{
currentScore = 0;
+ score = 0;
+ club = 0;
+ course = 0;
}
Qt::ItemFlags flags ( const QModelIndex & index );
void setScore(QList<Score *> &sList);