Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
Already on GitHub? Sign in to your account
Qt: Enable searching by transaction id #11395
Conversation
fanquake
added
the
GUI
label
Sep 25, 2017
MeshCollider
reviewed
Sep 25, 2017
•
utACK 3b35414
nit: use snake_case since you are refactoring the variable names anyway
| @@ -36,6 +36,7 @@ bool TransactionFilterProxy::filterAcceptsRow(int sourceRow, const QModelIndex & | ||
| int type = index.data(TransactionTableModel::TypeRole).toInt(); | ||
| QDateTime datetime = index.data(TransactionTableModel::DateRole).toDateTime(); | ||
| bool involvesWatchAddress = index.data(TransactionTableModel::WatchonlyRole).toBool(); | ||
| + QString txid = index.data(TransactionTableModel::TxIDRole).toString(); |
promag
Sep 25, 2017
Contributor
Nit, declare after label (sorted and follows the same test order below)?
| @@ -20,7 +20,7 @@ TransactionFilterProxy::TransactionFilterProxy(QObject *parent) : | ||
| QSortFilterProxyModel(parent), | ||
| dateFrom(MIN_DATE), | ||
| dateTo(MAX_DATE), | ||
| - addrPrefix(), | ||
| + searchString(), |
| @@ -51,8 +52,11 @@ bool TransactionFilterProxy::filterAcceptsRow(int sourceRow, const QModelIndex & | ||
| return false; | ||
| if(datetime < dateFrom || datetime > dateTo) | ||
| return false; | ||
| - if (!address.contains(searchString, Qt::CaseInsensitive) && !label.contains(searchString, Qt::CaseInsensitive)) | ||
| + if (!address.contains(searchString, Qt::CaseInsensitive) |
promag
Sep 25, 2017
Contributor
Avoid unnecessary code execution?
if (!searchString.isEmpty()) {
...
}
luke-jr
Sep 25, 2017
Member
address.contains("") will immediately return true, so the other two clauses won't get executed. I don't know that we need to over-optimise here.
| @@ -51,8 +52,11 @@ bool TransactionFilterProxy::filterAcceptsRow(int sourceRow, const QModelIndex & | ||
| return false; | ||
| if(datetime < dateFrom || datetime > dateTo) | ||
| return false; | ||
| - if (!address.contains(searchString, Qt::CaseInsensitive) && !label.contains(searchString, Qt::CaseInsensitive)) | ||
| + if (!address.contains(searchString, Qt::CaseInsensitive) | ||
| + && ! label.contains(searchString, Qt::CaseInsensitive) |
promag
Sep 25, 2017
Contributor
As it is clang-format makes it one line. This is preserved by clang-format:
if (!address.contains(searchString, Qt::CaseInsensitive) &&
!label.contains(searchString, Qt::CaseInsensitive) &&
!txid.contains(searchString, Qt::CaseInsensitive)) {| @@ -66,9 +66,9 @@ void TransactionFilterProxy::setDateRange(const QDateTime &from, const QDateTime | ||
| invalidateFilter(); | ||
| } | ||
| -void TransactionFilterProxy::setAddressPrefix(const QString &_addrPrefix) | ||
| +void TransactionFilterProxy::setSearchString(const QString &_searchString) |
| { | ||
| - this->addrPrefix = _addrPrefix; | ||
| + this->searchString = _searchString; |
promag
Sep 25, 2017
Contributor
As it is now yes because QLineEdit doesn't emit unnecessary signals. But from this method perspective IMO this makes sense, the cost of the condition is way cheaper than invalidating the filter.
promag
Sep 25, 2017
Contributor
BTW, we could lower case the stored m_search_string to make the filter faster.
luke-jr
Sep 25, 2017
Member
On second thought, we should never get to this point if the string hasn't changed, and lowercasing the search string doesn't make the filter faster because label/address aren't lowercased.
promag
Sep 25, 2017
Contributor
Imagine if pressing the ESC key erases the search string, pressing it the 2nd time would do nothing if the check is there.
So why .contains(..., Qt::CaseInsensitive)?
| @@ -305,11 +305,11 @@ void TransactionView::chooseWatchonly(int idx) | ||
| (TransactionFilterProxy::WatchOnlyFilter)watchOnlyWidget->itemData(idx).toInt()); | ||
| } | ||
| -void TransactionView::changedPrefix(const QString &prefix) | ||
| +void TransactionView::changedSearch(const QString &prefix) |
| { | ||
| if(!transactionProxyModel) | ||
| return; | ||
| - transactionProxyModel->setAddressPrefix(prefix); | ||
| + transactionProxyModel->setSearchString(prefix); |
| @@ -51,8 +52,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) && |
luke-jr
Sep 26, 2017
Member
I consider this a shortcoming of clang-format, then. I don't consider the remaining nits as things that should be changed.
| @@ -66,9 +66,9 @@ void TransactionFilterProxy::setDateRange(const QDateTime &from, const QDateTime | ||
| invalidateFilter(); | ||
| } | ||
| -void TransactionFilterProxy::setAddressPrefix(const QString &_addrPrefix) | ||
| +void TransactionFilterProxy::setSearchString(const QString &search_string) |
| @@ -35,7 +35,7 @@ class TransactionFilterProxy : public QSortFilterProxyModel | ||
| }; | ||
| void setDateRange(const QDateTime &from, const QDateTime &to); | ||
| - void setAddressPrefix(const QString &addrPrefix); | ||
| + void setSearchString(const QString &); |
MeshCollider
Nov 13, 2017
Member
Nit: I prefer having the variable names in the header (all others in this header do too). Unsure if there's a general preference though
| @@ -305,11 +305,11 @@ void TransactionView::chooseWatchonly(int idx) | ||
| (TransactionFilterProxy::WatchOnlyFilter)watchOnlyWidget->itemData(idx).toInt()); | ||
| } | ||
| -void TransactionView::changedPrefix(const QString &prefix) | ||
| +void TransactionView::changedSearch(const QString &search_string) |
| @@ -66,7 +66,7 @@ class TransactionView : public QWidget | ||
| QComboBox *dateWidget; | ||
| QComboBox *typeWidget; | ||
| QComboBox *watchOnlyWidget; | ||
| - QLineEdit *addressWidget; | ||
| + QLineEdit *search_widget; |
| @@ -110,7 +110,7 @@ public Q_SLOTS: | ||
| void chooseDate(int idx); | ||
| void chooseType(int idx); | ||
| void chooseWatchonly(int idx); | ||
| - void changedPrefix(const QString &prefix); | ||
| + void changedSearch(const QString &search_string); |
| @@ -51,8 +52,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) && |
promag
Sep 25, 2017
Contributor
BTW, back to if (!m_search_string.isEmpty()) { ... }, it can also save querying the model for those properties:
if (!m_search_string_lowered_case.isEmpty()) {
QString address = ...toLowerCase();
...
return ...;
}
These aren't significant changes so why not comply with developer notes? |
|
The developer notes don't say anything about which side |
|
Concept ACK (haven't looked at the code so far). |
|
Needs rebase. |
|
@luke-jr ping. |
It is also strange to not have the txid in the "Transactions" view. |
luke-jr
added some commits
Sep 25, 2017
|
Rebased |
|
Restarted travis job due to unrelated error. |
|
utACK. |
| @@ -35,7 +35,7 @@ class TransactionFilterProxy : public QSortFilterProxyModel | ||
| }; | ||
| void setDateRange(const QDateTime &from, const QDateTime &to); | ||
| - void setAddressPrefix(const QString &addrPrefix); | ||
| + void setSearchString(const QString &); |
MeshCollider
Nov 13, 2017
Member
Nit: I prefer having the variable names in the header (all others in this header do too). Unsure if there's a general preference though

luke-jr commentedSep 25, 2017
No description provided.