Skip to content

Commit a35223f

Browse files
committed
qt, refactor: Use enum type as switch argument in BanTableModel
1 parent ab8a747 commit a35223f

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

src/qt/bantablemodel.cpp

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

26-
switch(column)
27-
{
26+
switch (static_cast<BanTableModel::ColumnIndex>(column)) {
2827
case BanTableModel::Address:
2928
return pLeft->subnet.ToString().compare(pRight->subnet.ToString()) < 0;
3029
case BanTableModel::Bantime:
3130
return pLeft->banEntry.nBanUntil < pRight->banEntry.nBanUntil;
32-
}
33-
34-
return false;
31+
} // no default case, so the compiler can warn about missing cases
32+
assert(false);
3533
}
3634

3735
// private implementation
@@ -119,16 +117,17 @@ QVariant BanTableModel::data(const QModelIndex &index, int role) const
119117

120118
CCombinedBan *rec = static_cast<CCombinedBan*>(index.internalPointer());
121119

120+
const auto column = static_cast<ColumnIndex>(index.column());
122121
if (role == Qt::DisplayRole) {
123-
switch(index.column())
124-
{
122+
switch (column) {
125123
case Address:
126124
return QString::fromStdString(rec->subnet.ToString());
127125
case Bantime:
128126
QDateTime date = QDateTime::fromMSecsSinceEpoch(0);
129127
date = date.addSecs(rec->banEntry.nBanUntil);
130128
return QLocale::system().toString(date, QLocale::LongFormat);
131-
}
129+
} // no default case, so the compiler can warn about missing cases
130+
assert(false);
132131
}
133132

134133
return QVariant();

0 commit comments

Comments
 (0)