Avoid several warnings when building against Qt 6

This commit is contained in:
Martchus 2021-11-04 00:06:15 +01:00
parent 2fb056e0b5
commit a2482ef37c
8 changed files with 29 additions and 20 deletions

View File

@ -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})

View File

@ -3,6 +3,8 @@
#include "../global.h"
#include <c++utilities/misc/traits.h>
#include <QtGlobal>
#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 <typename PosType1, typename PosType2,
CppUtilities::Traits::EnableIf<std::is_integral<PosType1>, std::is_signed<PosType1>, std::is_integral<PosType2>, std::is_signed<PosType2>>
* = 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);

View File

@ -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<qint32>(image.bytesPerLine()))
, hasAlpha(image.hasAlphaChannel())
, channels(image.isGrayscale() ? 1
: hasAlpha ? 4

View File

@ -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();

View File

@ -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<int>(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<int>(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<int>(m_items.size())), { Qt::CheckStateRole });
}
} // namespace QtUtilities

View File

@ -282,7 +282,7 @@ PaletteModel::PaletteModel(QObject *parent)
int PaletteModel::rowCount(const QModelIndex &) const
{
return m_roleNames.count();
return static_cast<int>(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<int>(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<int>(m_roleNames.count()) - 1, 3);
emit dataChanged(idxBegin, idxEnd);
}

View File

@ -6,6 +6,8 @@
#include <QStyle>
#endif
#include <utility>
namespace QtUtilities {
/*!
@ -30,7 +32,7 @@ OptionCategoryModel::OptionCategoryModel(const QList<OptionCategory *> &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<OptionCategory *> &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<OptionCategory *> &categorie
int OptionCategoryModel::rowCount(const QModelIndex &parent) const
{
return parent.isValid() ? 0 : m_categories.size();
return parent.isValid() ? 0 : static_cast<int>(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<int>(m_categories.size()); i < end; ++i) {
if (senderCategory == m_categories.at(i)) {
QModelIndex index = this->index(i);
emit dataChanged(index, index, QVector<int>({ 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<int>(m_categories.size()); i < end; ++i) {
if (senderCategory == m_categories.at(i)) {
QModelIndex index = this->index(i);
emit dataChanged(index, index, QVector<int>({ Qt::DecorationRole }));

View File

@ -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());
}