diff options
Diffstat (limited to 'framework/src/domain')
-rw-r--r-- | framework/src/domain/perioddayeventmodel.cpp (renamed from framework/src/domain/eventtreemodel.cpp) | 42 | ||||
-rw-r--r-- | framework/src/domain/perioddayeventmodel.h (renamed from framework/src/domain/eventtreemodel.h) | 25 |
2 files changed, 43 insertions, 24 deletions
diff --git a/framework/src/domain/eventtreemodel.cpp b/framework/src/domain/perioddayeventmodel.cpp index 4e25cffe..0b374d5c 100644 --- a/framework/src/domain/eventtreemodel.cpp +++ b/framework/src/domain/perioddayeventmodel.cpp | |||
@@ -19,7 +19,7 @@ | |||
19 | 02110-1301, USA. | 19 | 02110-1301, USA. |
20 | */ | 20 | */ |
21 | 21 | ||
22 | #include "eventtreemodel.h" | 22 | #include "perioddayeventmodel.h" |
23 | 23 | ||
24 | #include <sink/log.h> | 24 | #include <sink/log.h> |
25 | #include <sink/query.h> | 25 | #include <sink/query.h> |
@@ -29,7 +29,7 @@ | |||
29 | #include <QJsonObject> | 29 | #include <QJsonObject> |
30 | #include <QMetaEnum> | 30 | #include <QMetaEnum> |
31 | 31 | ||
32 | EventTreeModel::EventTreeModel(QObject *parent) : QAbstractItemModel(parent), partitionedEvents(7) | 32 | PeriodDayEventModel::PeriodDayEventModel(QObject *parent) : QAbstractItemModel(parent), partitionedEvents(7) |
33 | { | 33 | { |
34 | Sink::Query query; | 34 | Sink::Query query; |
35 | query.setFlags(Sink::Query::LiveQuery); | 35 | query.setFlags(Sink::Query::LiveQuery); |
@@ -40,17 +40,17 @@ EventTreeModel::EventTreeModel(QObject *parent) : QAbstractItemModel(parent), pa | |||
40 | 40 | ||
41 | eventModel = Sink::Store::loadModel<Event>(query); | 41 | eventModel = Sink::Store::loadModel<Event>(query); |
42 | 42 | ||
43 | QObject::connect(eventModel.data(), &QAbstractItemModel::dataChanged, this, &EventTreeModel::partitionData); | 43 | QObject::connect(eventModel.data(), &QAbstractItemModel::dataChanged, this, &PeriodDayEventModel::partitionData); |
44 | QObject::connect(eventModel.data(), &QAbstractItemModel::layoutChanged, this, &EventTreeModel::partitionData); | 44 | QObject::connect(eventModel.data(), &QAbstractItemModel::layoutChanged, this, &PeriodDayEventModel::partitionData); |
45 | QObject::connect(eventModel.data(), &QAbstractItemModel::modelReset, this, &EventTreeModel::partitionData); | 45 | QObject::connect(eventModel.data(), &QAbstractItemModel::modelReset, this, &PeriodDayEventModel::partitionData); |
46 | QObject::connect(eventModel.data(), &QAbstractItemModel::rowsInserted, this, &EventTreeModel::partitionData); | 46 | QObject::connect(eventModel.data(), &QAbstractItemModel::rowsInserted, this, &PeriodDayEventModel::partitionData); |
47 | QObject::connect(eventModel.data(), &QAbstractItemModel::rowsMoved, this, &EventTreeModel::partitionData); | 47 | QObject::connect(eventModel.data(), &QAbstractItemModel::rowsMoved, this, &PeriodDayEventModel::partitionData); |
48 | QObject::connect(eventModel.data(), &QAbstractItemModel::rowsRemoved, this, &EventTreeModel::partitionData); | 48 | QObject::connect(eventModel.data(), &QAbstractItemModel::rowsRemoved, this, &PeriodDayEventModel::partitionData); |
49 | 49 | ||
50 | partitionData(); | 50 | partitionData(); |
51 | } | 51 | } |
52 | 52 | ||
53 | void EventTreeModel::partitionData() | 53 | void PeriodDayEventModel::partitionData() |
54 | { | 54 | { |
55 | SinkLog() << "Partitioning event data"; | 55 | SinkLog() << "Partitioning event data"; |
56 | 56 | ||
@@ -78,7 +78,7 @@ void EventTreeModel::partitionData() | |||
78 | endResetModel(); | 78 | endResetModel(); |
79 | } | 79 | } |
80 | 80 | ||
81 | int EventTreeModel::bucketOf(QDate const &candidate) const | 81 | int PeriodDayEventModel::bucketOf(QDate const &candidate) const |
82 | { | 82 | { |
83 | int bucket = mViewStart.daysTo(candidate); | 83 | int bucket = mViewStart.daysTo(candidate); |
84 | if(bucket >= mViewLength || bucket < 0) { | 84 | if(bucket >= mViewLength || bucket < 0) { |
@@ -88,7 +88,7 @@ int EventTreeModel::bucketOf(QDate const &candidate) const | |||
88 | return bucket; | 88 | return bucket; |
89 | } | 89 | } |
90 | 90 | ||
91 | QModelIndex EventTreeModel::index(int row, int column, const QModelIndex &parent) const | 91 | QModelIndex PeriodDayEventModel::index(int row, int column, const QModelIndex &parent) const |
92 | { | 92 | { |
93 | if (!hasIndex(row, column, parent)) { | 93 | if (!hasIndex(row, column, parent)) { |
94 | return {}; | 94 | return {}; |
@@ -115,7 +115,7 @@ QModelIndex EventTreeModel::index(int row, int column, const QModelIndex &parent | |||
115 | return createIndex(row, column, day); | 115 | return createIndex(row, column, day); |
116 | } | 116 | } |
117 | 117 | ||
118 | QModelIndex EventTreeModel::parent(const QModelIndex &index) const | 118 | QModelIndex PeriodDayEventModel::parent(const QModelIndex &index) const |
119 | { | 119 | { |
120 | if (!index.isValid()) { | 120 | if (!index.isValid()) { |
121 | return {}; | 121 | return {}; |
@@ -130,7 +130,7 @@ QModelIndex EventTreeModel::parent(const QModelIndex &index) const | |||
130 | return this->index(day, 0); | 130 | return this->index(day, 0); |
131 | } | 131 | } |
132 | 132 | ||
133 | int EventTreeModel::rowCount(const QModelIndex &parent) const | 133 | int PeriodDayEventModel::rowCount(const QModelIndex &parent) const |
134 | { | 134 | { |
135 | if (!parent.isValid()) { | 135 | if (!parent.isValid()) { |
136 | return mViewLength; | 136 | return mViewLength; |
@@ -141,7 +141,7 @@ int EventTreeModel::rowCount(const QModelIndex &parent) const | |||
141 | return partitionedEvents[day].size(); | 141 | return partitionedEvents[day].size(); |
142 | } | 142 | } |
143 | 143 | ||
144 | int EventTreeModel::columnCount(const QModelIndex &parent) const | 144 | int PeriodDayEventModel::columnCount(const QModelIndex &parent) const |
145 | { | 145 | { |
146 | if (!parent.isValid()) { | 146 | if (!parent.isValid()) { |
147 | return 1; | 147 | return 1; |
@@ -150,7 +150,7 @@ int EventTreeModel::columnCount(const QModelIndex &parent) const | |||
150 | return eventModel->columnCount(); | 150 | return eventModel->columnCount(); |
151 | } | 151 | } |
152 | 152 | ||
153 | QVariant EventTreeModel::data(const QModelIndex &id, int role) const | 153 | QVariant PeriodDayEventModel::data(const QModelIndex &id, int role) const |
154 | { | 154 | { |
155 | if (id.internalId() == DAY_ID) { | 155 | if (id.internalId() == DAY_ID) { |
156 | auto day = id.row(); | 156 | auto day = id.row(); |
@@ -211,7 +211,7 @@ QVariant EventTreeModel::data(const QModelIndex &id, int role) const | |||
211 | } | 211 | } |
212 | } | 212 | } |
213 | 213 | ||
214 | QHash<int, QByteArray> EventTreeModel::roleNames() const | 214 | QHash<int, QByteArray> PeriodDayEventModel::roleNames() const |
215 | { | 215 | { |
216 | QHash<int, QByteArray> roles; | 216 | QHash<int, QByteArray> roles; |
217 | 217 | ||
@@ -224,12 +224,12 @@ QHash<int, QByteArray> EventTreeModel::roleNames() const | |||
224 | return roles; | 224 | return roles; |
225 | } | 225 | } |
226 | 226 | ||
227 | QDate EventTreeModel::viewStart() const | 227 | QDate PeriodDayEventModel::viewStart() const |
228 | { | 228 | { |
229 | return mViewStart; | 229 | return mViewStart; |
230 | } | 230 | } |
231 | 231 | ||
232 | void EventTreeModel::setViewStart(QDate start) | 232 | void PeriodDayEventModel::setViewStart(QDate start) |
233 | { | 233 | { |
234 | if (!start.isValid()) { | 234 | if (!start.isValid()) { |
235 | SinkWarning() << "Passed an invalid starting date in setViewStart, ignoring..."; | 235 | SinkWarning() << "Passed an invalid starting date in setViewStart, ignoring..."; |
@@ -240,17 +240,17 @@ void EventTreeModel::setViewStart(QDate start) | |||
240 | partitionData(); | 240 | partitionData(); |
241 | } | 241 | } |
242 | 242 | ||
243 | void EventTreeModel::setViewStart(QVariant start) | 243 | void PeriodDayEventModel::setViewStart(QVariant start) |
244 | { | 244 | { |
245 | setViewStart(start.toDate()); | 245 | setViewStart(start.toDate()); |
246 | } | 246 | } |
247 | 247 | ||
248 | int EventTreeModel::viewLength() const | 248 | int PeriodDayEventModel::viewLength() const |
249 | { | 249 | { |
250 | return mViewLength; | 250 | return mViewLength; |
251 | } | 251 | } |
252 | 252 | ||
253 | void EventTreeModel::setViewLength(int length) | 253 | void PeriodDayEventModel::setViewLength(int length) |
254 | { | 254 | { |
255 | mViewLength = std::move(length); | 255 | mViewLength = std::move(length); |
256 | partitionData(); | 256 | partitionData(); |
diff --git a/framework/src/domain/eventtreemodel.h b/framework/src/domain/perioddayeventmodel.h index 516410ee..cd26fe46 100644 --- a/framework/src/domain/eventtreemodel.h +++ b/framework/src/domain/perioddayeventmodel.h | |||
@@ -30,6 +30,25 @@ | |||
30 | 30 | ||
31 | #include <limits> | 31 | #include <limits> |
32 | 32 | ||
33 | // Facility used to get a restricted view into a Sink model comprised of | ||
34 | // events, partitioned according to the day the events take place. | ||
35 | // | ||
36 | // Model Format | ||
37 | // ============ | ||
38 | // | ||
39 | // Day 0 | ||
40 | // |--- Event 0 starting at `viewStart + 0d` | ||
41 | // |--- Event 1 starting at `viewStart + 0d` | ||
42 | // '--- Event 2 starting at `viewStart + 0d` | ||
43 | // Day 1 | ||
44 | // '--- Event 0 starting at `viewStart + 1d` | ||
45 | // Day 2 | ||
46 | // Day 3 | ||
47 | // |--- Event 0 starting at `viewStart + 3d` | ||
48 | // '--- Event 1 starting at `viewStart + 3d` | ||
49 | // Day 4 | ||
50 | // ⋮ | ||
51 | // | ||
33 | // Implementation notes | 52 | // Implementation notes |
34 | // ==================== | 53 | // ==================== |
35 | // | 54 | // |
@@ -57,7 +76,7 @@ | |||
57 | // | '--- List of event pointers for that day | 76 | // | '--- List of event pointers for that day |
58 | // '--- Partition / day | 77 | // '--- Partition / day |
59 | // | 78 | // |
60 | class EventTreeModel : public QAbstractItemModel | 79 | class PeriodDayEventModel : public QAbstractItemModel |
61 | { | 80 | { |
62 | Q_OBJECT | 81 | Q_OBJECT |
63 | 82 | ||
@@ -76,8 +95,8 @@ public: | |||
76 | Duration, | 95 | Duration, |
77 | }; | 96 | }; |
78 | Q_ENUM(Roles); | 97 | Q_ENUM(Roles); |
79 | EventTreeModel(QObject *parent = nullptr); | 98 | PeriodDayEventModel(QObject *parent = nullptr); |
80 | ~EventTreeModel() = default; | 99 | ~PeriodDayEventModel() = default; |
81 | 100 | ||
82 | QModelIndex index(int row, int column, const QModelIndex &parent = {}) const override; | 101 | QModelIndex index(int row, int column, const QModelIndex &parent = {}) const override; |
83 | QModelIndex parent(const QModelIndex &index) const override; | 102 | QModelIndex parent(const QModelIndex &index) const override; |