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

pull/21382/head
Hennadii Stepanov 4 years ago
parent a35223f1cd
commit 52f122c11f
No known key found for this signature in database
GPG Key ID: 410108112E7EA81F

@ -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,9 +175,13 @@ 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()) {
switch (column) {
case NetNodeId:
case Address:
return {};
case ConnectionType:
case Network:
return QVariant(Qt::AlignCenter);
@ -187,9 +189,10 @@ QVariant PeerTableModel::data(const QModelIndex &index, int role) const
case Sent:
case Received:
return QVariant(Qt::AlignRight | Qt::AlignVCenter);
default:
return QVariant();
}
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);

Loading…
Cancel
Save