-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprototablemodel.h
More file actions
90 lines (74 loc) · 2.9 KB
/
Copy pathprototablemodel.h
File metadata and controls
90 lines (74 loc) · 2.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#pragma once
#include <QAbstractTableModel>
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
#include <QFile>
#include <QDir>
#include <QDebug>
#include <QMap>
#include "regime.h"
class ProtoTableModel : public QAbstractTableModel
{
Q_OBJECT
public:
explicit ProtoTableModel(QObject *parent = nullptr);
enum Role {
RegimeRole = Qt::UserRole + 1,
ConditionRole,
RepeatRole,
// Maximum time for the regime in minutes
MaxTimeRole,
CycleRowCountRole,
CycleStatusRole,
CycleRepeatRole,
StateRole,
// Time passed in seconds
TimePassedInSecondsRole,
RepeatsDoneRole,
RepeatsSkippedRole,
RepeatsErrorRole,
CycleIdRole,
CurrentRepeatRole,
ConditionCompletedRole,
ConditionTimePassedRole,
RegimeTimePassedRole
};
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
bool setData(const QModelIndex &index, const QVariant &value, int role) override;
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
bool moveRows(const QModelIndex &sourceParent, int sourceRow, int count, const QModelIndex &destinationParent, int destinationChild) override;
QHash<int, QByteArray> roleNames() const override;
Qt::ItemFlags flags(const QModelIndex &index) const override;
Q_INVOKABLE void setRegimes(const QList<Regime> ®imes);
Q_INVOKABLE QList<Regime> getRegimes() const;
Q_INVOKABLE void groupRows(QVariantList rows);
Q_INVOKABLE void ungroupRows(QVariantList rows);
Q_INVOKABLE QVariantList moveSelection(QVariantList rows, bool up);
Q_INVOKABLE void addRow(const QString ®imeName);
Q_INVOKABLE void deleteRows(QVariantList rows);
Q_INVOKABLE void clear();
Q_INVOKABLE bool isSelectionGroupable(QVariantList rows) const;
Q_INVOKABLE bool isSelectionUngroupable(QVariantList rows) const;
Q_INVOKABLE bool isMoveUpEnabled(QVariantList rows) const;
Q_INVOKABLE bool isMoveDownEnabled(QVariantList rows) const;
Q_INVOKABLE Regime getRegime(int row) const;
Q_INVOKABLE QVariantMap getRegimeAsVariantMap(int row) const;
Q_INVOKABLE QVariant get(int row, const QByteArray& roleName) const;
Q_INVOKABLE bool isAnyRegimeRunning() const;
public slots:
Q_INVOKABLE int getRowCount() { return m_regimes.count(); }
signals:
void selectionShouldBeCleared();
void totalTimeChanged();
private:
void updateCycleIds();
void checkAndUpdateRunningState();
int getBlockStart(QVariantList rows) const;
int getBlockEnd(QVariantList rows) const;
QList<Regime> m_regimes;
QStringList m_columnNames;
bool m_isAnyRegimeRunning = false;
};