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 /// Updates SUIT_ResourceMgr values by Config_PropManager properties
53 static void updateResourcesByConfig();
55 /// Set default values to the Config_PropManager properties
56 static void resetConfig();
58 /// Loads properties defined by module to Config_PropManager
59 static void loadCustomProps();
61 /// Create editable content
62 /// \param thePref interface to preference manager
63 /// \param thePage an id of a page
64 static void createEditContent(ModuleBase_IPrefMgr* thePref, int thePage);
67 /// Creates content of preferences editing widget
68 static void createCustomPage(ModuleBase_IPrefMgr* thePref, int thePageId);
70 static SUIT_ResourceMgr* myResourceMgr;
73 //***********************************************************************
75 /// Manager of preferences
76 class MODULEBASE_EXPORT ModuleBase_PreferencesMgr : public SUIT_PreferenceMgr
81 /// \param theResource resource manager
82 /// \param theParent a paren widget
83 ModuleBase_PreferencesMgr(QtxResourceMgr* theResource, QWidget* theParent)
84 : SUIT_PreferenceMgr(theResource, theParent)
88 virtual ~ModuleBase_PreferencesMgr()
92 /// Returns True if preferences were modified
93 ModuleBase_Prefs modified() const
99 /// Store changed resource
100 virtual void changedResources(const ResourceMap& theMap);
103 ModuleBase_Prefs myModified;
106 //***********************************************************************
108 /// Dialog box for preferences editing
109 class MODULEBASE_EXPORT ModuleBase_PreferencesDlg : public QDialog
114 /// \param theResurces resources manager
115 /// \param theParent a parent widget
116 ModuleBase_PreferencesDlg(SUIT_ResourceMgr* theResurces, QWidget* theParent = 0);
117 virtual ~ModuleBase_PreferencesDlg();
119 /// Returns True if preferences were changed
120 bool isChanged() const
125 /// Returns list of modified preferences
126 /// \param theModified output list of modified preferences
127 void modified(ModuleBase_Prefs& theModified) const;
130 /// A slot called on Ok button press
131 virtual void accept();
134 /// A slot called on Default button press
138 /// Create editors for aplication properties
139 void createEditors();
141 /// Create a viewer page in dialog box
142 void createViewerPage(int thePageId);
144 /// Create menu properties page in the dialog box
145 void createMenuPage(int thePageId);
147 ModuleBase_PreferencesMgr* myPreferences;