diff options
Diffstat (limited to 'framework/src/domain/eventtreemodel.h')
-rw-r--r-- | framework/src/domain/eventtreemodel.h | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/framework/src/domain/eventtreemodel.h b/framework/src/domain/eventtreemodel.h new file mode 100644 index 00000000..daa45a7b --- /dev/null +++ b/framework/src/domain/eventtreemodel.h | |||
@@ -0,0 +1,98 @@ | |||
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 <QMutex> | ||
28 | #include <QSharedPointer> | ||
29 | #include <QVector> | ||
30 | |||
31 | // Implementation notes | ||
32 | // ==================== | ||
33 | // | ||
34 | // On the model side | ||
35 | // ----------------- | ||
36 | // | ||
37 | // Columns are never used. | ||
38 | // | ||
39 | // Top-level items just contains the ".events" attribute, and their rows | ||
40 | // correspond to their day of week. In that case the internalId contains | ||
41 | // DAY_ID. | ||
42 | // | ||
43 | // Direct children are events, and their rows corresponds to their index in | ||
44 | // their partition. In that case no internalId / internalPointer is used. | ||
45 | // | ||
46 | // Internally: | ||
47 | // ----------- | ||
48 | // | ||
49 | // On construction and on dataChanged, all events are processed and partitioned | ||
50 | // in partitionedEvents: | ||
51 | // | ||
52 | // QVector< QList<QSharedPointer<Event> > | ||
53 | // ~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
54 | // | | | ||
55 | // | '--- List of event pointers for that day | ||
56 | // '--- Partition / day | ||
57 | // | ||
58 | class EventTreeModel : public QAbstractItemModel | ||
59 | { | ||
60 | Q_OBJECT | ||
61 | |||
62 | public: | ||
63 | using Event = Sink::ApplicationDomain::Event; | ||
64 | |||
65 | enum Roles | ||
66 | { | ||
67 | Events = Qt::UserRole + 1, | ||
68 | Summary, | ||
69 | Description, | ||
70 | StartTime, | ||
71 | Duration, | ||
72 | }; | ||
73 | Q_ENUM(Roles); | ||
74 | EventTreeModel(QObject *parent = nullptr); | ||
75 | ~EventTreeModel() = default; | ||
76 | |||
77 | QModelIndex index(int row, int column, const QModelIndex &parent = {}) const override; | ||
78 | QModelIndex parent(const QModelIndex &index) const override; | ||
79 | |||
80 | int rowCount(const QModelIndex &parent) const override; | ||
81 | int columnCount(const QModelIndex &parent) const override; | ||
82 | |||
83 | //bool hasChildren(const QModelIndex &parent) const override; | ||
84 | |||
85 | QVariant data(const QModelIndex &index, int role) const override; | ||
86 | |||
87 | QHash<int, QByteArray> roleNames() const override; | ||
88 | |||
89 | private: | ||
90 | void partitionData(); | ||
91 | |||
92 | QSharedPointer<QAbstractItemModel> eventModel; | ||
93 | QVector<QList<QSharedPointer<Event>>> partitionedEvents; | ||
94 | |||
95 | QMutex partitioningMutex; | ||
96 | |||
97 | static const constexpr quintptr DAY_ID = 7; | ||
98 | }; | ||