From 7339cc0c0a0c63576f38f0bc96c15f28967b92d1 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Thu, 30 Mar 2017 13:51:09 +0200 Subject: Indicate if the outbox is not empty ..we could of course also just hide the outbox if empty. --- components/package/contents/ui/Outbox.qml | 13 ++++++++++++- framework/domain/outboxmodel.cpp | 6 ++++++ framework/domain/outboxmodel.h | 5 +++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/components/package/contents/ui/Outbox.qml b/components/package/contents/ui/Outbox.qml index 1b48aa6f..1f0400d3 100644 --- a/components/package/contents/ui/Outbox.qml +++ b/components/package/contents/ui/Outbox.qml @@ -40,6 +40,17 @@ Button { id: outboxController } + KubeFramework.OutboxModel { + id: outboxModel + } + + states: [ + State { + name: "noempty"; when: outboxModel.count > 0 + PropertyChanges { target: root; text: "outbox (" + outboxModel.count + ")" } + } + ] + Popup { id: dialog @@ -65,7 +76,7 @@ Button { width: parent.width height: count * Kirigami.Units.gridUnit * 3 - model: KubeFramework.OutboxModel {} + model: outboxModel delegate: Rectangle { id: delegateRoot diff --git a/framework/domain/outboxmodel.cpp b/framework/domain/outboxmodel.cpp index b82c1c6b..68a0e8be 100644 --- a/framework/domain/outboxmodel.cpp +++ b/framework/domain/outboxmodel.cpp @@ -40,6 +40,8 @@ OutboxModel::OutboxModel(QObject *parent) query.request(); query.request(); runQuery(query); + connect(this, &QAbstractItemModel::rowsInserted, this, &OutboxModel::countChanged); + connect(this, &QAbstractItemModel::rowsRemoved, this, &OutboxModel::countChanged); } OutboxModel::~OutboxModel() @@ -96,3 +98,7 @@ void OutboxModel::runQuery(const Sink::Query &query) setSourceModel(m_model.data()); } +int OutboxModel::count() const +{ + return rowCount(); +} diff --git a/framework/domain/outboxmodel.h b/framework/domain/outboxmodel.h index 86821bc2..4e226223 100644 --- a/framework/domain/outboxmodel.h +++ b/framework/domain/outboxmodel.h @@ -30,6 +30,7 @@ class OutboxModel : public QSortFilterProxyModel { Q_OBJECT + Q_PROPERTY (int count READ count NOTIFY countChanged) public: enum Status { PendingStatus, @@ -58,6 +59,10 @@ public: void runQuery(const Sink::Query &query); + int count() const; +signals: + void countChanged(); + private: QSharedPointer m_model; }; -- cgit v1.2.3