0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-02-02 09:46:52 -05:00

qt, refactor: Use enum type as switch argument in PeerTableModel

This commit is contained in:
Hennadii Stepanov 2020-12-25 22:29:15 +02:00
parent a35223f1cd
commit 52f122c11f
No known key found for this signature in database
GPG key ID: 410108112E7EA81F

View file

@ -23,8 +23,7 @@ bool NodeLessThan::operator()(const CNodeCombinedStats &left, const CNodeCombine
if (order == Qt::DescendingOrder) if (order == Qt::DescendingOrder)
std::swap(pLeft, pRight); std::swap(pLeft, pRight);
switch(column) switch (static_cast<PeerTableModel::ColumnIndex>(column)) {
{
case PeerTableModel::NetNodeId: case PeerTableModel::NetNodeId:
return pLeft->nodeid < pRight->nodeid; return pLeft->nodeid < pRight->nodeid;
case PeerTableModel::Address: case PeerTableModel::Address:
@ -41,9 +40,8 @@ bool NodeLessThan::operator()(const CNodeCombinedStats &left, const CNodeCombine
return pLeft->nRecvBytes < pRight->nRecvBytes; return pLeft->nRecvBytes < pRight->nRecvBytes;
case PeerTableModel::Subversion: case PeerTableModel::Subversion:
return pLeft->cleanSubVer.compare(pRight->cleanSubVer) < 0; return pLeft->cleanSubVer.compare(pRight->cleanSubVer) < 0;
} } // no default case, so the compiler can warn about missing cases
assert(false);
return false;
} }
// private implementation // private implementation
@ -157,9 +155,9 @@ QVariant PeerTableModel::data(const QModelIndex &index, int role) const
CNodeCombinedStats *rec = static_cast<CNodeCombinedStats*>(index.internalPointer()); CNodeCombinedStats *rec = static_cast<CNodeCombinedStats*>(index.internalPointer());
const auto column = static_cast<ColumnIndex>(index.column());
if (role == Qt::DisplayRole) { if (role == Qt::DisplayRole) {
switch(index.column()) switch (column) {
{
case NetNodeId: case NetNodeId:
return (qint64)rec->nodeStats.nodeid; return (qint64)rec->nodeStats.nodeid;
case Address: case Address:
@ -177,19 +175,24 @@ QVariant PeerTableModel::data(const QModelIndex &index, int role) const
return GUIUtil::formatBytes(rec->nodeStats.nRecvBytes); return GUIUtil::formatBytes(rec->nodeStats.nRecvBytes);
case Subversion: case Subversion:
return QString::fromStdString(rec->nodeStats.cleanSubVer); return QString::fromStdString(rec->nodeStats.cleanSubVer);
} } // no default case, so the compiler can warn about missing cases
assert(false);
} else if (role == Qt::TextAlignmentRole) { } else if (role == Qt::TextAlignmentRole) {
switch (index.column()) { switch (column) {
case ConnectionType: case NetNodeId:
case Network: case Address:
return QVariant(Qt::AlignCenter); return {};
case Ping: case ConnectionType:
case Sent: case Network:
case Received: return QVariant(Qt::AlignCenter);
return QVariant(Qt::AlignRight | Qt::AlignVCenter); case Ping:
default: case Sent:
return QVariant(); 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) { } else if (role == StatsRole) {
switch (index.column()) { switch (index.column()) {
case NetNodeId: return QVariant::fromValue(rec); case NetNodeId: return QVariant::fromValue(rec);