Browse Source

qml: split off AddressDelegate and handle imported addresses more gracefully

master
Sander van Grieken 3 years ago
parent
commit
2f8ab8027b
  1. 2
      electrum/gui/qml/components/AddressDetails.qml
  2. 87
      electrum/gui/qml/components/Addresses.qml
  3. 95
      electrum/gui/qml/components/controls/AddressDelegate.qml
  4. 14
      electrum/gui/qml/qeaddresslistmodel.py

2
electrum/gui/qml/components/AddressDetails.qml

@ -200,11 +200,13 @@ Pane {
}
Label {
visible: addressdetails.derivationPath
text: qsTr('Derivation path')
color: Material.accentColor
}
Label {
visible: addressdetails.derivationPath
text: addressdetails.derivationPath
}

87
electrum/gui/qml/components/Addresses.qml

@ -31,14 +31,7 @@ Pane {
section.criteria: ViewSection.FullString
section.delegate: sectionDelegate
delegate: ItemDelegate {
id: delegate
width: ListView.view.width
height: delegateLayout.height
highlighted: ListView.isCurrentItem
font.pixelSize: constants.fontSizeMedium // set default font size for child controls
delegate: AddressDelegate {
onClicked: {
var page = app.stack.push(Qt.resolvedUrl('AddressDetails.qml'), {'address': model.address})
page.addressDetailsChanged.connect(function() {
@ -46,84 +39,6 @@ Pane {
listview.model.update_address(model.address)
})
}
ColumnLayout {
id: delegateLayout
width: parent.width
spacing: 0
GridLayout {
columns: 2
Layout.topMargin: constants.paddingSmall
Layout.leftMargin: constants.paddingLarge
Layout.rightMargin: constants.paddingLarge
Label {
id: indexLabel
font.bold: true
text: '#' + ('00'+model.iaddr).slice(-2)
Layout.fillWidth: true
}
Label {
font.family: FixedFont
text: model.address
elide: Text.ElideMiddle
Layout.fillWidth: true
}
Rectangle {
id: useIndicator
Layout.preferredWidth: constants.iconSizeMedium
Layout.preferredHeight: constants.iconSizeMedium
color: model.held
? constants.colorAddressFrozen
: model.numtx > 0
? model.balance.satsInt == 0
? constants.colorAddressUsed
: constants.colorAddressUsedWithBalance
: model.type == 'receive'
? constants.colorAddressExternal
: constants.colorAddressInternal
}
RowLayout {
Label {
id: labelLabel
font.pixelSize: model.label != '' ? constants.fontSizeLarge : constants.fontSizeSmall
text: model.label != '' ? model.label : qsTr('<no label>')
opacity: model.label != '' ? 1.0 : 0.8
elide: Text.ElideRight
maximumLineCount: 2
wrapMode: Text.WordWrap
Layout.fillWidth: true
}
Label {
font.family: FixedFont
text: Config.formatSats(model.balance, false)
visible: model.balance.satsInt != 0
}
Label {
color: Material.accentColor
text: Config.baseUnit + ','
visible: model.balance.satsInt != 0
}
Label {
text: model.numtx
visible: model.numtx > 0
}
Label {
color: Material.accentColor
text: qsTr('tx')
visible: model.numtx > 0
}
}
}
Item {
Layout.preferredWidth: 1
Layout.preferredHeight: constants.paddingSmall
}
}
}
ScrollIndicator.vertical: ScrollIndicator { }

95
electrum/gui/qml/components/controls/AddressDelegate.qml

@ -0,0 +1,95 @@
import QtQuick 2.6
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.0
import QtQuick.Controls.Material 2.0
import org.electrum 1.0
ItemDelegate {
id: delegate
width: ListView.view.width
height: delegateLayout.height
highlighted: ListView.isCurrentItem
font.pixelSize: constants.fontSizeMedium // set default font size for child controls
ColumnLayout {
id: delegateLayout
width: parent.width
spacing: 0
GridLayout {
columns: 2
Layout.topMargin: constants.paddingSmall
Layout.leftMargin: constants.paddingLarge
Layout.rightMargin: constants.paddingLarge
Label {
id: indexLabel
font.bold: true
text: model.iaddr < 10
? '#' + ('0'+model.iaddr).slice(-2)
: '#' + model.iaddr
Layout.fillWidth: true
}
Label {
font.family: FixedFont
text: model.address
elide: Text.ElideMiddle
Layout.fillWidth: true
}
Rectangle {
id: useIndicator
Layout.preferredWidth: constants.iconSizeMedium
Layout.preferredHeight: constants.iconSizeMedium
color: model.held
? constants.colorAddressFrozen
: model.numtx > 0
? model.balance.satsInt == 0
? constants.colorAddressUsed
: constants.colorAddressUsedWithBalance
: model.type == 'change'
? constants.colorAddressInternal
: constants.colorAddressExternal
}
RowLayout {
Label {
id: labelLabel
font.pixelSize: model.label != '' ? constants.fontSizeLarge : constants.fontSizeSmall
text: model.label != '' ? model.label : qsTr('<no label>')
opacity: model.label != '' ? 1.0 : 0.8
elide: Text.ElideRight
maximumLineCount: 2
wrapMode: Text.WordWrap
Layout.fillWidth: true
}
Label {
font.family: FixedFont
text: Config.formatSats(model.balance, false)
visible: model.balance.satsInt != 0
}
Label {
color: Material.accentColor
text: Config.baseUnit + ','
visible: model.balance.satsInt != 0
}
Label {
text: model.numtx
visible: model.numtx > 0
}
Label {
color: Material.accentColor
text: qsTr('tx')
visible: model.numtx > 0
}
}
}
Item {
Layout.preferredWidth: 1
Layout.preferredHeight: constants.paddingSmall
}
}
}

14
electrum/gui/qml/qeaddresslistmodel.py

@ -73,7 +73,7 @@ class QEAddressListModel(QAbstractListModel):
return
r_addresses = self.wallet.get_receiving_addresses()
c_addresses = self.wallet.get_change_addresses()
c_addresses = self.wallet.get_change_addresses() if self.wallet.wallet_type != 'imported' else []
n_addresses = len(r_addresses) + len(c_addresses)
def insert_row(atype, alist, address, iaddr):
@ -84,10 +84,14 @@ class QEAddressListModel(QAbstractListModel):
self.clear()
self.beginInsertRows(QModelIndex(), 0, n_addresses - 1)
for i, address in enumerate(r_addresses):
insert_row('receive', self.receive_addresses, address, i)
for i, address in enumerate(c_addresses):
insert_row('change', self.change_addresses, address, i)
if self.wallet.wallet_type != 'imported':
for i, address in enumerate(r_addresses):
insert_row('receive', self.receive_addresses, address, i)
for i, address in enumerate(c_addresses):
insert_row('change', self.change_addresses, address, i)
else:
for i, address in enumerate(r_addresses):
insert_row('imported', self.receive_addresses, address, i)
self.endInsertRows()
self._dirty = False

Loading…
Cancel
Save