mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 12:02:48 +01:00
merge bitcoin-core/gui#166: Use enum type as switch argument in *TableModel
This commit is contained in:
parent
5a67b52725
commit
c33afea7fd
@ -195,42 +195,38 @@ QVariant AddressTableModel::data(const QModelIndex &index, int role) const
|
|||||||
|
|
||||||
AddressTableEntry *rec = static_cast<AddressTableEntry*>(index.internalPointer());
|
AddressTableEntry *rec = static_cast<AddressTableEntry*>(index.internalPointer());
|
||||||
|
|
||||||
if(role == Qt::DisplayRole || role == Qt::EditRole)
|
const auto column = static_cast<ColumnIndex>(index.column());
|
||||||
{
|
if (role == Qt::DisplayRole || role == Qt::EditRole) {
|
||||||
switch(index.column())
|
switch (column) {
|
||||||
{
|
|
||||||
case Label:
|
case Label:
|
||||||
if(rec->label.isEmpty() && role == Qt::DisplayRole)
|
if (rec->label.isEmpty() && role == Qt::DisplayRole) {
|
||||||
{
|
|
||||||
return tr("(no label)");
|
return tr("(no label)");
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
return rec->label;
|
return rec->label;
|
||||||
}
|
}
|
||||||
case Address:
|
case Address:
|
||||||
return rec->address;
|
return rec->address;
|
||||||
}
|
} // no default case, so the compiler can warn about missing cases
|
||||||
}
|
assert(false);
|
||||||
else if (role == Qt::FontRole)
|
} else if (role == Qt::FontRole) {
|
||||||
{
|
switch (column) {
|
||||||
QFont font;
|
case Label:
|
||||||
if(index.column() == Address)
|
return QFont();
|
||||||
{
|
case Address:
|
||||||
font = GUIUtil::getFontNormal();
|
return GUIUtil::getFontNormal();
|
||||||
}
|
} // no default case, so the compiler can warn about missing cases
|
||||||
return font;
|
assert(false);
|
||||||
}
|
} else if (role == TypeRole) {
|
||||||
else if (role == TypeRole)
|
|
||||||
{
|
|
||||||
switch(rec->type)
|
switch(rec->type)
|
||||||
{
|
{
|
||||||
case AddressTableEntry::Sending:
|
case AddressTableEntry::Sending:
|
||||||
return Send;
|
return Send;
|
||||||
case AddressTableEntry::Receiving:
|
case AddressTableEntry::Receiving:
|
||||||
return Receive;
|
return Receive;
|
||||||
default: break;
|
case AddressTableEntry::Hidden:
|
||||||
}
|
return {};
|
||||||
|
} // no default case, so the compiler can warn about missing cases
|
||||||
|
assert(false);
|
||||||
}
|
}
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
@ -23,15 +23,13 @@ bool BannedNodeLessThan::operator()(const CCombinedBan& left, const CCombinedBan
|
|||||||
if (order == Qt::DescendingOrder)
|
if (order == Qt::DescendingOrder)
|
||||||
std::swap(pLeft, pRight);
|
std::swap(pLeft, pRight);
|
||||||
|
|
||||||
switch(column)
|
switch (static_cast<BanTableModel::ColumnIndex>(column)) {
|
||||||
{
|
|
||||||
case BanTableModel::Address:
|
case BanTableModel::Address:
|
||||||
return pLeft->subnet.ToString().compare(pRight->subnet.ToString()) < 0;
|
return pLeft->subnet.ToString().compare(pRight->subnet.ToString()) < 0;
|
||||||
case BanTableModel::Bantime:
|
case BanTableModel::Bantime:
|
||||||
return pLeft->banEntry.nBanUntil < pRight->banEntry.nBanUntil;
|
return pLeft->banEntry.nBanUntil < pRight->banEntry.nBanUntil;
|
||||||
}
|
} // no default case, so the compiler can warn about missing cases
|
||||||
|
assert(false);
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// private implementation
|
// private implementation
|
||||||
@ -119,16 +117,17 @@ QVariant BanTableModel::data(const QModelIndex &index, int role) const
|
|||||||
|
|
||||||
CCombinedBan *rec = static_cast<CCombinedBan*>(index.internalPointer());
|
CCombinedBan *rec = static_cast<CCombinedBan*>(index.internalPointer());
|
||||||
|
|
||||||
|
const auto column = static_cast<ColumnIndex>(index.column());
|
||||||
if (role == Qt::DisplayRole) {
|
if (role == Qt::DisplayRole) {
|
||||||
switch(index.column())
|
switch (column) {
|
||||||
{
|
|
||||||
case Address:
|
case Address:
|
||||||
return QString::fromStdString(rec->subnet.ToString());
|
return QString::fromStdString(rec->subnet.ToString());
|
||||||
case Bantime:
|
case Bantime:
|
||||||
QDateTime date = QDateTime::fromMSecsSinceEpoch(0);
|
QDateTime date = QDateTime::fromMSecsSinceEpoch(0);
|
||||||
date = date.addSecs(rec->banEntry.nBanUntil);
|
date = date.addSecs(rec->banEntry.nBanUntil);
|
||||||
return QLocale::system().toString(date, QLocale::LongFormat);
|
return QLocale::system().toString(date, QLocale::LongFormat);
|
||||||
}
|
} // no default case, so the compiler can warn about missing cases
|
||||||
|
assert(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
@ -23,8 +23,7 @@ bool NodeLessThan::operator()(const CNodeCombinedStats &left, const CNodeCombine
|
|||||||
if (order == Qt::DescendingOrder)
|
if (order == Qt::DescendingOrder)
|
||||||
std::swap(pLeft, pRight);
|
std::swap(pLeft, pRight);
|
||||||
|
|
||||||
switch(column)
|
switch (static_cast<PeerTableModel::ColumnIndex>(column)) {
|
||||||
{
|
|
||||||
case PeerTableModel::NetNodeId:
|
case PeerTableModel::NetNodeId:
|
||||||
return pLeft->nodeid < pRight->nodeid;
|
return pLeft->nodeid < pRight->nodeid;
|
||||||
case PeerTableModel::Address:
|
case PeerTableModel::Address:
|
||||||
@ -41,9 +40,8 @@ bool NodeLessThan::operator()(const CNodeCombinedStats &left, const CNodeCombine
|
|||||||
return pLeft->nRecvBytes < pRight->nRecvBytes;
|
return pLeft->nRecvBytes < pRight->nRecvBytes;
|
||||||
case PeerTableModel::Subversion:
|
case PeerTableModel::Subversion:
|
||||||
return pLeft->cleanSubVer.compare(pRight->cleanSubVer) < 0;
|
return pLeft->cleanSubVer.compare(pRight->cleanSubVer) < 0;
|
||||||
}
|
} // no default case, so the compiler can warn about missing cases
|
||||||
|
assert(false);
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// private implementation
|
// private implementation
|
||||||
@ -158,9 +156,9 @@ QVariant PeerTableModel::data(const QModelIndex &index, int role) const
|
|||||||
|
|
||||||
CNodeCombinedStats *rec = static_cast<CNodeCombinedStats*>(index.internalPointer());
|
CNodeCombinedStats *rec = static_cast<CNodeCombinedStats*>(index.internalPointer());
|
||||||
|
|
||||||
|
const auto column = static_cast<ColumnIndex>(index.column());
|
||||||
if (role == Qt::DisplayRole) {
|
if (role == Qt::DisplayRole) {
|
||||||
switch(index.column())
|
switch (column) {
|
||||||
{
|
|
||||||
case NetNodeId:
|
case NetNodeId:
|
||||||
return (qint64)rec->nodeStats.nodeid;
|
return (qint64)rec->nodeStats.nodeid;
|
||||||
case Address:
|
case Address:
|
||||||
@ -178,19 +176,24 @@ QVariant PeerTableModel::data(const QModelIndex &index, int role) const
|
|||||||
return GUIUtil::formatBytes(rec->nodeStats.nRecvBytes);
|
return GUIUtil::formatBytes(rec->nodeStats.nRecvBytes);
|
||||||
case Subversion:
|
case Subversion:
|
||||||
return QString::fromStdString(rec->nodeStats.cleanSubVer);
|
return QString::fromStdString(rec->nodeStats.cleanSubVer);
|
||||||
}
|
} // no default case, so the compiler can warn about missing cases
|
||||||
|
assert(false);
|
||||||
} else if (role == Qt::TextAlignmentRole) {
|
} else if (role == Qt::TextAlignmentRole) {
|
||||||
switch (index.column()) {
|
switch (column) {
|
||||||
case ConnectionType:
|
case NetNodeId:
|
||||||
case Network:
|
case Address:
|
||||||
return QVariant(Qt::AlignCenter);
|
return {};
|
||||||
case Ping:
|
case ConnectionType:
|
||||||
case Sent:
|
case Network:
|
||||||
case Received:
|
return QVariant(Qt::AlignCenter);
|
||||||
return QVariant(Qt::AlignRight | Qt::AlignVCenter);
|
case Ping:
|
||||||
default:
|
case Sent:
|
||||||
return QVariant();
|
case Received:
|
||||||
}
|
return QVariant(Qt::AlignRight | Qt::AlignVCenter);
|
||||||
|
case Subversion:
|
||||||
|
return {};
|
||||||
|
} // no default case, so the compiler can warn about missing cases
|
||||||
|
assert(false);
|
||||||
} else if (role == StatsRole) {
|
} else if (role == StatsRole) {
|
||||||
switch (index.column()) {
|
switch (index.column()) {
|
||||||
case NetNodeId: return QVariant::fromValue(rec);
|
case NetNodeId: return QVariant::fromValue(rec);
|
||||||
|
@ -607,26 +607,29 @@ 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:
|
||||||
{
|
{
|
||||||
return qvariant_cast<QIcon>(index.data(RawDecorationRole));
|
return qvariant_cast<QIcon>(index.data(RawDecorationRole));
|
||||||
}
|
}
|
||||||
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:
|
||||||
@ -635,12 +638,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:
|
||||||
@ -653,8 +655,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:
|
||||||
|
Loading…
Reference in New Issue
Block a user