Changeset View
Changeset View
Standalone View
Standalone View
src/presentation/workdaypagemodel.cpp
Show First 20 Lines • Show All 93 Lines • ▼ Show 20 Line(s) | 93 | auto flags = [](const Domain::Task::Ptr &task) { | |||
---|---|---|---|---|---|
94 | const Qt::ItemFlags defaultFlags = Qt::ItemIsSelectable | 94 | const Qt::ItemFlags defaultFlags = Qt::ItemIsSelectable | ||
95 | | Qt::ItemIsEnabled | 95 | | Qt::ItemIsEnabled | ||
96 | | Qt::ItemIsEditable | 96 | | Qt::ItemIsEditable | ||
97 | | Qt::ItemIsDragEnabled; | 97 | | Qt::ItemIsDragEnabled; | ||
98 | 98 | | |||
99 | return task ? (defaultFlags | Qt::ItemIsUserCheckable | Qt::ItemIsDropEnabled) : defaultFlags; | 99 | return task ? (defaultFlags | Qt::ItemIsUserCheckable | Qt::ItemIsDropEnabled) : defaultFlags; | ||
100 | }; | 100 | }; | ||
101 | 101 | | |||
102 | using AdditionalInfo = Domain::QueryResult<Domain::Project::Ptr>::Ptr; // later on we'll want a struct with the context query as well | 102 | struct AdditionalData | ||
103 | { | ||||
104 | bool childTask = false; | ||||
105 | Domain::QueryResult<Domain::Project::Ptr>::Ptr projectQueryResult; | ||||
106 | // later on we'll want the context query as well | ||||
107 | }; | ||||
108 | using AdditionalInfo = QSharedPointer<AdditionalData>; | ||||
103 | 109 | | |||
104 | auto data = [](const Domain::Task::Ptr &task, int role, const AdditionalInfo &projectQueryResult) -> QVariant { | 110 | auto data = [](const Domain::Task::Ptr &task, int role, const AdditionalInfo &info) -> QVariant { | ||
105 | switch (role) { | 111 | switch (role) { | ||
106 | case Qt::DisplayRole: | 112 | case Qt::DisplayRole: | ||
107 | case Qt::EditRole: | 113 | case Qt::EditRole: | ||
108 | return task->title(); | 114 | return task->title(); | ||
109 | case Qt::CheckStateRole: | 115 | case Qt::CheckStateRole: | ||
110 | return task->isDone() ? Qt::Checked : Qt::Unchecked; | 116 | return task->isDone() ? Qt::Checked : Qt::Unchecked; | ||
111 | case Presentation::QueryTreeModelBase::AdditionalInfoRole: | 117 | case Presentation::QueryTreeModelBase::AdditionalInfoRole: | ||
112 | if (projectQueryResult && !projectQueryResult->data().isEmpty()) { | 118 | if (!info || info->childTask) | ||
113 | Domain::Project::Ptr project = projectQueryResult->data().at(0); | 119 | return QString(); | ||
120 | if (info->projectQueryResult && !info->projectQueryResult->data().isEmpty()) { | ||||
121 | Domain::Project::Ptr project = info->projectQueryResult->data().at(0); | ||||
114 | return i18n("Project: %1", project->name()); | 122 | return i18n("Project: %1", project->name()); | ||
115 | } | 123 | } | ||
116 | return i18n("Inbox"); // TODO add source name | 124 | return i18n("Inbox"); // TODO add source name | ||
117 | default: | 125 | default: | ||
118 | break; | 126 | break; | ||
119 | } | 127 | } | ||
120 | return QVariant(); | 128 | return QVariant(); | ||
121 | }; | 129 | }; | ||
122 | 130 | | |||
123 | auto fetchAdditionalInfo = [this](const QModelIndex &index, const Domain::Task::Ptr &task) -> AdditionalInfo { | 131 | auto fetchAdditionalInfo = [this](const QModelIndex &index, const Domain::Task::Ptr &task) -> AdditionalInfo { | ||
124 | if (index.parent().isValid()) // children are in the same collection as their parent, so the same project | 132 | AdditionalInfo info = AdditionalInfo::create(); | ||
125 | return nullptr; | 133 | if (index.parent().isValid()) { // children are in the same collection as their parent, so the same project | ||
134 | info->childTask = true; | ||||
135 | return info; | ||||
136 | } | ||||
126 | 137 | | |||
127 | AdditionalInfo projectQueryResult = m_taskQueries->findProject(task); | 138 | info->projectQueryResult = m_taskQueries->findProject(task); | ||
128 | if (projectQueryResult) { | 139 | if (info->projectQueryResult) { | ||
129 | QPersistentModelIndex persistentIndex(index); | 140 | QPersistentModelIndex persistentIndex(index); | ||
130 | projectQueryResult->addPostInsertHandler([persistentIndex](const Domain::Project::Ptr &, int) { | 141 | info->projectQueryResult->addPostInsertHandler([persistentIndex](const Domain::Project::Ptr &, int) { | ||
131 | // When a project was found (inserted into the result), update the rendering of the item | 142 | // When a project was found (inserted into the result), update the rendering of the item | ||
132 | auto model = const_cast<QAbstractItemModel *>(persistentIndex.model()); | 143 | auto model = const_cast<QAbstractItemModel *>(persistentIndex.model()); | ||
133 | model->dataChanged(persistentIndex, persistentIndex); | 144 | model->dataChanged(persistentIndex, persistentIndex); | ||
134 | }); | 145 | }); | ||
135 | } | 146 | } | ||
136 | return projectQueryResult; | 147 | return info; | ||
137 | }; | 148 | }; | ||
138 | 149 | | |||
139 | auto setData = [this](const Domain::Task::Ptr &task, const QVariant &value, int role) { | 150 | auto setData = [this](const Domain::Task::Ptr &task, const QVariant &value, int role) { | ||
140 | if (role != Qt::EditRole && role != Qt::CheckStateRole) { | 151 | if (role != Qt::EditRole && role != Qt::CheckStateRole) { | ||
141 | return false; | 152 | return false; | ||
142 | } | 153 | } | ||
143 | 154 | | |||
144 | const auto currentTitle = task->title(); | 155 | const auto currentTitle = task->title(); | ||
▲ Show 20 Lines • Show All 48 Lines • Show Last 20 Lines |