1
0

qml: begone, you C-style for loops

how am I going to continue in the middle of the loop body if the i+=1 is at the end? :P
This commit is contained in:
SomberNight
2023-04-05 14:13:40 +00:00
parent e47059c96b
commit fcff4b7274
5 changed files with 14 additions and 41 deletions

View File

@@ -1,3 +1,4 @@
import itertools
from typing import TYPE_CHECKING
from PyQt5.QtCore import pyqtProperty, pyqtSignal, pyqtSlot, QObject
@@ -83,31 +84,20 @@ class QEAddressListModel(QAbstractListModel):
self.clear()
self.beginInsertRows(QModelIndex(), 0, n_addresses - 1)
i = 0
for address in r_addresses:
for i, address in enumerate(r_addresses):
insert_row('receive', self.receive_addresses, address, i)
i = i + 1
i = 0
for address in c_addresses:
for i, address in enumerate(c_addresses):
insert_row('change', self.change_addresses, address, i)
i = i + 1
self.endInsertRows()
self._dirty = False
@pyqtSlot(str)
def update_address(self, address):
i = 0
for a in self.receive_addresses:
for i, a in enumerate(itertools.chain(self.receive_addresses, self.change_addresses)):
if a['address'] == address:
self.do_update(i,a)
return
i = i + 1
for a in self.change_addresses:
if a['address'] == address:
self.do_update(i,a)
return
i = i + 1
def do_update(self, modelindex, modelitem):
mi = self.createIndex(modelindex, 0)

View File

@@ -134,12 +134,10 @@ class QEChannelListModel(QAbstractListModel, QtEventListener):
self.countChanged.emit()
def on_channel_updated(self, channel):
i = 0
for c in self.channels:
for i, c in enumerate(self.channels):
if c['cid'] == channel.channel_id.hex():
self.do_update(i,channel)
break
i = i + 1
def do_update(self, modelindex, channel):
self._logger.debug(f'updating our channel {channel.short_id_for_GUI()}')
@@ -167,8 +165,7 @@ class QEChannelListModel(QAbstractListModel, QtEventListener):
@pyqtSlot(str)
def remove_channel(self, cid):
self._logger.debug('remove channel with cid %s' % cid)
i = 0
for channel in self.channels:
for i, channel in enumerate(self.channels):
if cid == channel['cid']:
self._logger.debug(cid)
self.beginRemoveRows(QModelIndex(), i, i)
@@ -176,7 +173,6 @@ class QEChannelListModel(QAbstractListModel, QtEventListener):
self.endRemoveRows()
self.countChanged.emit()
return
i = i + 1
def filterModel(self, role, match):
_filterModel = QEFilterProxyModel(self, self)

View File

@@ -302,6 +302,7 @@ class QEDaemon(AuthMixin, QObject):
@pyqtSlot(result=str)
def suggestWalletName(self):
# FIXME why not use util.get_new_wallet_name ?
i = 1
while self.availableWallets.wallet_name_exists(f'wallet_{i}'):
i = i + 1

View File

@@ -92,14 +92,12 @@ class QEAbstractInvoiceListModel(QAbstractListModel):
self.add_invoice(self.get_invoice_for_key(key))
def delete_invoice(self, key: str):
i = 0
for invoice in self.invoices:
for i, invoice in enumerate(self.invoices):
if invoice['key'] == key:
self.beginRemoveRows(QModelIndex(), i, i)
self.invoices.pop(i)
self.endRemoveRows()
break
i = i + 1
self.set_status_timer()
def get_model_invoice(self, key: str):
@@ -111,8 +109,7 @@ class QEAbstractInvoiceListModel(QAbstractListModel):
@pyqtSlot(str, int)
def updateInvoice(self, key, status):
self._logger.debug('updating invoice for %s to %d' % (key,status))
i = 0
for item in self.invoices:
for i, item in enumerate(self.invoices):
if item['key'] == key:
invoice = self.get_invoice_for_key(key)
item['status'] = status
@@ -120,7 +117,6 @@ class QEAbstractInvoiceListModel(QAbstractListModel):
index = self.index(i,0)
self.dataChanged.emit(index, index, [self._ROLE_RMAP['status'], self._ROLE_RMAP['status_str']])
return
i = i + 1
def invoice_to_model(self, invoice: BaseInvoice):
item = self.get_invoice_as_dict(invoice)
@@ -149,14 +145,12 @@ class QEAbstractInvoiceListModel(QAbstractListModel):
@pyqtSlot()
def updateStatusStrings(self):
i = 0
for item in self.invoices:
for i, item in enumerate(self.invoices):
invoice = self.get_invoice_for_key(item['key'])
item['status'] = self.wallet.get_invoice_status(invoice)
item['status_str'] = invoice.get_status_str(item['status'])
index = self.index(i,0)
self.dataChanged.emit(index, index, [self._ROLE_RMAP['status'], self._ROLE_RMAP['status_str']])
i = i + 1
self.set_status_timer()

View File

@@ -55,12 +55,10 @@ class QETransactionListModel(QAbstractListModel, QtEventListener):
if adb != self.wallet.adb:
return
self._logger.debug(f'adb_set_future_tx event for txid {txid}')
i = 0
for item in self.tx_history:
for i, item in enumerate(self.tx_history):
if 'txid' in item and item['txid'] == txid:
self._update_future_txitem(i)
return
i = i + 1
def rowCount(self, index):
return len(self.tx_history)
@@ -193,8 +191,7 @@ class QETransactionListModel(QAbstractListModel, QtEventListener):
self._dirty = False
def on_tx_verified(self, txid, info):
i = 0
for tx in self.tx_history:
for i, tx in enumerate(self.tx_history):
if 'txid' in tx and tx['txid'] == txid:
tx['height'] = info.height
tx['confirmations'] = info.conf
@@ -205,7 +202,6 @@ class QETransactionListModel(QAbstractListModel, QtEventListener):
roles = [self._ROLE_RMAP[x] for x in ['section','height','confirmations','timestamp','date']]
self.dataChanged.emit(index, index, roles)
return
i = i + 1
def _update_future_txitem(self, tx_item_idx: int):
tx_item = self.tx_history[tx_item_idx]
@@ -227,20 +223,17 @@ class QETransactionListModel(QAbstractListModel, QtEventListener):
@pyqtSlot(str, str)
def update_tx_label(self, key, label):
i = 0
for tx in self.tx_history:
for i, tx in enumerate(self.tx_history):
if tx['key'] == key:
tx['label'] = label
index = self.index(i,0)
self.dataChanged.emit(index, index, [self._ROLE_RMAP['label']])
return
i = i + 1
@pyqtSlot(int)
def updateBlockchainHeight(self, height):
self._logger.debug('updating height to %d' % height)
i = 0
for tx_item in self.tx_history:
for i, tx_item in enumerate(self.tx_history):
if 'height' in tx_item:
if tx_item['height'] > 0:
tx_item['confirmations'] = height - tx_item['height'] + 1
@@ -249,4 +242,3 @@ class QETransactionListModel(QAbstractListModel, QtEventListener):
self.dataChanged.emit(index, index, roles)
elif tx_item['height'] in (TX_HEIGHT_FUTURE, TX_HEIGHT_LOCAL):
self._update_future_txitem(i)
i = i + 1