diff --git a/src/kcmodule.h b/src/kcmodule.h --- a/src/kcmodule.h +++ b/src/kcmodule.h @@ -359,6 +359,18 @@ */ void changed(bool state); + /** + * Indicate that the state of the modules contents matches the default + * settings. + * + * This signal is emitted whenever the state of the configuration + * shown in the module changes. It allows the module container to + * keep track of defaults. + * + * @since 5.65 + */ + void defaulted(bool state); + /** * Indicate that the module's quickhelp has changed. * @@ -453,12 +465,27 @@ */ bool managedWidgetChangeState() const; + /** + * Returns the defaulted state of automatically managed widgets in this dialog + * + * @since 5.65 + */ + bool managedWidgetDefaultState() const; + /** * Call this method when your manually managed widgets change state between * changed and not changed */ void unmanagedWidgetChangeState(bool); + /** + * Call this method when your manually managed widgets change state between + * defaulted and not defaulted + * + * @since 5.65 + */ + void unmanagedWidgetDefaultState(bool); + private: KCModulePrivate *const d; }; diff --git a/src/kcmodule.cpp b/src/kcmodule.cpp --- a/src/kcmodule.cpp +++ b/src/kcmodule.cpp @@ -43,7 +43,9 @@ _useRootOnlyMessage(false), _firstshow(true), _needsAuthorization(false), - _unmanagedWidgetChangeState(false) + _unmanagedWidgetChangeState(false), + _unmanagedWidgetDefaultState(false), + _unmanagedWidgetDefaultStateCalled(false) { } void authStatusChanged(int status); @@ -69,6 +71,8 @@ // widgets to coexist peacefully and do the correct thing with // the changed(bool) signal bool _unmanagedWidgetChangeState : 1; + bool _unmanagedWidgetDefaultState : 1; + bool _unmanagedWidgetDefaultStateCalled : 1; }; KCModule::KCModule(const KAboutData *aboutData, QWidget *parent, const QVariantList &) @@ -194,7 +198,7 @@ for (KConfigDialogManager *manager : qAsConst(d->managers)) { manager->updateWidgets(); } - emit changed(false); + widgetChanged(); } void KCModule::save() @@ -215,6 +219,11 @@ void KCModule::widgetChanged() { emit changed(d->_unmanagedWidgetChangeState || managedWidgetChangeState()); + if (d->_unmanagedWidgetDefaultStateCalled) { + emit defaulted(d->_unmanagedWidgetDefaultState && managedWidgetDefaultState()); + } else { + emit defaulted(!d->managers.isEmpty() && managedWidgetDefaultState()); + } } bool KCModule::managedWidgetChangeState() const @@ -228,12 +237,30 @@ return false; } +bool KCModule::managedWidgetDefaultState() const +{ + for (KConfigDialogManager *manager : qAsConst(d->managers)) { + if (!manager->isDefault()) { + return false; + } + } + + return true; +} + void KCModule::unmanagedWidgetChangeState(bool changed) { d->_unmanagedWidgetChangeState = changed; widgetChanged(); } +void KCModule::unmanagedWidgetDefaultState(bool defaulted) +{ + d->_unmanagedWidgetDefaultStateCalled = true; + d->_unmanagedWidgetDefaultState = defaulted; + widgetChanged(); +} + const KAboutData *KCModule::aboutData() const { return d->_about;