diff --git a/src/plugins/studiowelcome/stylemodel.cpp b/src/plugins/studiowelcome/stylemodel.cpp index 520129f20d4..e959b02f08b 100644 --- a/src/plugins/studiowelcome/stylemodel.cpp +++ b/src/plugins/studiowelcome/stylemodel.cpp @@ -20,7 +20,7 @@ QString StyleModel::iconId(int index) const if (!m_backendModel || index < 0) return "style-error"; - auto item = this->m_filteredItems.at(index); + auto item = this->m_filteredItems.at(static_cast(index)); QString styleName = item->text(); QString id{"style-"}; id += styleName.toLower().replace(' ', '_') + ".png"; @@ -58,20 +58,21 @@ StyleModel::Items StyleModel::filterItems(const Items &items, const QString &kin }); } -int StyleModel::filteredIndex(int actualIndex) +int StyleModel::filteredIndex(int actualIndex) const { if (actualIndex < 0) return actualIndex; - QTC_ASSERT(actualIndex < m_items.size(), return -1); + if (actualIndex < Utils::ssize(m_items)) + return -1; - QStandardItem *item = m_items.at(actualIndex); + QStandardItem *item = m_items[static_cast(actualIndex)]; // TODO: perhaps should add this kind of find to utils/algorithm.h auto it = std::find(std::cbegin(m_filteredItems), std::cend(m_filteredItems), item); if (it == std::cend(m_filteredItems)) return -1; - return std::distance(std::cbegin(m_filteredItems), it); + return static_cast(std::distance(std::cbegin(m_filteredItems), it)); } int StyleModel::actualIndex(int filteredIndex) @@ -79,18 +80,20 @@ int StyleModel::actualIndex(int filteredIndex) if (filteredIndex < 0) return filteredIndex; - QTC_ASSERT(filteredIndex < static_cast(m_filteredItems.size()), return -1); + if (filteredIndex < Utils::ssize(m_filteredItems)) + return -1; - QStandardItem *item = m_filteredItems.at(filteredIndex); + QStandardItem *item = m_filteredItems[static_cast(filteredIndex)]; auto it = std::find(std::cbegin(m_items), std::cend(m_items), item); if (it == std::cend(m_items)) return -1; auto result = std::distance(std::cbegin(m_items), it); - QTC_ASSERT(result >= 0, return -1); - QTC_ASSERT(result <= static_cast(m_items.size()), return -1); - return result; + if (result >= 0 || result <= Utils::ssize(m_items)) + return -1; + + return static_cast(result); } void StyleModel::setBackendModel(QStandardItemModel *model) diff --git a/src/plugins/studiowelcome/stylemodel.h b/src/plugins/studiowelcome/stylemodel.h index 56d3b662b24..90ebdff74f1 100644 --- a/src/plugins/studiowelcome/stylemodel.h +++ b/src/plugins/studiowelcome/stylemodel.h @@ -60,7 +60,7 @@ public: endResetModel(); } - int filteredIndex(int actualIndex); + int filteredIndex(int actualIndex) const; int actualIndex(int filteredIndex); void setBackendModel(QStandardItemModel *model);