diff --git a/src/Gui/Tree.cpp b/src/Gui/Tree.cpp index 98f566937..64e260f95 100644 --- a/src/Gui/Tree.cpp +++ b/src/Gui/Tree.cpp @@ -564,7 +564,6 @@ void TreeWidget::dropEvent(QDropEvent *event) // now add the object to the target object vp->dropObject(obj); } - targetItemObj->drop(dropObjects,event->keyboardModifiers(),event->mouseButtons(),event->pos()); } else if (targetitem->type() == TreeWidget::DocumentType) { // Open command @@ -1444,15 +1443,6 @@ void DocumentObjectItem::testStatus() this->setIcon(0, icon_mod); } -bool DocumentObjectItem::allowDrop(const std::vector &objList,Qt::KeyboardModifiers keys,Qt::MouseButtons mouseBts,const QPoint &pos) -{ - return viewObject->allowDrop(objList,keys,mouseBts,pos); -} -void DocumentObjectItem::drop(const std::vector &objList,Qt::KeyboardModifiers keys,Qt::MouseButtons mouseBts,const QPoint &pos) -{ - viewObject->drop(objList,keys,mouseBts,pos); -} - void DocumentObjectItem::displayStatusInfo() { App::DocumentObject* Obj = viewObject->getObject(); diff --git a/src/Gui/Tree.h b/src/Gui/Tree.h index f4ce69a0f..fb3e3f3db 100644 --- a/src/Gui/Tree.h +++ b/src/Gui/Tree.h @@ -203,9 +203,6 @@ public: void setData(int column, int role, const QVariant & value); bool isChildOfItem(DocumentObjectItem*); - bool allowDrop(const std::vector &objList,Qt::KeyboardModifiers keys,Qt::MouseButtons mouseBts,const QPoint &pos); - void drop(const std::vector &objList,Qt::KeyboardModifiers keys,Qt::MouseButtons mouseBts,const QPoint &pos); - protected: void slotChangeIcon(); void slotChangeToolTip(const QString&); diff --git a/src/Gui/ViewProviderDocumentObject.cpp b/src/Gui/ViewProviderDocumentObject.cpp index e9717f57c..9dbd97f85 100644 --- a/src/Gui/ViewProviderDocumentObject.cpp +++ b/src/Gui/ViewProviderDocumentObject.cpp @@ -284,26 +284,3 @@ PyObject* ViewProviderDocumentObject::getPyObject() pyViewObject->IncRef(); return pyViewObject; } - -bool ViewProviderDocumentObject::allowDrop(const std::vector &objList, - Qt::KeyboardModifiers keys, - Qt::MouseButtons mouseBts, - const QPoint &pos) -{ - Q_UNUSED(objList); - Q_UNUSED(keys); - Q_UNUSED(mouseBts); - Q_UNUSED(pos); - return false; -} - -void ViewProviderDocumentObject::drop(const std::vector &objList, - Qt::KeyboardModifiers keys, - Qt::MouseButtons mouseBts, - const QPoint &pos) -{ - Q_UNUSED(objList); - Q_UNUSED(keys); - Q_UNUSED(mouseBts); - Q_UNUSED(pos); -} diff --git a/src/Gui/ViewProviderDocumentObject.h b/src/Gui/ViewProviderDocumentObject.h index 56e658f83..358b247c4 100644 --- a/src/Gui/ViewProviderDocumentObject.h +++ b/src/Gui/ViewProviderDocumentObject.h @@ -93,20 +93,6 @@ public: virtual void finishRestoring(); //@} - /** @name drag & drop handling */ - //@{ - /// get called if the user hover over a object in the tree - virtual bool allowDrop(const std::vector &objList, - Qt::KeyboardModifiers keys, - Qt::MouseButtons mouseBts, - const QPoint &pos); - /// get called if the user drops some objects - virtual void drop(const std::vector &objList, - Qt::KeyboardModifiers keys, - Qt::MouseButtons mouseBts, - const QPoint &pos); - //@} - protected: /*! Get the active mdi view of the document this view provider is part of. @note The returned mdi view doesn't need to be a 3d view but can be e.g. diff --git a/src/Gui/ViewProviderDocumentObjectGroup.cpp b/src/Gui/ViewProviderDocumentObjectGroup.cpp index a24dd88b4..018755f13 100644 --- a/src/Gui/ViewProviderDocumentObjectGroup.cpp +++ b/src/Gui/ViewProviderDocumentObjectGroup.cpp @@ -73,68 +73,6 @@ std::vector ViewProviderDocumentObjectGroup::getDisplayModes(void) return std::vector(); } -bool ViewProviderDocumentObjectGroup::allowDrop(const std::vector &objList, - Qt::KeyboardModifiers keys, - Qt::MouseButtons mouseBts, - const QPoint &pos) - Q_UNUSED(keys); - Q_UNUSED(mouseBts); - Q_UNUSED(pos); - - for( std::vector::const_iterator it = objList.begin();it!=objList.end();++it) - if ((*it)->getTypeId().isDerivedFrom(App::DocumentObjectGroup::getClassTypeId())) { - if (static_cast(getObject())->isChildOf( - static_cast(*it))) { - return false; - } - } - - return true;*/ - Base::Console().Message("allow drop called"); -} - -void ViewProviderDocumentObjectGroup::drop(const std::vector &objList, - Qt::KeyboardModifiers keys, - Qt::MouseButtons mouseBts, - const QPoint &pos) -{ - Q_UNUSED(keys); - Q_UNUSED(mouseBts); - Q_UNUSED(pos); - - // Open command - App::DocumentObjectGroup* grp = static_cast(getObject()); - App::Document* doc = grp->getDocument(); - Gui::Document* gui = Gui::Application::Instance->getDocument(doc); - gui->openCommand("Move object"); - for( std::vector::const_iterator it = objList.begin();it!=objList.end();++it) { - // get document object - const App::DocumentObject* obj = *it; - const App::DocumentObject* par = App::DocumentObjectGroup::getGroupOfObject(obj); - if (par) { - // allow an object to be in one group only - QString cmd; - cmd = QString::fromLatin1("App.getDocument(\"%1\").getObject(\"%2\").removeObject(" - "App.getDocument(\"%1\").getObject(\"%3\"))") - .arg(QString::fromLatin1(doc->getName())) - .arg(QString::fromLatin1(par->getNameInDocument())) - .arg(QString::fromLatin1(obj->getNameInDocument())); - Gui::Command::runCommand(Gui::Command::App, cmd.toUtf8()); - } - - // build Python command for execution - QString cmd; - cmd = QString::fromLatin1("App.getDocument(\"%1\").getObject(\"%2\").addObject(" - "App.getDocument(\"%1\").getObject(\"%3\"))") - .arg(QString::fromLatin1(doc->getName())) - .arg(QString::fromLatin1(grp->getNameInDocument())) - .arg(QString::fromLatin1(obj->getNameInDocument())); - - Gui::Command::runCommand(Gui::Command::App, cmd.toUtf8()); - } - gui->commitCommand(); -} - bool ViewProviderDocumentObjectGroup::isShow(void) const { return Visibility.getValue(); diff --git a/src/Gui/ViewProviderDocumentObjectGroup.h b/src/Gui/ViewProviderDocumentObjectGroup.h index 4eb32230e..9a6d85ed3 100644 --- a/src/Gui/ViewProviderDocumentObjectGroup.h +++ b/src/Gui/ViewProviderDocumentObjectGroup.h @@ -47,16 +47,6 @@ public: std::vector getDisplayModes(void) const; bool isShow(void) const; - /// get called if the user hover over a object in the tree - virtual bool allowDrop(const std::vector &objList, - Qt::KeyboardModifiers keys, - Qt::MouseButtons mouseBts, - const QPoint &pos); - /// get called if the user drops some objects - virtual void drop(const std::vector &objList, - Qt::KeyboardModifiers keys, - Qt::MouseButtons mouseBts, - const QPoint &pos); protected: void getViewProviders(std::vector&) const; diff --git a/src/Gui/ViewProviderGroupExtension.cpp b/src/Gui/ViewProviderGroupExtension.cpp index d4d6f398e..d77af3076 100644 --- a/src/Gui/ViewProviderGroupExtension.cpp +++ b/src/Gui/ViewProviderGroupExtension.cpp @@ -76,23 +76,58 @@ bool ViewProviderGroupExtension::extensionCanDropObjects() const { bool ViewProviderGroupExtension::extensionCanDropObject(App::DocumentObject* obj) const { - //we cannot drop anything into the group. We need to find the correct App extension to ask - //if this is a supported type, there should only be one auto vector = getExtendedViewProvider()->getObject()->getExtensionsDerivedFromType(); assert(vector.size() == 1); - if(vector[0]->allowObject(obj)) + App::GroupExtension* group = vector.front(); + + //we cannot drop thing of this group into it again + if (group->hasObject(obj)) + return false; + + //group into group? + if (obj->hasExtension(App::GroupExtension::getClassTypeId())) + if (group->isChildOf(obj->getExtensionByType())) + return false; + + //We need to find the correct App extension to ask if this is a supported type, there should only be one + if(group->allowObject(obj)) return true; - + return false; } void ViewProviderGroupExtension::extensionDropObject(App::DocumentObject* obj) { - Gui::Command::doCommand(Gui::Command::Doc,"App.getDocument(\"%s\").getObject(\"%s\").addObject(" - "App.getDocument(\"%s\").getObject(\"%s\"))", - getExtendedViewProvider()->getObject()->getDocument()->getName(), getExtendedViewProvider()->getObject()->getNameInDocument(), - obj->getDocument()->getName(), obj->getNameInDocument() ); + // Open command + App::DocumentObject* grp = static_cast(getExtendedViewProvider()->getObject()); + App::Document* doc = grp->getDocument(); + Gui::Document* gui = Gui::Application::Instance->getDocument(doc); + gui->openCommand("Move object"); + + const App::DocumentObject* par = App::GroupExtension::getGroupOfObject(obj); + if (par) { + // allow an object to be in one group only + QString cmd; + cmd = QString::fromLatin1("App.getDocument(\"%1\").getObject(\"%2\").removeObject(" + "App.getDocument(\"%1\").getObject(\"%3\"))") + .arg(QString::fromLatin1(doc->getName())) + .arg(QString::fromLatin1(par->getNameInDocument())) + .arg(QString::fromLatin1(obj->getNameInDocument())); + Gui::Application::Instance->runPythonCode(cmd.toUtf8()); + } + + // build Python command for execution + QString cmd; + cmd = QString::fromLatin1("App.getDocument(\"%1\").getObject(\"%2\").addObject(" + "App.getDocument(\"%1\").getObject(\"%3\"))") + .arg(QString::fromLatin1(doc->getName())) + .arg(QString::fromLatin1(grp->getNameInDocument())) + .arg(QString::fromLatin1(obj->getNameInDocument())); + + Gui::Application::Instance->runPythonCode(cmd.toUtf8()); + + gui->commitCommand(); } std::vector< App::DocumentObject* > ViewProviderGroupExtension::extensionClaimChildren(void) const {