Changeset View
Changeset View
Standalone View
Standalone View
src/presentation/noteinboxpagemodel.cpp
Show All 20 Lines | 1 | /* This file is part of Zanshin | |||
---|---|---|---|---|---|
21 | USA. | 21 | USA. | ||
22 | */ | 22 | */ | ||
23 | 23 | | |||
24 | 24 | | |||
25 | #include "noteinboxpagemodel.h" | 25 | #include "noteinboxpagemodel.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 | NoteInboxPageModel::NoteInboxPageModel(const Domain::NoteQueries::Ptr ¬eQueries, | 35 | NoteInboxPageModel::NoteInboxPageModel(const Domain::NoteQueries::Ptr ¬eQueries, | ||
34 | const Domain::NoteRepository::Ptr ¬eRepository, | 36 | const Domain::NoteRepository::Ptr ¬eRepository, | ||
35 | QObject *parent) | 37 | QObject *parent) | ||
36 | : PageModel(parent), | 38 | : PageModel(parent), | ||
37 | m_noteQueries(noteQueries), | 39 | m_noteQueries(noteQueries), | ||
38 | m_noteRepository(noteRepository) | 40 | m_noteRepository(noteRepository) | ||
39 | { | 41 | { | ||
40 | } | 42 | } | ||
41 | 43 | | |||
42 | Domain::Artifact::Ptr NoteInboxPageModel::addItem(const QString &title, const QModelIndex &) | 44 | Domain::Artifact::Ptr NoteInboxPageModel::addItem(const QString &title, const QModelIndex &) | ||
43 | { | 45 | { | ||
44 | auto note = Domain::Note::Ptr::create(); | 46 | auto note = Domain::Note::Ptr::create(); | ||
45 | note->setTitle(title); | 47 | note->setTitle(title); | ||
46 | const auto job = m_noteRepository->create(note); | 48 | const auto job = m_noteRepository->create(note); | ||
47 | installHandler(job, tr("Cannot add note %1 in Inbox").arg(title)); | 49 | installHandler(job, i18n("Cannot add note %1 in Inbox", title)); | ||
48 | 50 | | |||
49 | return note; | 51 | return note; | ||
50 | } | 52 | } | ||
51 | 53 | | |||
52 | void NoteInboxPageModel::removeItem(const QModelIndex &index) | 54 | void NoteInboxPageModel::removeItem(const QModelIndex &index) | ||
53 | { | 55 | { | ||
54 | QVariant data = index.data(QueryTreeModel<Domain::Note::Ptr>::ObjectRole); | 56 | QVariant data = index.data(QueryTreeModel<Domain::Note::Ptr>::ObjectRole); | ||
55 | auto artifact = data.value<Domain::Artifact::Ptr>(); | 57 | auto artifact = data.value<Domain::Artifact::Ptr>(); | ||
56 | auto note = artifact.objectCast<Domain::Note>(); | 58 | auto note = artifact.objectCast<Domain::Note>(); | ||
57 | Q_ASSERT(note); | 59 | Q_ASSERT(note); | ||
58 | const auto job = m_noteRepository->remove(note); | 60 | const auto job = m_noteRepository->remove(note); | ||
59 | installHandler(job, tr("Cannot remove note %1 from Inbox").arg(note->title())); | 61 | installHandler(job, i18n("Cannot remove note %1 from Inbox", note->title())); | ||
60 | } | 62 | } | ||
61 | 63 | | |||
62 | void NoteInboxPageModel::promoteItem(const QModelIndex &) | 64 | void NoteInboxPageModel::promoteItem(const QModelIndex &) | ||
63 | { | 65 | { | ||
64 | qFatal("Not supported"); | 66 | qFatal("Not supported"); | ||
65 | } | 67 | } | ||
66 | 68 | | |||
67 | QAbstractItemModel *NoteInboxPageModel::createCentralListModel() | 69 | QAbstractItemModel *NoteInboxPageModel::createCentralListModel() | ||
Show All 23 Lines | 70 | { | |||
91 | auto setData = [this](const Domain::Note::Ptr ¬e, const QVariant &value, int role) { | 93 | auto setData = [this](const Domain::Note::Ptr ¬e, const QVariant &value, int role) { | ||
92 | if (role != Qt::EditRole) { | 94 | if (role != Qt::EditRole) { | ||
93 | return false; | 95 | return false; | ||
94 | } | 96 | } | ||
95 | 97 | | |||
96 | const auto currentTitle = note->title(); | 98 | const auto currentTitle = note->title(); | ||
97 | note->setTitle(value.toString()); | 99 | note->setTitle(value.toString()); | ||
98 | const auto job = m_noteRepository->update(note); | 100 | const auto job = m_noteRepository->update(note); | ||
99 | installHandler(job, tr("Cannot modify note %1 in Inbox").arg(currentTitle)); | 101 | installHandler(job, i18n("Cannot modify note %1 in Inbox", currentTitle)); | ||
100 | return true; | 102 | return true; | ||
101 | }; | 103 | }; | ||
102 | 104 | | |||
103 | auto drop = [this](const QMimeData *, Qt::DropAction, const Domain::Artifact::Ptr &) { | 105 | auto drop = [this](const QMimeData *, Qt::DropAction, const Domain::Artifact::Ptr &) { | ||
104 | return false; | 106 | return false; | ||
105 | }; | 107 | }; | ||
106 | 108 | | |||
107 | auto drag = [](const Domain::Note::List ¬es) -> QMimeData* { | 109 | auto drag = [](const Domain::Note::List ¬es) -> QMimeData* { | ||
Show All 16 Lines |