Skip to content

Commit 52f122c

Browse files
committed
qt, refactor: Use enum type as switch argument in PeerTableModel
1 parent a35223f commit 52f122c

File tree

1 file changed

+22
-19
lines changed

1 file changed

+22
-19
lines changed

src/qt/peertablemodel.cpp

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ bool NodeLessThan::operator()(const CNodeCombinedStats &left, const CNodeCombine
2323
if (order == Qt::DescendingOrder)
2424
std::swap(pLeft, pRight);
2525

26-
switch(column)
27-
{
26+
switch (static_cast<PeerTableModel::ColumnIndex>(column)) {
2827
case PeerTableModel::NetNodeId:
2928
return pLeft->nodeid < pRight->nodeid;
3029
case PeerTableModel::Address:
@@ -41,9 +40,8 @@ bool NodeLessThan::operator()(const CNodeCombinedStats &left, const CNodeCombine
4140
return pLeft->nRecvBytes < pRight->nRecvBytes;
4241
case PeerTableModel::Subversion:
4342
return pLeft->cleanSubVer.compare(pRight->cleanSubVer) < 0;
44-
}
45-
46-
return false;
43+
} // no default case, so the compiler can warn about missing cases
44+
assert(false);
4745
}
4846

4947
// private implementation
@@ -157,9 +155,9 @@ QVariant PeerTableModel::data(const QModelIndex &index, int role) const
157155

158156
CNodeCombinedStats *rec = static_cast<CNodeCombinedStats*>(index.internalPointer());
159157

158+
const auto column = static_cast<ColumnIndex>(index.column());
160159
if (role == Qt::DisplayRole) {
161-
switch(index.column())
162-
{
160+
switch (column) {
163161
case NetNodeId:
164162
return (qint64)rec->nodeStats.nodeid;
165163
case Address:
@@ -177,19 +175,24 @@ QVariant PeerTableModel::data(const QModelIndex &index, int role) const
177175
return GUIUtil::formatBytes(rec->nodeStats.nRecvBytes);
178176
case Subversion:
179177
return QString::fromStdString(rec->nodeStats.cleanSubVer);
180-
}
178+
} // no default case, so the compiler can warn about missing cases
179+
assert(false);
181180
} else if (role == Qt::TextAlignmentRole) {
182-
switch (index.column()) {
183-
case ConnectionType:
184-
case Network:
185-
return QVariant(Qt::AlignCenter);
186-
case Ping:
187-
case Sent:
188-
case Received:
189-
return QVariant(Qt::AlignRight | Qt::AlignVCenter);
190-
default:
191-
return QVariant();
192-
}
181+
switch (column) {
182+
case NetNodeId:
183+
case Address:
184+
return {};
185+
case ConnectionType:
186+
case Network:
187+
return QVariant(Qt::AlignCenter);
188+
case Ping:
189+
case Sent:
190+
case Received:
191+
return QVariant(Qt::AlignRight | Qt::AlignVCenter);
192+
case Subversion:
193+
return {};
194+
} // no default case, so the compiler can warn about missing cases
195+
assert(false);
193196
} else if (role == StatsRole) {
194197
switch (index.column()) {
195198
case NetNodeId: return QVariant::fromValue(rec);

0 commit comments

Comments
 (0)