Changeset View
Changeset View
Standalone View
Standalone View
src/presentation/pagemodel.cpp
Show First 20 Lines • Show All 44 Lines • ▼ Show 20 Line(s) | |||||
45 | 45 | | |||
46 | PageModel::TaskExtraDataPtr PageModel::fetchTaskExtraData(Domain::TaskQueries::Ptr taskQueries, | 46 | PageModel::TaskExtraDataPtr PageModel::fetchTaskExtraData(Domain::TaskQueries::Ptr taskQueries, | ||
47 | const TaskExtraParts &parts, | 47 | const TaskExtraParts &parts, | ||
48 | const QModelIndex &index, | 48 | const QModelIndex &index, | ||
49 | const Domain::Task::Ptr &task) | 49 | const Domain::Task::Ptr &task) | ||
50 | { | 50 | { | ||
51 | TaskExtraDataPtr info = TaskExtraDataPtr::create(); | 51 | TaskExtraDataPtr info = TaskExtraDataPtr::create(); | ||
52 | if (index.parent().isValid()) { | 52 | if (index.parent().isValid()) { | ||
53 | info->childTask = true; | 53 | info->isChildTask = true; | ||
54 | } | 54 | } | ||
55 | 55 | | |||
56 | // children are in the same data source as their parent | 56 | // children are in the same data source as their parent | ||
57 | if (!info->childTask && parts.testFlag(TaskExtraPart::DataSource)) { | 57 | if (!info->isChildTask && parts.testFlag(TaskExtraPart::DataSource)) { | ||
58 | info->dataSourceQueryResult = taskQueries->findDataSource(task); | 58 | info->dataSourceQueryResult = taskQueries->findDataSource(task); | ||
59 | if (info->dataSourceQueryResult) { | 59 | if (info->dataSourceQueryResult) { | ||
60 | QPersistentModelIndex persistentIndex(index); | 60 | QPersistentModelIndex persistentIndex(index); | ||
61 | info->dataSourceQueryResult->addPostInsertHandler([persistentIndex](const Domain::DataSource::Ptr &, int) { | 61 | info->dataSourceQueryResult->addPostInsertHandler([persistentIndex](const Domain::DataSource::Ptr &, int) { | ||
62 | // When a data source was found (inserted into the result), update the rendering of the item | 62 | // When a data source was found (inserted into the result), update the rendering of the item | ||
63 | auto model = const_cast<QAbstractItemModel *>(persistentIndex.model()); | 63 | auto model = const_cast<QAbstractItemModel *>(persistentIndex.model()); | ||
64 | model->dataChanged(persistentIndex, persistentIndex); | 64 | model->dataChanged(persistentIndex, persistentIndex); | ||
65 | }); | 65 | }); | ||
66 | } | 66 | } | ||
67 | } | 67 | } | ||
68 | 68 | | |||
69 | // children are in the same project as their parent | 69 | // children are in the same project as their parent | ||
70 | if (!info->childTask && parts.testFlag(TaskExtraPart::Project)) { | 70 | if (!info->isChildTask && parts.testFlag(TaskExtraPart::Project)) { | ||
71 | info->projectQueryResult = taskQueries->findProject(task); | 71 | info->projectQueryResult = taskQueries->findProject(task); | ||
72 | if (info->projectQueryResult) { | 72 | if (info->projectQueryResult) { | ||
73 | QPersistentModelIndex persistentIndex(index); | 73 | QPersistentModelIndex persistentIndex(index); | ||
74 | info->projectQueryResult->addPostInsertHandler([persistentIndex](const Domain::Project::Ptr &, int) { | 74 | info->projectQueryResult->addPostInsertHandler([persistentIndex](const Domain::Project::Ptr &, int) { | ||
75 | // When a project was found (inserted into the result), update the rendering of the item | 75 | // When a project was found (inserted into the result), update the rendering of the item | ||
76 | auto model = const_cast<QAbstractItemModel *>(persistentIndex.model()); | 76 | auto model = const_cast<QAbstractItemModel *>(persistentIndex.model()); | ||
77 | model->dataChanged(persistentIndex, persistentIndex); | 77 | model->dataChanged(persistentIndex, persistentIndex); | ||
78 | }); | 78 | }); | ||
Show All 19 Lines | |||||
98 | { | 98 | { | ||
99 | switch (role) { | 99 | switch (role) { | ||
100 | case Qt::DisplayRole: | 100 | case Qt::DisplayRole: | ||
101 | case Qt::EditRole: | 101 | case Qt::EditRole: | ||
102 | return task->title(); | 102 | return task->title(); | ||
103 | case Qt::CheckStateRole: | 103 | case Qt::CheckStateRole: | ||
104 | return task->isDone() ? Qt::Checked : Qt::Unchecked; | 104 | return task->isDone() ? Qt::Checked : Qt::Unchecked; | ||
105 | case Presentation::QueryTreeModelBase::IsChildRole: | 105 | case Presentation::QueryTreeModelBase::IsChildRole: | ||
106 | return !info ? QVariant() : info->childTask; | 106 | return !info ? QVariant() : info->isChildTask; | ||
107 | case Presentation::QueryTreeModelBase::ProjectRole: | 107 | case Presentation::QueryTreeModelBase::ProjectRole: | ||
108 | if (!info || !info->projectQueryResult) { | 108 | if (!info || !info->projectQueryResult) { | ||
109 | return QVariant(); | 109 | return QVariant(); | ||
110 | } else if (info->projectQueryResult->data().isEmpty()) { | 110 | } else if (info->projectQueryResult->data().isEmpty()) { | ||
111 | return QString(); | 111 | return QString(); | ||
112 | } else { | 112 | } else { | ||
113 | return info->projectQueryResult->data().at(0)->name(); | 113 | return info->projectQueryResult->data().at(0)->name(); | ||
114 | } | 114 | } | ||
Show All 24 Lines |