initial channel list model and delegate
This commit is contained in:
@@ -89,36 +89,10 @@ Pane {
|
|||||||
Layout.preferredWidth: parent.width
|
Layout.preferredWidth: parent.width
|
||||||
Layout.fillHeight: true
|
Layout.fillHeight: true
|
||||||
clip: true
|
clip: true
|
||||||
model: 3 //Daemon.currentWallet.channelsModel
|
model: Daemon.currentWallet.channelModel
|
||||||
|
|
||||||
delegate: ItemDelegate {
|
delegate: ChannelDelegate {
|
||||||
width: ListView.view.width
|
|
||||||
height: row.height
|
|
||||||
highlighted: ListView.isCurrentItem
|
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 { }
|
ScrollIndicator.vertical: ScrollIndicator { }
|
||||||
|
|||||||
80
electrum/gui/qml/components/controls/ChannelDelegate.qml
Normal file
80
electrum/gui/qml/components/controls/ChannelDelegate.qml
Normal file
@@ -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'
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -19,35 +19,57 @@ class QEChannelListModel(QAbstractListModel):
|
|||||||
# define listmodel rolemap
|
# define listmodel rolemap
|
||||||
_ROLE_NAMES=('cid','state','initiator','capacity','can_send','can_receive',
|
_ROLE_NAMES=('cid','state','initiator','capacity','can_send','can_receive',
|
||||||
'l_csv_delat','r_csv_delay','send_frozen','receive_frozen',
|
'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_KEYS = range(Qt.UserRole, Qt.UserRole + len(_ROLE_NAMES))
|
||||||
_ROLE_MAP = dict(zip(_ROLE_KEYS, [bytearray(x.encode()) for x in _ROLE_NAMES]))
|
_ROLE_MAP = dict(zip(_ROLE_KEYS, [bytearray(x.encode()) for x in _ROLE_NAMES]))
|
||||||
_ROLE_RMAP = dict(zip(_ROLE_NAMES, _ROLE_KEYS))
|
_ROLE_RMAP = dict(zip(_ROLE_NAMES, _ROLE_KEYS))
|
||||||
|
|
||||||
def rowCount(self, index):
|
def rowCount(self, index):
|
||||||
return len(self.tx_history)
|
return len(self.channels)
|
||||||
|
|
||||||
def roleNames(self):
|
def roleNames(self):
|
||||||
return self._ROLE_MAP
|
return self._ROLE_MAP
|
||||||
|
|
||||||
def data(self, index, role):
|
def data(self, index, role):
|
||||||
tx = self.tx_history[index.row()]
|
tx = self.channels[index.row()]
|
||||||
role_index = role - Qt.UserRole
|
role_index = role - Qt.UserRole
|
||||||
value = tx[self._ROLE_NAMES[role_index]]
|
value = tx[self._ROLE_NAMES[role_index]]
|
||||||
if isinstance(value, (bool, list, int, str, QEAmount)) or value is None:
|
if isinstance(value, (bool, list, int, str, QEAmount)) or value is None:
|
||||||
return value
|
return value
|
||||||
if isinstance(value, Satoshis):
|
if isinstance(value, Satoshis):
|
||||||
return value.value
|
return value.value
|
||||||
if isinstance(value, QEAmount):
|
|
||||||
return value
|
|
||||||
return str(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()
|
@pyqtSlot()
|
||||||
def init_model(self):
|
def init_model(self):
|
||||||
if not self.wallet.lnworker:
|
if not self.wallet.lnworker:
|
||||||
self._logger.warning('lnworker should be defined')
|
self._logger.warning('lnworker should be defined')
|
||||||
return
|
return
|
||||||
|
|
||||||
channels = self.wallet.lnworker.channels
|
channels = []
|
||||||
self._logger.debug(repr(channels))
|
|
||||||
#channels = list(lnworker.channels.values()) if lnworker else []
|
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()
|
||||||
|
|||||||
@@ -38,8 +38,6 @@ class QETransactionListModel(QAbstractListModel):
|
|||||||
return value
|
return value
|
||||||
if isinstance(value, Satoshis):
|
if isinstance(value, Satoshis):
|
||||||
return value.value
|
return value.value
|
||||||
if isinstance(value, QEAmount):
|
|
||||||
return value
|
|
||||||
return str(value)
|
return str(value)
|
||||||
|
|
||||||
def clear(self):
|
def clear(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user