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 //***********************************************************************
26 /// Class for manipulation with preferences in the application
27 class MODULEBASE_EXPORT ModuleBase_Preferences
30 /// Name of preferences of viewer section
31 static const QString VIEWER_SECTION;
33 /// Name of preferences of menu section
34 static const QString MENU_SECTION;
36 /// Shows a dialog box to edit preferences
37 /// \param theModified a list of modified preferences
38 static bool editPreferences(ModuleBase_Prefs& theModified);
40 /// Returns currently installed resource manager
41 static SUIT_ResourceMgr* resourceMgr();
43 /// Sets a resource manager
44 /// It is used in case of necessity to define external resource manager (not NewGeom)
45 /// \param theMgr resource manager
46 static void setResourceMgr(SUIT_ResourceMgr* theMgr) { myResourceMgr = theMgr; }
48 /// Updates Config_PropManager properties by module from SUIT_ResourceMgr
49 static void updateConfigByResources();
51 /// Updates SUIT_ResourceMgr values by Config_PropManager properties
52 static void updateResourcesByConfig();
54 /// Set default values to the Config_PropManager properties
55 static void resetConfig();
57 /// Loads properties defined by module to Config_PropManager
58 static void loadCustomProps();
60 /// Create editable content
61 /// \param thePref interface to preference manager
62 /// \param thePage an id of a page
63 static void createEditContent(ModuleBase_IPrefMgr* thePref, int thePage);
66 /// Creates content of preferences editing widget
67 static void createCustomPage(ModuleBase_IPrefMgr* thePref, int thePageId);
69 static SUIT_ResourceMgr* myResourceMgr;
72 //***********************************************************************
73 /// Manager of preferences
74 class MODULEBASE_EXPORT ModuleBase_PreferencesMgr : public SUIT_PreferenceMgr
79 /// \param theResource resource manager
80 /// \param theParent a paren widget
81 ModuleBase_PreferencesMgr(QtxResourceMgr* theResource, QWidget* theParent)
82 : SUIT_PreferenceMgr(theResource, theParent)
86 virtual ~ModuleBase_PreferencesMgr()
90 /// Returns True if preferences were modified
91 ModuleBase_Prefs modified() const
97 /// Store changed resource
98 virtual void changedResources(const ResourceMap& theMap);
101 ModuleBase_Prefs myModified;
104 //***********************************************************************
105 /// Dialog box for preferences editing
106 class MODULEBASE_EXPORT ModuleBase_PreferencesDlg : public QDialog
111 /// \param theResurces resources manager
112 /// \param theParent a parent widget
113 ModuleBase_PreferencesDlg(SUIT_ResourceMgr* theResurces, QWidget* theParent = 0);
114 virtual ~ModuleBase_PreferencesDlg();
116 /// Returns True if preferences were changed
117 bool isChanged() const
122 /// Returns list of modified preferences
123 /// \param theModified output list of modified preferences
124 void modified(ModuleBase_Prefs& theModified) const;
127 /// A slot called on Ok button press
128 virtual void accept();
131 /// A slot called on Default button press
135 /// Create editors for aplication properties
136 void createEditors();
138 /// Create a viewer page in dialog box
139 void createViewerPage(int thePageId);
141 /// Create menu properties page in the dialog box
142 void createMenuPage(int thePageId);
144 ModuleBase_PreferencesMgr* myPreferences;