Changeset View
Changeset View
Standalone View
Standalone View
src/presentation/workdaypagemodel.cpp
Show All 20 Lines | 1 | /* This file is part of Zanshin | |||
---|---|---|---|---|---|
21 | USA. | 21 | USA. | ||
22 | */ | 22 | */ | ||
23 | 23 | | |||
24 | 24 | | |||
25 | #include "workdaypagemodel.h" | 25 | #include "workdaypagemodel.h" | ||
26 | 26 | | |||
27 | #include <QMimeData> | 27 | #include <QMimeData> | ||
28 | 28 | | |||
29 | #include <KLocalizedString> | ||||
30 | | ||||
29 | #include "domain/noterepository.h" | 31 | #include "domain/noterepository.h" | ||
30 | #include "domain/taskqueries.h" | 32 | #include "domain/taskqueries.h" | ||
31 | #include "domain/taskrepository.h" | 33 | #include "domain/taskrepository.h" | ||
32 | 34 | | |||
33 | #include "presentation/querytreemodel.h" | 35 | #include "presentation/querytreemodel.h" | ||
34 | 36 | | |||
35 | #include "utils/datetime.h" | 37 | #include "utils/datetime.h" | ||
36 | 38 | | |||
Show All 15 Lines | 51 | { | |||
52 | const auto parentTask = parentArtifact.objectCast<Domain::Task>(); | 54 | const auto parentTask = parentArtifact.objectCast<Domain::Task>(); | ||
53 | 55 | | |||
54 | auto task = Domain::Task::Ptr::create(); | 56 | auto task = Domain::Task::Ptr::create(); | ||
55 | task->setTitle(title); | 57 | task->setTitle(title); | ||
56 | if (!parentTask) | 58 | if (!parentTask) | ||
57 | task->setStartDate(Utils::DateTime::currentDateTime()); | 59 | task->setStartDate(Utils::DateTime::currentDateTime()); | ||
58 | const auto job = parentTask ? m_taskRepository->createChild(task, parentTask) | 60 | const auto job = parentTask ? m_taskRepository->createChild(task, parentTask) | ||
59 | : m_taskRepository->create(task); | 61 | : m_taskRepository->create(task); | ||
60 | installHandler(job, tr("Cannot add task %1 in Workday").arg(title)); | 62 | installHandler(job, i18n("Cannot add task %1 in Workday", title)); | ||
61 | 63 | | |||
62 | return task; | 64 | return task; | ||
63 | } | 65 | } | ||
64 | 66 | | |||
65 | void WorkdayPageModel::removeItem(const QModelIndex &index) | 67 | void WorkdayPageModel::removeItem(const QModelIndex &index) | ||
66 | { | 68 | { | ||
67 | QVariant data = index.data(QueryTreeModel<Domain::Artifact::Ptr>::ObjectRole); | 69 | QVariant data = index.data(QueryTreeModel<Domain::Artifact::Ptr>::ObjectRole); | ||
68 | auto artifact = data.value<Domain::Artifact::Ptr>(); | 70 | auto artifact = data.value<Domain::Artifact::Ptr>(); | ||
69 | auto task = artifact.objectCast<Domain::Task>(); | 71 | auto task = artifact.objectCast<Domain::Task>(); | ||
70 | if (task) { | 72 | if (task) { | ||
71 | const auto job = m_taskRepository->remove(task); | 73 | const auto job = m_taskRepository->remove(task); | ||
72 | installHandler(job, tr("Cannot remove task %1 from Workday").arg(task->title())); | 74 | installHandler(job, i18n("Cannot remove task %1 from Workday", task->title())); | ||
73 | } | 75 | } | ||
74 | } | 76 | } | ||
75 | 77 | | |||
76 | void WorkdayPageModel::promoteItem(const QModelIndex &index) | 78 | void WorkdayPageModel::promoteItem(const QModelIndex &index) | ||
77 | { | 79 | { | ||
78 | QVariant data = index.data(QueryTreeModel<Domain::Task::Ptr>::ObjectRole); | 80 | QVariant data = index.data(QueryTreeModel<Domain::Task::Ptr>::ObjectRole); | ||
79 | auto artifact = data.value<Domain::Artifact::Ptr>(); | 81 | auto artifact = data.value<Domain::Artifact::Ptr>(); | ||
80 | auto task = artifact.objectCast<Domain::Task>(); | 82 | auto task = artifact.objectCast<Domain::Task>(); | ||
81 | Q_ASSERT(task); | 83 | Q_ASSERT(task); | ||
82 | const auto job = m_taskRepository->promoteToProject(task); | 84 | const auto job = m_taskRepository->promoteToProject(task); | ||
83 | installHandler(job, tr("Cannot promote task %1 to be a project").arg(task->title())); | 85 | installHandler(job, i18n("Cannot promote task %1 to be a project", task->title())); | ||
84 | } | 86 | } | ||
85 | 87 | | |||
86 | QAbstractItemModel *WorkdayPageModel::createCentralListModel() | 88 | QAbstractItemModel *WorkdayPageModel::createCentralListModel() | ||
87 | { | 89 | { | ||
88 | auto query = [this](const Domain::Artifact::Ptr &artifact) -> Domain::QueryResultInterface<Domain::Artifact::Ptr>::Ptr { | 90 | auto query = [this](const Domain::Artifact::Ptr &artifact) -> Domain::QueryResultInterface<Domain::Artifact::Ptr>::Ptr { | ||
89 | if (!artifact) | 91 | if (!artifact) | ||
90 | return Domain::QueryResult<Domain::Task::Ptr, Domain::Artifact::Ptr>::copy(m_taskQueries->findWorkdayTopLevel()); | 92 | return Domain::QueryResult<Domain::Task::Ptr, Domain::Artifact::Ptr>::copy(m_taskQueries->findWorkdayTopLevel()); | ||
91 | else if (auto task = artifact.dynamicCast<Domain::Task>()) | 93 | else if (auto task = artifact.dynamicCast<Domain::Task>()) | ||
Show All 35 Lines | 124 | auto setData = [this](const Domain::Artifact::Ptr &artifact, const QVariant &value, int role) { | |||
127 | if (auto task = artifact.dynamicCast<Domain::Task>()) { | 129 | if (auto task = artifact.dynamicCast<Domain::Task>()) { | ||
128 | const auto currentTitle = task->title(); | 130 | const auto currentTitle = task->title(); | ||
129 | if (role == Qt::EditRole) | 131 | if (role == Qt::EditRole) | ||
130 | task->setTitle(value.toString()); | 132 | task->setTitle(value.toString()); | ||
131 | else | 133 | else | ||
132 | task->setDone(value.toInt() == Qt::Checked); | 134 | task->setDone(value.toInt() == Qt::Checked); | ||
133 | 135 | | |||
134 | const auto job = m_taskRepository->update(task); | 136 | const auto job = m_taskRepository->update(task); | ||
135 | installHandler(job, tr("Cannot modify task %1 in Workday").arg(currentTitle)); | 137 | installHandler(job, i18n("Cannot modify task %1 in Workday", currentTitle)); | ||
136 | return true; | 138 | return true; | ||
137 | } | 139 | } | ||
138 | 140 | | |||
139 | return false; | 141 | return false; | ||
140 | }; | 142 | }; | ||
141 | 143 | | |||
142 | auto drop = [this](const QMimeData *mimeData, Qt::DropAction, const Domain::Artifact::Ptr &artifact) { | 144 | auto drop = [this](const QMimeData *mimeData, Qt::DropAction, const Domain::Artifact::Ptr &artifact) { | ||
143 | auto parentTask = artifact.objectCast<Domain::Task>(); | 145 | auto parentTask = artifact.objectCast<Domain::Task>(); | ||
Show All 12 Lines | 154 | if (std::any_of(droppedArtifacts.begin(), droppedArtifacts.end(), | |||
156 | return false; | 158 | return false; | ||
157 | } | 159 | } | ||
158 | 160 | | |||
159 | foreach(const auto &droppedArtifact, droppedArtifacts) { | 161 | foreach(const auto &droppedArtifact, droppedArtifacts) { | ||
160 | auto childTask = droppedArtifact.objectCast<Domain::Task>(); | 162 | auto childTask = droppedArtifact.objectCast<Domain::Task>(); | ||
161 | 163 | | |||
162 | if (parentTask) { | 164 | if (parentTask) { | ||
163 | const auto job = m_taskRepository->associate(parentTask, childTask); | 165 | const auto job = m_taskRepository->associate(parentTask, childTask); | ||
164 | installHandler(job, tr("Cannot move task %1 as sub-task of %2").arg(childTask->title(), parentTask->title())); | 166 | installHandler(job, i18n("Cannot move task %1 as sub-task of %2", childTask->title(), parentTask->title())); | ||
165 | } else { | 167 | } else { | ||
166 | childTask->setStartDate(Utils::DateTime::currentDateTime()); | 168 | childTask->setStartDate(Utils::DateTime::currentDateTime()); | ||
167 | 169 | | |||
168 | auto job = m_taskRepository->update(childTask); | 170 | auto job = m_taskRepository->update(childTask); | ||
169 | installHandler(job, tr("Cannot update task %1").arg(childTask->title())); | 171 | installHandler(job, i18n("Cannot update task %1", childTask->title())); | ||
170 | 172 | | |||
171 | job = m_taskRepository->dissociate(childTask); | 173 | job = m_taskRepository->dissociate(childTask); | ||
172 | installHandler(job, tr("Cannot deparent task %1 from its parent").arg(childTask->title())); | 174 | installHandler(job, i18n("Cannot deparent task %1 from its parent", childTask->title())); | ||
173 | } | 175 | } | ||
174 | } | 176 | } | ||
175 | 177 | | |||
176 | return true; | 178 | return true; | ||
177 | }; | 179 | }; | ||
178 | 180 | | |||
179 | auto drag = [](const Domain::Artifact::List &artifacts) -> QMimeData* { | 181 | auto drag = [](const Domain::Artifact::List &artifacts) -> QMimeData* { | ||
180 | if (artifacts.isEmpty()) | 182 | if (artifacts.isEmpty()) | ||
Show All 10 Lines |