Part: allow to open attachment editor via context-menu
This commit is contained in:
@@ -36,6 +36,7 @@ class ViewProviderTube:
|
||||
def __init__(self, obj):
|
||||
''' Set this object to the proxy object of the actual view provider '''
|
||||
obj.Proxy = self
|
||||
obj.addExtension("PartGui::ViewProviderAttachExtensionPython", self)
|
||||
|
||||
def attach(self, obj):
|
||||
''' Setup the scene sub-graph of the view provider, this method is mandatory '''
|
||||
|
||||
@@ -28,12 +28,17 @@
|
||||
# define _USE_MATH_DEFINES
|
||||
# include <cmath>
|
||||
# endif //_MSC_VER
|
||||
# include <QAction>
|
||||
# include <QMenu>
|
||||
#endif
|
||||
|
||||
#include "ViewProviderAttachExtension.h"
|
||||
#include "TaskAttacher.h"
|
||||
#include <Mod/Part/App/AttachExtension.h>
|
||||
|
||||
#include <Gui/ActionFunction.h>
|
||||
#include <Gui/BitmapFactory.h>
|
||||
#include <Gui/Control.h>
|
||||
|
||||
using namespace PartGui;
|
||||
|
||||
@@ -104,6 +109,36 @@ void ViewProviderAttachExtension::extensionUpdateData(const App::Property* prop)
|
||||
|
||||
}
|
||||
|
||||
void ViewProviderAttachExtension::extensionSetupContextMenu(QMenu* menu, QObject*, const char*)
|
||||
{
|
||||
// toggle command to display components
|
||||
Gui::ActionFunction* func = new Gui::ActionFunction(menu);
|
||||
QAction* act = menu->addAction(QObject::tr("Attachment editor"));
|
||||
if (Gui::Control().activeDialog())
|
||||
act->setDisabled(true);
|
||||
func->trigger(act, boost::bind(&ViewProviderAttachExtension::showAttachmentEditor, this));
|
||||
}
|
||||
|
||||
void ViewProviderAttachExtension::showAttachmentEditor()
|
||||
{
|
||||
// See PropertyEnumAttacherItem::openTask()
|
||||
Gui::TaskView::TaskDialog* dlg = Gui::Control().activeDialog();
|
||||
TaskDlgAttacher* task;
|
||||
task = qobject_cast<TaskDlgAttacher*>(dlg);
|
||||
|
||||
if (dlg && !task) {
|
||||
// there is already another task dialog which must be closed first
|
||||
Gui::Control().showDialog(dlg);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!task) {
|
||||
task = new TaskDlgAttacher(getExtendedViewProvider());
|
||||
}
|
||||
|
||||
Gui::Control().showDialog(task);
|
||||
}
|
||||
|
||||
namespace Gui {
|
||||
EXTENSION_PROPERTY_SOURCE_TEMPLATE(PartGui::ViewProviderAttachExtensionPython, PartGui::ViewProviderAttachExtension)
|
||||
|
||||
|
||||
@@ -42,7 +42,10 @@ public:
|
||||
virtual QIcon extensionMergeOverlayIcons(const QIcon & orig) const override;
|
||||
|
||||
virtual void extensionUpdateData(const App::Property*) override;
|
||||
virtual void extensionSetupContextMenu(QMenu*, QObject*, const char*) override;
|
||||
|
||||
private:
|
||||
void showAttachmentEditor();
|
||||
};
|
||||
|
||||
typedef Gui::ViewProviderExtensionPythonT<PartGui::ViewProviderAttachExtension> ViewProviderAttachExtensionPython;
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#define PARTGUI_VIEWPROVIDERPRIMITIVE_H
|
||||
|
||||
#include <Mod/Part/Gui/ViewProvider.h>
|
||||
#include <Mod/Part/Gui/ViewProviderAttachExtension.h>
|
||||
|
||||
|
||||
namespace PartGui {
|
||||
@@ -47,6 +48,9 @@ protected:
|
||||
|
||||
private:
|
||||
void startDefaultEditMode();
|
||||
|
||||
private:
|
||||
ViewProviderAttachExtension extension;
|
||||
};
|
||||
|
||||
} // namespace PartGui
|
||||
|
||||
@@ -96,6 +96,8 @@ void ViewProvider::setupContextMenu(QMenu* menu, QObject* receiver, const char*
|
||||
{
|
||||
QAction* act = menu->addAction(QObject::tr("Set colors..."), receiver, member);
|
||||
act->setData(QVariant((int)ViewProvider::Color));
|
||||
// Call the extensions
|
||||
Gui::ViewProvider::setupContextMenu(menu, receiver, member);
|
||||
}
|
||||
|
||||
bool ViewProvider::setEdit(int ModNum)
|
||||
|
||||
Reference in New Issue
Block a user