This repository was archived by the owner on Sep 11, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlistcontroller.cpp
More file actions
212 lines (191 loc) · 6.61 KB
/
listcontroller.cpp
File metadata and controls
212 lines (191 loc) · 6.61 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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
/****************************************************************************
**
** Copyright (C) 2011-2012 Jan M. Binder, Simeon Voelkel
** Contact: jan.binder@sfz-bw.de, simeon.voelkel@sfz-bw.de
**
** $QT_BEGIN_LICENSE:GPL$
** GNU General Public License Usage
** This file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met: http://www.gnu.org/copyleft/gpl.html.
** $QT_END_LICENSE$
**
****************************************************************************/
#include "listcontroller.h"
#include <QFile>
#include <QStringList>
#include <QTextStream>
#include <QBrush>
ListController::ListController(QObject *parent) :
QObject(parent)
{
stlm = new StageListModel();
currentIndex = 0;
}
ListController::~ListController(){
delete stlm;
}
void ListController::forward(){
QTime tmpt = QTime(0,0,0);
if(currentIndex < stlm->rowCount()-1){
currentIndex++;
stlm->setHighlightedRow(currentIndex);
Stage st = stlm->getList().value(currentIndex);
Stage lastst = stlm->getList().value(currentIndex-1);
if (!lastst.carry) {
if (lastst.ocarry) {
emit getElapsedOverTime();
}
else {
emit resetTime();
}
}
emit allowedTimeChanged(tmpt.msecsTo(st.duration));
emit overTimeChanged(tmpt.msecsTo(st.overtime));
emit stageNameChanged(st.name);
emit roomClockChanged(st.roomclock);
} else if (currentIndex >= stlm->rowCount()-1){
emit endOfStage();
currentIndex = stlm->rowCount()-1;
}
}
void ListController::backward(){
QTime tmpt = QTime(0,0,0);
if(currentIndex > 0){
currentIndex--;
stlm->setHighlightedRow(currentIndex);
Stage st = stlm->getList().value(currentIndex);
if (!st.carry) emit resetTime();
emit allowedTimeChanged(tmpt.msecsTo(st.duration));
emit overTimeChanged(tmpt.msecsTo(st.overtime));
emit stageNameChanged(st.name);
emit roomClockChanged(st.roomclock);
} else if (currentIndex <= 0){
emit endOfStage();
currentIndex = 0;
}
}
void ListController::handleOvertime(int over){
Stage st = stlm->getList().value(currentIndex);
if (!st.autoadvance)
return;
forward();
if (!st.carry && st.ocarry){
emit elapsedTimeChanged(over);
}
}
void ListController::setElapsedOverTime(int over){
if (over < 0) over = 0;
emit elapsedTimeChanged(over);
}
int ListController::loadListFromFile(QString path){
QList<Stage> tmplist;
QFile file(path);
StageListModel* oldstlm;
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
return 1;
QTextStream in(&file);
while (!in.atEnd()) {
QTime tmpt = QTime(0,0,0);
QString line = in.readLine();
QStringList sl = line.split(QChar('\t'));
if(sl.size() == 3){
tmplist.append( Stage(
tmpt.addMSecs(sl.value(0).toInt()),
tmpt.addMSecs(sl.value(1).toInt()),
sl.value(2))
);
}else if(sl.size() == 4){
tmplist.append( Stage(
tmpt.addMSecs(sl.value(0).toInt()),
tmpt.addMSecs(sl.value(1).toInt()),
sl.value(2),
(sl.value(3).toUInt() > 0 ? true : false)
) );
}else if(sl.size() >= 7){
tmplist.append( Stage(
tmpt.addMSecs(sl.value(0).toInt()),
tmpt.addMSecs(sl.value(1).toInt()),
sl.value(2),
(sl.value(3).toUInt() > 0 ? true : false),
(sl.value(4).toUInt() > 0 ? true : false),
(sl.value(5).toUInt() > 0 ? true : false),
(sl.value(6).toUInt() > 0 ? true : false)
) );
}else{
// We read a comment line
}
}
oldstlm = stlm;
stlm = new StageListModel(tmplist);
emit modelChanged(stlm);
delete oldstlm;
file.close();
QTime tmpt = QTime(0,0,0);
if(currentIndex < stlm->rowCount()-1){
Stage st = stlm->getList().value(currentIndex);
emit allowedTimeChanged(tmpt.msecsTo(st.duration));
emit overTimeChanged(tmpt.msecsTo(st.overtime));
emit stageNameChanged(st.name);
emit roomClockChanged(st.roomclock);
}
return 0;
}
int ListController::saveListToFile(QString path){
QTime tmpt = QTime(0,0,0);
QList<Stage> tmplist = stlm->getList();
QFile file(path);
if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
return 1;
QTextStream out(&file);
for(QList<Stage>::iterator t = tmplist.begin(); t != tmplist.end(); t++){
out << tmpt.msecsTo(t->duration);
out << "\t" << tmpt.msecsTo(t->overtime);
out << "\t" << t->name;
out << "\t" << (unsigned int)(t->autoadvance ? 1 : 0);
out << "\t" << (unsigned int)(t->carry ? 1 : 0);
out << "\t" << (unsigned int)(t->ocarry ? 1 : 0);
out << "\t" << (unsigned int)(t->roomclock ? 1 : 0);
out << "\n";
}
file.close();
return 0;
}
QAbstractTableModel* ListController::getModel(){
return stlm;
}
void ListController::add(){
stlm->insertRows(stlm->rowCount(),1);
}
void ListController::del(QModelIndex ind){
stlm->removeRows(ind.row(),1);
}
int ListController::getCurrentIndex(){
return currentIndex;
}
int ListController::getMaxIndex(){
return stlm->rowCount()-1;
}
void ListController::setCurrentIndex(int currentIndex){
QTime tmpt = QTime(0,0,0);
if(currentIndex >= 0 && currentIndex <= stlm->rowCount()-1){
this->currentIndex = currentIndex;
stlm->setHighlightedRow(currentIndex);
Stage st = stlm->getList().value(currentIndex);
emit allowedTimeChanged(tmpt.msecsTo(st.duration));
emit overTimeChanged(tmpt.msecsTo(st.overtime));
emit stageNameChanged(st.name);
emit roomClockChanged(st.roomclock);
}
}
void ListController::checkAutoStart(){
if(currentIndex >= 0 && currentIndex <= stlm->rowCount()-1){
Stage st = stlm->getList().value(currentIndex);
if(st.roomclock){
forward();
}
}
}