1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: ModuleBase_Preferences.h
4 // Created: 07 Aug 2014
5 // Author: Vitaly SMETANNIKOV
7 #ifndef ModuleBase_Preferences_H
8 #define ModuleBase_Preferences_H
10 #include "ModuleBase.h"
11 #include "ModuleBase_IPrefMgr.h"
13 #include <SUIT_PreferenceMgr.h>
16 class SUIT_ResourceMgr;
19 /// Pair of values: section name, value name
20 typedef QPair<QString, QString> ModuleBase_Pref;
22 /// List of preferences
23 typedef QList<ModuleBase_Pref> ModuleBase_Prefs;
25 //***********************************************************************
27 /// Class for manipulation with preferences in the application
28 class MODULEBASE_EXPORT ModuleBase_Preferences
31 /// Name of preferences of viewer section
32 static const QString VIEWER_SECTION;
34 /// Name of preferences of menu section
35 static const QString MENU_SECTION;
37 /// Shows a dialog box to edit preferences
38 /// \param theModified a list of modified preferences
39 static bool editPreferences(ModuleBase_Prefs& theModified);
41 /// Returns currently installed resource manager
42 static SUIT_ResourceMgr* resourceMgr();
44 /// Sets a resource manager
45 /// It is used in case of necessity to define external resource manager (not NewGeom)
46 /// \param theMgr resource manager
47 static void setResourceMgr(SUIT_ResourceMgr* theMgr) { myResourceMgr = theMgr; }
49 /// Updates Config_PropManager properties by module from SUIT_ResourceMgr
50 static void updateConfigByResources();
52 /// Loads properties defined by module to Config_PropManager
53 static void loadCustomProps();
55 /// Create editable content
56 /// \param thePref interface to preference manager
57 /// \param thePage an id of a page
58 static void createEditContent(ModuleBase_IPrefMgr* thePref, int thePage);
60 /// Retrieve preferences of resource manage to default state
61 static void resetResourcePreferences(SUIT_PreferenceMgr* thePref);
63 static void resetConfigPropPreferences(SUIT_PreferenceMgr* thePref);
66 /// Updates SUIT_ResourceMgr values by Config_PropManager properties
67 static void updateResourcesByConfig();
69 /// Set default values to the Config_PropManager properties
70 static void resetConfig();
72 /// Creates content of preferences editing widget
73 static void createCustomPage(ModuleBase_IPrefMgr* thePref, int thePageId);
75 static SUIT_ResourceMgr* myResourceMgr;
78 //***********************************************************************
80 /// Manager of preferences
81 class MODULEBASE_EXPORT ModuleBase_PreferencesMgr : public SUIT_PreferenceMgr
86 /// \param theResource resource manager
87 /// \param theParent a paren widget
88 ModuleBase_PreferencesMgr(QtxResourceMgr* theResource, QWidget* theParent)
89 : SUIT_PreferenceMgr(theResource, theParent)
93 virtual ~ModuleBase_PreferencesMgr()
97 /// Returns True if preferences were modified
98 ModuleBase_Prefs modified() const
104 /// Store changed resource
105 virtual void changedResources(const ResourceMap& theMap);
108 ModuleBase_Prefs myModified;
111 //***********************************************************************
113 /// Dialog box for preferences editing
114 class MODULEBASE_EXPORT ModuleBase_PreferencesDlg : public QDialog
119 /// \param theResurces resources manager
120 /// \param theParent a parent widget
121 ModuleBase_PreferencesDlg(SUIT_ResourceMgr* theResurces, QWidget* theParent = 0);
122 virtual ~ModuleBase_PreferencesDlg();
124 /// Returns True if preferences were changed
125 bool isChanged() const
130 /// Returns list of modified preferences
131 /// \param theModified output list of modified preferences
132 void modified(ModuleBase_Prefs& theModified) const;
135 /// A slot called on Ok button press
136 virtual void accept();
139 /// A slot called on Default button press
143 /// Create editors for aplication properties
144 void createEditors();
146 /// Create a viewer page in dialog box
147 void createViewerPage(int thePageId);
149 /// Create menu properties page in the dialog box
150 void createMenuPage(int thePageId);
152 ModuleBase_PreferencesMgr* myPreferences;