]> SALOME platform Git repositories - modules/gui.git/blob - src/SUIT/SUIT_DataObject.h
Salome HOME
8e06fad064460a5b95932f3567e427e9f0cda3cb
[modules/gui.git] / src / SUIT / SUIT_DataObject.h
1 //  Copyright (C) 2007-2008  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 // File   : SUIT_DataObject.h
23 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
24 //
25 #ifndef SUIT_DATAOBJECT_H
26 #define SUIT_DATAOBJECT_H
27
28 #include "SUIT.h"
29
30 #include <QList>
31 #include <QObject>
32 #include <QString>
33 #include <QPixmap>
34 #include <QFont>
35
36 class SUIT_DataObject;
37 class SUIT_DataObjectKey;
38
39 typedef QList<SUIT_DataObject*> DataObjectList;
40
41 #ifdef WIN32
42 #pragma warning( disable:4251 )
43 #endif
44
45 class SUIT_EXPORT SUIT_DataObject  
46 {
47 public:
48   class Signal;
49
50   //! Color role
51   typedef enum { 
52     Text,              //!< editor foreground (text) color
53     Base,              //!< editor background color
54     Foreground,        //!< foreground (text) color
55     Background,        //!< background color
56     Highlight,         //!< highlight background color
57     HighlightedText    //!< highlighted foreground (text) color
58   } ColorRole;
59
60   //! Column id
61   enum
62   { 
63     NameId            //!< name column
64   };
65
66   SUIT_DataObject( SUIT_DataObject* = 0 );
67   virtual ~SUIT_DataObject();
68
69   SUIT_DataObject*            root() const;
70   SUIT_DataObject*            lastChild() const;
71   SUIT_DataObject*            firstChild() const;
72
73   int                         childCount() const;
74   int                         childPos( const SUIT_DataObject* ) const;
75   SUIT_DataObject*            childObject( const int ) const;
76   int                         level() const;
77   int                         position() const;
78
79   SUIT_DataObject*            nextBrother() const;
80   SUIT_DataObject*            prevBrother() const;
81
82   bool                        autoDeleteChildren() const;
83   virtual void                setAutoDeleteChildren( const bool );
84
85   virtual void                children( DataObjectList&, const bool = false ) const;
86   virtual DataObjectList      children( const bool = false );
87   
88   void                        appendChild( SUIT_DataObject* );
89   virtual void                insertChild( SUIT_DataObject*, int );
90   virtual void                removeChild( SUIT_DataObject*, const bool = false );
91   bool                        replaceChild( SUIT_DataObject*, SUIT_DataObject*, const bool = false );
92
93   void                        reparentChildren( const SUIT_DataObject* );
94
95   virtual SUIT_DataObject*    parent() const;
96   virtual void                setParent( SUIT_DataObject* );
97
98   virtual QString             name() const;
99   virtual QString             text( const int = NameId ) const;
100   virtual QPixmap             icon( const int = NameId ) const;
101   virtual QColor              color( const ColorRole, const int = NameId ) const;
102   virtual QString             toolTip( const int = NameId ) const;
103   virtual QString             statusTip( const int = NameId ) const;
104   virtual QString             whatsThis( const int = NameId ) const;
105   virtual QFont               font( const int = NameId ) const;
106   virtual int                 alignment( const int = NameId ) const;
107
108   virtual bool                isDragable() const;
109   virtual bool                isDropAccepted( SUIT_DataObject* obj );
110
111   virtual bool                isEnabled() const;
112   virtual bool                isSelectable() const;
113   virtual bool                isCheckable( const int = NameId ) const;
114
115   virtual bool                isOn( const int = NameId ) const;
116   virtual void                setOn( const bool, const int = NameId );
117
118   virtual bool                isOpen() const;
119   virtual void                setOpen( const bool );
120
121   virtual void                update();
122   virtual bool                customSorting( const int = NameId ) const;
123   virtual bool                compare( const QVariant&, const QVariant&, const int = NameId ) const;
124
125   virtual SUIT_DataObjectKey* key() const;
126   virtual int groupId() const;
127
128   static Signal*              signal();
129   static bool                 connect( const char*, QObject*, const char* );
130   static bool                 disconnect( const char*, QObject*, const char* );
131
132   void                        deleteLater();
133
134   void                        dump( const int indent = 2 ) const; // dump to cout
135
136 private:
137   SUIT_DataObject*            myParent;
138   bool                        myOpen;
139   bool                        myCheck;
140   bool                        myAutoDel;
141   DataObjectList              myChildren;
142
143   static Signal*              mySignal;
144
145   friend class SUIT_DataObject::Signal;
146   friend class SUIT_DataObjectIterator;
147 };
148
149 class SUIT_EXPORT SUIT_DataObject::Signal : public QObject
150 {
151   Q_OBJECT
152
153 public:
154   Signal();
155   virtual ~Signal();
156
157 private:
158   void emitCreated( SUIT_DataObject* );
159   void emitDestroyed( SUIT_DataObject* );
160   void emitInserted( SUIT_DataObject*, SUIT_DataObject* );
161   void emitRemoved( SUIT_DataObject*, SUIT_DataObject* );
162
163   void deleteLater( SUIT_DataObject* );
164
165 signals:
166   void created( SUIT_DataObject* );
167   void destroyed( SUIT_DataObject* );
168   void inserted( SUIT_DataObject*, SUIT_DataObject* );
169   void removed( SUIT_DataObject*, SUIT_DataObject* );
170
171   friend class SUIT_DataObject;
172
173 private:
174   DataObjectList myDelLaterObjects;
175 };
176
177 #ifdef WIN32
178 #pragma warning( default:4251 )
179 #endif
180
181 #endif  // SUIT_DATAOBJECT_H