5 #include "branchitem.h"
9 Task::Task(TaskModel *tm)
11 // qDebug()<<"Constr. Task";
13 awake = Task::WideAwake;
18 date_creation = QDateTime::currentDateTime();
23 // qDebug()<<"Destr. Task";
25 branch->setTask(NULL);
28 void Task::setModel(TaskModel *tm) { model = tm; }
30 void Task::cycleStatus(bool reverse)
43 setStatus((Task::Status)i);
46 branch->updateTaskFlag();
49 void Task::setStatus(const QString &s)
51 if (s == "NotStarted")
52 setStatus(NotStarted);
55 else if (s == "Finished")
58 qWarning() << "Task::setStatus Unknown value: " << s;
61 void Task::setStatus(Status s)
67 branch->updateTaskFlag();
70 Task::Status Task::getStatus() { return status; }
72 QString Task::getStatusString()
85 QString Task::getIconString()
99 s = "status:undefined";
101 if (status != Finished)
115 void Task::setAwake(const QString &s)
119 else if (s == "Morning")
121 else if (s == "WideAwake")
124 qWarning() << "Task::setAwake Unknown value: " << s;
127 void Task::setAwake(Task::Awake a)
132 branch->updateTaskFlag();
136 Task::Awake Task::getAwake() { return awake; }
138 QString Task::getAwakeString()
140 switch (getAwake()) {
151 bool Task::updateAwake()
153 qint64 secs = getSecsSleep();
156 if (awake == Task::Sleeping) {
157 setAwake(Task::Morning);
162 if (awake != Task::Sleeping) {
163 setAwake(Task::Sleeping);
170 void Task::setPriority(int p) { prio = p; }
172 int Task::getPriority() { return prio; }
174 int Task::getAgeCreation()
176 return date_creation.daysTo(QDateTime::currentDateTime());
179 int Task::getAgeModification()
181 if (date_modification.isValid())
182 return date_modification.daysTo(QDateTime::currentDateTime());
184 return getAgeCreation();
187 void Task::setDateCreation(const QString &s)
189 date_creation = QDateTime().fromString(s, Qt::ISODate);
192 QDateTime Task::getDateCreation() { return date_creation; }
194 void Task::setDateModification()
196 date_modification = QDateTime::currentDateTime();
199 void Task::setDateModification(const QString &s)
201 date_modification = QDateTime().fromString(s, Qt::ISODate);
204 QDateTime Task::getDateModification() { return date_modification; }
206 bool Task::setDaysSleep(qint64 n)
208 return setDateSleep(QDate::currentDate().addDays(n).toString(Qt::ISODate));
211 bool Task::setHoursSleep(qint64 n)
214 QDateTime::currentDateTime().addSecs(n * 3600).toString(Qt::ISODate));
217 bool Task::setSecsSleep(qint64 n)
222 QDateTime::currentDateTime().addSecs(n).toString(Qt::ISODate));
225 bool Task::setDateSleep(const QString &s)
227 if (setDateSleep(QDateTime().fromString(s, Qt::ISODate)))
229 else if (setDateSleep(QDateTime().fromString(s, Qt::TextDate)))
231 else if (setDateSleep(
232 QDateTime().fromString(s, Qt::DefaultLocaleShortDate)))
234 else if (setDateSleep(QDateTime().fromString(s, Qt::DefaultLocaleLongDate)))
240 bool Task::setDateSleep(const QDateTime &d)
250 qint64 Task::getDaysSleep()
253 if (date_sleep.isValid())
254 d = QDateTime::currentDateTime().daysTo(date_sleep);
256 // qWarning() << "Task::getDaysSleep date_sleep is invalid for branch "
257 // << branch->getHeadingPlain();
263 qint64 Task::getSecsSleep()
265 qint64 d = 0; // Meaning: No sleep time set so far
266 if (date_sleep.isValid())
267 d = QDateTime::currentDateTime().secsTo(date_sleep);
271 QDateTime Task::getSleep() { return date_sleep; }
273 void Task::setPriorityDelta(const int &n) { prio_delta = n; }
275 int Task::getPriorityDelta() { return prio_delta; }
277 void Task::setBranch(BranchItem *bi)
280 mapName = bi->getModel()->getMapName();
283 BranchItem *Task::getBranch() { return branch; }
285 QString Task::getName()
288 return branch->getHeadingPlain();
290 qWarning() << "Task::getName no branch!";
295 QString Task::getMapName() { return mapName; }
297 QString Task::saveToDir()
300 if (date_sleep.isValid())
301 sleepAttr = attribut("date_sleep", date_sleep.toString(Qt::ISODate));
303 sleepAttr = attribut("date_sleep", "2018-01-01T00:00:00");
305 // Experimental: Also output priority based on arrow flags for external
309 if (branch->hasActiveFlag("2arrow-up"))
310 prioAttr = attribut("prio", "2");
311 if (branch->hasActiveFlag("arrow-up"))
312 prioAttr = attribut("prio", "1");
315 QString prioDeltaAttr;
317 prioDeltaAttr = attribut("prio_delta", QString("%1").arg(prio_delta));
318 return singleElement(
320 attribut("status", getStatusString()) +
321 attribut("awake", getAwakeString()) +
322 attribut("date_creation", date_creation.toString(Qt::ISODate)) +
323 attribut("date_modification",
324 date_modification.toString(Qt::ISODate)) +
325 prioDeltaAttr + sleepAttr + prioAttr);