itom
Loading...
Searching...
No Matches
timerModel.h
1/* ********************************************************************
2 itom software
3 URL: http://www.uni-stuttgart.de/ito
4 Copyright (C) 2020, Institut für Technische Optik (ITO),
5 Universität 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
38namespace ito
39{
40
41class TimerModel : public QAbstractItemModel
42{
43 Q_OBJECT
44
45public:
46 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
63protected:
64 QVariant headerData(int section, Qt::Orientation orientation, int role) const;
65
66 void timerEvent(QTimerEvent *ev);
67
68private:
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;
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
94private Q_SLOTS:
95 void timerDestroyed(QObject *timer);
96};
97
98} //end namespace ito
model for management of all timer objects. This model will be is used as model for the view in the ti...
Definition timerModel.h:42
bool cacheItem(TimerItem &item)
Definition timerModel.cpp:272
int rowCount(const QModelIndex &parent=QModelIndex()) const
counts number of bookmarks in this model
Definition timerModel.cpp:61
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
returns QModelIndex for given row and column
Definition timerModel.cpp:152
int columnCount(const QModelIndex &parent=QModelIndex()) const
counts number of columns in this model (corresponds to number of header-elements)
Definition timerModel.cpp:71
TimerModel()
constructor
Definition timerModel.cpp:41
~TimerModel()
destructor
Definition timerModel.cpp:52
QModelIndex parent(const QModelIndex &index) const
returns parent of given QModelIndex
Definition timerModel.cpp:174
QVariant data(const QModelIndex &index, int role) const
overwritten data method of QAbstractItemModel
Definition timerModel.cpp:84
QVariant headerData(int section, Qt::Orientation orientation, int role) const
returns header element at given position
Definition timerModel.cpp:187
Definition apiFunctionsGraph.cpp:40
item of TimerModel
Definition timerModel.h:74
QString name
optional name of the name, can also be an empty string
Definition timerModel.h:77
bool started
cache value
Definition timerModel.h:78
bool singleShot
cache value
Definition timerModel.h:80
int timerId
cache value
Definition timerModel.h:81
int interval
cache value
Definition timerModel.h:79