CMakeProjectManager: Register settings aspects more directly

Change-Id: I7bfbe3ad625b0902561975968221e90ce6af06d6
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
hjk
2023-05-26 10:11:55 +02:00
parent 4e60203132
commit a69489cd1e
3 changed files with 11 additions and 22 deletions

View File

@@ -50,21 +50,17 @@ public:
setDisplayCategory("CMake"); setDisplayCategory("CMake");
setCategory(Constants::Settings::CATEGORY); setCategory(Constants::Settings::CATEGORY);
registerAspect(&command);
command.setSettingsKey("autoFormatCommand"); command.setSettingsKey("autoFormatCommand");
command.setDefaultValue("cmake-format"); command.setDefaultValue("cmake-format");
command.setExpectedKind(PathChooser::ExistingCommand); command.setExpectedKind(PathChooser::ExistingCommand);
registerAspect(&autoFormatOnSave);
autoFormatOnSave.setSettingsKey("autoFormatOnSave"); autoFormatOnSave.setSettingsKey("autoFormatOnSave");
autoFormatOnSave.setLabelText(Tr::tr("Enable auto format on file save")); autoFormatOnSave.setLabelText(Tr::tr("Enable auto format on file save"));
registerAspect(&autoFormatOnlyCurrentProject);
autoFormatOnlyCurrentProject.setSettingsKey("autoFormatOnlyCurrentProject"); autoFormatOnlyCurrentProject.setSettingsKey("autoFormatOnlyCurrentProject");
autoFormatOnlyCurrentProject.setDefaultValue(true); autoFormatOnlyCurrentProject.setDefaultValue(true);
autoFormatOnlyCurrentProject.setLabelText(Tr::tr("Restrict to files contained in the current project")); autoFormatOnlyCurrentProject.setLabelText(Tr::tr("Restrict to files contained in the current project"));
registerAspect(&autoFormatMime);
autoFormatMime.setSettingsKey("autoFormatMime"); autoFormatMime.setSettingsKey("autoFormatMime");
autoFormatMime.setDefaultValue("text/x-cmake"); autoFormatMime.setDefaultValue("text/x-cmake");
autoFormatMime.setLabelText(Tr::tr("Restrict to MIME types:")); autoFormatMime.setLabelText(Tr::tr("Restrict to MIME types:"));
@@ -127,10 +123,10 @@ public:
return cmd; return cmd;
} }
FilePathAspect command; FilePathAspect command{this};
BoolAspect autoFormatOnSave; BoolAspect autoFormatOnSave{this};
BoolAspect autoFormatOnlyCurrentProject; BoolAspect autoFormatOnlyCurrentProject{this};
StringAspect autoFormatMime; StringAspect autoFormatMime{this};
QAction formatFile{Tr::tr("Format &Current File")}; QAction formatFile{Tr::tr("Format &Current File")};
}; };

View File

@@ -51,20 +51,17 @@ CMakeSpecificSettings::CMakeSpecificSettings()
setSettingsGroup("CMakeSpecificSettings"); setSettingsGroup("CMakeSpecificSettings");
setAutoApply(false); setAutoApply(false);
registerAspect(&autorunCMake);
autorunCMake.setSettingsKey("AutorunCMake"); autorunCMake.setSettingsKey("AutorunCMake");
autorunCMake.setDefaultValue(true); autorunCMake.setDefaultValue(true);
autorunCMake.setLabelText(::CMakeProjectManager::Tr::tr("Autorun CMake")); autorunCMake.setLabelText(::CMakeProjectManager::Tr::tr("Autorun CMake"));
autorunCMake.setToolTip(::CMakeProjectManager::Tr::tr( autorunCMake.setToolTip(::CMakeProjectManager::Tr::tr(
"Automatically run CMake after changes to CMake project files.")); "Automatically run CMake after changes to CMake project files."));
registerAspect(&ninjaPath);
ninjaPath.setSettingsKey("NinjaPath"); ninjaPath.setSettingsKey("NinjaPath");
// never save this to the settings: // never save this to the settings:
ninjaPath.setToSettingsTransformation( ninjaPath.setToSettingsTransformation(
[](const QVariant &) { return QVariant::fromValue(QString()); }); [](const QVariant &) { return QVariant::fromValue(QString()); });
registerAspect(&packageManagerAutoSetup);
packageManagerAutoSetup.setSettingsKey("PackageManagerAutoSetup"); packageManagerAutoSetup.setSettingsKey("PackageManagerAutoSetup");
packageManagerAutoSetup.setDefaultValue(true); packageManagerAutoSetup.setDefaultValue(true);
packageManagerAutoSetup.setLabelText(::CMakeProjectManager::Tr::tr("Package manager auto setup")); packageManagerAutoSetup.setLabelText(::CMakeProjectManager::Tr::tr("Package manager auto setup"));
@@ -72,24 +69,20 @@ CMakeSpecificSettings::CMakeSpecificSettings()
"pointing to a CMake script that will install dependencies from the conanfile.txt, " "pointing to a CMake script that will install dependencies from the conanfile.txt, "
"conanfile.py, or vcpkg.json file from the project source directory.")); "conanfile.py, or vcpkg.json file from the project source directory."));
registerAspect(&askBeforeReConfigureInitialParams);
askBeforeReConfigureInitialParams.setSettingsKey("AskReConfigureInitialParams"); askBeforeReConfigureInitialParams.setSettingsKey("AskReConfigureInitialParams");
askBeforeReConfigureInitialParams.setDefaultValue(true); askBeforeReConfigureInitialParams.setDefaultValue(true);
askBeforeReConfigureInitialParams.setLabelText(::CMakeProjectManager::Tr::tr("Ask before re-configuring with " askBeforeReConfigureInitialParams.setLabelText(::CMakeProjectManager::Tr::tr("Ask before re-configuring with "
"initial parameters")); "initial parameters"));
registerAspect(&askBeforePresetsReload);
askBeforePresetsReload.setSettingsKey("AskBeforePresetsReload"); askBeforePresetsReload.setSettingsKey("AskBeforePresetsReload");
askBeforePresetsReload.setDefaultValue(true); askBeforePresetsReload.setDefaultValue(true);
askBeforePresetsReload.setLabelText(::CMakeProjectManager::Tr::tr("Ask before reloading CMake Presets")); askBeforePresetsReload.setLabelText(::CMakeProjectManager::Tr::tr("Ask before reloading CMake Presets"));
registerAspect(&showSourceSubFolders);
showSourceSubFolders.setSettingsKey("ShowSourceSubFolders"); showSourceSubFolders.setSettingsKey("ShowSourceSubFolders");
showSourceSubFolders.setDefaultValue(true); showSourceSubFolders.setDefaultValue(true);
showSourceSubFolders.setLabelText( showSourceSubFolders.setLabelText(
::CMakeProjectManager::Tr::tr("Show subfolders inside source group folders")); ::CMakeProjectManager::Tr::tr("Show subfolders inside source group folders"));
registerAspect(&showAdvancedOptionsByDefault);
showAdvancedOptionsByDefault.setSettingsKey("ShowAdvancedOptionsByDefault"); showAdvancedOptionsByDefault.setSettingsKey("ShowAdvancedOptionsByDefault");
showAdvancedOptionsByDefault.setDefaultValue(false); showAdvancedOptionsByDefault.setDefaultValue(false);
showAdvancedOptionsByDefault.setLabelText( showAdvancedOptionsByDefault.setLabelText(

View File

@@ -14,13 +14,13 @@ public:
static CMakeSpecificSettings *instance(); static CMakeSpecificSettings *instance();
Utils::BoolAspect autorunCMake; Utils::BoolAspect autorunCMake{this};
Utils::FilePathAspect ninjaPath; Utils::FilePathAspect ninjaPath{this};
Utils::BoolAspect packageManagerAutoSetup; Utils::BoolAspect packageManagerAutoSetup{this};
Utils::BoolAspect askBeforeReConfigureInitialParams; Utils::BoolAspect askBeforeReConfigureInitialParams{this};
Utils::BoolAspect askBeforePresetsReload; Utils::BoolAspect askBeforePresetsReload{this};
Utils::BoolAspect showSourceSubFolders; Utils::BoolAspect showSourceSubFolders{this};
Utils::BoolAspect showAdvancedOptionsByDefault; Utils::BoolAspect showAdvancedOptionsByDefault{this};
}; };
} // CMakeProjectManager::Internal } // CMakeProjectManager::Internal