This repository has been archived on 2026-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
2018-06-26 04:14:19 +02:00

85 lines
2.3 KiB
C++

#ifndef LOGSMODEL_H
#define LOGSMODEL_H
#include <QAbstractListModel>
#include "jsonrpc/jsonhandler.h"
#include "types/logentry.h"
class LogsModel : public QAbstractListModel
{
Q_OBJECT
Q_PROPERTY(bool busy READ busy NOTIFY busyChanged)
Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
Q_PROPERTY(QString deviceId READ deviceId WRITE setDeviceId NOTIFY deviceIdChanged)
Q_PROPERTY(QStringList typeIds READ typeIds WRITE setTypeIds NOTIFY typeIdsChanged)
Q_PROPERTY(QDateTime startTime READ startTime WRITE setStartTime NOTIFY startTimeChanged)
Q_PROPERTY(QDateTime endTime READ endTime WRITE setEndTime NOTIFY endTimeChanged)
Q_PROPERTY(bool live READ live WRITE setLive NOTIFY liveChanged)
public:
enum Roles {
RoleTimestamp,
RoleValue,
RoleDeviceId,
RoleTypeId,
RoleSource,
RoleLoggingEventType
};
explicit LogsModel(QObject *parent = nullptr);
bool busy() const;
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role) const override;
QHash<int, QByteArray> roleNames() const override;
bool live() const;
void setLive(bool live);
QString deviceId() const;
void setDeviceId(const QString &deviceId);
QStringList typeIds() const;
void setTypeIds(const QStringList &typeIds);
QDateTime startTime() const;
void setStartTime(const QDateTime &startTime);
QDateTime endTime() const;
void setEndTime(const QDateTime &endTime);
Q_INVOKABLE LogEntry* get(int index) const;
Q_INVOKABLE void notificationReceived(const QVariantMap &data);
signals:
void busyChanged();
void liveChanged();
void countChanged();
void deviceIdChanged();
void typeIdsChanged();
void startTimeChanged();
void endTimeChanged();
public slots:
virtual void update();
private slots:
virtual void logsReply(const QVariantMap &data);
void newLogEntryReceived(const QVariantMap &data);
protected:
QList<LogEntry*> m_list;
QString m_deviceId;
QStringList m_typeIds;
QDateTime m_startTime = QDateTime::currentDateTime().addDays(-1);
QDateTime m_endTime = QDateTime::currentDateTime();
bool m_busy = false;
bool m_live = false;
};
#endif // LOGSMODEL_H