]> Nutra Git (v2) - gamesguru/feather.git/commitdiff
Coins: add searchbar
authortobtoht <thotbot@protonmail.com>
Mon, 28 Jun 2021 17:20:16 +0000 (19:20 +0200)
committertobtoht <thotbot@protonmail.com>
Mon, 28 Jun 2021 17:20:16 +0000 (19:20 +0200)
src/coinswidget.cpp
src/coinswidget.h
src/coinswidget.ui
src/mainwindow.cpp
src/model/CoinsProxyModel.cpp
src/model/CoinsProxyModel.h
src/model/TransactionHistoryProxyModel.cpp
src/model/TransactionHistoryProxyModel.h

index c6f0d08cedf6d33e60feab8fcebe7f163c8450f1..e7026de3e30c1916b63940bfa147abd51d018422 100644 (file)
@@ -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()};
index e87f2f159eb7a8367a77e336496d8d792ca542be..a9c418eff0196a93bbaf1a1b6bd39472e26db43b 100644 (file)
@@ -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);
index cddca313e5e782c224e016e1a650bc47369e056f..eaf7a7691cf14c269b2a0ecfd5a5efa06c0a6015 100644 (file)
    <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">
index 04adfc0e013ad68a4c9f58e46160973c38c600b1..353407f85812a5d37ea5b2205464fa3e2b5ecb5c 100644 (file)
@@ -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)
index d376813d73e9c3820409d473290c91b8f7382597..1920d806a07b4eb6a5a6be0f9454764fe3c917b5 100644 (file)
@@ -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);
+
+    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 && isSpent) && accountIndex == 0;
+    return !(!m_showSpent && coin->spent()) && coin->subaddrAccount() == 0;
 }
\ No newline at end of file
index 43bff1330712a03cf6edf371e7eab596913373b4..6c522ed60ee1ed8ac89571232793a040da756412 100644 (file)
@@ -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
index 40b7f34dbffee7fdd0321ba2d9c3b60d01932d63..c549c0116b673833602f8292854bd3fd57f4903a 100644 (file)
@@ -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();
 }
 
index a84535d8f6ae943a41641cb8231ad51362ef3ad0..45feb007b0071704141e12a1399cafd3792d311b 100644 (file)
@@ -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