Skip to content

Commit 217d42b

Browse files
committed
gui: Add "Alternating Row Color" settings for the Peers Tab
1 parent ada34cf commit 217d42b

File tree

7 files changed

+40
-8
lines changed

7 files changed

+40
-8
lines changed

src/qt/forms/debugwindow.ui

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -893,9 +893,6 @@
893893
<property name="tabKeyNavigation">
894894
<bool>false</bool>
895895
</property>
896-
<property name="alternatingRowColors">
897-
<bool>true</bool>
898-
</property>
899896
<property name="textElideMode">
900897
<enum>Qt::ElideMiddle</enum>
901898
</property>
@@ -957,9 +954,6 @@
957954
<property name="tabKeyNavigation">
958955
<bool>false</bool>
959956
</property>
960-
<property name="alternatingRowColors">
961-
<bool>true</bool>
962-
</property>
963957
<property name="sortingEnabled">
964958
<bool>true</bool>
965959
</property>

src/qt/forms/optionsdialog.ui

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
<rect>
77
<x>0</x>
88
<y>0</y>
9-
<width>560</width>
10-
<height>440</height>
9+
<width>646</width>
10+
<height>529</height>
1111
</rect>
1212
</property>
1313
<property name="windowTitle">
@@ -805,6 +805,16 @@
805805
</layout>
806806
</widget>
807807
</item>
808+
<item>
809+
<widget class="QCheckBox" name="peersTabAlternatingRowColors">
810+
<property name="toolTip">
811+
<string>Alternate the row colors for the &quot;Peers&quot; and &quot;Banned peers&quot; tables in the Peers tab.</string>
812+
</property>
813+
<property name="text">
814+
<string>Alternate row colors in the Peers tab</string>
815+
</property>
816+
</widget>
817+
</item>
808818
<item>
809819
<spacer name="verticalSpacer_Display">
810820
<property name="orientation">

src/qt/optionsdialog.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ void OptionsDialog::setMapper()
261261
mapper->addMapping(ui->unit, OptionsModel::DisplayUnit);
262262
mapper->addMapping(ui->thirdPartyTxUrls, OptionsModel::ThirdPartyTxUrls);
263263
mapper->addMapping(ui->embeddedFont_radioButton, OptionsModel::UseEmbeddedMonospacedFont);
264+
mapper->addMapping(ui->peersTabAlternatingRowColors, OptionsModel::PeersTabAlternatingRowColors);
264265
}
265266

266267
void OptionsDialog::setOkButtonState(bool fState)

src/qt/optionsmodel.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,12 @@ void OptionsModel::Init(bool resetSettings)
170170
}
171171
m_use_embedded_monospaced_font = settings.value("UseEmbeddedMonospacedFont").toBool();
172172
Q_EMIT useEmbeddedMonospacedFontChanged(m_use_embedded_monospaced_font);
173+
174+
if (!settings.contains("PeersTabAlternatingRowColors")) {
175+
settings.setValue("PeersTabAlternatingRowColors", "false");
176+
}
177+
m_peers_tab_alternating_row_colors = settings.value("PeersTabAlternatingRowColors").toBool();
178+
Q_EMIT peersTabAlternatingRowColorsChanged(m_peers_tab_alternating_row_colors);
173179
}
174180

175181
/** Helper function to copy contents from one QSettings to another.
@@ -335,6 +341,8 @@ QVariant OptionsModel::data(const QModelIndex & index, int role) const
335341
return settings.value("language");
336342
case UseEmbeddedMonospacedFont:
337343
return m_use_embedded_monospaced_font;
344+
case PeersTabAlternatingRowColors:
345+
return m_peers_tab_alternating_row_colors;
338346
case CoinControlFeatures:
339347
return fCoinControlFeatures;
340348
case Prune:
@@ -467,6 +475,11 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in
467475
settings.setValue("UseEmbeddedMonospacedFont", m_use_embedded_monospaced_font);
468476
Q_EMIT useEmbeddedMonospacedFontChanged(m_use_embedded_monospaced_font);
469477
break;
478+
case PeersTabAlternatingRowColors:
479+
m_peers_tab_alternating_row_colors = value.toBool();
480+
settings.setValue("PeersTabAlternatingRowColors", m_peers_tab_alternating_row_colors);
481+
Q_EMIT peersTabAlternatingRowColorsChanged(m_peers_tab_alternating_row_colors);
482+
break;
470483
case CoinControlFeatures:
471484
fCoinControlFeatures = value.toBool();
472485
settings.setValue("fCoinControlFeatures", fCoinControlFeatures);

src/qt/optionsmodel.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ class OptionsModel : public QAbstractListModel
6060
ThirdPartyTxUrls, // QString
6161
Language, // QString
6262
UseEmbeddedMonospacedFont, // bool
63+
PeersTabAlternatingRowColors, // bool
6364
CoinControlFeatures, // bool
6465
ThreadsScriptVerif, // int
6566
Prune, // bool
@@ -86,6 +87,7 @@ class OptionsModel : public QAbstractListModel
8687
int getDisplayUnit() const { return nDisplayUnit; }
8788
QString getThirdPartyTxUrls() const { return strThirdPartyTxUrls; }
8889
bool getUseEmbeddedMonospacedFont() const { return m_use_embedded_monospaced_font; }
90+
bool getPeersTabAlternatingRowColors() const { return m_peers_tab_alternating_row_colors; }
8991
bool getCoinControlFeatures() const { return fCoinControlFeatures; }
9092
const QString& getOverriddenByCommandLine() { return strOverriddenByCommandLine; }
9193

@@ -110,6 +112,7 @@ class OptionsModel : public QAbstractListModel
110112
int nDisplayUnit;
111113
QString strThirdPartyTxUrls;
112114
bool m_use_embedded_monospaced_font;
115+
bool m_peers_tab_alternating_row_colors;
113116
bool fCoinControlFeatures;
114117
/* settings that were overridden by command-line */
115118
QString strOverriddenByCommandLine;
@@ -124,6 +127,7 @@ class OptionsModel : public QAbstractListModel
124127
void coinControlFeaturesChanged(bool);
125128
void showTrayIconChanged(bool);
126129
void useEmbeddedMonospacedFontChanged(bool);
130+
void peersTabAlternatingRowColorsChanged(bool);
127131
};
128132

129133
#endif // BITCOIN_QT_OPTIONSMODEL_H

src/qt/rpcconsole.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <netbase.h>
1515
#include <qt/bantablemodel.h>
1616
#include <qt/clientmodel.h>
17+
#include <qt/optionsmodel.h>
1718
#include <qt/peertablesortproxy.h>
1819
#include <qt/platformstyle.h>
1920
#include <qt/walletmodel.h>
@@ -489,6 +490,7 @@ RPCConsole::RPCConsole(interfaces::Node& node, const PlatformStyle *_platformSty
489490

490491
m_peer_widget_header_state = settings.value("PeersTabPeerHeaderState").toByteArray();
491492
m_banlist_widget_header_state = settings.value("PeersTabBanlistHeaderState").toByteArray();
493+
m_alternating_row_colors = settings.value("PeersTabAlternatingRowColors").toBool();
492494

493495
constexpr QChar nonbreaking_hyphen(8209);
494496
const std::vector<QString> CONNECTION_TYPE_DOC{
@@ -658,6 +660,11 @@ void RPCConsole::setClientModel(ClientModel *model, int bestblock_height, int64_
658660

659661
connect(model, &ClientModel::mempoolSizeChanged, this, &RPCConsole::setMempoolSize);
660662

663+
connect(model->getOptionsModel(), &OptionsModel::peersTabAlternatingRowColorsChanged, [this](bool alternating_row_colors) {
664+
ui->peerWidget->setAlternatingRowColors(alternating_row_colors);
665+
ui->banlistWidget->setAlternatingRowColors(alternating_row_colors);
666+
});
667+
661668
// set up peer table
662669
ui->peerWidget->setModel(model->peerTableSortProxy());
663670
ui->peerWidget->verticalHeader()->hide();
@@ -672,6 +679,7 @@ void RPCConsole::setClientModel(ClientModel *model, int bestblock_height, int64_
672679
}
673680
ui->peerWidget->horizontalHeader()->setStretchLastSection(true);
674681
ui->peerWidget->setItemDelegateForColumn(PeerTableModel::NetNodeId, new PeerIdViewDelegate(this));
682+
ui->peerWidget->setAlternatingRowColors(m_alternating_row_colors);
675683

676684
// create peer table context menu
677685
peersTableContextMenu = new QMenu(this);
@@ -698,6 +706,7 @@ void RPCConsole::setClientModel(ClientModel *model, int bestblock_height, int64_
698706
ui->banlistWidget->setColumnWidth(BanTableModel::Bantime, BANTIME_COLUMN_WIDTH);
699707
}
700708
ui->banlistWidget->horizontalHeader()->setStretchLastSection(true);
709+
ui->banlistWidget->setAlternatingRowColors(m_alternating_row_colors);
701710

702711
// create ban table context menu
703712
banTableContextMenu = new QMenu(this);

src/qt/rpcconsole.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ public Q_SLOTS:
170170
bool m_is_executing{false};
171171
QByteArray m_peer_widget_header_state;
172172
QByteArray m_banlist_widget_header_state;
173+
bool m_alternating_row_colors{false};
173174

174175
/** Update UI with latest network info from model. */
175176
void updateNetworkState();

0 commit comments

Comments
 (0)