Apply PR feedback

Formulate a single case switch-statement as an if-statement.  If we ever
want to add additional cases, just turn it back into a switch-statement.

Avoid calling QComboBox::setItemData with out-of-bounds indices.  While
QComboBox::insertItem documents that it works with larger indices,
QComboBox::setItemData does not.  So instead use the actual real index
for both.
(Note that QComboBox::addItem also just calls "insertItem(count(),
...)", so QComboBox::addItem wouldn't be any more efficient, but this
way we see both calls actually using the same index.)

Suggested by CodeQL (switch -> if) and Copilot (QComboBox indices).
This commit is contained in:
Timon Reinold 2025-07-09 16:57:48 +02:00
parent 8667760099
commit cb7cfdd95f
2 changed files with 4 additions and 5 deletions

View file

@ -353,11 +353,9 @@ namespace FdoSecrets
QVariant SettingsAliasesModel::dataForDatabase(const QUuid& publicUuid, int role) const
{
switch (role) {
case Qt::EditRole: {
if (role == Qt::EditRole) {
return publicUuid; // initial value for editor for this cell
}
}
auto dbWidget = m_databases->databaseWidgetFromPublicUuid(publicUuid);
if (dbWidget) {

View file

@ -237,8 +237,9 @@ public:
auto dbWidget = m_dbTabs->databaseWidgetFromIndex(i);
auto db = dbWidget->database();
if (!FdoSecrets::settings()->exposedGroup(db).isNull()) {
e->insertItem(i, dbWidget->displayName(), db->publicUuid());
e->setItemData(i, db->filePath(), Qt::ToolTipRole);
auto idx = e->count();
e->insertItem(idx, dbWidget->displayName(), db->publicUuid());
e->setItemData(idx, db->filePath(), Qt::ToolTipRole);
}
}
return e;