Salome HOME
Coding style (fix too long line)
[modules/shaper.git] / src / ModuleBase / ModuleBase_Preferences.h
1 // Copyright (C) 2014-2021  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 private:
83   /// Updates SUIT_ResourceMgr values by Config_PropManager properties
84   static void updateResourcesByConfig();
85
86   /// Set default values to the Config_PropManager properties
87   static void resetConfig();
88
89   /// Creates a content for General tab, which defines the behavior of loading parts
90   /// and displaying shapes
91   static void createGeneralTab(ModuleBase_IPrefMgr* thePref, int thePageId);
92
93   /// Creates content of preferences editing widget
94   static void createCustomPage(ModuleBase_IPrefMgr* thePref, int thePageId);
95
96   static SUIT_ResourceMgr* myResourceMgr;
97 };
98
99 //***********************************************************************
100 /// \ingroup GUI
101 /// Manager of preferences
102 class MODULEBASE_EXPORT ModuleBase_PreferencesMgr : public SUIT_PreferenceMgr
103 {
104 Q_OBJECT
105  public:
106    /// Constructor
107    /// \param theResource resource manager
108    /// \param theParent a paren widget
109   ModuleBase_PreferencesMgr(QtxResourceMgr* theResource, QWidget* theParent)
110       : SUIT_PreferenceMgr(theResource, theParent)
111   {
112   }
113
114   virtual ~ModuleBase_PreferencesMgr()
115   {
116   }
117
118   /// Returns True if preferences were modified
119   ModuleBase_Prefs modified() const
120   {
121     return myModified;
122   }
123
124  protected:
125    /// Store changed resource
126   virtual void changedResources(const ResourceMap& theMap);
127
128  private:
129   ModuleBase_Prefs myModified;
130 };
131
132 //***********************************************************************
133 /// \ingroup GUI
134 /// Dialog box for preferences editing
135 class MODULEBASE_EXPORT ModuleBase_PreferencesDlg : public QDialog
136 {
137 Q_OBJECT
138  public:
139    /// Constructor
140    /// \param theResurces resources manager
141    /// \param theParent a parent widget
142   ModuleBase_PreferencesDlg(SUIT_ResourceMgr* theResurces, QWidget* theParent = 0);
143   virtual ~ModuleBase_PreferencesDlg();
144
145   /// Returns True if preferences were changed
146   bool isChanged() const
147   {
148     return myIsChanged;
149   }
150
151   /// Returns list of modified preferences
152   /// \param theModified output list of modified preferences
153   void modified(ModuleBase_Prefs& theModified) const;
154
155  public slots:
156    /// A slot called on Ok button press
157   virtual void accept();
158
159 protected:
160   virtual void showEvent(QShowEvent* theEvent);
161
162 protected slots:
163   /// A slot called on Default button press
164   void onDefault();
165
166  private:
167    /// Create editors for aplication properties
168    void createEditors();
169
170    /// Create a viewer page in dialog box
171    void createViewerPage(int thePageId);
172
173    /// Create menu properties page in the dialog box
174    void createMenuPage(int thePageId);
175
176   ModuleBase_PreferencesMgr* myPreferences;
177   bool myIsChanged;
178 };
179
180 #endif