-
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.
Merge #401: Introduce Wallet Select Dropdown
0939f2b qml: Introduce the WalletSelect component (johnny9) 5906e69 qml: Introduce the WalletBadge component (johnny9) Pull request description: 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. This PR uses the arrow icon that is shared with the Tooltip so it is based off of that commit. [![Build Artifacts](https://img.shields.io/badge/Build%20Artifacts-green )](https://github.com/bitcoin-core/gui-qml/actions/runs/9263281845) ACKs for top commit: D33r-Gee: tACK [0939f2b](0939f2b) on WSL Ubuntu 22.04 Tree-SHA512: 19b877ca1be7488c54e79dba28720818711ab9f9f8de34cdb4f540daa150dc6debb8d78d9e0ba14b8a246f88497f6a04b089bcd3e4dca433afe49990201439d9
- Loading branch information
Showing
12 changed files
with
458 additions
and
20 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
Oops, something went wrong.