-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvisibleregimemodel.cpp
More file actions
189 lines (175 loc) · 7.18 KB
/
Copy pathvisibleregimemodel.cpp
File metadata and controls
189 lines (175 loc) · 7.18 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#include "visibleregimemodel.h"
VisibleRegimeModel::VisibleRegimeModel(QObject *parent)
: QAbstractListModel(parent)
{
}
int VisibleRegimeModel::rowCount(const QModelIndex &parent) const
{
if (parent.isValid())
return 0;
return m_repeatEntries.count();
}
QVariant VisibleRegimeModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid() || index.row() >= m_repeatEntries.count())
return QVariant();
const RepeatEntry &entry = m_repeatEntries.at(index.row());
const Regime ®ime = entry.regime;
switch (role) {
case NameRole:
return regime.m_name;
case MaxTimeRole:
// Include condition time in the displayed max time
{
int conditionTimeInSeconds = 0;
if (regime.m_condition.type == "time" || regime.m_condition.type == "temp") {
conditionTimeInSeconds = regime.m_condition.time * 60; // Convert minutes to seconds
}
return regime.m_maxTime + conditionTimeInSeconds;
}
case RepeatCountRole:
// Return appropriate repeat count: cycle repeat for cycles, individual repeat for regimes
if (regime.m_cycleId != -1) {
return regime.m_cycleRepeat;
}
return regime.m_repeatCount;
case StateRole:
return QVariant::fromValue(regime.m_state);
case TimePassedInSecondsRole:
return regime.m_timePassedInSeconds;
case CycleIdRole:
return regime.m_cycleId;
case IsCycleRole:
return regime.m_cycleId != -1;
case ConditionTimeRole:
{
int conditionTimeInSeconds = 0;
if (regime.m_condition.type == "time" || regime.m_condition.type == "temp") {
conditionTimeInSeconds = regime.m_condition.time * 60; // Convert minutes to seconds
}
return conditionTimeInSeconds;
}
case RegimeExecutionTimeRole:
return regime.m_maxTime; // Pure regime execution time without condition
case CurrentRepeatRole:
return regime.m_currentRepeat;
case ConditionCompletedRole:
// For this specific repeat entry, check if it's completed
if (entry.repeatIndex < regime.m_currentRepeat) {
return true; // Past repeats are completed
} else if (entry.repeatIndex == regime.m_currentRepeat) {
return regime.m_conditionCompleted; // Current repeat status
}
return false; // Future repeats not completed
case ConditionTimePassedRole:
// For this specific repeat entry, return appropriate progress
if (entry.repeatIndex < regime.m_currentRepeat) {
// Past repeats: show full condition time
int conditionTimeInSeconds = 0;
if (regime.m_condition.type == "time" || regime.m_condition.type == "temp") {
conditionTimeInSeconds = regime.m_condition.time * 60;
}
return conditionTimeInSeconds;
} else if (entry.repeatIndex == regime.m_currentRepeat) {
return regime.m_conditionTimePassed; // Current repeat progress
}
return 0; // Future repeats have no progress
case RegimeTimePassedRole:
// For this specific repeat entry, return appropriate progress
if (entry.repeatIndex < regime.m_currentRepeat) {
return regime.m_maxTime; // Past repeats: show full execution time
} else if (entry.repeatIndex == regime.m_currentRepeat) {
return regime.m_regimeTimePassed; // Current repeat progress
}
return 0; // Future repeats have no progress
case RepeatIndexRole:
return entry.repeatIndex;
case RegimeIndexRole:
return entry.regimeIndex;
case IsCycleEntryRole:
return entry.isCycleEntry;
case CycleRepeatIndexRole:
return entry.cycleRepeatIndex;
}
return QVariant();
}
QHash<int, QByteArray> VisibleRegimeModel::roleNames() const
{
return {
{ NameRole, "name" },
{ MaxTimeRole, "maxTime" },
{ RepeatCountRole, "repeatCount" },
{ StateRole, "state" },
{ TimePassedInSecondsRole, "timePassedInSeconds" },
{ CycleIdRole, "cycleId" },
{ IsCycleRole, "isCycle" },
{ ConditionTimeRole, "conditionTime" },
{ RegimeExecutionTimeRole, "regimeExecutionTime" },
{ CurrentRepeatRole, "currentRepeat" },
{ ConditionCompletedRole, "conditionCompleted" },
{ ConditionTimePassedRole, "conditionTimePassed" },
{ RegimeTimePassedRole, "regimeTimePassed" },
{ RepeatIndexRole, "repeatIndex" },
{ RegimeIndexRole, "regimeIndex" },
{ IsCycleEntryRole, "isCycleEntry" },
{ CycleRepeatIndexRole, "cycleRepeatIndex" }
};
}
void VisibleRegimeModel::setRegimes(const QList<Regime> ®imes)
{
beginResetModel();
expandRegimesToRepeats(regimes);
endResetModel();
}
void VisibleRegimeModel::expandRegimesToRepeats(const QList<Regime> ®imes)
{
m_repeatEntries.clear();
QSet<int> processedCycleIds;
for (int regimeIndex = 0; regimeIndex < regimes.count(); ++regimeIndex) {
const Regime ®ime = regimes.at(regimeIndex);
if (regime.m_cycleId != -1) {
if (!processedCycleIds.contains(regime.m_cycleId)) {
// This is the first regime of a new cycle
QList<int> cycleRegimeIndices;
for (int i = regimeIndex; i < regimes.count(); ++i) {
if (regimes.at(i).m_cycleId == regime.m_cycleId) {
cycleRegimeIndices.append(i);
}
}
for (int cycleRepeat = 0; cycleRepeat < regime.m_cycleRepeat; ++cycleRepeat) {
for (int cycleRegimeIndex : cycleRegimeIndices) {
const Regime &cycleRegime = regimes.at(cycleRegimeIndex);
// a cycle regime is a sequence of regimes that repeats
// so we need to add each repeat of the regime to the list
for (int repeat = 0; repeat < cycleRegime.m_repeatCount; ++repeat) {
RepeatEntry entry;
entry.regime = cycleRegime;
entry.repeatIndex = repeat;
entry.regimeIndex = cycleRegimeIndex;
entry.isCycleEntry = true;
entry.cycleRepeatIndex = cycleRepeat;
m_repeatEntries.append(entry);
}
}
}
processedCycleIds.insert(regime.m_cycleId);
}
} else {
// Individual regime - expand by repeat count
for (int repeat = 0; repeat < regime.m_repeatCount; ++repeat) {
RepeatEntry entry;
entry.regime = regime;
entry.repeatIndex = repeat;
entry.regimeIndex = regimeIndex;
entry.isCycleEntry = false;
entry.cycleRepeatIndex = 0;
m_repeatEntries.append(entry);
}
}
}
}
void VisibleRegimeModel::notifyTimelineUpdate()
{
// Emit signal to notify TimeProgressBar that timeline needs update
emit timelineUpdateRequired();
}