Browse Source

qml: make listmodel item count a property for channels and transactions

master
Sander van Grieken 3 years ago
parent
commit
6c410c0548
  1. 4
      electrum/gui/qml/components/Channels.qml
  2. 2
      electrum/gui/qml/components/History.qml
  3. 11
      electrum/gui/qml/qechannellistmodel.py
  4. 8
      electrum/gui/qml/qetransactionlistmodel.py

4
electrum/gui/qml/components/Channels.qml

@ -123,12 +123,12 @@ Pane {
ScrollIndicator.vertical: ScrollIndicator { } ScrollIndicator.vertical: ScrollIndicator { }
Label { Label {
visible: Daemon.currentWallet.channelModel.rowCount() == 0 visible: Daemon.currentWallet.channelModel.count == 0
anchors.centerIn: parent anchors.centerIn: parent
width: listview.width * 4/5 width: listview.width * 4/5
font.pixelSize: constants.fontSizeXXLarge font.pixelSize: constants.fontSizeXXLarge
color: constants.mutedForeground 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 wrapMode: Text.Wrap
horizontalAlignment: Text.AlignHCenter horizontalAlignment: Text.AlignHCenter
} }

2
electrum/gui/qml/components/History.qml

@ -83,7 +83,7 @@ Pane {
ScrollIndicator.vertical: ScrollIndicator { } ScrollIndicator.vertical: ScrollIndicator { }
Label { Label {
visible: Daemon.currentWallet.historyModel.rowCount() == 0 visible: Daemon.currentWallet.historyModel.count == 0
anchors.centerIn: parent anchors.centerIn: parent
width: listview.width * 4/5 width: listview.width * 4/5
font.pixelSize: constants.fontSizeXXLarge font.pixelSize: constants.fontSizeXXLarge

11
electrum/gui/qml/qechannellistmodel.py

@ -46,6 +46,12 @@ class QEChannelListModel(QAbstractListModel, QtEventListener):
def rowCount(self, index): def rowCount(self, index):
return len(self.channels) 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): def roleNames(self):
return self._ROLE_MAP return self._ROLE_MAP
@ -113,6 +119,8 @@ class QEChannelListModel(QAbstractListModel, QtEventListener):
self.channels = channels self.channels = channels
self.endInsertRows() self.endInsertRows()
self.countChanged.emit()
def on_channel_updated(self, channel): def on_channel_updated(self, channel):
i = 0 i = 0
for c in self.channels: for c in self.channels:
@ -141,6 +149,8 @@ class QEChannelListModel(QAbstractListModel, QtEventListener):
self.beginInsertRows(QModelIndex(), 0, 0) self.beginInsertRows(QModelIndex(), 0, 0)
self.channels.insert(0,item) self.channels.insert(0,item)
self.endInsertRows() self.endInsertRows()
self.countChanged.emit()
return
@pyqtSlot(str) @pyqtSlot(str)
def remove_channel(self, cid): def remove_channel(self, cid):
@ -152,5 +162,6 @@ class QEChannelListModel(QAbstractListModel, QtEventListener):
self.beginRemoveRows(QModelIndex(), i, i) self.beginRemoveRows(QModelIndex(), i, i)
self.channels.remove(channel) self.channels.remove(channel)
self.endRemoveRows() self.endRemoveRows()
self.countChanged.emit()
return return
i = i + 1 i = i + 1

8
electrum/gui/qml/qetransactionlistmodel.py

@ -46,6 +46,12 @@ class QETransactionListModel(QAbstractListModel, QtEventListener):
def rowCount(self, index): def rowCount(self, index):
return len(self.tx_history) 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): def roleNames(self):
return self._ROLE_MAP return self._ROLE_MAP
@ -147,6 +153,8 @@ class QETransactionListModel(QAbstractListModel, QtEventListener):
self.tx_history.reverse() self.tx_history.reverse()
self.endInsertRows() self.endInsertRows()
self.countChanged.emit()
def on_tx_verified(self, txid, info): def on_tx_verified(self, txid, info):
i = 0 i = 0
for tx in self.tx_history: for tx in self.tx_history:

Loading…
Cancel
Save