Skip to content

Commit

Permalink
qt, refactor: Use enum type as switch argument in PeerTableModel
Browse files Browse the repository at this point in the history
  • Loading branch information
hebasto committed Jan 11, 2021
1 parent cc51cab commit 3677be9
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions src/qt/peertablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -39,9 +38,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
Expand Down Expand Up @@ -155,9 +153,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:
Expand All @@ -173,18 +171,23 @@ 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 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 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);
Expand Down

0 comments on commit 3677be9

Please sign in to comment.