Back to index

salome-gui  6.5.0
SUIT_DataObject.h
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 // File   : SUIT_DataObject.h
00024 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
00025 
00026 #ifndef SUIT_DATAOBJECT_H
00027 #define SUIT_DATAOBJECT_H
00028 
00029 #include "SUIT.h"
00030 
00031 #include <Qtx.h>
00032 
00033 #include <QList>
00034 #include <QObject>
00035 #include <QString>
00036 #include <QPixmap>
00037 #include <QFont>
00038 
00039 class SUIT_DataObject;
00040 class SUIT_DataObjectKey;
00041 
00042 typedef QList<SUIT_DataObject*> DataObjectList;
00043 
00044 #ifdef WIN32
00045 #pragma warning( disable:4251 )
00046 #endif
00047 
00048 class SUIT_EXPORT SUIT_DataObject
00049 {
00050 public:
00051   class Signal;
00052 
00054   typedef enum {
00055     Text,              
00056     Base,              
00057     Foreground,        
00058     Background,        
00059     Highlight,         
00060     HighlightedText    
00061   } ColorRole;
00062 
00064   enum
00065   {
00066     NameId,          
00067     VisibilityId     
00068   };
00069 
00070   SUIT_DataObject( SUIT_DataObject* = 0 );
00071   virtual ~SUIT_DataObject();
00072 
00073   SUIT_DataObject*            root() const;
00074   SUIT_DataObject*            lastChild() const;
00075   SUIT_DataObject*            firstChild() const;
00076 
00077   int                         childCount() const;
00078   int                         childPos( const SUIT_DataObject* ) const;
00079   SUIT_DataObject*            childObject( const int ) const;
00080   int                         level() const;
00081   int                         position() const;
00082 
00083   SUIT_DataObject*            nextBrother() const;
00084   SUIT_DataObject*            prevBrother() const;
00085 
00086   bool                        autoDeleteChildren() const;
00087   virtual void                setAutoDeleteChildren( const bool );
00088 
00089   virtual void                children( DataObjectList&, const bool = false ) const;
00090   virtual DataObjectList      children( const bool = false );
00091 
00092   void                        appendChild( SUIT_DataObject* );
00093   virtual void                insertChild( SUIT_DataObject*, int );
00094   virtual void                removeChild( SUIT_DataObject*, const bool = false );
00095   bool                        replaceChild( SUIT_DataObject*, SUIT_DataObject*, const bool = false );
00096 
00097   void                        reparentChildren( const SUIT_DataObject* );
00098 
00099   virtual SUIT_DataObject*    parent() const;
00100   virtual void                setParent( SUIT_DataObject* );
00101   virtual void                assignParent( SUIT_DataObject* );
00102   void                        insertChildAtPos( SUIT_DataObject* obj, int position );
00103   bool                        modified(){return _modified;};
00104   void                        setModified(bool modified){_modified = modified;};
00105 
00106   virtual QString             name() const;
00107   virtual QString             text( const int = NameId ) const;
00108   virtual QPixmap             icon( const int = NameId ) const;
00109   virtual QColor              color( const ColorRole, const int = NameId ) const;
00110   virtual QString             toolTip( const int = NameId ) const;
00111   virtual QString             statusTip( const int = NameId ) const;
00112   virtual QString             whatsThis( const int = NameId ) const;
00113   virtual QFont               font( const int = NameId ) const;
00114   virtual int                 alignment( const int = NameId ) const;
00115 
00116   virtual bool                expandable() const;
00117   virtual bool                isVisible() const;
00118   virtual bool                isDraggable() const;
00119   virtual bool                isDropAccepted() const;
00120 
00121   virtual bool                isEnabled() const;
00122   virtual bool                isSelectable() const;
00123   virtual bool                isCheckable( const int = NameId ) const;
00124   virtual bool                renameAllowed( const int = NameId ) const;
00125   virtual bool                setName(const QString& name);
00126 
00127   virtual bool                isOn( const int = NameId ) const;
00128   virtual void                setOn( const bool, const int = NameId );
00129 
00130   virtual bool                isOpen() const;
00131   virtual void                setOpen( const bool );
00132 
00133   virtual void                update();
00134   virtual bool                customSorting( const int = NameId ) const;
00135   virtual bool                compare( const QVariant&, const QVariant&, const int = NameId ) const;
00136 
00137   virtual SUIT_DataObjectKey* key() const;
00138   virtual int                 groupId() const;
00139   virtual QVariant            customData(Qtx::CustomDataType /*type*/);
00140 
00141   static Signal*              signal();
00142   static bool                 connect( const char*, QObject*, const char* );
00143   static bool                 disconnect( const char*, QObject*, const char* );
00144 
00145   void                        deleteLater();
00146 
00147   void                        dump( const int indent = 2 ) const; // dump to cout
00148 
00149 private:
00150   SUIT_DataObject*            myParent;
00151   bool                        myOpen;
00152   bool                        myCheck;
00153   bool                        myAutoDel;
00154   DataObjectList              myChildren;
00155   bool                        _modified;
00156 
00157   static Signal*              mySignal;
00158 
00159   friend class SUIT_DataObject::Signal;
00160   friend class SUIT_DataObjectIterator;
00161 };
00162 
00163 class SUIT_EXPORT SUIT_DataObject::Signal : public QObject
00164 {
00165   Q_OBJECT
00166 
00167 public:
00168   Signal();
00169   virtual ~Signal();
00170 
00171 private:
00172   void emitCreated( SUIT_DataObject* );
00173   void emitDestroyed( SUIT_DataObject* );
00174   void emitInserted( SUIT_DataObject*, SUIT_DataObject* );
00175   void emitRemoved( SUIT_DataObject*, SUIT_DataObject* );
00176 
00177   void deleteLater( SUIT_DataObject* );
00178 
00179 signals:
00180   void created( SUIT_DataObject* );
00181   void destroyed( SUIT_DataObject* );
00182   void inserted( SUIT_DataObject*, SUIT_DataObject* );
00183   void removed( SUIT_DataObject*, SUIT_DataObject* );
00184 
00185   friend class SUIT_DataObject;
00186 
00187 private:
00188   DataObjectList myDelLaterObjects;
00189 };
00190 
00191 #ifdef WIN32
00192 #pragma warning( default:4251 )
00193 #endif
00194 
00195 #endif  // SUIT_DATAOBJECT_H