drag and drop for compound objects

This commit is contained in:
wmayer
2017-08-11 12:53:35 +02:00
parent 24bdf806e2
commit d84c2d3544
2 changed files with 49 additions and 0 deletions

View File

@@ -113,3 +113,44 @@ void ViewProviderCompound::updateData(const App::Property* prop)
}
}
}
bool ViewProviderCompound::canDragObjects() const
{
return true;
}
bool ViewProviderCompound::canDragObject(App::DocumentObject* obj) const
{
return obj->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId());
}
void ViewProviderCompound::dragObject(App::DocumentObject* obj)
{
Part::Compound* pComp = static_cast<Part::Compound*>(getObject());
std::vector<App::DocumentObject*> pShapes = pComp->Links.getValues();
for (std::vector<App::DocumentObject*>::iterator it = pShapes.begin(); it != pShapes.end(); ++it) {
if (*it == obj) {
pShapes.erase(it);
pComp->Links.setValues(pShapes);
break;
}
}
}
bool ViewProviderCompound::canDropObjects() const
{
return true;
}
bool ViewProviderCompound::canDropObject(App::DocumentObject* obj) const
{
return obj->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId());
}
void ViewProviderCompound::dropObject(App::DocumentObject* obj)
{
Part::Compound* pComp = static_cast<Part::Compound*>(getObject());
std::vector<App::DocumentObject*> pShapes = pComp->Links.getValues();
pShapes.push_back(obj);
pComp->Links.setValues(pShapes);
}

View File

@@ -41,6 +41,14 @@ public:
std::vector<App::DocumentObject*> claimChildren() const;
bool onDelete(const std::vector<std::string> &);
/// drag and drop
bool canDragObjects() const;
bool canDragObject(App::DocumentObject*) const;
void dragObject(App::DocumentObject*);
bool canDropObjects() const;
bool canDropObject(App::DocumentObject*) const;
void dropObject(App::DocumentObject*);
protected:
void updateData(const App::Property*);
};