2021-09-01 17:13:51 +02:00
|
|
|
#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:
|
2021-09-05 21:16:46 +02:00
|
|
|
int insert(const QString& tag = {}, const int time = -1);
|
|
|
|
bool removeRows(int row, int count = 1, const QModelIndex& parent = {});
|
2021-09-01 17:13:51 +02:00
|
|
|
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 };
|
|
|
|
|
|
|
|
QJsonObject tags;
|
2021-09-05 21:16:46 +02:00
|
|
|
QStringList tagsOrder;
|
2021-09-01 17:13:51 +02:00
|
|
|
QList<Event> events;
|
|
|
|
|
|
|
|
int find(long long time) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|