]> SALOME platform Git repositories - modules/shaper.git/blob - src/ModuleBase/ModuleBase_Preferences.h
Salome HOME
b307a5e2451124cef8cd8a3e305fc6c95374e632
[modules/shaper.git] / src / ModuleBase / ModuleBase_Preferences.h
1 // File:        ModuleBase_Preferences.h
2 // Created:     07 Aug 2014
3 // Author:      Vitaly SMETANNIKOV
4
5 #ifndef ModuleBase_Preferences_H
6 #define ModuleBase_Preferences_H
7
8 #include "ModuleBase.h"
9 #include "ModuleBase_IPrefMgr.h"
10
11 #include <SUIT_PreferenceMgr.h>
12 #include <QDialog>
13
14 class SUIT_ResourceMgr;
15 class QWidget;
16
17 // Pair of values: section name, value name
18 typedef QPair<QString, QString> ModuleBase_Pref;
19 typedef QList<ModuleBase_Pref> ModuleBase_Prefs;
20
21 //***********************************************************************
22 /// Class for manipulation  with preferences in the application
23 class MODULEBASE_EXPORT ModuleBase_Preferences
24 {
25  public:
26   static const QString VIEWER_SECTION;
27   static const QString MENU_SECTION;
28
29   static bool editPreferences(ModuleBase_Prefs& theModified);
30
31   /// Returns currently installed resource manager
32   static SUIT_ResourceMgr* resourceMgr();
33
34   /// Sets a resource manager
35   /// It is used in case of necessity to define external resource manager (not NewGeom)
36   static void setResourceMgr(SUIT_ResourceMgr* theMgr) { myResourceMgr = theMgr; }
37
38   /// Updates Config_PropManager properties by module from SUIT_ResourceMgr
39   static void updateConfigByResources();
40
41   /// Updates SUIT_ResourceMgr values by Config_PropManager properties
42   /// \param theUpdateOnlyInvalid flag to update only invalid values, if it is false, all are updated
43   static void updateResourcesByConfig();
44
45   /// Set default values to the Config_PropManager properties
46   static void resetConfig();
47
48   /// Loads properties defined by module to Config_PropManager
49   static void loadCustomProps();
50
51   /// 
52   static void createEditContent(ModuleBase_IPrefMgr* thePref, int thePage);
53
54 private:
55   /// Creates content of preferences editing widget
56   static void createCustomPage(ModuleBase_IPrefMgr* thePref, int thePageId);
57
58   static SUIT_ResourceMgr* myResourceMgr;
59 };
60
61 //***********************************************************************
62 /// Manager of preferences
63 class MODULEBASE_EXPORT ModuleBase_PreferencesMgr : public SUIT_PreferenceMgr
64 {
65 Q_OBJECT
66  public:
67   ModuleBase_PreferencesMgr(QtxResourceMgr* theResource, QWidget* theParent)
68       : SUIT_PreferenceMgr(theResource, theParent)
69   {
70   }
71
72   virtual ~ModuleBase_PreferencesMgr()
73   {
74   }
75
76   ModuleBase_Prefs modified() const
77   {
78     return myModified;
79   }
80
81  protected:
82   virtual void changedResources(const ResourceMap& theMap);
83
84  private:
85   ModuleBase_Prefs myModified;
86 };
87
88 //***********************************************************************
89 /// Dialog box for preferences editing
90 class MODULEBASE_EXPORT ModuleBase_PreferencesDlg : public QDialog
91 {
92 Q_OBJECT
93  public:
94   ModuleBase_PreferencesDlg(SUIT_ResourceMgr* theResurces, QWidget* theParent = 0);
95   virtual ~ModuleBase_PreferencesDlg();
96
97   bool isChanged() const
98   {
99     return myIsChanged;
100   }
101
102   void modified(ModuleBase_Prefs& theModified) const;
103
104  public slots:
105   virtual void accept();
106
107 protected slots:
108   void onDefault();
109
110  private:
111    /// Create editors for aplication properties
112    void createEditors();
113
114    /// Create a viewer page in dialog box
115    void createViewerPage(int thePageId);
116    
117    /// Create menu properties page in the dialog box
118    void createMenuPage(int thePageId);
119
120   ModuleBase_PreferencesMgr* myPreferences;
121   bool myIsChanged;
122 };
123
124 #endif