LogsModel doesn't use the Engine singleton any more
This commit is contained in:
parent
7a960de69a
commit
e529cc87f0
@ -7,7 +7,20 @@
|
|||||||
|
|
||||||
LogsModel::LogsModel(QObject *parent) : QAbstractListModel(parent)
|
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
|
bool LogsModel::busy() const
|
||||||
@ -132,6 +145,10 @@ void LogsModel::notificationReceived(const QVariantMap &data)
|
|||||||
|
|
||||||
void LogsModel::update()
|
void LogsModel::update()
|
||||||
{
|
{
|
||||||
|
if (!m_engine) {
|
||||||
|
qWarning() << "LogsModel: Can't update, no engine set";
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (m_busy) {
|
if (m_busy) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -157,7 +174,7 @@ void LogsModel::update()
|
|||||||
timeFilter.insert("endDate", m_endTime.toSecsSinceEpoch());
|
timeFilter.insert("endDate", m_endTime.toSecsSinceEpoch());
|
||||||
timeFilters.append(timeFilter);
|
timeFilters.append(timeFilter);
|
||||||
params.insert("timeFilters", timeFilters);
|
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)
|
void LogsModel::fetchEarlier(int hours)
|
||||||
|
|||||||
@ -6,9 +6,13 @@
|
|||||||
#include "jsonrpc/jsonhandler.h"
|
#include "jsonrpc/jsonhandler.h"
|
||||||
#include "types/logentry.h"
|
#include "types/logentry.h"
|
||||||
|
|
||||||
|
class Engine;
|
||||||
|
|
||||||
class LogsModel : public QAbstractListModel
|
class LogsModel : public QAbstractListModel
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(Engine* engine READ engine WRITE setEngine NOTIFY engineChanged)
|
||||||
|
|
||||||
Q_PROPERTY(bool busy READ busy NOTIFY busyChanged)
|
Q_PROPERTY(bool busy READ busy NOTIFY busyChanged)
|
||||||
Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
|
Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
|
||||||
Q_PROPERTY(QString deviceId READ deviceId WRITE setDeviceId NOTIFY deviceIdChanged)
|
Q_PROPERTY(QString deviceId READ deviceId WRITE setDeviceId NOTIFY deviceIdChanged)
|
||||||
@ -29,6 +33,9 @@ public:
|
|||||||
};
|
};
|
||||||
explicit LogsModel(QObject *parent = nullptr);
|
explicit LogsModel(QObject *parent = nullptr);
|
||||||
|
|
||||||
|
Engine* engine() const;
|
||||||
|
void setEngine(Engine* engine);
|
||||||
|
|
||||||
bool busy() const;
|
bool busy() const;
|
||||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||||
QVariant data(const QModelIndex &index, int role) const override;
|
QVariant data(const QModelIndex &index, int role) const override;
|
||||||
@ -54,6 +61,7 @@ public:
|
|||||||
Q_INVOKABLE void notificationReceived(const QVariantMap &data);
|
Q_INVOKABLE void notificationReceived(const QVariantMap &data);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
void engineChanged();
|
||||||
void busyChanged();
|
void busyChanged();
|
||||||
void liveChanged();
|
void liveChanged();
|
||||||
void countChanged();
|
void countChanged();
|
||||||
@ -73,6 +81,7 @@ private slots:
|
|||||||
void newLogEntryReceived(const QVariantMap &data);
|
void newLogEntryReceived(const QVariantMap &data);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
Engine *m_engine;
|
||||||
QList<LogEntry*> m_list;
|
QList<LogEntry*> m_list;
|
||||||
QString m_deviceId;
|
QString m_deviceId;
|
||||||
QStringList m_typeIds;
|
QStringList m_typeIds;
|
||||||
|
|||||||
@ -14,6 +14,7 @@ GenericDevicePage {
|
|||||||
text: qsTr("This button has been pressed %1 times in the last %2 days.")
|
text: qsTr("This button has been pressed %1 times in the last %2 days.")
|
||||||
|
|
||||||
logsModel: LogsModel {
|
logsModel: LogsModel {
|
||||||
|
engine: Engine
|
||||||
deviceId: root.device.id
|
deviceId: root.device.id
|
||||||
live: true
|
live: true
|
||||||
typeIds: {
|
typeIds: {
|
||||||
|
|||||||
@ -13,6 +13,7 @@ GenericDevicePage {
|
|||||||
text: qsTr("This event has appeared %1 times in the last %2 days.")
|
text: qsTr("This event has appeared %1 times in the last %2 days.")
|
||||||
|
|
||||||
logsModel: LogsModel {
|
logsModel: LogsModel {
|
||||||
|
engine: Engine
|
||||||
deviceId: root.device.id
|
deviceId: root.device.id
|
||||||
live: true
|
live: true
|
||||||
Component.onCompleted: update()
|
Component.onCompleted: update()
|
||||||
|
|||||||
@ -28,6 +28,7 @@ Page {
|
|||||||
|
|
||||||
LogsModel {
|
LogsModel {
|
||||||
id: logsModel
|
id: logsModel
|
||||||
|
engine: Engine
|
||||||
deviceId: root.device.id
|
deviceId: root.device.id
|
||||||
live: true
|
live: true
|
||||||
Component.onCompleted: update()
|
Component.onCompleted: update()
|
||||||
|
|||||||
@ -25,6 +25,7 @@ Page {
|
|||||||
|
|
||||||
LogsModel {
|
LogsModel {
|
||||||
id: logsModel
|
id: logsModel
|
||||||
|
engine: Engine
|
||||||
startTime: {
|
startTime: {
|
||||||
var date = new Date();
|
var date = new Date();
|
||||||
date.setHours(new Date().getHours() - 2);
|
date.setHours(new Date().getHours() - 2);
|
||||||
|
|||||||
Reference in New Issue
Block a user