diff options
author | Brad King <brad.king@kitware.com> | 2023-02-20 22:23:11 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2023-02-20 22:55:49 (GMT) |
commit | 5cda8a399398020bba462bbf70609d3a37bb8c18 (patch) | |
tree | 88f28b0c01519394279300fbbed0bea298792058 /Source | |
parent | d18806e67336d96a9a22b860246de3f1c518ce40 (diff) | |
download | CMake-5cda8a399398020bba462bbf70609d3a37bb8c18.zip CMake-5cda8a399398020bba462bbf70609d3a37bb8c18.tar.gz CMake-5cda8a399398020bba462bbf70609d3a37bb8c18.tar.bz2 |
cmake-gui: Fix conversion warnings about Qt indexing types
Qt 5 uses `int` for indexing, and Qt 6 uses `qsizetype`. Add helper
types and casts to the appropriate type to avoid conversion warnings.
Diffstat (limited to 'Source')
-rw-r--r-- | Source/QtDialog/AddCacheEntry.cxx | 3 | ||||
-rw-r--r-- | Source/QtDialog/CMakeLists.txt | 1 | ||||
-rw-r--r-- | Source/QtDialog/CMakeSetupDialog.cxx | 5 | ||||
-rw-r--r-- | Source/QtDialog/FirstConfigure.cxx | 7 | ||||
-rw-r--r-- | Source/QtDialog/QCMake.cxx | 3 | ||||
-rw-r--r-- | Source/QtDialog/QCMakeCacheView.cxx | 17 | ||||
-rw-r--r-- | Source/QtDialog/QCMakePresetItemModel.cxx | 17 | ||||
-rw-r--r-- | Source/QtDialog/QCMakeSizeType.h | 12 |
8 files changed, 45 insertions, 20 deletions
diff --git a/Source/QtDialog/AddCacheEntry.cxx b/Source/QtDialog/AddCacheEntry.cxx index 1075895..7c34c60 100644 --- a/Source/QtDialog/AddCacheEntry.cxx +++ b/Source/QtDialog/AddCacheEntry.cxx @@ -2,6 +2,7 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "AddCacheEntry.h" +#include "QCMakeSizeType.h" #include <QCompleter> #include <QMetaProperty> @@ -88,7 +89,7 @@ QString AddCacheEntry::typeString() const void AddCacheEntry::onCompletionActivated(const QString& text) { - int idx = this->VarNames.indexOf(text); + cm_qsizetype idx = this->VarNames.indexOf(text); if (idx != -1) { QString vartype = this->VarTypes[idx]; for (int i = 0; i < NumTypes; i++) { diff --git a/Source/QtDialog/CMakeLists.txt b/Source/QtDialog/CMakeLists.txt index c90b7ee..e6e41ec 100644 --- a/Source/QtDialog/CMakeLists.txt +++ b/Source/QtDialog/CMakeLists.txt @@ -175,6 +175,7 @@ add_library( QCMakePresetComboBox.h QCMakePresetItemModel.cxx QCMakePresetItemModel.h + QCMakeSizeType.h QCMakeWidgets.cxx QCMakeWidgets.h RegexExplorer.cxx diff --git a/Source/QtDialog/CMakeSetupDialog.cxx b/Source/QtDialog/CMakeSetupDialog.cxx index 8641407..1effdd3 100644 --- a/Source/QtDialog/CMakeSetupDialog.cxx +++ b/Source/QtDialog/CMakeSetupDialog.cxx @@ -32,6 +32,7 @@ #include "QCMake.h" #include "QCMakeCacheView.h" +#include "QCMakeSizeType.h" #include "cmSystemTools.h" #include "cmVersion.h" @@ -1120,12 +1121,12 @@ void CMakeSetupDialog::saveBuildPaths(const QStringList& paths) QSettings settings; settings.beginGroup("Settings/StartPath"); - int num = paths.count(); + cm_qsizetype num = paths.count(); if (num > 10) { num = 10; } - for (int i = 0; i < num; i++) { + for (cm_qsizetype i = 0; i < num; i++) { settings.setValue(QString("WhereBuild%1").arg(i), paths[i]); } } diff --git a/Source/QtDialog/FirstConfigure.cxx b/Source/QtDialog/FirstConfigure.cxx index 707eaae..a454cb6 100644 --- a/Source/QtDialog/FirstConfigure.cxx +++ b/Source/QtDialog/FirstConfigure.cxx @@ -1,6 +1,7 @@ #include "FirstConfigure.h" +#include "QCMakeSizeType.h" #include <QComboBox> #include <QRadioButton> #include <QSettings> @@ -242,10 +243,12 @@ void StartCompilerSetup::onGeneratorChanged(int index) // Default to generator platform from environment if (!DefaultGeneratorPlatform.isEmpty()) { - int platform_index = platforms.indexOf(DefaultGeneratorPlatform); + cm_qsizetype platform_index = + platforms.indexOf(DefaultGeneratorPlatform); if (platform_index != -1) { // The index is off-by-one due to the first empty item added above. - this->PlatformOptions->setCurrentIndex(platform_index + 1); + this->PlatformOptions->setCurrentIndex( + static_cast<int>(platform_index + 1)); } } } else { diff --git a/Source/QtDialog/QCMake.cxx b/Source/QtDialog/QCMake.cxx index 6b3cb9f..ea02f98 100644 --- a/Source/QtDialog/QCMake.cxx +++ b/Source/QtDialog/QCMake.cxx @@ -6,6 +6,7 @@ #include <cm/memory> +#include "QCMakeSizeType.h" #include <QCoreApplication> #include <QDir> #include <QString> @@ -326,7 +327,7 @@ void QCMake::setProperties(const QCMakePropertyList& newProps) QCMakeProperty prop; prop.Key = QString::fromStdString(key); - int idx = props.indexOf(prop); + cm_qsizetype idx = props.indexOf(prop); if (idx == -1) { toremove.append(QString::fromStdString(key)); } else { diff --git a/Source/QtDialog/QCMakeCacheView.cxx b/Source/QtDialog/QCMakeCacheView.cxx index 6f19b67..e67e0c2 100644 --- a/Source/QtDialog/QCMakeCacheView.cxx +++ b/Source/QtDialog/QCMakeCacheView.cxx @@ -2,6 +2,7 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "QCMakeCacheView.h" +#include "QCMakeSizeType.h" #include "QCMakeWidgets.h" #include <QApplication> #include <QEvent> @@ -188,7 +189,7 @@ QCMakeCacheModel::~QCMakeCacheModel() = default; static uint qHash(const QCMakeProperty& p) { - return qHash(p.Key); + return static_cast<uint>(qHash(p.Key)); } void QCMakeCacheModel::setShowNewProperties(bool f) @@ -241,7 +242,7 @@ void QCMakeCacheModel::setProperties(const QCMakePropertyList& props) bool b = this->blockSignals(true); this->clear(); - this->NewPropertyCount = newProps.size(); + this->NewPropertyCount = static_cast<int>(newProps.size()); if (View == FlatView) { QCMakePropertyList newP = newProps.values(); @@ -297,8 +298,8 @@ void QCMakeCacheModel::setProperties(const QCMakePropertyList& props) parentItems[1]->setData(1, GroupRole); root->appendRow(parentItems); - int num = props2.size(); - for (int i = 0; i < num; i++) { + cm_qsizetype num = props2.size(); + for (cm_qsizetype i = 0; i < num; i++) { QCMakeProperty const& prop = props2[i]; QList<QStandardItem*> items; items.append(new QStandardItem()); @@ -319,8 +320,8 @@ void QCMakeCacheModel::setProperties(const QCMakePropertyList& props) root->appendRow(parentItem); parentItem->setData(1, GroupRole); - int num = props2.size(); - for (int i = 0; i < num; i++) { + cm_qsizetype num = props2.size(); + for (cm_qsizetype i = 0; i < num; i++) { QCMakeProperty const& prop = props2[i]; QList<QStandardItem*> items; items.append(new QStandardItem()); @@ -349,8 +350,8 @@ void QCMakeCacheModel::setViewType(QCMakeCacheModel::ViewType t) QCMakePropertyList props = this->properties(); QCMakePropertyList oldProps; int numNew = this->NewPropertyCount; - int numTotal = props.count(); - for (int i = numNew; i < numTotal; i++) { + cm_qsizetype numTotal = props.count(); + for (cm_qsizetype i = numNew; i < numTotal; i++) { oldProps.append(props[i]); } diff --git a/Source/QtDialog/QCMakePresetItemModel.cxx b/Source/QtDialog/QCMakePresetItemModel.cxx index 7ada2a5..31a6000 100644 --- a/Source/QtDialog/QCMakePresetItemModel.cxx +++ b/Source/QtDialog/QCMakePresetItemModel.cxx @@ -2,6 +2,7 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "QCMakePresetItemModel.h" +#include "QCMakeSizeType.h" #include <QFont> QCMakePresetItemModel::QCMakePresetItemModel(QObject* parent) @@ -27,7 +28,8 @@ QVariant QCMakePresetItemModel::data(const QModelIndex& index, int role) const if (index.internalId() == SEPARATOR_INDEX) { return QVariant{}; } - auto const& preset = this->m_presets[index.internalId()]; + auto const& preset = + this->m_presets[static_cast<cm_qsizetype>(index.internalId())]; return preset.displayName.isEmpty() ? preset.name : preset.displayName; } case Qt::ToolTipRole: @@ -37,7 +39,8 @@ QVariant QCMakePresetItemModel::data(const QModelIndex& index, int role) const if (index.internalId() == SEPARATOR_INDEX) { return QVariant{}; } - return this->m_presets[index.internalId()].description; + return this->m_presets[static_cast<cm_qsizetype>(index.internalId())] + .description; case Qt::UserRole: if (index.internalId() == CUSTOM_INDEX) { return QVariant{}; @@ -45,7 +48,8 @@ QVariant QCMakePresetItemModel::data(const QModelIndex& index, int role) const if (index.internalId() == SEPARATOR_INDEX) { return QVariant{}; } - return QVariant::fromValue(this->m_presets[index.internalId()]); + return QVariant::fromValue( + this->m_presets[static_cast<cm_qsizetype>(index.internalId())]); case Qt::FontRole: if (index.internalId() == CUSTOM_INDEX) { QFont font; @@ -64,7 +68,8 @@ Qt::ItemFlags QCMakePresetItemModel::flags(const QModelIndex& index) const Qt::ItemIsEditable | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled; if (index.internalId() != SEPARATOR_INDEX && (index.internalId() == CUSTOM_INDEX || - this->m_presets[index.internalId()].enabled)) { + this->m_presets[static_cast<cm_qsizetype>(index.internalId())] + .enabled)) { flags |= Qt::ItemIsSelectable | Qt::ItemIsEnabled; } return flags; @@ -78,7 +83,7 @@ int QCMakePresetItemModel::rowCount(const QModelIndex& parent) const if (this->m_presets.empty()) { return 1; } - return this->m_presets.size() + 2; + return static_cast<int>(this->m_presets.size() + 2); } int QCMakePresetItemModel::columnCount(const QModelIndex& parent) const @@ -139,5 +144,5 @@ int QCMakePresetItemModel::presetNameToRow(const QString& name) const index++; } - return this->m_presets.size() + 1; + return static_cast<int>(this->m_presets.size() + 1); } diff --git a/Source/QtDialog/QCMakeSizeType.h b/Source/QtDialog/QCMakeSizeType.h new file mode 100644 index 0000000..b5cac17 --- /dev/null +++ b/Source/QtDialog/QCMakeSizeType.h @@ -0,0 +1,12 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#pragma once + +#include <QtGlobal> + +// The signed integer type that Qt uses for indexing. +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) +using cm_qsizetype = qsizetype; +#else +using cm_qsizetype = int; +#endif |