logsmodelng not using Engine singletong any more

This commit is contained in:
Michael Zanetti 2018-09-01 00:26:39 +02:00
parent 18f573fce2
commit c3dd7da60c
3 changed files with 26 additions and 2 deletions

View File

@ -46,7 +46,7 @@ class Engine : public QObject
Q_PROPERTY(AWSClient* awsClient READ awsClient CONSTANT)
public:
static Engine *instance();
// static Engine *instance();
bool connected() const;
QString connectedHost() const;

View File

@ -11,6 +11,19 @@ LogsModelNg::LogsModelNg(QObject *parent) : QAbstractListModel(parent)
}
JsonRpcClient *LogsModelNg::jsonRpcClient() const
{
return m_jsonRpcClient;
}
void LogsModelNg::setJsonRpcClient(JsonRpcClient *jsonRpcClient)
{
if (m_jsonRpcClient != jsonRpcClient) {
m_jsonRpcClient = jsonRpcClient;
emit jsonRpcClientChanged();
}
}
int LogsModelNg::rowCount(const QModelIndex &parent) const
{
Q_UNUSED(parent)
@ -122,6 +135,10 @@ void LogsModelNg::setEndTime(const QDateTime &endTime)
void LogsModelNg::update()
{
if (!m_jsonRpcClient) {
qWarning() << "Cannot update. JsonRpcClient not set";
return;
}
if (m_busy) {
return;
}
@ -206,7 +223,7 @@ void LogsModelNg::update()
timeFilter.insert("endDate", m_currentFetchEndTime.toSecsSinceEpoch());
timeFilters.append(timeFilter);
params.insert("timeFilters", timeFilters);
Engine::instance()->jsonRpcClient()->sendCommand("Logging.GetLogEntries", params, this, "logsReply");
m_jsonRpcClient->sendCommand("Logging.GetLogEntries", params, this, "logsReply");
}
void LogsModelNg::logsReply(const QVariantMap &data)

View File

@ -6,10 +6,12 @@
#include <QDateTime>
class LogEntry;
class JsonRpcClient;
class LogsModelNg : public QAbstractListModel
{
Q_OBJECT
Q_PROPERTY(JsonRpcClient* jsonRpcClient READ jsonRpcClient WRITE setJsonRpcClient NOTIFY jsonRpcClientChanged)
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 +31,9 @@ public:
explicit LogsModelNg(QObject *parent = nullptr);
JsonRpcClient *jsonRpcClient() const;
void setJsonRpcClient(JsonRpcClient* jsonRpcClient);
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role) const override;
QHash<int, QByteArray> roleNames() const override;
@ -59,10 +64,12 @@ signals:
void countChanged();
void startTimeChanged();
void endTimeChanged();
void jsonRpcClientChanged();
private:
QList<LogEntry*> m_list;
JsonRpcClient *m_jsonRpcClient = nullptr;
bool m_busy = false;
bool m_live = false;
QString m_deviceId;