1 | #ifndef EVENTMODEL_H |
---|
2 | #define EVENTMODEL_H |
---|
3 | |
---|
4 | #include <QAbstractItemModel> |
---|
5 | |
---|
6 | #include "event.h" |
---|
7 | |
---|
8 | class EventModel : public QAbstractItemModel |
---|
9 | { |
---|
10 | public: |
---|
11 | static const QString COMMA_SEPARATOR; |
---|
12 | public: |
---|
13 | EventModel(); |
---|
14 | QVariant data(const QModelIndex& index, int role) const; |
---|
15 | QModelIndex index(int row, int column, const QModelIndex & parent = QModelIndex()) const; |
---|
16 | QModelIndex parent ( const QModelIndex & index ) const; |
---|
17 | int columnCount ( const QModelIndex & parent = QModelIndex() ) const; |
---|
18 | int rowCount ( const QModelIndex & parent = QModelIndex() ) const; |
---|
19 | void loadEvents(const QDate &aDate, int aConferenceId); // loads Events from the DB |
---|
20 | void loadFavEvents(const QDate &aDate, int aConferenceId); // loads Favourite events from the DB |
---|
21 | void loadEventsByTrack(const QDate &aDate, int aConferenceId); // loads Events grouped by Track from the DB |
---|
22 | void loadSearchResultEvents(const QDate &aDate, int aConferenceId); |
---|
23 | // a method to force 'EventModel' emit signal 'dataChanged()' |
---|
24 | // a 'view', eg. 'TreeView' listens for this signal and redraws changed items(indexes) |
---|
25 | void emitDataChangedSignal(const QModelIndex &aTopLeft, const QModelIndex &aBottomRight); |
---|
26 | |
---|
27 | private: |
---|
28 | struct Group |
---|
29 | { |
---|
30 | Group(const QString & title, |
---|
31 | int firstEventIndex) : |
---|
32 | |
---|
33 | mTitle(title), |
---|
34 | mFirstEventIndex(firstEventIndex), |
---|
35 | mChildCount(0) |
---|
36 | {} |
---|
37 | |
---|
38 | QString mTitle; |
---|
39 | int mFirstEventIndex; |
---|
40 | int mChildCount; |
---|
41 | }; |
---|
42 | |
---|
43 | private: |
---|
44 | void createTimeGroups(); |
---|
45 | void createTrackGroups(); |
---|
46 | void clearModel(); |
---|
47 | |
---|
48 | private: |
---|
49 | QList<Event> mEvents; |
---|
50 | QList<Group> mGroups; |
---|
51 | QHash<int, int> mParents; |
---|
52 | }; |
---|
53 | |
---|
54 | #endif // EVENTMODEL_H |
---|
55 | |
---|