Salome HOME
Join modifications from branch BR_DEBUG_3_2_0b1
[modules/gui.git] / src / Qtx / QtxResourceEdit.h
1 // Copyright (C) 2005  OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
2 // 
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either 
6 // version 2.1 of the License.
7 // 
8 // This library is distributed in the hope that it will be useful 
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public  
14 // License along with this library; if not, write to the Free Software 
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 // File:      QtxResourceEdit.h
20 // Author:    Sergey TELKOV
21
22 #ifndef QTXRESOURCEEDIT_H
23 #define QTXRESOURCEEDIT_H
24
25 #ifdef WIN32
26 #pragma warning( disable:4251 )
27 #endif
28
29 #include "Qtx.h"
30
31 class QString;
32 class QtxResourceMgr;
33
34 #include <qcolor.h>
35 #include <qvariant.h>
36 #include <qfont.h>
37
38 /*!
39   \class QtxResourceEdit
40   Class for managing preferences items
41 */
42 class QTX_EXPORT QtxResourceEdit
43 {
44 public:
45   class Item;
46
47 public:
48   QtxResourceEdit( QtxResourceMgr* );
49   virtual ~QtxResourceEdit();
50
51   QtxResourceMgr*      resourceMgr() const;
52
53   virtual int          addItem( const QString& label, const int pId = -1, const int = -1,
54                                 const QString& section = QString::null,
55                                 const QString& param = QString::null );
56
57   QVariant             itemProperty( const int, const QString& ) const;
58   virtual void         setItemProperty( const int, const QString&, const QVariant& );
59
60   void                 resource( const int, QString&, QString& ) const;
61
62   virtual void         store();
63   virtual void         retrieve();
64
65   virtual void         update();
66
67   virtual void         toBackup();
68   virtual void         fromBackup();
69
70 protected:
71   Item*                item( const int ) const;
72   Item*                item( const QString& ) const;
73   Item*                item( const QString&, const int ) const;
74
75   virtual Item*        createItem( const QString&, const int ) = 0;
76
77   void                 resourceValues( QMap<int, QString>& ) const;
78   void                 resourceValues( QMap<Item*, QString>& ) const;
79
80   void                 setResourceValues( QMap<int, QString>& ) const;
81   void                 setResourceValues( QMap<Item*, QString>& ) const;
82   
83   void                 differentValues( const QMap<int, QString>&, const QMap<int, QString>&,
84                                         QMap<int, QString>&, const bool fromFirst = false ) const;
85   void                 differentValues( const QMap<Item*, QString>&, const QMap<Item*, QString>&,
86                                         QMap<Item*, QString>&, const bool fromFirst = false ) const;
87
88   virtual void         changedResources( const QMap<Item*, QString>& );
89
90   virtual void         itemAdded( Item* );
91   virtual void         itemRemoved( Item* );
92
93   void                 childItems( QPtrList<Item>& ) const;
94
95 private:
96   void                 removeItem( Item* );
97   Item*                createItem( const QString&, const int, const int );
98
99 private:
100   typedef QMap<int, Item*> ItemMap;
101
102 private:
103   ItemMap              myItems;
104   QtxResourceMgr*      myResMgr;
105   QMap<Item*, QString> myBackup;
106   QPtrList<Item>       myChildren;
107
108   friend class QtxResourceEdit::Item;
109 };
110
111 /*!
112   \class QtxResourceEditor::Item
113   Class for incapsulation of one preference item
114 */
115
116 class QTX_EXPORT QtxResourceEdit::Item
117 {
118 public:
119   Item( QtxResourceEdit*, Item* = 0 );
120   virtual ~Item();
121
122   int                  id() const;
123   virtual int          type() const = 0;
124
125   Item*                parentItem() const;
126   void                 childItems( QPtrList<Item>& ) const;
127
128   virtual bool         isEmpty() const;
129
130   QString              title() const;
131   void                 resource( QString&, QString& ) const;
132
133   virtual void         setTitle( const QString& );
134   virtual void         setResource( const QString&, const QString& );
135
136   virtual void         update();
137
138   QVariant             property( const QString& ) const;
139   virtual void         setProperty( const QString&, const QVariant& );
140
141   virtual void         store() = 0;
142   virtual void         retrieve() = 0;
143
144   virtual Item*        createItem( const QString&, const int ) = 0;
145
146   QString              resourceValue() const;
147   void                 setResourceValue( const QString& );
148
149   virtual void         insertChild( Item* );
150   virtual void         removeChild( Item* );
151
152 protected:
153   QtxResourceMgr*      resourceMgr() const;
154   QtxResourceEdit*     resourceEdit() const;
155
156   int                  getInteger( const int = 0 ) const;
157   double               getDouble( const double = 0.0 ) const;
158   bool                 getBoolean( const bool = false ) const;
159   QColor               getColor( const QColor& = QColor() ) const;
160   QFont                getFont( const QFont& = QFont() ) const;
161   QString              getString( const QString& = QString::null ) const;
162
163   void                 setInteger( const int );
164   void                 setDouble( const double );
165   void                 setBoolean( const bool );
166   void                 setColor( const QColor& );
167   void                 setFont( const QFont& );  
168   void                 setString( const QString& );
169
170   Item*                item( const int ) const;
171   Item*                item( const QString& ) const;
172   Item*                item( const QString&, const int ) const;
173
174 protected:
175   typedef QPtrList<Item>         ItemList;
176   typedef QPtrListIterator<Item> ItemListIterator;
177
178 private:
179   static int           generateId();
180
181 private:
182   int                  myId;
183   Item*                myParent;
184   ItemList             myChildren;
185
186   QString              myTitle;
187   QString              myResSection;
188   QString              myResParameter;
189
190   QtxResourceEdit*     myEdit;
191 };
192
193 #ifdef WIN32
194 #pragma warning( default:4251 )
195 #endif
196
197 #endif