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