Skip to content

Commit

Permalink
qt, refactor: Use enum type as switch argument in BanTableModel
Browse files Browse the repository at this point in the history
  • Loading branch information
hebasto committed Jan 11, 2021
1 parent 5bc77b0 commit cc51cab
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/qt/bantablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,13 @@ bool BannedNodeLessThan::operator()(const CCombinedBan& left, const CCombinedBan
if (order == Qt::DescendingOrder)
std::swap(pLeft, pRight);

switch(column)
{
switch (static_cast<BanTableModel::ColumnIndex>(column)) {
case BanTableModel::Address:
return pLeft->subnet.ToString().compare(pRight->subnet.ToString()) < 0;
case BanTableModel::Bantime:
return pLeft->banEntry.nBanUntil < pRight->banEntry.nBanUntil;
}

return false;
} // no default case, so the compiler can warn about missing cases
assert(false);
}

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

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

const auto column = static_cast<ColumnIndex>(index.column());
if (role == Qt::DisplayRole) {
switch(index.column())
{
switch (column) {
case Address:
return QString::fromStdString(rec->subnet.ToString());
case Bantime:
QDateTime date = QDateTime::fromMSecsSinceEpoch(0);
date = date.addSecs(rec->banEntry.nBanUntil);
return QLocale::system().toString(date, QLocale::LongFormat);
}
} // no default case, so the compiler can warn about missing cases
assert(false);
}

return QVariant();
Expand Down

0 comments on commit cc51cab

Please sign in to comment.