Salome HOME
Copyrights update
[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 provide support data object.
41 */
42 class SUIT_EXPORT SUIT_DataObject  
43 {
44 public:
45   class Signal;
46
47   typedef enum { None, RadioButton, CheckBox } CheckType;
48   typedef enum { Text, Base, Foreground, Background, Highlight, HighlightedText } ColorRole;
49
50   SUIT_DataObject( SUIT_DataObject* = 0 );
51   virtual ~SUIT_DataObject();
52
53   SUIT_DataObject*            root() const;
54   SUIT_DataObject*            lastChild() const;
55   SUIT_DataObject*            firstChild() const;
56
57   int                         childCount() const;
58   int                         childPos( const SUIT_DataObject* ) const;
59   SUIT_DataObject*            childObject( const int ) const;
60   int                         level() const;
61
62   SUIT_DataObject*            nextBrother() const;
63   SUIT_DataObject*            prevBrother() const;
64
65   bool                        autoDeleteChildren() const;
66   virtual void                setAutoDeleteChildren( const bool );
67
68   virtual void                children( DataObjectList&, const bool = false ) const;
69   virtual DataObjectList      children( const bool = false );
70   
71   void                        appendChild( SUIT_DataObject* );
72   virtual void                removeChild( SUIT_DataObject* );
73   virtual void                insertChild( SUIT_DataObject*, int thePosition );
74   bool                        replaceChild( SUIT_DataObject*, SUIT_DataObject*, const bool = false );
75
76   void                        reparentChildren( const SUIT_DataObject* );
77
78   virtual QString             text( const int ) const;
79   virtual QColor              color( const ColorRole ) const;
80
81   virtual QString             name() const;
82   virtual QPixmap             icon() const;
83   virtual QString             toolTip() const;
84
85   virtual SUIT_DataObject*    parent() const;
86   virtual void                setParent( SUIT_DataObject* );
87
88   virtual bool                isDragable() const;
89   virtual bool                isDropAccepted( SUIT_DataObject* obj );
90
91   virtual CheckType           checkType() const;
92
93   virtual bool                isOn() const;
94   virtual void                setOn( const bool );
95
96   virtual bool                isOpen() const;
97   virtual void                setOpen( const bool );
98
99   virtual SUIT_DataObjectKey* key() const;
100
101   bool                        connect( QObject*, const char* );
102   bool                        disconnect( QObject*, const char* );
103
104   void                        deleteLater();
105   
106   void                        dump( const int indent = 2 ) const; // dump to cout
107
108 private:
109   bool                        myOpen;
110   bool                        myCheck;
111   Signal*                     mySignal;
112   SUIT_DataObject*            myParent;
113   DataObjectList              myChildren;
114
115   friend class SUIT_DataObject::Signal;
116   friend class SUIT_DataObjectIterator;
117 };
118
119 class SUIT_DataObject::Signal : public QObject
120 {
121   Q_OBJECT
122
123 public:
124   Signal( SUIT_DataObject* );
125   virtual ~Signal();
126
127   void                        emitSignal();
128   void                        setOwner( SUIT_DataObject* o );
129
130 signals:
131   void                        destroyed( SUIT_DataObject* );
132
133 private:
134   SUIT_DataObject*            myOwner;
135 };
136
137 #ifdef WIN32
138 #pragma warning( default:4251 )
139 #endif
140
141 #endif