1 // Copyright (C) 2014-2015 EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 // Lesser General Public License for more details.
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include <HYDROGUI_DataModelSync.h>
20 #include <HYDROGUI_DataObject.h>
23 HYDROGUI_DataModelSync::HYDROGUI_DataModelSync( SUIT_DataObject* theRoot )
28 HYDROGUI_DataModelSync::~HYDROGUI_DataModelSync()
32 void HYDROGUI_DataModelSync::deleteItemWithChildren( const suitPtr& theSuitPtr ) const
37 theSuitPtr->setAutoDeleteChildren( true );
38 theSuitPtr->deleteLater();
41 suitPtr HYDROGUI_DataModelSync::nullSrc() const
46 suitPtr HYDROGUI_DataModelSync::nullTrg() const
51 QList<suitPtr> HYDROGUI_DataModelSync::children( const suitPtr& theSuitPtr ) const
53 QList<suitPtr> aChildren;
56 DataObjectList anObjList;
57 theSuitPtr->children( anObjList );
58 foreach( SUIT_DataObject* anObj, anObjList )
59 aChildren.append( anObj );
64 suitPtr HYDROGUI_DataModelSync::parent( const suitPtr& theSuitPtr ) const
66 return theSuitPtr ? theSuitPtr->parent() : 0;
69 void HYDROGUI_DataModelSync::updateItem( const suitPtr& theSrcPtr, const suitPtr& theTrgPtr ) const
71 HYDROGUI_DataObject* aDataObj = dynamic_cast<HYDROGUI_DataObject*>( theTrgPtr );
73 aDataObj->updateBy( theSrcPtr );
75 HYDROGUI_NamedObject* aNamedObj = dynamic_cast<HYDROGUI_NamedObject*>( theTrgPtr );
77 aNamedObj->updateBy( theSrcPtr );
80 bool HYDROGUI_DataModelSync::isEqual( const suitPtr& theSrcPtr, const suitPtr& theTrgPtr ) const
82 if( theSrcPtr==myRoot )
91 QString aSrcClass = typeid( *theSrcPtr ).name();
92 QString aTrgClass = typeid( *theTrgPtr ).name();
93 return aSrcClass==aTrgClass;
96 suitPtr HYDROGUI_DataModelSync::createItem( const suitPtr& theSrcPtr,
97 const suitPtr& theParent,
98 const suitPtr& theAfter ) const
102 int aPos = theParent->childPos( theAfter );
104 theParent->insertChild( theSrcPtr, aPos+1 );
106 theParent->appendChild( theSrcPtr );