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