Salome HOME
Upgrade to paraview 5.4
[modules/gui.git] / src / SUIT / SUIT_DataObject.cxx
index 7f4f1db88d9a37548efc39583db083c5e10f7ad2..246097ca59a332edb536488b98280ad76a016a1f 100755 (executable)
@@ -1,29 +1,33 @@
-//  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
 //
-//  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+// Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
 //
-//  This library is free software; you can redistribute it and/or
-//  modify it under the terms of the GNU Lesser General Public
-//  License as published by the Free Software Foundation; either
-//  version 2.1 of the License.
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
 //
-//  This library is distributed in the hope that it will be useful,
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-//  Lesser General Public License for more details.
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
 //
-//  You should have received a copy of the GNU Lesser General Public
-//  License along with this library; if not, write to the Free Software
-//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
-//  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
+
 // File   : SUIT_DataObject.cxx
 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
-//
+
+#include <QVariant>
+
 #include "SUIT_DataObject.h"
 #include "SUIT_DataObjectKey.h"
+#include <cstdio>
 
 SUIT_DataObject::Signal* SUIT_DataObject::mySignal = 0;
 
@@ -47,7 +51,8 @@ SUIT_DataObject::SUIT_DataObject( SUIT_DataObject* p )
 : myParent( 0 ),
   myOpen( false ),
   myCheck( false ),
-  myAutoDel( true )
+  myAutoDel( true ),
+  _modified( false )
 {
   setParent( p );
   signal()->emitCreated( this );
@@ -133,6 +138,25 @@ int SUIT_DataObject::childPos( const SUIT_DataObject* obj ) const
   return myChildren.indexOf( (SUIT_DataObject*)obj );
 }
 
+/*!
+  \brief Moves the child position from current to new one.
+  \param theObj child object
+  \param theNewPos child objectnew position in the children list
+
+*/
+void SUIT_DataObject::moveChildPos( SUIT_DataObject* theObj, int theNewPos)
+{
+  if (myChildren.size() <= 1)  return;
+
+  int aNewPos = theNewPos;
+  if (aNewPos < 0) aNewPos = 0;
+  if (aNewPos > (myChildren.size() - 1)) aNewPos = myChildren.size() - 1;
+
+  if (myChildren.removeOne(theObj))
+    myChildren.insert(aNewPos, theObj);
+}
+
+
 /*!
   \brief Get child object by the specified index.
   \param idx child object index
@@ -175,6 +199,16 @@ int SUIT_DataObject::position() const
   return myParent ? myParent->childPos( this ) : 0;
 }
 
+/*!
+  \brief Sets new position of the object in parent's list
+*/
+void SUIT_DataObject::setPosition(int theNewPos)
+{
+  if (theNewPos == position())  return;
+  if (!myParent)  return;
+  myParent->moveChildPos(this, theNewPos);
+}
+
 /*!
   \brief Get the next sibling data object in the children list.
   \return child object or 0 if there is no next sibling
@@ -280,6 +314,19 @@ void SUIT_DataObject::insertChild( SUIT_DataObject* obj, int position )
   signal()->emitInserted( obj, this );
 }
 
+/*!
+  \brief Insert new child object into the list of the children (faster version of insertChild without signal).
+  \param obj child object being added
+  \param position child position
+*/
+void SUIT_DataObject::insertChildAtPos( SUIT_DataObject* obj, int position )
+{
+  if ( !obj )return;
+  int pos = position < 0 ? myChildren.count() : position;
+  myChildren.insert( qMin( pos, (int)myChildren.count() ), obj );
+  obj->assignParent( this );
+}
+
 /*!
   \brief Remove the specified child object reference.
   \param obj child object being removed
@@ -373,6 +420,32 @@ void SUIT_DataObject::setParent( SUIT_DataObject* p )
     parent()->appendChild( this );
 }
 
+void SUIT_DataObject::assignParent( SUIT_DataObject* p )
+{
+  if ( p == myParent )
+    return;
+
+  myParent = p;
+}
+
+/*!
+  \brief Sets modification state of the object.
+
+  When the object has been modified (modified is set to true)
+  a signal is emitted to notify the tree model and eventually redraw the data object.
+
+  \param modified modified state 
+*/
+void SUIT_DataObject::setModified(bool modified)
+{
+  if ( _modified == modified )
+    return;
+
+  _modified = modified;
+  if ( _modified )
+    signal()->emitModified( this );
+}
+
 /*!
   \brief Get data object name.
 
@@ -520,6 +593,24 @@ int SUIT_DataObject::alignment( const int /*id*/ ) const
   return Qt::AlignLeft;
 }
 
+bool SUIT_DataObject::expandable() const
+{
+  return true;
+}
+
+/*!
+  \brief Check if the object is visible.
+
+  This method can be re-implemented in the subclasses.
+  Default implementation returns \c true (all objects are visible by default).
+
+  \return \c true if this object is displayable or \c false otherwise
+*/
+bool SUIT_DataObject::isVisible() const
+{
+  return true;
+}
+
 /*!
   \brief Check if the object is draggable.
 
@@ -528,23 +619,20 @@ int SUIT_DataObject::alignment( const int /*id*/ ) const
 
   \return \c true if it is possible to drag this object
 */
-bool SUIT_DataObject::isDragable() const
+bool SUIT_DataObject::isDraggable() const
 {
   return false;
 }
 
 /*!
-  \brief Check if the drop operation fo this object is possible.
+  \brief Check if the drop operation for this object is possible.
 
   This method can be re-implemented in the subclasses.
   Default implementation returns \c false (drop operation is not allowed).
 
-  \param obj object being dropped
-  \return \c true if it is possible to drop an object \c obj
-          to this object
+  \return \c true if it is possible to drop one or more objects (currently selected) to this object
 */
-
-bool SUIT_DataObject::isDropAccepted( SUIT_DataObject* /*obj*/ )
+bool SUIT_DataObject::isDropAccepted() const
 {
   return false;
 }
@@ -590,6 +678,32 @@ bool SUIT_DataObject::isCheckable( const int /*id*/ ) const
   return false;
 }
 
+/*!
+  \brief Check if this object is can't be renamed in place
+
+  This method can be re-implemented in the subclasses.
+  Default implementation returns \c false (all objects can not be renamed).
+
+  \param id column id
+  \return \c true if the item can be renamed by the user in place (e.g. in the Object browser)
+*/
+bool SUIT_DataObject::renameAllowed( const int /*id*/ ) const
+{
+  return false;
+}
+
+/*!
+  \brief Set name of the this object.
+
+  This method can be re-implemented in the subclasses.
+  Default implementation returns \c false.
+
+  \return \c true if rename operation finished successfully, \c false otherwise.
+*/
+bool SUIT_DataObject::setName(const QString& /*name*/) {
+  return false;
+}
+
 /*!
   \brief Get the checked state of the object (if it is checkable)
   for the specified column.
@@ -676,7 +790,7 @@ bool SUIT_DataObject::customSorting( const int /*id*/ ) const
   \sa customSorting()
 */
 bool SUIT_DataObject::compare( const QVariant& /*left*/, const QVariant& /*right*/,
-                              const int /*id*/ ) const
+                               const int /*id*/ ) const
 {
   return false;
 }
@@ -806,7 +920,7 @@ SUIT_DataObject::Signal::Signal()
 SUIT_DataObject::Signal::~Signal()
 {
   for ( DataObjectList::Iterator it = myDelLaterObjects.begin();
-       it != myDelLaterObjects.end(); ++it ) {
+        it != myDelLaterObjects.end(); ++it ) {
     delete *it;
   }
   myDelLaterObjects.clear();
@@ -861,6 +975,15 @@ void SUIT_DataObject::Signal::emitRemoved( SUIT_DataObject* object, SUIT_DataObj
   emit( removed( object, parent ) );
 }
 
+/*!
+  \brief Emit a signal to notify that the data object has been modified.
+  \param object data object that has been modified
+*/
+void SUIT_DataObject::Signal::emitModified( SUIT_DataObject* object )
+{
+  emit( modified( object ) );
+}
+
 /*!
   \brief Schedule data object for the late deleting.
   \param object data object to be deleted later
@@ -894,7 +1017,12 @@ int SUIT_DataObject::groupId() const
 {
   return 0;
 }
-
+/*!
+  \brief return custom data for data object.
+ */
+QVariant SUIT_DataObject::customData(Qtx::CustomDataType /*type*/) {
+  return QVariant();
+}
 /*!
   \fn void SUIT_DataObject::Signal::created( SUIT_DataObject* object );
   \brief Emitted when data object is created.