LogsModel doesn't use the Engine singleton any more

This commit is contained in:
Michael Zanetti 2018-08-31 20:09:47 +02:00
parent 7a960de69a
commit e529cc87f0
6 changed files with 32 additions and 2 deletions

View File

@ -7,7 +7,20 @@
LogsModel::LogsModel(QObject *parent) : QAbstractListModel(parent)
{
connect(Engine::instance()->logManager(), &LogManager::logEntryReceived, this, &LogsModel::newLogEntryReceived);
}
Engine *LogsModel::engine() const
{
return m_engine;
}
void LogsModel::setEngine(Engine *engine)
{
if (m_engine != engine) {
m_engine = engine;
connect(engine->logManager(), &LogManager::logEntryReceived, this, &LogsModel::newLogEntryReceived);
emit engineChanged();
}
}
bool LogsModel::busy() const
@ -132,6 +145,10 @@ void LogsModel::notificationReceived(const QVariantMap &data)
void LogsModel::update()
{
if (!m_engine) {
qWarning() << "LogsModel: Can't update, no engine set";
return;
}
if (m_busy) {
return;
}
@ -157,7 +174,7 @@ void LogsModel::update()
timeFilter.insert("endDate", m_endTime.toSecsSinceEpoch());
timeFilters.append(timeFilter);
params.insert("timeFilters", timeFilters);
Engine::instance()->jsonRpcClient()->sendCommand("Logging.GetLogEntries", params, this, "logsReply");
m_engine->jsonRpcClient()->sendCommand("Logging.GetLogEntries", params, this, "logsReply");
}
void LogsModel::fetchEarlier(int hours)

View File

@ -6,9 +6,13 @@
#include "jsonrpc/jsonhandler.h"
#include "types/logentry.h"
class Engine;
class LogsModel : public QAbstractListModel
{
Q_OBJECT
Q_PROPERTY(Engine* engine READ engine WRITE setEngine NOTIFY engineChanged)
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)
@ -29,6 +33,9 @@ public:
};
explicit LogsModel(QObject *parent = nullptr);
Engine* engine() const;
void setEngine(Engine* engine);
bool busy() const;
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role) const override;
@ -54,6 +61,7 @@ public:
Q_INVOKABLE void notificationReceived(const QVariantMap &data);
signals:
void engineChanged();
void busyChanged();
void liveChanged();
void countChanged();
@ -73,6 +81,7 @@ private slots:
void newLogEntryReceived(const QVariantMap &data);
protected:
Engine *m_engine;
QList<LogEntry*> m_list;
QString m_deviceId;
QStringList m_typeIds;

View File

@ -14,6 +14,7 @@ GenericDevicePage {
text: qsTr("This button has been pressed %1 times in the last %2 days.")
logsModel: LogsModel {
engine: Engine
deviceId: root.device.id
live: true
typeIds: {

View File

@ -13,6 +13,7 @@ GenericDevicePage {
text: qsTr("This event has appeared %1 times in the last %2 days.")
logsModel: LogsModel {
engine: Engine
deviceId: root.device.id
live: true
Component.onCompleted: update()

View File

@ -28,6 +28,7 @@ Page {
LogsModel {
id: logsModel
engine: Engine
deviceId: root.device.id
live: true
Component.onCompleted: update()

View File

@ -25,6 +25,7 @@ Page {
LogsModel {
id: logsModel
engine: Engine
startTime: {
var date = new Date();
date.setHours(new Date().getHours() - 2);