Changeset View
Changeset View
Standalone View
Standalone View
src/presentation/contextpagemodel.cpp
Show First 20 Lines • Show All 108 Lines • ▼ Show 20 Line(s) | 107 | auto flags = [] (const Domain::Task::Ptr &task) { | |||
---|---|---|---|---|---|
109 | return Qt::ItemIsSelectable | 109 | return Qt::ItemIsSelectable | ||
110 | | Qt::ItemIsEnabled | 110 | | Qt::ItemIsEnabled | ||
111 | | Qt::ItemIsEditable | 111 | | Qt::ItemIsEditable | ||
112 | | Qt::ItemIsDragEnabled | 112 | | Qt::ItemIsDragEnabled | ||
113 | | Qt::ItemIsUserCheckable | 113 | | Qt::ItemIsUserCheckable | ||
114 | | Qt::ItemIsDropEnabled; | 114 | | Qt::ItemIsDropEnabled; | ||
115 | }; | 115 | }; | ||
116 | 116 | | |||
117 | auto data = [] (const Domain::Task::Ptr &task, int role, int) -> QVariant { | 117 | using AdditionalInfo = Domain::QueryResult<Domain::Project::Ptr>::Ptr; // later on we'll want a struct with the context query as well | ||
118 | if (role != Qt::DisplayRole | | |||
119 | && role != Qt::EditRole | | |||
120 | && role != Qt::CheckStateRole) { | | |||
121 | return QVariant(); | | |||
122 | } | | |||
123 | 118 | | |||
124 | if (role == Qt::DisplayRole || role == Qt::EditRole) { | 119 | auto data = [] (const Domain::Task::Ptr &task, int role, const AdditionalInfo &projectQueryResult) -> QVariant { | ||
120 | switch (role) { | ||||
121 | case Qt::DisplayRole: | ||||
122 | case Qt::EditRole: | ||||
125 | return task->title(); | 123 | return task->title(); | ||
126 | } else if (role == Qt::CheckStateRole){ | 124 | case Qt::CheckStateRole: | ||
127 | return task->isDone() ? Qt::Checked : Qt::Unchecked; | 125 | return task->isDone() ? Qt::Checked : Qt::Unchecked; | ||
128 | } else { | 126 | case Presentation::QueryTreeModelBase::AdditionalInfoRole: | ||
127 | if (projectQueryResult && !projectQueryResult->data().isEmpty()) { | ||||
128 | Domain::Project::Ptr project = projectQueryResult->data().at(0); | ||||
129 | return i18n("Project: %1", project->name()); | ||||
130 | } | ||||
131 | return i18n("Inbox"); | ||||
132 | default: | ||||
133 | break; | ||||
134 | } | ||||
129 | return QVariant(); | 135 | return QVariant(); | ||
136 | }; | ||||
137 | | ||||
138 | auto fetchAdditionalInfo = [this](const QModelIndex &index, const Domain::Artifact::Ptr &artifact) -> AdditionalInfo { | ||||
139 | if (auto task = artifact.dynamicCast<Domain::Task>()) { | ||||
140 | AdditionalInfo projectQueryResult = m_taskQueries->findProject(task); | ||||
141 | if (projectQueryResult) { | ||||
142 | QPersistentModelIndex persistentIndex(index); | ||||
143 | projectQueryResult->addPostInsertHandler([persistentIndex](const Domain::Project::Ptr &, int) { | ||||
144 | // When a project was found (inserted into the result), update the rendering of the item | ||||
145 | auto model = const_cast<QAbstractItemModel *>(persistentIndex.model()); | ||||
146 | model->dataChanged(persistentIndex, persistentIndex); | ||||
147 | }); | ||||
148 | } | ||||
149 | return projectQueryResult; | ||||
130 | } | 150 | } | ||
151 | return nullptr; | ||||
131 | }; | 152 | }; | ||
132 | 153 | | |||
133 | auto setData = [this] (const Domain::Task::Ptr &task, const QVariant &value, int role) { | 154 | auto setData = [this] (const Domain::Task::Ptr &task, const QVariant &value, int role) { | ||
134 | if (role != Qt::EditRole && role != Qt::CheckStateRole) | 155 | if (role != Qt::EditRole && role != Qt::CheckStateRole) | ||
135 | return false; | 156 | return false; | ||
136 | 157 | | |||
137 | const auto currentTitle = task->title(); | 158 | const auto currentTitle = task->title(); | ||
138 | if (role == Qt::EditRole) | 159 | if (role == Qt::EditRole) | ||
▲ Show 20 Lines • Show All 59 Lines • ▼ Show 20 Line(s) | 211 | auto drag = [] (const Domain::Task::List &tasks) -> QMimeData* { | |||
198 | } | 219 | } | ||
199 | 220 | | |||
200 | auto data = new QMimeData(); | 221 | auto data = new QMimeData(); | ||
201 | data->setData(QStringLiteral("application/x-zanshin-object"), "object"); | 222 | data->setData(QStringLiteral("application/x-zanshin-object"), "object"); | ||
202 | data->setProperty("objects", QVariant::fromValue(draggedArtifacts)); | 223 | data->setProperty("objects", QVariant::fromValue(draggedArtifacts)); | ||
203 | return data; | 224 | return data; | ||
204 | }; | 225 | }; | ||
205 | 226 | | |||
206 | return new QueryTreeModel<Domain::Task::Ptr>(query, flags, data, setData, drop, drag, nullptr, this); | 227 | return new QueryTreeModel<Domain::Task::Ptr, AdditionalInfo>(query, flags, data, setData, drop, drag, fetchAdditionalInfo, this); | ||
207 | } | 228 | } |