From 6c410c05483bdb3a59afcb07241c382a8831d190 Mon Sep 17 00:00:00 2001 From: Sander van Grieken Date: Fri, 6 Jan 2023 10:58:47 +0100 Subject: [PATCH] qml: make listmodel item count a property for channels and transactions --- electrum/gui/qml/components/Channels.qml | 4 ++-- electrum/gui/qml/components/History.qml | 2 +- electrum/gui/qml/qechannellistmodel.py | 11 +++++++++++ electrum/gui/qml/qetransactionlistmodel.py | 8 ++++++++ 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/electrum/gui/qml/components/Channels.qml b/electrum/gui/qml/components/Channels.qml index 36f3c742e..5f8dcee39 100644 --- a/electrum/gui/qml/components/Channels.qml +++ b/electrum/gui/qml/components/Channels.qml @@ -123,12 +123,12 @@ Pane { ScrollIndicator.vertical: ScrollIndicator { } Label { - visible: Daemon.currentWallet.channelModel.rowCount() == 0 + visible: Daemon.currentWallet.channelModel.count == 0 anchors.centerIn: parent width: listview.width * 4/5 font.pixelSize: constants.fontSizeXXLarge color: constants.mutedForeground - text: qsTr('You have no Lightning channels yet in this wallet') + text: qsTr('No Lightning channels yet in this wallet') wrapMode: Text.Wrap horizontalAlignment: Text.AlignHCenter } diff --git a/electrum/gui/qml/components/History.qml b/electrum/gui/qml/components/History.qml index 23b5a7fb2..3c01a2563 100644 --- a/electrum/gui/qml/components/History.qml +++ b/electrum/gui/qml/components/History.qml @@ -83,7 +83,7 @@ Pane { ScrollIndicator.vertical: ScrollIndicator { } Label { - visible: Daemon.currentWallet.historyModel.rowCount() == 0 + visible: Daemon.currentWallet.historyModel.count == 0 anchors.centerIn: parent width: listview.width * 4/5 font.pixelSize: constants.fontSizeXXLarge diff --git a/electrum/gui/qml/qechannellistmodel.py b/electrum/gui/qml/qechannellistmodel.py index c2d0d8aaf..4d33eff7c 100644 --- a/electrum/gui/qml/qechannellistmodel.py +++ b/electrum/gui/qml/qechannellistmodel.py @@ -46,6 +46,12 @@ class QEChannelListModel(QAbstractListModel, QtEventListener): def rowCount(self, index): return len(self.channels) + # also expose rowCount as a property + countChanged = pyqtSignal() + @pyqtProperty(int, notify=countChanged) + def count(self): + return len(self.channels) + def roleNames(self): return self._ROLE_MAP @@ -113,6 +119,8 @@ class QEChannelListModel(QAbstractListModel, QtEventListener): self.channels = channels self.endInsertRows() + self.countChanged.emit() + def on_channel_updated(self, channel): i = 0 for c in self.channels: @@ -141,6 +149,8 @@ class QEChannelListModel(QAbstractListModel, QtEventListener): self.beginInsertRows(QModelIndex(), 0, 0) self.channels.insert(0,item) self.endInsertRows() + self.countChanged.emit() + return @pyqtSlot(str) def remove_channel(self, cid): @@ -152,5 +162,6 @@ class QEChannelListModel(QAbstractListModel, QtEventListener): self.beginRemoveRows(QModelIndex(), i, i) self.channels.remove(channel) self.endRemoveRows() + self.countChanged.emit() return i = i + 1 diff --git a/electrum/gui/qml/qetransactionlistmodel.py b/electrum/gui/qml/qetransactionlistmodel.py index 80a1bc7a7..b56001cad 100644 --- a/electrum/gui/qml/qetransactionlistmodel.py +++ b/electrum/gui/qml/qetransactionlistmodel.py @@ -46,6 +46,12 @@ class QETransactionListModel(QAbstractListModel, QtEventListener): def rowCount(self, index): return len(self.tx_history) + # also expose rowCount as a property + countChanged = pyqtSignal() + @pyqtProperty(int, notify=countChanged) + def count(self): + return len(self.tx_history) + def roleNames(self): return self._ROLE_MAP @@ -147,6 +153,8 @@ class QETransactionListModel(QAbstractListModel, QtEventListener): self.tx_history.reverse() self.endInsertRows() + self.countChanged.emit() + def on_tx_verified(self, txid, info): i = 0 for tx in self.tx_history: