Skip to content

Commit

Permalink
gui: Add "Alternating Row Color" settings for the Peers Tab
Browse files Browse the repository at this point in the history
  • Loading branch information
hebasto committed May 1, 2021
1 parent 00e27aa commit 180539a
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 8 deletions.
6 changes: 0 additions & 6 deletions src/qt/forms/debugwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -923,9 +923,6 @@
<property name="tabKeyNavigation">
<bool>false</bool>
</property>
<property name="alternatingRowColors">
<bool>true</bool>
</property>
<property name="textElideMode">
<enum>Qt::ElideMiddle</enum>
</property>
Expand Down Expand Up @@ -987,9 +984,6 @@
<property name="tabKeyNavigation">
<bool>false</bool>
</property>
<property name="alternatingRowColors">
<bool>true</bool>
</property>
<property name="sortingEnabled">
<bool>true</bool>
</property>
Expand Down
14 changes: 12 additions & 2 deletions src/qt/forms/optionsdialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>560</width>
<height>440</height>
<width>646</width>
<height>529</height>
</rect>
</property>
<property name="windowTitle">
Expand Down Expand Up @@ -805,6 +805,16 @@
</layout>
</widget>
</item>
<item>
<widget class="QCheckBox" name="peersTabAlternatingRowColors">
<property name="toolTip">
<string>Turn on/off row color alternating for both &quot;Peers&quot; and &quot;Banned peers&quot; tables in the Peer Tab.</string>
</property>
<property name="text">
<string>Alternate row colors in the Peers Tab</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_Display">
<property name="orientation">
Expand Down
1 change: 1 addition & 0 deletions src/qt/optionsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ void OptionsDialog::setMapper()
mapper->addMapping(ui->unit, OptionsModel::DisplayUnit);
mapper->addMapping(ui->thirdPartyTxUrls, OptionsModel::ThirdPartyTxUrls);
mapper->addMapping(ui->embeddedFont_radioButton, OptionsModel::UseEmbeddedMonospacedFont);
mapper->addMapping(ui->peersTabAlternatingRowColors, OptionsModel::PeersTabAlternatingRowColors);
}

void OptionsDialog::setOkButtonState(bool fState)
Expand Down
13 changes: 13 additions & 0 deletions src/qt/optionsmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,12 @@ void OptionsModel::Init(bool resetSettings)
}
m_use_embedded_monospaced_font = settings.value("UseEmbeddedMonospacedFont").toBool();
Q_EMIT useEmbeddedMonospacedFontChanged(m_use_embedded_monospaced_font);

if (!settings.contains("PeersTabAlternatingRowColors")) {
settings.setValue("PeersTabAlternatingRowColors", "false");
}
m_peers_tab_alternating_row_colors = settings.value("PeersTabAlternatingRowColors").toBool();
Q_EMIT peersTabAlternatingRowColorsChanged(m_peers_tab_alternating_row_colors);
}

/** Helper function to copy contents from one QSettings to another.
Expand Down Expand Up @@ -334,6 +340,8 @@ QVariant OptionsModel::data(const QModelIndex & index, int role) const
return settings.value("language");
case UseEmbeddedMonospacedFont:
return m_use_embedded_monospaced_font;
case PeersTabAlternatingRowColors:
return m_peers_tab_alternating_row_colors;
case CoinControlFeatures:
return fCoinControlFeatures;
case Prune:
Expand Down Expand Up @@ -466,6 +474,11 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in
settings.setValue("UseEmbeddedMonospacedFont", m_use_embedded_monospaced_font);
Q_EMIT useEmbeddedMonospacedFontChanged(m_use_embedded_monospaced_font);
break;
case PeersTabAlternatingRowColors:
m_peers_tab_alternating_row_colors = value.toBool();
settings.setValue("PeersTabAlternatingRowColors", m_peers_tab_alternating_row_colors);
Q_EMIT peersTabAlternatingRowColorsChanged(m_peers_tab_alternating_row_colors);
break;
case CoinControlFeatures:
fCoinControlFeatures = value.toBool();
settings.setValue("fCoinControlFeatures", fCoinControlFeatures);
Expand Down
4 changes: 4 additions & 0 deletions src/qt/optionsmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class OptionsModel : public QAbstractListModel
ThirdPartyTxUrls, // QString
Language, // QString
UseEmbeddedMonospacedFont, // bool
PeersTabAlternatingRowColors, // bool
CoinControlFeatures, // bool
ThreadsScriptVerif, // int
Prune, // bool
Expand All @@ -86,6 +87,7 @@ class OptionsModel : public QAbstractListModel
int getDisplayUnit() const { return nDisplayUnit; }
QString getThirdPartyTxUrls() const { return strThirdPartyTxUrls; }
bool getUseEmbeddedMonospacedFont() const { return m_use_embedded_monospaced_font; }
bool getPeersTabAlternatingRowColors() const { return m_peers_tab_alternating_row_colors; }
bool getCoinControlFeatures() const { return fCoinControlFeatures; }
const QString& getOverriddenByCommandLine() { return strOverriddenByCommandLine; }

Expand All @@ -110,6 +112,7 @@ class OptionsModel : public QAbstractListModel
int nDisplayUnit;
QString strThirdPartyTxUrls;
bool m_use_embedded_monospaced_font;
bool m_peers_tab_alternating_row_colors;
bool fCoinControlFeatures;
/* settings that were overridden by command-line */
QString strOverriddenByCommandLine;
Expand All @@ -124,6 +127,7 @@ class OptionsModel : public QAbstractListModel
void coinControlFeaturesChanged(bool);
void showTrayIconChanged(bool);
void useEmbeddedMonospacedFontChanged(bool);
void peersTabAlternatingRowColorsChanged(bool);
};

#endif // BITCOIN_QT_OPTIONSMODEL_H
9 changes: 9 additions & 0 deletions src/qt/rpcconsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <netbase.h>
#include <qt/bantablemodel.h>
#include <qt/clientmodel.h>
#include <qt/optionsmodel.h>
#include <qt/peertablesortproxy.h>
#include <qt/platformstyle.h>
#include <qt/walletmodel.h>
Expand Down Expand Up @@ -460,6 +461,7 @@ RPCConsole::RPCConsole(interfaces::Node& node, const PlatformStyle *_platformSty
}

ui->splitter->restoreState(settings.value("PeersTabSplitterSizes").toByteArray());
m_alternating_row_colors = settings.value("PeersTabAlternatingRowColors").toBool();

constexpr QChar nonbreaking_hyphen(8209);
const std::vector<QString> CONNECTION_TYPE_DOC{
Expand Down Expand Up @@ -606,6 +608,11 @@ void RPCConsole::setClientModel(ClientModel *model, int bestblock_height, int64_

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

connect(model->getOptionsModel(), &OptionsModel::peersTabAlternatingRowColorsChanged, [this](bool alternating_row_colors) {
ui->peerWidget->setAlternatingRowColors(alternating_row_colors);
ui->banlistWidget->setAlternatingRowColors(alternating_row_colors);
});

// set up peer table
ui->peerWidget->setModel(model->peerTableSortProxy());
ui->peerWidget->verticalHeader()->hide();
Expand All @@ -616,6 +623,7 @@ void RPCConsole::setClientModel(ClientModel *model, int bestblock_height, int64_
ui->peerWidget->setColumnWidth(PeerTableModel::Subversion, SUBVERSION_COLUMN_WIDTH);
ui->peerWidget->setColumnWidth(PeerTableModel::Ping, PING_COLUMN_WIDTH);
ui->peerWidget->horizontalHeader()->setStretchLastSection(true);
ui->peerWidget->setAlternatingRowColors(m_alternating_row_colors);

// create peer table context menu
peersTableContextMenu = new QMenu(this);
Expand All @@ -639,6 +647,7 @@ void RPCConsole::setClientModel(ClientModel *model, int bestblock_height, int64_
ui->banlistWidget->setColumnWidth(BanTableModel::Address, BANSUBNET_COLUMN_WIDTH);
ui->banlistWidget->setColumnWidth(BanTableModel::Bantime, BANTIME_COLUMN_WIDTH);
ui->banlistWidget->horizontalHeader()->setStretchLastSection(true);
ui->banlistWidget->setAlternatingRowColors(m_alternating_row_colors);

// create ban table context menu
banTableContextMenu = new QMenu(this);
Expand Down
1 change: 1 addition & 0 deletions src/qt/rpcconsole.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ public Q_SLOTS:
QCompleter *autoCompleter = nullptr;
QThread thread;
WalletModel* m_last_wallet_model{nullptr};
bool m_alternating_row_colors{false};

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

0 comments on commit 180539a

Please sign in to comment.