From a2482ef37cc90370865e583c4f3cbcc11752d6f9 Mon Sep 17 00:00:00 2001 From: Martchus Date: Thu, 4 Nov 2021 00:06:15 +0100 Subject: [PATCH] Avoid several warnings when building against Qt 6 --- CMakeLists.txt | 2 +- misc/compat.h | 7 ++++++- misc/dbusnotification.cpp | 2 +- misc/recentmenumanager.cpp | 2 +- models/checklistmodel.cpp | 6 +++--- paletteeditor/paletteeditor.cpp | 6 +++--- settingsdialog/optioncategorymodel.cpp | 12 +++++++----- settingsdialog/qtsettings.cpp | 12 +++++++----- 8 files changed, 29 insertions(+), 20 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e5d8dad..727a58b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,7 +10,7 @@ set(META_APP_DESCRIPTION "Common Qt related C++ classes and routines used by my applications such as dialogs, widgets and models") set(META_VERSION_MAJOR 6) set(META_VERSION_MINOR 5) -set(META_VERSION_PATCH 2) +set(META_VERSION_PATCH 3) set(META_APP_VERSION ${META_VERSION_MAJOR}.${META_VERSION_MINOR}.${META_VERSION_PATCH}) project(${META_PROJECT_NAME}) diff --git a/misc/compat.h b/misc/compat.h index d9c3262..77b791c 100644 --- a/misc/compat.h +++ b/misc/compat.h @@ -3,6 +3,8 @@ #include "../global.h" +#include + #include #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) @@ -50,7 +52,10 @@ inline StringView makeStringView(const QString &str) /*! * \brief Makes either a QStringView or a QStringRef depending on the Qt version, applying "mid()" parameters. */ -inline StringView midRef(const QString &str, int pos, int n = -1) +template , std::is_signed, std::is_integral, std::is_signed> + * = nullptr> +inline StringView midRef(const QString &str, PosType1 pos, PosType2 n = -1) { #ifdef QT_UTILITIES_USE_Q_STRING_VIEW return QStringView(str).mid(pos, n); diff --git a/misc/dbusnotification.cpp b/misc/dbusnotification.cpp index f7c1867..298adba 100644 --- a/misc/dbusnotification.cpp +++ b/misc/dbusnotification.cpp @@ -113,7 +113,7 @@ inline NotificationImage::NotificationImage(SwappedImage image) inline NotificationImage::NotificationImage(const QImage &image) : width(image.width()) , height(image.height()) - , rowstride(image.bytesPerLine()) + , rowstride(static_cast(image.bytesPerLine())) , hasAlpha(image.hasAlphaChannel()) , channels(image.isGrayscale() ? 1 : hasAlpha ? 4 diff --git a/misc/recentmenumanager.cpp b/misc/recentmenumanager.cpp index 93480d8..0e73eb8 100644 --- a/misc/recentmenumanager.cpp +++ b/misc/recentmenumanager.cpp @@ -94,7 +94,7 @@ void RecentMenuManager::addEntry(const QString &path) } if (!entry) { // remove old entries to have never more than 10 entries - for (int i = existingEntries.size() - 1; i > 8; --i) { + for (auto i = existingEntries.size() - 1; i > 8; --i) { delete existingEntries[i]; } existingEntries = m_menu->actions(); diff --git a/models/checklistmodel.cpp b/models/checklistmodel.cpp index 15ccaf3..5cf237a 100644 --- a/models/checklistmodel.cpp +++ b/models/checklistmodel.cpp @@ -32,7 +32,7 @@ ChecklistModel::ChecklistModel(QObject *parent) int ChecklistModel::rowCount(const QModelIndex &parent) const { if (!parent.isValid()) { - return m_items.size(); + return static_cast(m_items.size()); } return 0; } @@ -261,7 +261,7 @@ void ChecklistModel::restore(QSettings &settings, const QString &name) */ void ChecklistModel::save(QSettings &settings, const QString &name) const { - settings.beginWriteArray(name, m_items.size()); + settings.beginWriteArray(name, static_cast(m_items.size())); int index = 0; for (const ChecklistItem &item : m_items) { settings.setArrayIndex(index); @@ -295,7 +295,7 @@ void ChecklistModel::applyVariantList(const QVariantList &checkedIds) for (auto &item : m_items) { item.m_checkState = checkedIds.contains(item.id()) ? Qt::Checked : Qt::Unchecked; } - emit dataChanged(index(0), index(m_items.size()), { Qt::CheckStateRole }); + emit dataChanged(index(0), index(static_cast(m_items.size())), { Qt::CheckStateRole }); } } // namespace QtUtilities diff --git a/paletteeditor/paletteeditor.cpp b/paletteeditor/paletteeditor.cpp index ad3d00c..d4d2fda 100644 --- a/paletteeditor/paletteeditor.cpp +++ b/paletteeditor/paletteeditor.cpp @@ -282,7 +282,7 @@ PaletteModel::PaletteModel(QObject *parent) int PaletteModel::rowCount(const QModelIndex &) const { - return m_roleNames.count(); + return static_cast(m_roleNames.count()); } int PaletteModel::columnCount(const QModelIndex &) const @@ -348,7 +348,7 @@ bool PaletteModel::setData(const QModelIndex &index, const QVariant &value, int m_palette.setBrush(QPalette::Disabled, QPalette::Text, br); m_palette.setBrush(QPalette::Disabled, QPalette::ButtonText, br); idxBegin = PaletteModel::index(0, 0); - idxEnd = PaletteModel::index(m_roleNames.count() - 1, 3); + idxEnd = PaletteModel::index(static_cast(m_roleNames.count()) - 1, 3); break; case QPalette::Window: m_palette.setBrush(QPalette::Disabled, QPalette::Base, br); @@ -435,7 +435,7 @@ void PaletteModel::setPalette(const QPalette &palette, const QPalette &parentPal m_parentPalette = parentPalette; m_palette = palette; const QModelIndex idxBegin = index(0, 0); - const QModelIndex idxEnd = index(m_roleNames.count() - 1, 3); + const QModelIndex idxEnd = index(static_cast(m_roleNames.count()) - 1, 3); emit dataChanged(idxBegin, idxEnd); } diff --git a/settingsdialog/optioncategorymodel.cpp b/settingsdialog/optioncategorymodel.cpp index 34a5ecb..0b31e10 100644 --- a/settingsdialog/optioncategorymodel.cpp +++ b/settingsdialog/optioncategorymodel.cpp @@ -6,6 +6,8 @@ #include #endif +#include + namespace QtUtilities { /*! @@ -30,7 +32,7 @@ OptionCategoryModel::OptionCategoryModel(const QList &categori : QAbstractListModel(parent) , m_categories(categories) { - for (OptionCategory *category : m_categories) { + for (OptionCategory *category : std::as_const(m_categories)) { category->setParent(this); } } @@ -52,7 +54,7 @@ void OptionCategoryModel::setCategories(const QList &categorie beginResetModel(); qDeleteAll(m_categories); m_categories = categories; - for (OptionCategory *const category : m_categories) { + for (OptionCategory *const category : std::as_const(m_categories)) { category->setParent(this); connect(category, &OptionCategory::displayNameChanged, this, &OptionCategoryModel::categoryChangedName); connect(category, &OptionCategory::iconChanged, this, &OptionCategoryModel::categoryChangedIcon); @@ -62,7 +64,7 @@ void OptionCategoryModel::setCategories(const QList &categorie int OptionCategoryModel::rowCount(const QModelIndex &parent) const { - return parent.isValid() ? 0 : m_categories.size(); + return parent.isValid() ? 0 : static_cast(m_categories.size()); } QVariant OptionCategoryModel::data(const QModelIndex &index, int role) const @@ -98,7 +100,7 @@ void OptionCategoryModel::categoryChangedName() if (!senderCategory) { return; } - for (int i = 0, end = m_categories.size(); i < end; ++i) { + for (int i = 0, end = static_cast(m_categories.size()); i < end; ++i) { if (senderCategory == m_categories.at(i)) { QModelIndex index = this->index(i); emit dataChanged(index, index, QVector({ Qt::DisplayRole })); @@ -115,7 +117,7 @@ void OptionCategoryModel::categoryChangedIcon() if (!senderCategory) { return; } - for (int i = 0, end = m_categories.size(); i < end; ++i) { + for (int i = 0, end = static_cast(m_categories.size()); i < end; ++i) { if (senderCategory == m_categories.at(i)) { QModelIndex index = this->index(i); emit dataChanged(index, index, QVector({ Qt::DecorationRole })); diff --git a/settingsdialog/qtsettings.cpp b/settingsdialog/qtsettings.cpp index 46438c3..2ff7eb4 100644 --- a/settingsdialog/qtsettings.cpp +++ b/settingsdialog/qtsettings.cpp @@ -293,15 +293,16 @@ QWidget *QtAppearanceOptionPage::setupWidget() // setup icon theme selection const QStringList searchPaths = QIcon::themeSearchPaths() << QStringLiteral("/usr/share/icons/"); for (const QString &searchPath : searchPaths) { - for (const QString &iconTheme : QDir(searchPath).entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name)) { + const auto dir = QDir(searchPath).entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name); + for (const QString &iconTheme : dir) { const int existingItemIndex = ui()->iconThemeComboBox->findData(iconTheme); QFile indexFile(searchPath % QChar('/') % iconTheme % QStringLiteral("/index.theme")); QByteArray index; if (indexFile.open(QFile::ReadOnly) && !(index = indexFile.readAll()).isEmpty()) { - const int iconThemeSection = index.indexOf("[Icon Theme]"); - const int nameStart = index.indexOf("Name=", iconThemeSection != -1 ? iconThemeSection : 0); + const auto iconThemeSection = index.indexOf("[Icon Theme]"); + const auto nameStart = index.indexOf("Name=", iconThemeSection != -1 ? iconThemeSection : 0); if (nameStart != -1) { - int nameLength = index.indexOf("\n", nameStart) - nameStart - 5; + auto nameLength = index.indexOf("\n", nameStart) - nameStart - 5; if (nameLength > 0) { QString displayName = index.mid(nameStart + 5, nameLength); if (displayName != iconTheme) { @@ -355,7 +356,8 @@ QWidget *QtLanguageOptionPage::setupWidget() // add all available locales to combo box auto *localeComboBox = ui()->localeComboBox; - for (const QLocale &locale : QLocale::matchingLocales(QLocale::AnyLanguage, QLocale::AnyScript, QLocale::AnyCountry)) { + const auto locales = QLocale::matchingLocales(QLocale::AnyLanguage, QLocale::AnyScript, QLocale::AnyCountry); + for (const QLocale &locale : locales) { localeComboBox->addItem(locale.name()); }