Web page: current version no longer called "new"
[kitchenalert] / src / currentalertstablemodel.h
1 /**************************************************************************
2         KitchenAlert
3
4         Copyright (C) 2010  Heli Hyvättinen
5
6         This file is part of KitchenAlert.
7
8         Kitchen Alert is free software: you can redistribute it and/or modify
9         it under the terms of the GNU General Public License as published by
10         the Free Software Foundation, either version 3 of the License, or
11         (at your option) any later version.
12
13         This program is distributed in the hope that it will be useful,
14         but WITHOUT ANY WARRANTY; without even the implied warranty of
15         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16         GNU General Public License for more details.
17
18         You should have received a copy of the GNU General Public License
19         along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
21 **************************************************************************/
22
23
24
25
26
27 #ifndef CURRENTALERTSTABLEMODEL_H
28 #define CURRENTALERTSTABLEMODEL_H
29
30 #include <QAbstractTableModel>
31 #include <QMainWindow>
32 #include "timer.h"
33
34
35 /*! Class that contains the model that holds the timers'
36
37   @author Heli Hyvättinen
38   @date 2011-04-05
39   @version 0.2.1
40
41 Class that contains the model that holds the timers
42
43 */
44
45
46 class CurrentAlertsTableModel : public QAbstractTableModel
47 {
48     Q_OBJECT
49 public:
50     explicit CurrentAlertsTableModel(QObject *parent = 0);
51
52     /*!
53     Returns the number of rows in the model.
54     Used by the view.
55     */
56     int rowCount(const QModelIndex &parent) const;
57
58     /*!
59       Returns the (fixed) number of columns in the model.
60       Used by the view.
61     */
62     int columnCount(const QModelIndex &parent) const;
63
64     /*!
65     Returns the queried contents of the cell
66     Used by the view.
67     */
68     QVariant data(const QModelIndex &index, int role) const;
69
70     /*!
71       Returns the queried header data.
72       As no headers are wanted, it always returns an empty QVariant.
73       Used by the view.
74       */
75     QVariant headerData(int section, Qt::Orientation orientation, int role) const;
76
77     /*!
78       Returns the index in the model of the given timer
79       */
80     QModelIndex giveIndexForTimer(Timer * ptimer);
81
82     /*!
83       Returns whether the timer in the given position is currently alerting.
84       @param index Any cell from the row of the alert is good here.
85       */
86     bool isThisTimerAlerting(QModelIndex index);
87
88
89     /*! Saves a timer to a file
90       @param index The index of the timer to be saved. Any cell from the row of the timer is good here.
91       @param filename The name of the file to which the timer is to be saved
92     */
93     bool saveTimer(QModelIndex index,QString filename);
94
95
96 signals:
97
98 public slots:
99
100     /*!
101        Adds the timers to the model
102     @param timers List of timers to be added
103     @param startImmediately If true, the timers will be started after adding to the model.
104     */
105     void addTimers(QList <Timer *> timers, bool startImmediately = true);
106
107     /*!
108      Tells the view to refresh all information in the time and status columns.
109      (The time and status change without user inervention unlike the alert text and thus
110      need to be refreshed.)
111       */
112     void refreshTimeAndStatusColumns ();
113
114     /*!
115       Passes the start command to the timer in the given index.
116       @param index Any cell from the row of the alert is good here.
117       */
118     void startTimer(QModelIndex index);
119
120     /*!
121       Passes the snooze command to the timer in the given index.
122       @param index Any cell from the row of the alert is good here.
123       */
124     void snoozeTimer(QModelIndex index);
125
126
127     /*!
128       Passes the stop command to the timer in the given index.
129       @param index Any cell from the row of the alert is good here.
130       */
131     void stopTimer(QModelIndex index);
132
133 /*!
134 Sets whether the view should be kept up to date.
135 */
136     void setUpdateViewOnChanges(bool update);
137
138 /*!
139   Removes a timer from the model
140   */
141
142     void removeTimer(QModelIndex index);
143
144
145
146 private:
147     QList <Timer * > currentTimers_; /*! Holds the timers */
148
149     static const int numberOfColumns_ = 3; /*! The fixed number of columns in the model */
150     static const int alertTextColumnNumber_ = 0; /*! Tells which column contains the alert text */
151     static const int timeRemainingColumnNumber_ = 1; /*! Tells which column contains the time remaining until alert */
152     static const int statusColumnNumber_ = 2; /*! Tells which column contains status information, such as that the timer is alerting  */
153
154
155
156     bool updateViewOnChanges_; /*! Keeps track on whether the view should be kept up to date. */
157
158 };
159
160 #endif // CURRENTALERTSTABLEMODEL_H