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 SHAPER)
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 /// Retrieve preferences of config prop to default state
64 static void resetConfigPropPreferences(SUIT_PreferenceMgr* thePref);
67 /// Updates SUIT_ResourceMgr values by Config_PropManager properties
68 static void updateResourcesByConfig();
70 /// Set default values to the Config_PropManager properties
71 static void resetConfig();
73 /// Creates content of preferences editing widget
74 static void createCustomPage(ModuleBase_IPrefMgr* thePref, int thePageId);
76 static SUIT_ResourceMgr* myResourceMgr;
79 //***********************************************************************
81 /// Manager of preferences
82 class MODULEBASE_EXPORT ModuleBase_PreferencesMgr : public SUIT_PreferenceMgr
87 /// \param theResource resource manager
88 /// \param theParent a paren widget
89 ModuleBase_PreferencesMgr(QtxResourceMgr* theResource, QWidget* theParent)
90 : SUIT_PreferenceMgr(theResource, theParent)
94 virtual ~ModuleBase_PreferencesMgr()
98 /// Returns True if preferences were modified
99 ModuleBase_Prefs modified() const
105 /// Store changed resource
106 virtual void changedResources(const ResourceMap& theMap);
109 ModuleBase_Prefs myModified;
112 //***********************************************************************
114 /// Dialog box for preferences editing
115 class MODULEBASE_EXPORT ModuleBase_PreferencesDlg : public QDialog
120 /// \param theResurces resources manager
121 /// \param theParent a parent widget
122 ModuleBase_PreferencesDlg(SUIT_ResourceMgr* theResurces, QWidget* theParent = 0);
123 virtual ~ModuleBase_PreferencesDlg();
125 /// Returns True if preferences were changed
126 bool isChanged() const
131 /// Returns list of modified preferences
132 /// \param theModified output list of modified preferences
133 void modified(ModuleBase_Prefs& theModified) const;
136 /// A slot called on Ok button press
137 virtual void accept();
140 /// A slot called on Default button press
144 /// Create editors for aplication properties
145 void createEditors();
147 /// Create a viewer page in dialog box
148 void createViewerPage(int thePageId);
150 /// Create menu properties page in the dialog box
151 void createMenuPage(int thePageId);
153 ModuleBase_PreferencesMgr* myPreferences;