Salome HOME
Merge branch 'Pre_2.8.0_development'
[modules/shaper.git] / src / ModuleBase / ModuleBase_Preferences.h
1 // Copyright (C) 2014-2017  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
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 //
20
21 #ifndef ModuleBase_Preferences_H
22 #define ModuleBase_Preferences_H
23
24 #include "ModuleBase.h"
25 #include "ModuleBase_IPrefMgr.h"
26
27 #include <SUIT_PreferenceMgr.h>
28 #include <QDialog>
29
30 class SUIT_ResourceMgr;
31 class QWidget;
32
33 /// Pair of values: section name, value name
34 typedef QPair<QString, QString> ModuleBase_Pref;
35
36 /// List of preferences
37 typedef QList<ModuleBase_Pref> ModuleBase_Prefs;
38
39 //***********************************************************************
40 /// \ingroup GUI
41 /// Class for manipulation  with preferences in the application
42 class MODULEBASE_EXPORT ModuleBase_Preferences
43 {
44  public:
45    /// Name of preferences of viewer section
46   static const QString VIEWER_SECTION;
47
48    /// Name of preferences of menu section
49   static const QString MENU_SECTION;
50
51   /// Shows a dialog box to edit preferences
52   /// \param theModified a list of modified preferences
53   static bool editPreferences(ModuleBase_Prefs& theModified);
54
55   /// Returns currently installed resource manager
56   static SUIT_ResourceMgr* resourceMgr();
57
58   /// Sets a resource manager
59   /// It is used in case of necessity to define external resource manager (not SHAPER)
60   /// \param theMgr resource manager
61   static void setResourceMgr(SUIT_ResourceMgr* theMgr) { myResourceMgr = theMgr; }
62
63   /// Updates Config_PropManager properties by module from SUIT_ResourceMgr
64   static void updateConfigByResources();
65
66   /// Loads properties defined by module to Config_PropManager
67   static void loadCustomProps();
68
69   /// Create editable content
70   /// \param thePref interface to preference manager
71   /// \param thePage an id of a page
72   static void createEditContent(ModuleBase_IPrefMgr* thePref, int thePage);
73
74   /// Retrieve preferences of resource manage to default state
75   static void resetResourcePreferences(SUIT_PreferenceMgr* thePref);
76
77   /// Retrieve preferences of config prop to default state
78   static void resetConfigPropPreferences(SUIT_PreferenceMgr* thePref);
79
80 private:
81   /// Updates SUIT_ResourceMgr values by Config_PropManager properties
82   static void updateResourcesByConfig();
83
84   /// Set default values to the Config_PropManager properties
85   static void resetConfig();
86
87   /// Creates content of preferences editing widget
88   static void createCustomPage(ModuleBase_IPrefMgr* thePref, int thePageId);
89
90   static SUIT_ResourceMgr* myResourceMgr;
91 };
92
93 //***********************************************************************
94 /// \ingroup GUI
95 /// Manager of preferences
96 class MODULEBASE_EXPORT ModuleBase_PreferencesMgr : public SUIT_PreferenceMgr
97 {
98 Q_OBJECT
99  public:
100    /// Constructor
101    /// \param theResource resource manager
102    /// \param theParent a paren widget
103   ModuleBase_PreferencesMgr(QtxResourceMgr* theResource, QWidget* theParent)
104       : SUIT_PreferenceMgr(theResource, theParent)
105   {
106   }
107
108   virtual ~ModuleBase_PreferencesMgr()
109   {
110   }
111
112   /// Returns True if preferences were modified
113   ModuleBase_Prefs modified() const
114   {
115     return myModified;
116   }
117
118  protected:
119    /// Store changed resource
120   virtual void changedResources(const ResourceMap& theMap);
121
122  private:
123   ModuleBase_Prefs myModified;
124 };
125
126 //***********************************************************************
127 /// \ingroup GUI
128 /// Dialog box for preferences editing
129 class MODULEBASE_EXPORT ModuleBase_PreferencesDlg : public QDialog
130 {
131 Q_OBJECT
132  public:
133    /// Constructor
134    /// \param theResurces resources manager
135    /// \param theParent a parent widget
136   ModuleBase_PreferencesDlg(SUIT_ResourceMgr* theResurces, QWidget* theParent = 0);
137   virtual ~ModuleBase_PreferencesDlg();
138
139   /// Returns True if preferences were changed
140   bool isChanged() const
141   {
142     return myIsChanged;
143   }
144
145   /// Returns list of modified preferences
146   /// \param theModified output list of modified preferences
147   void modified(ModuleBase_Prefs& theModified) const;
148
149  public slots:
150    /// A slot called on Ok button press
151   virtual void accept();
152
153 protected slots:
154   /// A slot called on Default button press
155   void onDefault();
156
157  private:
158    /// Create editors for aplication properties
159    void createEditors();
160
161    /// Create a viewer page in dialog box
162    void createViewerPage(int thePageId);
163
164    /// Create menu properties page in the dialog box
165    void createMenuPage(int thePageId);
166
167   ModuleBase_PreferencesMgr* myPreferences;
168   bool myIsChanged;
169 };
170
171 #endif