From: vsr Date: Tue, 6 Mar 2012 13:22:31 +0000 (+0000) Subject: 0020136: EDF 933 DEV : Drag&Drop in OB, complete implementation X-Git-Tag: V6_5_0a1~35 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=a2d03c2857fce64d46cc5d1af395816f0fb5af9c;p=modules%2Fgui.git 0020136: EDF 933 DEV : Drag&Drop in OB, complete implementation --- diff --git a/src/LightApp/LightApp_Application.cxx b/src/LightApp/LightApp_Application.cxx index aacb2800d..4e5c0e46c 100644 --- a/src/LightApp/LightApp_Application.cxx +++ b/src/LightApp/LightApp_Application.cxx @@ -1682,57 +1682,15 @@ void LightApp_Application::onRefresh() } /*!Private SLOT. Support drag-and-drop operation.*/ -void LightApp_Application::onDropped (const QMimeData *data, Qt::DropAction action, - int row, int column, const QModelIndex& parent) +void LightApp_Application::onDropped( const QList& objects, SUIT_DataObject* parent, int row, Qt::DropAction action ) { - if (action == Qt::IgnoreAction) + LightApp_DataObject* parentObj = dynamic_cast( parent ); + if ( !parentObj ) return; - if (!data->hasFormat("application/vnd.text.list")) - return; - - if (column > 0) - return; - - if (!parent.isValid()) - // dropping into the top level of the model is not allowed - return; - - SUIT_AbstractModel* treeModel = dynamic_cast(objectBrowser()->model()); - - SUIT_DataObject* obj = treeModel->object(parent); - if (!obj) - return; - - LightApp_DataObject* parentObj = dynamic_cast(obj); - if (!parentObj) - return; - - // decode mime data - QByteArray encodedData = data->data("application/vnd.text.list"); - QDataStream stream (&encodedData, QIODevice::ReadOnly); - QStringList newItems; - - while (!stream.atEnd()) { - QString text; - stream >> text; - if (!text.isEmpty()) - newItems << text; - } - - DataObjectList listObjs; - foreach (QString text, newItems) { - SUIT_DataObject* anObji = findObject(text); - if (anObji) - listObjs.append(anObji); - } - - // tmp: clear selection to avoid problem with persistent data model indexes - //mySelMgr->clearSelected(); - - LightApp_Module* aModule = dynamic_cast(parentObj->module()); - if (aModule) - aModule->dropObjects(listObjs, action, parentObj, row); + LightApp_Module* aModule = dynamic_cast( parentObj->module() ); + if ( aModule ) + aModule->dropObjects( objects, parentObj, row, action ); } /*!Private SLOT. On preferences.*/ @@ -1844,8 +1802,10 @@ QWidget* LightApp_Application::createWindow( const int flag ) // Mantis issue 0020136: Drag&Drop in OB SUIT_ProxyModel* proxyModel = dynamic_cast(treeModel); - connect( proxyModel, SIGNAL(dropped(const QMimeData*, Qt::DropAction, int, int, const QModelIndex&)), - this, SLOT(onDropped(const QMimeData*, Qt::DropAction, int, int, const QModelIndex&)) ); + if ( proxyModel ) { + connect( proxyModel, SIGNAL( dropped( const QList&, SUIT_DataObject*, int, Qt::DropAction ) ), + this, SLOT( onDropped( const QList&, SUIT_DataObject*, int, Qt::DropAction ) ) ); + } // temporary commented /* diff --git a/src/LightApp/LightApp_Application.h b/src/LightApp/LightApp_Application.h index f758aad1d..1d552f406 100644 --- a/src/LightApp/LightApp_Application.h +++ b/src/LightApp/LightApp_Application.h @@ -237,8 +237,7 @@ protected slots: private slots: void onSelection(); void onRefresh(); - void onDropped( const QMimeData*, Qt::DropAction, - int, int, const QModelIndex& ); + void onDropped( const QList&, SUIT_DataObject*, int, Qt::DropAction ); void onPreferences(); void onPreferenceChanged( QString&, QString&, QString& ); void onRenameWindow(); diff --git a/src/LightApp/LightApp_DataObject.cxx b/src/LightApp/LightApp_DataObject.cxx index 90e0a64f1..98b17cc3a 100644 --- a/src/LightApp/LightApp_DataObject.cxx +++ b/src/LightApp/LightApp_DataObject.cxx @@ -176,7 +176,7 @@ bool LightApp_DataObject::isDragable() const \return \c true if it is possible to drop an object \c obj to this object */ -bool LightApp_DataObject::isDropAccepted() +bool LightApp_DataObject::isDropAccepted() const { LightApp_Module* aModule = dynamic_cast(module()); if (aModule) { diff --git a/src/LightApp/LightApp_DataObject.h b/src/LightApp/LightApp_DataObject.h index ac7ac8c57..6ba9c446e 100644 --- a/src/LightApp/LightApp_DataObject.h +++ b/src/LightApp/LightApp_DataObject.h @@ -65,7 +65,7 @@ public: virtual bool isVisible() const; virtual bool isDragable() const; - virtual bool isDropAccepted(); + virtual bool isDropAccepted() const; virtual bool renameAllowed( const int = NameId ) const; virtual bool setName( const QString& ); diff --git a/src/LightApp/LightApp_Module.cxx b/src/LightApp/LightApp_Module.cxx index 857807f17..d4b094d24 100644 --- a/src/LightApp/LightApp_Module.cxx +++ b/src/LightApp/LightApp_Module.cxx @@ -707,7 +707,7 @@ void LightApp_Module::paste() virtual method \return true if module allows dragging the given object */ -bool LightApp_Module::isDragable(const SUIT_DataObject* /*what*/) const +bool LightApp_Module::isDragable( const SUIT_DataObject* /*what*/ ) const { return false; } @@ -716,16 +716,18 @@ bool LightApp_Module::isDragable(const SUIT_DataObject* /*what*/) const virtual method \return true if module allows dropping one or more objects (currently selected) on the object \c where */ -bool LightApp_Module::isDropAccepted(const SUIT_DataObject* /*where*/) const +bool LightApp_Module::isDropAccepted( const SUIT_DataObject* /*where*/ ) const { return false; } /*! virtual method + Complete drag-n-drop operation by processing objects \a what being dragged, dropped to the line \a row + within the object \a where. The drop action being performed is specified by \a action. */ -void LightApp_Module::dropObjects(const DataObjectList& what, Qt::DropAction action, - const SUIT_DataObject* parent, const int row) +void LightApp_Module::dropObjects( const DataObjectList& /*what*/, SUIT_DataObject* /*where*/, + const int /*row*/, Qt::DropAction /*action*/ ) { } diff --git a/src/LightApp/LightApp_Module.h b/src/LightApp/LightApp_Module.h index 2d82ad2d6..16bcc29ed 100644 --- a/src/LightApp/LightApp_Module.h +++ b/src/LightApp/LightApp_Module.h @@ -95,10 +95,10 @@ public: virtual bool canCopy() const; virtual bool canPaste() const; - virtual bool isDragable(const SUIT_DataObject* what) const; - virtual bool isDropAccepted(const SUIT_DataObject* where) const; - virtual void dropObjects(const DataObjectList& what, Qt::DropAction action, - const SUIT_DataObject* parent, const int row); + virtual bool isDragable( const SUIT_DataObject* ) const; + virtual bool isDropAccepted( const SUIT_DataObject* ) const; + virtual void dropObjects( const DataObjectList&, SUIT_DataObject*, + const int, Qt::DropAction ); virtual void copy(); virtual void paste(); virtual bool renameAllowed( const QString& ) const; diff --git a/src/ObjBrowser/OB_Browser.cxx b/src/ObjBrowser/OB_Browser.cxx index 0e9fa2a33..5bcb78548 100755 --- a/src/ObjBrowser/OB_Browser.cxx +++ b/src/ObjBrowser/OB_Browser.cxx @@ -136,23 +136,23 @@ OB_Browser::OB_Browser( QWidget* parent, QAbstractItemModel* model ) : QWidget( parent ), myAutoOpenLevel( 0 ) { - myView = new QtxTreeView( this ); - myView->setRootIsDecorated( true ); - myView->setSelectionMode( QAbstractItemView::ExtendedSelection ); - myView->setAllColumnsShowFocus( true ); - - // Mantis issue 0020136: Drag&Drop in OB - myView->setDragEnabled(TRUE); - myView->setAcceptDrops(TRUE); - myView->setDropIndicatorShown(TRUE); - myView->setDragDropMode(QAbstractItemView::DragDrop); - //myView->setDragDropMode(QAbstractItemView::InternalMove); - - mySearchTool = new QtxSearchTool( this, myView ); - mySearchTool->setFrameStyle( QFrame::NoFrame | QFrame::Plain ); - mySearchTool->setActivators( QtxSearchTool::StandardKey | QtxSearchTool::SlashKey ); - mySearchTool->setSearcher( new QtxTreeViewSearcher( myView ) ); + // set-up tree view + myView = new QtxTreeView( this ); // create tree view + myView->setRootIsDecorated( true ); // show root item + myView->setSelectionMode( QAbstractItemView::ExtendedSelection ); // enable extended selection mode + myView->setAllColumnsShowFocus( true ); // focus is shown in all columns + + // enable drag-n-drop support + myView->setDragDropMode( QAbstractItemView::DragDrop ); // enable both drag and drop operations + myView->setDropIndicatorShown( true ); // show drag indicator on dragging + + // set-up search tool + mySearchTool = new QtxSearchTool( this, myView ); // create search tool + mySearchTool->setFrameStyle( QFrame::NoFrame | QFrame::Plain ); // do not show frame + mySearchTool->setActivators( QtxSearchTool::StandardKey | QtxSearchTool::SlashKey ); // set activation mode + mySearchTool->setSearcher( new QtxTreeViewSearcher( myView ) ); // assign searcher (for tree view) + // layout widgets QVBoxLayout* main = new QVBoxLayout( this ); main->addWidget( myView ); main->addWidget( mySearchTool ); diff --git a/src/SUIT/SUIT_DataObject.cxx b/src/SUIT/SUIT_DataObject.cxx index aa6e2bd29..d0b58b3d0 100755 --- a/src/SUIT/SUIT_DataObject.cxx +++ b/src/SUIT/SUIT_DataObject.cxx @@ -584,7 +584,7 @@ bool SUIT_DataObject::isDragable() const \return \c true if it is possible to drop one or more objects (currently selected) to this object */ -bool SUIT_DataObject::isDropAccepted() +bool SUIT_DataObject::isDropAccepted() const { return false; } diff --git a/src/SUIT/SUIT_DataObject.h b/src/SUIT/SUIT_DataObject.h index 8f35fb66e..6851fbd80 100755 --- a/src/SUIT/SUIT_DataObject.h +++ b/src/SUIT/SUIT_DataObject.h @@ -115,7 +115,7 @@ public: virtual bool expandable() const; virtual bool isVisible() const; virtual bool isDragable() const; - virtual bool isDropAccepted(); + virtual bool isDropAccepted() const; virtual bool isEnabled() const; virtual bool isSelectable() const; diff --git a/src/SUIT/SUIT_TreeModel.cxx b/src/SUIT/SUIT_TreeModel.cxx index a6ff0c455..f6f784707 100755 --- a/src/SUIT/SUIT_TreeModel.cxx +++ b/src/SUIT/SUIT_TreeModel.cxx @@ -828,17 +828,24 @@ QVariant SUIT_TreeModel::data( const QModelIndex& index, int role ) const val = obj->text( id ); break; case DecorationRole: { - if(id == SUIT_DataObject::VisibilityId) { - int anId = obj->customData(Qtx::IdType).toInt(); - QString objId = data(createIndex(index.row(),anId,index.internalPointer())).toString(); - if(myVisibilityMap.contains(objId)) { + // icon + if ( id == SUIT_DataObject::VisibilityId ) { + // for visibility column, icon is defined specifically (using data object id) + QString objId = objectId( index ); + if ( myVisibilityMap.contains( objId ) ) { + // visibility status is defined -> return proper icon SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr(); - val = (myVisibilityMap.value(objId) == Qtx::ShownState) ? - resMgr->loadPixmap( "SUIT", tr( "ICON_DATAOBJ_VISIBLE" )) : resMgr->loadPixmap( "SUIT", tr( "ICON_DATAOBJ_INVISIBLE" )); - } else { + val = ( myVisibilityMap.value( objId ) == Qtx::ShownState ) ? + resMgr->loadPixmap( "SUIT", tr( "ICON_DATAOBJ_VISIBLE" ) ) : + resMgr->loadPixmap( "SUIT", tr( "ICON_DATAOBJ_INVISIBLE" ) ); + } + else { + // visibility status is undefined -> no icon val = QIcon(); } - } else { + } + else { + // for other columns get icon from the object val = obj->icon( id ); } break; @@ -971,34 +978,6 @@ bool SUIT_TreeModel::setData( const QModelIndex& index, */ Qt::ItemFlags SUIT_TreeModel::flags( const QModelIndex& index ) const { - /* - if ( !index.isValid() ) - return 0; - - SUIT_DataObject* obj = object( index ); - Qt::ItemFlags f = 0; - - if ( obj ) { - // data object is enabled - if ( obj->isEnabled() ) - f = f | Qt::ItemIsEnabled; - - // data object is selectable - if ( obj->isSelectable() ) - f = f | Qt::ItemIsSelectable; - - // data object is checkable - if ( obj->isCheckable( index.column() ) ) - f = f | Qt::ItemIsUserCheckable; - - // data object can be renamed - if ( obj->renameAllowed( index.column() ) ) - f = f | Qt::ItemIsEditable; - } - - return f; - */ - Qt::ItemFlags f = 0; if (!index.isValid()) @@ -1041,23 +1020,6 @@ Qt::DropActions SUIT_TreeModel::supportedDropActions() const return Qt::CopyAction | Qt::MoveAction; } -//This function is never called -bool SUIT_TreeModel::removeRows(int row, int count, const QModelIndex &parent) -{ - qDebug("Remove"); - if (parent.isValid()) - return FALSE; - - beginRemoveRows(parent, row, row + count - 1); - - for (int i = 0; i < count; ++i){ - //delete m_pAllData->takeAt(row); - } - - endRemoveRows(); - return TRUE; -} - /*! \brief Get header data (can be used in any data view). \param column column number @@ -1289,6 +1251,11 @@ bool SUIT_TreeModel::customSorting( const int column ) const return root() ? root()->customSorting( column ) : false; } +void SUIT_TreeModel::forgetObject( const SUIT_DataObject* obj ) +{ + removeItem( treeItem( obj ) ); +} + /*! \brief Compares two model indexes for the sorting purposes. @@ -1520,6 +1487,28 @@ SUIT_DataObject* SUIT_TreeModel::object( const SUIT_TreeModel::TreeItem* item ) return myItems.contains( obj ) ? obj : 0; } +/*! + \brief Get unique object identifier + + Object identifier is customized via the Qtx::IdType custom data + + \param index model index + \return object identifier or null string if it isn't specified + \sa SUIT_DataObject::customData() +*/ +QString SUIT_TreeModel::objectId( const QModelIndex& index ) const +{ + QString objId; + if ( index.isValid() ) { + SUIT_DataObject* obj = object( index ); + if ( obj ) { + int anId = obj->customData( Qtx::IdType ).toInt(); + objId = data( createIndex( index.row(), anId, index.internalPointer() ) ).toString(); + } + } + return objId; +} + /*! \brief Create an item corresponding to the data object. \param obj source data object @@ -1688,33 +1677,66 @@ QStringList SUIT_TreeModel::mimeTypes() const \brief Called when the data objects are exported(dragged) from the tree. \param indexes the list of exported objects */ -QMimeData* SUIT_TreeModel::mimeData (const QModelIndexList &indexes) const +QMimeData* SUIT_TreeModel::mimeData( const QModelIndexList& indexes ) const { - QMimeData *mimeData = new QMimeData(); + QMimeData* mimeData = new QMimeData(); QByteArray encodedData; - QDataStream stream (&encodedData, QIODevice::WriteOnly); + QDataStream stream( &encodedData, QIODevice::WriteOnly ); - foreach (QModelIndex index, indexes) { - if (index.isValid()) { - if (index.column() == 0) { - SUIT_DataObject* aDObj = object(index); - QString anEntry = aDObj->text(SUIT_DataObject::VisibilityId + 1); - stream << anEntry; - } - } + foreach ( QModelIndex index, indexes ) { + QString id = objectId( index ); + // we have to check only 0 column in order to avoid repeating items in the drag object + // - QTreeView tries to drag indices for all visible columns + if ( index.isValid() && index.column() == 0 && !id.isEmpty() ) + stream << id; } - mimeData->setData("application/vnd.text.list", encodedData); + mimeData->setData( "application/vnd.text.list", encodedData ); return mimeData; } -bool SUIT_TreeModel::dropMimeData (const QMimeData* data, Qt::DropAction action, - int row, int column, const QModelIndex& parent) +bool SUIT_TreeModel::dropMimeData( const QMimeData* data, Qt::DropAction action, + int row, int column, const QModelIndex& parent ) { - emit dropped(data, action, row, column, parent); + if ( action == Qt::IgnoreAction ) + // do nothing with data + return false; - return true; + if ( !data->hasFormat( "application/vnd.text.list" ) ) + // not supported data dropped + return false; + + if ( !parent.isValid() ) + // dropping into the top level of the model is not allowed + return false; + + // get parent object + SUIT_DataObject* pobj = object( parent ); + if ( !pobj ) + // invalid parent + return false; + + // decode mime data and collect data objects being dropped + QByteArray encodedData = data->data( "application/vnd.text.list" ); + QDataStream stream( &encodedData, QIODevice::ReadOnly ); + + DataObjectList objects; + + while ( !stream.atEnd() ) { + QString id; + stream >> id; + if ( !id.isEmpty() && searcher() ) { + SUIT_DataObject* obj = searcher()->findObject( id ); + if ( obj ) objects << obj; + } + } + + // emit signal + emit dropped( objects, pobj, row, action ); + + // return true if there's any to drop + return !objects.isEmpty(); } /*! @@ -1737,10 +1759,9 @@ SUIT_ProxyModel::SUIT_ProxyModel( QObject* parent ) { SUIT_TreeModel* model = new SUIT_TreeModel( this ); connect( model, SIGNAL( modelUpdated() ), this, SIGNAL( modelUpdated() ) ); - connect( model, SIGNAL( clicked(SUIT_DataObject*, int) ), this, SIGNAL(clicked(SUIT_DataObject*, int) ) ); - connect( model, SIGNAL( dropped(const QMimeData*, Qt::DropAction, int, int, const QModelIndex&) ), - //this, SIGNAL( dropped(const QMimeData*, Qt::DropAction, int, int, const QModelIndex&) )); - this, SLOT( onDropped(const QMimeData*, Qt::DropAction, int, int, const QModelIndex&) )); + connect( model, SIGNAL( clicked( SUIT_DataObject*, int ) ), this, SIGNAL(clicked( SUIT_DataObject*, int ) ) ); + connect( model, SIGNAL( dropped( const QList&, SUIT_DataObject*, int, Qt::DropAction ) ), + this, SIGNAL( dropped( const QList&, SUIT_DataObject*, int, Qt::DropAction ) ) ); setSourceModel( model ); setDynamicSortFilter( true ); } @@ -1756,10 +1777,9 @@ SUIT_ProxyModel::SUIT_ProxyModel( SUIT_DataObject* root, QObject* parent ) { SUIT_TreeModel* model = new SUIT_TreeModel( root, this ); connect( model, SIGNAL( modelUpdated() ), this, SIGNAL( modelUpdated() ) ); - connect( model, SIGNAL( clicked(SUIT_DataObject*, int) ), this, SIGNAL(clicked(SUIT_DataObject*, int) ) ); - connect( model, SIGNAL( dropped(const QMimeData*, Qt::DropAction, int, int, const QModelIndex&) ), - //this, SIGNAL( dropped(const QMimeData*, Qt::DropAction, int, int, const QModelIndex&) )); - this, SLOT( onDropped(const QMimeData*, Qt::DropAction, int, int, const QModelIndex&) )); + connect( model, SIGNAL( clicked( SUIT_DataObject*, int ) ), this, SIGNAL( clicked( SUIT_DataObject*, int ) ) ); + connect( model, SIGNAL( dropped( const QList&, SUIT_DataObject*, int, Qt::DropAction ) ), + this, SIGNAL( dropped( const QList&, SUIT_DataObject*, int, Qt::DropAction ) ) ); setSourceModel( model ); setDynamicSortFilter( true ); } @@ -1774,10 +1794,9 @@ SUIT_ProxyModel::SUIT_ProxyModel( SUIT_AbstractModel* model, QObject* parent ) mySortingEnabled( true ) { connect( *model, SIGNAL( modelUpdated() ), this, SIGNAL( modelUpdated() ) ); - connect( *model, SIGNAL( clicked(SUIT_DataObject*, int) ), this, SIGNAL(clicked(SUIT_DataObject*, int) ) ); - connect( *model, SIGNAL( dropped(const QMimeData*, Qt::DropAction, int, int, const QModelIndex&) ), - //this, SIGNAL( dropped(const QMimeData*, Qt::DropAction, int, int, const QModelIndex&) )); - this, SLOT( onDropped(const QMimeData*, Qt::DropAction, int, int, const QModelIndex&) )); + connect( *model, SIGNAL( clicked( SUIT_DataObject*, int ) ), this, SIGNAL( clicked( SUIT_DataObject*, int ) ) ); + connect( *model, SIGNAL( dropped( const QList&, SUIT_DataObject*, int, Qt::DropAction ) ), + this, SIGNAL( dropped( const QList&, SUIT_DataObject*, int, Qt::DropAction ) ) ); setSourceModel( *model ); setDynamicSortFilter( true ); } @@ -1964,6 +1983,12 @@ void SUIT_ProxyModel::updateTree( SUIT_DataObject* obj ) treeModel()->updateTree( obj ); } +void SUIT_ProxyModel::forgetObject( const SUIT_DataObject* obj ) +{ + if ( treeModel() ) + treeModel()->forgetObject( obj ); +} + /*! \brief Compares two model indexes for the sorting purposes. \param left first index to compare @@ -2120,7 +2145,8 @@ Qtx::Appropriate SUIT_ProxyModel::appropriate( const QString& name ) const \param flags - header flags */ -void SUIT_ProxyModel::setHeaderFlags( const QString& name, const Qtx::HeaderViewFlags flags ) { +void SUIT_ProxyModel::setHeaderFlags( const QString& name, const Qtx::HeaderViewFlags flags ) +{ if(treeModel()) treeModel()->setHeaderFlags(name, flags); } @@ -2134,7 +2160,8 @@ void SUIT_ProxyModel::setHeaderFlags( const QString& name, const Qtx::HeaderView \param name - column name \return header flags */ -Qtx::HeaderViewFlags SUIT_ProxyModel::headerFlags( const QString& name ) const { +Qtx::HeaderViewFlags SUIT_ProxyModel::headerFlags( const QString& name ) const +{ return treeModel() ? treeModel()->headerFlags( name ) : Qtx::ShowAll; } @@ -2144,7 +2171,8 @@ Qtx::HeaderViewFlags SUIT_ProxyModel::headerFlags( const QString& name ) const { \param id - column name \param state - visible state */ -void SUIT_ProxyModel::setVisibilityState(const QString& id, Qtx::VisibilityState state) { +void SUIT_ProxyModel::setVisibilityState(const QString& id, Qtx::VisibilityState state) +{ if(treeModel()) treeModel()->setVisibilityState(id,state); } @@ -2155,7 +2183,8 @@ void SUIT_ProxyModel::setVisibilityState(const QString& id, Qtx::VisibilityState \param id - column name \param state - visible state */ -void SUIT_ProxyModel::setVisibilityStateForAll(Qtx::VisibilityState state) { +void SUIT_ProxyModel::setVisibilityStateForAll(Qtx::VisibilityState state) +{ if(treeModel()) treeModel()->setVisibilityStateForAll(state); } @@ -2166,21 +2195,17 @@ void SUIT_ProxyModel::setVisibilityStateForAll(Qtx::VisibilityState state) { \param id - column name \return visible state */ -Qtx::VisibilityState SUIT_ProxyModel::visibilityState(const QString& id) const { +Qtx::VisibilityState SUIT_ProxyModel::visibilityState(const QString& id) const +{ return treeModel() ? treeModel()->visibilityState(id) : Qtx::UnpresentableState; } -void SUIT_ProxyModel::emitClicked( SUIT_DataObject* obj, const QModelIndex& index) { +void SUIT_ProxyModel::emitClicked( SUIT_DataObject* obj, const QModelIndex& index) +{ if(treeModel()) treeModel()->emitClicked(obj,index); } -void SUIT_ProxyModel::onDropped (const QMimeData* data, Qt::DropAction action, - int row, int column, const QModelIndex& parent) -{ - emit dropped(data, action, row, column, mapFromSource(parent)); -} - /*! \class SUIT_ItemDelegate \brief An SUIT_DataObject-based item delegate class. diff --git a/src/SUIT/SUIT_TreeModel.h b/src/SUIT/SUIT_TreeModel.h index 8a259da3b..9aa6973cc 100755 --- a/src/SUIT/SUIT_TreeModel.h +++ b/src/SUIT/SUIT_TreeModel.h @@ -71,6 +71,7 @@ public: virtual QAbstractItemDelegate* delegate() const = 0; virtual bool customSorting( const int ) const = 0; virtual bool lessThan( const QModelIndex& left, const QModelIndex& right ) const = 0; + virtual void forgetObject( const SUIT_DataObject* ) = 0; virtual void updateTree( const QModelIndex& ) = 0; virtual void updateTree( SUIT_DataObject* = 0 ) = 0; @@ -138,7 +139,6 @@ public: virtual QVariant headerData( int, Qt::Orientation, int = Qt::DisplayRole ) const; virtual Qt::DropActions supportedDropActions() const; - virtual bool removeRows(int row, int count, const QModelIndex &parent); virtual QModelIndex index( int, int, const QModelIndex& = QModelIndex() ) const; virtual QModelIndex parent( const QModelIndex& ) const; @@ -173,6 +173,7 @@ public: virtual bool customSorting( const int ) const; virtual bool lessThan( const QModelIndex& left, const QModelIndex& right ) const; + virtual void forgetObject( const SUIT_DataObject* ); QAbstractItemDelegate* delegate() const; @@ -191,7 +192,7 @@ public slots: signals: void modelUpdated(); void clicked( SUIT_DataObject*, int ); - void dropped( const QMimeData*, Qt::DropAction, int, int, const QModelIndex& ); + void dropped( const QList&, SUIT_DataObject*, int, Qt::DropAction ); private: void initialize(); @@ -200,6 +201,7 @@ private: TreeItem* treeItem( const QModelIndex& ) const; TreeItem* treeItem( const SUIT_DataObject* ) const; SUIT_DataObject* object( const TreeItem* ) const; + QString objectId( const QModelIndex& = QModelIndex() ) const; TreeItem* createItem( SUIT_DataObject*, TreeItem* = 0, TreeItem* = 0 ); TreeItem* createItemAtPos( SUIT_DataObject*, TreeItem* = 0, int pos=0 ); @@ -264,6 +266,7 @@ public: bool isSortingEnabled() const; bool customSorting( const int ) const; + virtual void forgetObject( const SUIT_DataObject* ); virtual bool lessThan( const QModelIndex&, const QModelIndex& ) const; virtual void registerColumn( const int group_id, const QString& name, const int custom_id ); virtual void unregisterColumn( const int group_id, const QString& name ); @@ -287,12 +290,11 @@ public slots: virtual void updateTree( const QModelIndex& ); virtual void updateTree( SUIT_DataObject* = 0 ); void setSortingEnabled( bool ); - void onDropped( const QMimeData*, Qt::DropAction, int, int, const QModelIndex& ); signals: void modelUpdated(); void clicked( SUIT_DataObject*, int ); - void dropped( const QMimeData*, Qt::DropAction, int, int, const QModelIndex& ); + void dropped( const QList&, SUIT_DataObject*, int, Qt::DropAction ); protected: SUIT_AbstractModel* treeModel() const; diff --git a/src/SalomeApp/SalomeApp_Study.cxx b/src/SalomeApp/SalomeApp_Study.cxx index f16825432..2a9e5053b 100644 --- a/src/SalomeApp/SalomeApp_Study.cxx +++ b/src/SalomeApp/SalomeApp_Study.cxx @@ -148,21 +148,17 @@ public: it = entry2SuitObject.find(theID); if (it != entry2SuitObject.end()) { // this SOobject is already added somethere - // tmp?? suit_obj = it->second; SUIT_DataObject* oldFather = suit_obj->parent(); if (oldFather) { oldFather->removeChild(suit_obj, false); - - suit_obj->updateItem(); // tmp?? + SalomeApp_Application* app = dynamic_cast( myStudy->application() ); + SUIT_AbstractModel* model = dynamic_cast(app->objectBrowser()->model()); + model->forgetObject( suit_obj ); + if (SalomeApp_DataObject* oldFatherSA = dynamic_cast(oldFather)) { - oldFatherSA->updateItem(); // tmp?? + oldFatherSA->updateItem(); } - - //entry2SuitObject.erase(it); - ////delete suit_obj; - //suit_obj = new SalomeApp_DataObject(aSObj); - //entry2SuitObject[theID] = suit_obj; } } else { @@ -170,6 +166,7 @@ public: entry2SuitObject[theID] = suit_obj; } + suit_obj->updateItem(); // define position in the data tree (in aFatherDO) to insert the aSObj int pos = -1; //int childDataObjCount = aFatherDO->childCount(); @@ -181,9 +178,9 @@ public: } } - //aFatherDO->insertChildAtPos(suit_obj, pos); - aFatherDO->insertChild(suit_obj, pos); - aFatherDO->updateItem(); // tmp?? + aFatherDO->insertChildAtPos(suit_obj, pos); + //aFatherDO->insertChild(suit_obj, pos); + aFatherDO->updateItem(); } // END: work with tree nodes structure else { // BEGIN: work with study structure