1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #ifndef ModuleBase_Preferences_H
22 #define ModuleBase_Preferences_H
24 #include "ModuleBase.h"
25 #include "ModuleBase_IPrefMgr.h"
27 #include <SUIT_PreferenceMgr.h>
30 class SUIT_ResourceMgr;
33 /// Pair of values: section name, value name
34 typedef QPair<QString, QString> ModuleBase_Pref;
36 /// List of preferences
37 typedef QList<ModuleBase_Pref> ModuleBase_Prefs;
39 //***********************************************************************
41 /// Class for manipulation with preferences in the application
42 class MODULEBASE_EXPORT ModuleBase_Preferences
45 /// Name of preferences of viewer section
46 static const QString VIEWER_SECTION;
48 /// Name of preferences of menu section
49 static const QString MENU_SECTION;
51 /// Shows a dialog box to edit preferences
52 /// \param theModified a list of modified preferences
53 static bool editPreferences(ModuleBase_Prefs& theModified);
55 /// Returns currently installed resource manager
56 static SUIT_ResourceMgr* resourceMgr();
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; }
63 /// Updates Config_PropManager properties by module from SUIT_ResourceMgr
64 static void updateConfigByResources();
66 /// Loads properties defined by module to Config_PropManager
67 static void loadCustomProps();
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);
74 /// Retrieve preferences of resource manage to default state
75 static void resetResourcePreferences(SUIT_PreferenceMgr* thePref);
77 /// Retrieve preferences of config prop to default state
78 static void resetConfigPropPreferences(SUIT_PreferenceMgr* thePref);
81 /// Updates SUIT_ResourceMgr values by Config_PropManager properties
82 static void updateResourcesByConfig();
84 /// Set default values to the Config_PropManager properties
85 static void resetConfig();
87 /// Creates content of preferences editing widget
88 static void createCustomPage(ModuleBase_IPrefMgr* thePref, int thePageId);
90 static SUIT_ResourceMgr* myResourceMgr;
93 //***********************************************************************
95 /// Manager of preferences
96 class MODULEBASE_EXPORT ModuleBase_PreferencesMgr : public SUIT_PreferenceMgr
101 /// \param theResource resource manager
102 /// \param theParent a paren widget
103 ModuleBase_PreferencesMgr(QtxResourceMgr* theResource, QWidget* theParent)
104 : SUIT_PreferenceMgr(theResource, theParent)
108 virtual ~ModuleBase_PreferencesMgr()
112 /// Returns True if preferences were modified
113 ModuleBase_Prefs modified() const
119 /// Store changed resource
120 virtual void changedResources(const ResourceMap& theMap);
123 ModuleBase_Prefs myModified;
126 //***********************************************************************
128 /// Dialog box for preferences editing
129 class MODULEBASE_EXPORT ModuleBase_PreferencesDlg : public QDialog
134 /// \param theResurces resources manager
135 /// \param theParent a parent widget
136 ModuleBase_PreferencesDlg(SUIT_ResourceMgr* theResurces, QWidget* theParent = 0);
137 virtual ~ModuleBase_PreferencesDlg();
139 /// Returns True if preferences were changed
140 bool isChanged() const
145 /// Returns list of modified preferences
146 /// \param theModified output list of modified preferences
147 void modified(ModuleBase_Prefs& theModified) const;
150 /// A slot called on Ok button press
151 virtual void accept();
154 /// A slot called on Default button press
158 /// Create editors for aplication properties
159 void createEditors();
161 /// Create a viewer page in dialog box
162 void createViewerPage(int thePageId);
164 /// Create menu properties page in the dialog box
165 void createMenuPage(int thePageId);
167 ModuleBase_PreferencesMgr* myPreferences;