9c6cb7ca219e506770970401003e0f8022f6e40e
[scorecard] / src / table-model.h
1 /*
2  * Copyright (C) 2009 Sakari Poussa
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, version 2.
7  */
8
9 #include <QStringList>
10 #include <QAbstractTableModel>
11
12 #include "data.h"
13
14 #define ROW_COUNT  3
15 #define COL_COUNT  9
16
17 // TODO: change name to ScoreTableModel
18 class ScoreTableModel : public QAbstractTableModel
19 {
20
21   Q_OBJECT
22
23 public:
24   enum { ViewMode = 0, EditMode = 1 };
25
26   ScoreTableModel(QObject *parent = 0) : QAbstractTableModel(parent) 
27   {
28     currentScore = 0;
29     score = 0;
30     club = 0;
31     course = 0;
32     currentMode = ViewMode;
33   }
34   Qt::ItemFlags flags ( const QModelIndex & index );
35   void setMode(int m);
36   int mode(void);
37   void setScore(QList<Score *> &sList, Score *score = 0);
38   Score *getScore(void);
39   void setClub(QList<Club *> &cList);
40   Club *getClub(void);
41   Course *getCourse(void);
42
43   Course *findCourse(const QString &clubName, const QString &courseName);
44   QString& clubName(void);
45   QString& courseName(void);
46   int rowCount(const QModelIndex & parent) const;
47   int columnCount(const QModelIndex & parent) const;
48   QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
49   QVariant data(const QModelIndex & index, int role) const;
50   QVariant headerData(int section, Qt::Orientation orientation, int role) const;
51
52   int setItem(int row, int col, int data);
53
54   QString getInfoText();
55   QString getCountText();
56
57   void next();
58   void prev();
59   void first();
60   void last();
61
62  private:
63   int currentMode;
64   enum { 
65     ROWS = 8, 
66     COLS = 9 
67   };
68   enum { 
69     ROW_HOLE = 0, 
70     ROW_PAR = 1, 
71     ROW_HCP = 2, 
72     ROW_SCORE = 3, 
73     ROW_HOLE_2 = 4, 
74     ROW_PAR_2 = 5, 
75     ROW_HCP_2 = 6, 
76     ROW_SCORE_2 = 7
77   };
78
79   QList<Score *> scoreList;
80   QList<Club *> clubList;
81
82   int currentScore;
83
84   // Current data pointers
85   Score *score;
86   Club *club;
87   Course *course;
88 };