Salome HOME
Copyrights update
[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/
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 class QTX_EXPORT QtxResourceEdit
39 {
40 public:
41   class Item;
42
43 public:
44   QtxResourceEdit( QtxResourceMgr* );
45   virtual ~QtxResourceEdit();
46
47   QtxResourceMgr*      resourceMgr() const;
48
49   virtual int          addItem( const QString& label, const int pId = -1, const int = -1,
50                                 const QString& section = QString::null,
51                                 const QString& param = QString::null );
52
53   QVariant             itemProperty( const int, const QString& ) const;
54   virtual void         setItemProperty( const int, const QString&, const QVariant& );
55
56   void                 resource( const int, QString&, QString& ) const;
57
58   virtual void         store();
59   virtual void         retrieve();
60
61   virtual void         update();
62
63   virtual void         toBackup();
64   virtual void         fromBackup();
65
66 protected:
67   Item*                item( const int ) const;
68   Item*                item( const QString& ) const;
69   Item*                item( const QString&, const int ) const;
70
71   virtual Item*        createItem( const QString&, const int ) = 0;
72
73   void                 resourceValues( QMap<int, QString>& ) const;
74   void                 resourceValues( QMap<Item*, QString>& ) const;
75
76   void                 setResourceValues( QMap<int, QString>& ) const;
77   void                 setResourceValues( QMap<Item*, QString>& ) const;
78   
79   void                 differentValues( const QMap<int, QString>&, const QMap<int, QString>&,
80                                         QMap<int, QString>&, const bool fromFirst = false ) const;
81   void                 differentValues( const QMap<Item*, QString>&, const QMap<Item*, QString>&,
82                                         QMap<Item*, QString>&, const bool fromFirst = false ) const;
83
84   virtual void         changedResources( const QMap<Item*, QString>& );
85
86   virtual void         itemAdded( Item* );
87   virtual void         itemRemoved( Item* );
88
89   void                 childItems( QPtrList<Item>& ) const;
90
91 private:
92   void                 removeItem( Item* );
93   Item*                createItem( const QString&, const int, const int );
94
95 private:
96   typedef QMap<int, Item*> ItemMap;
97
98 private:
99   ItemMap              myItems;
100   QtxResourceMgr*      myResMgr;
101   QMap<Item*, QString> myBackup;
102   QPtrList<Item>       myChildren;
103
104   friend class QtxResourceEdit::Item;
105 };
106
107 /*
108   Class: QtxResourceEditor::Item
109   Descr: Class for incapsulation of one preference item
110 */
111
112 class QTX_EXPORT QtxResourceEdit::Item
113 {
114 public:
115   Item( QtxResourceEdit*, Item* = 0 );
116   virtual ~Item();
117
118   int                  id() const;
119   virtual int          type() const = 0;
120
121   Item*                parentItem() const;
122   void                 childItems( QPtrList<Item>& ) const;
123
124   virtual bool         isEmpty() const;
125
126   QString              title() const;
127   void                 resource( QString&, QString& ) const;
128
129   virtual void         setTitle( const QString& );
130   virtual void         setResource( const QString&, const QString& );
131
132   virtual void         update();
133
134   QVariant             property( const QString& ) const;
135   virtual void         setProperty( const QString&, const QVariant& );
136
137   virtual void         store() = 0;
138   virtual void         retrieve() = 0;
139
140   virtual Item*        createItem( const QString&, const int ) = 0;
141
142   QString              resourceValue() const;
143   void                 setResourceValue( const QString& );
144
145   virtual void         insertChild( Item* );
146   virtual void         removeChild( Item* );
147
148 protected:
149   QtxResourceMgr*      resourceMgr() const;
150   QtxResourceEdit*     resourceEdit() const;
151
152   int                  getInteger( const int = 0 ) const;
153   double               getDouble( const double = 0.0 ) const;
154   bool                 getBoolean( const bool = false ) const;
155   QColor               getColor( const QColor& = QColor() ) const;
156   QFont                getFont( const QFont& = QFont() ) const;
157   QString              getString( const QString& = QString::null ) const;
158
159   void                 setInteger( const int );
160   void                 setDouble( const double );
161   void                 setBoolean( const bool );
162   void                 setColor( const QColor& );
163   void                 setFont( const QFont& );  
164   void                 setString( const QString& );
165
166   Item*                item( const int ) const;
167   Item*                item( const QString& ) const;
168   Item*                item( const QString&, const int ) const;
169
170 protected:
171   typedef QPtrList<Item>         ItemList;
172   typedef QPtrListIterator<Item> ItemListIterator;
173
174 private:
175   static int           generateId();
176
177 private:
178   int                  myId;
179   Item*                myParent;
180   ItemList             myChildren;
181
182   QString              myTitle;
183   QString              myResSection;
184   QString              myResParameter;
185
186   QtxResourceEdit*     myEdit;
187 };
188
189 #ifdef WIN32
190 #pragma warning( default:4251 )
191 #endif
192
193 #endif