Main repository
Revision | fa3a7abf7be9b06fa3d7e4452ac4fec0c4986970 (tree) |
---|---|
Time | 2022-06-28 02:16:44 |
Author | Jaime Marquínez Ferrándiz <jaime.marquinez.ferrandiz@fast...> |
Commiter | Jaime Marquínez Ferrándiz |
When editing a task we only save it once and we reload the information from taskwarrior
@@ -11,11 +11,11 @@ | ||
11 | 11 | Task::Task(QJsonObject jsonObj, QObject *parent) : QObject(parent) |
12 | 12 | { |
13 | 13 | this->m_jsonObj = jsonObj; |
14 | + this->_hasUnsavedChanges = false; | |
14 | 15 | } |
15 | 16 | |
16 | -Task::Task(QObject *parent) : QObject(parent) | |
17 | +Task::Task(QObject *parent) : Task(QJsonObject(), parent) | |
17 | 18 | { |
18 | - this->m_jsonObj = QJsonObject(); | |
19 | 19 | } |
20 | 20 | |
21 | 21 | QJsonObject Task::toJSON() |
@@ -69,6 +69,7 @@ | ||
69 | 69 | void setTags(QStringList tags); |
70 | 70 | bool Running(); |
71 | 71 | QList<TaskAnnotation> Annotations(); |
72 | + bool _hasUnsavedChanges; | |
72 | 73 | signals: |
73 | 74 | |
74 | 75 | public slots: |
@@ -37,18 +37,14 @@ | ||
37 | 37 | process->setArguments(QStringList() << "export"); |
38 | 38 | process->start(); |
39 | 39 | process->waitForFinished(); |
40 | - QByteArray output = process->readAllStandardOutput(); | |
41 | - QJsonDocument jsonDoc = QJsonDocument::fromJson(output); | |
42 | - QJsonArray tasksArray = jsonDoc.array(); | |
40 | + auto newTasks = this->readTasksFromOutput(process); | |
43 | 41 | qDeleteAll(tasks.begin(), tasks.end()); |
44 | 42 | tasks.clear(); |
45 | 43 | m_projects.clear(); |
46 | 44 | m_projects.insert(""); // No project |
47 | 45 | m_tags.clear(); |
48 | 46 | m_tags.insert(""); // No tag |
49 | - foreach (QJsonValue t, tasksArray) { | |
50 | - Task *task = new Task(t.toObject(), this); | |
51 | - | |
47 | + foreach (Task *task, newTasks) { | |
52 | 48 | m_projects.insert(task->Project()); |
53 | 49 | foreach(QString tag, task->Tags()) |
54 | 50 | { |
@@ -64,7 +60,7 @@ | ||
64 | 60 | { |
65 | 61 | tasks.append(task); |
66 | 62 | } else { |
67 | - delete task; | |
63 | + task->deleteLater(); | |
68 | 64 | } |
69 | 65 | } |
70 | 66 | process->deleteLater(); |
@@ -78,6 +74,19 @@ | ||
78 | 74 | return; |
79 | 75 | } |
80 | 76 | |
77 | +QList<Task*> TasksItemModel::readTasksFromOutput(QProcess *process) | |
78 | +{ | |
79 | + QByteArray output = process->readAllStandardOutput(); | |
80 | + QJsonDocument jsonDoc = QJsonDocument::fromJson(output); | |
81 | + QJsonArray tasksArray = jsonDoc.array(); | |
82 | + QList<Task*> result; | |
83 | + foreach (QJsonValue t, tasksArray) { | |
84 | + result.append(new Task(t.toObject(), this)); | |
85 | + } | |
86 | + | |
87 | + return result; | |
88 | +} | |
89 | + | |
81 | 90 | void TasksItemModel::ReloadTasks() |
82 | 91 | { |
83 | 92 | emit layoutAboutToBeChanged(); |
@@ -109,6 +118,13 @@ | ||
109 | 118 | } |
110 | 119 | } |
111 | 120 | process->deleteLater(); |
121 | + | |
122 | + auto exportProc = this->runCommandOnTask(task, QStringList("export")); | |
123 | + auto newTask = this->readTasksFromOutput(exportProc).first(); | |
124 | + auto index = this->tasks.indexOf(task); | |
125 | + this->tasks.replace(index, newTask); | |
126 | + emit dataChanged(this->createIndex(index, 0), this->createIndex(index, TaskModelIndex::_LAST_INDEX)); | |
127 | + exportProc->deleteLater(); | |
112 | 128 | // TODO: check for errors |
113 | 129 | return; |
114 | 130 | } |
@@ -357,7 +373,7 @@ | ||
357 | 373 | default: |
358 | 374 | return false; |
359 | 375 | } |
360 | - SaveTask(task); | |
376 | + task->_hasUnsavedChanges = true; | |
361 | 377 | emit dataChanged(index, index); |
362 | 378 | return true; |
363 | 379 | } |
@@ -485,3 +501,15 @@ | ||
485 | 501 | return KFormat().formatRelativeDateTime(date, format); |
486 | 502 | } |
487 | 503 | } |
504 | + | |
505 | +bool TasksItemModel::submit() | |
506 | +{ | |
507 | + foreach(Task *task, this->tasks) | |
508 | + { | |
509 | + if (task->_hasUnsavedChanges) | |
510 | + { | |
511 | + this->SaveTask(task); | |
512 | + } | |
513 | + } | |
514 | + return true; | |
515 | +} |
@@ -70,10 +70,12 @@ | ||
70 | 70 | QModelIndex newTask(); |
71 | 71 | |
72 | 72 | Q_INVOKABLE QString formatRelativeDateTime(QDateTime date, QLocale::FormatType format = QLocale::ShortFormat) const; |
73 | + bool submit(); | |
73 | 74 | signals: |
74 | 75 | void pendingTasksCountChanged(); |
75 | 76 | private: |
76 | 77 | QProcess* runCommandOnTask(Task *task, QStringList arguments); |
78 | + QList<Task*> readTasksFromOutput(QProcess *process); | |
77 | 79 | |
78 | 80 | QList<Task*> tasks; |
79 | 81 | QSet<QString> m_projects; |
@@ -298,107 +298,107 @@ | ||
298 | 298 | <context> |
299 | 299 | <name>TasksItemModel</name> |
300 | 300 | <message> |
301 | - <location filename="../lib/tasksitemmodel.cpp" line="208"/> | |
301 | + <location filename="../lib/tasksitemmodel.cpp" line="224"/> | |
302 | 302 | <source>Completed</source> |
303 | 303 | <translation>Completada</translation> |
304 | 304 | </message> |
305 | 305 | <message> |
306 | - <location filename="../lib/tasksitemmodel.cpp" line="210"/> | |
306 | + <location filename="../lib/tasksitemmodel.cpp" line="226"/> | |
307 | 307 | <source>Pending</source> |
308 | 308 | <translation>Pendiente</translation> |
309 | 309 | </message> |
310 | 310 | <message> |
311 | - <location filename="../lib/tasksitemmodel.cpp" line="212"/> | |
311 | + <location filename="../lib/tasksitemmodel.cpp" line="228"/> | |
312 | 312 | <source>Deleted</source> |
313 | 313 | <translation>Eliminada</translation> |
314 | 314 | </message> |
315 | 315 | <message> |
316 | - <location filename="../lib/tasksitemmodel.cpp" line="214"/> | |
316 | + <location filename="../lib/tasksitemmodel.cpp" line="230"/> | |
317 | 317 | <source>Waiting</source> |
318 | 318 | <translation>Esperando</translation> |
319 | 319 | </message> |
320 | 320 | <message> |
321 | - <location filename="../lib/tasksitemmodel.cpp" line="216"/> | |
321 | + <location filename="../lib/tasksitemmodel.cpp" line="232"/> | |
322 | 322 | <source>Unknown status</source> |
323 | 323 | <translation>Estado desconocido</translation> |
324 | 324 | </message> |
325 | 325 | <message> |
326 | - <location filename="../lib/tasksitemmodel.cpp" line="231"/> | |
326 | + <location filename="../lib/tasksitemmodel.cpp" line="247"/> | |
327 | 327 | <source>No priority</source> |
328 | 328 | <translation>Sin prioridad</translation> |
329 | 329 | </message> |
330 | 330 | <message> |
331 | - <location filename="../lib/tasksitemmodel.cpp" line="233"/> | |
331 | + <location filename="../lib/tasksitemmodel.cpp" line="249"/> | |
332 | 332 | <source>Low</source> |
333 | 333 | <translation>Baja</translation> |
334 | 334 | </message> |
335 | 335 | <message> |
336 | - <location filename="../lib/tasksitemmodel.cpp" line="235"/> | |
336 | + <location filename="../lib/tasksitemmodel.cpp" line="251"/> | |
337 | 337 | <source>Medium</source> |
338 | 338 | <translation>Media</translation> |
339 | 339 | </message> |
340 | 340 | <message> |
341 | - <location filename="../lib/tasksitemmodel.cpp" line="237"/> | |
341 | + <location filename="../lib/tasksitemmodel.cpp" line="253"/> | |
342 | 342 | <source>High</source> |
343 | 343 | <translation>Alta</translation> |
344 | 344 | </message> |
345 | 345 | <message> |
346 | - <location filename="../lib/tasksitemmodel.cpp" line="300"/> | |
346 | + <location filename="../lib/tasksitemmodel.cpp" line="316"/> | |
347 | 347 | <source>Id</source> |
348 | 348 | <translation>Id</translation> |
349 | 349 | </message> |
350 | 350 | <message> |
351 | - <location filename="../lib/tasksitemmodel.cpp" line="302"/> | |
351 | + <location filename="../lib/tasksitemmodel.cpp" line="318"/> | |
352 | 352 | <source>Description</source> |
353 | 353 | <translation>Descripción</translation> |
354 | 354 | </message> |
355 | 355 | <message> |
356 | - <location filename="../lib/tasksitemmodel.cpp" line="304"/> | |
356 | + <location filename="../lib/tasksitemmodel.cpp" line="320"/> | |
357 | 357 | <source>Due date</source> |
358 | 358 | <translation>Fecha límite</translation> |
359 | 359 | </message> |
360 | 360 | <message> |
361 | - <location filename="../lib/tasksitemmodel.cpp" line="306"/> | |
361 | + <location filename="../lib/tasksitemmodel.cpp" line="322"/> | |
362 | 362 | <source>Urgency</source> |
363 | 363 | <translation>Urgencia</translation> |
364 | 364 | </message> |
365 | 365 | <message> |
366 | - <location filename="../lib/tasksitemmodel.cpp" line="308"/> | |
366 | + <location filename="../lib/tasksitemmodel.cpp" line="324"/> | |
367 | 367 | <source>UUID</source> |
368 | 368 | <translation>UUID</translation> |
369 | 369 | </message> |
370 | 370 | <message> |
371 | - <location filename="../lib/tasksitemmodel.cpp" line="310"/> | |
371 | + <location filename="../lib/tasksitemmodel.cpp" line="326"/> | |
372 | 372 | <source>Status</source> |
373 | 373 | <translation>Estado</translation> |
374 | 374 | </message> |
375 | 375 | <message> |
376 | - <location filename="../lib/tasksitemmodel.cpp" line="312"/> | |
376 | + <location filename="../lib/tasksitemmodel.cpp" line="328"/> | |
377 | 377 | <source>Priority</source> |
378 | 378 | <translation>Prioridad</translation> |
379 | 379 | </message> |
380 | 380 | <message> |
381 | - <location filename="../lib/tasksitemmodel.cpp" line="314"/> | |
381 | + <location filename="../lib/tasksitemmodel.cpp" line="330"/> | |
382 | 382 | <source>Wait until</source> |
383 | 383 | <translation>Esperar hasta</translation> |
384 | 384 | </message> |
385 | 385 | <message> |
386 | - <location filename="../lib/tasksitemmodel.cpp" line="316"/> | |
386 | + <location filename="../lib/tasksitemmodel.cpp" line="332"/> | |
387 | 387 | <source>Project</source> |
388 | 388 | <translation>Proyecto</translation> |
389 | 389 | </message> |
390 | 390 | <message> |
391 | - <location filename="../lib/tasksitemmodel.cpp" line="318"/> | |
391 | + <location filename="../lib/tasksitemmodel.cpp" line="334"/> | |
392 | 392 | <source>Tags</source> |
393 | 393 | <translation>Etiquetas</translation> |
394 | 394 | </message> |
395 | 395 | <message> |
396 | - <location filename="../lib/tasksitemmodel.cpp" line="320"/> | |
396 | + <location filename="../lib/tasksitemmodel.cpp" line="336"/> | |
397 | 397 | <source>Annotations</source> |
398 | 398 | <translation>Anotaciones</translation> |
399 | 399 | </message> |
400 | 400 | <message> |
401 | - <location filename="../lib/tasksitemmodel.cpp" line="322"/> | |
401 | + <location filename="../lib/tasksitemmodel.cpp" line="338"/> | |
402 | 402 | <source>Entry date</source> |
403 | 403 | <translation>Fecha de introducción</translation> |
404 | 404 | </message> |