From 78da2b5b1b5b2e4c43b4fddb6324a30ea1bdc574 Mon Sep 17 00:00:00 2001 From: "moneromooo.monero" Date: Wed, 16 Nov 2016 23:09:00 +0000 Subject: [PATCH] History: replace payment id search with global incremental search --- pages/History.qml | 30 ++++++-------- .../TransactionHistorySortFilterModel.cpp | 41 ++++++++++++++++++- src/model/TransactionHistorySortFilterModel.h | 7 ++++ 3 files changed, 60 insertions(+), 18 deletions(-) diff --git a/pages/History.qml b/pages/History.qml index 2a1eca7f..c6f94dd4 100644 --- a/pages/History.qml +++ b/pages/History.qml @@ -170,34 +170,32 @@ Rectangle { } */ - // Filter by Payment ID input + // Filter by string Label { - id: paymentIdLabel + id: searchLabel anchors.left: parent.left anchors.top: filterHeaderText.bottom // addressLine.bottom anchors.leftMargin: 17 anchors.topMargin: 17 - text: qsTr("Payment ID (Optional)") + translationManager.emptyString + text: qsTr("Incremental search") + translationManager.emptyString fontSize: 14 - tipText: qsTr("Payment ID

A unique user name used in
the address book. It is not a
transfer of information sent
during thevtransfer") - + translationManager.emptyString + tipText: qsTr("Search transfers for a given string") + translationManager.emptyString } LineEdit { - id: paymentIdLine + id: searchLine anchors.left: parent.left anchors.right: parent.right - anchors.top: paymentIdLabel.bottom // addressLabel.bottom + anchors.top: searchLabel.bottom // addressLabel.bottom anchors.leftMargin: 17 anchors.rightMargin: 17 anchors.topMargin: 5 - placeholderText: qsTr("16 or 64 hexadecimal characters") + translationManager.emptyString - validator: RegExpValidator { - regExp: /[0-9a-fA-F]+/ + placeholderText: qsTr("Type search string") + translationManager.emptyString + onTextChanged: { + model.searchFilter = searchLine.text + selectedAmount.text = getSelectedAmount() } - - } // Filter by description input (not implemented yet) @@ -205,7 +203,7 @@ Rectangle { Label { id: descriptionLabel anchors.left: parent.left - anchors.top: paymentIdLine.bottom + anchors.top: searchLine.bottom anchors.leftMargin: 17 anchors.topMargin: 17 text: qsTr("Description (Local database)") + translationManager.emptyString @@ -229,7 +227,7 @@ Rectangle { Label { id: dateFromText anchors.left: parent.left - anchors.top: paymentIdLine.bottom // descriptionLine.bottom + anchors.top: searchLine.bottom // descriptionLine.bottom anchors.leftMargin: 17 anchors.topMargin: 17 width: 156 @@ -255,7 +253,7 @@ Rectangle { Label { id: dateToText anchors.left: dateFromText.right - anchors.top: paymentIdLine.bottom //descriptionLine.bottom + anchors.top: searchLine.bottom //descriptionLine.bottom anchors.leftMargin: 17 anchors.topMargin: 17 text: qsTr("To") @@ -292,8 +290,6 @@ Rectangle { onClicked: { // Apply filter here; - model.paymentIdFilter = paymentIdLine.text - resetFilter(model) if (fromDatePicker.currentDate > toDatePicker.currentDate) { diff --git a/src/model/TransactionHistorySortFilterModel.cpp b/src/model/TransactionHistorySortFilterModel.cpp index 6d6a2b44..c2dd0e6f 100644 --- a/src/model/TransactionHistorySortFilterModel.cpp +++ b/src/model/TransactionHistorySortFilterModel.cpp @@ -42,6 +42,20 @@ TransactionHistorySortFilterModel::TransactionHistorySortFilterModel(QObject *pa setDynamicSortFilter(true); } +QString TransactionHistorySortFilterModel::searchFilter() const +{ + return m_searchString; +} + +void TransactionHistorySortFilterModel::setSearchFilter(const QString &arg) +{ + if (searchFilter() != arg) { + m_searchString = arg; + emit searchFilterChanged(); + invalidateFilter(); + } +} + QString TransactionHistorySortFilterModel::paymentIdFilter() const { return m_filterValues.value(TransactionHistoryModel::TransactionPaymentIdRole).toString(); @@ -200,7 +214,32 @@ bool TransactionHistorySortFilterModel::filterAcceptsRow(int source_row, const Q } } - return result; + if (!result || m_searchString.isEmpty()) + return result; + + QVariant data = sourceModel()->data(index, TransactionHistoryModel::TransactionPaymentIdRole); + if (data.toString().contains(m_searchString)) + return true; + data = sourceModel()->data(index, TransactionHistoryModel::TransactionDisplayAmountRole); + if (data.toString().contains(m_searchString)) + return true; + data = sourceModel()->data(index, TransactionHistoryModel::TransactionBlockHeightRole); + if (data.toString().contains(m_searchString)) + return true; + data = sourceModel()->data(index, TransactionHistoryModel::TransactionFeeRole); + if (data.toString().contains(m_searchString)) + return true; + data = sourceModel()->data(index, TransactionHistoryModel::TransactionHashRole); + if (data.toString().contains(m_searchString)) + return true; + data = sourceModel()->data(index, TransactionHistoryModel::TransactionDateRole); + if (data.toString().contains(m_searchString)) + return true; + data = sourceModel()->data(index, TransactionHistoryModel::TransactionTimeRole); + if (data.toString().contains(m_searchString)) + return true; + + return false; } bool TransactionHistorySortFilterModel::lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const diff --git a/src/model/TransactionHistorySortFilterModel.h b/src/model/TransactionHistorySortFilterModel.h index 1b5c2fce..b8f0031d 100644 --- a/src/model/TransactionHistorySortFilterModel.h +++ b/src/model/TransactionHistorySortFilterModel.h @@ -14,6 +14,7 @@ class TransactionHistory; class TransactionHistorySortFilterModel: public QSortFilterProxyModel { Q_OBJECT + Q_PROPERTY(QString searchFilter READ searchFilter WRITE setSearchFilter NOTIFY searchFilterChanged) Q_PROPERTY(QString paymentIdFilter READ paymentIdFilter WRITE setPaymentIdFilter NOTIFY paymentIdFilterChanged) Q_PROPERTY(QDate dateFromFilter READ dateFromFilter WRITE setDateFromFilter NOTIFY dateFromFilterChanged) Q_PROPERTY(QDate dateToFilter READ dateToFilter WRITE setDateToFilter NOTIFY dateToFilterChanged) @@ -25,6 +26,10 @@ class TransactionHistorySortFilterModel: public QSortFilterProxyModel public: TransactionHistorySortFilterModel(QObject * parent = nullptr); + //! filtering by string search + QString searchFilter() const; + void setSearchFilter(const QString &arg); + //! filtering by payment id QString paymentIdFilter() const; void setPaymentIdFilter(const QString &arg); @@ -53,6 +58,7 @@ public: TransactionHistory * transactionHistory() const; signals: + void searchFilterChanged(); void paymentIdFilterChanged(); void dateFromFilterChanged(); void dateToFilterChanged(); @@ -74,6 +80,7 @@ private: private: QMap m_filterValues; + QString m_searchString; }; #endif // TRANSACTIONHISTORYSORTFILTERMODEL_H