+ support context-menu in Python view providers
This commit is contained in:
parent
9ce46db813
commit
1d4de73415
|
@ -59,6 +59,7 @@
|
||||||
#include "Application.h"
|
#include "Application.h"
|
||||||
#include "BitmapFactory.h"
|
#include "BitmapFactory.h"
|
||||||
#include "Document.h"
|
#include "Document.h"
|
||||||
|
#include "WidgetFactory.h"
|
||||||
#include <App/DocumentObjectPy.h>
|
#include <App/DocumentObjectPy.h>
|
||||||
#include <App/GeoFeature.h>
|
#include <App/GeoFeature.h>
|
||||||
#include <App/PropertyGeo.h>
|
#include <App/PropertyGeo.h>
|
||||||
|
@ -516,6 +517,40 @@ bool ViewProviderPythonFeatureImp::doubleClicked(void)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ViewProviderPythonFeatureImp::setupContextMenu(QMenu* menu)
|
||||||
|
{
|
||||||
|
// Run the attach method of the proxy object.
|
||||||
|
Base::PyGILStateLocker lock;
|
||||||
|
try {
|
||||||
|
App::Property* proxy = object->getPropertyByName("Proxy");
|
||||||
|
if (proxy && proxy->getTypeId() == App::PropertyPythonObject::getClassTypeId()) {
|
||||||
|
Py::Object vp = static_cast<App::PropertyPythonObject*>(proxy)->getValue();
|
||||||
|
if (vp.hasAttr(std::string("setupContextMenu"))) {
|
||||||
|
if (vp.hasAttr("__object__")) {
|
||||||
|
PythonWrapper wrap;
|
||||||
|
wrap.loadGuiModule();
|
||||||
|
Py::Callable method(vp.getAttr(std::string("setupContextMenu")));
|
||||||
|
Py::Tuple args(1);
|
||||||
|
args.setItem(0, wrap.fromQWidget(menu, "QMenu"));
|
||||||
|
method.apply(args);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
PythonWrapper wrap;
|
||||||
|
wrap.loadGuiModule();
|
||||||
|
Py::Callable method(vp.getAttr(std::string("setupContextMenu")));
|
||||||
|
Py::Tuple args(2);
|
||||||
|
args.setItem(0, Py::Object(object->getPyObject(), true));
|
||||||
|
args.setItem(1, wrap.fromQWidget(menu, "QMenu"));
|
||||||
|
method.apply(args);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Py::Exception&) {
|
||||||
|
Base::PyException e; // extract the Python error text
|
||||||
|
e.ReportException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void ViewProviderPythonFeatureImp::attach(App::DocumentObject *pcObject)
|
void ViewProviderPythonFeatureImp::attach(App::DocumentObject *pcObject)
|
||||||
{
|
{
|
||||||
|
|
|
@ -55,6 +55,7 @@ public:
|
||||||
bool setEdit(int ModNum);
|
bool setEdit(int ModNum);
|
||||||
bool unsetEdit(int ModNum);
|
bool unsetEdit(int ModNum);
|
||||||
bool doubleClicked(void);
|
bool doubleClicked(void);
|
||||||
|
void setupContextMenu(QMenu* menu);
|
||||||
|
|
||||||
/** @name Update data methods*/
|
/** @name Update data methods*/
|
||||||
//@{
|
//@{
|
||||||
|
@ -319,6 +320,14 @@ protected:
|
||||||
if (!ok) ViewProviderT::unsetEdit(ModNum);
|
if (!ok) ViewProviderT::unsetEdit(ModNum);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
virtual void setupContextMenu(QMenu* menu, QObject* recipient, const char* member)
|
||||||
|
{
|
||||||
|
ViewProviderT::setupContextMenu(menu, recipient, member);
|
||||||
|
imp->setupContextMenu(menu);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
virtual bool doubleClicked(void)
|
virtual bool doubleClicked(void)
|
||||||
{
|
{
|
||||||
bool ok = imp->doubleClicked();
|
bool ok = imp->doubleClicked();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user