StudioWelcome: Fix more warnings

Change-Id: I1c1fa8fdfd33b50d47afe4eab82347cf3c0eff08
Reviewed-by: Qt CI Patch Build Bot <ci_patchbuild_bot@qt.io>
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
Marco Bubke
2023-07-05 09:26:50 +02:00
parent 98c32d2043
commit 194b7d49b0
2 changed files with 14 additions and 11 deletions

View File

@@ -20,7 +20,7 @@ QString StyleModel::iconId(int index) const
if (!m_backendModel || index < 0) if (!m_backendModel || index < 0)
return "style-error"; return "style-error";
auto item = this->m_filteredItems.at(index); auto item = this->m_filteredItems.at(static_cast<std::size_t>(index));
QString styleName = item->text(); QString styleName = item->text();
QString id{"style-"}; QString id{"style-"};
id += styleName.toLower().replace(' ', '_') + ".png"; 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) if (actualIndex < 0)
return actualIndex; 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<std::size_t>(actualIndex)];
// TODO: perhaps should add this kind of find to utils/algorithm.h // 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); auto it = std::find(std::cbegin(m_filteredItems), std::cend(m_filteredItems), item);
if (it == std::cend(m_filteredItems)) if (it == std::cend(m_filteredItems))
return -1; return -1;
return std::distance(std::cbegin(m_filteredItems), it); return static_cast<int>(std::distance(std::cbegin(m_filteredItems), it));
} }
int StyleModel::actualIndex(int filteredIndex) int StyleModel::actualIndex(int filteredIndex)
@@ -79,18 +80,20 @@ int StyleModel::actualIndex(int filteredIndex)
if (filteredIndex < 0) if (filteredIndex < 0)
return filteredIndex; return filteredIndex;
QTC_ASSERT(filteredIndex < static_cast<int>(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<std::size_t>(filteredIndex)];
auto it = std::find(std::cbegin(m_items), std::cend(m_items), item); auto it = std::find(std::cbegin(m_items), std::cend(m_items), item);
if (it == std::cend(m_items)) if (it == std::cend(m_items))
return -1; return -1;
auto result = std::distance(std::cbegin(m_items), it); auto result = std::distance(std::cbegin(m_items), it);
QTC_ASSERT(result >= 0, return -1);
QTC_ASSERT(result <= static_cast<int>(m_items.size()), return -1);
return result; if (result >= 0 || result <= Utils::ssize(m_items))
return -1;
return static_cast<int>(result);
} }
void StyleModel::setBackendModel(QStandardItemModel *model) void StyleModel::setBackendModel(QStandardItemModel *model)

View File

@@ -60,7 +60,7 @@ public:
endResetModel(); endResetModel();
} }
int filteredIndex(int actualIndex); int filteredIndex(int actualIndex) const;
int actualIndex(int filteredIndex); int actualIndex(int filteredIndex);
void setBackendModel(QStandardItemModel *model); void setBackendModel(QStandardItemModel *model);