From cb7cfdd95f3589bfbf77c2e1361797201c0af3b4 Mon Sep 17 00:00:00 2001 From: Timon Reinold Date: Wed, 9 Jul 2025 16:57:48 +0200 Subject: [PATCH] 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). --- src/fdosecrets/widgets/SettingsModels.cpp | 4 +--- src/fdosecrets/widgets/SettingsWidgetFdoSecrets.cpp | 5 +++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/fdosecrets/widgets/SettingsModels.cpp b/src/fdosecrets/widgets/SettingsModels.cpp index 98f218477..e7b12b477 100644 --- a/src/fdosecrets/widgets/SettingsModels.cpp +++ b/src/fdosecrets/widgets/SettingsModels.cpp @@ -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) { diff --git a/src/fdosecrets/widgets/SettingsWidgetFdoSecrets.cpp b/src/fdosecrets/widgets/SettingsWidgetFdoSecrets.cpp index fbd09cfb0..7e6a8ad33 100644 --- a/src/fdosecrets/widgets/SettingsWidgetFdoSecrets.cpp +++ b/src/fdosecrets/widgets/SettingsWidgetFdoSecrets.cpp @@ -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;