File indexing completed on 2024-05-12 07:47:31
0001 /* 0002 SPDX-FileCopyrightText: 2019 Kevin Ottens <kevin.ottens@enioka.com> 0003 SPDX-License-Identifier: LGPL-2.0-or-later 0004 */ 0005 0006 #ifndef MANAGEDCONFIGMODULE_H 0007 #define MANAGEDCONFIGMODULE_H 0008 0009 #include "kquickconfigmodule.h" 0010 #include <memory> 0011 0012 class KCoreConfigSkeleton; 0013 0014 class KQuickManagedConfigModulePrivate; 0015 0016 /** 0017 * @class KQuickManagedConfigModule managedconfigmodule.h KQuickAddons/ManagedConfigModule 0018 * 0019 * The base class for configuration modules using KConfigXT settings. 0020 * 0021 * We are assuming here that SettingsObject is a class generated from a kcfg file 0022 * and that it will be somehow exposed as a constant property to be used from the QML side. 0023 * It will be automatically discovered by ManagedConfigModule which will update 0024 * the saveNeeded and defaults inherited properties by itself. Thus by inheriting from 0025 * this class you shall not try to manage those properties yourselves. 0026 * By passing in "this" as a parent, we prevent memory leaks and allow KQuickManagedConfigModule to 0027 * automatically find the created settings object. 0028 * 0029 * The constructor of the ConfigModule then looks like this: 0030 * \code 0031 * YourConfigModule::YourConfigModule(QObject *parent, const KPluginMetaData &metaData) 0032 * : ManagedConfigModule(parent, metaData) 0033 * , m_settingsObject(new SettingsObject(this)) 0034 * { 0035 * } 0036 * \endcode 0037 * 0038 * @since 6.0 0039 */ 0040 class KCMUTILSQUICK_EXPORT KQuickManagedConfigModule : public KQuickConfigModule 0041 { 0042 Q_OBJECT 0043 0044 public: 0045 /** 0046 * Destroys the module. 0047 */ 0048 ~KQuickManagedConfigModule() override; 0049 0050 public Q_SLOTS: 0051 /** 0052 * Load the configuration data into the module. 0053 * 0054 * This method is invoked whenever the module should read its configuration 0055 * (most of the times from a config file) and update the user interface. 0056 * This happens when the user clicks the "Reset" button in the control 0057 * center, to undo all of his changes and restore the currently valid 0058 * settings. It is also called right after construction. 0059 * 0060 * By default this will load the settings from the child setting objects 0061 * of this module. 0062 */ 0063 void load() override; 0064 0065 /** 0066 * Save the configuration data. 0067 * 0068 * The save method stores the config information as shown 0069 * in the user interface in the config files. 0070 * It is called when the user clicks "Apply" or "Ok". 0071 * 0072 * By default this will save the child setting objects 0073 * of this module. 0074 */ 0075 void save() override; 0076 0077 /** 0078 * Sets the configuration to sensible default values. 0079 * 0080 * This method is called when the user clicks the "Default" 0081 * button. It should set the display to useful values. 0082 * 0083 * By default this will reset to defaults the child setting objects 0084 * of this module. 0085 */ 0086 void defaults() override; 0087 0088 protected Q_SLOTS: 0089 /** 0090 * Forces the module to reevaluate the saveNeeded and 0091 * representsDefault state. 0092 * 0093 * This is required for some modules which might have 0094 * some settings managed outside of KConfigXT objects. 0095 */ 0096 void settingsChanged(); 0097 0098 /** 0099 * Allow to register manually settings class generated from a kcfg file. 0100 * Used by derived class when automatic discovery is not possible. 0101 * After skeleton is registered it will automatically call settingsChanged(). 0102 */ 0103 void registerSettings(KCoreConfigSkeleton *skeleton); 0104 0105 protected: 0106 /** 0107 * Base class for all KControlModules. 0108 * Use KQuickConfigModuleLoader to instantiate this class 0109 * 0110 * @note do not emit changed signals here, since they are not yet connected to any slot. 0111 */ 0112 explicit KQuickManagedConfigModule(QObject *parent, const KPluginMetaData &metaData); 0113 0114 private: 0115 /** 0116 * Allows to indicate if the module requires saving. 0117 * 0118 * By default this returns false, it needs to be overridden only 0119 * if the module has state outside of the settings declared in 0120 * the KConfigXT classes it uses. 0121 */ 0122 virtual bool isSaveNeeded() const; 0123 0124 /** 0125 * Allows to indicate if the module state is representing its defaults. 0126 * 0127 * By default this returns true, it needs to be overridden only 0128 * if the module has state outside of the settings declared in 0129 * the KConfigXT classes it uses. 0130 */ 0131 virtual bool isDefaults() const; 0132 0133 const std::unique_ptr<KQuickManagedConfigModulePrivate> d; 0134 friend class KQuickManagedConfigModulePrivate; 0135 }; 0136 0137 #endif // MANAGEDCONFIGMODULE_H