-
Notifications
You must be signed in to change notification settings - Fork 268
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add peertablesortproxy module #18
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
df2d165
qt: Add peertablesortproxy module
hebasto 778a64a
qt: Use PeerTableSortProxy for sorting peer table
hebasto 9a9f180
qt, refactor: Drop no longer used PeerTableModel::sort function
hebasto 5a4a15d
qt, refactor: Drop no longer used PeerTableModel::getRowByNodeId func
hebasto File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
778a64a
I don't think this belongs here, should be a member of
RPCConsole
- usually, sort/filter models are instanced for each view unless you want to share the same sorting/filter result in multiple views (I know it's only used inRPCConsole
).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From the
##bitcoin-core-gui
IRC channel: