mirror of
https://github.com/feather-wallet/feather.git
synced 2025-01-24 03:25:51 +00:00
Coins: add searchbar
This commit is contained in:
parent
04b2f5f9a0
commit
e5ac996ae5
8 changed files with 60 additions and 26 deletions
|
@ -59,6 +59,8 @@ CoinsWidget::CoinsWidget(QSharedPointer<AppContext> ctx, QWidget *parent)
|
||||||
|
|
||||||
connect(ui->coins, &QTreeView::customContextMenuRequested, this, &CoinsWidget::showContextMenu);
|
connect(ui->coins, &QTreeView::customContextMenuRequested, this, &CoinsWidget::showContextMenu);
|
||||||
connect(ui->coins, &QTreeView::doubleClicked, this, &CoinsWidget::viewOutput);
|
connect(ui->coins, &QTreeView::doubleClicked, this, &CoinsWidget::viewOutput);
|
||||||
|
|
||||||
|
connect(ui->search, &QLineEdit::textChanged, this, &CoinsWidget::setSearchFilter);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CoinsWidget::setModel(CoinsModel * model, Coins * coins) {
|
void CoinsWidget::setModel(CoinsModel * model, Coins * coins) {
|
||||||
|
@ -83,6 +85,10 @@ void CoinsWidget::setModel(CoinsModel * model, Coins * coins) {
|
||||||
ui->coins->setSortingEnabled(true);
|
ui->coins->setSortingEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CoinsWidget::setSearchbarVisible(bool visible) {
|
||||||
|
ui->search->setVisible(visible);
|
||||||
|
}
|
||||||
|
|
||||||
void CoinsWidget::showContextMenu(const QPoint &point) {
|
void CoinsWidget::showContextMenu(const QPoint &point) {
|
||||||
QModelIndexList list = ui->coins->selectionModel()->selectedRows();
|
QModelIndexList list = ui->coins->selectionModel()->selectedRows();
|
||||||
|
|
||||||
|
@ -130,6 +136,11 @@ void CoinsWidget::setShowSpent(bool show)
|
||||||
m_proxyModel->setShowSpent(show);
|
m_proxyModel->setShowSpent(show);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CoinsWidget::setSearchFilter(const QString &filter) {
|
||||||
|
if (!m_proxyModel) return;
|
||||||
|
m_proxyModel->setSearchFilter(filter);
|
||||||
|
}
|
||||||
|
|
||||||
void CoinsWidget::freezeOutput() {
|
void CoinsWidget::freezeOutput() {
|
||||||
QModelIndex index = ui->coins->currentIndex();
|
QModelIndex index = ui->coins->currentIndex();
|
||||||
QVector<int> indexes = {m_proxyModel->mapToSource(index).row()};
|
QVector<int> indexes = {m_proxyModel->mapToSource(index).row()};
|
||||||
|
|
|
@ -26,6 +26,9 @@ public:
|
||||||
void setModel(CoinsModel * model, Coins * coins);
|
void setModel(CoinsModel * model, Coins * coins);
|
||||||
~CoinsWidget() override;
|
~CoinsWidget() override;
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void setSearchbarVisible(bool visible);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void showHeaderMenu(const QPoint& position);
|
void showHeaderMenu(const QPoint& position);
|
||||||
void setShowSpent(bool show);
|
void setShowSpent(bool show);
|
||||||
|
@ -36,6 +39,7 @@ private slots:
|
||||||
void viewOutput();
|
void viewOutput();
|
||||||
void onSweepOutput();
|
void onSweepOutput();
|
||||||
void onSweepMulti();
|
void onSweepMulti();
|
||||||
|
void setSearchFilter(const QString &filter);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void freezeCoins(const QVector<int>& indexes);
|
void freezeCoins(const QVector<int>& indexes);
|
||||||
|
|
|
@ -29,6 +29,13 @@
|
||||||
<property name="bottomMargin">
|
<property name="bottomMargin">
|
||||||
<number>0</number>
|
<number>0</number>
|
||||||
</property>
|
</property>
|
||||||
|
<item>
|
||||||
|
<widget class="QLineEdit" name="search">
|
||||||
|
<property name="placeholderText">
|
||||||
|
<string>Search..</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QTreeView" name="coins">
|
<widget class="QTreeView" name="coins">
|
||||||
<property name="selectionMode">
|
<property name="selectionMode">
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
// SPDX-License-Identifier: BSD-3-Clause
|
// SPDX-License-Identifier: BSD-3-Clause
|
||||||
// Copyright (c) 2020-2021, The Monero Project.
|
// Copyright (c) 2020-2021, The Monero Project.
|
||||||
|
|
||||||
#include <QMessageBox>
|
|
||||||
#include <QFileDialog>
|
|
||||||
|
|
||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
#include "ui_mainwindow.h"
|
#include "ui_mainwindow.h"
|
||||||
|
|
||||||
|
#include <QMessageBox>
|
||||||
|
#include <QFileDialog>
|
||||||
|
|
||||||
#include "config-feather.h"
|
#include "config-feather.h"
|
||||||
#include "dialog/TxConfDialog.h"
|
#include "dialog/TxConfDialog.h"
|
||||||
#include "dialog/TxConfAdvDialog.h"
|
#include "dialog/TxConfAdvDialog.h"
|
||||||
|
@ -1414,6 +1414,7 @@ void MainWindow::toggleSearchbar(bool visible) {
|
||||||
m_historyWidget->setSearchbarVisible(visible);
|
m_historyWidget->setSearchbarVisible(visible);
|
||||||
m_receiveWidget->setSearchbarVisible(visible);
|
m_receiveWidget->setSearchbarVisible(visible);
|
||||||
m_contactsWidget->setSearchbarVisible(visible);
|
m_contactsWidget->setSearchbarVisible(visible);
|
||||||
|
m_coinsWidget->setSearchbarVisible(visible);
|
||||||
|
|
||||||
int currentTab = ui->tabWidget->currentIndex();
|
int currentTab = ui->tabWidget->currentIndex();
|
||||||
if (currentTab == Tabs::HISTORY)
|
if (currentTab == Tabs::HISTORY)
|
||||||
|
|
|
@ -6,19 +6,32 @@
|
||||||
#include "libwalletqt/CoinsInfo.h"
|
#include "libwalletqt/CoinsInfo.h"
|
||||||
|
|
||||||
CoinsProxyModel::CoinsProxyModel(QObject *parent, Coins *coins)
|
CoinsProxyModel::CoinsProxyModel(QObject *parent, Coins *coins)
|
||||||
: QSortFilterProxyModel(parent), m_coins(coins)
|
: QSortFilterProxyModel(parent)
|
||||||
|
, m_coins(coins)
|
||||||
|
, m_searchRegExp("")
|
||||||
{
|
{
|
||||||
|
m_searchRegExp.setPatternOptions(QRegularExpression::CaseInsensitiveOption);
|
||||||
setSortRole(Qt::UserRole);
|
setSortRole(Qt::UserRole);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CoinsProxyModel::setShowSpent(const bool showSpent) {
|
||||||
|
m_showSpent = showSpent;
|
||||||
|
invalidateFilter();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CoinsProxyModel::setSearchFilter(const QString &searchString) {
|
||||||
|
m_searchRegExp.setPattern(searchString);
|
||||||
|
invalidateFilter();
|
||||||
|
}
|
||||||
|
|
||||||
bool CoinsProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
|
bool CoinsProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
|
||||||
{
|
{
|
||||||
bool isSpent;
|
CoinsInfo* coin = m_coins->coin(sourceRow);
|
||||||
int accountIndex;
|
|
||||||
m_coins->coin(sourceRow, [&isSpent, &accountIndex](const CoinsInfo &c){
|
|
||||||
isSpent = c.spent();
|
|
||||||
accountIndex = c.subaddrAccount();
|
|
||||||
});
|
|
||||||
|
|
||||||
return !(!m_showSpent && isSpent) && accountIndex == 0;
|
if (!m_searchRegExp.pattern().isEmpty()) {
|
||||||
|
return coin->pubKey().contains(m_searchRegExp) || coin->address().contains(m_searchRegExp)
|
||||||
|
|| coin->hash().contains(m_searchRegExp) || coin->addressLabel().contains(m_searchRegExp);
|
||||||
|
}
|
||||||
|
|
||||||
|
return !(!m_showSpent && coin->spent()) && coin->subaddrAccount() == 0;
|
||||||
}
|
}
|
|
@ -5,6 +5,7 @@
|
||||||
#define FEATHER_COINSPROXYMODEL_H
|
#define FEATHER_COINSPROXYMODEL_H
|
||||||
|
|
||||||
#include <QSortFilterProxyModel>
|
#include <QSortFilterProxyModel>
|
||||||
|
|
||||||
#include "libwalletqt/Coins.h"
|
#include "libwalletqt/Coins.h"
|
||||||
|
|
||||||
class CoinsProxyModel : public QSortFilterProxyModel
|
class CoinsProxyModel : public QSortFilterProxyModel
|
||||||
|
@ -12,17 +13,16 @@ class CoinsProxyModel : public QSortFilterProxyModel
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit CoinsProxyModel(QObject* parent, Coins *coins);
|
explicit CoinsProxyModel(QObject* parent, Coins *coins);
|
||||||
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const;
|
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void setShowSpent(const bool showSpent){
|
void setSearchFilter(const QString &searchString);
|
||||||
m_showSpent = showSpent;
|
void setShowSpent(bool showSpent);
|
||||||
invalidateFilter();
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool m_showSpent = false;
|
|
||||||
Coins *m_coins;
|
Coins *m_coins;
|
||||||
|
bool m_showSpent = false;
|
||||||
|
QRegularExpression m_searchRegExp;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //FEATHER_COINSPROXYMODEL_H
|
#endif //FEATHER_COINSPROXYMODEL_H
|
||||||
|
|
|
@ -7,12 +7,11 @@
|
||||||
#include "libwalletqt/TransactionInfo.h"
|
#include "libwalletqt/TransactionInfo.h"
|
||||||
|
|
||||||
TransactionHistoryProxyModel::TransactionHistoryProxyModel(Wallet *wallet, QObject *parent)
|
TransactionHistoryProxyModel::TransactionHistoryProxyModel(Wallet *wallet, QObject *parent)
|
||||||
: QSortFilterProxyModel(parent),
|
: QSortFilterProxyModel(parent)
|
||||||
m_wallet(wallet),
|
, m_wallet(wallet)
|
||||||
m_searchRegExp("")
|
, m_searchRegExp("")
|
||||||
{
|
{
|
||||||
m_searchRegExp.setCaseSensitivity(Qt::CaseInsensitive);
|
m_searchRegExp.setPatternOptions(QRegularExpression::CaseInsensitiveOption);
|
||||||
m_searchRegExp.setPatternSyntax(QRegExp::RegExp);
|
|
||||||
m_history = m_wallet->history();
|
m_history = m_wallet->history();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,11 +4,10 @@
|
||||||
#ifndef FEATHER_TRANSACTIONHISTORYPROXYMODEL_H
|
#ifndef FEATHER_TRANSACTIONHISTORYPROXYMODEL_H
|
||||||
#define FEATHER_TRANSACTIONHISTORYPROXYMODEL_H
|
#define FEATHER_TRANSACTIONHISTORYPROXYMODEL_H
|
||||||
|
|
||||||
|
#include <QSortFilterProxyModel>
|
||||||
|
|
||||||
#include "libwalletqt/TransactionHistory.h"
|
#include "libwalletqt/TransactionHistory.h"
|
||||||
#include "libwalletqt/Wallet.h"
|
#include "libwalletqt/Wallet.h"
|
||||||
#include "libwalletqt/TransactionHistory.h"
|
|
||||||
|
|
||||||
#include <QSortFilterProxyModel>
|
|
||||||
|
|
||||||
class TransactionHistoryProxyModel : public QSortFilterProxyModel
|
class TransactionHistoryProxyModel : public QSortFilterProxyModel
|
||||||
{
|
{
|
||||||
|
@ -28,7 +27,7 @@ private:
|
||||||
Wallet *m_wallet;
|
Wallet *m_wallet;
|
||||||
TransactionHistory *m_history;
|
TransactionHistory *m_history;
|
||||||
|
|
||||||
QRegExp m_searchRegExp;
|
QRegularExpression m_searchRegExp;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //FEATHER_TRANSACTIONHISTORYPROXYMODEL_H
|
#endif //FEATHER_TRANSACTIONHISTORYPROXYMODEL_H
|
||||||
|
|
Loading…
Reference in a new issue