1 /*
2     SPDX-FileCopyrightText: 2014 Alex Richardson <arichardson.kde@gmail.com>
3 
4     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5 */
6 
7 #ifndef KDEVELOP_CONFIGPAGE_H
8 #define KDEVELOP_CONFIGPAGE_H
9 
10 #include <KTextEditor/ConfigPage>
11 #include <KLocalizedString>
12 
13 #include "interfacesexport.h"
14 
15 class KCoreConfigSkeleton;
16 
17 namespace KDevelop {
18 class IPlugin;
19 class ConfigPagePrivate;
20 
21 class KDEVPLATFORMINTERFACES_EXPORT ConfigPage : public KTextEditor::ConfigPage
22 {
23     Q_OBJECT
24 
25 public:
26     /**
27      * Create a new config page
28      * @param plugin the plugin that created this config page
29      * @param config the config skeleton that is used to store the preferences. If you don't use
30      * a K(Core)ConfigSkeleton to save the settings you can also pass null here.
31      * However this means that you will have to manually implement the apply(), defaults() and reset() slots
32      * @param parent parent widget
33      */
34     explicit ConfigPage(IPlugin* plugin, KCoreConfigSkeleton* config = nullptr, QWidget* parent = nullptr);
35     ~ConfigPage() override;
36 
37     /**
38      * Get the number of subpages of this page
39      * @return The number of child pages or an integer < 1 if there are none.
40      * The default implementation returns zero.
41      */
42     virtual int childPages() const;
43 
44     /**
45      * @return the child config page for index @p number or @c nullptr if there is none.
46      * The default implementation returns @c nullptr.
47      */
48     virtual ConfigPage* childPage(int number);
49 
50     enum ConfigPageType
51     {
52         DefaultConfigPage,
53         LanguageConfigPage, ///< A config page that contains language specific settings. This page is appended as a child page to the "Language support" config page.
54         AnalyzerConfigPage, ///< A config page that contains settings for some analyzer. This page is appended as a child page to the "Analyzers" config page.
55         DocumentationConfigPage, ///< A config page that contains settings for some documentation plugin. This page is appended as a child page to the "Documentation" config page.
56         RuntimeConfigPage ///< A config page that contains settings for some runtime plugin. This page is appended as a child page to the "Runtimes" config page.
57     };
58 
59     /**
60      * @return The type of this config page. Default implementaion returns DefaultConfigPageType
61      */
62     virtual ConfigPageType configPageType() const;
63 
64     /**
65      * @return the plugin that this config page was created by or nullptr if it was not created by a plugin.
66      */
67     IPlugin* plugin() const;
68 
69     /**
70      * Initializes the KConfigDialogManager.
71      * Must be called explicitly since not all child widgets are available at the end of the constructor.
72      * This is handled automatically by KDevelop::ConfigDialog, subclasses don't need to call this.
73      */
74     void initConfigManager();
75 
76     /**
77      * @return the KCoreConfigSkeleton used to store the settings for this page or @c nullptr
78      * if settings are managed differently
79      */
80     KCoreConfigSkeleton* configSkeleton() const;
81 
82     /**
83      * Sets the config skeleton to @p skel and will create a KConfigDialogManager if needed.
84      * This can be used if the KCoreConfigSkeleton* doesn't exist yet when calling the base class constructor.
85      */
86     void setConfigSkeleton(KCoreConfigSkeleton* skel);
87 
88 public Q_SLOTS:
89     void apply() override;
90     void defaults() override;
91     void reset() override;
92 
93 private:
94     const QScopedPointer<class ConfigPagePrivate> d_ptr;
95     Q_DECLARE_PRIVATE(ConfigPage)
96 };
97 
98 }
99 
100 #endif // KDEVELOP_CONFIGPAGE_H
101