Salome HOME
Replace NewGeom text to SHAPER
[modules/shaper.git] / src / ModuleBase / ModuleBase_Preferences.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        ModuleBase_Preferences.h
4 // Created:     07 Aug 2014
5 // Author:      Vitaly SMETANNIKOV
6
7 #ifndef ModuleBase_Preferences_H
8 #define ModuleBase_Preferences_H
9
10 #include "ModuleBase.h"
11 #include "ModuleBase_IPrefMgr.h"
12
13 #include <SUIT_PreferenceMgr.h>
14 #include <QDialog>
15
16 class SUIT_ResourceMgr;
17 class QWidget;
18
19 /// Pair of values: section name, value name
20 typedef QPair<QString, QString> ModuleBase_Pref;
21
22 /// List of preferences
23 typedef QList<ModuleBase_Pref> ModuleBase_Prefs;
24
25 //***********************************************************************
26 /// \ingroup GUI
27 /// Class for manipulation  with preferences in the application
28 class MODULEBASE_EXPORT ModuleBase_Preferences
29 {
30  public:
31    /// Name of preferences of viewer section
32   static const QString VIEWER_SECTION;
33
34    /// Name of preferences of menu section
35   static const QString MENU_SECTION;
36
37   /// Shows a dialog box to edit preferences
38   /// \param theModified a list of modified preferences
39   static bool editPreferences(ModuleBase_Prefs& theModified);
40
41   /// Returns currently installed resource manager
42   static SUIT_ResourceMgr* resourceMgr();
43
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; }
48
49   /// Updates Config_PropManager properties by module from SUIT_ResourceMgr
50   static void updateConfigByResources();
51
52   /// Loads properties defined by module to Config_PropManager
53   static void loadCustomProps();
54
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);
59
60   /// Retrieve preferences of resource manage to default state
61   static void resetResourcePreferences(SUIT_PreferenceMgr* thePref);
62
63   /// Retrieve preferences of config prop to default state
64   static void resetConfigPropPreferences(SUIT_PreferenceMgr* thePref);
65
66 private:
67   /// Updates SUIT_ResourceMgr values by Config_PropManager properties
68   static void updateResourcesByConfig();
69
70   /// Set default values to the Config_PropManager properties
71   static void resetConfig();
72
73   /// Creates content of preferences editing widget
74   static void createCustomPage(ModuleBase_IPrefMgr* thePref, int thePageId);
75
76   static SUIT_ResourceMgr* myResourceMgr;
77 };
78
79 //***********************************************************************
80 /// \ingroup GUI
81 /// Manager of preferences
82 class MODULEBASE_EXPORT ModuleBase_PreferencesMgr : public SUIT_PreferenceMgr
83 {
84 Q_OBJECT
85  public:
86    /// Constructor
87    /// \param theResource resource manager
88    /// \param theParent a paren widget
89   ModuleBase_PreferencesMgr(QtxResourceMgr* theResource, QWidget* theParent)
90       : SUIT_PreferenceMgr(theResource, theParent)
91   {
92   }
93
94   virtual ~ModuleBase_PreferencesMgr()
95   {
96   }
97
98   /// Returns True if preferences were modified
99   ModuleBase_Prefs modified() const
100   {
101     return myModified;
102   }
103
104  protected:
105    /// Store changed resource
106   virtual void changedResources(const ResourceMap& theMap);
107
108  private:
109   ModuleBase_Prefs myModified;
110 };
111
112 //***********************************************************************
113 /// \ingroup GUI
114 /// Dialog box for preferences editing
115 class MODULEBASE_EXPORT ModuleBase_PreferencesDlg : public QDialog
116 {
117 Q_OBJECT
118  public:
119    /// Constructor
120    /// \param theResurces resources manager
121    /// \param theParent a parent widget
122   ModuleBase_PreferencesDlg(SUIT_ResourceMgr* theResurces, QWidget* theParent = 0);
123   virtual ~ModuleBase_PreferencesDlg();
124
125   /// Returns True if preferences were changed
126   bool isChanged() const
127   {
128     return myIsChanged;
129   }
130
131   /// Returns list of modified preferences
132   /// \param theModified output list of modified preferences
133   void modified(ModuleBase_Prefs& theModified) const;
134
135  public slots:
136    /// A slot called on Ok button press
137   virtual void accept();
138
139 protected slots:
140   /// A slot called on Default button press
141   void onDefault();
142
143  private:
144    /// Create editors for aplication properties
145    void createEditors();
146
147    /// Create a viewer page in dialog box
148    void createViewerPage(int thePageId);
149    
150    /// Create menu properties page in the dialog box
151    void createMenuPage(int thePageId);
152
153   ModuleBase_PreferencesMgr* myPreferences;
154   bool myIsChanged;
155 };
156
157 #endif