Skip to content

Commit ab8a747

Browse files
committed
qt, refactor: Use enum type as switch argument in AddressTableModel
1 parent 08eec69 commit ab8a747

File tree

1 file changed

+20
-24
lines changed

1 file changed

+20
-24
lines changed

src/qt/addresstablemodel.cpp

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -198,42 +198,38 @@ QVariant AddressTableModel::data(const QModelIndex &index, int role) const
198198

199199
AddressTableEntry *rec = static_cast<AddressTableEntry*>(index.internalPointer());
200200

201-
if(role == Qt::DisplayRole || role == Qt::EditRole)
202-
{
203-
switch(index.column())
204-
{
201+
const auto column = static_cast<ColumnIndex>(index.column());
202+
if (role == Qt::DisplayRole || role == Qt::EditRole) {
203+
switch (column) {
205204
case Label:
206-
if(rec->label.isEmpty() && role == Qt::DisplayRole)
207-
{
205+
if (rec->label.isEmpty() && role == Qt::DisplayRole) {
208206
return tr("(no label)");
209-
}
210-
else
211-
{
207+
} else {
212208
return rec->label;
213209
}
214210
case Address:
215211
return rec->address;
216-
}
217-
}
218-
else if (role == Qt::FontRole)
219-
{
220-
QFont font;
221-
if(index.column() == Address)
222-
{
223-
font = GUIUtil::fixedPitchFont();
224-
}
225-
return font;
226-
}
227-
else if (role == TypeRole)
228-
{
212+
} // no default case, so the compiler can warn about missing cases
213+
assert(false);
214+
} else if (role == Qt::FontRole) {
215+
switch (column) {
216+
case Label:
217+
return QFont();
218+
case Address:
219+
return GUIUtil::fixedPitchFont();
220+
} // no default case, so the compiler can warn about missing cases
221+
assert(false);
222+
} else if (role == TypeRole) {
229223
switch(rec->type)
230224
{
231225
case AddressTableEntry::Sending:
232226
return Send;
233227
case AddressTableEntry::Receiving:
234228
return Receive;
235-
default: break;
236-
}
229+
case AddressTableEntry::Hidden:
230+
return {};
231+
} // no default case, so the compiler can warn about missing cases
232+
assert(false);
237233
}
238234
return QVariant();
239235
}

0 commit comments

Comments
 (0)