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