diff options
| author | Timotej Lazar <timotej.lazar@araneo.si> | 2021-09-01 17:13:51 +0200 |
|---|---|---|
| committer | Timotej Lazar <timotej.lazar@araneo.si> | 2021-09-16 20:33:05 +0200 |
| commit | cb76fedcbc8e419e2b945baa56ac3f986a9e79a3 (patch) | |
| tree | e29be52e4372d3d6e5bfe7056d7af1e1cc0ae2bc /event_list.h | |
| parent | e9b70c585c6bf1fa68a594a8755d90c017e6260c (diff) | |
Implement event model in C++
Filtering events in JS is too slow with >20,000 events. This moves the
event data model into C++.
Diffstat (limited to 'event_list.h')
| -rw-r--r-- | event_list.h | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/event_list.h b/event_list.h new file mode 100644 index 0000000..1c50c59 --- /dev/null +++ b/event_list.h @@ -0,0 +1,46 @@ +#ifndef EVENT_LIST_H +#define EVENT_LIST_H + +#include <QAbstractListModel> +#include <QJsonObject> +#include <QStringList> +#include <qqml.h> + +class EventList : public QAbstractListModel +{ + Q_OBJECT + Q_PROPERTY(QStringList tagsOrder MEMBER tagsOrder NOTIFY tagsChanged) + Q_PROPERTY(QJsonObject tags MEMBER tags NOTIFY tagsChanged) + QML_ELEMENT +public: + Qt::ItemFlags flags(const QModelIndex& index) const; + QHash<int, QByteArray> roleNames() const; + int rowCount(const QModelIndex& parent = {}) const; + QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const; + bool setData(const QModelIndex& index, const QVariant& value, int role); + +public slots: + int insert(const int time = -1); + bool removeRows(int row, int count = 1, const QModelIndex &parent = {}); + void load(const QJsonObject& json); + QJsonObject save() const; + +signals: + void tagsChanged(); + +private: + struct Event { + long long time; + QString tag{}; + QVariantMap values{}; + }; + enum Role { Time = Qt::UserRole + 1, Tag, Values }; + + QStringList tagsOrder; + QJsonObject tags; + QList<Event> events; + + int find(long long time) const; +}; + +#endif |
