1 // Copyright (C) 2014-2019 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 email : webmaster.salome@opencascade.com
20 #ifndef ModuleBase_Preferences_H
21 #define ModuleBase_Preferences_H
23 #include "ModuleBase.h"
24 #include "ModuleBase_IPrefMgr.h"
26 #include <SUIT_PreferenceMgr.h>
29 class SUIT_ResourceMgr;
32 /// Pair of values: section name, value name
33 typedef QPair<QString, QString> ModuleBase_Pref;
35 /// List of preferences
36 typedef QList<ModuleBase_Pref> ModuleBase_Prefs;
38 //***********************************************************************
40 /// Class for manipulation with preferences in the application
41 class MODULEBASE_EXPORT ModuleBase_Preferences
44 /// Name of preferences of viewer section
45 static const QString VIEWER_SECTION;
47 /// Name of preferences of menu section
48 static const QString MENU_SECTION;
50 /// Shows a dialog box to edit preferences
51 /// \param theModified a list of modified preferences
52 static bool editPreferences(ModuleBase_Prefs& theModified);
54 /// Returns currently installed resource manager
55 static SUIT_ResourceMgr* resourceMgr();
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; }
62 /// Updates Config_PropManager properties by module from SUIT_ResourceMgr
63 static void updateConfigByResources();
65 /// Loads properties defined by module to Config_PropManager
66 static void loadCustomProps();
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);
73 /// Retrieve preferences of resource manage to default state
74 static void resetResourcePreferences(SUIT_PreferenceMgr* thePref);
76 /// Retrieve preferences of config prop to default state
77 static void resetConfigPropPreferences(SUIT_PreferenceMgr* thePref);
80 /// Updates SUIT_ResourceMgr values by Config_PropManager properties
81 static void updateResourcesByConfig();
83 /// Set default values to the Config_PropManager properties
84 static void resetConfig();
86 /// Creates content of preferences editing widget
87 static void createCustomPage(ModuleBase_IPrefMgr* thePref, int thePageId);
89 static SUIT_ResourceMgr* myResourceMgr;
92 //***********************************************************************
94 /// Manager of preferences
95 class MODULEBASE_EXPORT ModuleBase_PreferencesMgr : public SUIT_PreferenceMgr
100 /// \param theResource resource manager
101 /// \param theParent a paren widget
102 ModuleBase_PreferencesMgr(QtxResourceMgr* theResource, QWidget* theParent)
103 : SUIT_PreferenceMgr(theResource, theParent)
107 virtual ~ModuleBase_PreferencesMgr()
111 /// Returns True if preferences were modified
112 ModuleBase_Prefs modified() const
118 /// Store changed resource
119 virtual void changedResources(const ResourceMap& theMap);
122 ModuleBase_Prefs myModified;
125 //***********************************************************************
127 /// Dialog box for preferences editing
128 class MODULEBASE_EXPORT ModuleBase_PreferencesDlg : public QDialog
133 /// \param theResurces resources manager
134 /// \param theParent a parent widget
135 ModuleBase_PreferencesDlg(SUIT_ResourceMgr* theResurces, QWidget* theParent = 0);
136 virtual ~ModuleBase_PreferencesDlg();
138 /// Returns True if preferences were changed
139 bool isChanged() const
144 /// Returns list of modified preferences
145 /// \param theModified output list of modified preferences
146 void modified(ModuleBase_Prefs& theModified) const;
149 /// A slot called on Ok button press
150 virtual void accept();
153 /// A slot called on Default button press
157 /// Create editors for aplication properties
158 void createEditors();
160 /// Create a viewer page in dialog box
161 void createViewerPage(int thePageId);
163 /// Create menu properties page in the dialog box
164 void createMenuPage(int thePageId);
166 ModuleBase_PreferencesMgr* myPreferences;