diff --git a/src/libs/utils/aspects.cpp b/src/libs/utils/aspects.cpp index e2c8cfeab91..8fdc99b3972 100644 --- a/src/libs/utils/aspects.cpp +++ b/src/libs/utils/aspects.cpp @@ -309,6 +309,17 @@ void BaseAspect::setEnabled(bool enabled) } } +/*! + Makes the enabled state of this aspect depend on the checked state of \a checker. +*/ +void BaseAspect::setEnabler(BoolAspect *checker) +{ + QTC_ASSERT(checker, return); + setEnabled(checker->value()); + connect(checker, &BoolAspect::volatileValueChanged, this, &BaseAspect::setEnabled); + connect(checker, &BoolAspect::valueChanged, this, &BaseAspect::setEnabled); +} + bool BaseAspect::isReadOnly() const { return d->m_readOnly; diff --git a/src/libs/utils/aspects.h b/src/libs/utils/aspects.h index db77275aaea..bb7f3c5e100 100644 --- a/src/libs/utils/aspects.h +++ b/src/libs/utils/aspects.h @@ -44,6 +44,7 @@ QT_END_NAMESPACE namespace Utils { class AspectContainer; +class BoolAspect; class LayoutBuilder; namespace Internal { @@ -95,6 +96,7 @@ public: bool isEnabled() const; void setEnabled(bool enabled); + void setEnabler(BoolAspect *checker); bool isReadOnly() const; void setReadOnly(bool enabled); diff --git a/src/plugins/autotest/boost/boosttestsettings.cpp b/src/plugins/autotest/boost/boosttestsettings.cpp index 910b955ccb1..a32899d0228 100644 --- a/src/plugins/autotest/boost/boosttestsettings.cpp +++ b/src/plugins/autotest/boost/boosttestsettings.cpp @@ -74,6 +74,7 @@ BoostTestSettings::BoostTestSettings() seed.setLabelText(tr("Seed:")); seed.setToolTip(tr("A seed of 0 means no randomization. A value of 1 uses the current " "time, any other value is used as random seed generator.")); + seed.setEnabler(&randomize); registerAspect(&randomize); randomize.setSettingsKey("Randomize"); @@ -99,8 +100,6 @@ BoostTestSettings::BoostTestSettings() memLeaks.setDefaultValue(true); memLeaks.setLabelText(tr("Detect memory leaks")); memLeaks.setToolTip(tr("Enable memory leak detection.")); - - QObject::connect(&randomize, &BoolAspect::volatileValueChanged, &seed, &BaseAspect::setEnabled); } BoostTestSettingsPage::BoostTestSettingsPage(BoostTestSettings *settings, Utils::Id settingsId) diff --git a/src/plugins/autotest/catch/catchtestsettings.cpp b/src/plugins/autotest/catch/catchtestsettings.cpp index e218940c3c8..358ff85fd43 100644 --- a/src/plugins/autotest/catch/catchtestsettings.cpp +++ b/src/plugins/autotest/catch/catchtestsettings.cpp @@ -44,33 +44,33 @@ CatchTestSettings::CatchTestSettings() registerAspect(&abortAfter); abortAfter.setSettingsKey("AbortAfter"); abortAfter.setRange(1, 9999); - abortAfter.setEnabled(false); + abortAfter.setEnabler(&abortAfterChecked); registerAspect(&benchmarkSamples); benchmarkSamples.setSettingsKey("BenchSamples"); benchmarkSamples.setRange(1, 999999); benchmarkSamples.setDefaultValue(100); - benchmarkSamples.setEnabled(false); + benchmarkSamples.setEnabler(&samplesChecked); registerAspect(&benchmarkResamples); benchmarkResamples.setSettingsKey("BenchResamples"); benchmarkResamples.setRange(1, 9999999); benchmarkResamples.setDefaultValue(100000); benchmarkResamples.setToolTip(tr("Number of resamples for bootstrapping.")); - benchmarkResamples.setEnabled(false); + benchmarkResamples.setEnabler(&resamplesChecked); registerAspect(&confidenceInterval); confidenceInterval.setSettingsKey("BenchConfInt"); confidenceInterval.setRange(0., 1.); confidenceInterval.setSingleStep(0.05); confidenceInterval.setDefaultValue(0.95); - confidenceInterval.setEnabled(false); + confidenceInterval.setEnabler(&confidenceIntervalChecked); registerAspect(&benchmarkWarmupTime); benchmarkWarmupTime.setSettingsKey("BenchWarmup"); benchmarkWarmupTime.setSuffix(tr(" ms")); benchmarkWarmupTime.setRange(0, 10000); - benchmarkWarmupTime.setEnabled(false); + benchmarkWarmupTime.setEnabler(&warmupChecked); registerAspect(&abortAfterChecked); abortAfterChecked.setSettingsKey("AbortChecked"); @@ -133,17 +133,6 @@ CatchTestSettings::CatchTestSettings() if (auto boolAspect = dynamic_cast(aspect)) boolAspect->setLabelPlacement(BoolAspect::LabelPlacement::AtCheckBoxWithoutDummyLabel); }); - - QObject::connect(&abortAfterChecked, &BoolAspect::volatileValueChanged, - &abortAfter, &BaseAspect::setEnabled); - QObject::connect(&samplesChecked, &BoolAspect::volatileValueChanged, - &benchmarkSamples, &BaseAspect::setEnabled); - QObject::connect(&resamplesChecked, &BoolAspect::volatileValueChanged, - &benchmarkResamples, &BaseAspect::setEnabled); - QObject::connect(&confidenceIntervalChecked, &BoolAspect::volatileValueChanged, - &confidenceInterval, &BaseAspect::setEnabled); - QObject::connect(&warmupChecked, &BoolAspect::volatileValueChanged, - &benchmarkWarmupTime, &BaseAspect::setEnabled); } CatchTestSettingsPage::CatchTestSettingsPage(CatchTestSettings *settings, Utils::Id settingsId) diff --git a/src/plugins/qmlprofiler/qmlprofilersettings.cpp b/src/plugins/qmlprofiler/qmlprofilersettings.cpp index 3b5cf312c88..ecc3442fc46 100644 --- a/src/plugins/qmlprofiler/qmlprofilersettings.cpp +++ b/src/plugins/qmlprofiler/qmlprofilersettings.cpp @@ -72,8 +72,8 @@ QmlProfilerSettings::QmlProfilerSettings() flushInterval.setSettingsKey("Analyzer.QmlProfiler.FlushInterval"); flushInterval.setRange(1, 10000000); flushInterval.setDefaultValue(1000); - flushInterval.setLabelText(tr("Flush interval (ms):", nullptr)); - flushInterval.setEnabled(false); // Controled by flushEnabled. + flushInterval.setLabelText(tr("Flush interval (ms):")); + flushInterval.setEnabler(&flushEnabled); registerAspect(&lastTraceFile); lastTraceFile.setSettingsKey("Analyzer.QmlProfiler.LastTraceFile"); @@ -88,11 +88,6 @@ QmlProfilerSettings::QmlProfilerSettings() "for example if multiple QML engines start and stop sequentially during a single run of\n" "the program.")); - connect(&flushEnabled, &BoolAspect::volatileValueChanged, - &flushInterval, &BaseAspect::setEnabled); - connect(&flushEnabled, &BoolAspect::valueChanged, - &flushInterval, &BaseAspect::setEnabled); - // Read stored values readSettings(Core::ICore::settings()); } diff --git a/src/plugins/qmlprofiler/qmlprofilersettings.h b/src/plugins/qmlprofiler/qmlprofilersettings.h index 092debb7822..fa65e73a52c 100644 --- a/src/plugins/qmlprofiler/qmlprofilersettings.h +++ b/src/plugins/qmlprofiler/qmlprofilersettings.h @@ -37,6 +37,7 @@ namespace Internal { class QmlProfilerSettings : public ProjectExplorer::ISettingsAspect { Q_OBJECT + public: QmlProfilerSettings();