Browse Source

initial channel list model and delegate

patch-4
Sander van Grieken 3 years ago
parent
commit
d69ed7a204
  1. 30
      electrum/gui/qml/components/Channels.qml
  2. 80
      electrum/gui/qml/components/controls/ChannelDelegate.qml
  3. 38
      electrum/gui/qml/qechannellistmodel.py
  4. 2
      electrum/gui/qml/qetransactionlistmodel.py

30
electrum/gui/qml/components/Channels.qml

@ -89,36 +89,10 @@ Pane {
Layout.preferredWidth: parent.width
Layout.fillHeight: true
clip: true
model: 3 //Daemon.currentWallet.channelsModel
model: Daemon.currentWallet.channelModel
delegate: ItemDelegate {
width: ListView.view.width
height: row.height
delegate: ChannelDelegate {
highlighted: ListView.isCurrentItem
font.pixelSize: constants.fontSizeMedium // set default font size for child controls
RowLayout {
id: row
spacing: 10
x: constants.paddingSmall
width: parent.width - 2 * constants.paddingSmall
Image {
id: walleticon
source: "../../icons/lightning.png"
fillMode: Image.PreserveAspectFit
Layout.preferredWidth: constants.iconSizeLarge
Layout.preferredHeight: constants.iconSizeLarge
}
Label {
font.pixelSize: constants.fontSizeLarge
text: index
Layout.fillWidth: true
}
}
}
ScrollIndicator.vertical: ScrollIndicator { }

80
electrum/gui/qml/components/controls/ChannelDelegate.qml

@ -0,0 +1,80 @@
import QtQuick 2.6
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.0
import QtQuick.Controls.Material 2.0
ItemDelegate {
id: root
height: item.height
width: ListView.view.width
font.pixelSize: constants.fontSizeSmall // set default font size for child controls
GridLayout {
id: item
anchors {
left: parent.left
right: parent.right
leftMargin: constants.paddingSmall
rightMargin: constants.paddingSmall
}
columns: 2
Rectangle {
Layout.columnSpan: 2
Layout.fillWidth: true
Layout.preferredHeight: constants.paddingTiny
color: 'transparent'
}
Image {
id: walleticon
source: "../../../icons/lightning.png"
fillMode: Image.PreserveAspectFit
Layout.rowSpan: 2
Layout.preferredWidth: constants.iconSizeLarge
Layout.preferredHeight: constants.iconSizeLarge
}
RowLayout {
Layout.fillWidth: true
Label {
Layout.fillWidth: true
text: model.node_alias
elide: Text.ElideRight
wrapMode: Text.Wrap
maximumLineCount: 2
}
Label {
text: model.state
}
}
RowLayout {
Layout.fillWidth: true
Label {
Layout.fillWidth: true
text: model.short_cid
}
Label {
text: Config.formatSats(model.capacity)
}
Label {
text: Config.baseUnit
}
}
Rectangle {
Layout.columnSpan: 2
Layout.fillWidth: true
Layout.preferredHeight: constants.paddingTiny
color: 'transparent'
}
}
}

38
electrum/gui/qml/qechannellistmodel.py

@ -19,35 +19,57 @@ class QEChannelListModel(QAbstractListModel):
# define listmodel rolemap
_ROLE_NAMES=('cid','state','initiator','capacity','can_send','can_receive',
'l_csv_delat','r_csv_delay','send_frozen','receive_frozen',
'type','node_id','funding_tx')
'type','node_id','node_alias','short_cid','funding_tx')
_ROLE_KEYS = range(Qt.UserRole, Qt.UserRole + len(_ROLE_NAMES))
_ROLE_MAP = dict(zip(_ROLE_KEYS, [bytearray(x.encode()) for x in _ROLE_NAMES]))
_ROLE_RMAP = dict(zip(_ROLE_NAMES, _ROLE_KEYS))
def rowCount(self, index):
return len(self.tx_history)
return len(self.channels)
def roleNames(self):
return self._ROLE_MAP
def data(self, index, role):
tx = self.tx_history[index.row()]
tx = self.channels[index.row()]
role_index = role - Qt.UserRole
value = tx[self._ROLE_NAMES[role_index]]
if isinstance(value, (bool, list, int, str, QEAmount)) or value is None:
return value
if isinstance(value, Satoshis):
return value.value
if isinstance(value, QEAmount):
return value
return str(value)
def clear(self):
self.beginResetModel()
self.channels = []
self.endResetModel()
def channel_to_model(self, lnc):
lnworker = self.wallet.lnworker
item = {}
item['node_alias'] = lnworker.get_node_alias(lnc.node_id) or lnc.node_id.hex()
item['short_cid'] = lnc.short_id_for_GUI()
item['state'] = lnc.get_state_for_GUI()
item['capacity'] = QEAmount(amount_sat=lnc.get_capacity())
self._logger.debug(repr(item))
return item
@pyqtSlot()
def init_model(self):
if not self.wallet.lnworker:
self._logger.warning('lnworker should be defined')
return
channels = self.wallet.lnworker.channels
self._logger.debug(repr(channels))
#channels = list(lnworker.channels.values()) if lnworker else []
channels = []
lnchannels = self.wallet.lnworker.channels
for channel in lnchannels.values():
self._logger.debug(repr(channel))
item = self.channel_to_model(channel)
channels.append(item)
self.clear()
self.beginInsertRows(QModelIndex(), 0, len(channels) - 1)
self.channels = channels
self.endInsertRows()

2
electrum/gui/qml/qetransactionlistmodel.py

@ -38,8 +38,6 @@ class QETransactionListModel(QAbstractListModel):
return value
if isinstance(value, Satoshis):
return value.value
if isinstance(value, QEAmount):
return value
return str(value)
def clear(self):

Loading…
Cancel
Save