1 // Copyright (C) 2014-2021 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 /// Name of preferences of general section
51 static const QString GENERAL_SECTION;
53 /// Shows a dialog box to edit preferences
54 /// \param theModified a list of modified preferences
55 static bool editPreferences(ModuleBase_Prefs& theModified);
57 /// Returns currently installed resource manager
58 static SUIT_ResourceMgr* resourceMgr();
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; }
65 /// Updates Config_PropManager properties by module from SUIT_ResourceMgr
66 static void updateConfigByResources();
68 /// Loads properties defined by module to Config_PropManager
69 static void loadCustomProps();
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);
76 /// Retrieve preferences of resource manage to default state
77 static void resetResourcePreferences(SUIT_PreferenceMgr* thePref);
79 /// Retrieve preferences of config prop to default state
80 static void resetConfigPropPreferences(SUIT_PreferenceMgr* thePref);
83 /// Updates SUIT_ResourceMgr values by Config_PropManager properties
84 static void updateResourcesByConfig();
86 /// Set default values to the Config_PropManager properties
87 static void resetConfig();
89 /// Creates a content for General tab, which defines behavior of loading parts and displaying shapes
90 static void createGeneralTab(ModuleBase_IPrefMgr* thePref, int thePageId);
92 /// Creates content of preferences editing widget
93 static void createCustomPage(ModuleBase_IPrefMgr* thePref, int thePageId);
95 static SUIT_ResourceMgr* myResourceMgr;
98 //***********************************************************************
100 /// Manager of preferences
101 class MODULEBASE_EXPORT ModuleBase_PreferencesMgr : public SUIT_PreferenceMgr
106 /// \param theResource resource manager
107 /// \param theParent a paren widget
108 ModuleBase_PreferencesMgr(QtxResourceMgr* theResource, QWidget* theParent)
109 : SUIT_PreferenceMgr(theResource, theParent)
113 virtual ~ModuleBase_PreferencesMgr()
117 /// Returns True if preferences were modified
118 ModuleBase_Prefs modified() const
124 /// Store changed resource
125 virtual void changedResources(const ResourceMap& theMap);
128 ModuleBase_Prefs myModified;
131 //***********************************************************************
133 /// Dialog box for preferences editing
134 class MODULEBASE_EXPORT ModuleBase_PreferencesDlg : public QDialog
139 /// \param theResurces resources manager
140 /// \param theParent a parent widget
141 ModuleBase_PreferencesDlg(SUIT_ResourceMgr* theResurces, QWidget* theParent = 0);
142 virtual ~ModuleBase_PreferencesDlg();
144 /// Returns True if preferences were changed
145 bool isChanged() const
150 /// Returns list of modified preferences
151 /// \param theModified output list of modified preferences
152 void modified(ModuleBase_Prefs& theModified) const;
155 /// A slot called on Ok button press
156 virtual void accept();
159 virtual void showEvent(QShowEvent* theEvent);
162 /// A slot called on Default button press
166 /// Create editors for aplication properties
167 void createEditors();
169 /// Create a viewer page in dialog box
170 void createViewerPage(int thePageId);
172 /// Create menu properties page in the dialog box
173 void createMenuPage(int thePageId);
175 ModuleBase_PreferencesMgr* myPreferences;