+ extend ActionFunction and use in mesh view provider
This commit is contained in:
parent
bbb3e3f459
commit
9ce46db813
|
@ -37,7 +37,9 @@ namespace Gui {
|
|||
class ActionFunctionPrivate
|
||||
{
|
||||
public:
|
||||
QMap<QAction*, boost::function<void()> > actionFuncMap;
|
||||
QMap<QAction*, boost::function<void()> > triggerMap;
|
||||
QMap<QAction*, boost::function<void(bool)> > toggleMap;
|
||||
QMap<QAction*, boost::function<void()> > hoverMap;
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -50,21 +52,61 @@ ActionFunction::~ActionFunction()
|
|||
{
|
||||
}
|
||||
|
||||
void ActionFunction::mapSignal(QAction* action, boost::function<void()> func)
|
||||
void ActionFunction::trigger(QAction* action, boost::function<void()> func)
|
||||
{
|
||||
Q_D(ActionFunction);
|
||||
|
||||
d->actionFuncMap[action] = func;
|
||||
connect(action, SIGNAL(triggered()), this, SLOT(trigger()));
|
||||
d->triggerMap[action] = func;
|
||||
connect(action, SIGNAL(triggered()), this, SLOT(triggered()));
|
||||
}
|
||||
|
||||
void ActionFunction::trigger()
|
||||
void ActionFunction::triggered()
|
||||
{
|
||||
Q_D(ActionFunction);
|
||||
|
||||
QAction* a = qobject_cast<QAction*>(sender());
|
||||
QMap<QAction*, boost::function<void()> >::iterator it = d->actionFuncMap.find(a);
|
||||
if (it != d->actionFuncMap.end()) {
|
||||
QMap<QAction*, boost::function<void()> >::iterator it = d->triggerMap.find(a);
|
||||
if (it != d->triggerMap.end()) {
|
||||
// invoke the class function here
|
||||
it.value()();
|
||||
}
|
||||
}
|
||||
|
||||
void ActionFunction::toggle(QAction* action, boost::function<void(bool)> func)
|
||||
{
|
||||
Q_D(ActionFunction);
|
||||
|
||||
d->toggleMap[action] = func;
|
||||
connect(action, SIGNAL(toggled(bool)), this, SLOT(toggled(bool)));
|
||||
}
|
||||
|
||||
void ActionFunction::toggled(bool on)
|
||||
{
|
||||
Q_D(ActionFunction);
|
||||
|
||||
QAction* a = qobject_cast<QAction*>(sender());
|
||||
QMap<QAction*, boost::function<void(bool)> >::iterator it = d->toggleMap.find(a);
|
||||
if (it != d->toggleMap.end()) {
|
||||
// invoke the class function here
|
||||
it.value()(on);
|
||||
}
|
||||
}
|
||||
|
||||
void ActionFunction::hover(QAction* action, boost::function<void()> func)
|
||||
{
|
||||
Q_D(ActionFunction);
|
||||
|
||||
d->hoverMap[action] = func;
|
||||
connect(action, SIGNAL(hovered()), this, SLOT(hovered()));
|
||||
}
|
||||
|
||||
void ActionFunction::hovered()
|
||||
{
|
||||
Q_D(ActionFunction);
|
||||
|
||||
QAction* a = qobject_cast<QAction*>(sender());
|
||||
QMap<QAction*, boost::function<void()> >::iterator it = d->hoverMap.find(a);
|
||||
if (it != d->hoverMap.end()) {
|
||||
// invoke the class function here
|
||||
it.value()();
|
||||
}
|
||||
|
|
|
@ -45,13 +45,13 @@ class ActionFunctionPrivate;
|
|||
Gui::ActionFunction* func = new Gui::ActionFunction(menu);
|
||||
|
||||
QAction* a1 = menu->addAction(QObject::tr("Menu item 1..."));
|
||||
func->mapSignal(a1, boost::bind(&MyViewProvider::doItem1, this));
|
||||
func->triggered(a1, boost::bind(&MyViewProvider::doItem1, this));
|
||||
|
||||
QAction* a2 = menu->addAction(QObject::tr("Menu item 2..."));
|
||||
func->mapSignal(a2, boost::bind(&MyViewProvider::doItem2, this));
|
||||
func->triggered(a2, boost::bind(&MyViewProvider::doItem2, this));
|
||||
|
||||
QAction* a3 = menu->addAction(QObject::tr("Menu item 3..."));
|
||||
func->mapSignal(a3, boost::bind(&MyViewProvider::doItem3, this));
|
||||
func->triggered(a3, boost::bind(&MyViewProvider::doItem3, this));
|
||||
}
|
||||
\endcode
|
||||
|
||||
|
@ -71,10 +71,14 @@ public:
|
|||
/*!
|
||||
Connects the QAction's triggered() signal with the function \a func
|
||||
*/
|
||||
void mapSignal(QAction* a, boost::function<void()> func);
|
||||
void trigger(QAction* a, boost::function<void()> func);
|
||||
void toggle(QAction* a, boost::function<void(bool)> func);
|
||||
void hover(QAction* a, boost::function<void()> func);
|
||||
|
||||
private Q_SLOTS:
|
||||
void trigger();
|
||||
void triggered();
|
||||
void toggled(bool);
|
||||
void hovered();
|
||||
|
||||
private:
|
||||
QScopedPointer<ActionFunctionPrivate> d_ptr;
|
||||
|
|
|
@ -79,6 +79,7 @@
|
|||
#include <Gui/WaitCursor.h>
|
||||
#include <Gui/View3DInventor.h>
|
||||
#include <Gui/View3DInventorViewer.h>
|
||||
#include <Gui/ActionFunction.h>
|
||||
|
||||
#include <Mod/Mesh/App/Core/Algorithm.h>
|
||||
#include <Mod/Mesh/App/Core/Evaluation.h>
|
||||
|
@ -92,6 +93,7 @@
|
|||
#include <Mod/Mesh/App/Mesh.h>
|
||||
#include <Mod/Mesh/App/MeshFeature.h>
|
||||
#include <zipios++/gzipoutputstream.h>
|
||||
#include <boost/bind.hpp>
|
||||
|
||||
#include "ViewProvider.h"
|
||||
#include "SoFCIndexedFaceSet.h"
|
||||
|
@ -577,8 +579,13 @@ bool ViewProviderMesh::exportToVrml(const char* filename, const MeshCore::Materi
|
|||
void ViewProviderMesh::setupContextMenu(QMenu* menu, QObject* receiver, const char* member)
|
||||
{
|
||||
ViewProviderGeometryObject::setupContextMenu(menu, receiver, member);
|
||||
QAction* act = menu->addAction(QObject::tr("Display components"), receiver, member);
|
||||
act->setData(QVariant((int)ViewProvider::Color));
|
||||
|
||||
// toggle command to display components
|
||||
Gui::ActionFunction* func = new Gui::ActionFunction(menu);
|
||||
QAction* act = menu->addAction(QObject::tr("Display components"));
|
||||
act->setCheckable(true);
|
||||
act->setChecked(pcMatBinding->value.getValue() == SoMaterialBinding::PER_FACE);
|
||||
func->toggle(act, boost::bind(&ViewProviderMesh::setHighlightedComponents, this, _1));
|
||||
}
|
||||
|
||||
bool ViewProviderMesh::setEdit(int ModNum)
|
||||
|
@ -1680,6 +1687,16 @@ void ViewProviderMesh::unhighlightSelection()
|
|||
pcShapeMaterial->diffuseColor.setValue(c.r,c.g,c.b);
|
||||
}
|
||||
|
||||
void ViewProviderMesh::setHighlightedComponents(bool on)
|
||||
{
|
||||
if (on) {
|
||||
highlightComponents();
|
||||
}
|
||||
else {
|
||||
unhighlightSelection();
|
||||
}
|
||||
}
|
||||
|
||||
void ViewProviderMesh::highlightComponents()
|
||||
{
|
||||
const Mesh::MeshObject& rMesh = static_cast<Mesh::Feature*>(pcObject)->Mesh.getValue();
|
||||
|
|
|
@ -171,6 +171,7 @@ protected:
|
|||
void highlightSelection();
|
||||
void unhighlightSelection();
|
||||
void highlightComponents();
|
||||
void setHighlightedComponents(bool);
|
||||
|
||||
virtual SoShape* getShapeNode() const;
|
||||
virtual SoNode* getCoordNode() const;
|
||||
|
|
Loading…
Reference in New Issue
Block a user