itom  4.1.0
timerModel.h
1 /* ********************************************************************
2  itom software
3  URL: http://www.uni-stuttgart.de/ito
4  Copyright (C) 2020, Institut fuer Technische Optik (ITO),
5  Universitaet Stuttgart, Germany
6 
7  This file is part of itom.
8 
9  itom is free software; you can redistribute it and/or modify it
10  under the terms of the GNU Library General Public Licence as published by
11  the Free Software Foundation; either version 2 of the Licence, or (at
12  your option) any later version.
13 
14  itom is distributed in the hope that it will be useful, but
15  WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library
17  General Public Licence for more details.
18 
19  You should have received a copy of the GNU Library General Public License
20  along with itom. If not, see <http://www.gnu.org/licenses/>.
21 *********************************************************************** */
22 
23 #pragma once
24 
25 #include "../common/sharedStructures.h"
26 
27 #include <qabstractitemmodel.h>
28 #include <qlist.h>
29 #include <qicon.h>
30 #include <qstring.h>
31 #include <qobject.h>
32 #include <qsharedpointer.h>
33 #include <qtimer.h>
34 #include <qevent.h>
35 #include <qlist.h>
36 
37 
38 namespace ito
39 {
40 
41 class TimerModel : public QAbstractItemModel
42 {
43  Q_OBJECT
44 
45 public:
46  TimerModel();
47  ~TimerModel();
48 
49  QVariant data(const QModelIndex &index, int role) const;
50  QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
51  QModelIndex parent(const QModelIndex &index) const;
52  int rowCount(const QModelIndex &parent = QModelIndex()) const;
53  int columnCount(const QModelIndex &parent = QModelIndex()) const;
54 
55  void registerNewTimer(const QWeakPointer<QTimer>& timer, const QString &name);
56  void updateTimerData();
57  void autoUpdateModel(bool enabled);
58 
59  void timerStart(const QModelIndex &index);
60  void timerStop(const QModelIndex &index);
61  void timerStopAll();
62 
63 protected:
64  QVariant headerData(int section, Qt::Orientation orientation, int role) const;
65 
66  void timerEvent(QTimerEvent *ev);
67 
68 private:
70 
73  struct TimerItem
74  {
75  TimerItem() : started(false), interval(0), singleShot(false), timerId(-1) {}
76  QWeakPointer<QTimer> timer;
77  QString name;
78  bool started;
79  int interval;
80  bool singleShot;
81  int timerId;
82  };
83 
84  bool cacheItem(TimerItem &item);
85 
87  QList<TimerItem> m_timers;
88  int m_timerId;
89  int m_enableCount;
90  QIcon m_iconRunning;
91  QIcon m_iconStopped;
92  QIcon m_iconUnknown;
93 
94 private Q_SLOTS:
95  void timerDestroyed(QObject *timer);
96 };
97 
98 } //end namespace ito
bool cacheItem(TimerItem &item)
Definition: timerModel.cpp:273
model for management of all timer objects. This model will be is used as model for the view in the ti...
Definition: timerModel.h:41
QVariant headerData(int section, Qt::Orientation orientation, int role) const
returns header element at given position
Definition: timerModel.cpp:187
item of TimerModel
Definition: timerModel.h:73
int columnCount(const QModelIndex &parent=QModelIndex()) const
counts number of columns in this model (corresponds to number of header-elements) ...
Definition: timerModel.cpp:71
Definition: apiFunctionsGraph.cpp:39
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
returns QModelIndex for given row and column
Definition: timerModel.cpp:152
QString name
optional name of the name, can also be an empty string
Definition: timerModel.h:77
QVariant data(const QModelIndex &index, int role) const
overwritten data method of QAbstractItemModel
Definition: timerModel.cpp:84
int timerId
cache value
Definition: timerModel.h:81
QModelIndex parent(const QModelIndex &index) const
returns parent of given QModelIndex
Definition: timerModel.cpp:174
~TimerModel()
destructor
Definition: timerModel.cpp:52
int interval
cache value
Definition: timerModel.h:79
int rowCount(const QModelIndex &parent=QModelIndex()) const
counts number of bookmarks in this model
Definition: timerModel.cpp:61
bool started
cache value
Definition: timerModel.h:78
bool singleShot
cache value
Definition: timerModel.h:80
TimerModel()
constructor
Definition: timerModel.cpp:41