Skip to content

Commit

Permalink
Remove redundant drag'n'drop interface
Browse files Browse the repository at this point in the history
In the long time of parallel assembly development an own drag'n'drop interface has been added to master and assembly branch. After merge both have been available. This commit removes one and keeps the more extensive implementation
  • Loading branch information
ickby authored and wwmayer committed Oct 8, 2016
1 parent 0a53953 commit cd53eb2
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 130 deletions.
10 changes: 0 additions & 10 deletions src/Gui/Tree.cpp
Expand Up @@ -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
Expand Down Expand Up @@ -1444,15 +1443,6 @@ void DocumentObjectItem::testStatus()
this->setIcon(0, icon_mod);
}

bool DocumentObjectItem::allowDrop(const std::vector<const App::DocumentObject*> &objList,Qt::KeyboardModifiers keys,Qt::MouseButtons mouseBts,const QPoint &pos)
{
return viewObject->allowDrop(objList,keys,mouseBts,pos);
}
void DocumentObjectItem::drop(const std::vector<const App::DocumentObject*> &objList,Qt::KeyboardModifiers keys,Qt::MouseButtons mouseBts,const QPoint &pos)
{
viewObject->drop(objList,keys,mouseBts,pos);
}

void DocumentObjectItem::displayStatusInfo()
{
App::DocumentObject* Obj = viewObject->getObject();
Expand Down
3 changes: 0 additions & 3 deletions src/Gui/Tree.h
Expand Up @@ -203,9 +203,6 @@ class DocumentObjectItem : public QTreeWidgetItem
void setData(int column, int role, const QVariant & value);
bool isChildOfItem(DocumentObjectItem*);

bool allowDrop(const std::vector<const App::DocumentObject*> &objList,Qt::KeyboardModifiers keys,Qt::MouseButtons mouseBts,const QPoint &pos);
void drop(const std::vector<const App::DocumentObject*> &objList,Qt::KeyboardModifiers keys,Qt::MouseButtons mouseBts,const QPoint &pos);

protected:
void slotChangeIcon();
void slotChangeToolTip(const QString&);
Expand Down
23 changes: 0 additions & 23 deletions src/Gui/ViewProviderDocumentObject.cpp
Expand Up @@ -284,26 +284,3 @@ PyObject* ViewProviderDocumentObject::getPyObject()
pyViewObject->IncRef();
return pyViewObject;
}

bool ViewProviderDocumentObject::allowDrop(const std::vector<const App::DocumentObject*> &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<const App::DocumentObject*> &objList,
Qt::KeyboardModifiers keys,
Qt::MouseButtons mouseBts,
const QPoint &pos)
{
Q_UNUSED(objList);
Q_UNUSED(keys);
Q_UNUSED(mouseBts);
Q_UNUSED(pos);
}
14 changes: 0 additions & 14 deletions src/Gui/ViewProviderDocumentObject.h
Expand Up @@ -93,20 +93,6 @@ class GuiExport ViewProviderDocumentObject : public ViewProvider
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<const App::DocumentObject*> &objList,
Qt::KeyboardModifiers keys,
Qt::MouseButtons mouseBts,
const QPoint &pos);
/// get called if the user drops some objects
virtual void drop(const std::vector<const App::DocumentObject*> &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.
Expand Down
62 changes: 0 additions & 62 deletions src/Gui/ViewProviderDocumentObjectGroup.cpp
Expand Up @@ -73,68 +73,6 @@ std::vector<std::string> ViewProviderDocumentObjectGroup::getDisplayModes(void)
return std::vector<std::string>();
}

bool ViewProviderDocumentObjectGroup::allowDrop(const std::vector<const App::DocumentObject*> &objList,
Qt::KeyboardModifiers keys,
Qt::MouseButtons mouseBts,
const QPoint &pos)
Q_UNUSED(keys);
Q_UNUSED(mouseBts);
Q_UNUSED(pos);

for( std::vector<const App::DocumentObject*>::const_iterator it = objList.begin();it!=objList.end();++it)
if ((*it)->getTypeId().isDerivedFrom(App::DocumentObjectGroup::getClassTypeId())) {
if (static_cast<App::DocumentObjectGroup*>(getObject())->isChildOf(
static_cast<const App::DocumentObjectGroup*>(*it))) {
return false;
}
}

return true;*/
Base::Console().Message("allow drop called");
}

void ViewProviderDocumentObjectGroup::drop(const std::vector<const App::DocumentObject*> &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<App::DocumentObjectGroup*>(getObject());
App::Document* doc = grp->getDocument();
Gui::Document* gui = Gui::Application::Instance->getDocument(doc);
gui->openCommand("Move object");
for( std::vector<const App::DocumentObject*>::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();
Expand Down
10 changes: 0 additions & 10 deletions src/Gui/ViewProviderDocumentObjectGroup.h
Expand Up @@ -47,16 +47,6 @@ class GuiExport ViewProviderDocumentObjectGroup : public ViewProviderDocumentObj
std::vector<std::string> 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<const App::DocumentObject*> &objList,
Qt::KeyboardModifiers keys,
Qt::MouseButtons mouseBts,
const QPoint &pos);
/// get called if the user drops some objects
virtual void drop(const std::vector<const App::DocumentObject*> &objList,
Qt::KeyboardModifiers keys,
Qt::MouseButtons mouseBts,
const QPoint &pos);

protected:
void getViewProviders(std::vector<ViewProviderDocumentObject*>&) const;
Expand Down
51 changes: 43 additions & 8 deletions src/Gui/ViewProviderGroupExtension.cpp
Expand Up @@ -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<App::GroupExtension>();
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<App::GroupExtension>()))
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<App::DocumentObject*>(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 {
Expand Down

0 comments on commit cd53eb2

Please sign in to comment.