diff options
Diffstat (limited to 'framework/src/domain/eventtreemodel.h')
-rw-r--r-- | framework/src/domain/eventtreemodel.h | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/framework/src/domain/eventtreemodel.h b/framework/src/domain/eventtreemodel.h new file mode 100644 index 00000000..ac126640 --- /dev/null +++ b/framework/src/domain/eventtreemodel.h | |||
@@ -0,0 +1,95 @@ | |||
1 | /* | ||
2 | Copyright (c) 2016 Michael Bohlender <michael.bohlender@kdemail.net> | ||
3 | Copyright (c) 2016 Christian Mollekopf <mollekopf@kolabsys.com> | ||
4 | |||
5 | This library is free software; you can redistribute it and/or modify it | ||
6 | under the terms of the GNU Library General Public License as published by | ||
7 | the Free Software Foundation; either version 2 of the License, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | This library is distributed in the hope that it will be useful, but WITHOUT | ||
11 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
12 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public | ||
13 | License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Library General Public License | ||
16 | along with this library; see the file COPYING.LIB. If not, write to the | ||
17 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
18 | 02110-1301, USA. | ||
19 | */ | ||
20 | |||
21 | #pragma once | ||
22 | |||
23 | #include <sink/applicationdomaintype.h> | ||
24 | |||
25 | #include <QAbstractItemModel> | ||
26 | #include <QList> | ||
27 | #include <QSharedPointer> | ||
28 | #include <QVector> | ||
29 | |||
30 | // Implementation notes | ||
31 | // ==================== | ||
32 | // | ||
33 | // On the model side | ||
34 | // ----------------- | ||
35 | // | ||
36 | // Columns are never used. | ||
37 | // | ||
38 | // Top-level items just contains the ".events" attribute, and their rows | ||
39 | // correspond to their day of week. In that case the internalId contains | ||
40 | // DAY_ID. | ||
41 | // | ||
42 | // Direct children are events, and their rows corresponds to their index in | ||
43 | // their partition. In that case no internalId / internalPointer is used. | ||
44 | // | ||
45 | // Internally: | ||
46 | // ----------- | ||
47 | // | ||
48 | // On construction and on dataChanged, all events are processed and partitioned | ||
49 | // in partitionedEvents: | ||
50 | // | ||
51 | // QVector< QList<QSharedPointer<Event> > | ||
52 | // ~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
53 | // | | | ||
54 | // | '--- List of event pointers for that day | ||
55 | // '--- Partition / day | ||
56 | // | ||
57 | class EventTreeModel : public QAbstractItemModel | ||
58 | { | ||
59 | Q_OBJECT | ||
60 | |||
61 | public: | ||
62 | using Event = Sink::ApplicationDomain::Event; | ||
63 | |||
64 | enum Roles | ||
65 | { | ||
66 | Events = Qt::UserRole + 1, | ||
67 | Summary, | ||
68 | Description, | ||
69 | StartTime, | ||
70 | Duration, | ||
71 | }; | ||
72 | Q_ENUM(Roles); | ||
73 | EventTreeModel(QObject *parent = nullptr); | ||
74 | ~EventTreeModel() = default; | ||
75 | |||
76 | QModelIndex index(int row, int column, const QModelIndex &parent = {}) const override; | ||
77 | QModelIndex parent(const QModelIndex &index) const override; | ||
78 | |||
79 | int rowCount(const QModelIndex &parent) const override; | ||
80 | int columnCount(const QModelIndex &parent) const override; | ||
81 | |||
82 | bool hasChildren(const QModelIndex &parent) const override; | ||
83 | |||
84 | QVariant data(const QModelIndex &index, int role) const override; | ||
85 | |||
86 | QHash<int, QByteArray> roleNames() const override; | ||
87 | |||
88 | private: | ||
89 | void partitionData(); | ||
90 | |||
91 | QSharedPointer<QAbstractItemModel> eventModel; | ||
92 | QVector<QList<QSharedPointer<Event>>> partitionedEvents; | ||
93 | |||
94 | static const constexpr quintptr DAY_ID = 7; | ||
95 | }; | ||