Skip to content

Commit 38ab7d0

Browse files
committed
Merge #325: Align numbers in the "Peer Id" column to the right
69b8b5d qt: Align numbers in the "Peer Id" column to the right (Hennadii Stepanov) Pull request description: On master (6b49d88): ![Screenshot from 2021-05-12 21-53-52](https://user-images.githubusercontent.com/32963518/118029170-9013f900-b36c-11eb-9e27-36140cbd618e.png) With this PR: ![Screenshot from 2021-05-12 21-48-19](https://user-images.githubusercontent.com/32963518/118028803-2a277180-b36c-11eb-83ae-77d3e8cdd343.png) ACKs for top commit: jarolrod: ACK 69b8b5d jonatack: ACK 69b8b5d happy to re-ack with more separation or center-aligned kristapsk: ACK 69b8b5d Tree-SHA512: 3279522745a0fe6db1ec9be723a2640a37983947ed1af4aad56f22ce4780cc943a25b2d774529a9eeb3b00309f0204cfbc3f38b7db2c52865d05bf6a7c87e747
2 parents 898dd9e + 69b8b5d commit 38ab7d0

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/qt/peertablemodel.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ QVariant PeerTableModel::data(const QModelIndex &index, int role) const
132132
} else if (role == Qt::TextAlignmentRole) {
133133
switch (column) {
134134
case NetNodeId:
135+
return QVariant(Qt::AlignRight | Qt::AlignVCenter);
135136
case Address:
136137
return {};
137138
case ConnectionType:

src/qt/rpcconsole.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,19 @@
3737
#include <QDateTime>
3838
#include <QFont>
3939
#include <QKeyEvent>
40+
#include <QLatin1String>
41+
#include <QLocale>
4042
#include <QMenu>
4143
#include <QMessageBox>
4244
#include <QScreen>
4345
#include <QScrollBar>
4446
#include <QSettings>
4547
#include <QString>
4648
#include <QStringList>
49+
#include <QStyledItemDelegate>
4750
#include <QTime>
4851
#include <QTimer>
49-
52+
#include <QVariant>
5053

5154
const int CONSOLE_HISTORY = 50;
5255
const int INITIAL_TRAFFIC_GRAPH_MINS = 30;
@@ -128,6 +131,20 @@ class QtRPCTimerInterface: public RPCTimerInterface
128131
}
129132
};
130133

134+
class PeerIdViewDelegate : public QStyledItemDelegate
135+
{
136+
Q_OBJECT
137+
public:
138+
explicit PeerIdViewDelegate(QObject* parent = nullptr)
139+
: QStyledItemDelegate(parent) {}
140+
141+
QString displayText(const QVariant& value, const QLocale& locale) const override
142+
{
143+
// Additional spaces should visually separate right-aligned content
144+
// from the next column to the right.
145+
return value.toString() + QLatin1String(" ");
146+
}
147+
};
131148

132149
#include <qt/rpcconsole.moc>
133150

@@ -644,6 +661,7 @@ void RPCConsole::setClientModel(ClientModel *model, int bestblock_height, int64_
644661
ui->peerWidget->setColumnWidth(PeerTableModel::Subversion, SUBVERSION_COLUMN_WIDTH);
645662
ui->peerWidget->setColumnWidth(PeerTableModel::Ping, PING_COLUMN_WIDTH);
646663
ui->peerWidget->horizontalHeader()->setStretchLastSection(true);
664+
ui->peerWidget->setItemDelegateForColumn(PeerTableModel::NetNodeId, new PeerIdViewDelegate(this));
647665

648666
// create peer table context menu
649667
peersTableContextMenu = new QMenu(this);

0 commit comments

Comments
 (0)