Salome HOME
b5b40da0820ce79bd93a48d72cd2fcb1a9495703
[modules/shaper.git] / src / ModuleBase / ModuleBase_Preferences.h
1 // Copyright (C) 2014-2023  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #ifndef ModuleBase_Preferences_H
21 #define ModuleBase_Preferences_H
22
23 #include "ModuleBase.h"
24 #include "ModuleBase_IPrefMgr.h"
25
26 #include <SUIT_PreferenceMgr.h>
27 #include <QDialog>
28
29 class SUIT_ResourceMgr;
30 class QWidget;
31
32 /// Pair of values: section name, value name
33 typedef QPair<QString, QString> ModuleBase_Pref;
34
35 /// List of preferences
36 typedef QList<ModuleBase_Pref> ModuleBase_Prefs;
37
38 //***********************************************************************
39 /// \ingroup GUI
40 /// Class for manipulation  with preferences in the application
41 class MODULEBASE_EXPORT ModuleBase_Preferences
42 {
43  public:
44    /// Name of preferences of viewer section
45   static const QString VIEWER_SECTION;
46
47    /// Name of preferences of menu section
48   static const QString MENU_SECTION;
49
50   /// Name of preferences of general section
51   static const QString GENERAL_SECTION;
52
53   /// Shows a dialog box to edit preferences
54   /// \param theModified a list of modified preferences
55   static bool editPreferences(ModuleBase_Prefs& theModified);
56
57   /// Returns currently installed resource manager
58   static SUIT_ResourceMgr* resourceMgr();
59
60   /// Sets a resource manager
61   /// It is used in case of necessity to define external resource manager (not SHAPER)
62   /// \param theMgr resource manager
63   static void setResourceMgr(SUIT_ResourceMgr* theMgr) { myResourceMgr = theMgr; }
64
65   /// Updates Config_PropManager properties by module from SUIT_ResourceMgr
66   static void updateConfigByResources();
67
68   /// Loads properties defined by module to Config_PropManager
69   static void loadCustomProps();
70
71   /// Create editable content
72   /// \param thePref interface to preference manager
73   /// \param thePage an id of a page
74   static void createEditContent(ModuleBase_IPrefMgr* thePref, int thePage);
75
76   /// Retrieve preferences of resource manage to default state
77   static void resetResourcePreferences(SUIT_PreferenceMgr* thePref);
78
79   /// Retrieve preferences of config prop to default state
80   static void resetConfigPropPreferences(SUIT_PreferenceMgr* thePref);
81
82   /// Updates content of preferences for sketch tab
83   static void updateSketchTab(ModuleBase_IPrefMgr* thePref, int thePageId);
84
85 private:
86   /// Updates SUIT_ResourceMgr values by Config_PropManager properties
87   static void updateResourcesByConfig();
88
89   /// Set default values to the Config_PropManager properties
90   static void resetConfig();
91
92   /// Creates a content for General tab, which defines the behavior of loading parts
93   /// and displaying shapes
94   static void createGeneralTab(ModuleBase_IPrefMgr* thePref, int thePageId);
95
96   /// Creates content of preferences editing widget
97   static void createCustomPage(ModuleBase_IPrefMgr* thePref, int thePageId);
98
99   static SUIT_ResourceMgr* myResourceMgr;
100 };
101
102 //***********************************************************************
103 /// \ingroup GUI
104 /// Manager of preferences
105 class MODULEBASE_EXPORT ModuleBase_PreferencesMgr : public SUIT_PreferenceMgr
106 {
107 Q_OBJECT
108  public:
109    /// Constructor
110    /// \param theResource resource manager
111    /// \param theParent a paren widget
112   ModuleBase_PreferencesMgr(QtxResourceMgr* theResource, QWidget* theParent)
113       : SUIT_PreferenceMgr(theResource, theParent)
114   {
115   }
116
117   virtual ~ModuleBase_PreferencesMgr()
118   {
119   }
120
121   /// Returns True if preferences were modified
122   ModuleBase_Prefs modified() const
123   {
124     return myModified;
125   }
126
127  protected:
128    /// Store changed resource
129   virtual void changedResources(const ResourceMap& theMap);
130
131  private:
132   ModuleBase_Prefs myModified;
133 };
134
135 //***********************************************************************
136 /// \ingroup GUI
137 /// Dialog box for preferences editing
138 class MODULEBASE_EXPORT ModuleBase_PreferencesDlg : public QDialog
139 {
140 Q_OBJECT
141  public:
142    /// Constructor
143    /// \param theResurces resources manager
144    /// \param theParent a parent widget
145   ModuleBase_PreferencesDlg(SUIT_ResourceMgr* theResurces, QWidget* theParent = 0);
146   virtual ~ModuleBase_PreferencesDlg();
147
148   /// Returns True if preferences were changed
149   bool isChanged() const
150   {
151     return myIsChanged;
152   }
153
154   /// Returns list of modified preferences
155   /// \param theModified output list of modified preferences
156   void modified(ModuleBase_Prefs& theModified) const;
157
158  public slots:
159    /// A slot called on Ok button press
160   virtual void accept();
161
162 protected:
163   virtual void showEvent(QShowEvent* theEvent);
164
165 protected slots:
166   /// A slot called on Default button press
167   void onDefault();
168
169  private:
170    /// Create editors for aplication properties
171    void createEditors();
172
173    /// Create a viewer page in dialog box
174    void createViewerPage(int thePageId);
175
176    /// Create menu properties page in the dialog box
177    void createMenuPage(int thePageId);
178
179   ModuleBase_PreferencesMgr* myPreferences;
180   bool myIsChanged;
181 };
182
183 #endif