Merge branch 'master' of /opt/src/sb1/qt/scorecard
[scorecard] / src / stat-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 <QAbstractTableModel>
10
11 #include "data.h"
12
13 class StatItem
14 {
15  public:
16   StatItem() {}
17
18   void setYear(QString &year) { m_year = year.toInt(); }
19   int year() { return m_year; }
20
21   void setRounds(int n) { m_rounds = n; }
22   int rounds() { return m_rounds; }
23
24   void setAverage(int n) { m_average = n; }
25   int average() { return m_average; }
26
27   void setMin(int n) { m_min = n; }
28   int min() { return m_min; }
29
30   void setMax(int n) { m_max = n; }
31   int max() { return m_max; }
32
33   void setBirdies(int n) { m_birdies = n; }
34   int birdies() { return m_birdies; }
35
36   void setPars(int n) { m_pars = n; }
37   int pars() { return m_pars; }
38
39   void setBogeys(int n) { m_bogeys = n; }
40   int bogeys() { return m_bogeys; }
41
42   void setMore(int n) { m_more = n; }
43   int more() { return m_more; }
44
45  private:
46
47   int m_year;
48   int m_rounds;
49   int m_average;
50   int m_min;
51   int m_max;
52   int m_birdies;
53   int m_pars;
54   int m_bogeys;
55   int m_more;
56 };
57
58 class StatModel : public QAbstractTableModel
59 {
60   Q_OBJECT
61
62 public:
63   StatModel(QList<Club *> &clubList, QList<Score *> &scoreList);
64
65   int rowCount(const QModelIndex & parent) const;
66   int columnCount(const QModelIndex & parent) const;
67   QVariant data(const QModelIndex & index, int role) const;
68   QVariant headerData(int section, Qt::Orientation orientation, int role) const;
69
70
71  private:
72
73   Course *findCourse(const QString &clubName, 
74                      const QString &courseName);
75   
76   enum { ROWS = 8, COLS = 4 };
77   enum { ROW_ROUNDS = 0, 
78          ROW_AVERAGE, 
79          ROW_MIN, 
80          ROW_MAX, 
81          ROW_BIRDIE, 
82          ROW_PAR, 
83          ROW_BOGEY, 
84          ROW_MORE
85   };
86   enum { COL_TOTAL = 0, 
87          COL_1ST_YEAR, // Latest year
88          COL_2ND_YEAR, // One before latest
89          COL_3RD_YEAR  // Two before latest
90   };
91
92
93   QList<Club *> &clubList;
94   QList<Score *> &scoreList;
95
96   QList<StatItem *> stat;
97
98   void update();
99 };