Salome HOME
Add copyright header according to request of CEA from 06.06.2017
[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 email : webmaster.salome@opencascade.com<mailto: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   /// Shows a dialog box to edit preferences
51   /// \param theModified a list of modified preferences
52   static bool editPreferences(ModuleBase_Prefs& theModified);
53
54   /// Returns currently installed resource manager
55   static SUIT_ResourceMgr* resourceMgr();
56
57   /// Sets a resource manager
58   /// It is used in case of necessity to define external resource manager (not SHAPER)
59   /// \param theMgr resource manager
60   static void setResourceMgr(SUIT_ResourceMgr* theMgr) { myResourceMgr = theMgr; }
61
62   /// Updates Config_PropManager properties by module from SUIT_ResourceMgr
63   static void updateConfigByResources();
64
65   /// Loads properties defined by module to Config_PropManager
66   static void loadCustomProps();
67
68   /// Create editable content
69   /// \param thePref interface to preference manager
70   /// \param thePage an id of a page
71   static void createEditContent(ModuleBase_IPrefMgr* thePref, int thePage);
72
73   /// Retrieve preferences of resource manage to default state
74   static void resetResourcePreferences(SUIT_PreferenceMgr* thePref);
75
76   /// Retrieve preferences of config prop to default state
77   static void resetConfigPropPreferences(SUIT_PreferenceMgr* thePref);
78
79 private:
80   /// Updates SUIT_ResourceMgr values by Config_PropManager properties
81   static void updateResourcesByConfig();
82
83   /// Set default values to the Config_PropManager properties
84   static void resetConfig();
85
86   /// Creates content of preferences editing widget
87   static void createCustomPage(ModuleBase_IPrefMgr* thePref, int thePageId);
88
89   static SUIT_ResourceMgr* myResourceMgr;
90 };
91
92 //***********************************************************************
93 /// \ingroup GUI
94 /// Manager of preferences
95 class MODULEBASE_EXPORT ModuleBase_PreferencesMgr : public SUIT_PreferenceMgr
96 {
97 Q_OBJECT
98  public:
99    /// Constructor
100    /// \param theResource resource manager
101    /// \param theParent a paren widget
102   ModuleBase_PreferencesMgr(QtxResourceMgr* theResource, QWidget* theParent)
103       : SUIT_PreferenceMgr(theResource, theParent)
104   {
105   }
106
107   virtual ~ModuleBase_PreferencesMgr()
108   {
109   }
110
111   /// Returns True if preferences were modified
112   ModuleBase_Prefs modified() const
113   {
114     return myModified;
115   }
116
117  protected:
118    /// Store changed resource
119   virtual void changedResources(const ResourceMap& theMap);
120
121  private:
122   ModuleBase_Prefs myModified;
123 };
124
125 //***********************************************************************
126 /// \ingroup GUI
127 /// Dialog box for preferences editing
128 class MODULEBASE_EXPORT ModuleBase_PreferencesDlg : public QDialog
129 {
130 Q_OBJECT
131  public:
132    /// Constructor
133    /// \param theResurces resources manager
134    /// \param theParent a parent widget
135   ModuleBase_PreferencesDlg(SUIT_ResourceMgr* theResurces, QWidget* theParent = 0);
136   virtual ~ModuleBase_PreferencesDlg();
137
138   /// Returns True if preferences were changed
139   bool isChanged() const
140   {
141     return myIsChanged;
142   }
143
144   /// Returns list of modified preferences
145   /// \param theModified output list of modified preferences
146   void modified(ModuleBase_Prefs& theModified) const;
147
148  public slots:
149    /// A slot called on Ok button press
150   virtual void accept();
151
152 protected slots:
153   /// A slot called on Default button press
154   void onDefault();
155
156  private:
157    /// Create editors for aplication properties
158    void createEditors();
159
160    /// Create a viewer page in dialog box
161    void createViewerPage(int thePageId);
162
163    /// Create menu properties page in the dialog box
164    void createMenuPage(int thePageId);
165
166   ModuleBase_PreferencesMgr* myPreferences;
167   bool myIsChanged;
168 };
169
170 #endif