0c1c60bfc19501ca7bc6d3d2b189ab0c72ac90e3
[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 { ROWS = 8, COLS = 9 };
65   enum { ROW_HOLE = 0, ROW_PAR = 1, ROW_HCP = 2, ROW_SCORE = 3, 
66          ROW_HOLE_2 = 4, ROW_PAR_2 = 5, ROW_HCP_2 = 6, ROW_SCORE_2 = 7};
67
68   QList<Score *> scoreList;
69   QList<Club *> clubList;
70
71   int currentScore;
72
73   // Current data pointers
74   Score *score;
75   Club *club;
76   Course *course;
77 };