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

This commit is contained in:
Hennadii Stepanov 2020-12-25 22:36:01 +02:00
parent 52f122c11f
commit 1d5d832d5c
No known key found for this signature in database
GPG key ID: 410108112E7EA81F

View file

@ -526,27 +526,30 @@ QVariant TransactionTableModel::data(const QModelIndex &index, int role) const
return QVariant(); return QVariant();
TransactionRecord *rec = static_cast<TransactionRecord*>(index.internalPointer()); TransactionRecord *rec = static_cast<TransactionRecord*>(index.internalPointer());
switch(role) const auto column = static_cast<ColumnIndex>(index.column());
{ switch (role) {
case RawDecorationRole: case RawDecorationRole:
switch(index.column()) switch (column) {
{
case Status: case Status:
return txStatusDecoration(rec); return txStatusDecoration(rec);
case Watchonly: case Watchonly:
return txWatchonlyDecoration(rec); return txWatchonlyDecoration(rec);
case Date: return {};
case Type: return {};
case ToAddress: case ToAddress:
return txAddressDecoration(rec); return txAddressDecoration(rec);
} case Amount: return {};
break; } // no default case, so the compiler can warn about missing cases
assert(false);
case Qt::DecorationRole: case Qt::DecorationRole:
{ {
QIcon icon = qvariant_cast<QIcon>(index.data(RawDecorationRole)); QIcon icon = qvariant_cast<QIcon>(index.data(RawDecorationRole));
return platformStyle->TextColorIcon(icon); return platformStyle->TextColorIcon(icon);
} }
case Qt::DisplayRole: case Qt::DisplayRole:
switch(index.column()) switch (column) {
{ case Status: return {};
case Watchonly: return {};
case Date: case Date:
return formatTxDate(rec); return formatTxDate(rec);
case Type: case Type:
@ -555,12 +558,11 @@ QVariant TransactionTableModel::data(const QModelIndex &index, int role) const
return formatTxToAddress(rec, false); return formatTxToAddress(rec, false);
case Amount: case Amount:
return formatTxAmount(rec, true, BitcoinUnits::SeparatorStyle::ALWAYS); return formatTxAmount(rec, true, BitcoinUnits::SeparatorStyle::ALWAYS);
} } // no default case, so the compiler can warn about missing cases
break; assert(false);
case Qt::EditRole: case Qt::EditRole:
// Edit role is used for sorting, so return the unformatted values // Edit role is used for sorting, so return the unformatted values
switch(index.column()) switch (column) {
{
case Status: case Status:
return QString::fromStdString(rec->status.sortKey); return QString::fromStdString(rec->status.sortKey);
case Date: case Date:
@ -573,8 +575,8 @@ QVariant TransactionTableModel::data(const QModelIndex &index, int role) const
return formatTxToAddress(rec, true); return formatTxToAddress(rec, true);
case Amount: case Amount:
return qint64(rec->credit + rec->debit); return qint64(rec->credit + rec->debit);
} } // no default case, so the compiler can warn about missing cases
break; assert(false);
case Qt::ToolTipRole: case Qt::ToolTipRole:
return formatTooltip(rec); return formatTooltip(rec);
case Qt::TextAlignmentRole: case Qt::TextAlignmentRole: