summaryrefslogtreecommitdiff
path: root/event_list.h
blob: 1c50c590b35206750202f2f521cf724d560b03d4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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