+ extend ActionFunction and use in mesh view provider

This commit is contained in:
wmayer
2015-03-31 01:02:16 +02:00
parent bbb3e3f459
commit 9ce46db813
4 changed files with 78 additions and 14 deletions

View File

@@ -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()();
}