Salome HOME
Merge branch 'Dev_0.7.1' of newgeom:newgeom into Dev_0.7.1
[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 /// Class for manipulation  with preferences in the application
27 class MODULEBASE_EXPORT ModuleBase_Preferences
28 {
29  public:
30    /// Name of preferences of viewer section
31   static const QString VIEWER_SECTION;
32
33    /// Name of preferences of menu section
34   static const QString MENU_SECTION;
35
36   /// Shows a dialog box to edit preferences
37   /// \param theModified a list of modified preferences
38   static bool editPreferences(ModuleBase_Prefs& theModified);
39
40   /// Returns currently installed resource manager
41   static SUIT_ResourceMgr* resourceMgr();
42
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; }
47
48   /// Updates Config_PropManager properties by module from SUIT_ResourceMgr
49   static void updateConfigByResources();
50
51   /// Updates SUIT_ResourceMgr values by Config_PropManager properties
52   static void updateResourcesByConfig();
53
54   /// Set default values to the Config_PropManager properties
55   static void resetConfig();
56
57   /// Loads properties defined by module to Config_PropManager
58   static void loadCustomProps();
59
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);
64
65 private:
66   /// Creates content of preferences editing widget
67   static void createCustomPage(ModuleBase_IPrefMgr* thePref, int thePageId);
68
69   static SUIT_ResourceMgr* myResourceMgr;
70 };
71
72 //***********************************************************************
73 /// Manager of preferences
74 class MODULEBASE_EXPORT ModuleBase_PreferencesMgr : public SUIT_PreferenceMgr
75 {
76 Q_OBJECT
77  public:
78    /// Constructor
79    /// \param theResource resource manager
80    /// \param theParent a paren widget
81   ModuleBase_PreferencesMgr(QtxResourceMgr* theResource, QWidget* theParent)
82       : SUIT_PreferenceMgr(theResource, theParent)
83   {
84   }
85
86   virtual ~ModuleBase_PreferencesMgr()
87   {
88   }
89
90   /// Returns True if preferences were modified
91   ModuleBase_Prefs modified() const
92   {
93     return myModified;
94   }
95
96  protected:
97    /// Store changed resource
98   virtual void changedResources(const ResourceMap& theMap);
99
100  private:
101   ModuleBase_Prefs myModified;
102 };
103
104 //***********************************************************************
105 /// Dialog box for preferences editing
106 class MODULEBASE_EXPORT ModuleBase_PreferencesDlg : public QDialog
107 {
108 Q_OBJECT
109  public:
110    /// Constructor
111    /// \param theResurces resources manager
112    /// \param theParent a parent widget
113   ModuleBase_PreferencesDlg(SUIT_ResourceMgr* theResurces, QWidget* theParent = 0);
114   virtual ~ModuleBase_PreferencesDlg();
115
116   /// Returns True if preferences were changed
117   bool isChanged() const
118   {
119     return myIsChanged;
120   }
121
122   /// Returns list of modified preferences
123   /// \param theModified output list of modified preferences
124   void modified(ModuleBase_Prefs& theModified) const;
125
126  public slots:
127    /// A slot called on Ok button press
128   virtual void accept();
129
130 protected slots:
131   /// A slot called on Default button press
132   void onDefault();
133
134  private:
135    /// Create editors for aplication properties
136    void createEditors();
137
138    /// Create a viewer page in dialog box
139    void createViewerPage(int thePageId);
140    
141    /// Create menu properties page in the dialog box
142    void createMenuPage(int thePageId);
143
144   ModuleBase_PreferencesMgr* myPreferences;
145   bool myIsChanged;
146 };
147
148 #endif