diff --git a/src/Gui/Action.cpp b/src/Gui/Action.cpp index 5e39c8a51..5cdc6d412 100644 --- a/src/Gui/Action.cpp +++ b/src/Gui/Action.cpp @@ -31,6 +31,7 @@ # include # include # include +# include # include # include #endif @@ -55,13 +56,21 @@ using namespace Gui::Dialog; * Constructs an action called \a name with parent \a parent. It also stores a pointer * to the command object. */ -Action::Action (Command* pcCmd,QObject * parent) +Action::Action (Command* pcCmd, QObject * parent) : QObject(parent), _action(new QAction( this )), _pcCmd(pcCmd) { _action->setObjectName(QString::fromAscii(_pcCmd->getName())); connect(_action, SIGNAL(triggered(bool)), this, SLOT(onActivated())); } +Action::Action (Command* pcCmd, QAction* action, QObject * parent) + : QObject(parent), _action(action), _pcCmd(pcCmd) +{ + _action->setParent(this); + _action->setObjectName(QString::fromAscii(_pcCmd->getName())); + connect(_action, SIGNAL(triggered(bool)), this, SLOT(onActivated())); +} + Action::~Action() { delete _action; @@ -257,6 +266,14 @@ void ActionGroup::setVisible( bool b ) _group->setVisible(b); } +QAction* ActionGroup::addAction(QAction* action) +{ + int index = _group->actions().size(); + action = _group->addAction(action); + action->setData(QVariant(index)); + return action; +} + QAction* ActionGroup::addAction(const QString& text) { int index = _group->actions().size(); @@ -289,6 +306,14 @@ void ActionGroup::onActivated () _pcCmd->invoke(this->property("defaultAction").toInt()); } +/** + * Activates the command. + */ +void ActionGroup::onActivated (int index) +{ + _pcCmd->invoke(index); +} + /** * Activates the command. */ @@ -410,6 +435,8 @@ void WorkbenchComboBox::onActivated(int i) int index = itemData(i).toInt(); WorkbenchActionEvent* ev = new WorkbenchActionEvent(this->actions()[index]); QApplication::postEvent(this->group, ev); + // TODO: Test if we can use this instead + //QTimer::singleShot(20, this->actions()[i], SLOT(trigger())); } void WorkbenchComboBox::onActivated(QAction* action) diff --git a/src/Gui/Action.h b/src/Gui/Action.h index 0b33f57ec..34ce2dd52 100644 --- a/src/Gui/Action.h +++ b/src/Gui/Action.h @@ -45,6 +45,8 @@ class GuiExport Action : public QObject public: Action (Command* pcCmd, QObject * parent = 0); + /// Action takes ownership of the 'action' object. + Action (Command* pcCmd, QAction* action, QObject * parent); virtual ~Action(); virtual void addTo (QWidget * w); @@ -100,6 +102,7 @@ public: void setVisible (bool); void setDropDownMenu(bool b) { _dropDown = b; } + QAction* addAction(QAction*); QAction* addAction(const QString&); QList actions() const; int checkedAction() const; @@ -107,6 +110,7 @@ public: public Q_SLOTS: void onActivated (); + void onActivated (int); void onActivated (QAction*); protected: