From 4f2fcbd1a36788be3437a1b9ff91f70eee496467 Mon Sep 17 00:00:00 2001 From: Jonas Schnelli Date: Wed, 29 Nov 2017 13:50:30 -1000 Subject: [PATCH] Merge #11395: Qt: Enable searching by transaction id eac2abca0 Qt: Enable searching by transaction id (Luke Dashjr) c407c61c5 Qt: Avoid invalidating the search filter, when it doesn't really change (Luke Dashjr) b1f634242 Qt: Rename confusingly-named "address prefix" to "search string" (Luke Dashjr) Pull request description: Tree-SHA512: 1c67037d19689fbaff21d15ed7848ac86188e5de34728312e1f9758dada759cab50d913a5bc09e413ecaa3e07557cf253809b95b5637ff79f2e3cf24d86dd3ed --- src/qt/transactionfilterproxy.cpp | 13 +++++++++---- src/qt/transactionfilterproxy.h | 4 ++-- src/qt/transactionview.cpp | 26 +++++++++++++------------- src/qt/transactionview.h | 4 ++-- 4 files changed, 26 insertions(+), 21 deletions(-) diff --git a/src/qt/transactionfilterproxy.cpp b/src/qt/transactionfilterproxy.cpp index b50fe7923ef47..c842d1a0f9165 100644 --- a/src/qt/transactionfilterproxy.cpp +++ b/src/qt/transactionfilterproxy.cpp @@ -20,7 +20,7 @@ TransactionFilterProxy::TransactionFilterProxy(QObject *parent) : QSortFilterProxyModel(parent), dateFrom(MIN_DATE.toTime_t()), dateTo(MAX_DATE.toTime_t()), - addrPrefix(), + m_search_string(), typeFilter(COMMON_TYPES), watchOnlyFilter(WatchOnlyFilter_All), instantsendFilter(InstantSendFilter_All), @@ -40,6 +40,7 @@ bool TransactionFilterProxy::filterAcceptsRow(int sourceRow, const QModelIndex & bool lockedByInstantSend = index.data(TransactionTableModel::InstantSendRole).toBool(); QString address = index.data(TransactionTableModel::AddressRole).toString(); QString label = index.data(TransactionTableModel::LabelRole).toString(); + QString txid = index.data(TransactionTableModel::TxIDRole).toString(); qint64 amount = llabs(index.data(TransactionTableModel::AmountRole).toLongLong()); int status = index.data(TransactionTableModel::StatusRole).toInt(); @@ -57,8 +58,11 @@ bool TransactionFilterProxy::filterAcceptsRow(int sourceRow, const QModelIndex & return false; if(datetime < dateFrom || datetime > dateTo) return false; - if (!address.contains(addrPrefix, Qt::CaseInsensitive) && !label.contains(addrPrefix, Qt::CaseInsensitive)) + if (!address.contains(m_search_string, Qt::CaseInsensitive) && + ! label.contains(m_search_string, Qt::CaseInsensitive) && + ! txid.contains(m_search_string, Qt::CaseInsensitive)) { return false; + } if(amount < minAmount) return false; @@ -72,9 +76,10 @@ void TransactionFilterProxy::setDateRange(const QDateTime &from, const QDateTime invalidateFilter(); } -void TransactionFilterProxy::setAddressPrefix(const QString &_addrPrefix) +void TransactionFilterProxy::setSearchString(const QString &search_string) { - this->addrPrefix = _addrPrefix; + if (m_search_string == search_string) return; + m_search_string = search_string; invalidateFilter(); } diff --git a/src/qt/transactionfilterproxy.h b/src/qt/transactionfilterproxy.h index 026ca31c9efdf..6ca1f782da5f2 100644 --- a/src/qt/transactionfilterproxy.h +++ b/src/qt/transactionfilterproxy.h @@ -44,7 +44,7 @@ class TransactionFilterProxy : public QSortFilterProxyModel }; void setDateRange(const QDateTime &from, const QDateTime &to); - void setAddressPrefix(const QString &addrPrefix); + void setSearchString(const QString &); /** @note Type filter takes a bit field created with TYPE() or ALL_TYPES */ @@ -67,7 +67,7 @@ class TransactionFilterProxy : public QSortFilterProxyModel private: qint64 dateFrom; qint64 dateTo; - QString addrPrefix; + QString m_search_string; quint32 typeFilter; WatchOnlyFilter watchOnlyFilter; InstantSendFilter instantsendFilter; diff --git a/src/qt/transactionview.cpp b/src/qt/transactionview.cpp index 1149f828a5404..accbc41f32f93 100644 --- a/src/qt/transactionview.cpp +++ b/src/qt/transactionview.cpp @@ -113,12 +113,12 @@ TransactionView::TransactionView(const PlatformStyle *platformStyle, QWidget *pa hlayout->addWidget(typeWidget); - addressWidget = new QLineEdit(this); + search_widget = new QLineEdit(this); #if QT_VERSION >= 0x040700 - addressWidget->setPlaceholderText(tr("Enter address or label to search")); + search_widget->setPlaceholderText(tr("Enter address, transaction id, or label to search")); #endif addressWidget->setObjectName("addressWidget"); - hlayout->addWidget(addressWidget); + hlayout->addWidget(search_widget); amountWidget = new QLineEdit(this); #if QT_VERSION >= 0x040700 @@ -128,7 +128,7 @@ TransactionView::TransactionView(const PlatformStyle *platformStyle, QWidget *pa amountWidget->setFixedWidth(118); } else { amountWidget->setFixedWidth(125); - } + } amountWidget->setValidator(new QDoubleValidator(0, 1e20, 8, this)); amountWidget->setObjectName("amountWidget"); hlayout->addWidget(amountWidget); @@ -207,8 +207,8 @@ TransactionView::TransactionView(const PlatformStyle *platformStyle, QWidget *pa connect(instantsendWidget, SIGNAL(activated(int)), this, SLOT(chooseInstantSend(int))); connect(amountWidget, SIGNAL(textChanged(QString)), amount_typing_delay, SLOT(start())); connect(amount_typing_delay, SIGNAL(timeout()), this, SLOT(changedAmount())); - connect(addressWidget, SIGNAL(textChanged(QString)), prefix_typing_delay, SLOT(start())); - connect(prefix_typing_delay, SIGNAL(timeout()), this, SLOT(changedPrefix())); + connect(search_widget, SIGNAL(textChanged(QString)), prefix_typing_delay, SLOT(start())); + connect(prefix_typing_delay, SIGNAL(timeout()), this, SLOT(changedSearch())); connect(view, SIGNAL(doubleClicked(QModelIndex)), this, SIGNAL(doubleClicked(QModelIndex))); connect(view, SIGNAL(clicked(QModelIndex)), this, SLOT(computeSum())); @@ -285,7 +285,7 @@ void TransactionView::setModel(WalletModel *_model) // Watch-only signal connect(_model, SIGNAL(notifyWatchonlyChanged(bool)), this, SLOT(updateWatchOnlyColumn(bool))); - + // Update transaction list with persisted settings chooseType(settings.value("transactionType").toInt()); chooseDate(settings.value("transactionDate").toInt()); @@ -296,7 +296,7 @@ void TransactionView::chooseDate(int idx) { if(!transactionProxyModel) return; - + QSettings settings; QDate current = QDate::currentDate(); dateRangeWidget->setVisible(false); @@ -375,11 +375,11 @@ void TransactionView::chooseInstantSend(int idx) (TransactionFilterProxy::InstantSendFilter)instantsendWidget->itemData(idx).toInt()); } -void TransactionView::changedPrefix() +void TransactionView::changedSearch() { if(!transactionProxyModel) return; - transactionProxyModel->setAddressPrefix(addressWidget->text()); + transactionProxyModel->setSearchString(search_widget->text()); } void TransactionView::changedAmount() @@ -615,7 +615,7 @@ QWidget *TransactionView::createDateRangeWidget() QString defaultDateFrom = QDate::currentDate().toString(PERSISTENCE_DATE_FORMAT); QString defaultDateTo = QDate::currentDate().addDays(1).toString(PERSISTENCE_DATE_FORMAT); QSettings settings; - + dateRangeWidget = new QFrame(); dateRangeWidget->setFrameStyle(QFrame::Panel | QFrame::Raised); dateRangeWidget->setContentsMargins(1,1,1,1); @@ -656,12 +656,12 @@ void TransactionView::dateRangeChanged() { if(!transactionProxyModel) return; - + // Persist new date range QSettings settings; settings.setValue("transactionDateFrom", dateFrom->date().toString(PERSISTENCE_DATE_FORMAT)); settings.setValue("transactionDateTo", dateTo->date().toString(PERSISTENCE_DATE_FORMAT)); - + transactionProxyModel->setDateRange( QDateTime(dateFrom->date()), QDateTime(dateTo->date())); diff --git a/src/qt/transactionview.h b/src/qt/transactionview.h index 460f02efe8e78..a20bfc81009c6 100644 --- a/src/qt/transactionview.h +++ b/src/qt/transactionview.h @@ -68,7 +68,7 @@ class TransactionView : public QWidget QComboBox *typeWidget; QComboBox *watchOnlyWidget; QComboBox *instantsendWidget; - QLineEdit *addressWidget; + QLineEdit *search_widget; QLineEdit *amountWidget; QMenu *contextMenu; @@ -118,7 +118,7 @@ public Q_SLOTS: void chooseWatchonly(int idx); void chooseInstantSend(int idx); void changedAmount(); - void changedPrefix(); + void changedSearch(); void exportClicked(); void focusTransaction(const QModelIndex&); void computeSum();