Skip to content

Commit 1d5d832

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

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

src/qt/transactiontablemodel.cpp

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -526,27 +526,30 @@ QVariant TransactionTableModel::data(const QModelIndex &index, int role) const
526526
return QVariant();
527527
TransactionRecord *rec = static_cast<TransactionRecord*>(index.internalPointer());
528528

529-
switch(role)
530-
{
529+
const auto column = static_cast<ColumnIndex>(index.column());
530+
switch (role) {
531531
case RawDecorationRole:
532-
switch(index.column())
533-
{
532+
switch (column) {
534533
case Status:
535534
return txStatusDecoration(rec);
536535
case Watchonly:
537536
return txWatchonlyDecoration(rec);
537+
case Date: return {};
538+
case Type: return {};
538539
case ToAddress:
539540
return txAddressDecoration(rec);
540-
}
541-
break;
541+
case Amount: return {};
542+
} // no default case, so the compiler can warn about missing cases
543+
assert(false);
542544
case Qt::DecorationRole:
543545
{
544546
QIcon icon = qvariant_cast<QIcon>(index.data(RawDecorationRole));
545547
return platformStyle->TextColorIcon(icon);
546548
}
547549
case Qt::DisplayRole:
548-
switch(index.column())
549-
{
550+
switch (column) {
551+
case Status: return {};
552+
case Watchonly: return {};
550553
case Date:
551554
return formatTxDate(rec);
552555
case Type:
@@ -555,12 +558,11 @@ QVariant TransactionTableModel::data(const QModelIndex &index, int role) const
555558
return formatTxToAddress(rec, false);
556559
case Amount:
557560
return formatTxAmount(rec, true, BitcoinUnits::SeparatorStyle::ALWAYS);
558-
}
559-
break;
561+
} // no default case, so the compiler can warn about missing cases
562+
assert(false);
560563
case Qt::EditRole:
561564
// Edit role is used for sorting, so return the unformatted values
562-
switch(index.column())
563-
{
565+
switch (column) {
564566
case Status:
565567
return QString::fromStdString(rec->status.sortKey);
566568
case Date:
@@ -573,8 +575,8 @@ QVariant TransactionTableModel::data(const QModelIndex &index, int role) const
573575
return formatTxToAddress(rec, true);
574576
case Amount:
575577
return qint64(rec->credit + rec->debit);
576-
}
577-
break;
578+
} // no default case, so the compiler can warn about missing cases
579+
assert(false);
578580
case Qt::ToolTipRole:
579581
return formatTooltip(rec);
580582
case Qt::TextAlignmentRole:

0 commit comments

Comments
 (0)