diff options
author | Mehdi Chinoune <mehdi.chinoune@hotmail.com> | 2022-06-09 20:19:19 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2022-06-10 18:33:20 (GMT) |
commit | 497397bd17ab2855c348c6ee0ed1e28bacd29aca (patch) | |
tree | b343be099a6bd9f51bc7cd00f88e5cddf16fadf0 /Source/QtDialog/QCMake.cxx | |
parent | efbbae9705d89719804387056c8d592545710487 (diff) | |
download | CMake-497397bd17ab2855c348c6ee0ed1e28bacd29aca.zip CMake-497397bd17ab2855c348c6ee0ed1e28bacd29aca.tar.gz CMake-497397bd17ab2855c348c6ee0ed1e28bacd29aca.tar.bz2 |
cmake-gui: Support non-ASCII chars on Windows with Qt6
Since commit baead1e2a8 (Encoding: Remove option to use ANSI code page
internally, 2016-11-01, v3.8.0-rc1~358^2), we always use UTF-8 strings
internally. Using fromLocal8Bit/toLocal8Bit + QTextCodec is no longer
needed. Convert to fromStdString/toStdString instead, which should work
both with Qt5 and Qt6.
Fixes: #23565
Diffstat (limited to 'Source/QtDialog/QCMake.cxx')
-rw-r--r-- | Source/QtDialog/QCMake.cxx | 118 |
1 files changed, 56 insertions, 62 deletions
diff --git a/Source/QtDialog/QCMake.cxx b/Source/QtDialog/QCMake.cxx index ffb6157..5420d8d 100644 --- a/Source/QtDialog/QCMake.cxx +++ b/Source/QtDialog/QCMake.cxx @@ -70,7 +70,7 @@ QCMake::QCMake(QObject* p) this->loadPresets(); if (!this->PresetName.isEmpty() && this->CMakePresetsGraph.ConfigurePresets.find( - std::string(this->PresetName.toLocal8Bit())) == + std::string(this->PresetName.toStdString())) == this->CMakePresetsGraph.ConfigurePresets.end()) { this->setPreset(QString{}); } @@ -87,8 +87,8 @@ void QCMake::loadCache(const QString& dir) void QCMake::setSourceDirectory(const QString& _dir) { - QString dir = QString::fromLocal8Bit( - cmSystemTools::GetActualCaseForPath(_dir.toLocal8Bit().data()).c_str()); + QString dir = QString::fromStdString( + cmSystemTools::GetActualCaseForPath(_dir.toStdString())); if (this->SourceDirectory != dir) { this->SourceDirectory = QDir::fromNativeSeparators(dir); emit this->sourceDirChanged(this->SourceDirectory); @@ -99,8 +99,8 @@ void QCMake::setSourceDirectory(const QString& _dir) void QCMake::setBinaryDirectory(const QString& _dir) { - QString dir = QString::fromLocal8Bit( - cmSystemTools::GetActualCaseForPath(_dir.toLocal8Bit().data()).c_str()); + QString dir = QString::fromStdString( + cmSystemTools::GetActualCaseForPath(_dir.toStdString())); if (this->BinaryDirectory != dir) { this->BinaryDirectory = QDir::fromNativeSeparators(dir); emit this->binaryDirChanged(this->BinaryDirectory); @@ -108,8 +108,7 @@ void QCMake::setBinaryDirectory(const QString& _dir) this->setGenerator(QString()); this->setToolset(QString()); this->setPlatform(QString()); - if (!this->CMakeInstance->LoadCache( - this->BinaryDirectory.toLocal8Bit().data())) { + if (!this->CMakeInstance->LoadCache(this->BinaryDirectory.toStdString())) { QDir testDir(this->BinaryDirectory); if (testDir.exists("CMakeCache.txt")) { cmSystemTools::Error( @@ -124,7 +123,7 @@ void QCMake::setBinaryDirectory(const QString& _dir) emit this->propertiesChanged(props); cmValue homeDir = state->GetCacheEntryValue("CMAKE_HOME_DIRECTORY"); if (homeDir) { - setSourceDirectory(QString::fromLocal8Bit(homeDir->c_str())); + setSourceDirectory(QString(homeDir->c_str())); } cmValue gen = state->GetCacheEntryValue("CMAKE_GENERATOR"); if (gen) { @@ -133,17 +132,17 @@ void QCMake::setBinaryDirectory(const QString& _dir) std::string curGen = cmExternalMakefileProjectGenerator::CreateFullGeneratorName(*gen, *extraGen); - this->setGenerator(QString::fromLocal8Bit(curGen.c_str())); + this->setGenerator(QString::fromStdString(curGen)); } cmValue platform = state->GetCacheEntryValue("CMAKE_GENERATOR_PLATFORM"); if (platform) { - this->setPlatform(QString::fromLocal8Bit(platform->c_str())); + this->setPlatform(QString(platform->c_str())); } cmValue toolset = state->GetCacheEntryValue("CMAKE_GENERATOR_TOOLSET"); if (toolset) { - this->setToolset(QString::fromLocal8Bit(toolset->c_str())); + this->setToolset(QString(toolset->c_str())); } checkOpenPossible(); @@ -157,13 +156,13 @@ void QCMake::setPreset(const QString& name, bool setBinary) emit this->presetChanged(this->PresetName); if (!name.isNull()) { - std::string presetName(name.toLocal8Bit()); + std::string presetName(name.toStdString()); auto const& expandedPreset = this->CMakePresetsGraph.ConfigurePresets[presetName].Expanded; if (expandedPreset) { if (setBinary && !expandedPreset->BinaryDir.empty()) { QString binaryDir = - QString::fromLocal8Bit(expandedPreset->BinaryDir.data()); + QString::fromStdString(expandedPreset->BinaryDir); this->setBinaryDirectory(binaryDir); } if (expandedPreset->WarnDev) { @@ -190,8 +189,8 @@ void QCMake::setPreset(const QString& name, bool setBinary) this->Environment = this->StartEnvironment; for (auto const& v : expandedPreset->Environment) { if (v.second) { - this->Environment.insert(QString::fromLocal8Bit(v.first.data()), - QString::fromLocal8Bit(v.second->data())); + this->Environment.insert(QString::fromStdString(v.first), + QString::fromStdString(v.second.value())); } } } @@ -240,17 +239,14 @@ void QCMake::configure() UINT lastErrorMode = SetErrorMode(0); #endif - this->CMakeInstance->SetHomeDirectory( - this->SourceDirectory.toLocal8Bit().data()); + this->CMakeInstance->SetHomeDirectory(this->SourceDirectory.toStdString()); this->CMakeInstance->SetHomeOutputDirectory( - this->BinaryDirectory.toLocal8Bit().data()); + this->BinaryDirectory.toStdString()); this->CMakeInstance->SetGlobalGenerator( this->CMakeInstance->CreateGlobalGenerator( - this->Generator.toLocal8Bit().data())); - this->CMakeInstance->SetGeneratorPlatform( - this->Platform.toLocal8Bit().data()); - this->CMakeInstance->SetGeneratorToolset( - this->Toolset.toLocal8Bit().data()); + this->Generator.toStdString())); + this->CMakeInstance->SetGeneratorPlatform(this->Platform.toStdString()); + this->CMakeInstance->SetGeneratorToolset(this->Toolset.toStdString()); this->CMakeInstance->LoadCache(); this->CMakeInstance->SetWarnUninitialized(this->WarnUninitializedMode); this->CMakeInstance->PreLoadCMakeFiles(); @@ -303,8 +299,8 @@ void QCMake::open() InterruptFlag = 0; cmSystemTools::ResetErrorOccuredFlag(); - auto successful = this->CMakeInstance->Open( - this->BinaryDirectory.toLocal8Bit().data(), false); + auto successful = + this->CMakeInstance->Open(this->BinaryDirectory.toStdString(), false); #ifdef Q_OS_WIN SetErrorMode(lastErrorMode); @@ -329,10 +325,10 @@ void QCMake::setProperties(const QCMakePropertyList& newProps) } QCMakeProperty prop; - prop.Key = QString::fromLocal8Bit(key.c_str()); + prop.Key = QString::fromStdString(key); int idx = props.indexOf(prop); if (idx == -1) { - toremove.append(QString::fromLocal8Bit(key.c_str())); + toremove.append(QString::fromStdString(key)); } else { prop = props[idx]; #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) @@ -343,8 +339,7 @@ void QCMake::setProperties(const QCMakePropertyList& newProps) if (isBool) { state->SetCacheEntryValue(key, prop.Value.toBool() ? "ON" : "OFF"); } else { - state->SetCacheEntryValue(key, - prop.Value.toString().toLocal8Bit().data()); + state->SetCacheEntryValue(key, prop.Value.toString().toStdString()); } props.removeAt(idx); } @@ -352,35 +347,35 @@ void QCMake::setProperties(const QCMakePropertyList& newProps) // remove some properties foreach (QString const& s, toremove) { - this->CMakeInstance->UnwatchUnusedCli(s.toLocal8Bit().data()); + this->CMakeInstance->UnwatchUnusedCli(s.toStdString()); - state->RemoveCacheEntry(s.toLocal8Bit().data()); + state->RemoveCacheEntry(s.toStdString()); } // add some new properties foreach (QCMakeProperty const& s, props) { - this->CMakeInstance->WatchUnusedCli(s.Key.toLocal8Bit().data()); + this->CMakeInstance->WatchUnusedCli(s.Key.toStdString()); if (s.Type == QCMakeProperty::BOOL) { this->CMakeInstance->AddCacheEntry( - s.Key.toLocal8Bit().data(), s.Value.toBool() ? "ON" : "OFF", - s.Help.toLocal8Bit().data(), cmStateEnums::BOOL); + s.Key.toStdString(), s.Value.toBool() ? "ON" : "OFF", + s.Help.toStdString().c_str(), cmStateEnums::BOOL); } else if (s.Type == QCMakeProperty::STRING) { this->CMakeInstance->AddCacheEntry( - s.Key.toLocal8Bit().data(), s.Value.toString().toLocal8Bit().data(), - s.Help.toLocal8Bit().data(), cmStateEnums::STRING); + s.Key.toStdString(), s.Value.toString().toStdString(), + s.Help.toStdString().c_str(), cmStateEnums::STRING); } else if (s.Type == QCMakeProperty::PATH) { this->CMakeInstance->AddCacheEntry( - s.Key.toLocal8Bit().data(), s.Value.toString().toLocal8Bit().data(), - s.Help.toLocal8Bit().data(), cmStateEnums::PATH); + s.Key.toStdString(), s.Value.toString().toStdString(), + s.Help.toStdString().c_str(), cmStateEnums::PATH); } else if (s.Type == QCMakeProperty::FILEPATH) { this->CMakeInstance->AddCacheEntry( - s.Key.toLocal8Bit().data(), s.Value.toString().toLocal8Bit().data(), - s.Help.toLocal8Bit().data(), cmStateEnums::FILEPATH); + s.Key.toStdString(), s.Value.toString().toStdString(), + s.Help.toStdString().c_str(), cmStateEnums::FILEPATH); } } - this->CMakeInstance->SaveCache(this->BinaryDirectory.toLocal8Bit().data()); + this->CMakeInstance->SaveCache(this->BinaryDirectory.toStdString()); } QCMakePropertyList QCMake::properties() const @@ -399,11 +394,11 @@ QCMakePropertyList QCMake::properties() const cmValue cachedValue = state->GetCacheEntryValue(key); QCMakeProperty prop; - prop.Key = QString::fromLocal8Bit(key.c_str()); + prop.Key = QString::fromStdString(key); if (cmValue hs = state->GetCacheEntryProperty(key, "HELPSTRING")) { - prop.Help = QString::fromLocal8Bit(hs->c_str()); + prop.Help = QString(hs->c_str()); } - prop.Value = QString::fromLocal8Bit(cachedValue->c_str()); + prop.Value = QString(cachedValue->c_str()); prop.Advanced = state->GetCacheEntryPropertyAsBool(key, "ADVANCED"); if (t == cmStateEnums::BOOL) { prop.Type = QCMakeProperty::BOOL; @@ -416,8 +411,7 @@ QCMakePropertyList QCMake::properties() const prop.Type = QCMakeProperty::STRING; cmValue stringsProperty = state->GetCacheEntryProperty(key, "STRINGS"); if (stringsProperty) { - prop.Strings = - QString::fromLocal8Bit(stringsProperty->c_str()).split(";"); + prop.Strings = QString(stringsProperty->c_str()).split(";"); } } @@ -425,7 +419,7 @@ QCMakePropertyList QCMake::properties() const } if (!this->PresetName.isNull()) { - std::string presetName(this->PresetName.toLocal8Bit()); + std::string presetName(this->PresetName.toStdString()); auto const& p = this->CMakePresetsGraph.ConfigurePresets.at(presetName).Expanded; if (p) { @@ -434,8 +428,8 @@ QCMakePropertyList QCMake::properties() const continue; } QCMakeProperty prop; - prop.Key = QString::fromLocal8Bit(v.first.data()); - prop.Value = QString::fromLocal8Bit(v.second->Value.data()); + prop.Key = QString::fromStdString(v.first); + prop.Value = QString::fromStdString(v.second->Value); prop.Type = QCMakeProperty::STRING; if (!v.second->Type.empty()) { auto type = cmState::StringToCacheEntryType(v.second->Type); @@ -523,18 +517,18 @@ void QCMake::setUpEnvironment() const { auto env = QProcessEnvironment::systemEnvironment(); for (auto const& key : env.keys()) { - cmSystemTools::UnsetEnv(key.toLocal8Bit().data()); + cmSystemTools::UnsetEnv(key.toStdString().c_str()); } for (auto const& var : this->Environment.toStringList()) { - cmSystemTools::PutEnv(var.toLocal8Bit().data()); + cmSystemTools::PutEnv(var.toStdString()); } } void QCMake::loadPresets() { auto result = this->CMakePresetsGraph.ReadProjectPresets( - this->SourceDirectory.toLocal8Bit().data(), true); + this->SourceDirectory.toStdString(), true); if (result != this->LastLoadPresetsResult && result != cmCMakePresetsGraph::ReadFileResult::READ_OK) { emit this->presetLoadError(this->SourceDirectory, result); @@ -550,14 +544,14 @@ void QCMake::loadPresets() } QCMakePreset preset; - preset.name = QString::fromLocal8Bit(p.Name.data()); - preset.displayName = QString::fromLocal8Bit(p.DisplayName.data()); - preset.description = QString::fromLocal8Bit(p.Description.data()); - preset.generator = QString::fromLocal8Bit(p.Generator.data()); - preset.architecture = QString::fromLocal8Bit(p.Architecture.data()); + preset.name = QString::fromStdString(p.Name); + preset.displayName = QString::fromStdString(p.DisplayName); + preset.description = QString::fromStdString(p.Description); + preset.generator = QString::fromStdString(p.Generator); + preset.architecture = QString::fromStdString(p.Architecture); preset.setArchitecture = !p.ArchitectureStrategy || p.ArchitectureStrategy == cmCMakePresetsGraph::ArchToolsetStrategy::Set; - preset.toolset = QString::fromLocal8Bit(p.Toolset.data()); + preset.toolset = QString::fromStdString(p.Toolset); preset.setToolset = !p.ToolsetStrategy || p.ToolsetStrategy == cmCMakePresetsGraph::ArchToolsetStrategy::Set; preset.enabled = it.Expanded && it.Expanded->ConditionResult && @@ -599,9 +593,9 @@ std::vector<cmake::GeneratorInfo> const& QCMake::availableGenerators() const void QCMake::deleteCache() { // delete cache - this->CMakeInstance->DeleteCache(this->BinaryDirectory.toLocal8Bit().data()); + this->CMakeInstance->DeleteCache(this->BinaryDirectory.toStdString()); // reload to make our cache empty - this->CMakeInstance->LoadCache(this->BinaryDirectory.toLocal8Bit().data()); + this->CMakeInstance->LoadCache(this->BinaryDirectory.toStdString()); // emit no generator and no properties this->setGenerator(QString()); this->setToolset(QString()); @@ -615,7 +609,7 @@ void QCMake::reloadCache() QCMakePropertyList props; emit this->propertiesChanged(props); // reload - this->CMakeInstance->LoadCache(this->BinaryDirectory.toLocal8Bit().data()); + this->CMakeInstance->LoadCache(this->BinaryDirectory.toStdString()); // emit new cache properties props = this->properties(); emit this->propertiesChanged(props); @@ -681,7 +675,7 @@ void QCMake::setWarnUninitializedMode(bool value) void QCMake::checkOpenPossible() { - std::string data = this->BinaryDirectory.toLocal8Bit().data(); + std::string data = this->BinaryDirectory.toStdString(); auto possible = this->CMakeInstance->Open(data, true); emit openPossible(possible); } |