Salome HOME
Join modifications from branch OCC_debug_for_3_2_0b1
[modules/gui.git] / src / SUIT / SUIT_DataObject.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 #ifndef SUIT_DATAOBJECT_H
20 #define SUIT_DATAOBJECT_H
21
22 #include <qobject.h>
23 #include <qstring.h>
24 #include <qpixmap.h>
25 #include <qptrlist.h>
26
27 #include "SUIT.h"
28
29 class SUIT_DataObject;
30 class SUIT_DataObjectKey;
31
32 typedef QPtrList<SUIT_DataObject>         DataObjectList;
33 typedef QPtrListIterator<SUIT_DataObject> DataObjectListIterator;
34
35 #ifdef WIN32
36 #pragma warning( disable:4251 )
37 #endif
38
39 /*!
40   \class SUIT_DataObject
41   Data Object represents uniform data tree structure recommended to use in SUIT-based applications
42   Many of standard classes (DataModel,ObjectBrowser) deal with SUIT_DataObjects
43 */
44 class SUIT_EXPORT SUIT_DataObject  
45 {
46 public:
47   class Signal;
48
49   typedef enum { None, RadioButton, CheckBox } CheckType;
50   typedef enum { Text, Base, Foreground, Background, Highlight, HighlightedText } ColorRole;
51
52   SUIT_DataObject( SUIT_DataObject* = 0 );
53   virtual ~SUIT_DataObject();
54
55   SUIT_DataObject*            root() const;
56   SUIT_DataObject*            lastChild() const;
57   SUIT_DataObject*            firstChild() const;
58
59   int                         childCount() const;
60   int                         childPos( const SUIT_DataObject* ) const;
61   SUIT_DataObject*            childObject( const int ) const;
62   int                         level() const;
63
64   SUIT_DataObject*            nextBrother() const;
65   SUIT_DataObject*            prevBrother() const;
66
67   bool                        autoDeleteChildren() const;
68   virtual void                setAutoDeleteChildren( const bool );
69
70   virtual void                children( DataObjectList&, const bool = false ) const;
71   virtual DataObjectList      children( const bool = false );
72   
73   void                        appendChild( SUIT_DataObject* );
74   virtual void                removeChild( SUIT_DataObject* );
75   virtual void                insertChild( SUIT_DataObject*, int thePosition );
76   bool                        replaceChild( SUIT_DataObject*, SUIT_DataObject*, const bool = false );
77
78   void                        reparentChildren( const SUIT_DataObject* );
79
80   virtual QString             text( const int ) const;
81   virtual QColor              color( const ColorRole ) const;
82
83   virtual QString             name() const;
84   virtual QPixmap             icon() const;
85   virtual QString             toolTip() const;
86
87   virtual SUIT_DataObject*    parent() const;
88   virtual void                setParent( SUIT_DataObject* );
89
90   virtual bool                isDragable() const;
91   virtual bool                isDropAccepted( SUIT_DataObject* obj );
92
93   virtual CheckType           checkType() const;
94
95   virtual bool                isOn() const;
96   virtual void                setOn( const bool );
97
98   virtual bool                isOpen() const;
99   virtual void                setOpen( const bool );
100
101   virtual SUIT_DataObjectKey* key() const;
102
103   bool                        connect( QObject*, const char* );
104   bool                        disconnect( QObject*, const char* );
105
106   void                        deleteLater();
107   
108   void                        dump( const int indent = 2 ) const; // dump to cout
109
110 private:
111   bool                        myOpen;
112   bool                        myCheck;
113   Signal*                     mySignal;
114   SUIT_DataObject*            myParent;
115   DataObjectList              myChildren;
116
117   friend class SUIT_DataObject::Signal;
118   friend class SUIT_DataObjectIterator;
119 };
120
121 /*!
122   \class SUIT_DataObject::Signal
123   Auxiliary class providing functionality to use signals of data object state change
124   SUIT_DataObject cannot have signals, because it isn't QObject, but
125   methods connect/disconnect of SUIT_DataObject with help of this it is possible
126   to emulate Qt signal processing
127 */
128 class SUIT_DataObject::Signal : public QObject
129 {
130   Q_OBJECT
131
132 public:
133   Signal( SUIT_DataObject* );
134   virtual ~Signal();
135
136   void                        emitSignal();
137   void                        setOwner( SUIT_DataObject* o );
138
139 signals:
140   void                        destroyed( SUIT_DataObject* );
141
142 private:
143   SUIT_DataObject*            myOwner;
144 };
145
146 #ifdef WIN32
147 #pragma warning( default:4251 )
148 #endif
149
150 #endif