Changeset View
Changeset View
Standalone View
Standalone View
src/presentation/pagemodel.cpp
Show All 18 Lines | 1 | /* This file is part of Zanshin | |||
---|---|---|---|---|---|
19 | along with this program; if not, write to the Free Software | 19 | along with this program; if not, write to the Free Software | ||
20 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, | 20 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, | ||
21 | USA. | 21 | USA. | ||
22 | */ | 22 | */ | ||
23 | 23 | | |||
24 | 24 | | |||
25 | #include "pagemodel.h" | 25 | #include "pagemodel.h" | ||
26 | 26 | | |||
27 | #include "presentation/querytreemodel.h" | ||||
28 | | ||||
29 | #include <klocalizedstring.h> | ||||
30 | | ||||
27 | using namespace Presentation; | 31 | using namespace Presentation; | ||
28 | 32 | | |||
29 | PageModel::PageModel(QObject *parent) | 33 | PageModel::PageModel(QObject *parent) | ||
30 | : QObject(parent), | 34 | : QObject(parent), | ||
31 | m_centralListModel(nullptr) | 35 | m_centralListModel(nullptr) | ||
32 | { | 36 | { | ||
33 | } | 37 | } | ||
34 | 38 | | |||
35 | QAbstractItemModel *PageModel::centralListModel() | 39 | QAbstractItemModel *PageModel::centralListModel() | ||
36 | { | 40 | { | ||
37 | if (!m_centralListModel) | 41 | if (!m_centralListModel) | ||
38 | m_centralListModel = createCentralListModel(); | 42 | m_centralListModel = createCentralListModel(); | ||
39 | return m_centralListModel; | 43 | return m_centralListModel; | ||
40 | } | 44 | } | ||
45 | | ||||
46 | PageModel::TaskExtraDataPtr PageModel::fetchTaskExtraData(Domain::TaskQueries::Ptr taskQueries, | ||||
47 | const QModelIndex &index, const Domain::Task::Ptr &task) | ||||
48 | { | ||||
49 | TaskExtraDataPtr info = TaskExtraDataPtr::create(); | ||||
50 | if (index.parent().isValid()) { // children are in the same collection as their parent, so the same project | ||||
51 | info->childTask = true; | ||||
52 | return info; | ||||
53 | } | ||||
54 | | ||||
55 | info->projectQueryResult = taskQueries->findProject(task); | ||||
56 | if (info->projectQueryResult) { | ||||
57 | QPersistentModelIndex persistentIndex(index); | ||||
58 | info->projectQueryResult->addPostInsertHandler([persistentIndex](const Domain::Project::Ptr &, int) { | ||||
59 | // When a project was found (inserted into the result), update the rendering of the item | ||||
60 | auto model = const_cast<QAbstractItemModel *>(persistentIndex.model()); | ||||
61 | model->dataChanged(persistentIndex, persistentIndex); | ||||
62 | }); | ||||
63 | } | ||||
64 | return info; | ||||
65 | } | ||||
66 | | ||||
67 | QVariant PageModel::dataForTaskWithProject(const Domain::Task::Ptr &task, int role, const TaskExtraDataPtr &info) | ||||
68 | { | ||||
69 | switch (role) { | ||||
70 | case Qt::DisplayRole: | ||||
71 | case Qt::EditRole: | ||||
72 | return task->title(); | ||||
73 | case Qt::CheckStateRole: | ||||
74 | return task->isDone() ? Qt::Checked : Qt::Unchecked; | ||||
75 | case Presentation::QueryTreeModelBase::AdditionalInfoRole: | ||||
76 | if (!info || info->childTask) | ||||
77 | return QString(); | ||||
78 | if (info->projectQueryResult && !info->projectQueryResult->data().isEmpty()) { | ||||
79 | Domain::Project::Ptr project = info->projectQueryResult->data().at(0); | ||||
80 | return i18n("Project: %1", project->name()); | ||||
81 | } | ||||
82 | return i18n("Inbox"); // TODO add source name | ||||
83 | default: | ||||
84 | break; | ||||
85 | } | ||||
86 | return QVariant(); | ||||
87 | } |