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();