Changeset View
Changeset View
Standalone View
Standalone View
src/presentation/taskinboxpagemodel.cpp
Show All 20 Lines | 1 | /* This file is part of Zanshin | |||
---|---|---|---|---|---|
21 | USA. | 21 | USA. | ||
22 | */ | 22 | */ | ||
23 | 23 | | |||
24 | 24 | | |||
25 | #include "taskinboxpagemodel.h" | 25 | #include "taskinboxpagemodel.h" | ||
26 | 26 | | |||
27 | #include <QMimeData> | 27 | #include <QMimeData> | ||
28 | 28 | | |||
29 | #include <KLocalizedString> | ||||
30 | | ||||
29 | #include "presentation/querytreemodel.h" | 31 | #include "presentation/querytreemodel.h" | ||
30 | 32 | | |||
31 | using namespace Presentation; | 33 | using namespace Presentation; | ||
32 | 34 | | |||
33 | TaskInboxPageModel::TaskInboxPageModel(const Domain::TaskQueries::Ptr &taskQueries, | 35 | TaskInboxPageModel::TaskInboxPageModel(const Domain::TaskQueries::Ptr &taskQueries, | ||
34 | const Domain::TaskRepository::Ptr &taskRepository, | 36 | const Domain::TaskRepository::Ptr &taskRepository, | ||
35 | QObject *parent) | 37 | QObject *parent) | ||
36 | : PageModel(parent), | 38 | : PageModel(parent), | ||
37 | m_taskQueries(taskQueries), | 39 | m_taskQueries(taskQueries), | ||
38 | m_taskRepository(taskRepository) | 40 | m_taskRepository(taskRepository) | ||
39 | { | 41 | { | ||
40 | } | 42 | } | ||
41 | 43 | | |||
42 | Domain::Artifact::Ptr TaskInboxPageModel::addItem(const QString &title, const QModelIndex &parentIndex) | 44 | Domain::Artifact::Ptr TaskInboxPageModel::addItem(const QString &title, const QModelIndex &parentIndex) | ||
43 | { | 45 | { | ||
44 | const auto parentData = parentIndex.data(QueryTreeModel<Domain::Task::Ptr>::ObjectRole); | 46 | const auto parentData = parentIndex.data(QueryTreeModel<Domain::Task::Ptr>::ObjectRole); | ||
45 | const auto parentArtifact = parentData.value<Domain::Artifact::Ptr>(); | 47 | const auto parentArtifact = parentData.value<Domain::Artifact::Ptr>(); | ||
46 | const auto parentTask = parentArtifact.objectCast<Domain::Task>(); | 48 | const auto parentTask = parentArtifact.objectCast<Domain::Task>(); | ||
47 | 49 | | |||
48 | auto task = Domain::Task::Ptr::create(); | 50 | auto task = Domain::Task::Ptr::create(); | ||
49 | task->setTitle(title); | 51 | task->setTitle(title); | ||
50 | const auto job = parentTask ? m_taskRepository->createChild(task, parentTask) | 52 | const auto job = parentTask ? m_taskRepository->createChild(task, parentTask) | ||
51 | : m_taskRepository->create(task); | 53 | : m_taskRepository->create(task); | ||
52 | installHandler(job, tr("Cannot add task %1 in Inbox").arg(title)); | 54 | installHandler(job, i18n("Cannot add task %1 in Inbox", title)); | ||
53 | 55 | | |||
54 | return task; | 56 | return task; | ||
55 | } | 57 | } | ||
56 | 58 | | |||
57 | void TaskInboxPageModel::removeItem(const QModelIndex &index) | 59 | void TaskInboxPageModel::removeItem(const QModelIndex &index) | ||
58 | { | 60 | { | ||
59 | QVariant data = index.data(QueryTreeModel<Domain::Artifact::Ptr>::ObjectRole); | 61 | QVariant data = index.data(QueryTreeModel<Domain::Artifact::Ptr>::ObjectRole); | ||
60 | auto artifact = data.value<Domain::Artifact::Ptr>(); | 62 | auto artifact = data.value<Domain::Artifact::Ptr>(); | ||
61 | auto task = artifact.objectCast<Domain::Task>(); | 63 | auto task = artifact.objectCast<Domain::Task>(); | ||
62 | Q_ASSERT(task); | 64 | Q_ASSERT(task); | ||
63 | const auto job = m_taskRepository->remove(task); | 65 | const auto job = m_taskRepository->remove(task); | ||
64 | installHandler(job, tr("Cannot remove task %1 from Inbox").arg(task->title())); | 66 | installHandler(job, i18n("Cannot remove task %1 from Inbox", task->title())); | ||
65 | } | 67 | } | ||
66 | 68 | | |||
67 | void TaskInboxPageModel::promoteItem(const QModelIndex &index) | 69 | void TaskInboxPageModel::promoteItem(const QModelIndex &index) | ||
68 | { | 70 | { | ||
69 | QVariant data = index.data(QueryTreeModel<Domain::Task::Ptr>::ObjectRole); | 71 | QVariant data = index.data(QueryTreeModel<Domain::Task::Ptr>::ObjectRole); | ||
70 | auto artifact = data.value<Domain::Artifact::Ptr>(); | 72 | auto artifact = data.value<Domain::Artifact::Ptr>(); | ||
71 | auto task = artifact.objectCast<Domain::Task>(); | 73 | auto task = artifact.objectCast<Domain::Task>(); | ||
72 | Q_ASSERT(task); | 74 | Q_ASSERT(task); | ||
73 | const auto job = m_taskRepository->promoteToProject(task); | 75 | const auto job = m_taskRepository->promoteToProject(task); | ||
74 | installHandler(job, tr("Cannot promote task %1 to be a project").arg(task->title())); | 76 | installHandler(job, i18n("Cannot promote task %1 to be a project", task->title())); | ||
75 | } | 77 | } | ||
76 | 78 | | |||
77 | QAbstractItemModel *TaskInboxPageModel::createCentralListModel() | 79 | QAbstractItemModel *TaskInboxPageModel::createCentralListModel() | ||
78 | { | 80 | { | ||
79 | auto query = [this](const Domain::Task::Ptr &task) -> Domain::QueryResultInterface<Domain::Task::Ptr>::Ptr { | 81 | auto query = [this](const Domain::Task::Ptr &task) -> Domain::QueryResultInterface<Domain::Task::Ptr>::Ptr { | ||
80 | if (!task) | 82 | if (!task) | ||
81 | return m_taskQueries->findInboxTopLevel(); | 83 | return m_taskQueries->findInboxTopLevel(); | ||
82 | else | 84 | else | ||
Show All 30 Lines | 111 | auto setData = [this](const Domain::Task::Ptr &task, const QVariant &value, int role) { | |||
113 | 115 | | |||
114 | const auto currentTitle = task->title(); | 116 | const auto currentTitle = task->title(); | ||
115 | if (role == Qt::EditRole) | 117 | if (role == Qt::EditRole) | ||
116 | task->setTitle(value.toString()); | 118 | task->setTitle(value.toString()); | ||
117 | else | 119 | else | ||
118 | task->setDone(value.toInt() == Qt::Checked); | 120 | task->setDone(value.toInt() == Qt::Checked); | ||
119 | 121 | | |||
120 | const auto job = m_taskRepository->update(task); | 122 | const auto job = m_taskRepository->update(task); | ||
121 | installHandler(job, tr("Cannot modify task %1 in Inbox").arg(currentTitle)); | 123 | installHandler(job, i18n("Cannot modify task %1 in Inbox", currentTitle)); | ||
122 | return true; | 124 | return true; | ||
123 | }; | 125 | }; | ||
124 | 126 | | |||
125 | auto drop = [this](const QMimeData *mimeData, Qt::DropAction, const Domain::Task::Ptr &task) { | 127 | auto drop = [this](const QMimeData *mimeData, Qt::DropAction, const Domain::Task::Ptr &task) { | ||
126 | auto parentTask = task.objectCast<Domain::Task>(); | 128 | auto parentTask = task.objectCast<Domain::Task>(); | ||
127 | 129 | | |||
128 | if (!mimeData->hasFormat(QStringLiteral("application/x-zanshin-object"))) | 130 | if (!mimeData->hasFormat(QStringLiteral("application/x-zanshin-object"))) | ||
129 | return false; | 131 | return false; | ||
Show All 9 Lines | 137 | if (std::any_of(droppedArtifacts.begin(), droppedArtifacts.end(), | |||
139 | return false; | 141 | return false; | ||
140 | } | 142 | } | ||
141 | 143 | | |||
142 | foreach(const auto &droppedArtifact, droppedArtifacts) { | 144 | foreach(const auto &droppedArtifact, droppedArtifacts) { | ||
143 | auto childTask = droppedArtifact.objectCast<Domain::Task>(); | 145 | auto childTask = droppedArtifact.objectCast<Domain::Task>(); | ||
144 | 146 | | |||
145 | if (parentTask) { | 147 | if (parentTask) { | ||
146 | const auto job = m_taskRepository->associate(parentTask, childTask); | 148 | const auto job = m_taskRepository->associate(parentTask, childTask); | ||
147 | installHandler(job, tr("Cannot move task %1 as sub-task of %2").arg(childTask->title(), parentTask->title())); | 149 | installHandler(job, i18n("Cannot move task %1 as sub-task of %2", childTask->title(), parentTask->title())); | ||
148 | } else { | 150 | } else { | ||
149 | const auto job = m_taskRepository->dissociate(childTask); | 151 | const auto job = m_taskRepository->dissociate(childTask); | ||
150 | installHandler(job, tr("Cannot deparent task %1 from its parent").arg(childTask->title())); | 152 | installHandler(job, i18n("Cannot deparent task %1 from its parent", childTask->title())); | ||
151 | } | 153 | } | ||
152 | } | 154 | } | ||
153 | 155 | | |||
154 | return true; | 156 | return true; | ||
155 | }; | 157 | }; | ||
156 | 158 | | |||
157 | auto drag = [](const Domain::Task::List &tasks) -> QMimeData* { | 159 | auto drag = [](const Domain::Task::List &tasks) -> QMimeData* { | ||
158 | if (tasks.isEmpty()) | 160 | if (tasks.isEmpty()) | ||
Show All 16 Lines |