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