Changeset View
Changeset View
Standalone View
Standalone View
src/presentation/taskinboxpagemodel.cpp
Show First 20 Lines • Show All 72 Lines • ▼ Show 20 Line(s) | 70 | { | |||
---|---|---|---|---|---|
73 | auto task = artifact.objectCast<Domain::Task>(); | 73 | auto task = artifact.objectCast<Domain::Task>(); | ||
74 | Q_ASSERT(task); | 74 | Q_ASSERT(task); | ||
75 | const auto job = m_taskRepository->promoteToProject(task); | 75 | const auto job = m_taskRepository->promoteToProject(task); | ||
76 | installHandler(job, i18n("Cannot promote task %1 to be a project", task->title())); | 76 | installHandler(job, i18n("Cannot promote task %1 to be a project", task->title())); | ||
77 | } | 77 | } | ||
78 | 78 | | |||
79 | QAbstractItemModel *TaskInboxPageModel::createCentralListModel() | 79 | QAbstractItemModel *TaskInboxPageModel::createCentralListModel() | ||
80 | { | 80 | { | ||
81 | using AdditionalInfo = Domain::QueryResult<Domain::DataSource::Ptr>::Ptr; | ||||
82 | | ||||
81 | auto query = [this](const Domain::Task::Ptr &task) -> Domain::QueryResultInterface<Domain::Task::Ptr>::Ptr { | 83 | auto query = [this](const Domain::Task::Ptr &task) -> Domain::QueryResultInterface<Domain::Task::Ptr>::Ptr { | ||
82 | if (!task) | 84 | if (!task) | ||
83 | return m_taskQueries->findInboxTopLevel(); | 85 | return m_taskQueries->findInboxTopLevel(); | ||
84 | else | 86 | else | ||
85 | return m_taskQueries->findChildren(task); | 87 | return m_taskQueries->findChildren(task); | ||
86 | }; | 88 | }; | ||
87 | 89 | | |||
88 | auto flags = [](const Domain::Task::Ptr &) { | 90 | auto flags = [](const Domain::Task::Ptr &) { | ||
89 | return Qt::ItemIsSelectable | 91 | return Qt::ItemIsSelectable | ||
90 | | Qt::ItemIsEnabled | 92 | | Qt::ItemIsEnabled | ||
91 | | Qt::ItemIsEditable | 93 | | Qt::ItemIsEditable | ||
92 | | Qt::ItemIsDragEnabled | 94 | | Qt::ItemIsDragEnabled | ||
93 | | Qt::ItemIsUserCheckable | 95 | | Qt::ItemIsUserCheckable | ||
94 | | Qt::ItemIsDropEnabled; | 96 | | Qt::ItemIsDropEnabled; | ||
95 | }; | 97 | }; | ||
96 | 98 | | |||
97 | auto data = [](const Domain::Task::Ptr &task, int role, int) -> QVariant { | 99 | auto data = [](const Domain::Task::Ptr &task, int role, const AdditionalInfo &dataSourceQueryResult) -> QVariant { | ||
98 | if (role != Qt::DisplayRole | 100 | switch (role) { | ||
99 | && role != Qt::EditRole | 101 | case Qt::DisplayRole: | ||
100 | && role != Qt::CheckStateRole) { | 102 | case Qt::EditRole: | ||
101 | return QVariant(); | | |||
102 | } | | |||
103 | | ||||
104 | if (role == Qt::DisplayRole || role == Qt::EditRole) { | | |||
105 | return task->title(); | 103 | return task->title(); | ||
106 | } else { | 104 | case Qt::CheckStateRole: | ||
107 | return task->isDone() ? Qt::Checked : Qt::Unchecked; | 105 | return task->isDone() ? Qt::Checked : Qt::Unchecked; | ||
106 | case Presentation::QueryTreeModelBase::AdditionalInfoRole: | ||||
107 | if (dataSourceQueryResult && !dataSourceQueryResult->data().isEmpty()) { | ||||
108 | Domain::DataSource::Ptr dataSource = dataSourceQueryResult->data().at(0); | ||||
109 | return dataSource->name(); | ||||
110 | } | ||||
111 | return QString(); | ||||
112 | default: | ||||
113 | break; | ||||
108 | } | 114 | } | ||
115 | return QVariant(); | ||||
116 | }; | ||||
117 | | ||||
118 | auto fetchAdditionalInfo = [this](const QModelIndex &index, const Domain::Artifact::Ptr &artifact) -> AdditionalInfo { | ||||
119 | if (index.parent().isValid()) // children are in the same collection as their parent, so the same datasource | ||||
ervin: Actually as far as the index is concerned, maybe you could look at it and only look up for the… | |||||
120 | return nullptr; | ||||
121 | if (auto task = artifact.dynamicCast<Domain::Task>()) { | ||||
122 | AdditionalInfo datasourceQueryResult = m_taskQueries->findDataSource(task); | ||||
123 | if (datasourceQueryResult) { | ||||
124 | QPersistentModelIndex persistentIndex(index); | ||||
125 | datasourceQueryResult->addPostInsertHandler([persistentIndex](const Domain::DataSource::Ptr &, int) { | ||||
126 | // When a datasource was found (inserted into the result), update the rendering of the item | ||||
127 | auto model = const_cast<QAbstractItemModel *>(persistentIndex.model()); | ||||
128 | model->dataChanged(persistentIndex, persistentIndex); | ||||
129 | }); | ||||
130 | } | ||||
131 | return datasourceQueryResult; | ||||
132 | } | ||||
133 | return nullptr; | ||||
134 | | ||||
109 | }; | 135 | }; | ||
110 | 136 | | |||
111 | auto setData = [this](const Domain::Task::Ptr &task, const QVariant &value, int role) { | 137 | auto setData = [this](const Domain::Task::Ptr &task, const QVariant &value, int role) { | ||
112 | if (role != Qt::EditRole && role != Qt::CheckStateRole) { | 138 | if (role != Qt::EditRole && role != Qt::CheckStateRole) { | ||
113 | return false; | 139 | return false; | ||
114 | } | 140 | } | ||
115 | 141 | | |||
116 | const auto currentTitle = task->title(); | 142 | const auto currentTitle = task->title(); | ||
▲ Show 20 Lines • Show All 50 Lines • ▼ Show 20 Line(s) | 185 | auto drag = [](const Domain::Task::List &tasks) -> QMimeData* { | |||
167 | } | 193 | } | ||
168 | 194 | | |||
169 | auto data = new QMimeData; | 195 | auto data = new QMimeData; | ||
170 | data->setData(QStringLiteral("application/x-zanshin-object"), "object"); | 196 | data->setData(QStringLiteral("application/x-zanshin-object"), "object"); | ||
171 | data->setProperty("objects", QVariant::fromValue(draggedArtifacts)); | 197 | data->setProperty("objects", QVariant::fromValue(draggedArtifacts)); | ||
172 | return data; | 198 | return data; | ||
173 | }; | 199 | }; | ||
174 | 200 | | |||
175 | return new QueryTreeModel<Domain::Task::Ptr>(query, flags, data, setData, drop, drag, nullptr, this); | 201 | return new QueryTreeModel<Domain::Task::Ptr, AdditionalInfo>(query, flags, data, setData, drop, drag, fetchAdditionalInfo, this); | ||
176 | } | 202 | } |
Actually as far as the index is concerned, maybe you could look at it and only look up for the collection if it has no parent. Children are in the same collection than their parents anyway.
Of course wouldn't apply to other extra information we might want to fetch now, but for collections doing it on top level items is enough.