-
Notifications
You must be signed in to change notification settings - Fork 388
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge bitcoin-core/gui#18: Add peertablesortproxy module
5a4a15d qt, refactor: Drop no longer used PeerTableModel::getRowByNodeId func (Hennadii Stepanov) 9a9f180 qt, refactor: Drop no longer used PeerTableModel::sort function (Hennadii Stepanov) 778a64a qt: Use PeerTableSortProxy for sorting peer table (Hennadii Stepanov) df2d165 qt: Add peertablesortproxy module (Hennadii Stepanov) Pull request description: The "Peers" table in the "Node" window does not hold multiple selection after sorting. This PR introduces a `QSortFilterProxyModel` subclass, that is a standard Qt [practice](https://doc.qt.io/qt-5/model-view-programming.html#custom-sorting-models) for such cases. Now the sorting code is encapsulated into the dedicated Qt class, and we do not need to maintain it. Fixes #283 (additionally). --- On **master** (7ae86b3): - rows are sorted by "Ping", and a selection is made ![Screenshot from 2020-11-28 22-53-11](https://user-images.githubusercontent.com/32963518/100525900-96eaed00-31cc-11eb-86e7-72ede3b8b33c.png) - rows are sorted by "NodeId", and the previous selection is _lost_ ![Screenshot from 2020-11-28 22-53-21](https://user-images.githubusercontent.com/32963518/100525904-9c483780-31cc-11eb-957c-06f53d7d31ab.png) With **this PR**: - rows are sorted by "Ping", and a selection is made ![Screenshot from 2020-11-28 22-39-41](https://user-images.githubusercontent.com/32963518/100525776-06aca800-31cc-11eb-8c4e-9c6566fe80fe.png) - rows are sorted by "NodeId", and the row are still selected ![Screenshot from 2020-11-28 22-39-53](https://user-images.githubusercontent.com/32963518/100525791-2348e000-31cc-11eb-8b78-716a5551d7ec.png) ACKs for top commit: jarolrod: re-ACK 5a4a15d, tested on macOS 11.2 Qt 5.15.2 after rebase promag: Tested ACK 5a4a15d. Tree-SHA512: f81c1385892fbf1a46ffb98b42094ca1cc97da52114bbbc94fedb553899b1f18c26a349e186bba6e27922a89426bd61e8bc88b1f7832512dbe211b5f834e076e
- Loading branch information
Showing
10 changed files
with
93 additions
and
155 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Copyright (c) 2020 The Bitcoin Core developers | ||
// Distributed under the MIT software license, see the accompanying | ||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
||
#include <qt/peertablesortproxy.h> | ||
|
||
#include <qt/peertablemodel.h> | ||
#include <util/check.h> | ||
|
||
#include <QModelIndex> | ||
#include <QString> | ||
#include <QVariant> | ||
|
||
PeerTableSortProxy::PeerTableSortProxy(QObject* parent) | ||
: QSortFilterProxyModel(parent) | ||
{ | ||
} | ||
|
||
bool PeerTableSortProxy::lessThan(const QModelIndex& left_index, const QModelIndex& right_index) const | ||
{ | ||
const CNodeStats left_stats = Assert(sourceModel()->data(left_index, PeerTableModel::StatsRole).value<CNodeCombinedStats*>())->nodeStats; | ||
const CNodeStats right_stats = Assert(sourceModel()->data(right_index, PeerTableModel::StatsRole).value<CNodeCombinedStats*>())->nodeStats; | ||
|
||
switch (static_cast<PeerTableModel::ColumnIndex>(left_index.column())) { | ||
case PeerTableModel::NetNodeId: | ||
return left_stats.nodeid < right_stats.nodeid; | ||
case PeerTableModel::Address: | ||
return left_stats.addrName.compare(right_stats.addrName) < 0; | ||
case PeerTableModel::ConnectionType: | ||
return left_stats.m_conn_type < right_stats.m_conn_type; | ||
case PeerTableModel::Network: | ||
return left_stats.m_network < right_stats.m_network; | ||
case PeerTableModel::Ping: | ||
return left_stats.m_min_ping_time < right_stats.m_min_ping_time; | ||
case PeerTableModel::Sent: | ||
return left_stats.nSendBytes < right_stats.nSendBytes; | ||
case PeerTableModel::Received: | ||
return left_stats.nRecvBytes < right_stats.nRecvBytes; | ||
case PeerTableModel::Subversion: | ||
return left_stats.cleanSubVer.compare(right_stats.cleanSubVer) < 0; | ||
} // no default case, so the compiler can warn about missing cases | ||
assert(false); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright (c) 2020 The Bitcoin Core developers | ||
// Distributed under the MIT software license, see the accompanying | ||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
||
#ifndef BITCOIN_QT_PEERTABLESORTPROXY_H | ||
#define BITCOIN_QT_PEERTABLESORTPROXY_H | ||
|
||
#include <QSortFilterProxyModel> | ||
|
||
QT_BEGIN_NAMESPACE | ||
class QModelIndex; | ||
QT_END_NAMESPACE | ||
|
||
class PeerTableSortProxy : public QSortFilterProxyModel | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
explicit PeerTableSortProxy(QObject* parent = nullptr); | ||
|
||
protected: | ||
bool lessThan(const QModelIndex& left_index, const QModelIndex& right_index) const override; | ||
}; | ||
|
||
#endif // BITCOIN_QT_PEERTABLESORTPROXY_H |
Oops, something went wrong.