+ FEM: Improve drag and drop for FEM analysis object
This commit is contained in:
parent
bf32404975
commit
13b8d323b2
|
@ -390,6 +390,9 @@ QMimeData * TreeWidget::mimeData (const QList<QTreeWidgetItem *> items) const
|
|||
if (!vp->canDragObjects()) {
|
||||
return 0;
|
||||
}
|
||||
else if (!vp->canDragObject(obj)) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -479,6 +482,12 @@ void TreeWidget::dragMoveEvent(QDragMoveEvent *event)
|
|||
event->ignore();
|
||||
return;
|
||||
}
|
||||
|
||||
// let the view provider decide to accept the object or ignore it
|
||||
if (!vp->canDropObject(obj)) {
|
||||
event->ignore();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -134,7 +134,7 @@ public:
|
|||
/** @name Methods used by the Tree
|
||||
* If you want to take control over the
|
||||
* appearance of your object in the tree you
|
||||
* can reimplemnt this methods.
|
||||
* can reimplemnt these methods.
|
||||
*/
|
||||
//@{
|
||||
/// deliver the icon shown in the tree view
|
||||
|
@ -148,15 +148,32 @@ public:
|
|||
*/
|
||||
virtual std::vector<App::DocumentObject*> claimChildren(void) const
|
||||
{ return std::vector<App::DocumentObject*>(); }
|
||||
//@}
|
||||
|
||||
/** @name Drag and drop
|
||||
* To enable drag and drop you have to re-implement \ref canDragObjects() and
|
||||
* \ref canDropObjects() to return true. For finer control you can also re-implement
|
||||
* \ref canDragObject() or \ref canDropObject() to filter certain object types, by
|
||||
* default these methods don't filter any types.
|
||||
* To take action of drag and drop the method \ref dragObject() and \ref dropObject()
|
||||
* must be re-implemented, too.
|
||||
*/
|
||||
//@{
|
||||
/** Check whether children can be removed from the view provider by drag and drop */
|
||||
virtual bool canDragObjects() const
|
||||
{ return false; }
|
||||
/** Check whether the object can be removed from the view provider by drag and drop */
|
||||
virtual bool canDragObject(App::DocumentObject*) const
|
||||
{ return true; }
|
||||
/** Remove a child from the view provider by drag and drop */
|
||||
virtual void dragObject(App::DocumentObject*)
|
||||
{ }
|
||||
/** Check whether objects can be added to the view provider by drag and drop */
|
||||
virtual bool canDropObjects() const
|
||||
{ return false; }
|
||||
/** Check whether the object can be dropped to the view provider by drag and drop */
|
||||
virtual bool canDropObject(App::DocumentObject*) const
|
||||
{ return true; }
|
||||
/** Add an object to the view provider by drag and drop */
|
||||
virtual void dropObject(App::DocumentObject*)
|
||||
{ }
|
||||
|
|
|
@ -25,7 +25,6 @@
|
|||
|
||||
#ifndef _PreComp_
|
||||
# include <Standard_math.hxx>
|
||||
|
||||
#endif
|
||||
|
||||
#include "ViewProviderAnalysis.h"
|
||||
|
@ -35,6 +34,9 @@
|
|||
|
||||
#include <Mod/Fem/App/FemAnalysis.h>
|
||||
#include <Mod/Fem/App/FemMeshObject.h>
|
||||
#include <Mod/Fem/App/FemSetObject.h>
|
||||
#include <Mod/Fem/App/FemConstraint.h>
|
||||
#include <App/MaterialObject.h>
|
||||
|
||||
#include "TaskDlgAnalysis.h"
|
||||
|
||||
|
@ -52,7 +54,6 @@ PROPERTY_SOURCE(FemGui::ViewProviderFemAnalysis, Gui::ViewProviderDocumentObject
|
|||
ViewProviderFemAnalysis::ViewProviderFemAnalysis()
|
||||
{
|
||||
sPixmap = "Fem_Analysis";
|
||||
|
||||
}
|
||||
|
||||
ViewProviderFemAnalysis::~ViewProviderFemAnalysis()
|
||||
|
@ -165,6 +166,22 @@ bool ViewProviderFemAnalysis::canDragObjects() const
|
|||
return true;
|
||||
}
|
||||
|
||||
bool ViewProviderFemAnalysis::canDragObject(App::DocumentObject* obj) const
|
||||
{
|
||||
if (!obj)
|
||||
return false;
|
||||
if (obj->getTypeId().isDerivedFrom(Fem::FemMeshObject::getClassTypeId()))
|
||||
return true;
|
||||
else if (obj->getTypeId().isDerivedFrom(Fem::Constraint::getClassTypeId()))
|
||||
return true;
|
||||
else if (obj->getTypeId().isDerivedFrom(Fem::FemSetObject::getClassTypeId()))
|
||||
return true;
|
||||
else if (obj->getTypeId().isDerivedFrom(App::MaterialObject::getClassTypeId()))
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
void ViewProviderFemAnalysis::dragObject(App::DocumentObject* obj)
|
||||
{
|
||||
Fem::FemAnalysis* analyze = static_cast<Fem::FemAnalysis*>(getObject());
|
||||
|
@ -183,10 +200,13 @@ bool ViewProviderFemAnalysis::canDropObjects() const
|
|||
return true;
|
||||
}
|
||||
|
||||
bool ViewProviderFemAnalysis::canDropObject(App::DocumentObject* obj) const
|
||||
{
|
||||
return canDragObject(obj);
|
||||
}
|
||||
|
||||
void ViewProviderFemAnalysis::dropObject(App::DocumentObject* obj)
|
||||
{
|
||||
if (!obj || !obj->getTypeId().isDerivedFrom(Fem::FemMeshObject::getClassTypeId()))
|
||||
return;
|
||||
Fem::FemAnalysis* analyze = static_cast<Fem::FemAnalysis*>(getObject());
|
||||
std::vector<App::DocumentObject*> fem = analyze->Member.getValues();
|
||||
fem.push_back(obj);
|
||||
|
|
|
@ -67,10 +67,14 @@ public:
|
|||
//@{
|
||||
/// Returns true if the view provider generally supports dragging objects
|
||||
bool canDragObjects() const;
|
||||
/// Check whether the object can be removed from the view provider by drag and drop
|
||||
bool canDragObject(App::DocumentObject*) const;
|
||||
/// Starts to drag the object
|
||||
void dragObject(App::DocumentObject*);
|
||||
/// Returns true if the view provider generally accepts dropping of objects
|
||||
bool canDropObjects() const;
|
||||
/// Check whether the object can be dropped to the view provider by drag and drop
|
||||
bool canDropObject(App::DocumentObject*) const;
|
||||
/// If the dropped object type is accepted the object will be added as child
|
||||
void dropObject(App::DocumentObject*);
|
||||
//@}
|
||||
|
|
Loading…
Reference in New Issue
Block a user