Salome HOME
Start of the edit should not change the current feature.
[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 NewGeom)
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   static void resetConfigPropPreferences(SUIT_PreferenceMgr* thePref);
64
65 private:
66   /// Updates SUIT_ResourceMgr values by Config_PropManager properties
67   static void updateResourcesByConfig();
68
69   /// Set default values to the Config_PropManager properties
70   static void resetConfig();
71
72   /// Creates content of preferences editing widget
73   static void createCustomPage(ModuleBase_IPrefMgr* thePref, int thePageId);
74
75   static SUIT_ResourceMgr* myResourceMgr;
76 };
77
78 //***********************************************************************
79 /// \ingroup GUI
80 /// Manager of preferences
81 class MODULEBASE_EXPORT ModuleBase_PreferencesMgr : public SUIT_PreferenceMgr
82 {
83 Q_OBJECT
84  public:
85    /// Constructor
86    /// \param theResource resource manager
87    /// \param theParent a paren widget
88   ModuleBase_PreferencesMgr(QtxResourceMgr* theResource, QWidget* theParent)
89       : SUIT_PreferenceMgr(theResource, theParent)
90   {
91   }
92
93   virtual ~ModuleBase_PreferencesMgr()
94   {
95   }
96
97   /// Returns True if preferences were modified
98   ModuleBase_Prefs modified() const
99   {
100     return myModified;
101   }
102
103  protected:
104    /// Store changed resource
105   virtual void changedResources(const ResourceMap& theMap);
106
107  private:
108   ModuleBase_Prefs myModified;
109 };
110
111 //***********************************************************************
112 /// \ingroup GUI
113 /// Dialog box for preferences editing
114 class MODULEBASE_EXPORT ModuleBase_PreferencesDlg : public QDialog
115 {
116 Q_OBJECT
117  public:
118    /// Constructor
119    /// \param theResurces resources manager
120    /// \param theParent a parent widget
121   ModuleBase_PreferencesDlg(SUIT_ResourceMgr* theResurces, QWidget* theParent = 0);
122   virtual ~ModuleBase_PreferencesDlg();
123
124   /// Returns True if preferences were changed
125   bool isChanged() const
126   {
127     return myIsChanged;
128   }
129
130   /// Returns list of modified preferences
131   /// \param theModified output list of modified preferences
132   void modified(ModuleBase_Prefs& theModified) const;
133
134  public slots:
135    /// A slot called on Ok button press
136   virtual void accept();
137
138 protected slots:
139   /// A slot called on Default button press
140   void onDefault();
141
142  private:
143    /// Create editors for aplication properties
144    void createEditors();
145
146    /// Create a viewer page in dialog box
147    void createViewerPage(int thePageId);
148    
149    /// Create menu properties page in the dialog box
150    void createMenuPage(int thePageId);
151
152   ModuleBase_PreferencesMgr* myPreferences;
153   bool myIsChanged;
154 };
155
156 #endif