-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
qml: Introduce the WalletSelect component
WalletSelect is a Popup that appears after clicking the main WalletBadge in the DesktopNavigation bar. It contains a ListView that allows the user to select one of the wallets listed in the wallet directory.
- Loading branch information
Showing
11 changed files
with
282 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// Copyright (c) 2024 The Bitcoin Core developers | ||
// Distributed under the MIT software license, see the accompanying | ||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
||
#include <qml/models/walletlistmodel.h> | ||
|
||
#include <interfaces/node.h> | ||
|
||
#include <QSet> | ||
|
||
WalletListModel::WalletListModel(interfaces::Node& node, QObject *parent) | ||
: QAbstractListModel(parent) | ||
, m_node(node) | ||
{ | ||
setSelectedWallet("Singlesig Wallet"); | ||
} | ||
|
||
void WalletListModel::listWalletDir() | ||
{ | ||
QSet<QString> existing_names; | ||
for (int i = 0; i < rowCount(); ++i) { | ||
QModelIndex index = this->index(i, 0); | ||
QString name = data(index, NameRole).toString(); | ||
existing_names.insert(name); | ||
} | ||
|
||
for (const std::string &name : m_node.walletLoader().listWalletDir()) { | ||
QString qname = QString::fromStdString(name); | ||
if (!existing_names.contains(qname)) { | ||
addItem({ qname }); | ||
} | ||
} | ||
} | ||
|
||
void WalletListModel::setSelectedWallet(QString wallet_name) | ||
{ | ||
if (m_selected_wallet != wallet_name) { | ||
m_selected_wallet = wallet_name; | ||
Q_EMIT selectedWalletChanged(); | ||
} | ||
} | ||
|
||
QString WalletListModel::selectedWallet() const | ||
{ | ||
return m_selected_wallet; | ||
} | ||
|
||
int WalletListModel::rowCount(const QModelIndex &parent) const | ||
{ | ||
Q_UNUSED(parent); | ||
return m_items.size(); | ||
} | ||
|
||
QVariant WalletListModel::data(const QModelIndex &index, int role) const | ||
{ | ||
if (!index.isValid() || index.row() < 0 || index.row() >= m_items.size()) | ||
return QVariant(); | ||
|
||
const auto &item = m_items[index.row()]; | ||
switch (role) { | ||
case Qt::DisplayRole: | ||
case NameRole: | ||
return item.name; | ||
default: | ||
return QVariant(); | ||
} | ||
} | ||
|
||
QHash<int, QByteArray> WalletListModel::roleNames() const | ||
{ | ||
QHash<int, QByteArray> roles; | ||
roles[NameRole] = "name"; | ||
return roles; | ||
} | ||
|
||
void WalletListModel::addItem(const Item &item) | ||
{ | ||
beginInsertRows(QModelIndex(), rowCount(), rowCount()); | ||
m_items.append(item); | ||
endInsertRows(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Copyright (c) 2024 The Bitcoin Core developers | ||
// Distributed under the MIT software license, see the accompanying | ||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
||
#ifndef BITCOIN_QML_MODELS_WALLETLISTMODEL_H | ||
#define BITCOIN_QML_MODELS_WALLETLISTMODEL_H | ||
|
||
#include <interfaces/wallet.h> | ||
#include <QAbstractListModel> | ||
#include <QList> | ||
|
||
namespace interfaces { | ||
class Node; | ||
} | ||
|
||
class WalletListModel : public QAbstractListModel | ||
{ | ||
Q_OBJECT | ||
Q_PROPERTY(QString selectedWallet READ selectedWallet WRITE setSelectedWallet NOTIFY selectedWalletChanged) | ||
|
||
public: | ||
WalletListModel(interfaces::Node& node, QObject *parent = nullptr); | ||
~WalletListModel() = default; | ||
|
||
enum Roles { | ||
NameRole = Qt::UserRole + 1 | ||
}; | ||
|
||
int rowCount(const QModelIndex &parent = QModelIndex()) const override; | ||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; | ||
QHash<int, QByteArray> roleNames() const override; | ||
|
||
void setSelectedWallet(QString wallet_name); | ||
QString selectedWallet() const; | ||
|
||
public Q_SLOTS: | ||
void listWalletDir(); | ||
|
||
Q_SIGNALS: | ||
void selectedWalletChanged(); | ||
|
||
private: | ||
struct Item { | ||
QString name; | ||
}; | ||
|
||
void addItem(const Item &item); | ||
|
||
QList<Item> m_items; | ||
interfaces::Node& m_node; | ||
QString m_selected_wallet; | ||
|
||
}; | ||
|
||
#endif // BITCOIN_QML_MODELS_WALLETLISTMODEL_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
// Copyright (c) 2024 The Bitcoin Core developers | ||
// Distributed under the MIT software license, see the accompanying | ||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
||
import QtQuick 2.15 | ||
import QtQuick.Controls 2.15 | ||
import QtQuick.Layouts 1.15 | ||
|
||
import "../../controls" | ||
|
||
Popup { | ||
id: root | ||
|
||
property alias model: listView.model | ||
implicitHeight: listView.height + arrow.height | ||
implicitWidth: 250 | ||
|
||
background: Item { | ||
anchors.fill: parent | ||
Rectangle { | ||
id: tooltipBg | ||
color: Theme.color.neutral0 | ||
border.color: Theme.color.neutral4 | ||
radius: 5 | ||
border.width: 1 | ||
width: parent.width | ||
height: parent.height - arrow.height - 1 | ||
anchors.top: arrow.bottom | ||
anchors.horizontalCenter: root.horizontalCenter | ||
anchors.topMargin: -1 | ||
} | ||
Image { | ||
id: arrow | ||
source: Theme.image.tooltipArrow | ||
width: 22 | ||
height: 10 | ||
anchors.horizontalCenter: parent.horizontalCenter | ||
anchors.top: parent.top | ||
} | ||
} | ||
|
||
ButtonGroup { | ||
id: buttonGroup | ||
} | ||
|
||
ListView { | ||
id: listView | ||
anchors.topMargin: arrow.height | ||
width: 220 | ||
height: contentHeight | ||
interactive: false | ||
spacing: 2 | ||
model: walletListModel | ||
|
||
header: CoreText { | ||
text: qsTr("Wallets") | ||
visible: listView.count > 0 | ||
bold: true | ||
width: 220 | ||
height: 30 | ||
color: Theme.color.neutral9 | ||
font.pixelSize: 14 | ||
topPadding: 10 | ||
bottomPadding: 5 | ||
} | ||
|
||
delegate: WalletBadge { | ||
required property string name; | ||
|
||
width: 220 | ||
height: 32 | ||
text: name | ||
ButtonGroup.group: buttonGroup | ||
showBalance: false | ||
showIcon: false | ||
onClicked: { | ||
walletListModel.selectedWallet = name | ||
root.close() | ||
} | ||
|
||
} | ||
|
||
footer: RowLayout { | ||
id: addWallet | ||
height: 45 | ||
width: addIcon.size + addText.width + spacing | ||
anchors.horizontalCenter: parent.horizontalCenter | ||
Icon { | ||
id: addIcon | ||
Layout.alignment: Qt.AlignHCenter | ||
source: "image://images/plus" | ||
color: Theme.color.neutral8 | ||
size: 14 | ||
topPadding: 5 | ||
bottomPadding: 10 | ||
} | ||
CoreText { | ||
id: addText | ||
Layout.alignment: Qt.AlignHCenter | ||
text: qsTr("Add Wallet") | ||
color: Theme.color.neutral9 | ||
font.pixelSize: 15 | ||
topPadding: 5 | ||
bottomPadding: 10 | ||
} | ||
} | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.