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) Q_PROPERTY(AWSClient* awsClient READ awsClient CONSTANT)
public: public:
static Engine *instance(); // static Engine *instance();
bool connected() const; bool connected() const;
QString connectedHost() 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 int LogsModelNg::rowCount(const QModelIndex &parent) const
{ {
Q_UNUSED(parent) Q_UNUSED(parent)
@ -122,6 +135,10 @@ void LogsModelNg::setEndTime(const QDateTime &endTime)
void LogsModelNg::update() void LogsModelNg::update()
{ {
if (!m_jsonRpcClient) {
qWarning() << "Cannot update. JsonRpcClient not set";
return;
}
if (m_busy) { if (m_busy) {
return; return;
} }
@ -206,7 +223,7 @@ void LogsModelNg::update()
timeFilter.insert("endDate", m_currentFetchEndTime.toSecsSinceEpoch()); timeFilter.insert("endDate", m_currentFetchEndTime.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_jsonRpcClient->sendCommand("Logging.GetLogEntries", params, this, "logsReply");
} }
void LogsModelNg::logsReply(const QVariantMap &data) void LogsModelNg::logsReply(const QVariantMap &data)

View File

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