Skip to content

Commit df2d165

Browse files
committed
qt: Add peertablesortproxy module
1 parent 8c049fe commit df2d165

File tree

4 files changed

+73
-0
lines changed

4 files changed

+73
-0
lines changed

build_msvc/libbitcoin_qt/libbitcoin_qt.vcxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
<ClCompile Include="..\..\src\qt\overviewpage.cpp" />
3535
<ClCompile Include="..\..\src\qt\paymentserver.cpp" />
3636
<ClCompile Include="..\..\src\qt\peertablemodel.cpp" />
37+
<ClCompile Include="..\..\src\qt\peertablesortproxy.cpp" />
3738
<ClCompile Include="..\..\src\qt\platformstyle.cpp" />
3839
<ClCompile Include="..\..\src\qt\psbtoperationsdialog.cpp" />
3940
<ClCompile Include="..\..\src\qt\qrimagewidget.cpp" />
@@ -87,6 +88,7 @@
8788
<ClCompile Include="$(GeneratedFilesOutDir)\moc\moc_overviewpage.cpp" />
8889
<ClCompile Include="$(GeneratedFilesOutDir)\moc\moc_paymentserver.cpp" />
8990
<ClCompile Include="$(GeneratedFilesOutDir)\moc\moc_peertablemodel.cpp" />
91+
<ClCompile Include="$(GeneratedFilesOutDir)\moc\moc_peertablesortproxy.cpp" />
9092
<ClCompile Include="$(GeneratedFilesOutDir)\moc\moc_platformstyle.cpp" />
9193
<ClCompile Include="$(GeneratedFilesOutDir)\moc\moc_psbtoperationsdialog.cpp" />
9294
<ClCompile Include="$(GeneratedFilesOutDir)\moc\moc_qrimagewidget.cpp" />

src/Makefile.qt.include

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ QT_MOC_CPP = \
6161
qt/moc_optionsmodel.cpp \
6262
qt/moc_overviewpage.cpp \
6363
qt/moc_peertablemodel.cpp \
64+
qt/moc_peertablesortproxy.cpp \
6465
qt/moc_paymentserver.cpp \
6566
qt/moc_psbtoperationsdialog.cpp \
6667
qt/moc_qrimagewidget.cpp \
@@ -134,6 +135,7 @@ BITCOIN_QT_H = \
134135
qt/overviewpage.h \
135136
qt/paymentserver.h \
136137
qt/peertablemodel.h \
138+
qt/peertablesortproxy.h \
137139
qt/platformstyle.h \
138140
qt/psbtoperationsdialog.h \
139141
qt/qrimagewidget.h \
@@ -232,6 +234,7 @@ BITCOIN_QT_BASE_CPP = \
232234
qt/optionsdialog.cpp \
233235
qt/optionsmodel.cpp \
234236
qt/peertablemodel.cpp \
237+
qt/peertablesortproxy.cpp \
235238
qt/platformstyle.cpp \
236239
qt/qvalidatedlineedit.cpp \
237240
qt/qvaluecombobox.cpp \

src/qt/peertablesortproxy.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Copyright (c) 2020 The Bitcoin Core developers
2+
// Distributed under the MIT software license, see the accompanying
3+
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4+
5+
#include <qt/peertablesortproxy.h>
6+
7+
#include <qt/peertablemodel.h>
8+
#include <util/check.h>
9+
10+
#include <QModelIndex>
11+
#include <QString>
12+
#include <QVariant>
13+
14+
PeerTableSortProxy::PeerTableSortProxy(QObject* parent)
15+
: QSortFilterProxyModel(parent)
16+
{
17+
}
18+
19+
bool PeerTableSortProxy::lessThan(const QModelIndex& left_index, const QModelIndex& right_index) const
20+
{
21+
const CNodeStats left_stats = Assert(sourceModel()->data(left_index, PeerTableModel::StatsRole).value<CNodeCombinedStats*>())->nodeStats;
22+
const CNodeStats right_stats = Assert(sourceModel()->data(right_index, PeerTableModel::StatsRole).value<CNodeCombinedStats*>())->nodeStats;
23+
24+
switch (static_cast<PeerTableModel::ColumnIndex>(left_index.column())) {
25+
case PeerTableModel::NetNodeId:
26+
return left_stats.nodeid < right_stats.nodeid;
27+
case PeerTableModel::Address:
28+
return left_stats.addrName.compare(right_stats.addrName) < 0;
29+
case PeerTableModel::ConnectionType:
30+
return left_stats.m_conn_type < right_stats.m_conn_type;
31+
case PeerTableModel::Network:
32+
return left_stats.m_network < right_stats.m_network;
33+
case PeerTableModel::Ping:
34+
return left_stats.m_min_ping_time < right_stats.m_min_ping_time;
35+
case PeerTableModel::Sent:
36+
return left_stats.nSendBytes < right_stats.nSendBytes;
37+
case PeerTableModel::Received:
38+
return left_stats.nRecvBytes < right_stats.nRecvBytes;
39+
case PeerTableModel::Subversion:
40+
return left_stats.cleanSubVer.compare(right_stats.cleanSubVer) < 0;
41+
} // no default case, so the compiler can warn about missing cases
42+
assert(false);
43+
}

src/qt/peertablesortproxy.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright (c) 2020 The Bitcoin Core developers
2+
// Distributed under the MIT software license, see the accompanying
3+
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4+
5+
#ifndef BITCOIN_QT_PEERTABLESORTPROXY_H
6+
#define BITCOIN_QT_PEERTABLESORTPROXY_H
7+
8+
#include <QSortFilterProxyModel>
9+
10+
QT_BEGIN_NAMESPACE
11+
class QModelIndex;
12+
QT_END_NAMESPACE
13+
14+
class PeerTableSortProxy : public QSortFilterProxyModel
15+
{
16+
Q_OBJECT
17+
18+
public:
19+
explicit PeerTableSortProxy(QObject* parent = nullptr);
20+
21+
protected:
22+
bool lessThan(const QModelIndex& left_index, const QModelIndex& right_index) const override;
23+
};
24+
25+
#endif // BITCOIN_QT_PEERTABLESORTPROXY_H

0 commit comments

Comments
 (0)