Commit d6b0baa8 authored by Clinton Stimpson's avatar Clinton Stimpson

Fix/improve menu playback.

Fix playback to do lookups for menu items the same way they are recorded.
Improve menu recording/playback for items that are not named.
parent 50c49129
......@@ -57,52 +57,21 @@ bool pqAbstractActivateEventPlayer::playEvent(QObject* Object,
if (QMenuBar* const menu_bar = qobject_cast<QMenuBar*>(Object))
{
QMenu* sub_menu = menu_bar->findChild<QMenu*>(Arguments);
if (sub_menu)
QAction* action = findAction(menu_bar, Arguments);
if (action)
{
QAction* action = 0;
foreach (QAction* cur_action, menu_bar->actions())
{
if (cur_action->menu() == sub_menu)
{
action = cur_action;
break;
}
}
if (action)
{
menu_bar->setActiveAction(action);
return true;
}
menu_bar->setActiveAction(action);
return true;
}
qCritical() << "couldn't find action " << Arguments;
Error = true;
return true;
}
if(QMenu* const object = qobject_cast<QMenu*>(Object))
{
QAction* action = NULL;
QList<QAction*> actions = object->actions();
for(int j = 0; j != actions.size() && !action; ++j)
{
if(actions[j]->objectName() == Arguments)
{
action = actions[j];
}
}
// fall back to the text of the action
if(!action)
{
for(int j = 0; j != actions.size() && !action; ++j)
{
if(actions[j]->text() == Arguments)
{
action = actions[j];
}
}
}
QAction* action = findAction(object, Arguments);
if(!action)
{
......@@ -182,3 +151,59 @@ bool pqAbstractActivateEventPlayer::playEvent(QObject* Object,
Error = true;
return true;
}
QAction* pqAbstractActivateEventPlayer::findAction(QMenuBar* p, const QString& name)
{
QList<QAction*> actions = p->actions();
QAction* action = NULL;
foreach(QAction* a, actions)
{
if(a->menu()->objectName() == name)
{
action = a;
break;
}
}
if(!action)
{
foreach(QAction* a, actions)
{
if(a->text() == name)
{
action = a;
break;
}
}
}
return action;
}
QAction* pqAbstractActivateEventPlayer::findAction(QMenu* p, const QString& name)
{
QList<QAction*> actions = p->actions();
QAction* action = NULL;
foreach(QAction* a, actions)
{
if(a->objectName() == name)
{
action = a;
break;
}
}
if(!action)
{
foreach(QAction* a, actions)
{
if(a->text() == name)
{
action = a;
break;
}
}
}
return action;
}
......@@ -34,13 +34,16 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#define _pqAbstractActivateEventPlayer_h
#include "pqWidgetEventPlayer.h"
class QAction;
class QMenuBar;
class QMenu;
/**
Concrete implementation of pqWidgetEventPlayer that handles playback of "activate" events for buttons and menus.
\sa pqEventPlayer
*/
class pqAbstractActivateEventPlayer :
class QTTESTING_EXPORT pqAbstractActivateEventPlayer :
public pqWidgetEventPlayer
{
public:
......@@ -49,6 +52,10 @@ public:
bool playEvent(QObject* Object, const QString& Command, const QString& Arguments, bool& Error);
private:
QAction* findAction(QMenu* p, const QString& name);
QAction* findAction(QMenuBar* p, const QString& name);
pqAbstractActivateEventPlayer(const pqAbstractActivateEventPlayer&);
pqAbstractActivateEventPlayer& operator=(const pqAbstractActivateEventPlayer&);
};
......
......@@ -66,6 +66,10 @@ bool pqMenuEventTranslator::translateEvent(QObject* Object, QEvent* Event,
if (action && action->menu())
{
QString which = action->menu()->objectName();
if(which.isEmpty())
{
which = action->text();
}
emit recordEvent(menubar, "activate", which);
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment