mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-11 08:20:18 -06:00
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.
This commit is contained in:
@@ -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++) {
|
||||
|
||||
@@ -175,6 +175,7 @@ add_library(
|
||||
QCMakePresetComboBox.h
|
||||
QCMakePresetItemModel.cxx
|
||||
QCMakePresetItemModel.h
|
||||
QCMakeSizeType.h
|
||||
QCMakeWidgets.cxx
|
||||
QCMakeWidgets.h
|
||||
RegexExplorer.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]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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]);
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
12
Source/QtDialog/QCMakeSizeType.h
Normal file
12
Source/QtDialog/QCMakeSizeType.h
Normal file
@@ -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
|
||||
Reference in New Issue
Block a user