Salome HOME
Merge from V6_main_20120808 08Aug12
[modules/gui.git] / src / SUIT / SUIT_DataObject.h
1 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 // File   : SUIT_DataObject.h
24 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
25
26 #ifndef SUIT_DATAOBJECT_H
27 #define SUIT_DATAOBJECT_H
28
29 #include "SUIT.h"
30
31 #include <Qtx.h>
32
33 #include <QList>
34 #include <QObject>
35 #include <QString>
36 #include <QPixmap>
37 #include <QFont>
38
39 class SUIT_DataObject;
40 class SUIT_DataObjectKey;
41
42 typedef QList<SUIT_DataObject*> DataObjectList;
43
44 #ifdef WIN32
45 #pragma warning( disable:4251 )
46 #endif
47
48 class SUIT_EXPORT SUIT_DataObject
49 {
50 public:
51   class Signal;
52
53   //! Color role
54   typedef enum {
55     Text,              //!< editor foreground (text) color
56     Base,              //!< editor background color
57     Foreground,        //!< foreground (text) color
58     Background,        //!< background color
59     Highlight,         //!< highlight background color
60     HighlightedText    //!< highlighted foreground (text) color
61   } ColorRole;
62
63   //! Column id
64   enum
65   {
66     NameId,          //!< name column
67     VisibilityId     //!< visibility state column
68   };
69
70   SUIT_DataObject( SUIT_DataObject* = 0 );
71   virtual ~SUIT_DataObject();
72
73   SUIT_DataObject*            root() const;
74   SUIT_DataObject*            lastChild() const;
75   SUIT_DataObject*            firstChild() const;
76
77   int                         childCount() const;
78   int                         childPos( const SUIT_DataObject* ) const;
79   SUIT_DataObject*            childObject( const int ) const;
80   int                         level() const;
81   int                         position() const;
82
83   SUIT_DataObject*            nextBrother() const;
84   SUIT_DataObject*            prevBrother() const;
85
86   bool                        autoDeleteChildren() const;
87   virtual void                setAutoDeleteChildren( const bool );
88
89   virtual void                children( DataObjectList&, const bool = false ) const;
90   virtual DataObjectList      children( const bool = false );
91
92   void                        appendChild( SUIT_DataObject* );
93   virtual void                insertChild( SUIT_DataObject*, int );
94   virtual void                removeChild( SUIT_DataObject*, const bool = false );
95   bool                        replaceChild( SUIT_DataObject*, SUIT_DataObject*, const bool = false );
96
97   void                        reparentChildren( const SUIT_DataObject* );
98
99   virtual SUIT_DataObject*    parent() const;
100   virtual void                setParent( SUIT_DataObject* );
101   virtual void                assignParent( SUIT_DataObject* );
102   void                        insertChildAtPos( SUIT_DataObject* obj, int position );
103   bool                        modified(){return _modified;};
104   void                        setModified(bool modified){_modified = modified;};
105
106   virtual QString             name() const;
107   virtual QString             text( const int = NameId ) const;
108   virtual QPixmap             icon( const int = NameId ) const;
109   virtual QColor              color( const ColorRole, const int = NameId ) const;
110   virtual QString             toolTip( const int = NameId ) const;
111   virtual QString             statusTip( const int = NameId ) const;
112   virtual QString             whatsThis( const int = NameId ) const;
113   virtual QFont               font( const int = NameId ) const;
114   virtual int                 alignment( const int = NameId ) const;
115
116   virtual bool                expandable() const;
117   virtual bool                isVisible() const;
118   virtual bool                isDraggable() const;
119   virtual bool                isDropAccepted() const;
120
121   virtual bool                isEnabled() const;
122   virtual bool                isSelectable() const;
123   virtual bool                isCheckable( const int = NameId ) const;
124   virtual bool                renameAllowed( const int = NameId ) const;
125   virtual bool                setName(const QString& name);
126
127   virtual bool                isOn( const int = NameId ) const;
128   virtual void                setOn( const bool, const int = NameId );
129
130   virtual bool                isOpen() const;
131   virtual void                setOpen( const bool );
132
133   virtual void                update();
134   virtual bool                customSorting( const int = NameId ) const;
135   virtual bool                compare( const QVariant&, const QVariant&, const int = NameId ) const;
136
137   virtual SUIT_DataObjectKey* key() const;
138   virtual int                 groupId() const;
139   virtual QVariant            customData(Qtx::CustomDataType /*type*/);
140
141   static Signal*              signal();
142   static bool                 connect( const char*, QObject*, const char* );
143   static bool                 disconnect( const char*, QObject*, const char* );
144
145   void                        deleteLater();
146
147   void                        dump( const int indent = 2 ) const; // dump to cout
148
149 private:
150   SUIT_DataObject*            myParent;
151   bool                        myOpen;
152   bool                        myCheck;
153   bool                        myAutoDel;
154   DataObjectList              myChildren;
155   bool                        _modified;
156
157   static Signal*              mySignal;
158
159   friend class SUIT_DataObject::Signal;
160   friend class SUIT_DataObjectIterator;
161 };
162
163 class SUIT_EXPORT SUIT_DataObject::Signal : public QObject
164 {
165   Q_OBJECT
166
167 public:
168   Signal();
169   virtual ~Signal();
170
171 private:
172   void emitCreated( SUIT_DataObject* );
173   void emitDestroyed( SUIT_DataObject* );
174   void emitInserted( SUIT_DataObject*, SUIT_DataObject* );
175   void emitRemoved( SUIT_DataObject*, SUIT_DataObject* );
176
177   void deleteLater( SUIT_DataObject* );
178
179 signals:
180   void created( SUIT_DataObject* );
181   void destroyed( SUIT_DataObject* );
182   void inserted( SUIT_DataObject*, SUIT_DataObject* );
183   void removed( SUIT_DataObject*, SUIT_DataObject* );
184
185   friend class SUIT_DataObject;
186
187 private:
188   DataObjectList myDelLaterObjects;
189 };
190
191 #ifdef WIN32
192 #pragma warning( default:4251 )
193 #endif
194
195 #endif  // SUIT_DATAOBJECT_H