diff options
author | MarcoFalke <falke.marco@gmail.com> | 2021-03-07 13:04:25 +0100 |
---|---|---|
committer | MarcoFalke <falke.marco@gmail.com> | 2021-03-07 13:04:30 +0100 |
commit | 8c21562180d25389b450dc90e761ba3fc266a9da (patch) | |
tree | 344a7db8e6a2a94f104956a4f80eb8d5046a8b79 /src/qt/peertablemodel.cpp | |
parent | 1020b04c390abab2a47177a28dfdc5a9bfc97654 (diff) | |
parent | 1d5d832d5c045cbbe3a0f4aa8fc29e52ecadc182 (diff) |
Merge bitcoin-core/gui#166: refactor: Use enum type as switch argument in *TableModel
1d5d832d5c045cbbe3a0f4aa8fc29e52ecadc182 qt, refactor: Use enum type as switch argument in TransactionTableModel (Hennadii Stepanov)
52f122c11f5ac40bc2f7e31cb4da0a79c842f08e qt, refactor: Use enum type as switch argument in PeerTableModel (Hennadii Stepanov)
a35223f1cdaf6918501faccac1ff94ebfd38c6f6 qt, refactor: Use enum type as switch argument in BanTableModel (Hennadii Stepanov)
ab8a747d1ced9f20ca32f9898418be70670da71a qt, refactor: Use enum type as switch argument in AddressTableModel (Hennadii Stepanov)
Pull request description:
This PR makes code more maintainable by leveraging `-Wswitch` compiler warnings.
Only the `RecentRequestsTableModel` is not refactored, because its `enum ColumnIndex` contains additional `NUMBER_OF_COLUMNS` value.
No behavior change.
ACKs for top commit:
hebasto:
Do you mind mentioning the _top_ pr commit with your ACK, i.e., 1d5d832d5c045cbbe3a0f4aa8fc29e52ecadc182, not ab8a747d1ced9f20ca32f9898418be70670da71a?
jarolrod:
ACK 1d5d832d5c045cbbe3a0f4aa8fc29e52ecadc182, tested on macOS 11.1 Qt 5.15.2
leonardojobim:
ACK https://github.com/bitcoin-core/gui/pull/166/commits/1d5d832d5c045cbbe3a0f4aa8fc29e52ecadc182, tested on Ubuntu 20.04 Qt 5.12.8
promag:
Code review ACK 1d5d832d5c045cbbe3a0f4aa8fc29e52ecadc182.
Tree-SHA512: 0d474d226a2fa0069495d1aa5ec13b2470708ec7b8a6ab35402236c7bf57cb9939577677a30dfa54f5e3bc0477c6cfffd20ed6f19e4eb394a938569cc9347851
Diffstat (limited to 'src/qt/peertablemodel.cpp')
-rw-r--r-- | src/qt/peertablemodel.cpp | 41 |
1 files changed, 22 insertions, 19 deletions
diff --git a/src/qt/peertablemodel.cpp b/src/qt/peertablemodel.cpp index 448024d657..3459bf4cf8 100644 --- a/src/qt/peertablemodel.cpp +++ b/src/qt/peertablemodel.cpp @@ -23,8 +23,7 @@ bool NodeLessThan::operator()(const CNodeCombinedStats &left, const CNodeCombine if (order == Qt::DescendingOrder) std::swap(pLeft, pRight); - switch(column) - { + switch (static_cast<PeerTableModel::ColumnIndex>(column)) { case PeerTableModel::NetNodeId: return pLeft->nodeid < pRight->nodeid; case PeerTableModel::Address: @@ -41,9 +40,8 @@ bool NodeLessThan::operator()(const CNodeCombinedStats &left, const CNodeCombine return pLeft->nRecvBytes < pRight->nRecvBytes; case PeerTableModel::Subversion: return pLeft->cleanSubVer.compare(pRight->cleanSubVer) < 0; - } - - return false; + } // no default case, so the compiler can warn about missing cases + assert(false); } // private implementation @@ -157,9 +155,9 @@ QVariant PeerTableModel::data(const QModelIndex &index, int role) const CNodeCombinedStats *rec = static_cast<CNodeCombinedStats*>(index.internalPointer()); + const auto column = static_cast<ColumnIndex>(index.column()); if (role == Qt::DisplayRole) { - switch(index.column()) - { + switch (column) { case NetNodeId: return (qint64)rec->nodeStats.nodeid; case Address: @@ -177,19 +175,24 @@ QVariant PeerTableModel::data(const QModelIndex &index, int role) const return GUIUtil::formatBytes(rec->nodeStats.nRecvBytes); case Subversion: return QString::fromStdString(rec->nodeStats.cleanSubVer); - } + } // no default case, so the compiler can warn about missing cases + assert(false); } else if (role == Qt::TextAlignmentRole) { - switch (index.column()) { - case ConnectionType: - case Network: - return QVariant(Qt::AlignCenter); - case Ping: - case Sent: - case Received: - return QVariant(Qt::AlignRight | Qt::AlignVCenter); - default: - return QVariant(); - } + switch (column) { + case NetNodeId: + case Address: + return {}; + case ConnectionType: + case Network: + return QVariant(Qt::AlignCenter); + case Ping: + case Sent: + case Received: + return QVariant(Qt::AlignRight | Qt::AlignVCenter); + case Subversion: + return {}; + } // no default case, so the compiler can warn about missing cases + assert(false); } else if (role == StatsRole) { switch (index.column()) { case NetNodeId: return QVariant::fromValue(rec); |