From 1da4e67df1c2ca288c6083bd1d5d32d77ff5a14f Mon Sep 17 00:00:00 2001 From: Utkarsh Ayachit <utkarsh.ayachit@kitware.com> Date: Wed, 6 Sep 2017 15:20:39 -0400 Subject: [PATCH 1/3] Add clang-format file (same as ParaView). --- .clang-format | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 .clang-format diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..78098da --- /dev/null +++ b/.clang-format @@ -0,0 +1,11 @@ +--- +# This configuration requires clang-format 3.8 or higher. +BasedOnStyle: Mozilla +AlignAfterOpenBracket: DontAlign +AlignOperands: false +AlwaysBreakAfterReturnType: None +AlwaysBreakAfterDefinitionReturnType: None +BreakBeforeBraces: Allman +ColumnLimit: 100 +Standard: Cpp03 +... -- GitLab From 6aa39647d931c78f2610d70877a74859dd4c7618 Mon Sep 17 00:00:00 2001 From: Utkarsh Ayachit <utkarsh.ayachit@kitware.com> Date: Thu, 7 Sep 2017 16:01:57 -0400 Subject: [PATCH 2/3] Add gitattributes. --- .gitattributes | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..e50dc01 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,20 @@ +.git* export-ignore +.hooks* export-ignore + +*.sh crlf=input +*.sh.in crlf=input + +# Custom attribute to mark sources as using our C code style. +[attr]our-c-style whitespace=tab-in-indent,-blank-at-eol format.clang-format + +*.c our-c-style +*.h our-c-style +*.cpp our-c-style +*.cxx our-c-style +*.hxx our-c-style +*.txx our-c-style +*.mm our-c-style +*.txt whitespace=tab-in-indent,-blank-at-eol +*.cmake whitespace=tab-in-indent,-blank-at-eol + +*.md whitespace=tab-in-indent conflict-marker-size=30 -- GitLab From 25869ff1f7a234ea19c67afa25f63ac639d6abe0 Mon Sep 17 00:00:00 2001 From: Utkarsh Ayachit <utkarsh.ayachit@kitware.com> Date: Wed, 6 Sep 2017 15:24:21 -0400 Subject: [PATCH 3/3] clang-format: fix code formatting This run of `clang-format` cleanups indentation and spacing to match ParaView style. --- QtTestingExport.h | 26 +- pq3DViewEventPlayer.cxx | 65 ++-- pq3DViewEventPlayer.h | 10 +- pq3DViewEventTranslator.cxx | 128 ++++--- pq3DViewEventTranslator.h | 6 +- pqAbstractActivateEventPlayer.cxx | 135 ++++--- pqAbstractActivateEventPlayer.h | 13 +- pqAbstractBooleanEventPlayer.cxx | 38 +- pqAbstractBooleanEventPlayer.h | 14 +- pqAbstractButtonEventTranslator.cxx | 91 +++-- pqAbstractButtonEventTranslator.h | 10 +- pqAbstractDoubleEventPlayer.cxx | 30 +- pqAbstractDoubleEventPlayer.h | 14 +- pqAbstractIntEventPlayer.cxx | 40 +-- pqAbstractIntEventPlayer.h | 15 +- pqAbstractItemViewEventPlayer.cxx | 130 ++++--- pqAbstractItemViewEventPlayer.h | 14 +- pqAbstractItemViewEventPlayerBase.cxx | 159 ++++----- pqAbstractItemViewEventPlayerBase.h | 16 +- pqAbstractItemViewEventTranslator.cxx | 141 ++++---- pqAbstractItemViewEventTranslator.h | 15 +- pqAbstractItemViewEventTranslatorBase.cxx | 172 ++++----- pqAbstractItemViewEventTranslatorBase.h | 8 +- pqAbstractMiscellaneousEventPlayer.cxx | 37 +- pqAbstractMiscellaneousEventPlayer.h | 12 +- pqAbstractSliderEventTranslator.cxx | 18 +- pqAbstractSliderEventTranslator.h | 14 +- pqAbstractStringEventPlayer.cxx | 41 +-- pqAbstractStringEventPlayer.h | 12 +- pqBasicWidgetEventPlayer.cxx | 69 ++-- pqBasicWidgetEventPlayer.h | 15 +- pqBasicWidgetEventTranslator.cxx | 123 ++++--- pqBasicWidgetEventTranslator.h | 11 +- pqCheckEventOverlay.cxx | 13 +- pqCheckEventOverlay.h | 4 +- pqComboBoxEventPlayer.cxx | 46 +-- pqComboBoxEventPlayer.h | 9 +- pqComboBoxEventTranslator.cxx | 39 ++- pqComboBoxEventTranslator.h | 6 +- pqCommentEventPlayer.cxx | 21 +- pqCommentEventPlayer.h | 7 +- pqDoubleSpinBoxEventTranslator.cxx | 53 ++- pqDoubleSpinBoxEventTranslator.h | 13 +- pqEventComment.cxx | 12 +- pqEventComment.h | 9 +- pqEventDispatcher.cxx | 204 ++++++----- pqEventDispatcher.h | 17 +- pqEventObserver.cxx | 6 +- pqEventObserver.h | 26 +- pqEventPlayer.cxx | 106 +++--- pqEventPlayer.h | 29 +- pqEventRecorder.cxx | 68 ++-- pqEventRecorder.h | 20 +- pqEventSource.h | 15 +- pqEventTranslator.cxx | 348 +++++++++--------- pqEventTranslator.h | 29 +- pqEventTypes.h | 10 +- pqLineEditEventTranslator.cxx | 86 ++--- pqLineEditEventTranslator.h | 10 +- pqListViewEventPlayer.cxx | 17 +- pqListViewEventPlayer.h | 9 +- pqListViewEventTranslator.cxx | 14 +- pqListViewEventTranslator.h | 5 +- pqMenuEventTranslator.cxx | 74 ++-- pqMenuEventTranslator.h | 11 +- pqNativeFileDialogEventPlayer.cxx | 201 +++++------ pqNativeFileDialogEventPlayer.h | 8 +- pqNativeFileDialogEventTranslator.cxx | 192 +++++----- pqNativeFileDialogEventTranslator.h | 6 +- pqObjectNaming.cxx | 218 ++++++------ pqObjectNaming.h | 10 +- pqPlayBackEventsDialog.cxx | 311 ++++++++--------- pqPlayBackEventsDialog.h | 15 +- pqPythonEventObserver.cxx | 23 +- pqPythonEventObserver.h | 12 +- pqPythonEventSource.cxx | 407 ++++++++++------------ pqPythonEventSource.h | 6 +- pqRecordEventsDialog.cxx | 108 +++--- pqRecordEventsDialog.h | 15 +- pqSpinBoxEventTranslator.cxx | 64 ++-- pqSpinBoxEventTranslator.h | 12 +- pqStdoutEventObserver.cxx | 14 +- pqStdoutEventObserver.h | 10 +- pqTabBarEventPlayer.cxx | 73 ++-- pqTabBarEventPlayer.h | 14 +- pqTabBarEventTranslator.cxx | 40 +-- pqTabBarEventTranslator.h | 11 +- pqTableViewEventPlayer.cxx | 17 +- pqTableViewEventPlayer.h | 9 +- pqTableViewEventTranslator.cxx | 18 +- pqTableViewEventTranslator.h | 5 +- pqTestUtility.cxx | 212 ++++++----- pqTestUtility.h | 46 ++- pqThreadedEventSource.cxx | 94 +++-- pqThreadedEventSource.h | 25 +- pqTimer.cxx | 4 +- pqTimer.h | 5 +- pqTreeViewEventPlayer.cxx | 61 ++-- pqTreeViewEventPlayer.h | 17 +- pqTreeViewEventTranslator.cxx | 31 +- pqTreeViewEventTranslator.h | 5 +- pqWidgetEventPlayer.cxx | 40 +-- pqWidgetEventPlayer.h | 15 +- pqWidgetEventTranslator.cxx | 25 +- pqWidgetEventTranslator.h | 16 +- 105 files changed, 2552 insertions(+), 2841 deletions(-) diff --git a/QtTestingExport.h b/QtTestingExport.h index 5f84b9f..7675650 100644 --- a/QtTestingExport.h +++ b/QtTestingExport.h @@ -7,7 +7,7 @@ All rights reserved. ParaView is a free software; you can redistribute it and/or modify it - under the terms of the ParaView license version 1.2. + under the terms of the ParaView license version 1.2. See License_v1.2.txt for the full ParaView license. A copy of this license can be obtained by contacting @@ -36,21 +36,21 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "QtTestingConfigure.h" #if defined(QTTESTING_BUILD_SHARED_LIBS) -# if defined(QtTesting_EXPORTS) -# if defined(WIN32) -# define QTTESTING_EXPORT __declspec(dllexport) -# elif defined(__GNUC__) && __GNUC__ >= 4 -# define QTTESTING_EXPORT __attribute__ ((visibility("default"))) -# endif -# else -# if defined(WIN32) -# define QTTESTING_EXPORT __declspec(dllimport) -# endif -# endif +#if defined(QtTesting_EXPORTS) +#if defined(WIN32) +#define QTTESTING_EXPORT __declspec(dllexport) +#elif defined(__GNUC__) && __GNUC__ >= 4 +#define QTTESTING_EXPORT __attribute__((visibility("default"))) +#endif +#else +#if defined(WIN32) +#define QTTESTING_EXPORT __declspec(dllimport) +#endif +#endif #endif #ifndef QTTESTING_EXPORT -# define QTTESTING_EXPORT +#define QTTESTING_EXPORT #endif #endif // !_QtTestingExport_h diff --git a/pq3DViewEventPlayer.cxx b/pq3DViewEventPlayer.cxx index e253fe3..5be26b8 100644 --- a/pq3DViewEventPlayer.cxx +++ b/pq3DViewEventPlayer.cxx @@ -35,46 +35,45 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include <QApplication> #include <QKeyEvent> #include <QMouseEvent> -#include <QtDebug> #include <QRegExp> #include <QWidget> +#include <QtDebug> -pq3DViewEventPlayer::pq3DViewEventPlayer(const QByteArray& classname, QObject * p) - : pqWidgetEventPlayer(p), mClassType(classname) +pq3DViewEventPlayer::pq3DViewEventPlayer(const QByteArray& classname, QObject* p) + : pqWidgetEventPlayer(p) + , mClassType(classname) { } -bool pq3DViewEventPlayer::playEvent(QObject* Object, - const QString& Command, - const QString& Arguments, - bool& Error) +bool pq3DViewEventPlayer::playEvent( + QObject* Object, const QString& Command, const QString& Arguments, bool& Error) { - QWidget* widget = qobject_cast<QWidget*>(Object); - if(widget && Object->inherits(mClassType.data())) + QWidget* widget = qobject_cast<QWidget*>(Object); + if (widget && Object->inherits(mClassType.data())) + { + if (Command == "mousePress" || Command == "mouseRelease" || Command == "mouseMove") + { + QRegExp mouseRegExp("\\(([^,]*),([^,]*),([^,]),([^,]),([^,]*)\\)"); + if (mouseRegExp.indexIn(Arguments) != -1) { - if (Command == "mousePress" || Command=="mouseRelease" || Command=="mouseMove") - { - QRegExp mouseRegExp("\\(([^,]*),([^,]*),([^,]),([^,]),([^,]*)\\)"); - if (mouseRegExp.indexIn(Arguments)!= -1) - { - QVariant v = mouseRegExp.cap(1); - int x = static_cast<int>(v.toDouble() * widget->size().width()); - v = mouseRegExp.cap(2); - int y = static_cast<int>(v.toDouble() * widget->size().height()); - v = mouseRegExp.cap(3); - Qt::MouseButton button = static_cast<Qt::MouseButton>(v.toInt()); - v = mouseRegExp.cap(4); - Qt::MouseButtons buttons = static_cast<Qt::MouseButton>(v.toInt()); - v = mouseRegExp.cap(5); - Qt::KeyboardModifiers keym = static_cast<Qt::KeyboardModifier>(v.toInt()); - QEvent::Type type = (Command == "mousePress")? QEvent::MouseButtonPress : - ((Command=="mouseMove")? QEvent::MouseMove : QEvent::MouseButtonRelease); - QMouseEvent e(type, QPoint(x,y), button, buttons, keym); - qApp->notify(Object, &e); - } - return true; - } + QVariant v = mouseRegExp.cap(1); + int x = static_cast<int>(v.toDouble() * widget->size().width()); + v = mouseRegExp.cap(2); + int y = static_cast<int>(v.toDouble() * widget->size().height()); + v = mouseRegExp.cap(3); + Qt::MouseButton button = static_cast<Qt::MouseButton>(v.toInt()); + v = mouseRegExp.cap(4); + Qt::MouseButtons buttons = static_cast<Qt::MouseButton>(v.toInt()); + v = mouseRegExp.cap(5); + Qt::KeyboardModifiers keym = static_cast<Qt::KeyboardModifier>(v.toInt()); + QEvent::Type type = (Command == "mousePress") + ? QEvent::MouseButtonPress + : ((Command == "mouseMove") ? QEvent::MouseMove : QEvent::MouseButtonRelease); + QMouseEvent e(type, QPoint(x, y), button, buttons, keym); + qApp->notify(Object, &e); } - return this->Superclass::playEvent(Object, Command, Arguments, Error); + return true; + } + } + return this->Superclass::playEvent(Object, Command, Arguments, Error); } - diff --git a/pq3DViewEventPlayer.h b/pq3DViewEventPlayer.h index e1cee73..6a4d118 100644 --- a/pq3DViewEventPlayer.h +++ b/pq3DViewEventPlayer.h @@ -36,13 +36,13 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "pqWidgetEventPlayer.h" /** -Concrete implementation of pqWidgetEventPlayer that handles playback of "activate" events for 3d views. +Concrete implementation of pqWidgetEventPlayer that handles playback of "activate" events for 3d +views. It is not registered by default, and user can register with their own 3d view type. \sa pqEventPlayer */ -class QTTESTING_EXPORT pq3DViewEventPlayer : - public pqWidgetEventPlayer +class QTTESTING_EXPORT pq3DViewEventPlayer : public pqWidgetEventPlayer { Q_OBJECT typedef pqWidgetEventPlayer Superclass; @@ -51,13 +51,13 @@ public: pq3DViewEventPlayer(const QByteArray& classname, QObject* p = 0); using Superclass::playEvent; - bool playEvent(QObject* Object, const QString& Command, const QString& Arguments, bool& Error) override; + bool playEvent( + QObject* Object, const QString& Command, const QString& Arguments, bool& Error) override; protected: QByteArray mClassType; private: - pq3DViewEventPlayer(const pq3DViewEventPlayer&); pq3DViewEventPlayer& operator=(const pq3DViewEventPlayer&); }; diff --git a/pq3DViewEventTranslator.cxx b/pq3DViewEventTranslator.cxx index b7307bf..4ab60a5 100644 --- a/pq3DViewEventTranslator.cxx +++ b/pq3DViewEventTranslator.cxx @@ -33,14 +33,15 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "pq3DViewEventTranslator.h" #include <QEvent> -#include <QMouseEvent> #include <QKeyEvent> +#include <QMouseEvent> #include <QWidget> pq3DViewEventTranslator::pq3DViewEventTranslator(const QByteArray& classname, QObject* p) - : pqWidgetEventTranslator(p), mClassType(classname), - lastMoveEvent(QEvent::MouseButtonPress, QPoint(), Qt::MouseButton(), - Qt::MouseButtons(), Qt::KeyboardModifiers()) + : pqWidgetEventTranslator(p) + , mClassType(classname) + , lastMoveEvent(QEvent::MouseButtonPress, QPoint(), Qt::MouseButton(), Qt::MouseButtons(), + Qt::KeyboardModifiers()) { } @@ -48,128 +49,125 @@ pq3DViewEventTranslator::~pq3DViewEventTranslator() { } -bool pq3DViewEventTranslator::translateEvent(QObject* Object, QEvent* Event, - bool& Error) +bool pq3DViewEventTranslator::translateEvent(QObject* Object, QEvent* Event, bool& Error) { QWidget* widget = qobject_cast<QWidget*>(Object); - if(!widget || !Object->inherits(mClassType.data())) - { + if (!widget || !Object->inherits(mClassType.data())) + { return false; - } + } - switch(Event->type()) - { + switch (Event->type()) + { case QEvent::ContextMenu: - { + { return true; break; - } + } case QEvent::MouseButtonPress: - { + { QMouseEvent* mouseEvent = dynamic_cast<QMouseEvent*>(Event); if (mouseEvent) - { + { QSize size = widget->size(); - double normalized_x = mouseEvent->x()/static_cast<double>(size.width()); - double normalized_y = mouseEvent->y()/static_cast<double>(size.height()); + double normalized_x = mouseEvent->x() / static_cast<double>(size.width()); + double normalized_y = mouseEvent->y() / static_cast<double>(size.height()); int button = mouseEvent->button(); int buttons = mouseEvent->buttons(); int modifiers = mouseEvent->modifiers(); emit recordEvent(Object, "mousePress", QString("(%1,%2,%3,%4,%5)") - .arg(normalized_x) - .arg(normalized_y) - .arg(button) - .arg(buttons) - .arg(modifiers)); - } + .arg(normalized_x) + .arg(normalized_y) + .arg(button) + .arg(buttons) + .arg(modifiers)); + } // reset lastMoveEvent - QMouseEvent e(QEvent::MouseButtonPress, QPoint(), Qt::MouseButton(), - Qt::MouseButtons(), Qt::KeyboardModifiers()); + QMouseEvent e(QEvent::MouseButtonPress, QPoint(), Qt::MouseButton(), Qt::MouseButtons(), + Qt::KeyboardModifiers()); lastMoveEvent = e; return true; break; - } + } case QEvent::MouseMove: - { + { QMouseEvent* mouseEvent = dynamic_cast<QMouseEvent*>(Event); if (mouseEvent) - { + { QMouseEvent e(QEvent::MouseMove, QPoint(mouseEvent->x(), mouseEvent->y()), - mouseEvent->button(), mouseEvent->buttons(), - mouseEvent->modifiers()); + mouseEvent->button(), mouseEvent->buttons(), mouseEvent->modifiers()); lastMoveEvent = e; - } + } return true; break; - } + } case QEvent::MouseButtonRelease: - { + { QMouseEvent* mouseEvent = dynamic_cast<QMouseEvent*>(Event); if (mouseEvent) - { + { QSize size = widget->size(); // record last move event if it is valid - if(lastMoveEvent.type() == QEvent::MouseMove) - { - double normalized_x = lastMoveEvent.x()/static_cast<double>(size.width()); - double normalized_y = lastMoveEvent.y()/static_cast<double>(size.height()); + if (lastMoveEvent.type() == QEvent::MouseMove) + { + double normalized_x = lastMoveEvent.x() / static_cast<double>(size.width()); + double normalized_y = lastMoveEvent.y() / static_cast<double>(size.height()); int button = lastMoveEvent.button(); int buttons = lastMoveEvent.buttons(); int modifiers = lastMoveEvent.modifiers(); emit recordEvent(Object, "mouseMove", QString("(%1,%2,%3,%4,%5)") - .arg(normalized_x) - .arg(normalized_y) - .arg(button) - .arg(buttons) - .arg(modifiers)); - } - + .arg(normalized_x) + .arg(normalized_y) + .arg(button) + .arg(buttons) + .arg(modifiers)); + } - double normalized_x = mouseEvent->x()/static_cast<double>(size.width()); - double normalized_y = mouseEvent->y()/static_cast<double>(size.height()); + double normalized_x = mouseEvent->x() / static_cast<double>(size.width()); + double normalized_y = mouseEvent->y() / static_cast<double>(size.height()); int button = mouseEvent->button(); int buttons = mouseEvent->buttons(); int modifiers = mouseEvent->modifiers(); emit recordEvent(Object, "mouseRelease", QString("(%1,%2,%3,%4,%5)") - .arg(normalized_x) - .arg(normalized_y) - .arg(button) - .arg(buttons) - .arg(modifiers)); - } + .arg(normalized_x) + .arg(normalized_y) + .arg(button) + .arg(buttons) + .arg(modifiers)); + } return true; break; - } + } case QEvent::KeyPress: case QEvent::KeyRelease: - { + { QKeyEvent* ke = static_cast<QKeyEvent*>(Event); - QString data =QString("%1:%2:%3:%4:%5:%6") - .arg(ke->type()) - .arg(ke->key()) - .arg(static_cast<int>(ke->modifiers())) - .arg(ke->text()) - .arg(ke->isAutoRepeat()) - .arg(ke->count()); + QString data = QString("%1:%2:%3:%4:%5:%6") + .arg(ke->type()) + .arg(ke->key()) + .arg(static_cast<int>(ke->modifiers())) + .arg(ke->text()) + .arg(ke->isAutoRepeat()) + .arg(ke->count()); emit recordEvent(Object, "keyEvent", data); return true; break; - } + } default: - { + { break; - } } + } return this->Superclass::translateEvent(Object, Event, Error); } diff --git a/pq3DViewEventTranslator.h b/pq3DViewEventTranslator.h index 27e4447..9078859 100644 --- a/pq3DViewEventTranslator.h +++ b/pq3DViewEventTranslator.h @@ -42,14 +42,13 @@ Translates low-level Qt events into high-level ParaView events that can be recor \sa pqEventTranslator */ -class QTTESTING_EXPORT pq3DViewEventTranslator : - public pqWidgetEventTranslator +class QTTESTING_EXPORT pq3DViewEventTranslator : public pqWidgetEventTranslator { Q_OBJECT typedef pqWidgetEventTranslator Superclass; public: - pq3DViewEventTranslator(const QByteArray& classname, QObject* p=0); + pq3DViewEventTranslator(const QByteArray& classname, QObject* p = 0); ~pq3DViewEventTranslator() override; using Superclass::translateEvent; @@ -62,7 +61,6 @@ protected: private: pq3DViewEventTranslator(const pq3DViewEventTranslator&); pq3DViewEventTranslator& operator=(const pq3DViewEventTranslator&); - }; #endif // !_pq3DViewEventTranslator_h diff --git a/pqAbstractActivateEventPlayer.cxx b/pqAbstractActivateEventPlayer.cxx index c8b0a80..c999ecf 100644 --- a/pqAbstractActivateEventPlayer.cxx +++ b/pqAbstractActivateEventPlayer.cxx @@ -38,85 +38,82 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include <QMenu> #include <QMenuBar> #include <QPushButton> -#include <QtDebug> #include <QToolButton> +#include <QtDebug> #include "pqEventDispatcher.h" -pqAbstractActivateEventPlayer::pqAbstractActivateEventPlayer(QObject * p) +pqAbstractActivateEventPlayer::pqAbstractActivateEventPlayer(QObject* p) : pqWidgetEventPlayer(p) { } -bool pqAbstractActivateEventPlayer::playEvent(QObject* Object, - const QString& Command, - const QString& Arguments, - bool& Error) +bool pqAbstractActivateEventPlayer::playEvent( + QObject* Object, const QString& Command, const QString& Arguments, bool& Error) { - if(Command != "activate" && Command != "longActivate") - return false; + if (Command != "activate" && Command != "longActivate") + return false; - if (QMenuBar* const menu_bar = qobject_cast<QMenuBar*>(Object)) - { + if (QMenuBar* const menu_bar = qobject_cast<QMenuBar*>(Object)) + { QAction* action = findAction(menu_bar, Arguments); if (action) - { + { menu_bar->setActiveAction(action); return true; - } + } qCritical() << "couldn't find action " << Arguments; Error = true; return true; - } + } - if(QMenu* const object = qobject_cast<QMenu*>(Object)) - { + if (QMenu* const object = qobject_cast<QMenu*>(Object)) + { QAction* action = findAction(object, Arguments); - if(!action) - { + if (!action) + { qCritical() << "couldn't find action " << Arguments; Error = true; return true; - } + } // get a list of menus that must be navigated to // click on the action QObjectList menus; - for(QObject* p = object; - qobject_cast<QMenu*>(p) || qobject_cast<QMenuBar*>(p); - p = p->parent()) - { + for (QObject* p = object; qobject_cast<QMenu*>(p) || qobject_cast<QMenuBar*>(p); + p = p->parent()) + { menus.push_front(p); - } + } // unfold menus to make action visible int i; int numMenus = menus.size() - 1; - for(i=0; i < numMenus; ++i) - { + for (i = 0; i < numMenus; ++i) + { QObject* p = menus[i]; - QMenu* next = qobject_cast<QMenu*>(menus[i+1]); - if(QMenuBar* menu_bar = qobject_cast<QMenuBar*>(p)) - { + QMenu* next = qobject_cast<QMenu*>(menus[i + 1]); + if (QMenuBar* menu_bar = qobject_cast<QMenuBar*>(p)) + { menu_bar->setActiveAction(next->menuAction()); int max_wait = 0; - while(!next->isVisible() && (++max_wait) <= 2) - { + while (!next->isVisible() && (++max_wait) <= 2) + { pqEventDispatcher::processEventsAndWait(100); - } } - else if(QMenu* menu = qobject_cast<QMenu*>(p)) - { + } + else if (QMenu* menu = qobject_cast<QMenu*>(p)) + { menu->setActiveAction(next->menuAction()); int max_wait = 0; - while(!next->isVisible() && (++max_wait) <= 2) - { + while (!next->isVisible() && (++max_wait) <= 2) + { pqEventDispatcher::processEventsAndWait(100); - } } } + } // set active action, will cause scrollable menus to scroll // to make action visible @@ -129,35 +126,35 @@ bool pqAbstractActivateEventPlayer::playEvent(QObject* Object, qApp->notify(object, &keyDown); qApp->notify(object, &keyUp); - //QApplication::processEvents(); + // QApplication::processEvents(); return true; - } + } - if(QAbstractButton* const object = qobject_cast<QAbstractButton*>(Object)) - { + if (QAbstractButton* const object = qobject_cast<QAbstractButton*>(Object)) + { if (Command == "activate") - { + { object->click(); - //QApplication::processEvents(); + // QApplication::processEvents(); return true; - } - if(Command == "longActivate") - { + } + if (Command == "longActivate") + { QToolButton* tButton = qobject_cast<QToolButton*>(Object); - if(tButton) - { + if (tButton) + { tButton->showMenu(); return true; - } } } + } if (QAction* const action = qobject_cast<QAction*>(Object)) - { + { action->activate(QAction::Trigger); - //QApplication::processEvents(); + // QApplication::processEvents(); return true; - } + } qCritical() << "calling activate on unhandled type " << Object; Error = true; @@ -168,26 +165,26 @@ QAction* pqAbstractActivateEventPlayer::findAction(QMenuBar* p, const QString& n { QList<QAction*> actions = p->actions(); QAction* action = NULL; - foreach(QAction* a, actions) + foreach (QAction* a, actions) + { + if (a->menu()->objectName() == name) { - if(a->menu()->objectName() == name) - { action = a; break; - } } + } - if(!action) + if (!action) + { + foreach (QAction* a, actions) { - foreach(QAction* a, actions) + if (a->text() == name) { - if(a->text() == name) - { action = a; break; - } } } + } return action; } @@ -196,26 +193,26 @@ QAction* pqAbstractActivateEventPlayer::findAction(QMenu* p, const QString& name { QList<QAction*> actions = p->actions(); QAction* action = NULL; - foreach(QAction* a, actions) + foreach (QAction* a, actions) + { + if (a->objectName() == name) { - if(a->objectName() == name) - { action = a; break; - } } + } - if(!action) + if (!action) + { + foreach (QAction* a, actions) { - foreach(QAction* a, actions) + if (a->text() == name) { - if(a->text() == name) - { action = a; break; - } } } + } return action; } diff --git a/pqAbstractActivateEventPlayer.h b/pqAbstractActivateEventPlayer.h index 09605e5..7be6407 100644 --- a/pqAbstractActivateEventPlayer.h +++ b/pqAbstractActivateEventPlayer.h @@ -7,7 +7,7 @@ All rights reserved. ParaView is a free software; you can redistribute it and/or modify it - under the terms of the ParaView license version 1.2. + under the terms of the ParaView license version 1.2. See License_v1.2.txt for the full ParaView license. A copy of this license can be obtained by contacting @@ -39,12 +39,12 @@ class QMenuBar; class QMenu; /** -Concrete implementation of pqWidgetEventPlayer that handles playback of "activate" events for buttons and menus. +Concrete implementation of pqWidgetEventPlayer that handles playback of "activate" events for +buttons and menus. \sa pqEventPlayer */ -class QTTESTING_EXPORT pqAbstractActivateEventPlayer : - public pqWidgetEventPlayer +class QTTESTING_EXPORT pqAbstractActivateEventPlayer : public pqWidgetEventPlayer { Q_OBJECT typedef pqWidgetEventPlayer Superclass; @@ -53,10 +53,10 @@ public: pqAbstractActivateEventPlayer(QObject* p = 0); using Superclass::playEvent; - bool playEvent(QObject* Object, const QString& Command, const QString& Arguments, bool& Error) override; + bool playEvent( + QObject* Object, const QString& Command, const QString& Arguments, bool& Error) override; private: - QAction* findAction(QMenu* p, const QString& name); QAction* findAction(QMenuBar* p, const QString& name); @@ -65,4 +65,3 @@ private: }; #endif // !_pqAbstractActivateEventPlayer_h - diff --git a/pqAbstractBooleanEventPlayer.cxx b/pqAbstractBooleanEventPlayer.cxx index f446c13..b90ea19 100644 --- a/pqAbstractBooleanEventPlayer.cxx +++ b/pqAbstractBooleanEventPlayer.cxx @@ -7,7 +7,7 @@ All rights reserved. ParaView is a free software; you can redistribute it and/or modify it - under the terms of the ParaView license version 1.2. + under the terms of the ParaView license version 1.2. See License_v1.2.txt for the full ParaView license. A copy of this license can be obtained by contacting @@ -33,48 +33,48 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "pqAbstractBooleanEventPlayer.h" #include <QAbstractButton> +#include <QAction> #include <QGroupBox> #include <QtDebug> -#include <QAction> pqAbstractBooleanEventPlayer::pqAbstractBooleanEventPlayer(QObject* p) : pqWidgetEventPlayer(p) { } -bool pqAbstractBooleanEventPlayer::playEvent(QObject* Object, const QString& Command, const QString& Arguments, bool& Error) +bool pqAbstractBooleanEventPlayer::playEvent( + QObject* Object, const QString& Command, const QString& Arguments, bool& Error) { - if(Command != "set_boolean") + if (Command != "set_boolean") return false; const bool value = Arguments == "true" ? true : false; - if(QAbstractButton* const object = qobject_cast<QAbstractButton*>(Object)) - { - if(value != object->isChecked()) + if (QAbstractButton* const object = qobject_cast<QAbstractButton*>(Object)) + { + if (value != object->isChecked()) object->click(); return true; - } + } if (QAction* const action = qobject_cast<QAction*>(Object)) - { + { if (action->isChecked() != value) - { + { action->trigger(); - } - return true; } + return true; + } - if ( QGroupBox* const object = qobject_cast<QGroupBox*>(Object)) + if (QGroupBox* const object = qobject_cast<QGroupBox*>(Object)) + { + if (value != object->isChecked()) { - if ( value != object->isChecked() ) - { - object->setChecked( value ); - } - return true; + object->setChecked(value); } + return true; + } qCritical() << "calling set_boolean on unhandled type " << Object; Error = true; return true; } - diff --git a/pqAbstractBooleanEventPlayer.h b/pqAbstractBooleanEventPlayer.h index 0a11cbc..7362651 100644 --- a/pqAbstractBooleanEventPlayer.h +++ b/pqAbstractBooleanEventPlayer.h @@ -7,7 +7,7 @@ All rights reserved. ParaView is a free software; you can redistribute it and/or modify it - under the terms of the ParaView license version 1.2. + under the terms of the ParaView license version 1.2. See License_v1.2.txt for the full ParaView license. A copy of this license can be obtained by contacting @@ -36,21 +36,22 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "pqWidgetEventPlayer.h" /** -Concrete implementation of pqWidgetEventPlayer that translates high-level ParaView events into low-level Qt events. +Concrete implementation of pqWidgetEventPlayer that translates high-level ParaView events into +low-level Qt events. \sa pqEventPlayer */ -class QTTESTING_EXPORT pqAbstractBooleanEventPlayer : - public pqWidgetEventPlayer +class QTTESTING_EXPORT pqAbstractBooleanEventPlayer : public pqWidgetEventPlayer { Q_OBJECT typedef pqWidgetEventPlayer Superclass; public: - pqAbstractBooleanEventPlayer(QObject* p=0); + pqAbstractBooleanEventPlayer(QObject* p = 0); using Superclass::playEvent; - bool playEvent(QObject* Object, const QString& Command, const QString& Arguments, bool& Error) override; + bool playEvent( + QObject* Object, const QString& Command, const QString& Arguments, bool& Error) override; private: pqAbstractBooleanEventPlayer(const pqAbstractBooleanEventPlayer&); @@ -58,4 +59,3 @@ private: }; #endif // !_pqAbstractBooleanEventPlayer_h - diff --git a/pqAbstractButtonEventTranslator.cxx b/pqAbstractButtonEventTranslator.cxx index 69492ca..6d14ffa 100644 --- a/pqAbstractButtonEventTranslator.cxx +++ b/pqAbstractButtonEventTranslator.cxx @@ -32,9 +32,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "pqAbstractButtonEventTranslator.h" -#include <QDebug> #include <QAbstractButton> #include <QAction> +#include <QDebug> #include <QKeyEvent> #include <QMouseEvent> #include <QPushButton> @@ -49,76 +49,72 @@ pqAbstractButtonEventTranslator::pqAbstractButtonEventTranslator(QObject* p) bool pqAbstractButtonEventTranslator::translateEvent(QObject* Object, QEvent* Event, bool& Error) { QAbstractButton* const object = qobject_cast<QAbstractButton*>(Object); - if(!object) - { + if (!object) + { return false; - } + } QPushButton* pushButton = qobject_cast<QPushButton*>(object); QToolButton* toolButton = qobject_cast<QToolButton*>(object); bool withMenu = (pushButton && pushButton->menu()) || - (toolButton && (toolButton->menu() || toolButton->defaultAction() && toolButton->defaultAction()->menu())); - switch(Event->type()) - { + (toolButton && (toolButton->menu() || + toolButton->defaultAction() && toolButton->defaultAction()->menu())); + switch (Event->type()) + { case QEvent::KeyPress: - { + { QKeyEvent* const e = dynamic_cast<QKeyEvent*>(Event); - if(e->key() == Qt::Key_Space) - { + if (e->key() == Qt::Key_Space) + { onActivate(object); - } + } return true; break; - } + } case QEvent::MouseButtonPress: - { + { QMouseEvent* const e = dynamic_cast<QMouseEvent*>(Event); this->LastMouseEventType = Event->type(); // Menus are opened on mouse press - if(e->button() == Qt::LeftButton && - object->rect().contains(e->pos()) && - this->hasMenu(object)) - { + if (e->button() == Qt::LeftButton && object->rect().contains(e->pos()) && + this->hasMenu(object)) + { onActivate(object); - } + } return true; break; - } + } case QEvent::Timer: - { + { if (this->LastMouseEventType == QEvent::MouseButtonPress) - { + { QToolButton* tButton = qobject_cast<QToolButton*>(object); - if(tButton && - tButton->popupMode() == QToolButton::DelayedPopup) - { + if (tButton && tButton->popupMode() == QToolButton::DelayedPopup) + { emit recordEvent(object, "longActivate", ""); // Tell comming mouse button release to not record activate. this->LastMouseEventType = QEvent::None; - } } + } return true; break; - } + } case QEvent::MouseButtonRelease: - { - bool lastEventWasMouseButtonPress = - this->LastMouseEventType == QEvent::MouseButtonPress; + { + bool lastEventWasMouseButtonPress = this->LastMouseEventType == QEvent::MouseButtonPress; QMouseEvent* const e = dynamic_cast<QMouseEvent*>(Event); this->LastMouseEventType = Event->type(); // Buttons are activated on mouse release. Menus should already be recorded. - if (e->button() == Qt::LeftButton - && object->rect().contains(e->pos()) - && !this->hasMenu(object) - && lastEventWasMouseButtonPress) - { + if (e->button() == Qt::LeftButton && object->rect().contains(e->pos()) && + !this->hasMenu(object) && lastEventWasMouseButtonPress) + { onActivate(object); - } + } return true; break; - } - default: - break; } + default: + break; + } return this->Superclass::translateEvent(Object, Event, Error); } @@ -127,18 +123,18 @@ void pqAbstractButtonEventTranslator::onActivate(QAbstractButton* actualObject) QObject* object = actualObject; QToolButton* tb = qobject_cast<QToolButton*>(object); if (tb && tb->defaultAction()) - { + { object = tb->defaultAction(); - } - if(actualObject->isCheckable()) - { + } + if (actualObject->isCheckable()) + { const bool new_value = !actualObject->isChecked(); emit recordEvent(object, "set_boolean", new_value ? "true" : "false"); - } + } else - { + { emit recordEvent(object, "activate", ""); - } + } } bool pqAbstractButtonEventTranslator::hasMenu(QAbstractButton* button) const @@ -152,9 +148,8 @@ bool pqAbstractButtonEventTranslator::hasMenu(QAbstractButton* button) const QToolButton* toolButton = qobject_cast<QToolButton*>(button); if (toolButton) { - hasMenu = toolButton->menu() != 0 - || (toolButton->defaultAction() - && toolButton->defaultAction()->menu() != 0); + hasMenu = toolButton->menu() != 0 || + (toolButton->defaultAction() && toolButton->defaultAction()->menu() != 0); hasMenu = hasMenu && toolButton->popupMode() != QToolButton::DelayedPopup; } return hasMenu; diff --git a/pqAbstractButtonEventTranslator.h b/pqAbstractButtonEventTranslator.h index d313f5e..9929ec2 100644 --- a/pqAbstractButtonEventTranslator.h +++ b/pqAbstractButtonEventTranslator.h @@ -7,7 +7,7 @@ All rights reserved. ParaView is a free software; you can redistribute it and/or modify it - under the terms of the ParaView license version 1.2. + under the terms of the ParaView license version 1.2. See License_v1.2.txt for the full ParaView license. A copy of this license can be obtained by contacting @@ -46,14 +46,13 @@ Translates low-level Qt events into high-level ParaView events that can be recor \sa pqEventTranslator */ -class QTTESTING_EXPORT pqAbstractButtonEventTranslator : - public pqWidgetEventTranslator +class QTTESTING_EXPORT pqAbstractButtonEventTranslator : public pqWidgetEventTranslator { Q_OBJECT typedef pqWidgetEventTranslator Superclass; - + public: - pqAbstractButtonEventTranslator(QObject* p=0); + pqAbstractButtonEventTranslator(QObject* p = 0); using Superclass::translateEvent; bool translateEvent(QObject* Object, QEvent* Event, bool& Error) override; @@ -70,4 +69,3 @@ private: }; #endif // !_pqAbstractButtonEventTranslator_h - diff --git a/pqAbstractDoubleEventPlayer.cxx b/pqAbstractDoubleEventPlayer.cxx index 16d2a6d..272b7d7 100644 --- a/pqAbstractDoubleEventPlayer.cxx +++ b/pqAbstractDoubleEventPlayer.cxx @@ -7,7 +7,7 @@ All rights reserved. ParaView is a free software; you can redistribute it and/or modify it - under the terms of the ParaView license version 1.2. + under the terms of the ParaView license version 1.2. See License_v1.2.txt for the full ParaView license. A copy of this license can be obtained by contacting @@ -40,34 +40,34 @@ pqAbstractDoubleEventPlayer::pqAbstractDoubleEventPlayer(QObject* p) { } -bool pqAbstractDoubleEventPlayer::playEvent(QObject* Object, const QString& Command, const QString& Arguments, bool& Error) +bool pqAbstractDoubleEventPlayer::playEvent( + QObject* Object, const QString& Command, const QString& Arguments, bool& Error) { - if(Command != "set_double" && Command != "spin") + if (Command != "set_double" && Command != "spin") return false; const double value = Arguments.toDouble(); - - if(QDoubleSpinBox* const object = qobject_cast<QDoubleSpinBox*>(Object)) + + if (QDoubleSpinBox* const object = qobject_cast<QDoubleSpinBox*>(Object)) + { + if (Command == "set_double") { - if(Command == "set_double") - { object->setValue(value); return true; - } - else if(Command == "spin" && Arguments == "up") - { + } + else if (Command == "spin" && Arguments == "up") + { object->stepUp(); return true; - } - else if(Command == "spin" && Arguments == "down") - { + } + else if (Command == "spin" && Arguments == "down") + { object->stepDown(); return true; - } } + } qCritical() << "calling set_double on unhandled type " << Object; Error = true; return true; } - diff --git a/pqAbstractDoubleEventPlayer.h b/pqAbstractDoubleEventPlayer.h index 8e890a3..e149f2f 100644 --- a/pqAbstractDoubleEventPlayer.h +++ b/pqAbstractDoubleEventPlayer.h @@ -7,7 +7,7 @@ All rights reserved. ParaView is a free software; you can redistribute it and/or modify it - under the terms of the ParaView license version 1.2. + under the terms of the ParaView license version 1.2. See License_v1.2.txt for the full ParaView license. A copy of this license can be obtained by contacting @@ -36,22 +36,23 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "pqWidgetEventPlayer.h" /** -Concrete implementation of pqWidgetEventPlayer that translates high-level ParaView events into low-level Qt events. +Concrete implementation of pqWidgetEventPlayer that translates high-level ParaView events into +low-level Qt events. \sa pqEventPlayer */ -class QTTESTING_EXPORT pqAbstractDoubleEventPlayer : - public pqWidgetEventPlayer +class QTTESTING_EXPORT pqAbstractDoubleEventPlayer : public pqWidgetEventPlayer { Q_OBJECT typedef pqWidgetEventPlayer Superclass; public: - pqAbstractDoubleEventPlayer(QObject* p=0); + pqAbstractDoubleEventPlayer(QObject* p = 0); using Superclass::playEvent; - bool playEvent(QObject* Object, const QString& Command, const QString& Arguments, bool& Error) override; + bool playEvent( + QObject* Object, const QString& Command, const QString& Arguments, bool& Error) override; private: pqAbstractDoubleEventPlayer(const pqAbstractDoubleEventPlayer&); @@ -59,4 +60,3 @@ private: }; #endif // !_pqAbstractDoubleEventPlayer_h - diff --git a/pqAbstractIntEventPlayer.cxx b/pqAbstractIntEventPlayer.cxx index 95bc3b3..d16428f 100644 --- a/pqAbstractIntEventPlayer.cxx +++ b/pqAbstractIntEventPlayer.cxx @@ -7,7 +7,7 @@ All rights reserved. ParaView is a free software; you can redistribute it and/or modify it - under the terms of the ParaView license version 1.2. + under the terms of the ParaView license version 1.2. See License_v1.2.txt for the full ParaView license. A copy of this license can be obtained by contacting @@ -41,46 +41,46 @@ pqAbstractIntEventPlayer::pqAbstractIntEventPlayer(QObject* p) { } -bool pqAbstractIntEventPlayer::playEvent(QObject* Object, const QString& Command, const QString& Arguments, bool& Error) +bool pqAbstractIntEventPlayer::playEvent( + QObject* Object, const QString& Command, const QString& Arguments, bool& Error) { - if(Command != "set_int" && Command != "spin") + if (Command != "set_int" && Command != "spin") return false; const int value = Arguments.toInt(); - - if(QAbstractSlider* const object = qobject_cast<QAbstractSlider*>(Object)) - { + + if (QAbstractSlider* const object = qobject_cast<QAbstractSlider*>(Object)) + { object->setValue(value); return true; - } + } - if(QSpinBox* const object = qobject_cast<QSpinBox*>(Object)) + if (QSpinBox* const object = qobject_cast<QSpinBox*>(Object)) + { + if (Command == "set_int") { - if(Command == "set_int") - { object->setValue(value); return true; - } - else if(Command == "spin" && Arguments == "up") - { + } + else if (Command == "spin" && Arguments == "up") + { object->stepUp(); return true; - } - else if(Command == "spin" && Arguments == "down") - { + } + else if (Command == "spin" && Arguments == "down") + { object->stepDown(); return true; - } } + } if (Command == "spin") - { + { // let pqAbstractEventPlayer handle it if possible. return false; - } + } qCritical() << "calling set_int on unhandled type " << Object; Error = true; return true; } - diff --git a/pqAbstractIntEventPlayer.h b/pqAbstractIntEventPlayer.h index 256cf15..533d940 100644 --- a/pqAbstractIntEventPlayer.h +++ b/pqAbstractIntEventPlayer.h @@ -7,7 +7,7 @@ All rights reserved. ParaView is a free software; you can redistribute it and/or modify it - under the terms of the ParaView license version 1.2. + under the terms of the ParaView license version 1.2. See License_v1.2.txt for the full ParaView license. A copy of this license can be obtained by contacting @@ -36,23 +36,23 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "pqWidgetEventPlayer.h" /** -Concrete implementation of pqWidgetEventPlayer that translates high-level ParaView events into low-level Qt events. +Concrete implementation of pqWidgetEventPlayer that translates high-level ParaView events into +low-level Qt events. \sa pqEventPlayer */ -class QTTESTING_EXPORT pqAbstractIntEventPlayer : - public pqWidgetEventPlayer +class QTTESTING_EXPORT pqAbstractIntEventPlayer : public pqWidgetEventPlayer { Q_OBJECT typedef pqWidgetEventPlayer Superclass; - public: - pqAbstractIntEventPlayer(QObject* p=0); + pqAbstractIntEventPlayer(QObject* p = 0); using Superclass::playEvent; - bool playEvent(QObject* Object, const QString& Command, const QString& Arguments, bool& Error) override; + bool playEvent( + QObject* Object, const QString& Command, const QString& Arguments, bool& Error) override; private: pqAbstractIntEventPlayer(const pqAbstractIntEventPlayer&); @@ -60,4 +60,3 @@ private: }; #endif // !_pqAbstractIntEventPlayer_h - diff --git a/pqAbstractItemViewEventPlayer.cxx b/pqAbstractItemViewEventPlayer.cxx index de6046b..95860b0 100644 --- a/pqAbstractItemViewEventPlayer.cxx +++ b/pqAbstractItemViewEventPlayer.cxx @@ -33,37 +33,37 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "pqAbstractItemViewEventPlayer.h" #include <QAbstractItemView> -#include <QHeaderView> #include <QApplication> -#include <QMouseEvent> +#include <QHeaderView> #include <QKeyEvent> -#include <QtDebug> #include <QList> #include <QListWidget> -#include <QWheelEvent> #include <QMenu> +#include <QMouseEvent> +#include <QWheelEvent> +#include <QtDebug> #include "pqEventDispatcher.h" /// Converts a string representation of a model index into the real thing static QModelIndex OldGetIndex(QAbstractItemView& View, const QString& Name) { - QStringList rows = Name.split('/', QString::SkipEmptyParts); - QString column; + QStringList rows = Name.split('/', QString::SkipEmptyParts); + QString column; - if (rows.size()) - { - column = rows.back().split('|').at(1); - rows.back() = rows.back().split('|').at(0); - } + if (rows.size()) + { + column = rows.back().split('|').at(1); + rows.back() = rows.back().split('|').at(0); + } - QModelIndex index; - for (int i = 0; i != rows.size(); ++i) - { - index = View.model()->index(rows[i].toInt(), column.toInt(), index); - } + QModelIndex index; + for (int i = 0; i != rows.size(); ++i) + { + index = View.model()->index(rows[i].toInt(), column.toInt(), index); + } - return index; + return index; } static QModelIndex GetIndexByItemName(QAbstractItemView& View, const QString& Name) @@ -72,16 +72,16 @@ static QModelIndex GetIndexByItemName(QAbstractItemView& View, const QString& Na QModelIndex index; if (!listWidget) - { + { return index; - } - QList<QListWidgetItem *> findResult = listWidget->findItems(Name, Qt::MatchExactly); + } + QList<QListWidgetItem*> findResult = listWidget->findItems(Name, Qt::MatchExactly); if (findResult.count() > 0) - { + { // in theory more than one item could match? Only return the index for // the first instance. index = View.model()->index(listWidget->row(findResult.first()), 0, index); - } + } return index; } @@ -92,10 +92,10 @@ static QModelIndex GetIndex(QAbstractItemView* View, const QString& Name) QModelIndex index; for (int i = 0; i != idxs.size(); ++i) - { + { QStringList rowCol = idxs[i].split(':'); index = View->model()->index(rowCol[0].toInt(), rowCol[1].toInt(), index); - } + } return index; } @@ -108,72 +108,70 @@ pqAbstractItemViewEventPlayer::pqAbstractItemViewEventPlayer(QObject* p) { } -bool pqAbstractItemViewEventPlayer::playEvent(QObject* Object, const QString& Command, const QString& Arguments, bool& Error) +bool pqAbstractItemViewEventPlayer::playEvent( + QObject* Object, const QString& Command, const QString& Arguments, bool& Error) { QAbstractItemView* object = qobject_cast<QAbstractItemView*>(Object); - QMenu* contextMenu= qobject_cast<QMenu*>(Object); + QMenu* contextMenu = qobject_cast<QMenu*>(Object); // if this a QMenu (potentially a context menu of the view), // we should not move onto parent if (!object && !contextMenu) - { + { // mouse events go to the viewport widget object = qobject_cast<QAbstractItemView*>(Object->parent()); - } + } if (!object) - { + { return false; - } + } if (Command == "key" || Command == "editCancel" || Command == "editAccepted") - { + { // We let the pqBasicWidgetEventPlayer do it ... return false; - } + } - if (Command == "currentChanged") // left to support old recordings - { + if (Command == "currentChanged") // left to support old recordings + { const QModelIndex index = OldGetIndex(*object, Arguments); if (!index.isValid()) return false; object->setCurrentIndex(index); return true; - } + } else if (Command == "currentChangedbyItemName") - { + { const QModelIndex index = GetIndexByItemName(*object, Arguments); if (!index.isValid()) return false; object->setCurrentIndex(index); return true; - } + } else if (Command == "keyEvent") - { + { QStringList data = Arguments.split(','); if (data.size() == 6) - { - QKeyEvent ke(static_cast<QEvent::Type>(data[0].toInt()), - data[1].toInt(), - static_cast<Qt::KeyboardModifiers>(data[2].toInt()), - data[3], - !!data[4].toInt(), - data[5].toInt()); + { + QKeyEvent ke(static_cast<QEvent::Type>(data[0].toInt()), data[1].toInt(), + static_cast<Qt::KeyboardModifiers>(data[2].toInt()), data[3], !!data[4].toInt(), + data[5].toInt()); qApp->notify(object, &ke); return true; - } } + } else if (Command.startsWith("mouse")) - { + { QStringList args = Arguments.split(','); if (args.size() == 5) - { + { // Sometime, mouseWheel event does not contain the index, in that case, // they should be played by the basic widget event player return false; - } + } if (args.size() == 6) - { + { Qt::MouseButtons buttons = static_cast<Qt::MouseButton>(args[1].toInt()); Qt::KeyboardModifiers keym = static_cast<Qt::KeyboardModifier>(args[2].toInt()); int x = args[3].toInt(); @@ -181,31 +179,31 @@ bool pqAbstractItemViewEventPlayer::playEvent(QObject* Object, const QString& Co QPoint pt; QHeaderView* header = qobject_cast<QHeaderView*>(object); if (header) - { + { int idx = args[5].toInt(); if (header->orientation() == Qt::Horizontal) - { + { pt = QPoint(header->sectionPosition(idx) + 4, 4); - } + } else - { + { pt = QPoint(4, header->sectionPosition(idx) + 4); - } } + } else - { + { QModelIndex idx = GetIndex(object, args[5]); object->scrollTo(idx); QRect r = object->visualRect(idx); pt = r.topLeft() + QPoint(x, y); - } + } if (Command == "mouseWheel") - { - int delta = args[0].toInt(); - QWheelEvent we(QPoint(x, y), delta, buttons, keym); - QCoreApplication::sendEvent(Object, &we); - return true; - } + { + int delta = args[0].toInt(); + QWheelEvent we(QPoint(x, y), delta, buttons, keym); + QCoreApplication::sendEvent(Object, &we); + return true; + } Qt::MouseButton button = static_cast<Qt::MouseButton>(args[0].toInt()); QEvent::Type type = QEvent::MouseButtonPress; type = Command == "mouseMove" ? QEvent::MouseMove : type; @@ -214,13 +212,13 @@ bool pqAbstractItemViewEventPlayer::playEvent(QObject* Object, const QString& Co QMouseEvent e(type, pt, button, buttons, keym); qApp->notify(object->viewport(), &e); return true; - } } + } if (!this->Superclass::playEvent(Object, Command, Arguments, Error)) - { + { qCritical() << "Unknown abstract item command: " << Command << "\n"; Error = true; - } + } return true; } diff --git a/pqAbstractItemViewEventPlayer.h b/pqAbstractItemViewEventPlayer.h index c66fa3e..f6e2640 100644 --- a/pqAbstractItemViewEventPlayer.h +++ b/pqAbstractItemViewEventPlayer.h @@ -7,7 +7,7 @@ All rights reserved. ParaView is a free software; you can redistribute it and/or modify it - under the terms of the ParaView license version 1.2. + under the terms of the ParaView license version 1.2. See License_v1.2.txt for the full ParaView license. A copy of this license can be obtained by contacting @@ -36,22 +36,23 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "pqWidgetEventPlayer.h" /** -Concrete implementation of pqWidgetEventPlayer that translates high-level ParaView events into low-level Qt events. +Concrete implementation of pqWidgetEventPlayer that translates high-level ParaView events into +low-level Qt events. \sa pqEventPlayer */ -class QTTESTING_EXPORT pqAbstractItemViewEventPlayer : - public pqWidgetEventPlayer +class QTTESTING_EXPORT pqAbstractItemViewEventPlayer : public pqWidgetEventPlayer { Q_OBJECT typedef pqWidgetEventPlayer Superclass; public: - pqAbstractItemViewEventPlayer(QObject* p=0); + pqAbstractItemViewEventPlayer(QObject* p = 0); using Superclass::playEvent; - bool playEvent(QObject* Object, const QString& Command, const QString& Arguments, bool& Error) override; + bool playEvent( + QObject* Object, const QString& Command, const QString& Arguments, bool& Error) override; private: pqAbstractItemViewEventPlayer(const pqAbstractItemViewEventPlayer&); @@ -59,4 +60,3 @@ private: }; #endif // !_pqAbstractItemViewEventPlayer_h - diff --git a/pqAbstractItemViewEventPlayerBase.cxx b/pqAbstractItemViewEventPlayerBase.cxx index 5e6e1a3..69a535f 100644 --- a/pqAbstractItemViewEventPlayerBase.cxx +++ b/pqAbstractItemViewEventPlayerBase.cxx @@ -50,135 +50,138 @@ pqAbstractItemViewEventPlayerBase::~pqAbstractItemViewEventPlayerBase() } //----------------------------------------------------------------------------- -QModelIndex pqAbstractItemViewEventPlayerBase::GetIndex(const QString& itemStr, - QAbstractItemView* abstractItemView, bool &error) +QModelIndex pqAbstractItemViewEventPlayerBase::GetIndex( + const QString& itemStr, QAbstractItemView* abstractItemView, bool& error) { // Get only the "index" part of the string int sep = itemStr.indexOf(","); QString strIndex = itemStr.left(sep); // Recover model index - QStringList indices = strIndex.split(".",QString::SkipEmptyParts); + QStringList indices = strIndex.split(".", QString::SkipEmptyParts); QModelIndex index; - if(indices.size() < 2) - { + if (indices.size() < 2) + { error = true; return index; - } + } index = abstractItemView->model()->index(indices[0].toInt(), indices[1].toInt(), index); - for (int cc=2; (cc+1) < indices.size(); cc+=2) - { - index = abstractItemView->model()->index(indices[cc].toInt(), indices[cc+1].toInt(), - index); + for (int cc = 2; (cc + 1) < indices.size(); cc += 2) + { + index = abstractItemView->model()->index(indices[cc].toInt(), indices[cc + 1].toInt(), index); if (!index.isValid()) - { - error=true; + { + error = true; qCritical() << "ERROR: Abstract Item view must have changed. " - << "Indices recorded in the test are no longer valid. Cannot playback."; + << "Indices recorded in the test are no longer valid. Cannot playback."; break; - } } + } return index; } //----------------------------------------------------------------------------- -QString pqAbstractItemViewEventPlayerBase::GetDataString(const QString& itemStr, bool &error) +QString pqAbstractItemViewEventPlayerBase::GetDataString(const QString& itemStr, bool& error) { // Get only the "data" part of the string int sep = itemStr.indexOf(","); - return itemStr.mid(sep+1); + return itemStr.mid(sep + 1); } //----------------------------------------------------------------------------- bool pqAbstractItemViewEventPlayerBase::playEvent( - QObject* object, const QString& command, - const QString& arguments, int eventType, bool& error) + QObject* object, const QString& command, const QString& arguments, int eventType, bool& error) { - QAbstractItemView* abstractItemView= qobject_cast<QAbstractItemView*>(object); - QMenu* contextMenu= qobject_cast<QMenu*>(object); + QAbstractItemView* abstractItemView = qobject_cast<QAbstractItemView*>(object); + QMenu* contextMenu = qobject_cast<QMenu*>(object); // if this a QMenu (potentially a context menu of the view), // we should not move onto parent - if(!abstractItemView && !contextMenu) - { + if (!abstractItemView && !contextMenu) + { // mouse events go to the viewport widget abstractItemView = qobject_cast<QAbstractItemView*>(object->parent()); - } - if(!abstractItemView) - { + } + if (!abstractItemView) + { return false; - } + } if (eventType == pqEventTypes::ACTION_EVENT) - { + { if (command == "key") - { + { return false; - } + } QRegExp regExp1("^([\\d\\.]+),(\\d+)$"); if (command == "setCheckState" && regExp1.indexIn(arguments) != -1) - { + { QString strIndex = regExp1.cap(1); int check_state = regExp1.cap(2).toInt(); - QModelIndex index = pqAbstractItemViewEventPlayerBase::GetIndex(strIndex, abstractItemView, error); + QModelIndex index = + pqAbstractItemViewEventPlayerBase::GetIndex(strIndex, abstractItemView, error); if (error) - { + { return true; - } - if (abstractItemView->model()->data(index, - Qt::CheckStateRole).toInt() != check_state) - { - abstractItemView->model()->setData(index, - static_cast<Qt::CheckState>(check_state), - Qt::CheckStateRole); - } - return true; } - else if(command == "edit") + if (abstractItemView->model()->data(index, Qt::CheckStateRole).toInt() != check_state) { + abstractItemView->model()->setData( + index, static_cast<Qt::CheckState>(check_state), Qt::CheckStateRole); + } + return true; + } + else if (command == "edit") + { QString strIndex = arguments; - QModelIndex index = pqAbstractItemViewEventPlayerBase::GetIndex(strIndex, abstractItemView, error); + QModelIndex index = + pqAbstractItemViewEventPlayerBase::GetIndex(strIndex, abstractItemView, error); if (error) - { + { return true; - } + } abstractItemView->edit(index); return true; - } + } else if (command == "editCancel") - { + { QString strIndex = arguments; - QModelIndex index = pqAbstractItemViewEventPlayerBase::GetIndex(strIndex, abstractItemView, error); + QModelIndex index = + pqAbstractItemViewEventPlayerBase::GetIndex(strIndex, abstractItemView, error); abstractItemView->closePersistentEditor(index); return true; - } + } else if (command == "editAccepted") - { + { QStringList list = arguments.split(','); - QModelIndex index = pqAbstractItemViewEventPlayerBase::GetIndex(list.at(0), abstractItemView, error); + QModelIndex index = + pqAbstractItemViewEventPlayerBase::GetIndex(list.at(0), abstractItemView, error); QVariant value = QVariant(list.at(1)); abstractItemView->model()->setData(index, value); abstractItemView->closePersistentEditor(index); return true; - } + } else if (command == "setCurrent" || command == "activate") - { + { QString strIndex = arguments; - QModelIndex index = pqAbstractItemViewEventPlayerBase::GetIndex(strIndex, abstractItemView, error); + QModelIndex index = + pqAbstractItemViewEventPlayerBase::GetIndex(strIndex, abstractItemView, error); if (error) - { + { return true; - } + } abstractItemView->setFocus(); abstractItemView->setCurrentIndex(index); // The following code will cause a modal dialog to close, - // such as the pqColorPresetDialog, if the abstractItemView widget is not handling the key event, + // such as the pqColorPresetDialog, if the abstractItemView widget is not handling the key + // event, // the key event will bevpropogated to the abstractItemView's parent, in this case the dialog, // and the dialog be default has OK/Cancel button in focus, and will process the key event, // close itself. This is causing a few a paraview's tests using pqColorPresetDialog to fail. // The fix here (above) is to add "abstractItemView->setFocus();" so that the - // "abstractItemView->setCurrentIndex(index);" will trigger selection changed event in abstractItemView, + // "abstractItemView->setCurrentIndex(index);" will trigger selection changed event in + // abstractItemView, // which is the purpose of the following code. /* QKeyEvent kd(QEvent::KeyPress, Qt::Key_Enter, Qt::NoModifier); @@ -188,51 +191,49 @@ bool pqAbstractItemViewEventPlayerBase::playEvent( */ return true; - } } + } else if (eventType == pqEventTypes::CHECK_EVENT) - { + { if (command == "modelItemData") - { + { // Recover index to check QString itemString = arguments; - QModelIndex index = pqAbstractItemViewEventPlayerBase::GetIndex(itemString, abstractItemView, error); + QModelIndex index = + pqAbstractItemViewEventPlayerBase::GetIndex(itemString, abstractItemView, error); if (error) - { + { return true; - } + } // Recover Data to check QString testDataString = pqAbstractItemViewEventPlayerBase::GetDataString(itemString, error); if (error) - { + { return true; - } + } // Recover current data, replacing tab by space as they are not existing in xml QString currentDataString = index.data().toString(); currentDataString.replace("\t", " "); // Compare strings if (currentDataString != testDataString) - { - qCritical() << "ERROR: Checked item contain :" - << index.data().toString() << ".Expecting :" - << testDataString; + { + qCritical() << "ERROR: Checked item contain :" << index.data().toString() + << ".Expecting :" << testDataString; error = true; - } - return true; } + return true; + } else if (command == "modelRowCount") - { + { if (abstractItemView->model()->rowCount() != arguments.toInt()) - { + { qCritical() << "ERROR: Checked abstract item view has " - << abstractItemView->model()->rowCount() << " rows. Expecting :" - << arguments; + << abstractItemView->model()->rowCount() << " rows. Expecting :" << arguments; error = true; - } - return true; } + return true; } + } return this->Superclass::playEvent(object, command, arguments, eventType, error); } - diff --git a/pqAbstractItemViewEventPlayerBase.h b/pqAbstractItemViewEventPlayerBase.h index 418df75..fee3ff4 100644 --- a/pqAbstractItemViewEventPlayerBase.h +++ b/pqAbstractItemViewEventPlayerBase.h @@ -43,25 +43,27 @@ class QTTESTING_EXPORT pqAbstractItemViewEventPlayerBase : public pqWidgetEventP { Q_OBJECT typedef pqWidgetEventPlayer Superclass; + public: - pqAbstractItemViewEventPlayerBase(QObject* parent=0); - ~pqAbstractItemViewEventPlayerBase() override =0; + pqAbstractItemViewEventPlayerBase(QObject* parent = 0); + ~pqAbstractItemViewEventPlayerBase() override = 0; /// Play an event on a QAbstractViewItem using Superclass::playEvent; - bool playEvent(QObject* object, const QString& command, - const QString& arguments, int eventType, bool& error) override; + bool playEvent(QObject* object, const QString& command, const QString& arguments, int eventType, + bool& error) override; protected: /// Get index using a previously recorded string - static QModelIndex GetIndex(const QString& str_index, QAbstractItemView* abstractItemView, bool &error); + static QModelIndex GetIndex( + const QString& str_index, QAbstractItemView* abstractItemView, bool& error); /// Get data string using a previously recorded string - static QString GetDataString(const QString& str_index, bool &error); + static QString GetDataString(const QString& str_index, bool& error); private: pqAbstractItemViewEventPlayerBase(const pqAbstractItemViewEventPlayerBase&); // Not implemented. - void operator=(const pqAbstractItemViewEventPlayerBase&); // Not implemented. + void operator=(const pqAbstractItemViewEventPlayerBase&); // Not implemented. }; #endif diff --git a/pqAbstractItemViewEventTranslator.cxx b/pqAbstractItemViewEventTranslator.cxx index 8a5447a..7fbcc7d 100644 --- a/pqAbstractItemViewEventTranslator.cxx +++ b/pqAbstractItemViewEventTranslator.cxx @@ -33,17 +33,17 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "pqAbstractItemViewEventTranslator.h" #include <QAbstractItemView> -#include <QHeaderView> #include <QEvent> +#include <QHeaderView> #include <QKeyEvent> static QString toIndexStr(QModelIndex index) { QString result; - for(QModelIndex i = index; i.isValid(); i = i.parent()) - { + for (QModelIndex i = index; i.isValid(); i = i.parent()) + { result = "/" + QString("%1:%2").arg(i.row()).arg(i.column()) + result; - } + } return result; } @@ -55,103 +55,103 @@ pqAbstractItemViewEventTranslator::pqAbstractItemViewEventTranslator(QObject* p) bool pqAbstractItemViewEventTranslator::translateEvent(QObject* Object, QEvent* Event, bool& Error) { QAbstractItemView* object = qobject_cast<QAbstractItemView*>(Object); - if(!object) - { + if (!object) + { // mouse events go to the viewport widget object = qobject_cast<QAbstractItemView*>(Object->parent()); - } - if(!object) - { + } + if (!object) + { return false; - } + } // Don't try to record events for QComboBox implementation details - if(object->inherits("QComboBoxListView")) - { + if (object->inherits("QComboBoxListView")) + { return false; - } + } - switch(Event->type()) - { + switch (Event->type()) + { case QEvent::KeyPress: case QEvent::KeyRelease: - { + { QKeyEvent* ke = static_cast<QKeyEvent*>(Event); - QString data =QString("%1,%2,%3,%4,%5,%6") - .arg(ke->type()) - .arg(ke->key()) - .arg(static_cast<int>(ke->modifiers())) - .arg(ke->text()) - .arg(ke->isAutoRepeat()) - .arg(ke->count()); + QString data = QString("%1,%2,%3,%4,%5,%6") + .arg(ke->type()) + .arg(ke->key()) + .arg(static_cast<int>(ke->modifiers())) + .arg(ke->text()) + .arg(ke->isAutoRepeat()) + .arg(ke->count()); emit recordEvent(object, "keyEvent", data); return true; - } + } case QEvent::MouseButtonPress: case QEvent::MouseButtonDblClick: case QEvent::MouseButtonRelease: + { + if (Object == object) { - if(Object == object) - { return false; - } + } QMouseEvent* mouseEvent = static_cast<QMouseEvent*>(Event); - if(Event->type() != QEvent::MouseButtonRelease) - { + if (Event->type() != QEvent::MouseButtonRelease) + { this->LastPos = mouseEvent->pos(); - } + } QString idxStr; - QPoint relPt = QPoint(0,0); + QPoint relPt = QPoint(0, 0); QHeaderView* header = qobject_cast<QHeaderView*>(object); - if(header) - { + if (header) + { int idx = header->logicalIndexAt(mouseEvent->pos()); idxStr = QString("%1").arg(idx); - } + } else - { + { QModelIndex idx = object->indexAt(mouseEvent->pos()); idxStr = toIndexStr(idx); QRect r = object->visualRect(idx); relPt = mouseEvent->pos() - r.topLeft(); - } + } QString info = QString("%1,%2,%3,%4,%5,%6") - .arg(mouseEvent->button()) - .arg(mouseEvent->buttons()) - .arg(mouseEvent->modifiers()) - .arg(relPt.x()) - .arg(relPt.y()) - .arg(idxStr); - if(Event->type() == QEvent::MouseButtonPress) - { + .arg(mouseEvent->button()) + .arg(mouseEvent->buttons()) + .arg(mouseEvent->modifiers()) + .arg(relPt.x()) + .arg(relPt.y()) + .arg(idxStr); + if (Event->type() == QEvent::MouseButtonPress) + { emit recordEvent(object, "mousePress", info); - } - else if(Event->type() == QEvent::MouseButtonDblClick) - { + } + else if (Event->type() == QEvent::MouseButtonDblClick) + { emit recordEvent(object, "mouseDblClick", info); - } - else if(Event->type() == QEvent::MouseButtonRelease) + } + else if (Event->type() == QEvent::MouseButtonRelease) + { + if (this->LastPos != mouseEvent->pos()) { - if(this->LastPos != mouseEvent->pos()) - { emit recordEvent(object, "mouseMove", info); - } - emit recordEvent(object, "mouseRelease", info); } + emit recordEvent(object, "mouseRelease", info); + } return true; break; - } + } case QEvent::Wheel: + { + if (Object == object) { - if(Object == object) - { return false; - } - QPoint relPt = QPoint(0,0); + } + QPoint relPt = QPoint(0, 0); QWheelEvent* wheelEvent = dynamic_cast<QWheelEvent*>(Event); - if(wheelEvent) - { + if (wheelEvent) + { QString idxStr; QModelIndex idx = object->indexAt(wheelEvent->pos()); idxStr = toIndexStr(idx); @@ -161,21 +161,20 @@ bool pqAbstractItemViewEventTranslator::translateEvent(QObject* Object, QEvent* int buttons = wheelEvent->buttons(); int modifiers = wheelEvent->modifiers(); emit emit recordEvent(Object, "mouseWheel", QString("%1,%2,%3,%4,%5") - .arg(numStep) - .arg(buttons) - .arg(modifiers) - .arg(relPt.x()) - .arg(relPt.y()) - .arg(idxStr)); - } + .arg(numStep) + .arg(buttons) + .arg(modifiers) + .arg(relPt.x()) + .arg(relPt.y()) + .arg(idxStr)); + } return true; break; - } + } default: - { + { break; - } } + } return this->Superclass::translateEvent(Object, Event, Error); } - diff --git a/pqAbstractItemViewEventTranslator.h b/pqAbstractItemViewEventTranslator.h index 06936fe..b103d49 100644 --- a/pqAbstractItemViewEventTranslator.h +++ b/pqAbstractItemViewEventTranslator.h @@ -7,7 +7,7 @@ All rights reserved. ParaView is a free software; you can redistribute it and/or modify it - under the terms of the ParaView license version 1.2. + under the terms of the ParaView license version 1.2. See License_v1.2.txt for the full ParaView license. A copy of this license can be obtained by contacting @@ -42,26 +42,23 @@ Translates low-level Qt events into high-level ParaView events that can be recor \sa pqEventTranslator */ -class QTTESTING_EXPORT pqAbstractItemViewEventTranslator : - public pqWidgetEventTranslator +class QTTESTING_EXPORT pqAbstractItemViewEventTranslator : public pqWidgetEventTranslator { Q_OBJECT typedef pqWidgetEventTranslator Superclass; - + public: - pqAbstractItemViewEventTranslator(QObject* p=0); + pqAbstractItemViewEventTranslator(QObject* p = 0); using Superclass::translateEvent; bool translateEvent(QObject* Object, QEvent* Event, bool& Error) override; - -protected: + +protected: QPoint LastPos; private: pqAbstractItemViewEventTranslator(const pqAbstractItemViewEventTranslator&); pqAbstractItemViewEventTranslator& operator=(const pqAbstractItemViewEventTranslator&); - }; #endif // !_pqAbstractItemViewEventTranslator_h - diff --git a/pqAbstractItemViewEventTranslatorBase.cxx b/pqAbstractItemViewEventTranslatorBase.cxx index 1e293ae..804fde4 100644 --- a/pqAbstractItemViewEventTranslatorBase.cxx +++ b/pqAbstractItemViewEventTranslatorBase.cxx @@ -32,9 +32,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "pqAbstractItemViewEventTranslatorBase.h" #include "pqEventTypes.h" +#include <QAbstractItemView> #include <QEvent> #include <QKeyEvent> -#include <QAbstractItemView> #include <QVariant> //----------------------------------------------------------------------------- @@ -52,9 +52,9 @@ pqAbstractItemViewEventTranslatorBase::pqAbstractItemViewEventTranslatorBase(QOb pqAbstractItemViewEventTranslatorBase::~pqAbstractItemViewEventTranslatorBase() { if (this->AbstractItemView != NULL) - { + { this->AbstractItemView->setMouseTracking(this->AbstractItemViewMouseTracking); - } + } } //----------------------------------------------------------------------------- @@ -64,95 +64,95 @@ bool pqAbstractItemViewEventTranslatorBase::translateEvent( // Recover corrected abstract item view QAbstractItemView* abstractItemView = this->findCorrectedAbstractItemView(object); if (!abstractItemView) - { + { return false; - } + } // Don't try to record events for QComboBox implementation details if (abstractItemView->inherits("QComboBoxListView")) - { + { return false; - } + } if (eventType == pqEventTypes::ACTION_EVENT) + { + switch (event->type()) { - switch(event->type()) - { case QEvent::KeyRelease: - { + { QKeyEvent* ke = static_cast<QKeyEvent*>(event); QModelIndex index = abstractItemView->currentIndex(); QString indexString = this->getIndexAsString(index); if (this->Editing) - { + { if (ke->key() == Qt::Key_Enter || ke->key() == Qt::Key_Return) - { + { QVariant value = abstractItemView->model()->data(index); this->Editing = false; emit this->recordEvent(abstractItemView, "editAccepted", QString("%1,%2").arg(indexString, value.toString())); return true; break; - } + } if (ke->key() == Qt::Key_Escape) - { + { this->Editing = false; emit this->recordEvent(abstractItemView, "editCancel", indexString); return true; break; - } } + } else if (ke->key() == Qt::Key_F2) - { + { this->Editing = true; emit this->recordEvent(abstractItemView, "edit", indexString); return true; break; - } - break; } + break; + } case QEvent::Enter: - { + { if (this->AbstractItemView != abstractItemView || this->Checking) - { - //Checking flag + { + // Checking flag this->Checking = false; - if(this->AbstractItemView) - { + if (this->AbstractItemView) + { QObject::disconnect(this->AbstractItemView, 0, this, 0); QObject::disconnect(this->AbstractItemView->selectionModel(), 0, this, 0); - } + } this->connectWidgetToSlots(abstractItemView); this->AbstractItemView = abstractItemView; - } + } return true; break; - } + } default: - { + { break; - } } } + } else if (eventType == pqEventTypes::CHECK_EVENT) - { + { if (event->type() == QEvent::MouseMove) - { + { // Entering while checking if (this->AbstractItemView != abstractItemView || !this->Checking) - { - //Checking flag + { + // Checking flag this->Checking = true; // Disconnect precedently check item view if (this->AbstractItemView != NULL) - { + { this->AbstractItemView->setMouseTracking(this->AbstractItemViewMouseTracking); - QObject::disconnect(this->AbstractItemView, SIGNAL(entered(const QModelIndex&)), - this, SLOT(onEnteredCheck(const QModelIndex&))); - QObject::disconnect(this->AbstractItemView, SIGNAL(viewportEntered()), - this, SLOT(onViewportEnteredCheck())); - } + QObject::disconnect(this->AbstractItemView, SIGNAL(entered(const QModelIndex&)), this, + SLOT(onEnteredCheck(const QModelIndex&))); + QObject::disconnect(this->AbstractItemView, SIGNAL(viewportEntered()), this, + SLOT(onViewportEnteredCheck())); + } // Keep track of checked item view this->AbstractItemView = abstractItemView; @@ -162,77 +162,81 @@ bool pqAbstractItemViewEventTranslatorBase::translateEvent( this->AbstractItemView->setMouseTracking(true); // Connect item entered event to the entered check slot - QObject::connect(this->AbstractItemView, SIGNAL(entered(const QModelIndex&)), - this, SLOT(onEnteredCheck(const QModelIndex&))); - QObject::connect(this->AbstractItemView, SIGNAL(viewportEntered()), - this, SLOT(onViewportEnteredCheck())); - } - return true; + QObject::connect(this->AbstractItemView, SIGNAL(entered(const QModelIndex&)), this, + SLOT(onEnteredCheck(const QModelIndex&))); + QObject::connect( + this->AbstractItemView, SIGNAL(viewportEntered()), this, SLOT(onViewportEnteredCheck())); } + return true; + } // Clicking while checking, actual check event if (event->type() == QEvent::MouseButtonRelease) - { + { // Item Check if (this->ModelItemCheck != NULL) - { + { QString indexString = this->getIndexAsString(*this->ModelItemCheck); - emit this->recordEvent(abstractItemView, "modelItemData", QString("%1,%2").arg(indexString).arg( - // Replacing tab by space, as they are not valid in xml - this->ModelItemCheck->data().toString().replace("\t", " ")), + emit this->recordEvent(abstractItemView, "modelItemData", + QString("%1,%2") + .arg(indexString) + .arg( + // Replacing tab by space, as they are not valid in xml + this->ModelItemCheck->data().toString().replace("\t", " ")), pqEventTypes::CHECK_EVENT); - } + } // Abstract Item View nb row check else - { + { emit this->recordEvent(abstractItemView, "modelRowCount", QString::number(abstractItemView->model()->rowCount()), pqEventTypes::CHECK_EVENT); - } - return true; } + return true; } + } return this->Superclass::translateEvent(object, event, eventType, error); } //----------------------------------------------------------------------------- -void pqAbstractItemViewEventTranslatorBase::connectWidgetToSlots(QAbstractItemView* abstractItemView) +void pqAbstractItemViewEventTranslatorBase::connectWidgetToSlots( + QAbstractItemView* abstractItemView) { - QObject::connect(abstractItemView, SIGNAL(clicked(const QModelIndex&)), - this, SLOT(onClicked(const QModelIndex&))); - QObject::connect(abstractItemView, SIGNAL(activated(const QModelIndex&)), - this, SLOT(onActivated(const QModelIndex&))); - QObject::connect(abstractItemView, SIGNAL(doubleClicked(const QModelIndex&)), - this, SLOT(onDoubleClicked(const QModelIndex&))); + QObject::connect(abstractItemView, SIGNAL(clicked(const QModelIndex&)), this, + SLOT(onClicked(const QModelIndex&))); + QObject::connect(abstractItemView, SIGNAL(activated(const QModelIndex&)), this, + SLOT(onActivated(const QModelIndex&))); + QObject::connect(abstractItemView, SIGNAL(doubleClicked(const QModelIndex&)), this, + SLOT(onDoubleClicked(const QModelIndex&))); QObject::connect(abstractItemView->selectionModel(), - SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)), - this, SLOT(onCurrentChanged(const QModelIndex&))); + SIGNAL(currentChanged(const QModelIndex&, const QModelIndex&)), this, + SLOT(onCurrentChanged(const QModelIndex&))); } //----------------------------------------------------------------------------- -void pqAbstractItemViewEventTranslatorBase::onClicked( - const QModelIndex& index) +void pqAbstractItemViewEventTranslatorBase::onClicked(const QModelIndex& index) { static QModelIndex oldIndex; QAbstractItemView* abstractItemView = qobject_cast<QAbstractItemView*>(this->sender()); QString indexString = this->getIndexAsString(index); - if ( (index.model()->flags(index) & Qt::ItemIsUserCheckable) != 0) - { + if ((index.model()->flags(index) & Qt::ItemIsUserCheckable) != 0) + { // record the check state change if the item is user-checkable. - emit this->recordEvent( abstractItemView, "setCheckState", - QString("%1,%3").arg(indexString).arg( - index.model()->data(index,Qt::CheckStateRole).toInt())); - } - if ((abstractItemView->editTriggers() & QAbstractItemView::SelectedClicked) - == QAbstractItemView::SelectedClicked && - index == oldIndex) - { + emit this->recordEvent(abstractItemView, "setCheckState", + QString("%1,%3") + .arg(indexString) + .arg(index.model()->data(index, Qt::CheckStateRole).toInt())); + } + if ((abstractItemView->editTriggers() & QAbstractItemView::SelectedClicked) == + QAbstractItemView::SelectedClicked && + index == oldIndex) + { this->Editing = true; emit this->recordEvent(abstractItemView, "edit", indexString); - } + } oldIndex = index; } //----------------------------------------------------------------------------- -void pqAbstractItemViewEventTranslatorBase::onActivated(const QModelIndex & index) +void pqAbstractItemViewEventTranslatorBase::onActivated(const QModelIndex& index) { QAbstractItemView* abstractItemView = qobject_cast<QAbstractItemView*>(this->sender()); QString indexString = this->getIndexAsString(index); @@ -245,12 +249,12 @@ void pqAbstractItemViewEventTranslatorBase::onDoubleClicked(const QModelIndex& i QAbstractItemView* abstractItemView = qobject_cast<QAbstractItemView*>(this->sender()); QString indexString = this->getIndexAsString(index); // record the check state change if the item is user-checkable. - if ((abstractItemView->editTriggers() & QAbstractItemView::DoubleClicked) - == QAbstractItemView::DoubleClicked) - { + if ((abstractItemView->editTriggers() & QAbstractItemView::DoubleClicked) == + QAbstractItemView::DoubleClicked) + { this->Editing = true; emit this->recordEvent(abstractItemView, "edit", indexString); - } + } } //----------------------------------------------------------------------------- @@ -258,9 +262,9 @@ QString pqAbstractItemViewEventTranslatorBase::getIndexAsString(const QModelInde { QString indexString; for (QModelIndex curIndex = index; curIndex.isValid(); curIndex = curIndex.parent()) - { + { indexString.prepend(QString("%1.%2.").arg(curIndex.row()).arg(curIndex.column())); - } + } // remove the last ".". indexString.chop(1); @@ -270,8 +274,7 @@ QString pqAbstractItemViewEventTranslatorBase::getIndexAsString(const QModelInde //----------------------------------------------------------------------------- void pqAbstractItemViewEventTranslatorBase::onCurrentChanged(const QModelIndex& index) { - emit this->recordEvent(this->AbstractItemView, - "setCurrent", this->getIndexAsString(index)); + emit this->recordEvent(this->AbstractItemView, "setCurrent", this->getIndexAsString(index)); } //----------------------------------------------------------------------------- @@ -280,4 +283,3 @@ void pqAbstractItemViewEventTranslatorBase::onViewportEnteredCheck() this->ModelItemCheck = NULL; emit this->specificOverlay(this->AbstractItemView->rect()); } - diff --git a/pqAbstractItemViewEventTranslatorBase.h b/pqAbstractItemViewEventTranslatorBase.h index 4f0c21f..5baa5f1 100644 --- a/pqAbstractItemViewEventTranslatorBase.h +++ b/pqAbstractItemViewEventTranslatorBase.h @@ -45,8 +45,9 @@ class QTTESTING_EXPORT pqAbstractItemViewEventTranslatorBase : public pqWidgetEv { Q_OBJECT typedef pqWidgetEventTranslator Superclass; + public: - pqAbstractItemViewEventTranslatorBase(QObject* parent=0); + pqAbstractItemViewEventTranslatorBase(QObject* parent = 0); ~pqAbstractItemViewEventTranslatorBase() override; /// Overridden to handle events on QAbstractItemView @@ -66,7 +67,7 @@ protected slots: virtual void onCurrentChanged(const QModelIndex&); /// Compute a visual rectangle for the item and signal it - virtual void onEnteredCheck(const QModelIndex&)=0; + virtual void onEnteredCheck(const QModelIndex&) = 0; virtual void onViewportEnteredCheck(); protected: @@ -80,7 +81,8 @@ protected: QPoint LastPos; private: - pqAbstractItemViewEventTranslatorBase(const pqAbstractItemViewEventTranslatorBase&); // Not implemented. + pqAbstractItemViewEventTranslatorBase( + const pqAbstractItemViewEventTranslatorBase&); // Not implemented. void operator=(const pqAbstractItemViewEventTranslatorBase&); // Not implemented. }; diff --git a/pqAbstractMiscellaneousEventPlayer.cxx b/pqAbstractMiscellaneousEventPlayer.cxx index f33c102..18eaf53 100644 --- a/pqAbstractMiscellaneousEventPlayer.cxx +++ b/pqAbstractMiscellaneousEventPlayer.cxx @@ -7,7 +7,7 @@ All rights reserved. ParaView is a free software; you can redistribute it and/or modify it - under the terms of the ParaView license version 1.2. + under the terms of the ParaView license version 1.2. See License_v1.2.txt for the full ParaView license. A copy of this license can be obtained by contacting @@ -30,14 +30,12 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. =========================================================================*/ - - #include "pqAbstractMiscellaneousEventPlayer.h" #include <QAbstractButton> -#include <QtDebug> #include <QFile> #include <QThread> +#include <QtDebug> #include "pqEventDispatcher.h" @@ -45,7 +43,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. class SleeperThread : public QThread { public: - //Allows for cross platform sleep function + // Allows for cross platform sleep function static bool msleep(unsigned long msecs) { QThread::msleep(msecs); @@ -58,34 +56,33 @@ pqAbstractMiscellaneousEventPlayer::pqAbstractMiscellaneousEventPlayer(QObject* { } -//Allows for execution of testing commands that don't merit their own class -bool pqAbstractMiscellaneousEventPlayer::playEvent(QObject* Object, const QString& Command, const QString& Arguments, bool& Error) +// Allows for execution of testing commands that don't merit their own class +bool pqAbstractMiscellaneousEventPlayer::playEvent( + QObject* Object, const QString& Command, const QString& Arguments, bool& Error) { if (Command == "pause") - { + { const int value = Arguments.toInt(); - if(SleeperThread::msleep(value)) - { + if (SleeperThread::msleep(value)) + { return true; - } + } Error = true; qCritical() << "calling pause on unhandled type " << Object; - } + } if (Command == "process_events") - { + { bool valid = false; const int ms = Arguments.toInt(&valid); if (valid) - { + { pqEventDispatcher::processEventsAndWait(ms); - } + } else - { + { pqEventDispatcher::processEvents(); - } - return true; } + return true; + } return false; } - - diff --git a/pqAbstractMiscellaneousEventPlayer.h b/pqAbstractMiscellaneousEventPlayer.h index d8214ab..bd1602a 100644 --- a/pqAbstractMiscellaneousEventPlayer.h +++ b/pqAbstractMiscellaneousEventPlayer.h @@ -7,7 +7,7 @@ All rights reserved. ParaView is a free software; you can redistribute it and/or modify it - under the terms of the ParaView license version 1.2. + under the terms of the ParaView license version 1.2. See License_v1.2.txt for the full ParaView license. A copy of this license can be obtained by contacting @@ -49,17 +49,17 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. /// the test playback. Unlike "pause" however, this will continue /// to process all events arising in the application e.g. /// responding to timer events. -class QTTESTING_EXPORT pqAbstractMiscellaneousEventPlayer : - public pqWidgetEventPlayer +class QTTESTING_EXPORT pqAbstractMiscellaneousEventPlayer : public pqWidgetEventPlayer { Q_OBJECT typedef pqWidgetEventPlayer Superclass; public: - pqAbstractMiscellaneousEventPlayer(QObject* p=0); + pqAbstractMiscellaneousEventPlayer(QObject* p = 0); using Superclass::playEvent; - bool playEvent(QObject* Object, const QString& Command, const QString& Arguments, bool& Error) override; + bool playEvent( + QObject* Object, const QString& Command, const QString& Arguments, bool& Error) override; private: pqAbstractMiscellaneousEventPlayer(const pqAbstractMiscellaneousEventPlayer&); @@ -67,5 +67,3 @@ private: }; #endif // !_pqAbstractMiscellaneousEventPlayer_h - - diff --git a/pqAbstractSliderEventTranslator.cxx b/pqAbstractSliderEventTranslator.cxx index f493de6..bcee5cf 100644 --- a/pqAbstractSliderEventTranslator.cxx +++ b/pqAbstractSliderEventTranslator.cxx @@ -7,7 +7,7 @@ All rights reserved. ParaView is a free software; you can redistribute it and/or modify it - under the terms of the ParaView license version 1.2. + under the terms of the ParaView license version 1.2. See License_v1.2.txt for the full ParaView license. A copy of this license can be obtained by contacting @@ -32,24 +32,24 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "pqAbstractSliderEventTranslator.h" -#include <QScrollBar> #include <QAbstractSlider> #include <QEvent> +#include <QScrollBar> pqAbstractSliderEventTranslator::pqAbstractSliderEventTranslator(QObject* p) - : pqWidgetEventTranslator(p), - CurrentObject(0) + : pqWidgetEventTranslator(p) + , CurrentObject(0) { } bool pqAbstractSliderEventTranslator::translateEvent(QObject* Object, QEvent* Event, bool& Error) { QAbstractSlider* const object = qobject_cast<QAbstractSlider*>(Object); - if(!object || qobject_cast<QScrollBar*>(object)) + if (!object || qobject_cast<QScrollBar*>(object)) return false; - - switch(Event->type()) - { + + switch (Event->type()) + { case QEvent::Enter: this->CurrentObject = Object; connect(object, SIGNAL(valueChanged(int)), this, SLOT(onValueChanged(int))); @@ -62,7 +62,7 @@ bool pqAbstractSliderEventTranslator::translateEvent(QObject* Object, QEvent* Ev break; default: break; - } + } return this->Superclass::translateEvent(Object, Event, Error); } diff --git a/pqAbstractSliderEventTranslator.h b/pqAbstractSliderEventTranslator.h index b61873d..5e6d48a 100644 --- a/pqAbstractSliderEventTranslator.h +++ b/pqAbstractSliderEventTranslator.h @@ -7,7 +7,7 @@ All rights reserved. ParaView is a free software; you can redistribute it and/or modify it - under the terms of the ParaView license version 1.2. + under the terms of the ParaView license version 1.2. See License_v1.2.txt for the full ParaView license. A copy of this license can be obtained by contacting @@ -41,14 +41,13 @@ Translates low-level Qt events into high-level ParaView events that can be recor \sa pqEventTranslator */ -class QTTESTING_EXPORT pqAbstractSliderEventTranslator : - public pqWidgetEventTranslator +class QTTESTING_EXPORT pqAbstractSliderEventTranslator : public pqWidgetEventTranslator { Q_OBJECT typedef pqWidgetEventTranslator Superclass; - + public: - pqAbstractSliderEventTranslator(QObject* p=0); + pqAbstractSliderEventTranslator(QObject* p = 0); using Superclass::translateEvent; bool translateEvent(QObject* Object, QEvent* Event, bool& Error) override; @@ -58,10 +57,9 @@ private: pqAbstractSliderEventTranslator& operator=(const pqAbstractSliderEventTranslator&); QObject* CurrentObject; - + private slots: - void onValueChanged(int); + void onValueChanged(int); }; #endif // !_pqAbstractSliderEventTranslator_h - diff --git a/pqAbstractStringEventPlayer.cxx b/pqAbstractStringEventPlayer.cxx index 6618abd..59353d6 100644 --- a/pqAbstractStringEventPlayer.cxx +++ b/pqAbstractStringEventPlayer.cxx @@ -46,60 +46,61 @@ pqAbstractStringEventPlayer::pqAbstractStringEventPlayer(QObject* p) { } -bool pqAbstractStringEventPlayer::playEvent(QObject* Object, const QString& Command, const QString& Arguments, bool& Error) +bool pqAbstractStringEventPlayer::playEvent( + QObject* Object, const QString& Command, const QString& Arguments, bool& Error) { if (Command != "set_string") - return false; + return false; const QString value = Arguments; if (QComboBox* const comboBox = qobject_cast<QComboBox*>(Object)) - { + { int index = comboBox->findText(value); if (index != -1) - { + { comboBox->setCurrentIndex(index); - } + } else - { + { QString possibles; for (int i = 0; i < comboBox->count(); i++) - { + { possibles += QString("\t") + comboBox->itemText(i) + QString("\n"); - } - qCritical() << "Unable to find " << value << " in combo box: " - << pqObjectNaming::GetName(*Object) - << "\nPossible values are:\n" << possibles; - Error = true; } - return true; + qCritical() << "Unable to find " << value + << " in combo box: " << pqObjectNaming::GetName(*Object) + << "\nPossible values are:\n" + << possibles; + Error = true; } + return true; + } if (QLineEdit* const lineEdit = qobject_cast<QLineEdit*>(Object)) - { + { lineEdit->setText(value); return true; - } + } if (QTextEdit* const textEdit = qobject_cast<QTextEdit*>(Object)) - { + { textEdit->setFocus(Qt::OtherFocusReason); textEdit->document()->setPlainText(value); textEdit->clearFocus(); return true; - } + } if (QPlainTextEdit* const plainTextEdit = qobject_cast<QPlainTextEdit*>(Object)) - { + { plainTextEdit->setFocus(Qt::OtherFocusReason); plainTextEdit->document()->setPlainText(value); plainTextEdit->clearFocus(); return true; - } + } qCritical() << "calling set_string on unhandled type " << Object; Error = true; return true; } - diff --git a/pqAbstractStringEventPlayer.h b/pqAbstractStringEventPlayer.h index ea9cd81..2512948 100644 --- a/pqAbstractStringEventPlayer.h +++ b/pqAbstractStringEventPlayer.h @@ -7,7 +7,7 @@ All rights reserved. ParaView is a free software; you can redistribute it and/or modify it - under the terms of the ParaView license version 1.2. + under the terms of the ParaView license version 1.2. See License_v1.2.txt for the full ParaView license. A copy of this license can be obtained by contacting @@ -37,7 +37,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "pqWidgetEventPlayer.h" /** -Concrete implementation of pqWidgetEventPlayer that translates high-level ParaView events into low-level Qt events. +Concrete implementation of pqWidgetEventPlayer that translates high-level ParaView events into +low-level Qt events. \sa pqEventPlayer */ @@ -46,11 +47,13 @@ class QTTESTING_EXPORT pqAbstractStringEventPlayer : public pqWidgetEventPlayer { Q_OBJECT typedef pqWidgetEventPlayer Superclass; + public: - pqAbstractStringEventPlayer(QObject* p=0); + pqAbstractStringEventPlayer(QObject* p = 0); using Superclass::playEvent; - bool playEvent(QObject* Object, const QString& Command, const QString& Arguments, bool& Error) override; + bool playEvent( + QObject* Object, const QString& Command, const QString& Arguments, bool& Error) override; private: pqAbstractStringEventPlayer(const pqAbstractStringEventPlayer&); @@ -58,4 +61,3 @@ private: }; #endif // !_pqAbstractStringEventPlayer_h - diff --git a/pqBasicWidgetEventPlayer.cxx b/pqBasicWidgetEventPlayer.cxx index f03a7fb..27663a3 100644 --- a/pqBasicWidgetEventPlayer.cxx +++ b/pqBasicWidgetEventPlayer.cxx @@ -44,96 +44,91 @@ pqBasicWidgetEventPlayer::pqBasicWidgetEventPlayer(QObject* p) { } -bool pqBasicWidgetEventPlayer::playEvent(QObject* object, - const QString& command, const QString& arguments, - int eventType, bool& error) +bool pqBasicWidgetEventPlayer::playEvent( + QObject* object, const QString& command, const QString& arguments, int eventType, bool& error) { QWidget* widget = qobject_cast<QWidget*>(object); - if(widget) - { + if (widget) + { if (eventType == pqEventTypes::ACTION_EVENT) + { { + if (command == "key") { - if(command == "key") - { QKeyEvent kd(QEvent::KeyPress, arguments.toInt(), Qt::NoModifier); QKeyEvent ku(QEvent::KeyRelease, arguments.toInt(), Qt::NoModifier); qApp->notify(widget, &kd); qApp->notify(widget, &ku); return true; - } - else if(command == "keyEvent") - { + } + else if (command == "keyEvent") + { QStringList data = arguments.split(':'); - QKeyEvent ke(static_cast<QEvent::Type>(data[0].toInt()), - data[1].toInt(), - static_cast<Qt::KeyboardModifiers>(data[2].toInt()), - data[3], - !!data[4].toInt(), - data[5].toInt()); + QKeyEvent ke(static_cast<QEvent::Type>(data[0].toInt()), data[1].toInt(), + static_cast<Qt::KeyboardModifiers>(data[2].toInt()), data[3], !!data[4].toInt(), + data[5].toInt()); qApp->notify(widget, &ke); return true; - } - else if(command.startsWith("mouse")) - { + } + else if (command.startsWith("mouse")) + { QStringList args = arguments.split(','); - if(args.size() == 5) - { + if (args.size() == 5) + { Qt::MouseButtons buttons = static_cast<Qt::MouseButton>(args[1].toInt()); Qt::KeyboardModifiers keym = static_cast<Qt::KeyboardModifier>(args[2].toInt()); int x = args[3].toInt(); int y = args[4].toInt(); - QPoint pt(x,y); + QPoint pt(x, y); if (command == "mouseWheel") - { + { int delta = args[0].toInt(); - QWheelEvent we(QPoint(x,y), delta, buttons, keym); + QWheelEvent we(QPoint(x, y), delta, buttons, keym); QCoreApplication::sendEvent(object, &we); return true; - } + } Qt::MouseButton button = static_cast<Qt::MouseButton>(args[0].toInt()); QEvent::Type type = QEvent::MouseButtonPress; type = command == "mouseMove" ? QEvent::MouseMove : type; type = command == "mouseRelease" ? QEvent::MouseButtonRelease : type; type = command == "mouseDblClick" ? QEvent::MouseButtonDblClick : type; if (type == QEvent::MouseMove) - { + { // We have not been setting mouse move correctly. buttons = button; button = Qt::NoButton; - } + } QMouseEvent e(type, pt, button, buttons, keym); qApp->notify(widget, &e); return true; - } } } } + } else if (eventType == pqEventTypes::CHECK_EVENT) - { + { // Recover QProperty QVariant propertyValue = object->property(command.toUtf8().data()); // Check it is valid if (!propertyValue.isValid()) - { + { QString errorMessage = object->objectName() + " has no valid property named:" + command; qCritical() << errorMessage.toUtf8().data(); error = true; return true; - } + } // Check property value if (propertyValue.toString().replace("\t", " ") != arguments) - { - QString errorMessage = object->objectName() + " property value is: " + propertyValue.toString() - + ". Expecting: "+ arguments + "."; + { + QString errorMessage = object->objectName() + " property value is: " + + propertyValue.toString() + ". Expecting: " + arguments + "."; qCritical() << errorMessage.toUtf8().data(); error = true; - } - return true; } + return true; } + } return this->Superclass::playEvent(object, command, arguments, error); } - diff --git a/pqBasicWidgetEventPlayer.h b/pqBasicWidgetEventPlayer.h index bd62ede..0f6ec73 100644 --- a/pqBasicWidgetEventPlayer.h +++ b/pqBasicWidgetEventPlayer.h @@ -7,7 +7,7 @@ All rights reserved. ParaView is a free software; you can redistribute it and/or modify it - under the terms of the ParaView license version 1.2. + under the terms of the ParaView license version 1.2. See License_v1.2.txt for the full ParaView license. A copy of this license can be obtained by contacting @@ -36,22 +36,22 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "pqWidgetEventPlayer.h" /** -Concrete implementation of pqWidgetEventPlayer that handles playback of "activate" events for buttons and menus. +Concrete implementation of pqWidgetEventPlayer that handles playback of "activate" events for +buttons and menus. \sa pqEventPlayer */ -class pqBasicWidgetEventPlayer : - public pqWidgetEventPlayer +class pqBasicWidgetEventPlayer : public pqWidgetEventPlayer { Q_OBJECT typedef pqWidgetEventPlayer Superclass; public: - pqBasicWidgetEventPlayer(QObject* p=0); + pqBasicWidgetEventPlayer(QObject* p = 0); using Superclass::playEvent; - bool playEvent(QObject* object, const QString& command, - const QString& arguments, int eventType, bool& error) override; + bool playEvent(QObject* object, const QString& command, const QString& arguments, int eventType, + bool& error) override; private: pqBasicWidgetEventPlayer(const pqBasicWidgetEventPlayer&); @@ -59,4 +59,3 @@ private: }; #endif // !_pqBasicWidgetEventPlayer_h - diff --git a/pqBasicWidgetEventTranslator.cxx b/pqBasicWidgetEventTranslator.cxx index 50c1208..06ce15a 100644 --- a/pqBasicWidgetEventTranslator.cxx +++ b/pqBasicWidgetEventTranslator.cxx @@ -7,7 +7,7 @@ All rights reserved. ParaView is a free software; you can redistribute it and/or modify it - under the terms of the ParaView license version 1.2. + under the terms of the ParaView license version 1.2. See License_v1.2.txt for the full ParaView license. A copy of this license can be obtained by contacting @@ -50,130 +50,129 @@ pqBasicWidgetEventTranslator::~pqBasicWidgetEventTranslator() { } -bool pqBasicWidgetEventTranslator::translateEvent(QObject* object, - QEvent* event, - int eventType, - bool& error) +bool pqBasicWidgetEventTranslator::translateEvent( + QObject* object, QEvent* event, int eventType, bool& error) { QWidget* widget = qobject_cast<QWidget*>(object); - if(!widget) - return false; + if (!widget) + return false; if (eventType == pqEventTypes::ACTION_EVENT) + { + switch (event->type()) { - switch(event->type()) - { case QEvent::KeyPress: - { + { QKeyEvent* keyEvent = static_cast<QKeyEvent*>(event); - if(qobject_cast<QDialog*>(object)) - { + if (qobject_cast<QDialog*>(object)) + { emit recordEvent(widget, "key", QString::number(keyEvent->key())); - } + } return true; break; - } + } case QEvent::MouseButtonPress: case QEvent::MouseButtonDblClick: case QEvent::MouseButtonRelease: - { + { QMouseEvent* mouseEvent = static_cast<QMouseEvent*>(event); QString info = QString("%1,%2,%3,%4,%5") - .arg(mouseEvent->button()) - .arg(mouseEvent->buttons()) - .arg(mouseEvent->modifiers()) - .arg(mouseEvent->x()) - .arg(mouseEvent->y()); + .arg(mouseEvent->button()) + .arg(mouseEvent->buttons()) + .arg(mouseEvent->modifiers()) + .arg(mouseEvent->x()) + .arg(mouseEvent->y()); - if(event->type() != QEvent::MouseButtonRelease) - { + if (event->type() != QEvent::MouseButtonRelease) + { this->LastPos = mouseEvent->pos(); - } + } - if(event->type() == QEvent::MouseButtonPress) - { + if (event->type() == QEvent::MouseButtonPress) + { emit recordEvent(widget, "mousePress", info); - } - if(event->type() == QEvent::MouseButtonDblClick) - { + } + if (event->type() == QEvent::MouseButtonDblClick) + { emit recordEvent(widget, "mouseDblClick", info); - } - else if(event->type() == QEvent::MouseButtonRelease) + } + else if (event->type() == QEvent::MouseButtonRelease) + { + if (this->LastPos != mouseEvent->pos()) { - if(this->LastPos != mouseEvent->pos()) - { emit recordEvent(widget, "mouseMove", info); - } - emit recordEvent(widget, "mouseRelease", info); } + emit recordEvent(widget, "mouseRelease", info); + } return true; break; - } + } case QEvent::Wheel: + { + if (qobject_cast<QScrollBar*>(object)) { - if(qobject_cast<QScrollBar*>(object)) - { QWheelEvent* wheelEvent = dynamic_cast<QWheelEvent*>(event); - if(wheelEvent) - { + if (wheelEvent) + { int buttons = wheelEvent->buttons(); int modifiers = wheelEvent->modifiers(); int numStep = wheelEvent->delta(); emit recordEvent(object, "mouseWheel", QString("%1,%2,%3,%4,%5") - .arg(numStep) - .arg(buttons) - .arg(modifiers) - .arg(wheelEvent->x()) - .arg(wheelEvent->y())); - } + .arg(numStep) + .arg(buttons) + .arg(modifiers) + .arg(wheelEvent->x()) + .arg(wheelEvent->y())); } + } return true; break; - } - default: - break; } + default: + break; } + } else if (eventType == pqEventTypes::CHECK_EVENT) - { + { if (event->type() == QEvent::MouseMove) - { + { // Check for available meta prop const QMetaProperty metaProp = widget->metaObject()->userProperty(); if (!metaProp.isValid() && qobject_cast<QWidget*>(widget->parent()) != NULL) - { + { // MouseEvent can be received by the viewport const QMetaProperty metaProp = widget->parent()->metaObject()->userProperty(); - } + } if (metaProp.isValid()) - { + { return true; - } } + } // Clicking while checking, actual check event if (event->type() == QEvent::MouseButtonRelease) - { - //Generic Meta prop check + { + // Generic Meta prop check const QMetaProperty metaProp = widget->metaObject()->userProperty(); if (!metaProp.isValid() && widget->parent() != NULL) - { + { // MouseEvent can be received by the viewport, so try the parent widget const QMetaProperty metaProp = widget->parent()->metaObject()->userProperty(); widget = qobject_cast<QWidget*>(widget->parent()); - } + } if (metaProp.isValid() && widget) - { + { // Recover meto prop name QString propName = metaProp.name(); // Record check event - emit recordEvent(widget, propName, widget->property(propName.toUtf8().data()).toString().replace("\t", " "), pqEventTypes::CHECK_EVENT); + emit recordEvent(widget, propName, + widget->property(propName.toUtf8().data()).toString().replace("\t", " "), + pqEventTypes::CHECK_EVENT); return true; - } } } + } return this->Superclass::translateEvent(object, event, eventType, error); } - diff --git a/pqBasicWidgetEventTranslator.h b/pqBasicWidgetEventTranslator.h index 3285a5a..e41419d 100644 --- a/pqBasicWidgetEventTranslator.h +++ b/pqBasicWidgetEventTranslator.h @@ -7,7 +7,7 @@ All rights reserved. ParaView is a free software; you can redistribute it and/or modify it - under the terms of the ParaView license version 1.2. + under the terms of the ParaView license version 1.2. See License_v1.2.txt for the full ParaView license. A copy of this license can be obtained by contacting @@ -43,14 +43,13 @@ Translates low-level Qt events into high-level ParaView events that can be recor \sa pqEventTranslator */ -class QTTESTING_EXPORT pqBasicWidgetEventTranslator : - public pqWidgetEventTranslator +class QTTESTING_EXPORT pqBasicWidgetEventTranslator : public pqWidgetEventTranslator { Q_OBJECT typedef pqWidgetEventTranslator Superclass; - + public: - pqBasicWidgetEventTranslator(QObject* p=0); + pqBasicWidgetEventTranslator(QObject* p = 0); ~pqBasicWidgetEventTranslator() override; using Superclass::translateEvent; @@ -62,8 +61,6 @@ protected: private: pqBasicWidgetEventTranslator(const pqBasicWidgetEventTranslator&); pqBasicWidgetEventTranslator& operator=(const pqBasicWidgetEventTranslator&); - }; #endif // !_pqBasicWidgetEventTranslator_h - diff --git a/pqCheckEventOverlay.cxx b/pqCheckEventOverlay.cxx index 36b2fe7..e46027c 100644 --- a/pqCheckEventOverlay.cxx +++ b/pqCheckEventOverlay.cxx @@ -34,8 +34,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include <QPainter> -pqCheckEventOverlay::pqCheckEventOverlay(QWidget * parent) - : QWidget(parent) +pqCheckEventOverlay::pqCheckEventOverlay(QWidget* parent) + : QWidget(parent) { setAttribute(Qt::WA_NoSystemBackground); setAttribute(Qt::WA_TransparentForMouseEvents); @@ -45,18 +45,19 @@ pqCheckEventOverlay::pqCheckEventOverlay(QWidget * parent) this->setObjectName("Overlay"); } -void pqCheckEventOverlay::paintEvent(QPaintEvent *) +void pqCheckEventOverlay::paintEvent(QPaintEvent*) { QPainter p(this); // Draw red on invalid widget QPen pen(Qt::red, pqCheckEventOverlay::OVERLAY_PEN_WIDTH); if (this->Valid) - { + { // Draw green on valid widget pen.setColor(Qt::green); - } + } p.setPen(pen); // Remove the margins to draw - p.drawRect(0, 0, width()-pqCheckEventOverlay::OVERLAY_MARGIN, height()-pqCheckEventOverlay::OVERLAY_MARGIN); + p.drawRect(0, 0, width() - pqCheckEventOverlay::OVERLAY_MARGIN, + height() - pqCheckEventOverlay::OVERLAY_MARGIN); } diff --git a/pqCheckEventOverlay.h b/pqCheckEventOverlay.h index 3f6ab82..6a8e50c 100644 --- a/pqCheckEventOverlay.h +++ b/pqCheckEventOverlay.h @@ -44,7 +44,7 @@ class pqCheckEventOverlay : public QWidget typedef QWidget Superclass; public: - pqCheckEventOverlay(QWidget * parent = 0); + pqCheckEventOverlay(QWidget* parent = 0); // true if the overlayed widget can be checked, false otherwise bool Valid; @@ -63,7 +63,7 @@ public: static const int OVERLAY_PEN_WIDTH = 5; protected: - void paintEvent(QPaintEvent *) override; + void paintEvent(QPaintEvent*) override; }; #endif diff --git a/pqComboBoxEventPlayer.cxx b/pqComboBoxEventPlayer.cxx index 87ec494..752d1d2 100644 --- a/pqComboBoxEventPlayer.cxx +++ b/pqComboBoxEventPlayer.cxx @@ -30,8 +30,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ========================================================================*/ #include "pqComboBoxEventPlayer.h" -#include "pqObjectNaming.h" #include "pqEventTypes.h" +#include "pqObjectNaming.h" #include <QComboBox> #include <QDebug> @@ -49,25 +49,24 @@ pqComboBoxEventPlayer::~pqComboBoxEventPlayer() //----------------------------------------------------------------------------- bool pqComboBoxEventPlayer::playEvent( - QObject* object, const QString& command, - const QString& arguments, int eventType, bool& error) + QObject* object, const QString& command, const QString& arguments, int eventType, bool& error) { QComboBox* comboBox = qobject_cast<QComboBox*>(object); if (!comboBox) - { + { return false; - } + } if (eventType == pqEventTypes::ACTION_EVENT) - { + { if (command == "activated" || command == "editTextChanged") - { + { int index = comboBox->findText(arguments); if (index != -1) - { + { comboBox->setCurrentIndex(index); if (command == "activated") - { + { #if QT_VERSION >= 0x050000 emit comboBox->activated(index); #else @@ -75,29 +74,30 @@ bool pqComboBoxEventPlayer::playEvent( emit this->activated(index); QObject::disconnect(this, SIGNAL(activated(int)), comboBox, SIGNAL(activated(int))); #endif - } } + } else - { + { QString possibles; - for (int i = 0; i<comboBox->count(); i++) - { + for (int i = 0; i < comboBox->count(); i++) + { possibles += QString("\t") + comboBox->itemText(i) + QString("\n"); - } - qCritical() << "Unable to find " << arguments << " in combo box: " - << pqObjectNaming::GetName(*comboBox) - << "\nPossible values are:\n" << possibles; - error = true; } + qCritical() << "Unable to find " << arguments + << " in combo box: " << pqObjectNaming::GetName(*comboBox) + << "\nPossible values are:\n" + << possibles; + error = true; + } if (command == "set_string") - { + { // Legacy support - qCritical() << "set_string should be handled by pqAbstractStringEventTranslator already, something hase gone wrong"; + qCritical() << "set_string should be handled by pqAbstractStringEventTranslator already, " + "something hase gone wrong"; error = true; - } } - return true; } + return true; + } return this->Superclass::playEvent(object, command, arguments, eventType, error); } - diff --git a/pqComboBoxEventPlayer.h b/pqComboBoxEventPlayer.h index 5ac81de..8e71f18 100644 --- a/pqComboBoxEventPlayer.h +++ b/pqComboBoxEventPlayer.h @@ -40,14 +40,15 @@ class QTTESTING_EXPORT pqComboBoxEventPlayer : public pqWidgetEventPlayer { Q_OBJECT typedef pqWidgetEventPlayer Superclass; + public: - pqComboBoxEventPlayer(QObject* parent=0); + pqComboBoxEventPlayer(QObject* parent = 0); ~pqComboBoxEventPlayer() override; /// Play an event on a QComboBox using Superclass::playEvent; - bool playEvent(QObject* object, const QString& command, - const QString& arguments, int eventType, bool& error) override; + bool playEvent(QObject* object, const QString& command, const QString& arguments, int eventType, + bool& error) override; signals: // Transition signal to call combo box activated signal @@ -55,7 +56,7 @@ signals: private: pqComboBoxEventPlayer(const pqComboBoxEventPlayer&); // Not implemented. - void operator=(const pqComboBoxEventPlayer&); // Not implemented. + void operator=(const pqComboBoxEventPlayer&); // Not implemented. }; #endif diff --git a/pqComboBoxEventTranslator.cxx b/pqComboBoxEventTranslator.cxx index 334e858..4074641 100644 --- a/pqComboBoxEventTranslator.cxx +++ b/pqComboBoxEventTranslator.cxx @@ -7,7 +7,7 @@ All rights reserved. ParaView is a free software; you can redistribute it and/or modify it - under the terms of the ParaView license version 1.2. + under the terms of the ParaView license version 1.2. See License_v1.2.txt for the full ParaView license. A copy of this license can be obtained by contacting @@ -35,42 +35,43 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include <QComboBox> #include <QEvent> -pqComboBoxEventTranslator::pqComboBoxEventTranslator(QObject* p) - : pqWidgetEventTranslator(p), - CurrentObject(0) +pqComboBoxEventTranslator::pqComboBoxEventTranslator(QObject* p) + : pqWidgetEventTranslator(p) + , CurrentObject(0) { } bool pqComboBoxEventTranslator::translateEvent(QObject* Object, QEvent* Event, bool& Error) { QComboBox* combo = NULL; - for(QObject* test = Object; combo == NULL && test != NULL; test = test->parent()) - { + for (QObject* test = Object; combo == NULL && test != NULL; test = test->parent()) + { combo = qobject_cast<QComboBox*>(test); - } + } - if(!combo) - { + if (!combo) + { // not for me return false; - } + } - if(Event->type() == QEvent::Enter && Object == combo) + if (Event->type() == QEvent::Enter && Object == combo) + { + if (this->CurrentObject != Object) { - if(this->CurrentObject != Object) + if (this->CurrentObject) { - if(this->CurrentObject) - { disconnect(this->CurrentObject, 0, this, 0); - } - + } + this->CurrentObject = Object; connect(combo, SIGNAL(destroyed(QObject*)), this, SLOT(onDestroyed(QObject*))); connect(combo, SIGNAL(activated(const QString&)), this, SLOT(onActivated(const QString&))); - connect(combo, SIGNAL(editTextChanged(const QString&)), this, SLOT(onEditTextChanged(const QString&))); - } - return true; + connect(combo, SIGNAL(editTextChanged(const QString&)), this, + SLOT(onEditTextChanged(const QString&))); } + return true; + } return this->Superclass::translateEvent(Object, Event, Error); } diff --git a/pqComboBoxEventTranslator.h b/pqComboBoxEventTranslator.h index 408369f..21e9a2c 100644 --- a/pqComboBoxEventTranslator.h +++ b/pqComboBoxEventTranslator.h @@ -41,14 +41,13 @@ Translates low-level Qt events into high-level ParaView events that can be recor \sa pqEventTranslator */ -class QTTESTING_EXPORT pqComboBoxEventTranslator : - public pqWidgetEventTranslator +class QTTESTING_EXPORT pqComboBoxEventTranslator : public pqWidgetEventTranslator { Q_OBJECT typedef pqWidgetEventTranslator Superclass; public: - pqComboBoxEventTranslator(QObject* p=0); + pqComboBoxEventTranslator(QObject* p = 0); using Superclass::translateEvent; bool translateEvent(QObject* Object, QEvent* Event, bool& Error) override; @@ -66,4 +65,3 @@ private slots: }; #endif // !_pqComboBoxEventTranslator_h - diff --git a/pqCommentEventPlayer.cxx b/pqCommentEventPlayer.cxx index 0312eb0..fd94a30 100644 --- a/pqCommentEventPlayer.cxx +++ b/pqCommentEventPlayer.cxx @@ -33,8 +33,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "pqCommentEventPlayer.h" // ---------------------------------------------------------------------------- -pqCommentEventPlayer::pqCommentEventPlayer(pqTestUtility* testUtility, - QObject* parent) +pqCommentEventPlayer::pqCommentEventPlayer(pqTestUtility* testUtility, QObject* parent) : pqWidgetEventPlayer(parent) { this->TestUtility = testUtility; @@ -47,25 +46,23 @@ pqCommentEventPlayer::~pqCommentEventPlayer() } // ---------------------------------------------------------------------------- -bool pqCommentEventPlayer::playEvent(QObject* Object, - const QString &Command, - const QString &Arguments, - bool &Error) +bool pqCommentEventPlayer::playEvent( + QObject* Object, const QString& Command, const QString& Arguments, bool& Error) { if (!Command.startsWith("comment")) - { + { return false; - } + } if (!Arguments.isEmpty()) - { + { emit this->comment(Arguments); - } + } if (Command.split("-").contains("block")) - { + { this->TestUtility->dispatcher()->run(false); - } + } return true; } diff --git a/pqCommentEventPlayer.h b/pqCommentEventPlayer.h index 3242c38..f4f2556 100644 --- a/pqCommentEventPlayer.h +++ b/pqCommentEventPlayer.h @@ -47,17 +47,18 @@ class QTTESTING_EXPORT pqCommentEventPlayer : public pqWidgetEventPlayer typedef pqWidgetEventPlayer Superclass; public: - pqCommentEventPlayer(pqTestUtility* testUtility, QObject* p =0); + pqCommentEventPlayer(pqTestUtility* testUtility, QObject* p = 0); ~pqCommentEventPlayer() override; using Superclass::playEvent; - bool playEvent(QObject* Object, const QString &Command, const QString &Arguments, bool &Error) override; + bool playEvent( + QObject* Object, const QString& Command, const QString& Arguments, bool& Error) override; signals: void comment(const QString&); private: - pqCommentEventPlayer(const pqCommentEventPlayer&); // Not implemented + pqCommentEventPlayer(const pqCommentEventPlayer&); // Not implemented pqCommentEventPlayer& operator=(const pqCommentEventPlayer&); // Not implemented pqTestUtility* TestUtility; diff --git a/pqDoubleSpinBoxEventTranslator.cxx b/pqDoubleSpinBoxEventTranslator.cxx index c299a1f..ae60baa 100644 --- a/pqDoubleSpinBoxEventTranslator.cxx +++ b/pqDoubleSpinBoxEventTranslator.cxx @@ -7,7 +7,7 @@ All rights reserved. ParaView is a free software; you can redistribute it and/or modify it - under the terms of the ParaView license version 1.2. + under the terms of the ParaView license version 1.2. See License_v1.2.txt for the full ParaView license. A copy of this license can be obtained by contacting @@ -33,15 +33,15 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "pqDoubleSpinBoxEventTranslator.h" #include <QDoubleSpinBox> -#include <QMouseEvent> #include <QKeyEvent> +#include <QMouseEvent> #include <QStyle> #include <QStyleOptionSpinBox> // ---------------------------------------------------------------------------- pqDoubleSpinBoxEventTranslator::pqDoubleSpinBoxEventTranslator(QObject* p) - : pqWidgetEventTranslator(p), - CurrentObject(0) + : pqWidgetEventTranslator(p) + , CurrentObject(0) { } @@ -51,45 +51,45 @@ bool pqDoubleSpinBoxEventTranslator::translateEvent(QObject* Object, QEvent* Eve QDoubleSpinBox* const object = qobject_cast<QDoubleSpinBox*>(Object); // consume line edit events if part of spin box - if(!object && qobject_cast<QDoubleSpinBox*>(Object->parent())) - { + if (!object && qobject_cast<QDoubleSpinBox*>(Object->parent())) + { return true; - } + } - if(!object) - return false; + if (!object) + return false; - if(Event->type() == QEvent::Enter && Object==object) + if (Event->type() == QEvent::Enter && Object == object) + { + if (this->CurrentObject != Object) { - if(this->CurrentObject != Object) + if (this->CurrentObject) { - if(this->CurrentObject) - { disconnect(this->CurrentObject, 0, this, 0); - } + } this->CurrentObject = Object; this->Value = object->value(); - connect(object, SIGNAL(valueChanged(double)),this, SLOT(onValueChanged(double))); + connect(object, SIGNAL(valueChanged(double)), this, SLOT(onValueChanged(double))); connect(object, SIGNAL(destroyed(QObject*)), this, SLOT(onDestroyed(QObject*))); - } - return true; } + return true; + } - if(Event->type() == QEvent::KeyRelease && Object==object) - { + if (Event->type() == QEvent::KeyRelease && Object == object) + { QKeyEvent* ke = static_cast<QKeyEvent*>(Event); QString keyText = ke->text(); - if(keyText.length() && keyText.at(0).isPrint()) - { + if (keyText.length() && keyText.at(0).isPrint()) + { emit recordEvent(object, "set_double", QString("%1").arg(object->value())); - } + } else - { + { emit recordEvent(object, "key", QString("%1").arg(ke->key())); - } - return true; } + return true; + } return this->Superclass::translateEvent(Object, Event, Error); } @@ -102,6 +102,5 @@ void pqDoubleSpinBoxEventTranslator::onDestroyed(QObject* /*Object*/) // ---------------------------------------------------------------------------- void pqDoubleSpinBoxEventTranslator::onValueChanged(double number) { - emit recordEvent(this->CurrentObject, "set_double", QString("%1") - .arg(number)); + emit recordEvent(this->CurrentObject, "set_double", QString("%1").arg(number)); } diff --git a/pqDoubleSpinBoxEventTranslator.h b/pqDoubleSpinBoxEventTranslator.h index 95e5380..baa9239 100644 --- a/pqDoubleSpinBoxEventTranslator.h +++ b/pqDoubleSpinBoxEventTranslator.h @@ -7,7 +7,7 @@ All rights reserved. ParaView is a free software; you can redistribute it and/or modify it - under the terms of the ParaView license version 1.2. + under the terms of the ParaView license version 1.2. See License_v1.2.txt for the full ParaView license. A copy of this license can be obtained by contacting @@ -41,14 +41,13 @@ Translates low-level Qt events into high-level ParaView events that can be recor \sa pqEventTranslator */ -class QTTESTING_EXPORT pqDoubleSpinBoxEventTranslator : - public pqWidgetEventTranslator +class QTTESTING_EXPORT pqDoubleSpinBoxEventTranslator : public pqWidgetEventTranslator { Q_OBJECT typedef pqWidgetEventTranslator Superclass; - + public: - pqDoubleSpinBoxEventTranslator(QObject* p=0); + pqDoubleSpinBoxEventTranslator(QObject* p = 0); using Superclass::translateEvent; bool translateEvent(QObject* Object, QEvent* Event, bool& Error) override; @@ -57,14 +56,12 @@ private: pqDoubleSpinBoxEventTranslator(const pqDoubleSpinBoxEventTranslator&); pqDoubleSpinBoxEventTranslator& operator=(const pqDoubleSpinBoxEventTranslator&); - int Value; + int Value; QObject* CurrentObject; private slots: void onDestroyed(QObject*); void onValueChanged(double number); - }; #endif // !_pqDoubleSpinBoxEventTranslator_h - diff --git a/pqEventComment.cxx b/pqEventComment.cxx index b0124dd..a507583 100644 --- a/pqEventComment.cxx +++ b/pqEventComment.cxx @@ -37,8 +37,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "pqEventComment.h" // ---------------------------------------------------------------------------- -pqEventComment::pqEventComment(pqTestUtility* util, - QObject* parent) +pqEventComment::pqEventComment(pqTestUtility* util, QObject* parent) : Superclass(parent) { this->TestUtility = util; @@ -63,15 +62,14 @@ void pqEventComment::recordCommentBlock(const QString& arguments) } // ---------------------------------------------------------------------------- -void pqEventComment::recordComment(const QString& command, - const QString& arguments, - QObject* object) +void pqEventComment::recordComment( + const QString& command, const QString& arguments, QObject* object) { if (arguments.isEmpty()) - { + { qCritical() << "The comment is empty ! No comment has been added !"; return; - } + } emit this->recordComment(object, command, arguments); } diff --git a/pqEventComment.h b/pqEventComment.h index a0e9bb8..02b21b5 100644 --- a/pqEventComment.h +++ b/pqEventComment.h @@ -37,16 +37,15 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include <QObject> // QtTesting inlcudes -#include "pqTestUtility.h" #include "QtTestingExport.h" +#include "pqTestUtility.h" /// pqEventComment is responsible for adding any kind of events that are not added /// by widgets. /// For exemple, you can add an event to block the playback, to show a custom /// comment etc ... -class QTTESTING_EXPORT pqEventComment : - public QObject +class QTTESTING_EXPORT pqEventComment : public QObject { Q_OBJECT typedef QObject Superclass; @@ -68,9 +67,7 @@ signals: void recordComment(QObject* widget, const QString& type, const QString& argument); protected: - void recordComment(const QString& command, - const QString& arguments, - QObject* = 0); + void recordComment(const QString& command, const QString& arguments, QObject* = 0); pqTestUtility* TestUtility; }; diff --git a/pqEventDispatcher.cxx b/pqEventDispatcher.cxx index d32d975..4b3e6be 100644 --- a/pqEventDispatcher.cxx +++ b/pqEventDispatcher.cxx @@ -7,7 +7,7 @@ All rights reserved. ParaView is a free software; you can redistribute it and/or modify it - under the terms of the ParaView license version 1.2. + under the terms of the ParaView license version 1.2. See License_v1.2.txt for the full ParaView license. A copy of this license can be obtained by contacting @@ -36,15 +36,15 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "pqEventSource.h" #include <QAbstractEventDispatcher> -#include <QtDebug> #include <QApplication> -#include <QEventLoop> -#include <QThread> #include <QDialog> -#include <QMainWindow> +#include <QEventLoop> #include <QList> +#include <QMainWindow> #include <QPointer> +#include <QThread> #include <QTimer> +#include <QtDebug> #include <iostream> using namespace std; @@ -52,21 +52,21 @@ using namespace std; //----------------------------------------------------------------------------- namespace { - static QList<QPointer<QTimer> > RegisteredTimers; - - void processTimers() +static QList<QPointer<QTimer> > RegisteredTimers; + +void processTimers() +{ + foreach (QTimer* timer, RegisteredTimers) + { + if (timer && timer->isActive()) { - foreach (QTimer* timer, RegisteredTimers) - { - if (timer && timer->isActive()) - { - QTimerEvent event(timer->timerId()); - qApp->notify(timer, &event); - } - } + QTimerEvent event(timer->timerId()); + qApp->notify(timer, &event); } + } +} - static int EventPlaybackDelay = QT_TESTING_EVENT_PLAYBACK_DELAY; +static int EventPlaybackDelay = QT_TESTING_EVENT_PLAYBACK_DELAY; }; bool pqEventDispatcher::DeferMenuTimeouts = false; @@ -74,8 +74,8 @@ bool pqEventDispatcher::DeferEventsIfBlocked = false; bool pqEventDispatcher::PlayingBlockingEvent = false; //----------------------------------------------------------------------------- -pqEventDispatcher::pqEventDispatcher(QObject* parentObject) : - Superclass(parentObject) +pqEventDispatcher::pqEventDispatcher(QObject* parentObject) + : Superclass(parentObject) { this->ActiveSource = NULL; this->ActivePlayer = NULL; @@ -92,8 +92,7 @@ pqEventDispatcher::pqEventDispatcher(QObject* parentObject) : this->BlockTimer.setInterval(100); #endif this->BlockTimer.setSingleShot(true); - QObject::connect(&this->BlockTimer, SIGNAL(timeout()), - this, SLOT(playEventOnBlocking())); + QObject::connect(&this->BlockTimer, SIGNAL(timeout()), this, SLOT(playEventOnBlocking())); } //----------------------------------------------------------------------------- @@ -101,11 +100,10 @@ pqEventDispatcher::~pqEventDispatcher() { } - //----------------------------------------------------------------------------- void pqEventDispatcher::setEventPlaybackDelay(int milliseconds) { - EventPlaybackDelay = (milliseconds <= 0)? 0 : milliseconds; + EventPlaybackDelay = (milliseconds <= 0) ? 0 : milliseconds; } //----------------------------------------------------------------------------- @@ -118,9 +116,9 @@ int pqEventDispatcher::eventPlaybackDelay() void pqEventDispatcher::registerTimer(QTimer* timer) { if (timer) - { + { RegisteredTimers.push_back(timer); - } + } } //----------------------------------------------------------------------------- @@ -129,25 +127,24 @@ void pqEventDispatcher::deferEventsIfBlocked(bool enable) pqEventDispatcher::DeferEventsIfBlocked = enable; } - //----------------------------------------------------------------------------- void pqEventDispatcher::aboutToBlock() { // if (!pqEventDispatcher::DeferMenuTimeouts) - { + { if (!this->BlockTimer.isActive()) - { + { // cout << "aboutToBlock" << endl; // Request a delayed playback for an event. this->BlockTimer.start(); - } } + } } //----------------------------------------------------------------------------- void pqEventDispatcher::awake() { - //if (!pqEventDispatcher::DeferMenuTimeouts) + // if (!pqEventDispatcher::DeferMenuTimeouts) // { // // cout << "awake" << endl; // // this->BlockTimer.stop(); @@ -165,13 +162,13 @@ void pqEventDispatcher::run(bool value) { this->PlayBackPaused = !value; if (value) - { + { emit this->restarted(); - } + } else - { + { emit this->paused(); - } + } } //----------------------------------------------------------------------------- @@ -203,25 +200,24 @@ void pqEventDispatcher::oneStep() bool pqEventDispatcher::playEvents(pqEventSource& source, pqEventPlayer& player) { if (this->ActiveSource || this->ActivePlayer) - { + { qCritical() << "Event dispatcher is already playing"; return false; - } + } this->ActiveSource = &source; this->ActivePlayer = &player; QApplication::setEffectEnabled(Qt::UI_General, false); - QApplication::setEffectEnabled(Qt::UI_AnimateMenu, false); // Show animated menus. - QApplication::setEffectEnabled(Qt::UI_FadeMenu, false); // Show faded menus. - QApplication::setEffectEnabled(Qt::UI_AnimateCombo, false); // Show animated comboboxes. + QApplication::setEffectEnabled(Qt::UI_AnimateMenu, false); // Show animated menus. + QApplication::setEffectEnabled(Qt::UI_FadeMenu, false); // Show faded menus. + QApplication::setEffectEnabled(Qt::UI_AnimateCombo, false); // Show animated comboboxes. QApplication::setEffectEnabled(Qt::UI_AnimateTooltip, false); // Show tooltip animations. - QApplication::setEffectEnabled(Qt::UI_FadeTooltip, false); // Show tooltip fading effects. + QApplication::setEffectEnabled(Qt::UI_FadeTooltip, false); // Show tooltip fading effects. - QObject::connect(QAbstractEventDispatcher::instance(), SIGNAL(aboutToBlock()), - this, SLOT(aboutToBlock())); - QObject::connect(QAbstractEventDispatcher::instance(), SIGNAL(awake()), - this, SLOT(awake())); + QObject::connect( + QAbstractEventDispatcher::instance(), SIGNAL(aboutToBlock()), this, SLOT(aboutToBlock())); + QObject::connect(QAbstractEventDispatcher::instance(), SIGNAL(awake()), this, SLOT(awake())); // This is how the playback logic works: // * In here, we continuously keep on playing one event after another until @@ -237,32 +233,31 @@ bool pqEventDispatcher::playEvents(pqEventSource& source, pqEventPlayer& player) this->PlayBackStatus = true; // success. this->PlayBackFinished = false; while (!this->PlayBackFinished) + { + if (!this->PlayBackPaused) { - if(!this->PlayBackPaused) - { - //cerr << "=== playEvent(1) ===" << endl; - this->playEvent(); + // cerr << "=== playEvent(1) ===" << endl; + this->playEvent(); } else - { + { if (this->PlayBackOneStep) - { + { this->PlayBackOneStep = false; this->playEvent(); - } + } else - { + { this->processEventsAndWait(100); - } } } + } this->ActiveSource = NULL; this->ActivePlayer = NULL; - QObject::disconnect(QAbstractEventDispatcher::instance(), SIGNAL(aboutToBlock()), - this, SLOT(aboutToBlock())); - QObject::disconnect(QAbstractEventDispatcher::instance(), SIGNAL(awake()), - this, SLOT(awake())); + QObject::disconnect( + QAbstractEventDispatcher::instance(), SIGNAL(aboutToBlock()), this, SLOT(aboutToBlock())); + QObject::disconnect(QAbstractEventDispatcher::instance(), SIGNAL(awake()), this, SLOT(awake())); return this->PlayBackStatus; } @@ -270,26 +265,26 @@ bool pqEventDispatcher::playEvents(pqEventSource& source, pqEventPlayer& player) //----------------------------------------------------------------------------- void pqEventDispatcher::playEventOnBlocking() { -// if(this->PlayingBlockingEvent) -// { -// qDebug() << "Event blocking already playing ...."; -// return; -// } + // if(this->PlayingBlockingEvent) + // { + // qDebug() << "Event blocking already playing ...."; + // return; + // } if (pqEventDispatcher::DeferMenuTimeouts || pqEventDispatcher::DeferEventsIfBlocked) - { - //cerr << "=== playEventOnBlocking ===" << endl; + { + // cerr << "=== playEventOnBlocking ===" << endl; this->BlockTimer.start(); return; - } + } pqEventDispatcher::PlayingBlockingEvent = true; - //cout << "---blocked event: " << endl; + // cout << "---blocked event: " << endl; // if needed for debugging, I can print blocking annotation here. - //cerr << "=== playEvent(2) ===" << endl; + // cerr << "=== playEvent(2) ===" << endl; this->playEvent(1); - //if (!this->BlockTimer.isActive()) + // if (!this->BlockTimer.isActive()) // { // this->BlockTimer.start(); // } @@ -301,37 +296,37 @@ void pqEventDispatcher::playEvent(int indent) { this->BlockTimer.stop(); if (this->PlayBackFinished) - { + { return; - } + } if (!this->ActiveSource) - { + { this->PlayBackFinished = true; this->PlayBackStatus = false; // failure. qCritical("Internal error: playEvent called without a valid event source."); return; - } + } QString object; QString command; QString arguments; int eventType; - + int result = this->ActiveSource->getNextEvent(object, command, arguments, eventType); if (result == pqEventSource::DONE) - { + { this->PlayBackFinished = true; return; - } - else if(result == pqEventSource::FAILURE) - { + } + else if (result == pqEventSource::FAILURE) + { this->PlayBackFinished = true; this->PlayBackStatus = false; // failure. return; - } - - static unsigned long counter=0; + } + + static unsigned long counter = 0; unsigned long local_counter = counter++; QString pretty_name = object.mid(object.lastIndexOf('/')); bool print_debug = getenv("PV_DEBUG_TEST") != NULL; @@ -339,22 +334,19 @@ void pqEventDispatcher::playEvent(int indent) print_debug = true; #endif if (print_debug) - { + { QString eventString = "Event"; if (eventType == pqEventTypes::CHECK_EVENT) - { + { eventString = "Check Event"; - } + } - cout << QTime::currentTime().toString("hh:mm:ss").toStdString().c_str() - << " : " - << QString().fill(' ', 4*indent).toStdString().c_str() - << local_counter << ": Test (" << indent << "): " - << eventString.toUtf8().data() << ": " - << pretty_name.toStdString().c_str() << ": " - << command.toStdString().c_str() << " : " + cout << QTime::currentTime().toString("hh:mm:ss").toStdString().c_str() << " : " + << QString().fill(' ', 4 * indent).toStdString().c_str() << local_counter << ": Test (" + << indent << "): " << eventString.toUtf8().data() << ": " + << pretty_name.toStdString().c_str() << ": " << command.toStdString().c_str() << " : " << arguments.toStdString().c_str() << endl; - } + } bool error = false; this->ActivePlayer->playEvent(object, command, arguments, eventType, error); @@ -370,20 +362,18 @@ void pqEventDispatcher::playEvent(int indent) this->BlockTimer.stop(); if (print_debug) - { - cout << QTime::currentTime().toString("hh:mm:ss").toStdString().c_str() - << " : " - << QString().fill(' ', 4*indent).toStdString().c_str() - << local_counter << ": Done" << endl; - } + { + cout << QTime::currentTime().toString("hh:mm:ss").toStdString().c_str() << " : " + << QString().fill(' ', 4 * indent).toStdString().c_str() << local_counter << ": Done" + << endl; + } if (error) - { - this->PlayBackStatus = false; + { + this->PlayBackStatus = false; this->PlayBackFinished = true; return; - } - + } } //----------------------------------------------------------------------------- @@ -392,26 +382,26 @@ void pqEventDispatcher::processEventsAndWait(int ms) bool prev = pqEventDispatcher::DeferMenuTimeouts; pqEventDispatcher::DeferMenuTimeouts = true; if (ms > 0) - { + { QApplication::sendPostedEvents(); QEventLoop loop; QTimer::singleShot(ms, &loop, SLOT(quit())); loop.exec(); - } + } // When this gets called during playback from a blocking event loop (e.g. a modal dialog) // calling `QApplication::processEvents()` has a sideeffect on Qt 5 + OsX where it does // not quit the eventloop for the modal dialog until a mouse event (for example) is // received by the application. Avoiding calling QApplication::processEvents when already // processing a event loop other the apps main event loop avoids that problem. if (!pqEventDispatcher::PlayingBlockingEvent) - { + { QApplication::processEvents(); - } + } QApplication::sendPostedEvents(); if (!pqEventDispatcher::PlayingBlockingEvent) - { + { QApplication::processEvents(); - } + } pqEventDispatcher::DeferMenuTimeouts = prev; } diff --git a/pqEventDispatcher.h b/pqEventDispatcher.h index 7acab7e..2e476bd 100644 --- a/pqEventDispatcher.h +++ b/pqEventDispatcher.h @@ -7,7 +7,7 @@ All rights reserved. ParaView is a free software; you can redistribute it and/or modify it - under the terms of the ParaView license version 1.2. + under the terms of the ParaView license version 1.2. See License_v1.2.txt for the full ParaView license. A copy of this license can be obtained by contacting @@ -35,10 +35,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "QtTestingExport.h" +#include <QEventLoop> #include <QObject> -#include <QTimer> #include <QTime> -#include <QEventLoop> +#include <QTimer> class pqEventPlayer; class pqEventSource; @@ -69,9 +69,10 @@ class pqEventSource; class QTTESTING_EXPORT pqEventDispatcher : public QObject { Q_OBJECT - typedef QObject Superclass; + typedef QObject Superclass; + public: - pqEventDispatcher(QObject* parent=0); + pqEventDispatcher(QObject* parent = 0); ~pqEventDispatcher() override; /// Retrieves events from the given event source, dispatching them to @@ -91,8 +92,8 @@ public: on slow processors that hang tests.*/ static void processEventsAndWait(int ms); - /** proccessEvents method for widgets and paraview to use instead of - calling Qt version, since that will break test playback*/ + /** proccessEvents method for widgets and paraview to use instead of + calling Qt version, since that will break test playback*/ static void processEvents(QEventLoop::ProcessEventsFlags flags = QEventLoop::AllEvents); /// register a timer that needs to be ensured to have timed-out after every @@ -120,7 +121,7 @@ signals: protected slots: /// Plays a single event. this->PlayBackFinished and this->PlayBackStatus are /// updated by this method. - void playEvent(int indent=0); + void playEvent(int indent = 0); void playEventOnBlocking(); /// Called when the mainThread is about to block. diff --git a/pqEventObserver.cxx b/pqEventObserver.cxx index ec8f4a4..288c324 100644 --- a/pqEventObserver.cxx +++ b/pqEventObserver.cxx @@ -7,7 +7,7 @@ All rights reserved. ParaView is a free software; you can redistribute it and/or modify it - under the terms of the ParaView license version 1.2. + under the terms of the ParaView license version 1.2. See License_v1.2.txt for the full ParaView license. A copy of this license can be obtained by contacting @@ -38,7 +38,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // pqEventObserver pqEventObserver::pqEventObserver(QObject* p) - : QObject(p), Stream(NULL) + : QObject(p) + , Stream(NULL) { } @@ -50,4 +51,3 @@ void pqEventObserver::setStream(QTextStream* stream) { this->Stream = stream; } - diff --git a/pqEventObserver.h b/pqEventObserver.h index 65910b6..d656e14 100644 --- a/pqEventObserver.h +++ b/pqEventObserver.h @@ -7,7 +7,7 @@ All rights reserved. ParaView is a free software; you can redistribute it and/or modify it - under the terms of the ParaView license version 1.2. + under the terms of the ParaView license version 1.2. See License_v1.2.txt for the full ParaView license. A copy of this license can be obtained by contacting @@ -33,13 +33,13 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef _pqEventObserver_h #define _pqEventObserver_h +#include "QtTestingExport.h" #include <QObject> #include <QString> -#include "QtTestingExport.h" class QTextStream; /** -Observes high-level ParaView events, and serializes them to a stream +Observes high-level ParaView events, and serializes them to a stream for possible playback (as a test-case, demo, tutorial, etc). To use, connect the onRecordEvent() slot to the pqEventTranslator::recordEvent() signal. @@ -47,11 +47,10 @@ signal. \sa pqEventTranslator, pqStdoutEventObserver */ -class QTTESTING_EXPORT pqEventObserver : - public QObject +class QTTESTING_EXPORT pqEventObserver : public QObject { Q_OBJECT - + public: pqEventObserver(QObject* p); ~pqEventObserver() override; @@ -64,22 +63,15 @@ public slots: // Event Type can be pqEventTypes::ACTION_EVENT or pqEventType::CHECK_EVENT // Widget, Command/Property and Arguments are QString // THis method has to be redefined by subclasses - virtual void onRecordEvent( - const QString& Widget, - const QString& Command, - const QString& Arguments, - const int& eventType)=0; - + virtual void onRecordEvent(const QString& Widget, const QString& Command, + const QString& Arguments, const int& eventType) = 0; signals: - void eventRecorded(const QString& Widget, - const QString& Command, - const QString& Arguments, - const int& eventType); + void eventRecorded( + const QString& Widget, const QString& Command, const QString& Arguments, const int& eventType); protected: QTextStream* Stream; }; #endif // !_pqEventObserver_h - diff --git a/pqEventPlayer.cxx b/pqEventPlayer.cxx index 2231d62..07688c6 100644 --- a/pqEventPlayer.cxx +++ b/pqEventPlayer.cxx @@ -32,10 +32,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "pqEventPlayer.h" +#include "pq3DViewEventPlayer.h" #include "pqAbstractActivateEventPlayer.h" #include "pqAbstractBooleanEventPlayer.h" #include "pqAbstractDoubleEventPlayer.h" -#include "pq3DViewEventPlayer.h" #include "pqAbstractIntEventPlayer.h" #include "pqAbstractItemViewEventPlayer.h" #include "pqAbstractMiscellaneousEventPlayer.h" @@ -43,17 +43,17 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "pqBasicWidgetEventPlayer.h" #include "pqComboBoxEventPlayer.h" #include "pqCommentEventPlayer.h" +#include "pqEventTypes.h" #include "pqListViewEventPlayer.h" #include "pqNativeFileDialogEventPlayer.h" #include "pqObjectNaming.h" #include "pqTabBarEventPlayer.h" #include "pqTableViewEventPlayer.h" #include "pqTreeViewEventPlayer.h" -#include "pqEventTypes.h" #include <QApplication> -#include <QWidget> #include <QDebug> +#include <QWidget> // ---------------------------------------------------------------------------- pqEventPlayer::pqEventPlayer() @@ -95,19 +95,18 @@ QList<pqWidgetEventPlayer*> pqEventPlayer::players() const // ---------------------------------------------------------------------------- void pqEventPlayer::addWidgetEventPlayer(pqWidgetEventPlayer* Player) { - if(Player) - { + if (Player) + { // We Check if the Player has already been added previously - int index = - this->getWidgetEventPlayerIndex(QString(Player->metaObject()->className())); + int index = this->getWidgetEventPlayerIndex(QString(Player->metaObject()->className())); if (index != -1) - { + { return; - } + } this->Players.push_front(Player); Player->setParent(this); - } + } } // ---------------------------------------------------------------------------- @@ -115,9 +114,9 @@ bool pqEventPlayer::removeWidgetEventPlayer(const QString& className) { int index = this->getWidgetEventPlayerIndex(className); if (index == -1) - { + { return false; - } + } this->Players.removeAt(index); return true; @@ -128,9 +127,9 @@ pqWidgetEventPlayer* pqEventPlayer::getWidgetEventPlayer(const QString& classNam { int index = this->getWidgetEventPlayerIndex(className); if (index == -1) - { + { return 0; - } + } return this->Players.at(index); } @@ -138,106 +137,95 @@ pqWidgetEventPlayer* pqEventPlayer::getWidgetEventPlayer(const QString& classNam // ---------------------------------------------------------------------------- int pqEventPlayer::getWidgetEventPlayerIndex(const QString& className) { - for(int i = 0 ; i < this->Players.count() ; ++i) - { + for (int i = 0; i < this->Players.count(); ++i) + { if (this->Players.at(i)->metaObject()->className() == className) - { + { return i; - } } + } return -1; } // ---------------------------------------------------------------------------- -void pqEventPlayer::playEvent(const QString& objectString, - const QString& command, - const QString& arguments, - bool& error) +void pqEventPlayer::playEvent( + const QString& objectString, const QString& command, const QString& arguments, bool& error) { this->playEvent(objectString, command, arguments, pqEventTypes::ACTION_EVENT, error); } // ---------------------------------------------------------------------------- -void pqEventPlayer::playEvent(const QString& objectString, - const QString& command, - const QString& arguments, - int eventType, - bool& error) +void pqEventPlayer::playEvent(const QString& objectString, const QString& command, + const QString& arguments, int eventType, bool& error) { emit this->eventAboutToBePlayed(objectString, command, arguments); // If we can't find an object with the right name, we're done ... QObject* const object = pqObjectNaming::GetObject(objectString); // Scroll bar depends on monitor's resolution - if(!object && objectString.contains(QString("QScrollBar"))) - { + if (!object && objectString.contains(QString("QScrollBar"))) + { emit this->eventPlayed(objectString, command, arguments); error = false; return; - } + } - if(!object && !command.startsWith("comment")) - { + if (!object && !command.startsWith("comment")) + { QString errorMsg = pqObjectNaming::lastErrorMessage(); qCritical() << (errorMsg.toLocal8Bit().data()); emit this->errorMessage(errorMsg); error = true; return; - } + } // Loop through players until the event gets handled ... bool accepted = false; bool tmpError = false; if (command.startsWith("comment")) - { - pqWidgetEventPlayer* widgetPlayer = - this->getWidgetEventPlayer(QString("pqCommentEventPlayer")); - pqCommentEventPlayer* commentPlayer = - qobject_cast<pqCommentEventPlayer*>(widgetPlayer); + { + pqWidgetEventPlayer* widgetPlayer = this->getWidgetEventPlayer(QString("pqCommentEventPlayer")); + pqCommentEventPlayer* commentPlayer = qobject_cast<pqCommentEventPlayer*>(widgetPlayer); if (commentPlayer) - { + { accepted = commentPlayer->playEvent(object, command, arguments, tmpError); - } } + } else + { + for (int i = 0; i != this->Players.size(); ++i) { - for(int i = 0; i != this->Players.size(); ++i) - { accepted = this->Players[i]->playEvent(object, command, arguments, eventType, tmpError); - if(accepted) - { + if (accepted) + { break; - } } } + } // The event wasn't handled at all ... - if(!accepted) - { - QString errorMessage = - QString("Unhandled event %1 object %2\n") - .arg(command, object ? object->objectName() : objectString); + if (!accepted) + { + QString errorMessage = QString("Unhandled event %1 object %2\n") + .arg(command, object ? object->objectName() : objectString); qCritical() << errorMessage; emit this->errorMessage(errorMessage); error = true; return; - } + } // The event was handled, but there was a problem ... - if(accepted && tmpError) - { - QString errorMessage = - QString("Event error %1 object %2 with args:%3\n") - .arg(command, object ? object->objectName() : objectString, - arguments); + if (accepted && tmpError) + { + QString errorMessage = QString("Event error %1 object %2 with args:%3\n") + .arg(command, object ? object->objectName() : objectString, arguments); qCritical() << errorMessage; emit this->errorMessage(errorMessage); error = true; return; - } + } // The event was handled successfully ... emit this->eventPlayed(objectString, command, arguments); error = false; } - diff --git a/pqEventPlayer.h b/pqEventPlayer.h index 7f51409..246adb9 100644 --- a/pqEventPlayer.h +++ b/pqEventPlayer.h @@ -35,9 +35,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "QtTestingExport.h" +#include <QList> #include <QObject> #include <QString> -#include <QList> class pqWidgetEventPlayer; class pqTestUtility; @@ -69,8 +69,7 @@ event playback, so you can also use this mechanism to pqEventSource, pqXMLEventSource */ -class QTTESTING_EXPORT pqEventPlayer : - public QObject +class QTTESTING_EXPORT pqEventPlayer : public QObject { Q_OBJECT @@ -98,25 +97,17 @@ public: If there was an error playing the event, Error argument will be set to "true". Note: Currently there is no guarantee that playEvent() will return immediately, since the functionality it invokes may enter - a separate event loop (a modal dialog or context menu, for example). + a separate event loop (a modal dialog or context menu, for example). Check event will not modify ui but check a widget value*/ - void playEvent(const QString& object, - const QString& command, - const QString& arguments, - int eventType, - bool& Error); - void playEvent(const QString& object, - const QString& command, - const QString& arguments, - bool& Error); + void playEvent(const QString& object, const QString& command, const QString& arguments, + int eventType, bool& Error); + void playEvent( + const QString& object, const QString& command, const QString& arguments, bool& Error); signals: - void eventAboutToBePlayed(const QString& Object, - const QString& Command, - const QString& Arguments); - void eventPlayed(const QString& Object, - const QString& Command, - const QString& Arguments); + void eventAboutToBePlayed( + const QString& Object, const QString& Command, const QString& Arguments); + void eventPlayed(const QString& Object, const QString& Command, const QString& Arguments); void errorMessage(const QString&); private: diff --git a/pqEventRecorder.cxx b/pqEventRecorder.cxx index 9455dea..a903d81 100644 --- a/pqEventRecorder.cxx +++ b/pqEventRecorder.cxx @@ -41,7 +41,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "pqEventTypes.h" // ---------------------------------------------------------------------------- -pqEventRecorder::pqEventRecorder(QObject *parent) +pqEventRecorder::pqEventRecorder(QObject* parent) : Superclass(parent) { this->ActiveObserver = 0; @@ -62,22 +62,20 @@ pqEventRecorder::~pqEventRecorder() void pqEventRecorder::setContinuousFlush(bool value) { if (!this->ActiveObserver) - { + { return; - } + } if (value) - { - QObject::connect(this->ActiveObserver, - SIGNAL(eventRecorded(QString,QString,QString, int)), - this, SLOT(flush())); - } + { + QObject::connect(this->ActiveObserver, SIGNAL(eventRecorded(QString, QString, QString, int)), + this, SLOT(flush())); + } else - { - QObject::disconnect(this->ActiveObserver, - SIGNAL(eventRecorded(QString,QString,QString, int)), - this, SLOT(flush())); - } + { + QObject::disconnect(this->ActiveObserver, SIGNAL(eventRecorded(QString, QString, QString, int)), + this, SLOT(flush())); + } this->ContinuousFlush = value; } @@ -137,10 +135,10 @@ pqEventObserver* pqEventRecorder::observer() const void pqEventRecorder::setTranslator(pqEventTranslator* translator) { this->ActiveTranslator = translator; - if( this->ActiveTranslator != NULL) - { + if (this->ActiveTranslator != NULL) + { this->ActiveTranslator->recordInteractionTimings(this->RecordInteractionTimings); - } + } } // ---------------------------------------------------------------------------- @@ -152,21 +150,19 @@ pqEventTranslator* pqEventRecorder::translator() const // ---------------------------------------------------------------------------- bool pqEventRecorder::isRecording() const { - if( this->ActiveTranslator != NULL) - { + if (this->ActiveTranslator != NULL) + { return this->ActiveTranslator->isRecording(); - } + } else - { + { return false; - } + } } // ---------------------------------------------------------------------------- -void pqEventRecorder::recordEvents(pqEventTranslator* translator, - pqEventObserver* observer, - QIODevice* file, - bool continuousFlush) +void pqEventRecorder::recordEvents( + pqEventTranslator* translator, pqEventObserver* observer, QIODevice* file, bool continuousFlush) { this->setTranslator(translator); this->setObserver(observer); @@ -186,15 +182,12 @@ void pqEventRecorder::flush() void pqEventRecorder::start() { if (!this->File || !this->ActiveObserver || !this->ActiveTranslator) - { + { return; - } + } - QObject::connect( - this->ActiveTranslator, - SIGNAL(recordEvent(QString,QString,QString, int)), - this->ActiveObserver, - SLOT(onRecordEvent(QString,QString,QString, int))); + QObject::connect(this->ActiveTranslator, SIGNAL(recordEvent(QString, QString, QString, int)), + this->ActiveObserver, SLOT(onRecordEvent(QString, QString, QString, int))); // Set the device this->Stream.setDevice(this->File); @@ -215,11 +208,8 @@ void pqEventRecorder::start() // ---------------------------------------------------------------------------- void pqEventRecorder::stop(int value) { - QObject::disconnect( - this->ActiveTranslator, - SIGNAL(recordEvent(QString,QString,QString, int)), - this->ActiveObserver, - SLOT(onRecordEvent(QString,QString,QString, int))); + QObject::disconnect(this->ActiveTranslator, SIGNAL(recordEvent(QString, QString, QString, int)), + this->ActiveObserver, SLOT(onRecordEvent(QString, QString, QString, int))); this->ActiveObserver->setStream(NULL); this->ActiveTranslator->stop(); @@ -227,9 +217,9 @@ void pqEventRecorder::stop(int value) this->ActiveTranslator->record(false); if (!value) - { + { return; - } + } this->flush(); emit this->stopped(); diff --git a/pqEventRecorder.h b/pqEventRecorder.h index 4a60e1a..f013545 100644 --- a/pqEventRecorder.h +++ b/pqEventRecorder.h @@ -60,7 +60,7 @@ class QTTESTING_EXPORT pqEventRecorder : public QObject typedef QObject Superclass; public: - explicit pqEventRecorder(QObject *parent = 0); + explicit pqEventRecorder(QObject* parent = 0); ~pqEventRecorder() override; bool continuousFlush() const; @@ -77,10 +77,8 @@ public: bool isRecording() const; - void recordEvents(pqEventTranslator* translator, - pqEventObserver* observer, - QIODevice* file, - bool continuousFlush); + void recordEvents(pqEventTranslator* translator, pqEventObserver* observer, QIODevice* file, + bool continuousFlush); signals: void started(); @@ -124,13 +122,13 @@ public slots: void setRecordInteractionTimings(bool value); protected: - pqEventObserver* ActiveObserver; - pqEventTranslator* ActiveTranslator; - QIODevice* File; + pqEventObserver* ActiveObserver; + pqEventTranslator* ActiveTranslator; + QIODevice* File; - bool ContinuousFlush; - bool RecordInteractionTimings; - QTextStream Stream; + bool ContinuousFlush; + bool RecordInteractionTimings; + QTextStream Stream; }; #endif // !_pqEventRecorder_h diff --git a/pqEventSource.h b/pqEventSource.h index e83b46f..81dae8e 100644 --- a/pqEventSource.h +++ b/pqEventSource.h @@ -43,10 +43,14 @@ class QTTESTING_EXPORT pqEventSource : public QObject { Q_OBJECT public: - pqEventSource(QObject* p) : QObject(p) {} + pqEventSource(QObject* p) + : QObject(p) + { + } ~pqEventSource() override {} - enum eventReturnFlag { + enum eventReturnFlag + { SUCCESS, FAILURE, DONE @@ -57,10 +61,7 @@ public: FAILURE if there was a problem, DONE, if there are no more events. */ virtual int getNextEvent( - QString& object, - QString& command, - QString& arguments, - int& eventType) = 0; + QString& object, QString& command, QString& arguments, int& eventType) = 0; /** Set the filename for contents. Returns true for valid file, false for invalid file */ @@ -68,8 +69,6 @@ public: /** tell the source to stop feeding in events */ virtual void stop() {} - }; #endif // !_pqEventSource_h - diff --git a/pqEventTranslator.cxx b/pqEventTranslator.cxx index 0883243..73de398 100644 --- a/pqEventTranslator.cxx +++ b/pqEventTranslator.cxx @@ -56,16 +56,16 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include <QCoreApplication> #include <QElapsedTimer> #include <QSet> -#include <QtDebug> #include <QToolBar> #include <QVector> +#include <QtDebug> //////////////////////////////////////////////////////////////////////////////// // pqEventTranslator::pqImplementation struct pqEventTranslator::pqImplementation { pqImplementation() - { + { this->EventComment = 0; this->Checking = false; this->Recording = false; @@ -75,20 +75,20 @@ struct pqEventTranslator::pqImplementation this->hideOverlay(); this->RecordInteractionTimings = false; - } + } ~pqImplementation() + { + if (this->EventComment) { - if(this->EventComment) - { delete this->EventComment; - } + } delete this->CheckOverlay; this->CheckOverlayWidgetOn = NULL; - } + } void hideOverlay() - { + { // Hide the overlay this->CheckOverlay->hide(); @@ -97,7 +97,7 @@ struct pqEventTranslator::pqImplementation // Set the overlayed widget to null this->CheckOverlayWidgetOn = NULL; - } + } pqEventComment* EventComment; /// Stores the working set of widget translators @@ -133,8 +133,8 @@ struct pqEventTranslator::pqImplementation // ---------------------------------------------------------------------------- pqEventTranslator::pqEventTranslator(QObject* p) -: QObject(p), - Implementation(new pqImplementation()) + : QObject(p) + , Implementation(new pqImplementation()) { // Ignore the overlay so it is transparent to events. this->ignoreObject(this->Implementation->CheckOverlay); @@ -186,40 +186,30 @@ void pqEventTranslator::addDefaultWidgetEventTranslators(pqTestUtility* util) // ---------------------------------------------------------------------------- void pqEventTranslator::addWidgetEventTranslator(pqWidgetEventTranslator* Translator) { - if(Translator) - { + if (Translator) + { // We Check if the translator has already been added previously. - int index = - this->getWidgetEventTranslatorIndex(Translator->metaObject()->className()); + int index = this->getWidgetEventTranslatorIndex(Translator->metaObject()->className()); if (index != -1) - { + { return; - } + } this->Implementation->Translators.push_front(Translator); Translator->setParent(this); // Legacy Connection, for translator not using event types - QObject::connect( - Translator, - SIGNAL(recordEvent(QObject*, const QString&, const QString&)), - this, - SLOT(onRecordEvent(QObject*, const QString&, const QString&))); + QObject::connect(Translator, SIGNAL(recordEvent(QObject*, const QString&, const QString&)), + this, SLOT(onRecordEvent(QObject*, const QString&, const QString&))); // Connect record event - QObject::connect( - Translator, - SIGNAL(recordEvent(QObject*, const QString&, const QString&, int)), - this, - SLOT(onRecordEvent(QObject*, const QString&, const QString&, int))); + QObject::connect(Translator, SIGNAL(recordEvent(QObject*, const QString&, const QString&, int)), + this, SLOT(onRecordEvent(QObject*, const QString&, const QString&, int))); // Connect resize specific overlay - QObject::connect( - Translator, - SIGNAL(specificOverlay(const QRect&)), - this, - SLOT(setOverlayGeometry(const QRect&))); - } + QObject::connect(Translator, SIGNAL(specificOverlay(const QRect&)), this, + SLOT(setOverlayGeometry(const QRect&))); + } } // ---------------------------------------------------------------------------- @@ -227,23 +217,22 @@ bool pqEventTranslator::removeWidgetEventTranslator(const QString& className) { int index = this->getWidgetEventTranslatorIndex(className); if (index == -1) - { + { return false; - } + } this->Implementation->Translators.removeAt(index); return true; } // ---------------------------------------------------------------------------- -pqWidgetEventTranslator* pqEventTranslator::getWidgetEventTranslator( - const QString& className) +pqWidgetEventTranslator* pqEventTranslator::getWidgetEventTranslator(const QString& className) { int index = this->getWidgetEventTranslatorIndex(className); if (index == -1) - { + { return 0; - } + } return this->Implementation->Translators.at(index); } @@ -251,14 +240,13 @@ pqWidgetEventTranslator* pqEventTranslator::getWidgetEventTranslator( // ---------------------------------------------------------------------------- int pqEventTranslator::getWidgetEventTranslatorIndex(const QString& className) { - for (int i = 0 ; i < this->Implementation->Translators.count() ; ++i) + for (int i = 0; i < this->Implementation->Translators.count(); ++i) + { + if (this->Implementation->Translators.at(i)->metaObject()->className() == className) { - if (this->Implementation->Translators.at(i)->metaObject()->className() == - className) - { return i; - } } + } return -1; } @@ -273,9 +261,8 @@ void pqEventTranslator::addDefaultEventManagers(pqTestUtility* util) { this->Implementation->EventComment = new pqEventComment(util); QObject::connect(this->Implementation->EventComment, - SIGNAL(recordComment(QObject*,QString,QString)), - this, - SLOT(onRecordEvent(QObject*,QString,QString))); + SIGNAL(recordComment(QObject*, QString, QString)), this, + SLOT(onRecordEvent(QObject*, QString, QString))); } // ---------------------------------------------------------------------------- @@ -294,53 +281,50 @@ void pqEventTranslator::ignoreObject(QObject* object, QRegExp commandFilter) bool pqEventTranslator::eventFilter(QObject* object, QEvent* event) { if (this->Implementation->Recording) - { + { #if QT_VERSION >= 0x050000 - if(object->isWindowType()) - { + if (object->isWindowType()) + { return false; - } + } #endif // Only widgets QWidget* widget = qobject_cast<QWidget*>(object); if (widget != NULL) - { + { // mouse events are propagated to parents // our event translators/players don't quite like that, // so lets consume those extra ones - if(event->type() == QEvent::MouseButtonPress || - event->type() == QEvent::MouseButtonDblClick || - event->type() == QEvent::MouseMove || - event->type() == QEvent::Enter || - event->type() == QEvent::Leave || - event->type() == QEvent::MouseButtonRelease || - event->type() == QEvent::ContextMenu) + if (event->type() == QEvent::MouseButtonPress || + event->type() == QEvent::MouseButtonDblClick || event->type() == QEvent::MouseMove || + event->type() == QEvent::Enter || event->type() == QEvent::Leave || + event->type() == QEvent::MouseButtonRelease || event->type() == QEvent::ContextMenu) + { + if (!this->Implementation->MouseParents.empty() && + this->Implementation->MouseParents.first() == object) { - if(!this->Implementation->MouseParents.empty() && - this->Implementation->MouseParents.first() == object) - { // right on track this->Implementation->MouseParents.removeFirst(); return false; - } + } // find the chain of parent that will get this mouse event this->Implementation->MouseParents.clear(); - for(QWidget* w = widget->parentWidget(); w; w = w->parentWidget()) - { + for (QWidget* w = widget->parentWidget(); w; w = w->parentWidget()) + { this->Implementation->MouseParents.append(w); - if(w->isWindow() || w->testAttribute(Qt::WA_NoMousePropagation)) - { + if (w->isWindow() || w->testAttribute(Qt::WA_NoMousePropagation)) + { break; - } } } + } // Checking mode - if(this->Implementation->Checking) - { + if (this->Implementation->Checking) + { // In Gl Case, parentless widget is not transparent to mouse event // The event is applied to the overlayed widget or an another top widget // (before ignoredObjects) @@ -352,96 +336,100 @@ bool pqEventTranslator::eventFilter(QObject* object, QEvent* event) // This is a mouse event we manage // The overlay receive the event if (this->Implementation->CheckOverlayWidgetOn != NULL && - this->Implementation->CheckOverlay->GlWidget && - widget == this->Implementation->CheckOverlay && - (event->type() == QEvent::MouseButtonRelease || - event->type() == QEvent::MouseMove)) - { + this->Implementation->CheckOverlay->GlWidget && + widget == this->Implementation->CheckOverlay && + (event->type() == QEvent::MouseButtonRelease || event->type() == QEvent::MouseMove)) + { // We are about to look for another top widget window behind the mouse cursor bool foundTop = false; QWidget* topWidget; // recover all top widgets QWidgetList topWidgets = QApplication::topLevelWidgets(); - foreach(topWidget, topWidgets) - { + foreach (topWidget, topWidgets) + { // only the visible ones - if(!topWidget->isHidden()) - { + if (!topWidget->isHidden()) + { // Check it is not the overlay, and it contains the mouse cursor if (topWidget != this->Implementation->CheckOverlay && topWidget->geometry().contains(static_cast<QMouseEvent*>(event)->globalPos(), true)) - { + { // Recover the child widget onder the cursor, if any - QWidget* childWidget = topWidget->childAt(topWidget->mapFromGlobal(static_cast<QMouseEvent*>(event)->globalPos())); + QWidget* childWidget = topWidget->childAt( + topWidget->mapFromGlobal(static_cast<QMouseEvent*>(event)->globalPos())); // If child exist, check it is not the overlayed widget and indeed a new widget - if (childWidget == NULL || (childWidget != NULL && childWidget != this->Implementation->CheckOverlayWidgetOn)) - { + if (childWidget == NULL || + (childWidget != NULL && + childWidget != this->Implementation->CheckOverlayWidgetOn)) + { // if a child exist, use it - if(childWidget != NULL) - { + if (childWidget != NULL) + { topWidget = childWidget; - } + } // Position top widget flag foundTop = true; break; - } } } } + } if (foundTop) - { + { // If we found a top widget behin the cursor, use it widget = topWidget; - } + } else - { + { // If not, use the widget behind the overlay widget = this->Implementation->CheckOverlayWidgetOn; - } } + } // Leaving the checkOverlay when a widget without grand parent // then hiding overlay (before ignoredObjects) if (this->Implementation->CheckOverlay == widget && - !this->Implementation->CheckOverlay->Specific ) - { + !this->Implementation->CheckOverlay->Specific) + { if (event->type() == QEvent::Leave) - { + { this->Implementation->hideOverlay(); - } } + } // Ignore object if specified if (this->Implementation->IgnoredObjects.contains(widget)) - { + { return false; - } + } // Do not check QToolBar as they can generate buggy overlay if (qobject_cast<QToolBar*>(widget) != NULL) - { + { return false; - } + } // Mouse Move on a non-previously overlayed widget - if (event->type() == QEvent::MouseMove - && this->Implementation->CheckOverlayWidgetOn != widget) - { + if (event->type() == QEvent::MouseMove && + this->Implementation->CheckOverlayWidgetOn != widget) + { // Check for any valid translator bool validTranslator = false; bool error; - for(int i = 0; i != this->Implementation->Translators.size(); ++i) + for (int i = 0; i != this->Implementation->Translators.size(); ++i) + { + // This will not record a check event, only check if a translator can record a check + // event + if (this->Implementation->Translators[i]->translateEvent( + widget, event, pqEventTypes::CHECK_EVENT, error)) { - // This will not record a check event, only check if a translator can record a check event - if(this->Implementation->Translators[i]->translateEvent(widget, event, pqEventTypes::CHECK_EVENT, error)) - { validTranslator = true; break; - } } + } // Draw overlay this->Implementation->hideOverlay(); @@ -449,29 +437,30 @@ bool pqEventTranslator::eventFilter(QObject* object, QEvent* event) // Only on non-window widget // TODO handle the overlay on window widget if (!widget->isWindow() && widget->parent() != NULL) - { + { // Check if widget is glWidget this->Implementation->CheckOverlay->GlWidget = widget->inherits("QVTKWidget"); // Check if widget is parent to gl widget - QList<QWidget *> children = widget->findChildren<QWidget *>(); - foreach(QWidget * child, children) - { + QList<QWidget*> children = widget->findChildren<QWidget*>(); + foreach (QWidget* child, children) + { if (child->inherits("QVTKWidget")) - { + { // Ignore widget containing a Gl widget as a child this->ignoreObject(widget); return false; - } } + } // Check widget size is valid, if not do not draw overlay // Widget can still be clicked and checked - int sizeThreshold = pqCheckEventOverlay::OVERLAY_MARGIN + 2*pqCheckEventOverlay::OVERLAY_PEN_WIDTH; + int sizeThreshold = + pqCheckEventOverlay::OVERLAY_MARGIN + 2 * pqCheckEventOverlay::OVERLAY_PEN_WIDTH; if (widget->width() < sizeThreshold || widget->height() < sizeThreshold) - { + { return false; - } + } // Set the validity of the overlay this->Implementation->CheckOverlay->Valid = validTranslator; @@ -480,21 +469,24 @@ bool pqEventTranslator::eventFilter(QObject* object, QEvent* event) this->Implementation->CheckOverlay->setParent(qobject_cast<QWidget*>(widget->parent())); if (this->Implementation->CheckOverlay->GlWidget) - { - // Cannot draw QPainter directive in openGl context, bust use another context, aka another window - //this->Implementation->CheckOverlay->setWindowFlags(Qt::ToolTip | Qt::FramelessWindowHint); // ToolTip is always on top - this->Implementation->CheckOverlay->setWindowFlags(Qt::Tool | Qt::FramelessWindowHint); //Tool generate avatar + { + // Cannot draw QPainter directive in openGl context, bust use another context, aka + // another window + // this->Implementation->CheckOverlay->setWindowFlags(Qt::ToolTip | + // Qt::FramelessWindowHint); // ToolTip is always on top + this->Implementation->CheckOverlay->setWindowFlags( + Qt::Tool | Qt::FramelessWindowHint); // Tool generate avatar this->Implementation->CheckOverlay->setAttribute(Qt::WA_NoSystemBackground, true); this->Implementation->CheckOverlay->setAttribute(Qt::WA_TranslucentBackground, true); this->Implementation->CheckOverlay->setAttribute(Qt::WA_PaintOnScreen, true); // Resize and move widget QRect geometry = widget->geometry(); - geometry.moveTo(widget->mapToGlobal(QPoint(0,0))); + geometry.moveTo(widget->mapToGlobal(QPoint(0, 0))); this->setOverlayGeometry(geometry, false); - } + } else - { + { // Restore window flags this->Implementation->CheckOverlay->setWindowFlags(Qt::Widget); this->Implementation->CheckOverlay->setAttribute(Qt::WA_NoSystemBackground, false); @@ -503,96 +495,96 @@ bool pqEventTranslator::eventFilter(QObject* object, QEvent* event) // Set overlay geometry to be the same as overlayed widget this->setOverlayGeometry(widget->geometry(), false); - } + } // Show and Register overlay this->Implementation->CheckOverlay->show(); this->Implementation->CheckOverlayWidgetOn = widget; - } } + } // Resize event - if(event->type() == QEvent::Resize) - { + if (event->type() == QEvent::Resize) + { // Set overlay geometry QRect geometry = widget->geometry(); if (this->Implementation->CheckOverlay->GlWidget) - { - geometry.moveTo(widget->mapToGlobal(QPoint(0,0))); - } - this->setOverlayGeometry(geometry, false); + { + geometry.moveTo(widget->mapToGlobal(QPoint(0, 0))); } + this->setOverlayGeometry(geometry, false); + } // Mouse button release -> Check Event if (event->type() == QEvent::MouseButtonRelease) - { + { // Check Translators - for(int i = 0; i != this->Implementation->Translators.size(); ++i) - { + for (int i = 0; i != this->Implementation->Translators.size(); ++i) + { bool error = false; - if(this->Implementation->Translators[i]->translateEvent(widget, event, pqEventTypes::CHECK_EVENT, error)) + if (this->Implementation->Translators[i]->translateEvent( + widget, event, pqEventTypes::CHECK_EVENT, error)) + { + if (error) { - if(error) - { qWarning() << "Error translating a check event for object " << widget; - } - return true; } + return true; } + } // Cannot check widget , Inform user trying to check uncheckable widget qWarning() << "Error checking an event for object, widget type not supported."; - qWarning() << "Name of the widget:" << widget->objectName() << ". Type of the widget:" << widget->metaObject()->className(); + qWarning() << "Name of the widget:" << widget->objectName() + << ". Type of the widget:" << widget->metaObject()->className(); if (widget->parent() != NULL) - { + { qWarning() << "Type of parent widget:" << widget->parent()->metaObject()->className(); - } } + } // Block all input events, so the UI is static but still drawn. // Except for MouseMove if (dynamic_cast<QInputEvent*>(event) != NULL && event->type() != QEvent::MouseMove) - { + { return true; - } } + } else - { + { // Event Recording - for(int i = 0; i != this->Implementation->Translators.size(); ++i) - { + for (int i = 0; i != this->Implementation->Translators.size(); ++i) + { bool error = false; - if(this->Implementation->Translators[i]->translateEvent(object, event, pqEventTypes::ACTION_EVENT, error)) + if (this->Implementation->Translators[i]->translateEvent( + object, event, pqEventTypes::ACTION_EVENT, error)) + { + if (error) { - if(error) - { qWarning() << "Error translating an event for object " << object; - } - return false; } + return false; } } } } + } return false; } // ---------------------------------------------------------------------------- -void pqEventTranslator::onRecordEvent(QObject* Object, - const QString& Command, - const QString& Arguments) +void pqEventTranslator::onRecordEvent( + QObject* Object, const QString& Command, const QString& Arguments) { this->onRecordEvent(Object, Command, Arguments, pqEventTypes::ACTION_EVENT); } // ---------------------------------------------------------------------------- -void pqEventTranslator::onRecordEvent(QObject* Object, - const QString& Command, - const QString& Arguments, - int eventType) +void pqEventTranslator::onRecordEvent( + QObject* Object, const QString& Command, const QString& Arguments, int eventType) { - if(this->Implementation->IgnoredObjects.contains(Object)) + if (this->Implementation->IgnoredObjects.contains(Object)) { QRegExp commandFilter = this->Implementation->IgnoredObjects.value(Object); - if(Command.contains(commandFilter)) + if (Command.contains(commandFilter)) { return; } @@ -600,24 +592,24 @@ void pqEventTranslator::onRecordEvent(QObject* Object, QString name; if (eventType == pqEventTypes::ACTION_EVENT) - { + { // When sender is pqEventObject, the Object name can be NULL. if (!qobject_cast<pqEventComment*>(this->sender()) || Object) - { + { name = pqObjectNaming::GetName(*Object); - if(name.isEmpty()) - return; - } + if (name.isEmpty()) + return; } + } else - { + { // Check the QObject does have a name name = pqObjectNaming::GetName(*Object); - if(name.isEmpty()) - { + if (name.isEmpty()) + { return; - } } + } // Record user interaction time if (this->Implementation->RecordInteractionTimings) @@ -644,10 +636,10 @@ void pqEventTranslator::check(bool value) this->Implementation->Checking = value; // Hide overlay when not checking - if(!value) - { + if (!value) + { this->Implementation->hideOverlay(); - } + } } // ---------------------------------------------------------------------------- @@ -656,10 +648,10 @@ void pqEventTranslator::record(bool value) this->Implementation->Recording = value; // Hide overlay when not recording - if(!value) - { + if (!value) + { this->Implementation->hideOverlay(); - } + } } // ---------------------------------------------------------------------------- @@ -682,8 +674,8 @@ void pqEventTranslator::recordInteractionTimings(bool value) void pqEventTranslator::setOverlayGeometry(const QRect& geometry, bool specific) { if (this->Implementation->CheckOverlay != NULL) - { + { this->Implementation->CheckOverlay->setGeometry(geometry); - } + } this->Implementation->CheckOverlay->Specific = specific; } diff --git a/pqEventTranslator.h b/pqEventTranslator.h index f9c2b0f..33cf18d 100644 --- a/pqEventTranslator.h +++ b/pqEventTranslator.h @@ -44,22 +44,26 @@ class pqWidgetEventTranslator; /** Manages serialization of user interaction for test-cases, demos, tutorials, etc. -pqEventTranslator installs itself as a global Qt event "filter" that receives notification of every Qt event. Each event is passed -through a collection of pqWidgetEventTranslator objects, until one of them "handles" the event. The pqWidgetEventTranslator objects -convert low-level Qt events (mouse move, button down, key released, etc) into high-level ParaView events (button clicked, row selected, etc) -that can be serialized as text. Once an event translator is found, the recordEvent() signal is emitted with the name of the widget -that is receiving the event, plus the serialized event. Observers such as pqEventObserverXML connect to the recordEvent() signal and +pqEventTranslator installs itself as a global Qt event "filter" that receives notification of every +Qt event. Each event is passed +through a collection of pqWidgetEventTranslator objects, until one of them "handles" the event. The +pqWidgetEventTranslator objects +convert low-level Qt events (mouse move, button down, key released, etc) into high-level ParaView +events (button clicked, row selected, etc) +that can be serialized as text. Once an event translator is found, the recordEvent() signal is +emitted with the name of the widget +that is receiving the event, plus the serialized event. Observers such as pqEventObserverXML +connect to the recordEvent() signal and handle storage of the events. \sa pqWidgetEventTranslator, pqEventObserverStdout, pqEventObserverXML, pqEventPlayer. */ -class QTTESTING_EXPORT pqEventTranslator : - public QObject +class QTTESTING_EXPORT pqEventTranslator : public QObject { Q_OBJECT public: - pqEventTranslator(QObject* p=0); + pqEventTranslator(QObject* p = 0); ~pqEventTranslator() override; /** Adds the default set of widget translators to the working set. @@ -88,7 +92,8 @@ public: /// translating events which command is equivalent to the regexp /// (useful to prevent recording UI events from being /// captured as part of the recording) - void ignoreObject(QObject* object, QRegExp commandFilter = QRegExp("*", Qt::CaseInsensitive, QRegExp::Wildcard)); + void ignoreObject( + QObject* object, QRegExp commandFilter = QRegExp("*", Qt::CaseInsensitive, QRegExp::Wildcard)); /// start listening to the GUI and translating events void start(); @@ -109,7 +114,8 @@ signals: /// This signal will be emitted every time a translator generates a /// high-level ParaView event. Observers should connect to this signal /// to serialize high-level events. - void recordEvent(const QString& Object, const QString& Command, const QString& Arguments, int eventType); + void recordEvent( + const QString& Object, const QString& Command, const QString& Arguments, int eventType); /// this signals when recording starts void started(); @@ -119,7 +125,8 @@ signals: private slots: // Slot called when recording an event - void onRecordEvent(QObject* Object, const QString& Command, const QString& Arguments, int eventType); + void onRecordEvent( + QObject* Object, const QString& Command, const QString& Arguments, int eventType); // Legacy convenient slot for pqEventTypes::ACTION_EVENT events void onRecordEvent(QObject* Object, const QString& Command, const QString& Arguments); diff --git a/pqEventTypes.h b/pqEventTypes.h index 31c73f5..37c8b18 100644 --- a/pqEventTypes.h +++ b/pqEventTypes.h @@ -35,11 +35,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. namespace pqEventTypes { - enum eventType { - ACTION_EVENT = 0, - CHECK_EVENT = 1 - }; +enum eventType +{ + ACTION_EVENT = 0, + CHECK_EVENT = 1 +}; }; #endif // !_pqEventTypes_h - diff --git a/pqLineEditEventTranslator.cxx b/pqLineEditEventTranslator.cxx index bff7c13..f051b44 100644 --- a/pqLineEditEventTranslator.cxx +++ b/pqLineEditEventTranslator.cxx @@ -32,14 +32,14 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "pqLineEditEventTranslator.h" -#include <QEvent> #include <QDebug> +#include <QEvent> +#include <QKeyEvent> #include <QLineEdit> +#include <QPlainTextEdit> #include <QSpinBox> #include <QTextDocument> #include <QTextEdit> -#include <QPlainTextEdit> -#include <QKeyEvent> #include "pqEventTypes.h" @@ -48,94 +48,94 @@ pqLineEditEventTranslator::pqLineEditEventTranslator(QObject* p) { } -bool pqLineEditEventTranslator::translateEvent(QObject* object, QEvent* event, int eventType, bool& error) +bool pqLineEditEventTranslator::translateEvent( + QObject* object, QEvent* event, int eventType, bool& error) { QObject* tmpObject = object; QLineEdit* leObject = qobject_cast<QLineEdit*>(object); QTextEdit* teObject = qobject_cast<QTextEdit*>(object); QPlainTextEdit* pteObject = qobject_cast<QPlainTextEdit*>(object); - if(!leObject && !teObject && !pteObject && object->parent() != NULL) - { + if (!leObject && !teObject && !pteObject && object->parent() != NULL) + { // MouseEvent can be received by viewport tmpObject = object->parent(); leObject = qobject_cast<QLineEdit*>(tmpObject); teObject = qobject_cast<QTextEdit*>(tmpObject); pteObject = qobject_cast<QPlainTextEdit*>(tmpObject); - } - if(!leObject && !teObject && !pteObject) - { + } + if (!leObject && !teObject && !pteObject) + { return false; - } + } if (eventType == pqEventTypes::ACTION_EVENT) - { + { // If this line edit is part of a spinbox, don't translate events // (the spinbox translator will receive the final value directly) - if(qobject_cast<QSpinBox*>(tmpObject->parent())) - { + if (qobject_cast<QSpinBox*>(tmpObject->parent())) + { return false; - } + } - switch(event->type()) - { + switch (event->type()) + { case QEvent::KeyRelease: - { + { QKeyEvent* ke = static_cast<QKeyEvent*>(event); QString keyText = ke->text(); - if(keyText.length() && keyText.at(0).isPrint()) - { + if (keyText.length() && keyText.at(0).isPrint()) + { if (leObject) - { + { emit recordEvent(tmpObject, "set_string", leObject->text()); - } + } else if (teObject) - { + { emit recordEvent(tmpObject, "set_string", teObject->document()->toPlainText()); - } + } else if (pteObject) - { + { emit recordEvent(tmpObject, "set_string", pteObject->document()->toPlainText()); - } - } + } // if we record F2 event, will cause some issue with the TreeView // Need test to know if we need to record those events else if (ke->key() != Qt::Key_F2) - { + { emit recordEvent(tmpObject, "key", QString("%1").arg(ke->key())); - } + } return true; break; - } - default: - break; } + default: + break; } + } else if (eventType == pqEventTypes::CHECK_EVENT) - { + { // TextEdit only, LineEdit does not need specific check if (teObject != NULL || pteObject != NULL) - { + { if (event->type() == QEvent::MouseMove) - { + { return true; - } + } // Clicking while checking, actual check event if (event->type() == QEvent::MouseButtonRelease) + { + if (teObject != NULL) { - if(teObject != NULL) - { - emit this->recordEvent(teObject, "plainText", - teObject->toPlainText().replace("\t", " "), pqEventTypes::CHECK_EVENT); - } + emit this->recordEvent(teObject, "plainText", teObject->toPlainText().replace("\t", " "), + pqEventTypes::CHECK_EVENT); + } else /* if (pteObject != NULL)*/ - { + { emit this->recordEvent(pteObject, "plainText", pteObject->toPlainText().replace("\t", " "), pqEventTypes::CHECK_EVENT); - } - return true; } + return true; } } + } return this->Superclass::translateEvent(object, event, eventType, error); } diff --git a/pqLineEditEventTranslator.h b/pqLineEditEventTranslator.h index 613d16c..ffe3a23 100644 --- a/pqLineEditEventTranslator.h +++ b/pqLineEditEventTranslator.h @@ -7,7 +7,7 @@ All rights reserved. ParaView is a free software; you can redistribute it and/or modify it - under the terms of the ParaView license version 1.2. + under the terms of the ParaView license version 1.2. See License_v1.2.txt for the full ParaView license. A copy of this license can be obtained by contacting @@ -41,14 +41,13 @@ Translates low-level Qt events into high-level ParaView events that can be recor \sa pqEventTranslator */ -class QTTESTING_EXPORT pqLineEditEventTranslator : - public pqWidgetEventTranslator +class QTTESTING_EXPORT pqLineEditEventTranslator : public pqWidgetEventTranslator { Q_OBJECT typedef pqWidgetEventTranslator Superclass; - + public: - pqLineEditEventTranslator(QObject* p=0); + pqLineEditEventTranslator(QObject* p = 0); using Superclass::translateEvent; bool translateEvent(QObject* object, QEvent* event, int eventType, bool& error) override; @@ -59,4 +58,3 @@ private: }; #endif // !_pqLineEditEventTranslator_h - diff --git a/pqListViewEventPlayer.cxx b/pqListViewEventPlayer.cxx index c9a4c62..74dcf0a 100644 --- a/pqListViewEventPlayer.cxx +++ b/pqListViewEventPlayer.cxx @@ -45,18 +45,17 @@ pqListViewEventPlayer::~pqListViewEventPlayer() //-----------------------------------------------------------------------------0000000 bool pqListViewEventPlayer::playEvent( - QObject* object, const QString& command, - const QString& arguments, int eventType, bool& error) + QObject* object, const QString& command, const QString& arguments, int eventType, bool& error) { - QListView* listView= qobject_cast<QListView*>(object); - if(!listView) - { + QListView* listView = qobject_cast<QListView*>(object); + if (!listView) + { // mouse events go to the viewport widget listView = qobject_cast<QListView*>(object->parent()); - } - if(!listView) - { + } + if (!listView) + { return false; - } + } return this->Superclass::playEvent(object, command, arguments, eventType, error); } diff --git a/pqListViewEventPlayer.h b/pqListViewEventPlayer.h index 9b50a27..cc43f3f 100644 --- a/pqListViewEventPlayer.h +++ b/pqListViewEventPlayer.h @@ -40,17 +40,18 @@ class QTTESTING_EXPORT pqListViewEventPlayer : public pqAbstractItemViewEventPla { Q_OBJECT typedef pqAbstractItemViewEventPlayerBase Superclass; + public: - pqListViewEventPlayer(QObject* parent=0); + pqListViewEventPlayer(QObject* parent = 0); ~pqListViewEventPlayer() override; using Superclass::playEvent; - bool playEvent(QObject* object, const QString& command, - const QString& arguments, int eventType, bool& error) override; + bool playEvent(QObject* object, const QString& command, const QString& arguments, int eventType, + bool& error) override; private: pqListViewEventPlayer(const pqListViewEventPlayer&); // Not implemented. - void operator=(const pqListViewEventPlayer&); // Not implemented. + void operator=(const pqListViewEventPlayer&); // Not implemented. }; #endif diff --git a/pqListViewEventTranslator.cxx b/pqListViewEventTranslator.cxx index a7aa280..1b87855 100644 --- a/pqListViewEventTranslator.cxx +++ b/pqListViewEventTranslator.cxx @@ -31,8 +31,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ========================================================================*/ #include "pqListViewEventTranslator.h" -#include <QListView> #include <QHeaderView> +#include <QListView> //----------------------------------------------------------------------------- pqListViewEventTranslator::pqListViewEventTranslator(QObject* parentObject) : Superclass(parentObject) @@ -54,8 +54,7 @@ void pqListViewEventTranslator::onEnteredCheck(const QModelIndex& item) QRect visualRect = listView->visualRect(item); // Translate the rect of margins and headers - visualRect.translate(listView->contentsMargins().left(), - listView->contentsMargins().top()); + visualRect.translate(listView->contentsMargins().left(), listView->contentsMargins().top()); // Stor item and signal that a specific overlay is ready to be drawn this->ModelItemCheck = &item; @@ -67,16 +66,15 @@ QAbstractItemView* pqListViewEventTranslator::findCorrectedAbstractItemView(QObj { // Ignore QHeaderView event specifically if (qobject_cast<QHeaderView*>(object)) - { + { return NULL; - } + } QAbstractItemView* abstractItemView = qobject_cast<QListView*>(object); if (!abstractItemView) - { + { // mouse events go to the viewport widget abstractItemView = qobject_cast<QListView*>(object->parent()); - } + } return abstractItemView; } - diff --git a/pqListViewEventTranslator.h b/pqListViewEventTranslator.h index 952baf1..8e65a89 100644 --- a/pqListViewEventTranslator.h +++ b/pqListViewEventTranslator.h @@ -41,8 +41,9 @@ class QTTESTING_EXPORT pqListViewEventTranslator : public pqAbstractItemViewEven { Q_OBJECT typedef pqAbstractItemViewEventTranslatorBase Superclass; + public: - pqListViewEventTranslator(QObject* parent=0); + pqListViewEventTranslator(QObject* parent = 0); ~pqListViewEventTranslator() override; /// find and set the corrected abstract item view @@ -54,7 +55,7 @@ protected slots: private: pqListViewEventTranslator(const pqListViewEventTranslator&); // Not implemented. - void operator=(const pqListViewEventTranslator&); // Not implemented. + void operator=(const pqListViewEventTranslator&); // Not implemented. }; #endif diff --git a/pqMenuEventTranslator.cxx b/pqMenuEventTranslator.cxx index 1fdeb46..d48b804 100644 --- a/pqMenuEventTranslator.cxx +++ b/pqMenuEventTranslator.cxx @@ -7,7 +7,7 @@ All rights reserved. ParaView is a free software; you can redistribute it and/or modify it - under the terms of the ParaView license version 1.2. + under the terms of the ParaView license version 1.2. See License_v1.2.txt for the full ParaView license. A copy of this license can be obtained by contacting @@ -33,13 +33,13 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "pqMenuEventTranslator.h" #include <QEvent> -#include <QMouseEvent> #include <QKeyEvent> #include <QMenu> #include <QMenuBar> +#include <QMouseEvent> pqMenuEventTranslator::pqMenuEventTranslator(QObject* p) -: pqWidgetEventTranslator(p) + : pqWidgetEventTranslator(p) { } @@ -47,72 +47,70 @@ pqMenuEventTranslator::~pqMenuEventTranslator() { } -bool pqMenuEventTranslator::translateEvent(QObject* Object, QEvent* Event, - bool& Error) +bool pqMenuEventTranslator::translateEvent(QObject* Object, QEvent* Event, bool& Error) { QMenu* const menu = qobject_cast<QMenu*>(Object); QMenuBar* const menubar = qobject_cast<QMenuBar*>(Object); - if(!menu && !menubar) - { + if (!menu && !menubar) + { return false; - } + } if (menubar) - { + { QMouseEvent* e = dynamic_cast<QMouseEvent*>(Event); if (e && e->button() == Qt::LeftButton) - { + { QAction* action = menubar->actionAt(e->pos()); if (action && action->menu()) - { + { QString which = action->menu()->objectName(); - if(which.isEmpty()) - { + if (which.isEmpty()) + { which = action->text(); - } - emit recordEvent(menubar, "activate", which); } + emit recordEvent(menubar, "activate", which); } - return true; } + return true; + } - if(Event->type() == QEvent::KeyPress) - { + if (Event->type() == QEvent::KeyPress) + { QKeyEvent* e = static_cast<QKeyEvent*>(Event); - if(e->key() == Qt::Key_Enter) - { + if (e->key() == Qt::Key_Enter) + { QAction* action = menu->activeAction(); - if(action) - { + if (action) + { QString which = action->objectName(); - if(which == QString::null) - { + if (which == QString::null) + { which = action->text(); - } - emit recordEvent(menu, "activate", which); } + emit recordEvent(menu, "activate", which); } - return true; } + return true; + } - if(Event->type() == QEvent::MouseButtonRelease) - { + if (Event->type() == QEvent::MouseButtonRelease) + { QMouseEvent* e = static_cast<QMouseEvent*>(Event); - if(e->button() == Qt::LeftButton) - { + if (e->button() == Qt::LeftButton) + { QAction* action = menu->actionAt(e->pos()); if (action && !action->menu()) - { + { QString which = action->objectName(); - if(which == QString::null) - { + if (which == QString::null) + { which = action->text(); - } - emit recordEvent(menu, "activate", which); } + emit recordEvent(menu, "activate", which); } - return true; } + return true; + } return this->Superclass::translateEvent(Object, Event, Error); } - diff --git a/pqMenuEventTranslator.h b/pqMenuEventTranslator.h index 2b5ef59..ca7dffa 100644 --- a/pqMenuEventTranslator.h +++ b/pqMenuEventTranslator.h @@ -7,7 +7,7 @@ All rights reserved. ParaView is a free software; you can redistribute it and/or modify it - under the terms of the ParaView license version 1.2. + under the terms of the ParaView license version 1.2. See License_v1.2.txt for the full ParaView license. A copy of this license can be obtained by contacting @@ -43,14 +43,13 @@ Translates low-level Qt events into high-level ParaView events that can be recor \sa pqEventTranslator */ -class QTTESTING_EXPORT pqMenuEventTranslator : - public pqWidgetEventTranslator +class QTTESTING_EXPORT pqMenuEventTranslator : public pqWidgetEventTranslator { Q_OBJECT typedef pqWidgetEventTranslator Superclass; - + public: - pqMenuEventTranslator(QObject* p=0); + pqMenuEventTranslator(QObject* p = 0); ~pqMenuEventTranslator() override; using Superclass::translateEvent; @@ -59,8 +58,6 @@ public: private: pqMenuEventTranslator(const pqMenuEventTranslator&); pqMenuEventTranslator& operator=(const pqMenuEventTranslator&); - }; #endif // !_pqMenuEventTranslator_h - diff --git a/pqNativeFileDialogEventPlayer.cxx b/pqNativeFileDialogEventPlayer.cxx index 0d0c537..5fad254 100644 --- a/pqNativeFileDialogEventPlayer.cxx +++ b/pqNativeFileDialogEventPlayer.cxx @@ -32,153 +32,158 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "pqNativeFileDialogEventPlayer.h" -#include <QEvent> -#include <QFileDialog> -#include <QApplication> #include "pqEventDispatcher.h" #include "pqTestUtility.h" +#include <QApplication> +#include <QEvent> +#include <QFileDialog> #if QT_VERSION < QT_VERSION_CHECK(5, 3, 0) -typedef QString (*_qt_filedialog_existing_directory_hook)(QWidget *parent, const QString &caption, const QString &dir, QFileDialog::Options options); +typedef QString (*_qt_filedialog_existing_directory_hook)( + QWidget* parent, const QString& caption, const QString& dir, QFileDialog::Options options); extern Q_DECL_IMPORT _qt_filedialog_existing_directory_hook qt_filedialog_existing_directory_hook; -typedef QString (*_qt_filedialog_open_filename_hook)(QWidget * parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedFilter, QFileDialog::Options options); +typedef QString (*_qt_filedialog_open_filename_hook)(QWidget* parent, const QString& caption, + const QString& dir, const QString& filter, QString* selectedFilter, QFileDialog::Options options); extern Q_DECL_IMPORT _qt_filedialog_open_filename_hook qt_filedialog_open_filename_hook; -typedef QStringList (*_qt_filedialog_open_filenames_hook)(QWidget * parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedFilter, QFileDialog::Options options); +typedef QStringList (*_qt_filedialog_open_filenames_hook)(QWidget* parent, const QString& caption, + const QString& dir, const QString& filter, QString* selectedFilter, QFileDialog::Options options); extern Q_DECL_IMPORT _qt_filedialog_open_filenames_hook qt_filedialog_open_filenames_hook; -typedef QString (*_qt_filedialog_save_filename_hook)(QWidget * parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedFilter, QFileDialog::Options options); +typedef QString (*_qt_filedialog_save_filename_hook)(QWidget* parent, const QString& caption, + const QString& dir, const QString& filter, QString* selectedFilter, QFileDialog::Options options); extern Q_DECL_IMPORT _qt_filedialog_save_filename_hook qt_filedialog_save_filename_hook; namespace { - pqNativeFileDialogEventPlayer* self; - _qt_filedialog_existing_directory_hook old_existing_directory_hook; - _qt_filedialog_open_filename_hook old_open_filename_hook; - _qt_filedialog_open_filenames_hook old_open_filenames_hook; - _qt_filedialog_save_filename_hook old_save_filename_hook; - - QEventLoop *loop = 0; - QString filename; - QStringList filenames; - - QString dir_hook(QWidget* pqNotUsed(parent), const QString& pqNotUsed(caption), const QString& pqNotUsed(dir), - QFileDialog::Options pqNotUsed(options)) - { - // wait for next event played to give us a filename - loop->exec(); - return filename; - } - - QString filename_hook(QWidget* pqNotUsed(parent), const QString& pqNotUsed(caption), const QString& pqNotUsed(dir), - const QString& pqNotUsed(filter), QString * pqNotUsed(selectedFilter), - QFileDialog::Options pqNotUsed(options)) - { - // wait for next event played to give us a filename - loop->exec(); - return filename; - } - - QStringList filenames_hook(QWidget* pqNotUsed(parent), const QString& pqNotUsed(caption), const QString& pqNotUsed(dir), - const QString& pqNotUsed(filter), QString *pqNotUsed(selectedFilter), - QFileDialog::Options pqNotUsed(options)) - { - // wait for next event played to give us a filename - loop->exec(); - return filenames; - } +pqNativeFileDialogEventPlayer* self; +_qt_filedialog_existing_directory_hook old_existing_directory_hook; +_qt_filedialog_open_filename_hook old_open_filename_hook; +_qt_filedialog_open_filenames_hook old_open_filenames_hook; +_qt_filedialog_save_filename_hook old_save_filename_hook; + +QEventLoop* loop = 0; +QString filename; +QStringList filenames; + +QString dir_hook(QWidget* pqNotUsed(parent), const QString& pqNotUsed(caption), + const QString& pqNotUsed(dir), QFileDialog::Options pqNotUsed(options)) +{ + // wait for next event played to give us a filename + loop->exec(); + return filename; +} +QString filename_hook(QWidget* pqNotUsed(parent), const QString& pqNotUsed(caption), + const QString& pqNotUsed(dir), const QString& pqNotUsed(filter), + QString* pqNotUsed(selectedFilter), QFileDialog::Options pqNotUsed(options)) +{ + // wait for next event played to give us a filename + loop->exec(); + return filename; +} +QStringList filenames_hook(QWidget* pqNotUsed(parent), const QString& pqNotUsed(caption), + const QString& pqNotUsed(dir), const QString& pqNotUsed(filter), + QString* pqNotUsed(selectedFilter), QFileDialog::Options pqNotUsed(options)) +{ + // wait for next event played to give us a filename + loop->exec(); + return filenames; +} } pqNativeFileDialogEventPlayer::pqNativeFileDialogEventPlayer(pqTestUtility* util, QObject* p) - : pqWidgetEventPlayer(p), mUtil(util) + : pqWidgetEventPlayer(p) + , mUtil(util) { - if(!loop) - { + if (!loop) + { loop = new QEventLoop(); - } + } - QObject::connect(util, SIGNAL(playbackStarted()), this, SLOT(start())); - QObject::connect(util, SIGNAL(playbackStopped()), this, SLOT(stop())); + QObject::connect(util, SIGNAL(playbackStarted()), this, SLOT(start())); + QObject::connect(util, SIGNAL(playbackStopped()), this, SLOT(stop())); } pqNativeFileDialogEventPlayer::~pqNativeFileDialogEventPlayer() { - if(loop) - { + if (loop) + { delete loop; loop = NULL; - } + } } void pqNativeFileDialogEventPlayer::start() { - self = this; + self = this; - // existing dir hook - old_existing_directory_hook = qt_filedialog_existing_directory_hook; - qt_filedialog_existing_directory_hook = dir_hook; + // existing dir hook + old_existing_directory_hook = qt_filedialog_existing_directory_hook; + qt_filedialog_existing_directory_hook = dir_hook; - // open file hook - old_open_filename_hook = qt_filedialog_open_filename_hook; - qt_filedialog_open_filename_hook = filename_hook; + // open file hook + old_open_filename_hook = qt_filedialog_open_filename_hook; + qt_filedialog_open_filename_hook = filename_hook; - // open files hook - old_open_filenames_hook = qt_filedialog_open_filenames_hook; - qt_filedialog_open_filenames_hook = filenames_hook; + // open files hook + old_open_filenames_hook = qt_filedialog_open_filenames_hook; + qt_filedialog_open_filenames_hook = filenames_hook; - // save file hook - old_save_filename_hook = qt_filedialog_save_filename_hook; - qt_filedialog_save_filename_hook = filename_hook; + // save file hook + old_save_filename_hook = qt_filedialog_save_filename_hook; + qt_filedialog_save_filename_hook = filename_hook; } void pqNativeFileDialogEventPlayer::stop() { - self = NULL; - qt_filedialog_existing_directory_hook = old_existing_directory_hook; - qt_filedialog_open_filename_hook = old_open_filename_hook; - qt_filedialog_open_filenames_hook = old_open_filenames_hook; - qt_filedialog_save_filename_hook = old_save_filename_hook; + self = NULL; + qt_filedialog_existing_directory_hook = old_existing_directory_hook; + qt_filedialog_open_filename_hook = old_open_filename_hook; + qt_filedialog_open_filenames_hook = old_open_filenames_hook; + qt_filedialog_save_filename_hook = old_save_filename_hook; } -bool pqNativeFileDialogEventPlayer::playEvent(QObject* Object, const QString& Command, const QString& Arguments, bool& pqNotUsed(Error)) +bool pqNativeFileDialogEventPlayer::playEvent( + QObject* Object, const QString& Command, const QString& Arguments, bool& pqNotUsed(Error)) { - if(!qobject_cast<QApplication*>(Object)) - { - return false; - } - - QStringList normalized_files = Arguments.split(";"); - QStringList files; - - foreach(QString file, normalized_files) - { - files.append(mUtil->convertFromDataDirectory(file)); - } - - if(Command == "FileOpen" || Command == "DirOpen" || Command == "FileSave") - { - filename = files.join(";"); - loop->quit(); - return true; - } - else if(Command == "FilesOpen") - { - filenames = files; - loop->quit(); - return true; - } - + if (!qobject_cast<QApplication*>(Object)) + { return false; + } + + QStringList normalized_files = Arguments.split(";"); + QStringList files; + + foreach (QString file, normalized_files) + { + files.append(mUtil->convertFromDataDirectory(file)); + } + + if (Command == "FileOpen" || Command == "DirOpen" || Command == "FileSave") + { + filename = files.join(";"); + loop->quit(); + return true; + } + else if (Command == "FilesOpen") + { + filenames = files; + loop->quit(); + return true; + } + + return false; } #else //----------------------------------------------------------------------------- -pqNativeFileDialogEventPlayer::pqNativeFileDialogEventPlayer( - pqTestUtility* util, QObject* p) : pqWidgetEventPlayer(p), mUtil(util) +pqNativeFileDialogEventPlayer::pqNativeFileDialogEventPlayer(pqTestUtility* util, QObject* p) + : pqWidgetEventPlayer(p) + , mUtil(util) { } pqNativeFileDialogEventPlayer::~pqNativeFileDialogEventPlayer() diff --git a/pqNativeFileDialogEventPlayer.h b/pqNativeFileDialogEventPlayer.h index 9cf46a2..0c9836d 100644 --- a/pqNativeFileDialogEventPlayer.h +++ b/pqNativeFileDialogEventPlayer.h @@ -44,18 +44,18 @@ Records usage of native file dialogs in test cases. \sa pqEventPlayer */ -class QTTESTING_EXPORT pqNativeFileDialogEventPlayer : - public pqWidgetEventPlayer +class QTTESTING_EXPORT pqNativeFileDialogEventPlayer : public pqWidgetEventPlayer { Q_OBJECT typedef pqWidgetEventPlayer Superclass; public: - pqNativeFileDialogEventPlayer(pqTestUtility* util, QObject* p=0); + pqNativeFileDialogEventPlayer(pqTestUtility* util, QObject* p = 0); ~pqNativeFileDialogEventPlayer() override; using Superclass::playEvent; - bool playEvent(QObject* Object, const QString& Command, const QString& Arguments, bool& Error) override; + bool playEvent( + QObject* Object, const QString& Command, const QString& Arguments, bool& Error) override; protected slots: void start(); diff --git a/pqNativeFileDialogEventTranslator.cxx b/pqNativeFileDialogEventTranslator.cxx index f0e0733..9042e7e 100644 --- a/pqNativeFileDialogEventTranslator.cxx +++ b/pqNativeFileDialogEventTranslator.cxx @@ -32,94 +32,97 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "pqNativeFileDialogEventTranslator.h" -#include <QEvent> -#include <QFileDialog> -#include <QApplication> #include "pqEventTranslator.h" #include "pqTestUtility.h" +#include <QApplication> +#include <QEvent> +#include <QFileDialog> #if QT_VERSION < QT_VERSION_CHECK(5, 3, 0) -typedef QString (*_qt_filedialog_existing_directory_hook)(QWidget *parent, const QString &caption, const QString &dir, QFileDialog::Options options); +typedef QString (*_qt_filedialog_existing_directory_hook)( + QWidget* parent, const QString& caption, const QString& dir, QFileDialog::Options options); extern Q_DECL_IMPORT _qt_filedialog_existing_directory_hook qt_filedialog_existing_directory_hook; -typedef QString (*_qt_filedialog_open_filename_hook)(QWidget * parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedFilter, QFileDialog::Options options); +typedef QString (*_qt_filedialog_open_filename_hook)(QWidget* parent, const QString& caption, + const QString& dir, const QString& filter, QString* selectedFilter, QFileDialog::Options options); extern Q_DECL_IMPORT _qt_filedialog_open_filename_hook qt_filedialog_open_filename_hook; -typedef QStringList (*_qt_filedialog_open_filenames_hook)(QWidget * parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedFilter, QFileDialog::Options options); +typedef QStringList (*_qt_filedialog_open_filenames_hook)(QWidget* parent, const QString& caption, + const QString& dir, const QString& filter, QString* selectedFilter, QFileDialog::Options options); extern Q_DECL_IMPORT _qt_filedialog_open_filenames_hook qt_filedialog_open_filenames_hook; -typedef QString (*_qt_filedialog_save_filename_hook)(QWidget * parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedFilter, QFileDialog::Options options); +typedef QString (*_qt_filedialog_save_filename_hook)(QWidget* parent, const QString& caption, + const QString& dir, const QString& filter, QString* selectedFilter, QFileDialog::Options options); extern Q_DECL_IMPORT _qt_filedialog_save_filename_hook qt_filedialog_save_filename_hook; namespace { - pqNativeFileDialogEventTranslator* self; - _qt_filedialog_existing_directory_hook old_existing_directory_hook; - _qt_filedialog_open_filename_hook old_open_filename_hook; - _qt_filedialog_open_filenames_hook old_open_filenames_hook; - _qt_filedialog_save_filename_hook old_save_filename_hook; - - QString existing_directory_hook(QWidget* parent, const QString& caption, const QString& dir, - QFileDialog::Options options) - { - qt_filedialog_existing_directory_hook = 0; - - QString path = QFileDialog::getExistingDirectory(parent, caption, dir, options); - self->record("DirOpen", path); - - qt_filedialog_existing_directory_hook = existing_directory_hook; - return path; - } +pqNativeFileDialogEventTranslator* self; +_qt_filedialog_existing_directory_hook old_existing_directory_hook; +_qt_filedialog_open_filename_hook old_open_filename_hook; +_qt_filedialog_open_filenames_hook old_open_filenames_hook; +_qt_filedialog_save_filename_hook old_save_filename_hook; + +QString existing_directory_hook( + QWidget* parent, const QString& caption, const QString& dir, QFileDialog::Options options) +{ + qt_filedialog_existing_directory_hook = 0; + QString path = QFileDialog::getExistingDirectory(parent, caption, dir, options); + self->record("DirOpen", path); - QString open_filename_hook(QWidget* parent, const QString& caption, const QString& dir, - const QString& filter, QString *selectedFilter, - QFileDialog::Options options) - { - qt_filedialog_open_filename_hook = 0; + qt_filedialog_existing_directory_hook = existing_directory_hook; + return path; +} - QString file = QFileDialog::getOpenFileName(parent, caption, dir, filter, selectedFilter, options); - self->record("FileOpen", file); +QString open_filename_hook(QWidget* parent, const QString& caption, const QString& dir, + const QString& filter, QString* selectedFilter, QFileDialog::Options options) +{ + qt_filedialog_open_filename_hook = 0; - qt_filedialog_open_filename_hook = open_filename_hook; - return file; - } + QString file = + QFileDialog::getOpenFileName(parent, caption, dir, filter, selectedFilter, options); + self->record("FileOpen", file); - QStringList open_filenames_hook(QWidget* parent, const QString& caption, const QString& dir, - const QString& filter, QString *selectedFilter, - QFileDialog::Options options) - { - qt_filedialog_open_filenames_hook = 0; + qt_filedialog_open_filename_hook = open_filename_hook; + return file; +} - QStringList files = QFileDialog::getOpenFileNames(parent, caption, dir, filter, selectedFilter, options); - self->record("FilesOpen", files.join(";")); +QStringList open_filenames_hook(QWidget* parent, const QString& caption, const QString& dir, + const QString& filter, QString* selectedFilter, QFileDialog::Options options) +{ + qt_filedialog_open_filenames_hook = 0; - qt_filedialog_open_filenames_hook = open_filenames_hook; - return files; - } + QStringList files = + QFileDialog::getOpenFileNames(parent, caption, dir, filter, selectedFilter, options); + self->record("FilesOpen", files.join(";")); - QString save_filename_hook(QWidget* parent, const QString& caption, const QString& dir, - const QString& filter, QString *selectedFilter, - QFileDialog::Options options) - { - qt_filedialog_save_filename_hook = 0; + qt_filedialog_open_filenames_hook = open_filenames_hook; + return files; +} - QString file = QFileDialog::getSaveFileName(parent, caption, dir, filter, selectedFilter, options); - self->record("FileSave", file); +QString save_filename_hook(QWidget* parent, const QString& caption, const QString& dir, + const QString& filter, QString* selectedFilter, QFileDialog::Options options) +{ + qt_filedialog_save_filename_hook = 0; - qt_filedialog_save_filename_hook = save_filename_hook; - return file; - } + QString file = + QFileDialog::getSaveFileName(parent, caption, dir, filter, selectedFilter, options); + self->record("FileSave", file); + qt_filedialog_save_filename_hook = save_filename_hook; + return file; +} } - -pqNativeFileDialogEventTranslator::pqNativeFileDialogEventTranslator(pqTestUtility* util, QObject* p) - : pqWidgetEventTranslator(p), mUtil(util) +pqNativeFileDialogEventTranslator::pqNativeFileDialogEventTranslator( + pqTestUtility* util, QObject* p) + : pqWidgetEventTranslator(p) + , mUtil(util) { - QObject::connect(mUtil->eventTranslator(), SIGNAL(started()), this, SLOT(start())); - QObject::connect(mUtil->eventTranslator(), SIGNAL(stopped()), this, SLOT(stop())); + QObject::connect(mUtil->eventTranslator(), SIGNAL(started()), this, SLOT(start())); + QObject::connect(mUtil->eventTranslator(), SIGNAL(stopped()), this, SLOT(stop())); } pqNativeFileDialogEventTranslator::~pqNativeFileDialogEventTranslator() @@ -128,65 +131,66 @@ pqNativeFileDialogEventTranslator::~pqNativeFileDialogEventTranslator() void pqNativeFileDialogEventTranslator::start() { - self = this; - - old_existing_directory_hook = qt_filedialog_existing_directory_hook; - qt_filedialog_existing_directory_hook = existing_directory_hook; + self = this; - old_open_filename_hook = qt_filedialog_open_filename_hook; - qt_filedialog_open_filename_hook = open_filename_hook; + old_existing_directory_hook = qt_filedialog_existing_directory_hook; + qt_filedialog_existing_directory_hook = existing_directory_hook; - old_open_filenames_hook = qt_filedialog_open_filenames_hook; - qt_filedialog_open_filenames_hook = open_filenames_hook; + old_open_filename_hook = qt_filedialog_open_filename_hook; + qt_filedialog_open_filename_hook = open_filename_hook; - old_save_filename_hook = qt_filedialog_save_filename_hook; - qt_filedialog_save_filename_hook = save_filename_hook; + old_open_filenames_hook = qt_filedialog_open_filenames_hook; + qt_filedialog_open_filenames_hook = open_filenames_hook; + old_save_filename_hook = qt_filedialog_save_filename_hook; + qt_filedialog_save_filename_hook = save_filename_hook; } void pqNativeFileDialogEventTranslator::stop() { - self = NULL; + self = NULL; - qt_filedialog_existing_directory_hook = old_existing_directory_hook; - qt_filedialog_open_filename_hook = old_open_filename_hook; - qt_filedialog_open_filenames_hook = old_open_filenames_hook; - qt_filedialog_save_filename_hook = old_save_filename_hook; + qt_filedialog_existing_directory_hook = old_existing_directory_hook; + qt_filedialog_open_filename_hook = old_open_filename_hook; + qt_filedialog_open_filenames_hook = old_open_filenames_hook; + qt_filedialog_save_filename_hook = old_save_filename_hook; } -bool pqNativeFileDialogEventTranslator::translateEvent(QObject* Object, QEvent* pqNotUsed(Event), - bool& pqNotUsed(Error)) +bool pqNativeFileDialogEventTranslator::translateEvent( + QObject* Object, QEvent* pqNotUsed(Event), bool& pqNotUsed(Error)) { - // capture events under a filedialog and consume them - QObject* tmp = Object; - while(tmp) + // capture events under a filedialog and consume them + QObject* tmp = Object; + while (tmp) + { + if (qobject_cast<QFileDialog*>(tmp)) { - if(qobject_cast<QFileDialog*>(tmp)) - { - return true; - } - tmp = tmp->parent(); + return true; } + tmp = tmp->parent(); + } - return false; + return false; } void pqNativeFileDialogEventTranslator::record(const QString& command, const QString& args) { - QStringList files = args.split(";"); - QStringList normalized_files; + QStringList files = args.split(";"); + QStringList normalized_files; - foreach(QString file, files) - { - normalized_files.append(mUtil->convertToDataDirectory(file)); - } + foreach (QString file, files) + { + normalized_files.append(mUtil->convertToDataDirectory(file)); + } - emit this->recordEvent(QApplication::instance(), command, normalized_files.join(";")); + emit this->recordEvent(QApplication::instance(), command, normalized_files.join(";")); } #else pqNativeFileDialogEventTranslator::pqNativeFileDialogEventTranslator( - pqTestUtility* util, QObject* p) : pqWidgetEventTranslator(p), mUtil(util) + pqTestUtility* util, QObject* p) + : pqWidgetEventTranslator(p) + , mUtil(util) { } pqNativeFileDialogEventTranslator::~pqNativeFileDialogEventTranslator() @@ -204,7 +208,7 @@ void pqNativeFileDialogEventTranslator::stop() bool pqNativeFileDialogEventTranslator::translateEvent( QObject* pqNotUsed(Object), QEvent* pqNotUsed(Event), bool& pqNotUsed(Error)) { - return false; + return false; } void pqNativeFileDialogEventTranslator::record(const QString& command, const QString& args) diff --git a/pqNativeFileDialogEventTranslator.h b/pqNativeFileDialogEventTranslator.h index e938791..a905de9 100644 --- a/pqNativeFileDialogEventTranslator.h +++ b/pqNativeFileDialogEventTranslator.h @@ -44,14 +44,13 @@ Records usage of native file dialogs in test cases. \sa pqEventTranslator */ -class QTTESTING_EXPORT pqNativeFileDialogEventTranslator : - public pqWidgetEventTranslator +class QTTESTING_EXPORT pqNativeFileDialogEventTranslator : public pqWidgetEventTranslator { Q_OBJECT typedef pqWidgetEventTranslator Superclass; public: - pqNativeFileDialogEventTranslator(pqTestUtility* util, QObject* p=0); + pqNativeFileDialogEventTranslator(pqTestUtility* util, QObject* p = 0); ~pqNativeFileDialogEventTranslator() override; using Superclass::translateEvent; @@ -64,7 +63,6 @@ protected slots: void stop(); protected: - pqTestUtility* mUtil; private: diff --git a/pqObjectNaming.cxx b/pqObjectNaming.cxx index 98eb55d..ad75ec5 100644 --- a/pqObjectNaming.cxx +++ b/pqObjectNaming.cxx @@ -7,7 +7,7 @@ All rights reserved. ParaView is a free software; you can redistribute it and/or modify it - under the terms of the ParaView license version 1.2. + under the terms of the ParaView license version 1.2. See License_v1.2.txt for the full ParaView license. A copy of this license can be obtained by contacting @@ -51,14 +51,14 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include <QStackedWidget> #include <QTabBar> #include <QTabWidget> -#include <QtDebug> #include <QTextStream> #include <QToolBar> #include <QToolButton> +#include <QtDebug> namespace { - QString ErrorMessage; +QString ErrorMessage; } /** Returns the name of an object as if it was unnamed.*/ @@ -67,63 +67,61 @@ static const QString InternalGetNameAsUnnamed(QObject& Object) QString result; QObjectList siblings; - if(Object.parent()) - { + if (Object.parent()) + { siblings = Object.parent()->children(); - } + } else - { + { QWidgetList widgets = QApplication::topLevelWidgets(); - for(int i = 0; i != widgets.size(); ++i) - { + for (int i = 0; i != widgets.size(); ++i) + { siblings.push_back(widgets[i]); - } } - + } + const QString type = Object.metaObject()->className(); - + // order of top level widgets is not guarenteed - // we can someone counter that by checking visibility, + // we can someone counter that by checking visibility, // as we usually only test visible widgets, we would get the right one int invisible_index = 0; int visible_index = 0; - for(int i = 0; i != siblings.size(); ++i) - { + for (int i = 0; i != siblings.size(); ++i) + { QObject* test = siblings[i]; - if(test == &Object) - { + if (test == &Object) + { break; - } - else if( - type == test->metaObject()->className() - && test->objectName().isEmpty()) - { + } + else if (type == test->metaObject()->className() && test->objectName().isEmpty()) + { QWidget* widget = qobject_cast<QWidget*>(test); - if(widget && widget->isVisible()) - { + if (widget && widget->isVisible()) + { ++visible_index; - } + } else - { + { ++invisible_index; - } } } - + } + int index = invisible_index; - if(QWidget* const widget = qobject_cast<QWidget*>(&Object)) + if (QWidget* const widget = qobject_cast<QWidget*>(&Object)) + { + if (widget->isVisible()) { - if(widget->isVisible()) - { result += QString::number(1); index = visible_index; - } + } else - { + { result += QString::number(0); - } } - + } + result += type + QString::number(index); result.replace("/", "|"); @@ -137,48 +135,48 @@ static const QString InternalGetName(QObject& Object) { QString result = Object.objectName(); - if(result.isEmpty()) - { + if (result.isEmpty()) + { result = InternalGetNameAsUnnamed(Object); - } + } - if(qobject_cast<QApplication*>(&Object)) + if (qobject_cast<QApplication*>(&Object)) { - result.append("-app"); + result.append("-app"); } result.replace("/", "|"); return result; } - const QString pqObjectNaming::GetName(QObject& Object) { QString name = InternalGetName(Object); - if(name.isEmpty()) - { + if (name.isEmpty()) + { qCritical() << "Cannot record event for unnamed object " << &Object; return QString(); - } - - for(QObject* p = Object.parent(); p; p = p->parent()) - { + } + + for (QObject* p = Object.parent(); p; p = p->parent()) + { const QString parent_name = InternalGetName(*p); - - if(parent_name.isEmpty()) - { - qCritical() << "Cannot record event for incompletely-named object " << name << " " << &Object << " with parent " << p; + + if (parent_name.isEmpty()) + { + qCritical() << "Cannot record event for incompletely-named object " << name << " " << &Object + << " with parent " << p; return QString(); - } - + } + name = parent_name + "/" + name; - - if(!p->parent() && !QApplication::topLevelWidgets().contains(qobject_cast<QWidget*>(p))) - { + + if (!p->parent() && !QApplication::topLevelWidgets().contains(qobject_cast<QWidget*>(p))) + { qCritical() << "Object " << p << " is not a top-level widget"; return QString(); - } } + } return name; } @@ -187,134 +185,132 @@ QObject* pqObjectNaming::GetObject(const QString& Name) { QObject* result = 0; QObject* lastObject = 0; - if(Name.isEmpty()) - { + if (Name.isEmpty()) + { return 0; - } + } const QStringList names = Name.split("/"); // see if QApplication is the requested object QString app_name = InternalGetName(*QApplication::instance()); - if( app_name == Name) + if (app_name == Name) { - return QApplication::instance(); + return QApplication::instance(); } const QWidgetList top_level_widgets = QApplication::topLevelWidgets(); - for(int i = 0; i != top_level_widgets.size(); ++i) - { + for (int i = 0; i != top_level_widgets.size(); ++i) + { QObject* object = top_level_widgets[i]; const QString name = InternalGetName(*object); const QString alt_name = InternalGetNameAsUnnamed(*object); - - if(name == names[0] || alt_name == names[0]) - { + + if (name == names[0] || alt_name == names[0]) + { result = object; lastObject = object; break; - } } - - for(int j = 1; j < names.size(); ++j) - { + } + + for (int j = 1; j < names.size(); ++j) + { const QObjectList& children = result ? result->children() : QObjectList(); - + result = 0; QString objectName = names[j]; - for(int k = 0; k != children.size(); ++k) - { + for (int k = 0; k != children.size(); ++k) + { QObject* child = children[k]; const QString name = InternalGetName(*child); const QString alt_name = InternalGetNameAsUnnamed(*child); - if(name == objectName || alt_name == objectName) - { + if (name == objectName || alt_name == objectName) + { result = child; lastObject = child; break; - } + } // Sometimes, when playing, widget are visible when they were not during recording, // try again with visibility at 1. - if (k == children.size() - 1 && - result == 0 && - !objectName.isEmpty() && - objectName[0] == '0') - { + if (k == children.size() - 1 && result == 0 && !objectName.isEmpty() && objectName[0] == '0') + { objectName[0] = '1'; k = 0; - } } } - - if(result) + } + + if (result) return result; ErrorMessage.clear(); QTextStream stream(&ErrorMessage); - stream << "Couldn't find object `"<< Name << "`\n"; + stream << "Couldn't find object `" << Name << "`\n"; if (lastObject) - { + { stream << "Found up to `" << pqObjectNaming::GetName(*lastObject) << "`\n"; - } + } // controls how many matches to dump in error message. QString matchLimitEnv = QString::fromLocal8Bit(qgetenv("PQOBJECTNAMING_MATCH_LIMIT")); const int matchLimit = matchLimitEnv.isEmpty() ? 20 : matchLimitEnv.toInt(); bool foundMatch = false; - if(lastObject) + if (lastObject) + { + const QObjectList matches = lastObject->findChildren<QObject*>(names[names.size() - 1]); + for (int cc = 0; (matchLimit <= 0 || cc < matchLimit) && cc < matches.size(); ++cc) { - const QObjectList matches = lastObject->findChildren<QObject*>(names[names.size()-1]); - for (int cc=0; (matchLimit <= 0 || cc < matchLimit) && cc < matches.size(); ++cc) - { stream << "\tPossible match: `" << pqObjectNaming::GetName(*matches[cc]) << "`\n"; - } + } if (matchLimit > 0 && matches.size() > matchLimit) - { + { stream << "\tPossible match: .... (and " << (matches.size() - matchLimit) << " more!)\n" - << "\tSet PQOBJECTNAMING_MATCH_LIMIT environment var to a +'ve number to limit entries (or 0 for unlimited).\n"; - } + << "\tSet PQOBJECTNAMING_MATCH_LIMIT environment var to a +'ve number to limit " + "entries (or 0 for unlimited).\n"; } + } if (!foundMatch) - { + { const QObjectList matches = lastObject->findChildren<QObject*>(); - for (int cc=0; (matchLimit <= 0 || cc < matchLimit) && cc < matches.size(); ++cc) - { + for (int cc = 0; (matchLimit <= 0 || cc < matchLimit) && cc < matches.size(); ++cc) + { stream << "\tAvailable widget: `" << pqObjectNaming::GetName(*matches[cc]) << "`\n"; - } + } if (matchLimit > 0 && matches.size() > matchLimit) - { + { stream << "\tAvailable widget: .... (and " << (matches.size() - matchLimit) << " more!)\n" - << "\tSet PQOBJECTNAMING_MATCH_LIMIT environment var to a +'ve number to limit entries (or 0 for unlimited).\n"; - } + << "\tSet PQOBJECTNAMING_MATCH_LIMIT environment var to a +'ve number to limit " + "entries (or 0 for unlimited).\n"; } + } return 0; } void pqObjectNaming::DumpHierarchy(QStringList& results) { const QWidgetList widgets = QApplication::topLevelWidgets(); - for(int i = 0; i != widgets.size(); ++i) - { + for (int i = 0; i != widgets.size(); ++i) + { DumpHierarchy(*widgets[i], results); - } + } } void pqObjectNaming::DumpHierarchy(QObject& object, QStringList& results) { results << GetName(object); - + const QObjectList children = object.children(); - for(int i = 0; i != children.size(); ++i) - { + for (int i = 0; i != children.size(); ++i) + { DumpHierarchy(*children[i], results); - } + } } QString pqObjectNaming::lastErrorMessage() { return ErrorMessage; } - diff --git a/pqObjectNaming.h b/pqObjectNaming.h index c02db4b..d31b28d 100644 --- a/pqObjectNaming.h +++ b/pqObjectNaming.h @@ -7,7 +7,7 @@ All rights reserved. ParaView is a free software; you can redistribute it and/or modify it - under the terms of the ParaView license version 1.2. + under the terms of the ParaView license version 1.2. See License_v1.2.txt for the full ParaView license. A copy of this license can be obtained by contacting @@ -40,15 +40,17 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. class QObject; class QStringList; -/// Provides functionality to ensuring that Qt objects can be uniquely identified for recording and playback of regression tests +/// Provides functionality to ensuring that Qt objects can be uniquely identified for recording and +/// playback of regression tests class QTTESTING_EXPORT pqObjectNaming { public: - /// Returns a unique identifier for the given object that can be serialized for later regression test playback + /// Returns a unique identifier for the given object that can be serialized for later regression + /// test playback static const QString GetName(QObject& Object); /// Given a unique identifier returned by GetName(), returns the corresponding object, or NULL static QObject* GetObject(const QString& Name); - + /** Dumps the widget hierarchy to a string */ static void DumpHierarchy(QStringList& results); /** Dumps a subtree of the widget hierarchy to a string */ diff --git a/pqPlayBackEventsDialog.cxx b/pqPlayBackEventsDialog.cxx index a09e09f..4bd569c 100644 --- a/pqPlayBackEventsDialog.cxx +++ b/pqPlayBackEventsDialog.cxx @@ -7,7 +7,7 @@ All rights reserved. ParaView is a free software; you can redistribute it and/or modify it - under the terms of the ParaView license version 1.2. + under the terms of the ParaView license version 1.2. See License_v1.2.txt for the full ParaView license. A copy of this license can be obtained by contacting @@ -30,10 +30,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. =========================================================================*/ +#include "pqPlayBackEventsDialog.h" #include "pqCommentEventPlayer.h" #include "pqEventDispatcher.h" #include "pqEventPlayer.h" -#include "pqPlayBackEventsDialog.h" #include "pqTestUtility.h" #include "ui_pqPlayBackEventsDialog.h" @@ -43,10 +43,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include <QFileDialog> #include <QMessageBox> #include <QMoveEvent> -#include <QTableWidget> #include <QProgressBar> #include <QPushButton> #include <QStringListModel> +#include <QTableWidget> #include <QTextStream> #include <QTimer> @@ -58,9 +58,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. struct pqPlayBackEventsDialog::pqImplementation { public: - pqImplementation(pqEventPlayer& player, - pqEventDispatcher& dispatcher, - pqTestUtility* testUtility); + pqImplementation( + pqEventPlayer& player, pqEventDispatcher& dispatcher, pqTestUtility* testUtility); ~pqImplementation(); void init(pqPlayBackEventsDialog* dialog); void setProgressBarsValue(int value); @@ -69,22 +68,21 @@ public: Ui::pqPlayBackEventsDialog Ui; - pqEventPlayer& Player; - pqEventDispatcher& Dispatcher; - pqTestUtility* TestUtility; + pqEventPlayer& Player; + pqEventDispatcher& Dispatcher; + pqTestUtility* TestUtility; - int CurrentLine; // Add counter to the Dispatcher - int MaxLines; - int CurrentFile; - QStringList Filenames; - QStringList CurrentEvent; - QRect OldRect; + int CurrentLine; // Add counter to the Dispatcher + int MaxLines; + int CurrentFile; + QStringList Filenames; + QStringList CurrentEvent; + QRect OldRect; }; // ---------------------------------------------------------------------------- -pqPlayBackEventsDialog::pqImplementation::pqImplementation(pqEventPlayer& player, - pqEventDispatcher& dispatcher, - pqTestUtility* testUtility) +pqPlayBackEventsDialog::pqImplementation::pqImplementation( + pqEventPlayer& player, pqEventDispatcher& dispatcher, pqTestUtility* testUtility) : Player(player) , Dispatcher(dispatcher) , TestUtility(testUtility) @@ -106,8 +104,7 @@ void pqPlayBackEventsDialog::pqImplementation::init(pqPlayBackEventsDialog* dial { this->Ui.setupUi(dialog); - this->Ui.loadFileButton->setIcon( - QApplication::style()->standardIcon(QStyle::SP_DirOpenIcon)); + this->Ui.loadFileButton->setIcon(QApplication::style()->standardIcon(QStyle::SP_DirOpenIcon)); this->Ui.playerErrorTextLabel->setVisible(false); this->Ui.playerErrorIconLabel->setVisible(false); @@ -116,68 +113,56 @@ void pqPlayBackEventsDialog::pqImplementation::init(pqPlayBackEventsDialog* dial this->Ui.logBrowser->setVisible(false); pqWidgetEventPlayer* widgetPlayer = - this->Player.getWidgetEventPlayer(QString("pqCommentEventPlayer")); - pqCommentEventPlayer* commentPlayer = - qobject_cast<pqCommentEventPlayer*>(widgetPlayer); + this->Player.getWidgetEventPlayer(QString("pqCommentEventPlayer")); + pqCommentEventPlayer* commentPlayer = qobject_cast<pqCommentEventPlayer*>(widgetPlayer); if (commentPlayer) - { - QObject::connect(commentPlayer, SIGNAL(comment(QString)), - this->Ui.logBrowser, SLOT(append(QString))); - } + { + QObject::connect( + commentPlayer, SIGNAL(comment(QString)), this->Ui.logBrowser, SLOT(append(QString))); + } dialog->setMaximumHeight(dialog->minimumSizeHint().height()); - QObject::connect(&this->Player, SIGNAL(eventAboutToBePlayed(QString, QString, QString)), - dialog, SLOT(onEventAboutToBePlayed(QString, QString, QString))); - - QObject::connect(this->Ui.timeStepSpinBox, SIGNAL(valueChanged(int)), - &this->Dispatcher, SLOT(setTimeStep(int))); - - QObject::connect(this->Ui.loadFileButton, SIGNAL(clicked()), - dialog, SLOT(loadFiles())); - QObject::connect(this->Ui.plusButton, SIGNAL(clicked()), - dialog, SLOT(insertFiles())); - QObject::connect(this->Ui.minusButton, SIGNAL(clicked()), - dialog, SLOT(removeFiles())); - - QObject::connect(this->Ui.playPauseButton, SIGNAL(toggled(bool)), - dialog, SLOT(onPlayOrPause(bool))); - QObject::connect(this->Ui.playPauseButton, SIGNAL(toggled(bool)), - &this->Dispatcher, SLOT(run(bool))); - QObject::connect(this->Ui.stopButton, SIGNAL(clicked()), - this->TestUtility, SLOT(stopTests())); - QObject::connect(this->Ui.stepButton, SIGNAL(clicked()), - dialog, SLOT(onOneStep())); - - QObject::connect(this->TestUtility, SIGNAL(playbackStarted(QString)), - dialog, SLOT(onStarted(QString))); - - QObject::connect(this->TestUtility, SIGNAL(playbackStarted()), - dialog, SLOT(onStarted())); - QObject::connect(this->TestUtility, SIGNAL(playbackStopped()), - dialog, SLOT(onStopped())); - QObject::connect(&this->Dispatcher, SIGNAL(paused()), - dialog, SLOT(updateUi())); - QObject::connect(&this->Dispatcher, SIGNAL(restarted()), - dialog, SLOT(updateUi())); - - QObject::connect(&this->Player, SIGNAL(errorMessage(QString)), - this->Ui.logBrowser, SLOT(append(QString))); + QObject::connect(&this->Player, SIGNAL(eventAboutToBePlayed(QString, QString, QString)), dialog, + SLOT(onEventAboutToBePlayed(QString, QString, QString))); + QObject::connect( + this->Ui.timeStepSpinBox, SIGNAL(valueChanged(int)), &this->Dispatcher, SLOT(setTimeStep(int))); + + QObject::connect(this->Ui.loadFileButton, SIGNAL(clicked()), dialog, SLOT(loadFiles())); + QObject::connect(this->Ui.plusButton, SIGNAL(clicked()), dialog, SLOT(insertFiles())); + QObject::connect(this->Ui.minusButton, SIGNAL(clicked()), dialog, SLOT(removeFiles())); + + QObject::connect( + this->Ui.playPauseButton, SIGNAL(toggled(bool)), dialog, SLOT(onPlayOrPause(bool))); + QObject::connect( + this->Ui.playPauseButton, SIGNAL(toggled(bool)), &this->Dispatcher, SLOT(run(bool))); + QObject::connect(this->Ui.stopButton, SIGNAL(clicked()), this->TestUtility, SLOT(stopTests())); + QObject::connect(this->Ui.stepButton, SIGNAL(clicked()), dialog, SLOT(onOneStep())); + + QObject::connect( + this->TestUtility, SIGNAL(playbackStarted(QString)), dialog, SLOT(onStarted(QString))); + + QObject::connect(this->TestUtility, SIGNAL(playbackStarted()), dialog, SLOT(onStarted())); + QObject::connect(this->TestUtility, SIGNAL(playbackStopped()), dialog, SLOT(onStopped())); + QObject::connect(&this->Dispatcher, SIGNAL(paused()), dialog, SLOT(updateUi())); + QObject::connect(&this->Dispatcher, SIGNAL(restarted()), dialog, SLOT(updateUi())); + + QObject::connect( + &this->Player, SIGNAL(errorMessage(QString)), this->Ui.logBrowser, SLOT(append(QString))); } // ---------------------------------------------------------------------------- void pqPlayBackEventsDialog::pqImplementation::setProgressBarsValue(int value) { - for(int i = 0; i < this->Ui.tableWidget->rowCount(); ++i) - { + for (int i = 0; i < this->Ui.tableWidget->rowCount(); ++i) + { this->setProgressBarValue(i, value); - } + } } // ---------------------------------------------------------------------------- -void pqPlayBackEventsDialog::pqImplementation::setProgressBarValue(int row, - int value) +void pqPlayBackEventsDialog::pqImplementation::setProgressBarValue(int row, int value) { QWidget* widget = this->Ui.tableWidget->cellWidget(row, 2); QProgressBar* progressBar = qobject_cast<QProgressBar*>(widget); @@ -185,13 +170,12 @@ void pqPlayBackEventsDialog::pqImplementation::setProgressBarValue(int row, } // ---------------------------------------------------------------------------- -QString pqPlayBackEventsDialog::pqImplementation::setMaxLenght(const QString& name, - int max) +QString pqPlayBackEventsDialog::pqImplementation::setMaxLenght(const QString& name, int max) { - if(name.length() > max) - { - return name.left(max/2) + "..." + name.right(max/2); - } + if (name.length() > max) + { + return name.left(max / 2) + "..." + name.right(max / 2); + } return name; } @@ -199,10 +183,8 @@ QString pqPlayBackEventsDialog::pqImplementation::setMaxLenght(const QString& na // pqPlayBackEventsDialog // ---------------------------------------------------------------------------- -pqPlayBackEventsDialog::pqPlayBackEventsDialog(pqEventPlayer& Player, - pqEventDispatcher& Dispatcher, - pqTestUtility* TestUtility, - QWidget* Parent) +pqPlayBackEventsDialog::pqPlayBackEventsDialog( + pqEventPlayer& Player, pqEventDispatcher& Dispatcher, pqTestUtility* TestUtility, QWidget* Parent) : QDialog(Parent) , Implementation(new pqImplementation(Player, Dispatcher, TestUtility)) { @@ -228,22 +210,21 @@ void pqPlayBackEventsDialog::done(int value) QStringList pqPlayBackEventsDialog::selectedFileNames() const { QStringList list; - for(int i = 0; i < this->Implementation->Ui.tableWidget->rowCount(); ++i) - { - QCheckBox* box = qobject_cast<QCheckBox*>( - this->Implementation->Ui.tableWidget->cellWidget(i, 0)); + for (int i = 0; i < this->Implementation->Ui.tableWidget->rowCount(); ++i) + { + QCheckBox* box = + qobject_cast<QCheckBox*>(this->Implementation->Ui.tableWidget->cellWidget(i, 0)); if (box->isChecked()) - { + { list << this->Implementation->Filenames[i]; - } } + } return list; } // ---------------------------------------------------------------------------- -void pqPlayBackEventsDialog::onEventAboutToBePlayed(const QString& Object, - const QString& Command, - const QString& Arguments) +void pqPlayBackEventsDialog::onEventAboutToBePlayed( + const QString& Object, const QString& Command, const QString& Arguments) { ++this->Implementation->CurrentLine; QStringList newEvent; @@ -255,29 +236,27 @@ void pqPlayBackEventsDialog::onEventAboutToBePlayed(const QString& Object, // ---------------------------------------------------------------------------- void pqPlayBackEventsDialog::loadFiles() { - QFileDialog* dialog = new QFileDialog(this, "Macro File Name", - QString(), "XML Files (*.xml)"); + QFileDialog* dialog = new QFileDialog(this, "Macro File Name", QString(), "XML Files (*.xml)"); dialog->setFileMode(QFileDialog::ExistingFiles); if (dialog->exec()) - { + { this->Implementation->Filenames = dialog->selectedFiles(); this->Implementation->Ui.tableWidget->setRowCount(0); this->loadFiles(this->Implementation->Filenames); - } + } delete dialog; } // ---------------------------------------------------------------------------- void pqPlayBackEventsDialog::insertFiles() { - QFileDialog* dialog = new QFileDialog(this, "Macro File Name", - QString(), "XML Files (*.xml)"); + QFileDialog* dialog = new QFileDialog(this, "Macro File Name", QString(), "XML Files (*.xml)"); dialog->setFileMode(QFileDialog::ExistingFiles); if (dialog->exec()) - { + { this->Implementation->Filenames << dialog->selectedFiles(); this->loadFiles(dialog->selectedFiles()); - } + } delete dialog; } @@ -285,28 +264,27 @@ void pqPlayBackEventsDialog::insertFiles() void pqPlayBackEventsDialog::removeFiles() { if (QMessageBox::Ok == QMessageBox::warning(this, QString("Remove files"), - QString("Are you sure you want to \n" - "remove all checked files ?\n"), - QMessageBox::Ok, - QMessageBox::Cancel)) + QString("Are you sure you want to \n" + "remove all checked files ?\n"), + QMessageBox::Ok, QMessageBox::Cancel)) + { + foreach (QString file, this->selectedFileNames()) { - foreach(QString file, this->selectedFileNames()) - { int index = this->Implementation->Filenames.indexOf(file); this->Implementation->Ui.tableWidget->removeRow(index); this->Implementation->Filenames.removeAt(index); - } - this->updateUi(); } + this->updateUi(); + } } // ---------------------------------------------------------------------------- void pqPlayBackEventsDialog::loadFiles(const QStringList& filenames) { - for(int i = 0 ; i < filenames.count() ; i++) - { + for (int i = 0; i < filenames.count(); i++) + { this->addFile(filenames[i]); - } + } this->Implementation->Ui.tableWidget->resizeColumnToContents(0); } @@ -316,10 +294,9 @@ void pqPlayBackEventsDialog::addFile(const QString& filename) QFileInfo info(filename); int newIndex = this->Implementation->Ui.tableWidget->rowCount(); this->Implementation->Ui.tableWidget->insertRow(newIndex); - this->Implementation->Ui.tableWidget->setItem( - newIndex, 1, new QTableWidgetItem(info.fileName())); + this->Implementation->Ui.tableWidget->setItem(newIndex, 1, new QTableWidgetItem(info.fileName())); this->Implementation->Ui.tableWidget->setCellWidget( - newIndex, 2, new QProgressBar(this->Implementation->Ui.tableWidget)); + newIndex, 2, new QProgressBar(this->Implementation->Ui.tableWidget)); this->Implementation->setProgressBarValue(newIndex, 0); QCheckBox* check = new QCheckBox(this->Implementation->Ui.tableWidget); check->setChecked(true); @@ -331,11 +308,10 @@ void pqPlayBackEventsDialog::addFile(const QString& filename) // ---------------------------------------------------------------------------- void pqPlayBackEventsDialog::onPlayOrPause(bool playOrPause) { - if (this->Implementation->TestUtility->playingTest() || - !playOrPause) - { + if (this->Implementation->TestUtility->playingTest() || !playOrPause) + { return; - } + } QStringList newList = this->selectedFileNames(); this->Implementation->TestUtility->playTests(newList); @@ -346,26 +322,24 @@ void pqPlayBackEventsDialog::onOneStep() { this->Implementation->Ui.playPauseButton->setChecked(false); if (!this->Implementation->TestUtility->playingTest()) - { + { this->Implementation->Dispatcher.run(false); this->Implementation->Dispatcher.oneStep(); QStringList newList = this->selectedFileNames(); this->Implementation->TestUtility->playTests(newList); - } + } else - { + { this->Implementation->Dispatcher.oneStep(); - } + } } // ---------------------------------------------------------------------------- void pqPlayBackEventsDialog::onStarted(const QString& filename) { - this->Implementation->CurrentFile = - this->Implementation->Filenames.indexOf(filename); - this->Implementation->Ui.tableWidget->setCurrentCell( - this->Implementation->CurrentFile, 1, - QItemSelectionModel::Rows | QItemSelectionModel::SelectCurrent); + this->Implementation->CurrentFile = this->Implementation->Filenames.indexOf(filename); + this->Implementation->Ui.tableWidget->setCurrentCell(this->Implementation->CurrentFile, 1, + QItemSelectionModel::Rows | QItemSelectionModel::SelectCurrent); this->Implementation->Ui.logBrowser->clear(); this->Implementation->MaxLines = 0; @@ -374,19 +348,18 @@ void pqPlayBackEventsDialog::onStarted(const QString& filename) QFile file(filename); QFileInfo infoFile(file); file.open(QIODevice::ReadOnly); - this->Implementation->Ui.logBrowser->append(QString("Start file : %1").arg( - infoFile.fileName())); + this->Implementation->Ui.logBrowser->append(QString("Start file : %1").arg(infoFile.fileName())); QTextStream stream(&file); stream.setCodec("UTF-8"); this->Implementation->Ui.currentFileLabel->setText(infoFile.fileName()); - while(!stream.atEnd()) - { + while (!stream.atEnd()) + { QString line = stream.readLine(); - if(line.trimmed().startsWith("<event")) - { + if (line.trimmed().startsWith("<event")) + { ++this->Implementation->MaxLines; - } } + } } // ---------------------------------------------------------------------------- @@ -408,66 +381,58 @@ void pqPlayBackEventsDialog::updateUi() { // Update Moda/Modeless this->onModal(this->Implementation->TestUtility->playingTest() && - !(this->Implementation->TestUtility->playingTest() && + !(this->Implementation->TestUtility->playingTest() && this->Implementation->Dispatcher.isPaused())); // Update player buttons this->Implementation->Ui.playPauseButton->setChecked( - this->Implementation->TestUtility->playingTest() && - !this->Implementation->Dispatcher.isPaused()); + this->Implementation->TestUtility->playingTest() && + !this->Implementation->Dispatcher.isPaused()); this->Implementation->Ui.playPauseButton->setEnabled( - !this->Implementation->Filenames.isEmpty() && - this->selectedFileNames().count() > 0); + !this->Implementation->Filenames.isEmpty() && this->selectedFileNames().count() > 0); this->Implementation->Ui.stepButton->setEnabled( - !this->Implementation->Filenames.isEmpty() && - this->selectedFileNames().count() > 0); - this->Implementation->Ui.stopButton->setEnabled( - this->Implementation->TestUtility->playingTest()); + !this->Implementation->Filenames.isEmpty() && this->selectedFileNames().count() > 0); + this->Implementation->Ui.stopButton->setEnabled(this->Implementation->TestUtility->playingTest()); // loadFile, plus and minus buttons this->Implementation->Ui.loadFileButton->setEnabled( - !this->Implementation->TestUtility->playingTest()); + !this->Implementation->TestUtility->playingTest()); this->Implementation->Ui.plusButton->setEnabled( - !this->Implementation->TestUtility->playingTest()); + !this->Implementation->TestUtility->playingTest()); this->Implementation->Ui.minusButton->setEnabled( - !this->Implementation->TestUtility->playingTest()); + !this->Implementation->TestUtility->playingTest()); // Time step - this->Implementation->Ui.timeStepSpinBox->setEnabled( - !this->Implementation->Filenames.isEmpty()); + this->Implementation->Ui.timeStepSpinBox->setEnabled(!this->Implementation->Filenames.isEmpty()); // Error feedback this->Implementation->Ui.playerErrorTextLabel->setVisible( - !this->Implementation->Dispatcher.status()); + !this->Implementation->Dispatcher.status()); this->Implementation->Ui.playerErrorIconLabel->setVisible( - !this->Implementation->Dispatcher.status()); + !this->Implementation->Dispatcher.status()); this->Implementation->Ui.infoErrorTextLabel->setVisible( - !this->Implementation->Dispatcher.status()); + !this->Implementation->Dispatcher.status()); this->Implementation->Ui.infoErrorIconLabel->setVisible( - !this->Implementation->Dispatcher.status()); + !this->Implementation->Dispatcher.status()); QString command = tr("Command : "); QString argument = tr("Argument(s) : "); QString object = tr("Object : "); - if(this->Implementation->TestUtility->playingTest() && - !this->Implementation->CurrentEvent.isEmpty()) - { - command += this->Implementation->setMaxLenght( - this->Implementation->CurrentEvent[1], 40); - argument += this->Implementation->setMaxLenght( - this->Implementation->CurrentEvent[2], 40); - object += this->Implementation->setMaxLenght( - this->Implementation->CurrentEvent[0], 40); + if (this->Implementation->TestUtility->playingTest() && + !this->Implementation->CurrentEvent.isEmpty()) + { + command += this->Implementation->setMaxLenght(this->Implementation->CurrentEvent[1], 40); + argument += this->Implementation->setMaxLenght(this->Implementation->CurrentEvent[2], 40); + object += this->Implementation->setMaxLenght(this->Implementation->CurrentEvent[0], 40); this->Implementation->setProgressBarValue(this->Implementation->CurrentFile, - static_cast<int>((static_cast<double>( - this->Implementation->CurrentLine)/static_cast<double>( - this->Implementation->MaxLines-1))*100)); - } + static_cast<int>((static_cast<double>(this->Implementation->CurrentLine) / + static_cast<double>(this->Implementation->MaxLines - 1)) * + 100)); + } else - { - this->Implementation->Ui.currentFileLabel->setText( - QString("No Test is playing ...")); - } + { + this->Implementation->Ui.currentFileLabel->setText(QString("No Test is playing ...")); + } this->Implementation->Ui.commandLabel->setText(command); this->Implementation->Ui.argumentsLabel->setText(argument); @@ -481,31 +446,31 @@ void pqPlayBackEventsDialog::onModal(bool value) { // From modal to modeless we don't need to hide() show() the dialog if (value) - { + { this->setAttribute(Qt::WA_WState_Visible, false); this->setAttribute(Qt::WA_WState_Hidden, true); - } + } this->setModal(value); if (value) - { + { this->Implementation->OldRect = this->frameGeometry(); this->setVisible(true); this->Implementation->OldRect = QRect(); - } + } this->raise(); } // ---------------------------------------------------------------------------- void pqPlayBackEventsDialog::moveEvent(QMoveEvent* event) { - if(this->Implementation->OldRect.isValid()) - { + if (this->Implementation->OldRect.isValid()) + { QPoint oldPos = this->Implementation->OldRect.topLeft(); this->Implementation->OldRect = QRect(); this->move(oldPos); - } + } else - { + { this->Superclass::moveEvent(event); - } + } } diff --git a/pqPlayBackEventsDialog.h b/pqPlayBackEventsDialog.h index 01f287c..8e7cc9a 100644 --- a/pqPlayBackEventsDialog.h +++ b/pqPlayBackEventsDialog.h @@ -7,7 +7,7 @@ All rights reserved. ParaView is a free software; you can redistribute it and/or modify it - under the terms of the ParaView license version 1.2. + under the terms of the ParaView license version 1.2. See License_v1.2.txt for the full ParaView license. A copy of this license can be obtained by contacting @@ -40,22 +40,24 @@ class pqEventPlayer; class pqEventDispatcher; class pqTestUtility; -/// Provides a standard dialog that will PlayBack user input to an XML file as long as the dialog remains open +/// Provides a standard dialog that will PlayBack user input to an XML file as long as the dialog +/// remains open class QTTESTING_EXPORT pqPlayBackEventsDialog : public QDialog { Q_OBJECT - + typedef QDialog Superclass; + public: /** Creates the dialog and begins translating user input with the supplied translator. */ - pqPlayBackEventsDialog(pqEventPlayer& Player,pqEventDispatcher& Source, - pqTestUtility* TestUtility, QWidget* Parent); + pqPlayBackEventsDialog( + pqEventPlayer& Player, pqEventDispatcher& Source, pqTestUtility* TestUtility, QWidget* Parent); ~pqPlayBackEventsDialog() override; private slots: - void onEventAboutToBePlayed(const QString&,const QString&,const QString&); + void onEventAboutToBePlayed(const QString&, const QString&, const QString&); void loadFiles(); void insertFiles(); void removeFiles(); @@ -86,4 +88,3 @@ private: }; #endif // !_pqPlayBackEventsDialog_h - diff --git a/pqPythonEventObserver.cxx b/pqPythonEventObserver.cxx index 4176d7f..93ba5bb 100644 --- a/pqPythonEventObserver.cxx +++ b/pqPythonEventObserver.cxx @@ -49,31 +49,28 @@ pqPythonEventObserver::~pqPythonEventObserver() void pqPythonEventObserver::setStream(QTextStream* stream) { pqEventObserver::setStream(stream); - if(this->Stream) - { + if (this->Stream) + { *this->Stream << "#/usr/bin/env python\n\n"; *this->Stream << "import QtTesting\n\n"; - } + } } void pqPythonEventObserver::onRecordEvent( - const QString& Widget, - const QString& Command, - const QString& Arguments, - const int& eventType) + const QString& Widget, const QString& Command, const QString& Arguments, const int& eventType) { - if(this->Stream) - { + if (this->Stream) + { QString varname = this->Names[Widget]; - if(varname == QString::null) - { + if (varname == QString::null) + { varname = QString("object%1").arg(this->Names.count()); this->Names.insert(Widget, varname); QString objname("%1 = '%2'"); objname = objname.arg(varname); objname = objname.arg(Widget); *this->Stream << objname << "\n"; - } + } QString pycommand("QtTesting.playCommand(%1, '%2', '%3', '%4')"); pycommand = pycommand.arg(varname); @@ -83,5 +80,5 @@ void pqPythonEventObserver::onRecordEvent( *this->Stream << pycommand << "\n"; emit eventRecorded(widget, command, arguments, eventType); - } + } } diff --git a/pqPythonEventObserver.h b/pqPythonEventObserver.h index b0f0283..5bf445a 100644 --- a/pqPythonEventObserver.h +++ b/pqPythonEventObserver.h @@ -7,7 +7,7 @@ All rights reserved. ParaView is a free software; you can redistribute it and/or modify it - under the terms of the ParaView license version 1.2. + under the terms of the ParaView license version 1.2. See License_v1.2.txt for the full ParaView license. A copy of this license can be obtained by contacting @@ -52,16 +52,13 @@ must ensure that it goes out of scope before trying to playback the stream. class QTTESTING_EXPORT pqPythonEventObserver : public pqEventObserver { Q_OBJECT - + public: - pqPythonEventObserver(QObject* p=0); + pqPythonEventObserver(QObject* p = 0); ~pqPythonEventObserver(); void onRecordEvent( - const QString& Widget, - const QString& Command, - const QString& Arguments, - const int& eventType); + const QString& Widget, const QString& Command, const QString& Arguments, const int& eventType); void setStream(QTextStream*); @@ -71,4 +68,3 @@ private: }; #endif // !_pqPythonEventObserver_h - diff --git a/pqPythonEventSource.cxx b/pqPythonEventSource.cxx index c88305f..b654b6a 100644 --- a/pqPythonEventSource.cxx +++ b/pqPythonEventSource.cxx @@ -7,7 +7,7 @@ All rights reserved. ParaView is a free software; you can redistribute it and/or modify it - under the terms of the ParaView license version 1.2. + under the terms of the ParaView license version 1.2. See License_v1.2.txt for the full ParaView license. A copy of this license can be obtained by contacting @@ -42,18 +42,16 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifdef _DEBUG -# undef _DEBUG -# if defined(_MSC_VER) && _MSC_VER >= 1400 -# define _CRT_NOFORCE_MANIFEST 1 -# endif -# include <Python.h> -# define _DEBUG +#undef _DEBUG +#if defined(_MSC_VER) && _MSC_VER >= 1400 +#define _CRT_NOFORCE_MANIFEST 1 +#endif +#include <Python.h> +#define _DEBUG #else -# include <Python.h> +#include <Python.h> #endif - - #ifndef PyMODINIT_FUNC #define PyMODINIT_FUNC extern "C" void #endif // PyMODINIT_FUNC @@ -65,22 +63,21 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include <signal.h> // Qt include -#include <QVariant> -#include <QFile> -#include <QtDebug> +#include <QApplication> #include <QCoreApplication> #include <QEvent> -#include <QStringList> -#include <QThread> -#include <QApplication> +#include <QFile> #include <QMetaObject> #include <QMetaProperty> +#include <QStringList> +#include <QThread> +#include <QVariant> +#include <QtDebug> // Qt testing includes +#include "pqEventDispatcher.h" #include "pqObjectNaming.h" #include "pqWidgetEventPlayer.h" -#include "pqEventDispatcher.h" - // TODO not have a global instance pointer? static pqPythonEventSource* Instance = NULL; @@ -89,9 +86,7 @@ static QString PropertyResult; static QString PropertyValue; static QStringList ObjectList; - -static PyObject* -QtTesting_playCommand(PyObject* /*self*/, PyObject* args) +static PyObject* QtTesting_playCommand(PyObject* /*self*/, PyObject* args) { // this gives the main thread some time to refresh before we start sending // commands. Avoids crazy hangs in QDialog::exec() calls. @@ -99,303 +94,264 @@ QtTesting_playCommand(PyObject* /*self*/, PyObject* args) // void QtTesting.playCommand('object', 'command', 'arguments') // an exception is thrown in this fails - + const char* object = 0; const char* command = 0; const char* arguments = 0; - if(!PyArg_ParseTuple(args, const_cast<char*>("sss"), &object, &command, &arguments)) - { + if (!PyArg_ParseTuple(args, const_cast<char*>("sss"), &object, &command, &arguments)) + { PyErr_SetString(PyExc_TypeError, "bad arguments to playCommand()"); return NULL; - } + } - if(Instance) + if (Instance) + { + if (!Instance->postNextEvent(object, command, arguments)) { - if(!Instance->postNextEvent(object, command, arguments)) - { PyErr_SetString(PyExc_AssertionError, "error processing event"); return NULL; - } } + } else - { + { PyErr_SetString(PyExc_AssertionError, "pqPythonEventSource not defined"); return NULL; - } + } return Py_BuildValue(const_cast<char*>("")); } -static PyObject* -QtTesting_getProperty(PyObject* /*self*/, PyObject* args) +static PyObject* QtTesting_getProperty(PyObject* /*self*/, PyObject* args) { // string QtTesting.getProperty('object', 'property') // returns the string value of the property - + const char* object = 0; const char* property = 0; - if(!PyArg_ParseTuple(args, const_cast<char*>("ss"), &object, &property)) - { + if (!PyArg_ParseTuple(args, const_cast<char*>("ss"), &object, &property)) + { return NULL; - } + } PropertyObject = object; PropertyResult = property; PropertyValue = QString::null; - if(Instance && QThread::currentThread() != QApplication::instance()->thread()) - { + if (Instance && QThread::currentThread() != QApplication::instance()->thread()) + { QMetaObject::invokeMethod(Instance, "threadGetProperty", Qt::QueuedConnection); - if(!Instance->waitForGUI()) - { + if (!Instance->waitForGUI()) + { PyErr_SetString(PyExc_ValueError, "error getting property"); return NULL; - } } - else if(QThread::currentThread() == QApplication::instance()->thread()) - { + } + else if (QThread::currentThread() == QApplication::instance()->thread()) + { PropertyValue = pqPythonEventSource::getProperty(PropertyObject, PropertyResult); - } + } else - { + { PyErr_SetString(PyExc_AssertionError, "pqPythonEventSource not defined"); return NULL; - } + } - if(PropertyObject == QString::null) - { + if (PropertyObject == QString::null) + { PyErr_SetString(PyExc_ValueError, "object not found"); return NULL; - } - - if(PropertyResult == QString::null) - { + } + + if (PropertyResult == QString::null) + { PyErr_SetString(PyExc_ValueError, "property not found"); return NULL; - } + } - return Py_BuildValue(const_cast<char*>("s"), - PropertyValue.toLatin1().data()); + return Py_BuildValue(const_cast<char*>("s"), PropertyValue.toLatin1().data()); } -static PyObject* -QtTesting_setProperty(PyObject* /*self*/, PyObject* args) +static PyObject* QtTesting_setProperty(PyObject* /*self*/, PyObject* args) { // string QtTesting.setProperty('object', 'property', 'value') // returns the string value of the property - + const char* object = 0; const char* property = 0; const char* value = 0; - if(!PyArg_ParseTuple(args, const_cast<char*>("sss"), &object, - &property, &value)) - { + if (!PyArg_ParseTuple(args, const_cast<char*>("sss"), &object, &property, &value)) + { return NULL; - } + } PropertyObject = object; PropertyResult = property; PropertyValue = value; - if(Instance && QThread::currentThread() != QApplication::instance()->thread()) - { + if (Instance && QThread::currentThread() != QApplication::instance()->thread()) + { QMetaObject::invokeMethod(Instance, "threadSetProperty", Qt::QueuedConnection); - if(!Instance->waitForGUI()) - { + if (!Instance->waitForGUI()) + { PyErr_SetString(PyExc_ValueError, "error setting property"); return NULL; - } - } - else if(QThread::currentThread() == QApplication::instance()->thread()) - { - pqPythonEventSource::setProperty(PropertyObject, - PropertyResult, - PropertyValue); } + } + else if (QThread::currentThread() == QApplication::instance()->thread()) + { + pqPythonEventSource::setProperty(PropertyObject, PropertyResult, PropertyValue); + } else - { + { PyErr_SetString(PyExc_AssertionError, "pqPythonEventSource not defined"); return NULL; - } + } - if(PropertyObject == QString::null) - { + if (PropertyObject == QString::null) + { PyErr_SetString(PyExc_ValueError, "object not found"); return NULL; - } + } - if(PropertyResult == QString::null) - { + if (PropertyResult == QString::null) + { PyErr_SetString(PyExc_ValueError, "property not found"); return NULL; - } + } return Py_BuildValue(const_cast<char*>("s"), ""); } -static PyObject* -QtTesting_getQtVersion(PyObject* /*self*/, PyObject* /*args*/) +static PyObject* QtTesting_getQtVersion(PyObject* /*self*/, PyObject* /*args*/) { // string QtTesting.getQtVersion() // returns the Qt version as a string - + return Py_BuildValue(const_cast<char*>("s"), qVersion()); } - -static PyObject* -QtTesting_getChildren(PyObject* /*self*/, PyObject* args) +static PyObject* QtTesting_getChildren(PyObject* /*self*/, PyObject* args) { // string QtTesting.getChildren('object') // returns the a list of strings with object names - + const char* object = 0; - if(!PyArg_ParseTuple(args, const_cast<char*>("s"), &object)) - { + if (!PyArg_ParseTuple(args, const_cast<char*>("s"), &object)) + { return NULL; - } + } PropertyObject = object; ObjectList.clear(); - if(Instance && QThread::currentThread() != QApplication::instance()->thread()) - { + if (Instance && QThread::currentThread() != QApplication::instance()->thread()) + { QMetaObject::invokeMethod(Instance, "threadGetChildren", Qt::QueuedConnection); - if(!Instance->waitForGUI()) - { + if (!Instance->waitForGUI()) + { PyErr_SetString(PyExc_ValueError, "error getting children"); return NULL; - } } - else if(QThread::currentThread() == QApplication::instance()->thread()) - { + } + else if (QThread::currentThread() == QApplication::instance()->thread()) + { ObjectList = pqPythonEventSource::getChildren(PropertyObject); - } + } else - { + { PyErr_SetString(PyExc_AssertionError, "pqPythonEventSource not defined"); return NULL; - } + } - if(PropertyObject == QString::null) - { + if (PropertyObject == QString::null) + { PyErr_SetString(PyExc_ValueError, "object not found"); return NULL; - } + } QString objs = ObjectList.join(", "); QString ret = QString("[%1]").arg(objs); - return Py_BuildValue(const_cast<char*>("s"), - ret.toLatin1().data()); + return Py_BuildValue(const_cast<char*>("s"), ret.toLatin1().data()); } -static PyObject* -QtTesting_invokeMethod(PyObject* /*self*/, PyObject* args) +static PyObject* QtTesting_invokeMethod(PyObject* /*self*/, PyObject* args) { // string QtTesting.invokeMethod('object', 'method') // calls a method and returns its value - + const char* object = 0; const char* method = 0; - if(!PyArg_ParseTuple(args, const_cast<char*>("ss"), &object, &method)) - { + if (!PyArg_ParseTuple(args, const_cast<char*>("ss"), &object, &method)) + { return NULL; - } + } PropertyObject = object; PropertyValue = method; PropertyResult = QString(); - if(Instance && QThread::currentThread() != QApplication::instance()->thread()) - { + if (Instance && QThread::currentThread() != QApplication::instance()->thread()) + { QMetaObject::invokeMethod(Instance, "threadInvokeMethod", Qt::QueuedConnection); - if(!Instance->waitForGUI()) - { + if (!Instance->waitForGUI()) + { PyErr_SetString(PyExc_ValueError, "error invoking method"); return NULL; - } - } - else if(QThread::currentThread() == QApplication::instance()->thread()) - { - PropertyResult = pqPythonEventSource::invokeMethod(PropertyObject, - PropertyValue); } + } + else if (QThread::currentThread() == QApplication::instance()->thread()) + { + PropertyResult = pqPythonEventSource::invokeMethod(PropertyObject, PropertyValue); + } else - { + { PyErr_SetString(PyExc_AssertionError, "pqPythonEventSource not defined"); return NULL; - } + } - if(PropertyObject == QString::null) - { + if (PropertyObject == QString::null) + { PyErr_SetString(PyExc_ValueError, "object not found"); return NULL; - } - else if(PropertyValue == QString::null) - { + } + else if (PropertyValue == QString::null) + { PyErr_SetString(PyExc_ValueError, "method not found"); return NULL; - } + } - return Py_BuildValue(const_cast<char*>("s"), - PropertyResult.toLatin1().data()); + return Py_BuildValue(const_cast<char*>("s"), PropertyResult.toLatin1().data()); } static PyMethodDef QtTestingMethods[] = { - { - const_cast<char*>("playCommand"), - QtTesting_playCommand, - METH_VARARGS, - const_cast<char*>("Play a test command.") - }, - { - const_cast<char*>("getProperty"), - QtTesting_getProperty, - METH_VARARGS, - const_cast<char*>("Get a property of an object.") - }, - { - const_cast<char*>("setProperty"), - QtTesting_setProperty, - METH_VARARGS, - const_cast<char*>("Set a property of an object.") - }, - - { - const_cast<char*>("getQtVersion"), - QtTesting_getQtVersion, - METH_VARARGS, - const_cast<char*>("Get the version of Qt being used.") - }, - { - const_cast<char*>("getChildren"), - QtTesting_getChildren, - METH_VARARGS, - const_cast<char*>("Return a list of child objects.") - }, - { - const_cast<char*>("invokeMethod"), - QtTesting_invokeMethod, - METH_VARARGS, - const_cast<char*>("Invoke a Qt slot with the signature \"QVariant foo()\".") - }, - - {NULL, NULL, 0, NULL} // Sentinal + { const_cast<char*>("playCommand"), QtTesting_playCommand, METH_VARARGS, + const_cast<char*>("Play a test command.") }, + { const_cast<char*>("getProperty"), QtTesting_getProperty, METH_VARARGS, + const_cast<char*>("Get a property of an object.") }, + { const_cast<char*>("setProperty"), QtTesting_setProperty, METH_VARARGS, + const_cast<char*>("Set a property of an object.") }, + + { const_cast<char*>("getQtVersion"), QtTesting_getQtVersion, METH_VARARGS, + const_cast<char*>("Get the version of Qt being used.") }, + { const_cast<char*>("getChildren"), QtTesting_getChildren, METH_VARARGS, + const_cast<char*>("Return a list of child objects.") }, + { const_cast<char*>("invokeMethod"), QtTesting_invokeMethod, METH_VARARGS, + const_cast<char*>("Invoke a Qt slot with the signature \"QVariant foo()\".") }, + + { NULL, NULL, 0, NULL } // Sentinal }; -PyMODINIT_FUNC -initQtTesting(void) +PyMODINIT_FUNC initQtTesting(void) { Py_InitModule(const_cast<char*>("QtTesting"), QtTestingMethods); } - class pqPythonEventSource::pqInternal { public: @@ -416,14 +372,14 @@ pqPythonEventSource::~pqPythonEventSource() void pqPythonEventSource::initPythonIfNeeded() { int initPy = Py_IsInitialized(); - if(!initPy) - { + if (!initPy) + { // initialize python Py_Initialize(); #ifdef SIGINT signal(SIGINT, SIG_DFL); #endif - } + } // add QtTesting to python's inittab, so it is // available to all interpreters PyImport_AppendInittab(const_cast<char*>("QtTesting"), initQtTesting); @@ -435,7 +391,7 @@ void pqPythonEventSource::setContent(const QString& path) this->Internal->FileName = path; this->start(); } - + QString pqPythonEventSource::getProperty(QString& object, QString& prop) { // ensure other tasks have been completed @@ -443,70 +399,65 @@ QString pqPythonEventSource::getProperty(QString& object, QString& prop) QVariant ret; QObject* qobject = pqObjectNaming::GetObject(object); - if(!qobject) - { + if (!qobject) + { object = QString::null; return QString(); - } + } int idx = qobject->metaObject()->indexOfProperty(prop.toLatin1().data()); - if(idx == -1) - { + if (idx == -1) + { prop = QString::null; return QString(); - } + } else - { - QMetaProperty metaProp = qobject->metaObject()->property(idx); + { + QMetaProperty metaProp = qobject->metaObject()->property(idx); ret = metaProp.read(qobject); - if(metaProp.type() == QVariant::List || metaProp.type() == - QVariant::StringList) - { + if (metaProp.type() == QVariant::List || metaProp.type() == QVariant::StringList) + { return ret.toStringList().join(";"); - } - return ret.toString(); } + return ret.toString(); + } } - void pqPythonEventSource::threadGetProperty() { PropertyValue = this->getProperty(PropertyObject, PropertyResult); this->guiAcknowledge(); } - -void pqPythonEventSource::setProperty(QString& object, QString& prop, - const QString& value) +void pqPythonEventSource::setProperty(QString& object, QString& prop, const QString& value) { // ensure other tasks have been completed pqEventDispatcher::processEventsAndWait(1); QVariant ret; QObject* qobject = pqObjectNaming::GetObject(object); - if(!qobject) - { + if (!qobject) + { object = QString::null; return; - } - + } + int idx = qobject->metaObject()->indexOfProperty(prop.toLatin1().data()); - if(idx == -1) - { + if (idx == -1) + { prop = QString::null; return; - } + } else - { + { QVariant val = value; - QMetaProperty metaProp = qobject->metaObject()->property(idx); - if(metaProp.type() == QVariant::List || metaProp.type() == - QVariant::StringList) - { + QMetaProperty metaProp = qobject->metaObject()->property(idx); + if (metaProp.type() == QVariant::List || metaProp.type() == QVariant::StringList) + { val = value.split(";"); - } - qobject->setProperty(prop.toLatin1().data(), val); } + qobject->setProperty(prop.toLatin1().data(), val); + } } void pqPythonEventSource::threadSetProperty() @@ -515,7 +466,6 @@ void pqPythonEventSource::threadSetProperty() this->guiAcknowledge(); } - QStringList pqPythonEventSource::getChildren(QString& object) { // ensure other tasks have been completed @@ -523,22 +473,21 @@ QStringList pqPythonEventSource::getChildren(QString& object) QStringList ret; QObject* qobject = pqObjectNaming::GetObject(object); - if(!qobject) - { + if (!qobject) + { object = QString::null; - } + } else - { + { const QObjectList& children = qobject->children(); - foreach(QObject* child, children) - { + foreach (QObject* child, children) + { ret.append(pqObjectNaming::GetName(*child)); - } } + } return ret; } - void pqPythonEventSource::threadGetChildren() { ObjectList = this->getChildren(PropertyObject); @@ -557,11 +506,11 @@ void pqPythonEventSource::start() void pqPythonEventSource::run() { QFile file(this->Internal->FileName); - if(!file.open(QFile::ReadOnly | QFile::Text)) - { + if (!file.open(QFile::ReadOnly | QFile::Text)) + { printf("Unable to open python script\n"); return; - } + } this->initPythonIfNeeded(); Instance = this; @@ -590,18 +539,16 @@ QString pqPythonEventSource::invokeMethod(QString& object, QString& method) QVariant ret; QObject* qobject = pqObjectNaming::GetObject(object); - if(!qobject) - { + if (!qobject) + { object = QString::null; - } + } else + { + if (!QMetaObject::invokeMethod(qobject, method.toLatin1().data(), Q_RETURN_ARG(QVariant, ret))) { - if(!QMetaObject::invokeMethod(qobject, method.toLatin1().data(), - Q_RETURN_ARG(QVariant, ret))) - { method = QString::null; - } } + } return ret.toString(); } - diff --git a/pqPythonEventSource.h b/pqPythonEventSource.h index 0ca8d98..466d275 100644 --- a/pqPythonEventSource.h +++ b/pqPythonEventSource.h @@ -7,7 +7,7 @@ All rights reserved. ParaView is a free software; you can redistribute it and/or modify it - under the terms of the ParaView license version 1.2. + under the terms of the ParaView license version 1.2. See License_v1.2.txt for the full ParaView license. A copy of this license can be obtained by contacting @@ -38,8 +38,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. /** Concrete implementation of pqEventSource that retrieves events recorded by pqPythonEventObserver */ -class QTTESTING_EXPORT pqPythonEventSource : - public pqThreadedEventSource +class QTTESTING_EXPORT pqPythonEventSource : public pqThreadedEventSource { Q_OBJECT public: @@ -73,4 +72,3 @@ private: }; #endif // !_pqPythonEventSource_h - diff --git a/pqRecordEventsDialog.cxx b/pqRecordEventsDialog.cxx index b925d89..c461ed7 100644 --- a/pqRecordEventsDialog.cxx +++ b/pqRecordEventsDialog.cxx @@ -7,7 +7,7 @@ All rights reserved. ParaView is a free software; you can redistribute it and/or modify it - under the terms of the ParaView license version 1.2. + under the terms of the ParaView license version 1.2. See License_v1.2.txt for the full ParaView license. A copy of this license can be obtained by contacting @@ -53,12 +53,12 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. struct pqRecordEventsDialog::pqImplementation { public: - pqImplementation(pqEventRecorder* recorder, - pqTestUtility* testUtility) - : Recorder(recorder), TestUtility(testUtility) + pqImplementation(pqEventRecorder* recorder, pqTestUtility* testUtility) + : Recorder(recorder) + , TestUtility(testUtility) { } - + ~pqImplementation() { this->Recorder = 0; @@ -67,19 +67,18 @@ public: Ui::pqRecordEventsDialog Ui; - pqEventRecorder* Recorder; - pqTestUtility* TestUtility; + pqEventRecorder* Recorder; + pqTestUtility* TestUtility; }; /////////////////////////////////////////////////////////////////////////////////// // pqRecordEventsDialog // ---------------------------------------------------------------------------- -pqRecordEventsDialog::pqRecordEventsDialog(pqEventRecorder* recorder, - pqTestUtility* testUtility, - QWidget* Parent) - : QDialog(Parent), - Implementation(new pqImplementation(recorder, testUtility)) +pqRecordEventsDialog::pqRecordEventsDialog( + pqEventRecorder* recorder, pqTestUtility* testUtility, QWidget* Parent) + : QDialog(Parent) + , Implementation(new pqImplementation(recorder, testUtility)) { this->Implementation->Ui.setupUi(this); this->setWindowFlags(this->windowFlags() | Qt::WindowStaysOnTopHint); @@ -90,41 +89,26 @@ pqRecordEventsDialog::pqRecordEventsDialog(pqEventRecorder* recorder, this->setObjectName(""); QObject::connect(this->Implementation->TestUtility->eventTranslator(), - SIGNAL(recordEvent(QString,QString,QString, int)), - this, SLOT(onEventRecorded(QString,QString,QString, int))); - - QObject::connect(this->Implementation->Ui.commentAddButton, - SIGNAL(clicked()), - this, SLOT(addComment())); - - QObject::connect(this->Implementation->Ui.checkButton, - SIGNAL(toggled(bool)), - this->Implementation->Recorder, - SLOT(check(bool))); - - QObject::connect(this->Implementation->Ui.recordPauseButton, - SIGNAL(toggled(bool)), - this->Implementation->Recorder, - SLOT(unpause(bool))); - - QObject::connect(this->Implementation->Ui.continuousFlush, - SIGNAL(toggled(bool)), - this->Implementation->Recorder, - SLOT(setContinuousFlush(bool))); - - QObject::connect(this->Implementation->Ui.recordInteractionTimings, - SIGNAL(toggled(bool)), - this->Implementation->Recorder, - SLOT(setRecordInteractionTimings(bool))); - - QObject::connect(this->Implementation->Recorder, - SIGNAL(started()), - this, - SLOT(updateUi())); - QObject::connect(this->Implementation->Recorder, - SIGNAL(stopped()), - this, - SLOT(updateUi())); + SIGNAL(recordEvent(QString, QString, QString, int)), this, + SLOT(onEventRecorded(QString, QString, QString, int))); + + QObject::connect( + this->Implementation->Ui.commentAddButton, SIGNAL(clicked()), this, SLOT(addComment())); + + QObject::connect(this->Implementation->Ui.checkButton, SIGNAL(toggled(bool)), + this->Implementation->Recorder, SLOT(check(bool))); + + QObject::connect(this->Implementation->Ui.recordPauseButton, SIGNAL(toggled(bool)), + this->Implementation->Recorder, SLOT(unpause(bool))); + + QObject::connect(this->Implementation->Ui.continuousFlush, SIGNAL(toggled(bool)), + this->Implementation->Recorder, SLOT(setContinuousFlush(bool))); + + QObject::connect(this->Implementation->Ui.recordInteractionTimings, SIGNAL(toggled(bool)), + this->Implementation->Recorder, SLOT(setRecordInteractionTimings(bool))); + + QObject::connect(this->Implementation->Recorder, SIGNAL(started()), this, SLOT(updateUi())); + QObject::connect(this->Implementation->Recorder, SIGNAL(stopped()), this, SLOT(updateUi())); } // ---------------------------------------------------------------------------- @@ -137,10 +121,10 @@ pqRecordEventsDialog::~pqRecordEventsDialog() void pqRecordEventsDialog::ignoreObject(QObject* object) { this->Implementation->TestUtility->eventTranslator()->ignoreObject(object); - foreach(QObject* child, object->children()) - { + foreach (QObject* child, object->children()) + { this->ignoreObject(child); - } + } } // ---------------------------------------------------------------------------- @@ -151,15 +135,13 @@ void pqRecordEventsDialog::done(int value) } // ---------------------------------------------------------------------------- -void pqRecordEventsDialog::onEventRecorded(const QString& widget, - const QString& command, - const QString& argument, - int eventType) +void pqRecordEventsDialog::onEventRecorded( + const QString& widget, const QString& command, const QString& argument, int eventType) { if (!this->Implementation->Recorder->isRecording()) - { + { return; - } + } this->Implementation->Ui.eventWidgetEdit->setText(widget); this->Implementation->Ui.eventCommandEdit->setText(command); @@ -172,15 +154,15 @@ void pqRecordEventsDialog::onEventRecorded(const QString& widget, void pqRecordEventsDialog::addComment() { if (this->Implementation->Ui.blockingCheckBox->isChecked()) - { + { this->Implementation->Recorder->translator()->eventComment()->recordCommentBlock( - this->Implementation->Ui.commentTextEdit->toPlainText()); - } + this->Implementation->Ui.commentTextEdit->toPlainText()); + } else - { + { this->Implementation->Recorder->translator()->eventComment()->recordComment( - this->Implementation->Ui.commentTextEdit->toPlainText()); - } + this->Implementation->Ui.commentTextEdit->toPlainText()); + } this->Implementation->Ui.commentTextEdit->clear(); } @@ -188,5 +170,5 @@ void pqRecordEventsDialog::addComment() void pqRecordEventsDialog::updateUi() { this->Implementation->Ui.recordPauseButton->setChecked( - this->Implementation->Recorder->isRecording()); + this->Implementation->Recorder->isRecording()); } diff --git a/pqRecordEventsDialog.h b/pqRecordEventsDialog.h index 763eebe..0eb7d2a 100644 --- a/pqRecordEventsDialog.h +++ b/pqRecordEventsDialog.h @@ -7,7 +7,7 @@ All rights reserved. ParaView is a free software; you can redistribute it and/or modify it - under the terms of the ParaView license version 1.2. + under the terms of the ParaView license version 1.2. See License_v1.2.txt for the full ParaView license. A copy of this license can be obtained by contacting @@ -39,19 +39,17 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. class pqEventRecorder; class pqTestUtility; -/// Provides a standard dialog that will record user input to an XML file as long as the dialog remains open -class QTTESTING_EXPORT pqRecordEventsDialog : - public QDialog +/// Provides a standard dialog that will record user input to an XML file as long as the dialog +/// remains open +class QTTESTING_EXPORT pqRecordEventsDialog : public QDialog { Q_OBJECT - + public: /** Creates the dialog and begins translating user input with the supplied translator. */ - pqRecordEventsDialog(pqEventRecorder* recorder, - pqTestUtility* testUtility, - QWidget* Parent); + pqRecordEventsDialog(pqEventRecorder* recorder, pqTestUtility* testUtility, QWidget* Parent); private slots: void done(int) override; @@ -74,4 +72,3 @@ private: }; #endif // !_pqRecordEventsDialog_h - diff --git a/pqSpinBoxEventTranslator.cxx b/pqSpinBoxEventTranslator.cxx index fcc1299..f33d834 100644 --- a/pqSpinBoxEventTranslator.cxx +++ b/pqSpinBoxEventTranslator.cxx @@ -7,7 +7,7 @@ All rights reserved. ParaView is a free software; you can redistribute it and/or modify it - under the terms of the ParaView license version 1.2. + under the terms of the ParaView license version 1.2. See License_v1.2.txt for the full ParaView license. A copy of this license can be obtained by contacting @@ -32,9 +32,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "pqSpinBoxEventTranslator.h" -#include <QSpinBox> -#include <QMouseEvent> #include <QKeyEvent> +#include <QMouseEvent> +#include <QSpinBox> #include <QStyle> #include <QStyleOptionSpinBox> @@ -46,60 +46,58 @@ pqSpinBoxEventTranslator::pqSpinBoxEventTranslator(QObject* p) } // ---------------------------------------------------------------------------- -bool pqSpinBoxEventTranslator::translateEvent(QObject* Object, - QEvent* Event, - bool& Error) +bool pqSpinBoxEventTranslator::translateEvent(QObject* Object, QEvent* Event, bool& Error) { QSpinBox* object = qobject_cast<QSpinBox*>(Object); - + // consume line edit events if part of spin box - if(!object && qobject_cast<QSpinBox*>(Object->parent())) - { + if (!object && qobject_cast<QSpinBox*>(Object->parent())) + { return true; - } + } - if(!object) - return false; + if (!object) + return false; - if(Event->type() == QEvent::Enter && Object==object) + if (Event->type() == QEvent::Enter && Object == object) + { + if (this->CurrentObject != Object) { - if(this->CurrentObject != Object) + if (this->CurrentObject) { - if(this->CurrentObject) - { disconnect(this->CurrentObject, 0, this, 0); - } + } this->CurrentObject = Object; this->Value = object->value(); - connect(object, SIGNAL(valueChanged(int)),this, SLOT(onValueChanged(int))); + connect(object, SIGNAL(valueChanged(int)), this, SLOT(onValueChanged(int))); connect(object, SIGNAL(destroyed(QObject*)), this, SLOT(onDestroyed(QObject*))); - } - return true; } + return true; + } - if (Event->type() == QEvent::Leave && Object==object) - { + if (Event->type() == QEvent::Leave && Object == object) + { disconnect(this->CurrentObject, 0, this, 0); this->CurrentObject = 0; return true; - } + } - if(Event->type() == QEvent::KeyRelease && Object == object) - { + if (Event->type() == QEvent::KeyRelease && Object == object) + { QKeyEvent* ke = static_cast<QKeyEvent*>(Event); QString keyText = ke->text(); this->Value = object->value(); - if(keyText.length() && keyText.at(0).isPrint()) - { + if (keyText.length() && keyText.at(0).isPrint()) + { emit recordEvent(object, "set_int", QString("%1").arg(object->value())); - } + } else - { + { emit recordEvent(object, "key", QString("%1").arg(ke->key())); - } - return true; } + return true; + } return this->Superclass::translateEvent(Object, Event, Error); } @@ -112,7 +110,5 @@ void pqSpinBoxEventTranslator::onDestroyed(QObject* /*Object*/) // ---------------------------------------------------------------------------- void pqSpinBoxEventTranslator::onValueChanged(int number) { - emit recordEvent(this->CurrentObject, "set_int", QString("%1") - .arg(number)); + emit recordEvent(this->CurrentObject, "set_int", QString("%1").arg(number)); } - diff --git a/pqSpinBoxEventTranslator.h b/pqSpinBoxEventTranslator.h index 88cf7f5..beaec69 100644 --- a/pqSpinBoxEventTranslator.h +++ b/pqSpinBoxEventTranslator.h @@ -7,7 +7,7 @@ All rights reserved. ParaView is a free software; you can redistribute it and/or modify it - under the terms of the ParaView license version 1.2. + under the terms of the ParaView license version 1.2. See License_v1.2.txt for the full ParaView license. A copy of this license can be obtained by contacting @@ -41,14 +41,13 @@ Translates low-level Qt events into high-level ParaView events that can be recor \sa pqEventTranslator */ -class QTTESTING_EXPORT pqSpinBoxEventTranslator : - public pqWidgetEventTranslator +class QTTESTING_EXPORT pqSpinBoxEventTranslator : public pqWidgetEventTranslator { Q_OBJECT typedef pqWidgetEventTranslator Superclass; - + public: - pqSpinBoxEventTranslator(QObject* p=0); + pqSpinBoxEventTranslator(QObject* p = 0); using Superclass::translateEvent; bool translateEvent(QObject* Object, QEvent* Event, bool& Error) override; @@ -57,7 +56,7 @@ private: pqSpinBoxEventTranslator(const pqSpinBoxEventTranslator&); pqSpinBoxEventTranslator& operator=(const pqSpinBoxEventTranslator&); - int Value; + int Value; QObject* CurrentObject; private slots: @@ -66,4 +65,3 @@ private slots: }; #endif // !_pqSpinBoxEventTranslator_h - diff --git a/pqStdoutEventObserver.cxx b/pqStdoutEventObserver.cxx index f289b04..4dc1bea 100644 --- a/pqStdoutEventObserver.cxx +++ b/pqStdoutEventObserver.cxx @@ -7,7 +7,7 @@ All rights reserved. ParaView is a free software; you can redistribute it and/or modify it - under the terms of the ParaView license version 1.2. + under the terms of the ParaView license version 1.2. See License_v1.2.txt for the full ParaView license. A copy of this license can be obtained by contacting @@ -34,14 +34,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include <stdio.h> void pqStdoutEventObserver::onRecordEvent( - const QString& Widget, - const QString& Command, - const QString& Arguments, - const int& eventType) + const QString& Widget, const QString& Command, const QString& Arguments, const int& eventType) { - printf("event: %s %s %s %i\n", - Widget.toLatin1().data(), - Command.toLatin1().data(), - Arguments.toLatin1().data(), - eventType); + printf("event: %s %s %s %i\n", Widget.toLatin1().data(), Command.toLatin1().data(), + Arguments.toLatin1().data(), eventType); } diff --git a/pqStdoutEventObserver.h b/pqStdoutEventObserver.h index 060b9b2..3be8e20 100644 --- a/pqStdoutEventObserver.h +++ b/pqStdoutEventObserver.h @@ -7,7 +7,7 @@ All rights reserved. ParaView is a free software; you can redistribute it and/or modify it - under the terms of the ParaView license version 1.2. + under the terms of the ParaView license version 1.2. See License_v1.2.txt for the full ParaView license. A copy of this license can be obtained by contacting @@ -44,17 +44,13 @@ slot to the pqEventTranslator::recordEvent() signal. \sa pqEventTranslator, pqEventObserverXML */ -class QTTESTING_EXPORT pqStdoutEventObserver : - public QObject +class QTTESTING_EXPORT pqStdoutEventObserver : public QObject { Q_OBJECT public slots: void onRecordEvent( - const QString& Widget, - const QString& Command, - const QString& Arguments, - const int& eventType); + const QString& Widget, const QString& Command, const QString& Arguments, const int& eventType); }; #endif // !_pqStdoutEventObserver_h diff --git a/pqTabBarEventPlayer.cxx b/pqTabBarEventPlayer.cxx index bea8f10..66abc0e 100644 --- a/pqTabBarEventPlayer.cxx +++ b/pqTabBarEventPlayer.cxx @@ -7,7 +7,7 @@ All rights reserved. ParaView is a free software; you can redistribute it and/or modify it - under the terms of the ParaView license version 1.2. + under the terms of the ParaView license version 1.2. See License_v1.2.txt for the full ParaView license. A copy of this license can be obtained by contacting @@ -46,53 +46,53 @@ pqTabBarEventPlayer::pqTabBarEventPlayer(QObject* p) bool pqTabBarEventPlayer::playEvent( QObject* target, const QString& command, const QString& arguments, bool& error_flag) { -/* if (command != "set_tab" && command != "set_tab_with_text") - { - // I don't handle this. Return false - return false; - }*/ + /* if (command != "set_tab" && command != "set_tab_with_text") + { + // I don't handle this. Return false + return false; + }*/ const QString value = arguments; - + QTabBar* const tab_bar = qobject_cast<QTabBar*>(target); if (!tab_bar) - { + { return false; - } + } - if (command=="set_tab") - { + if (command == "set_tab") + { // "set_tab" saves tab index. This was done in the past. Newly recorded // tests will use set_tab_with_text for more reliable playback. bool ok = false; int which = value.toInt(&ok); - if(!ok) - { + if (!ok) + { qCritical() << "calling set_tab with invalid argument on " << target; error_flag = true; - } - else if(tab_bar->count() < which) - { + } + else if (tab_bar->count() < which) + { qCritical() << "calling set_tab with out of bounds index on " << target; error_flag = true; - } + } else - { + { tab_bar->setCurrentIndex(which); - } - return true; } + return true; + } if (command == "set_tab_with_text") + { + for (int cc = 0; cc < tab_bar->count(); cc++) { - for (int cc=0 ; cc < tab_bar->count(); cc++) - { if (tab_bar->tabText(cc) == value) - { + { tab_bar->setCurrentIndex(cc); return true; - } } + } // With Qt 4.8, we have started seeing change in the order of the // tab-widgets created for docked panels. That results in the names not @@ -100,37 +100,36 @@ bool pqTabBarEventPlayer::playEvent( // an attempt to locate a sibling tab-bar that has a pane with the expected // name. If none is found, then alone do we give up. if (tab_bar->parentWidget()) - { + { QObjectList siblings = tab_bar->parentWidget()->children(); foreach (QObject* sibling_object, siblings) - { + { QTabBar* sibling_tab_bar = qobject_cast<QTabBar*>(sibling_object); - for (int cc=0 ; sibling_tab_bar != NULL && cc < sibling_tab_bar->count(); cc++) - { + for (int cc = 0; sibling_tab_bar != NULL && cc < sibling_tab_bar->count(); cc++) + { if (sibling_tab_bar->tabText(cc) == value) - { + { sibling_tab_bar->setCurrentIndex(cc); return true; - } } } } + } qCritical() << "calling set_tab with unknown tab " << value; qCritical() << "Available tabs are (count=" << tab_bar->count() << ")"; - for (int cc=0 ; cc < tab_bar->count(); cc++) - { + for (int cc = 0; cc < tab_bar->count(); cc++) + { qCritical() << " " << tab_bar->tabText(cc); - } + } error_flag = true; return true; - } + } if (!this->Superclass::playEvent(target, command, arguments, error_flag)) - { + { qCritical() << "calling set_tab on unhandled type " << target; error_flag = true; - } + } return true; } - diff --git a/pqTabBarEventPlayer.h b/pqTabBarEventPlayer.h index 05fc581..9deb935 100644 --- a/pqTabBarEventPlayer.h +++ b/pqTabBarEventPlayer.h @@ -7,7 +7,7 @@ All rights reserved. ParaView is a free software; you can redistribute it and/or modify it - under the terms of the ParaView license version 1.2. + under the terms of the ParaView license version 1.2. See License_v1.2.txt for the full ParaView license. A copy of this license can be obtained by contacting @@ -36,22 +36,23 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "pqWidgetEventPlayer.h" /** -Concrete implementation of pqWidgetEventPlayer that translates high-level ParaView events into low-level Qt events. +Concrete implementation of pqWidgetEventPlayer that translates high-level ParaView events into +low-level Qt events. \sa pqEventPlayer */ -class QTTESTING_EXPORT pqTabBarEventPlayer : - public pqWidgetEventPlayer +class QTTESTING_EXPORT pqTabBarEventPlayer : public pqWidgetEventPlayer { Q_OBJECT typedef pqWidgetEventPlayer Superclass; public: - pqTabBarEventPlayer(QObject* p=0); + pqTabBarEventPlayer(QObject* p = 0); using Superclass::playEvent; - bool playEvent(QObject* Object, const QString& Command, const QString& Arguments, bool& Error) override; + bool playEvent( + QObject* Object, const QString& Command, const QString& Arguments, bool& Error) override; private: pqTabBarEventPlayer(const pqTabBarEventPlayer&); @@ -59,4 +60,3 @@ private: }; #endif // !_pqTabBarEventPlayer_h - diff --git a/pqTabBarEventTranslator.cxx b/pqTabBarEventTranslator.cxx index ea05d78..8699292 100644 --- a/pqTabBarEventTranslator.cxx +++ b/pqTabBarEventTranslator.cxx @@ -7,7 +7,7 @@ All rights reserved. ParaView is a free software; you can redistribute it and/or modify it - under the terms of the ParaView license version 1.2. + under the terms of the ParaView license version 1.2. See License_v1.2.txt for the full ParaView license. A copy of this license can be obtained by contacting @@ -32,49 +32,47 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "pqTabBarEventTranslator.h" -#include <QTabBar> #include <QEvent> +#include <QTabBar> -pqTabBarEventTranslator::pqTabBarEventTranslator(QObject* p) - : pqWidgetEventTranslator(p), - CurrentObject(0) +pqTabBarEventTranslator::pqTabBarEventTranslator(QObject* p) + : pqWidgetEventTranslator(p) + , CurrentObject(0) { } bool pqTabBarEventTranslator::translateEvent(QObject* Object, QEvent* Event, bool& Error) { QTabBar* const object = qobject_cast<QTabBar*>(Object); - if(!object) - { + if (!object) + { return false; - } + } - switch(Event->type()) - { + switch (Event->type()) + { case QEvent::Enter: + { + if (this->CurrentObject != Object) { - if(this->CurrentObject != Object) + if (this->CurrentObject) { - if(this->CurrentObject) - { disconnect(this->CurrentObject, 0, this, 0); - } + } this->CurrentObject = object; connect(object, SIGNAL(currentChanged(int)), this, SLOT(indexChanged(int))); - } + } return true; break; - } - default: - break; } + default: + break; + } return this->Superclass::translateEvent(Object, Event, Error); } void pqTabBarEventTranslator::indexChanged(int which) { - emit recordEvent(this->CurrentObject, "set_tab_with_text", - this->CurrentObject->tabText(which)); + emit recordEvent(this->CurrentObject, "set_tab_with_text", this->CurrentObject->tabText(which)); } - diff --git a/pqTabBarEventTranslator.h b/pqTabBarEventTranslator.h index fda27fc..a507c8a 100644 --- a/pqTabBarEventTranslator.h +++ b/pqTabBarEventTranslator.h @@ -7,7 +7,7 @@ All rights reserved. ParaView is a free software; you can redistribute it and/or modify it - under the terms of the ParaView license version 1.2. + under the terms of the ParaView license version 1.2. See License_v1.2.txt for the full ParaView license. A copy of this license can be obtained by contacting @@ -43,14 +43,13 @@ Translates low-level Qt events into high-level ParaView events that can be recor \sa pqEventTranslator */ -class QTTESTING_EXPORT pqTabBarEventTranslator : - public pqWidgetEventTranslator +class QTTESTING_EXPORT pqTabBarEventTranslator : public pqWidgetEventTranslator { Q_OBJECT typedef pqWidgetEventTranslator Superclass; - + public: - pqTabBarEventTranslator(QObject* p=0); + pqTabBarEventTranslator(QObject* p = 0); using Superclass::translateEvent; bool translateEvent(QObject* Object, QEvent* Event, bool& Error) override; @@ -63,8 +62,6 @@ private: pqTabBarEventTranslator& operator=(const pqTabBarEventTranslator&); QPointer<QTabBar> CurrentObject; - }; #endif // !_pqTabBarEventTranslator_h - diff --git a/pqTableViewEventPlayer.cxx b/pqTableViewEventPlayer.cxx index 5cdbd34..64400bd 100644 --- a/pqTableViewEventPlayer.cxx +++ b/pqTableViewEventPlayer.cxx @@ -45,18 +45,17 @@ pqTableViewEventPlayer::~pqTableViewEventPlayer() //-----------------------------------------------------------------------------0000000 bool pqTableViewEventPlayer::playEvent( - QObject* object, const QString& command, - const QString& arguments, int eventType, bool& error) + QObject* object, const QString& command, const QString& arguments, int eventType, bool& error) { - QTableView* tableView= qobject_cast<QTableView*>(object); - if(!tableView) - { + QTableView* tableView = qobject_cast<QTableView*>(object); + if (!tableView) + { // mouse events go to the viewport widget tableView = qobject_cast<QTableView*>(object->parent()); - } - if(!tableView) - { + } + if (!tableView) + { return false; - } + } return this->Superclass::playEvent(object, command, arguments, eventType, error); } diff --git a/pqTableViewEventPlayer.h b/pqTableViewEventPlayer.h index 2e43e7d..7e6e0c9 100644 --- a/pqTableViewEventPlayer.h +++ b/pqTableViewEventPlayer.h @@ -40,17 +40,18 @@ class QTTESTING_EXPORT pqTableViewEventPlayer : public pqAbstractItemViewEventPl { Q_OBJECT typedef pqAbstractItemViewEventPlayerBase Superclass; + public: - pqTableViewEventPlayer(QObject* parent=0); + pqTableViewEventPlayer(QObject* parent = 0); ~pqTableViewEventPlayer() override; using Superclass::playEvent; - bool playEvent(QObject* object, const QString& command, - const QString& arguments, int eventType, bool& error) override; + bool playEvent(QObject* object, const QString& command, const QString& arguments, int eventType, + bool& error) override; private: pqTableViewEventPlayer(const pqTableViewEventPlayer&); // Not implemented. - void operator=(const pqTableViewEventPlayer&); // Not implemented. + void operator=(const pqTableViewEventPlayer&); // Not implemented. }; #endif diff --git a/pqTableViewEventTranslator.cxx b/pqTableViewEventTranslator.cxx index 39bdace..205561e 100644 --- a/pqTableViewEventTranslator.cxx +++ b/pqTableViewEventTranslator.cxx @@ -31,8 +31,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ========================================================================*/ #include "pqTableViewEventTranslator.h" -#include <QTableView> #include <QHeaderView> +#include <QTableView> //----------------------------------------------------------------------------- pqTableViewEventTranslator::pqTableViewEventTranslator(QObject* parentObject) : Superclass(parentObject) @@ -54,10 +54,9 @@ void pqTableViewEventTranslator::onEnteredCheck(const QModelIndex& item) QRect visualRect = tableView->visualRect(item); // Translate the rect of margins and headers - visualRect.translate(tableView->contentsMargins().left(), - tableView->contentsMargins().top()); - visualRect.translate(tableView->verticalHeader()->width(), - tableView->horizontalHeader()->height()); + visualRect.translate(tableView->contentsMargins().left(), tableView->contentsMargins().top()); + visualRect.translate( + tableView->verticalHeader()->width(), tableView->horizontalHeader()->height()); // Stor item and signal that a specific overlay is ready to be drawn this->ModelItemCheck = &item; @@ -69,16 +68,15 @@ QAbstractItemView* pqTableViewEventTranslator::findCorrectedAbstractItemView(QOb { // Ignore QHeaderView event specifically if (qobject_cast<QHeaderView*>(object)) - { + { return NULL; - } + } QAbstractItemView* abstractItemView = qobject_cast<QTableView*>(object); if (!abstractItemView) - { + { // mouse events go to the viewport widget abstractItemView = qobject_cast<QTableView*>(object->parent()); - } + } return abstractItemView; } - diff --git a/pqTableViewEventTranslator.h b/pqTableViewEventTranslator.h index ca906ec..9988c24 100644 --- a/pqTableViewEventTranslator.h +++ b/pqTableViewEventTranslator.h @@ -41,8 +41,9 @@ class QTTESTING_EXPORT pqTableViewEventTranslator : public pqAbstractItemViewEve { Q_OBJECT typedef pqAbstractItemViewEventTranslatorBase Superclass; + public: - pqTableViewEventTranslator(QObject* parent=0); + pqTableViewEventTranslator(QObject* parent = 0); ~pqTableViewEventTranslator() override; /// find and set the corrected abstract item view @@ -54,7 +55,7 @@ protected slots: private: pqTableViewEventTranslator(const pqTableViewEventTranslator&); // Not implemented. - void operator=(const pqTableViewEventTranslator&); // Not implemented. + void operator=(const pqTableViewEventTranslator&); // Not implemented. }; #endif diff --git a/pqTestUtility.cxx b/pqTestUtility.cxx index 6ae24ea..c291230 100644 --- a/pqTestUtility.cxx +++ b/pqTestUtility.cxx @@ -7,7 +7,7 @@ All rights reserved. ParaView is a free software; you can redistribute it and/or modify it - under the terms of the ParaView license version 1.2. + under the terms of the ParaView license version 1.2. See License_v1.2.txt for the full ParaView license. A copy of this license can be obtained by contacting @@ -45,15 +45,14 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "pqEventTranslator.h" #include "pqPlayBackEventsDialog.h" #ifdef QT_TESTING_WITH_PYTHON -#include "pqPythonEventSource.h" #include "pqPythonEventObserver.h" +#include "pqPythonEventSource.h" #endif #include "pqRecordEventsDialog.h" #include "pqTestUtility.h" #include "QtTestingConfigure.h" - //----------------------------------------------------------------------------- pqTestUtility::pqTestUtility(QObject* p) : QObject(p) @@ -81,7 +80,7 @@ pqTestUtility::~pqTestUtility() { this->File = 0; } - + //----------------------------------------------------------------------------- pqEventDispatcher* pqTestUtility::dispatcher() { @@ -107,27 +106,26 @@ pqEventTranslator* pqTestUtility::eventTranslator() } //----------------------------------------------------------------------------- -void pqTestUtility::addEventSource(const QString& fileExtension, - pqEventSource* source) +void pqTestUtility::addEventSource(const QString& fileExtension, pqEventSource* source) { if (!source) - { + { return; - } + } QMap<QString, pqEventSource*>::iterator iter; iter = this->EventSources.find(fileExtension); - if(iter != this->EventSources.end()) - { + if (iter != this->EventSources.end()) + { if (iter.value() == source) - { + { return; - } + } pqEventSource* src = iter.value(); this->EventSources.erase(iter); delete src; - } + } this->EventSources.insert(fileExtension, source); source->setParent(this); } @@ -139,27 +137,26 @@ QMap<QString, pqEventSource*> pqTestUtility::eventSources() const } //----------------------------------------------------------------------------- -void pqTestUtility::addEventObserver(const QString& fileExtension, - pqEventObserver* observer) +void pqTestUtility::addEventObserver(const QString& fileExtension, pqEventObserver* observer) { if (!observer) - { + { return; - } + } QMap<QString, pqEventObserver*>::iterator iter; iter = this->EventObservers.find(fileExtension); - if(iter != this->EventObservers.end()) - { + if (iter != this->EventObservers.end()) + { if (iter.value() == observer) - { + { return; - } + } pqEventObserver* src = iter.value(); this->EventObservers.erase(iter); delete src; - } + } this->EventObservers.insert(fileExtension, observer); observer->setParent(this); } @@ -174,10 +171,7 @@ QMap<QString, pqEventObserver*> pqTestUtility::eventObservers() const void pqTestUtility::openPlayerDialog() { pqPlayBackEventsDialog* dialog = - new pqPlayBackEventsDialog(this->Player, - this->Dispatcher, - this, - QApplication::activeWindow()); + new pqPlayBackEventsDialog(this->Player, this->Dispatcher, this, QApplication::activeWindow()); dialog->show(); } @@ -204,34 +198,34 @@ void pqTestUtility::pauseRecords(bool value) void pqTestUtility::onRecordStopped() { QTemporaryFile* file = qobject_cast<QTemporaryFile*>(this->File); - if(file) - { - QFileDialog* dialog = new QFileDialog(0, tr("Macro File Name"), - QString("macro"), tr("XML Files (*.xml)")); + if (file) + { + QFileDialog* dialog = + new QFileDialog(0, tr("Macro File Name"), QString("macro"), tr("XML Files (*.xml)")); dialog->setAcceptMode(QFileDialog::AcceptSave); dialog->setDefaultSuffix("xml"); if (dialog->exec() == QDialog::Rejected) - { + { return; - } + } QStringList newFilename = dialog->selectedFiles(); if (newFilename[0].isEmpty()) - { + { return; - } + } if (!newFilename[0].endsWith(QString(".%1").arg(this->FileSuffix))) - { + { newFilename[0] += QString(".%1").arg(this->FileSuffix); - } + } // QFile::copy doesn't overwrite if the file already exist, and return false - if(QFile::exists(newFilename[0])) - { + if (QFile::exists(newFilename[0])) + { QFile::remove(newFilename[0]); - } + } QFile::copy(file->fileName(), newFilename[0]); delete dialog; - } + } this->File->close(); } @@ -247,47 +241,47 @@ bool pqTestUtility::playTests(const QString& filename) bool pqTestUtility::playTests(const QStringList& filenames) { if (this->PlayingTest) - { + { qCritical("playTests() cannot be called recursively."); return false; - } + } this->PlayingTest = true; emit this->playbackStarted(); bool success = true; foreach (QString filename, filenames) - { + { this->Filename = filename; - if(!this->playingTest()) - { + if (!this->playingTest()) + { break; - } + } QFileInfo info(filename); emit this->playbackStarted(filename); QString suffix = info.completeSuffix(); QMap<QString, pqEventSource*>::iterator iter; iter = this->EventSources.find(suffix); - if(info.isReadable() && iter != this->EventSources.end()) - { + if (info.isReadable() && iter != this->EventSources.end()) + { iter.value()->setContent(filename); -// QEventLoop loop; -// QTimer::singleShot(100, &loop, SLOT(quit())); -// loop.exec(); + // QEventLoop loop; + // QTimer::singleShot(100, &loop, SLOT(quit())); + // loop.exec(); QApplication::processEvents(); if (!this->Dispatcher.playEvents(*iter.value(), this->Player)) - { + { // dispatcher returned failure, don't continue with rest of the tests // and flag error. success = false; emit this->playbackStopped(info.fileName(), success); break; - } + } emit this->playbackStopped(info.fileName(), success); qDebug() << "Test " << info.fileName() << "is finished. Success = " << success; - } } + } this->Filename = ""; this->PlayingTest = false; @@ -303,50 +297,48 @@ void pqTestUtility::recordTests() // check for native or non-native menu bar. // testing framework doesn't work with native menu bar, so let's warn if we // get that. - if(!getenv("QT_MAC_NO_NATIVE_MENUBAR")) - { + if (!getenv("QT_MAC_NO_NATIVE_MENUBAR")) + { qWarning("Recording menu events for native Mac menus doesn't work.\n" "Set the QT_MAC_NO_NATIVE_MENUBAR environment variable to" " correctly record menus"); - } + } #endif pqEventObserver* observer = this->EventObservers.value(this->FileSuffix); - if(!observer) - { + if (!observer) + { return; - } + } - if(!this->File->open(QIODevice::WriteOnly)) - { + if (!this->File->open(QIODevice::WriteOnly)) + { qCritical() << "File cannot be opened"; return; - } + } - QObject::connect(&this->Recorder, SIGNAL(stopped()), - this, SLOT(onRecordStopped()), Qt::UniqueConnection); + QObject::connect( + &this->Recorder, SIGNAL(stopped()), this, SLOT(onRecordStopped()), Qt::UniqueConnection); if (this->RecordWithDialog) { if (QApplication::activeWindow()) - { - pqRecordEventsDialog* dialog = new pqRecordEventsDialog(&this->Recorder, - this, - QApplication::activeWindow()); + { + pqRecordEventsDialog* dialog = + new pqRecordEventsDialog(&this->Recorder, this, QApplication::activeWindow()); dialog->setAttribute(Qt::WA_QuitOnClose, false); QRect rectApp = QApplication::activeWindow()->geometry(); - QRect rectDialog(QPoint(rectApp.left(), - rectApp.bottom() - dialog->sizeHint().height()), - QSize(dialog->geometry().width(), dialog->sizeHint().height())); + QRect rectDialog(QPoint(rectApp.left(), rectApp.bottom() - dialog->sizeHint().height()), + QSize(dialog->geometry().width(), dialog->sizeHint().height())); dialog->setGeometry(rectDialog); dialog->show(); - } + } else - { + { qWarning() << "No active windows has been found"; - } + } } this->Recorder.recordEvents(&this->Translator, observer, this->File, true); @@ -375,33 +367,30 @@ void pqTestUtility::recordTestsBySuffix(const QString& suffix) void pqTestUtility::addObjectStateProperty(QObject* object, const QString& property) { if (!object) - { + { return; - } - if (property.isEmpty() || - !object->property(property.toLatin1()).isValid()) - { + } + if (property.isEmpty() || !object->property(property.toLatin1()).isValid()) + { return; - } - if(this->objectStatePropertyAlreadyAdded(object, property)) - { + } + if (this->objectStatePropertyAlreadyAdded(object, property)) + { return; - } + } this->ObjectStateProperty[object].append(property); } // ---------------------------------------------------------------------------- -bool pqTestUtility::objectStatePropertyAlreadyAdded(QObject* object, - const QString& property) +bool pqTestUtility::objectStatePropertyAlreadyAdded(QObject* object, const QString& property) { // Check if this property already exist for this object - QMap<QObject*, QStringList>::iterator iter = - this->ObjectStateProperty.find(object); + QMap<QObject*, QStringList>::iterator iter = this->ObjectStateProperty.find(object); if (iter != this->ObjectStateProperty.end()) - { + { return this->ObjectStateProperty[object].contains(property); - } + } return false; } @@ -417,17 +406,17 @@ void pqTestUtility::addDataDirectory(const QString& label, const QDir& path) { // To simplify, we allow only absolute path for the moment. if (label.isEmpty()) - { + { return; - } + } // Find better way to check if the path seams to be valid. // But as long as we would like to label some path, to allow a cross // platform use of QtTesting, a simple path.exist() seams not good. // not working ! if (!path.isAbsolute()) - { + { return; - } + } this->DataDirectories[label] = path; } @@ -445,46 +434,45 @@ QMap<QString, QDir> pqTestUtility::dataDirectory() const } //----------------------------------------------------------------------------- -QMap<QString, QDir>::iterator pqTestUtility::findBestIterator(const QString& file, - QMap<QString, QDir>::iterator startIter) +QMap<QString, QDir>::iterator pqTestUtility::findBestIterator( + const QString& file, QMap<QString, QDir>::iterator startIter) { QMap<QString, QDir>::iterator currentIter; QMap<QString, QDir>::iterator iter; int size = file.size(); bool find = false; - for(iter = startIter; iter != this->DataDirectories.end() ; ++ iter) - { + for (iter = startIter; iter != this->DataDirectories.end(); ++iter) + { if (file.startsWith(iter.value().path())) - { + { QString relativePos = iter.value().relativeFilePath(file); if (relativePos.size() < size) - { + { find = true; size = relativePos.size(); currentIter = iter; - } } } + } if (!find) - { + { return this->DataDirectories.end(); - } + } return currentIter; } //----------------------------------------------------------------------------- QString pqTestUtility::convertToDataDirectory(const QString& file) { - QMap<QString, QDir>::iterator iter = - this->findBestIterator(file, this->DataDirectories.begin()); + QMap<QString, QDir>::iterator iter = this->findBestIterator(file, this->DataDirectories.begin()); // If iterator at the end, we didn't find a match. if (iter == this->DataDirectories.end()) - { + { return file; - } + } QString rel_file = iter.value().relativeFilePath(file); return QString("${%1}/%2").arg(iter.key()).arg(rel_file); @@ -495,15 +483,15 @@ QString pqTestUtility::convertFromDataDirectory(const QString& file) { QString filename = file; QMap<QString, QDir>::iterator iter; - for(iter = this->DataDirectories.begin(); iter != this->DataDirectories.end(); ++iter) - { + for (iter = this->DataDirectories.begin(); iter != this->DataDirectories.end(); ++iter) + { QString label = QString("${%1}").arg(iter.key()); - if(filename.contains(label)) - { + if (filename.contains(label)) + { filename.replace(label, iter.value().absolutePath()); break; - } } + } return filename; } diff --git a/pqTestUtility.h b/pqTestUtility.h index e78eebc..20d66f5 100644 --- a/pqTestUtility.h +++ b/pqTestUtility.h @@ -7,7 +7,7 @@ All rights reserved. ParaView is a free software; you can redistribute it and/or modify it - under the terms of the ParaView license version 1.2. + under the terms of the ParaView license version 1.2. See License_v1.2.txt for the full ParaView license. A copy of this license can be obtained by contacting @@ -66,7 +66,6 @@ public: ~pqTestUtility() override; public: - /// Get the event dispatcher. Dispatcher is used to play tests back. pqEventDispatcher* dispatcher(); @@ -88,19 +87,17 @@ public: /// Return a QMap of all the eventSources. QMap<QString, pqEventSource*> eventSources() const; - + /// add an event observer for recording files /// An pqXMLEventObserver is automatically added if XML support is enabled. /// A pqPythonEventObserver is automatically added if Python support is enabled. - void addEventObserver(const QString& fileExtension, - pqEventObserver* translator); + void addEventObserver(const QString& fileExtension, pqEventObserver* translator); /// Return a QMap of all the event Observers. QMap<QString, pqEventObserver*> eventObservers() const; /// Returns if the utility is currently playing a test. - bool playingTest() const - { return this->PlayingTest; } + bool playingTest() const { return this->PlayingTest; } /// Plays back the test given by the filename(s). This is a blocking call i.e. /// it does not return until the test has been played or aborted due to @@ -130,7 +127,7 @@ public: QString convertFromDataDirectory(const QString& file); // Get current test filname if any - const QString& filename() const {return this->Filename;}; + const QString& filename() const { return this->Filename; }; /// True if a dialog is opened when recording, false otherwise bool recordWithDialog() const; @@ -153,28 +150,27 @@ signals: void playbackStopped(const QString& filename, bool error); private: - QMap<QString, QDir>::iterator findBestIterator(const QString& file, - QMap<QString, QDir>::iterator startIter); + QMap<QString, QDir>::iterator findBestIterator( + const QString& file, QMap<QString, QDir>::iterator startIter); bool objectStatePropertyAlreadyAdded(QObject* object, const QString& property); protected: - pqEventRecorder Recorder; - pqEventDispatcher Dispatcher; - pqEventPlayer Player; - pqEventTranslator Translator; - bool PlayingTest; - bool RecordWithDialog; - - QString Filename; - QIODevice* File; - QString FileSuffix; - - QMap<QString, pqEventSource*> EventSources; + pqEventRecorder Recorder; + pqEventDispatcher Dispatcher; + pqEventPlayer Player; + pqEventTranslator Translator; + bool PlayingTest; + bool RecordWithDialog; + + QString Filename; + QIODevice* File; + QString FileSuffix; + + QMap<QString, pqEventSource*> EventSources; QMap<QString, pqEventObserver*> EventObservers; - QMap<QString, QDir> DataDirectories; - QMap<QObject*, QStringList> ObjectStateProperty; - + QMap<QString, QDir> DataDirectories; + QMap<QObject*, QStringList> ObjectStateProperty; }; #endif // !_pqTestUtility_h diff --git a/pqThreadedEventSource.cxx b/pqThreadedEventSource.cxx index f94e556..c25f9c1 100644 --- a/pqThreadedEventSource.cxx +++ b/pqThreadedEventSource.cxx @@ -7,7 +7,7 @@ All rights reserved. ParaView is a free software; you can redistribute it and/or modify it - under the terms of the ParaView license version 1.2. + under the terms of the ParaView license version 1.2. See License_v1.2.txt for the full ParaView license. A copy of this license can be obtained by contacting @@ -30,32 +30,29 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. =========================================================================*/ - #include "pqThreadedEventSource.h" #include <QMutex> -#include <QWaitCondition> -#include <QThread> #include <QString> +#include <QThread> +#include <QWaitCondition> #include "pqEventDispatcher.h" class pqThreadedEventSource::pqInternal : public QThread { friend class pqThreadedEventSource; + public: pqInternal(pqThreadedEventSource& source) - : Source(source), - ShouldStop(0), - GotEvent(0) - { - } - - void run() override - { - Source.run(); - } - + : Source(source) + , ShouldStop(0) + , GotEvent(0) + { + } + + void run() override { Source.run(); } + pqThreadedEventSource& Source; QWaitCondition WaitCondition; @@ -69,11 +66,8 @@ public: class ThreadHelper : public QThread { - public: - static void msleep(int msecs) - { - QThread::msleep(msecs); - } + public: + static void msleep(int msecs) { QThread::msleep(msecs); } }; }; @@ -90,34 +84,30 @@ pqThreadedEventSource::~pqThreadedEventSource() delete this->Internal; } - -int pqThreadedEventSource::getNextEvent( - QString& object, - QString& command, - QString& arguments) +int pqThreadedEventSource::getNextEvent(QString& object, QString& command, QString& arguments) { - while(!this->Internal->GotEvent) - { + while (!this->Internal->GotEvent) + { // wait for the other thread to post an event, while // we keep the GUI alive. pqEventDispatcher::processEventsAndWait(100); - } + } object = this->Internal->CurrentObject; command = this->Internal->CurrentCommand; arguments = this->Internal->CurrentArgument; this->Internal->GotEvent = 0; this->guiAcknowledge(); - - if(object == QString::null) + + if (object == QString::null) + { + if (arguments == "failure") { - if(arguments == "failure") - { return FAILURE; - } - return DONE; } + return DONE; + } return SUCCESS; } @@ -130,15 +120,11 @@ void pqThreadedEventSource::relayEvent(QString object, QString command, QString this->Internal->GotEvent = 1; } - -bool pqThreadedEventSource::postNextEvent(const QString& object, - const QString& command, - const QString& argument) +bool pqThreadedEventSource::postNextEvent( + const QString& object, const QString& command, const QString& argument) { - QMetaObject::invokeMethod(this, "relayEvent", Qt::QueuedConnection, - Q_ARG(QString, object), - Q_ARG(QString, command), - Q_ARG(QString, argument)); + QMetaObject::invokeMethod(this, "relayEvent", Qt::QueuedConnection, Q_ARG(QString, object), + Q_ARG(QString, command), Q_ARG(QString, argument)); return this->waitForGUI(); } @@ -159,12 +145,11 @@ bool pqThreadedEventSource::waitForGUI() { this->Internal->Waiting = 1; - while(this->Internal->Waiting == 1 && - this->Internal->ShouldStop == 0) - { + while (this->Internal->Waiting == 1 && this->Internal->ShouldStop == 0) + { pqInternal::ThreadHelper::msleep(50); - } - + } + this->Internal->Waiting = 0; return !this->Internal->ShouldStop; @@ -172,11 +157,11 @@ bool pqThreadedEventSource::waitForGUI() void pqThreadedEventSource::guiAcknowledge() { - while(this->Internal->Waiting == 0) - { + while (this->Internal->Waiting == 0) + { pqInternal::ThreadHelper::msleep(50); - } - + } + this->Internal->Waiting = 0; } @@ -187,11 +172,10 @@ void pqThreadedEventSource::msleep(int msec) void pqThreadedEventSource::done(int success) { - if(success == 0) - { + if (success == 0) + { this->postNextEvent(QString(), QString(), QString()); return; - } + } this->postNextEvent(QString(), QString(), "failure"); } - diff --git a/pqThreadedEventSource.h b/pqThreadedEventSource.h index c34c6dd..f44a0bf 100644 --- a/pqThreadedEventSource.h +++ b/pqThreadedEventSource.h @@ -7,7 +7,7 @@ All rights reserved. ParaView is a free software; you can redistribute it and/or modify it - under the terms of the ParaView license version 1.2. + under the terms of the ParaView license version 1.2. See License_v1.2.txt for the full ParaView license. A copy of this license can be obtained by contacting @@ -51,21 +51,16 @@ public: /** Called by the dispatcher on the GUI thread. Retrieves the next available event. Returns true if an event was - returned, false if there are no more events. + returned, false if there are no more events. In the case of a threaded event source, this function is called by the GUI thread and waits for the other thread to pos and event. */ - virtual int getNextEvent( - QString& object, - QString& command, - QString& arguments); - + virtual int getNextEvent(QString& object, QString& command, QString& arguments); + /** The testing thread may post an event for the GUI to process. - This function blocks until there are no previously queued + This function blocks until there are no previously queued events to play. If the event plays successfully, true is returned. */ - bool postNextEvent(const QString& object, - const QString& command, - const QString& argument); + bool postNextEvent(const QString& object, const QString& command, const QString& argument); /** tell this source to stop */ void stop() override; @@ -73,7 +68,7 @@ public: /** Wait for the GUI thread to acknowledge an event. A previously locked mutex must be passed in. For use by the testing thread. - If return value is false, an error occurred and + If return value is false, an error occurred and the testing thread should terminate. */ bool waitForGUI(); @@ -83,7 +78,7 @@ public: // helper method to sleep. static void msleep(int msecs); - + private slots: void relayEvent(QString object, QString command, QString arguments); @@ -96,15 +91,13 @@ protected: // pass in zero for success, non-zero for failure void done(int); - // run the thread, return + // run the thread, return virtual void run() = 0; private: class pqInternal; pqInternal* Internal; friend class pqInternal; - }; #endif // !_pqThreadedEventSource_h - diff --git a/pqTimer.cxx b/pqTimer.cxx index f6be081..fc99ed5 100644 --- a/pqTimer.cxx +++ b/pqTimer.cxx @@ -57,11 +57,11 @@ void pqTimer::timerEvent(QTimerEvent* evt) void pqTimer::singleShot(int msec, QObject* receiver, const char* member) { if (receiver && member) - { + { pqTimer* timer = new pqTimer(receiver); QObject::connect(timer, SIGNAL(timeout()), receiver, member); QObject::connect(timer, SIGNAL(timeout()), timer, SLOT(deleteLater())); timer->setSingleShot(true); timer->start(msec); - } + } } diff --git a/pqTimer.h b/pqTimer.h index 035e9da..618aad1 100644 --- a/pqTimer.h +++ b/pqTimer.h @@ -32,8 +32,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef __pqTimer_h #define __pqTimer_h -#include <QTimer> #include "QtTestingExport.h" +#include <QTimer> /// pqTimer is a extension for QTimer which ensures that the timer is registered /// with the pqEventDispatcher. Register timers with pqEventDispatcher ensures @@ -44,8 +44,9 @@ class QTTESTING_EXPORT pqTimer : public QTimer { Q_OBJECT typedef QTimer Superclass; + public: - pqTimer(QObject* parent=0); + pqTimer(QObject* parent = 0); ~pqTimer() override; /// This static function calls a slot after a given time interval. diff --git a/pqTreeViewEventPlayer.cxx b/pqTreeViewEventPlayer.cxx index 04d00a5..ff45e54 100644 --- a/pqTreeViewEventPlayer.cxx +++ b/pqTreeViewEventPlayer.cxx @@ -30,9 +30,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ========================================================================*/ #include "pqTreeViewEventPlayer.h" -#include <QTreeWidget> -#include <QMenu> #include <QDebug> +#include <QMenu> +#include <QTreeWidget> //----------------------------------------------------------------------------- pqTreeViewEventPlayer::pqTreeViewEventPlayer(QObject* parentObject) @@ -47,71 +47,70 @@ pqTreeViewEventPlayer::~pqTreeViewEventPlayer() //-----------------------------------------------------------------------------0000000 bool pqTreeViewEventPlayer::playEvent( - QObject* object, const QString& command, - const QString& arguments, int eventType, bool& error) + QObject* object, const QString& command, const QString& arguments, int eventType, bool& error) { - QTreeView* treeView= qobject_cast<QTreeView*>(object); - QMenu* contextMenu= qobject_cast<QMenu*>(object); + QTreeView* treeView = qobject_cast<QTreeView*>(object); + QMenu* contextMenu = qobject_cast<QMenu*>(object); // if this a QMenu (potentially a context menu of the view), // we should not move onto parent - if(!treeView && !contextMenu) - { + if (!treeView && !contextMenu) + { // mouse events go to the viewport widget treeView = qobject_cast<QTreeView*>(object->parent()); - } - if(!treeView) - { + } + if (!treeView) + { return false; - } + } QRegExp regExp0("^([\\d\\.]+),(\\d+),(\\d+)$"); if (command == "setTreeItemCheckState" && regExp0.indexIn(arguments) != -1) - { + { // legacy command recorded from tree widgets. QTreeWidget* treeWidget = qobject_cast<QTreeWidget*>(object); if (!treeWidget) - { + { return false; - } + } QString str_index = regExp0.cap(1); int column = regExp0.cap(2).toInt(); int check_state = regExp0.cap(3).toInt(); - QStringList indices = str_index.split(".",QString::SkipEmptyParts); + QStringList indices = str_index.split(".", QString::SkipEmptyParts); QTreeWidgetItem* cur_item = NULL; foreach (QString cur_index, indices) - { + { int index = cur_index.toInt(); if (!cur_item) - { + { cur_item = treeWidget->topLevelItem(index); - } + } else - { + { cur_item = cur_item->child(index); - } + } if (!cur_item) - { - error=true; + { + error = true; qCritical() << "ERROR: Tree widget must have changed. " - << "Indices recorded in the test are no longer valid. Cannot playback."; + << "Indices recorded in the test are no longer valid. Cannot playback."; return true; - } } + } cur_item->setCheckState(column, static_cast<Qt::CheckState>(check_state)); return true; - } + } if (command == "expand" || command == "collapse") - { + { QString str_index = arguments; QModelIndex index = pqTreeViewEventPlayer::GetIndex(str_index, treeView, error); if (error) - { + { return true; - } - treeView->setExpanded(index, (command=="expand")); - return true; } + treeView->setExpanded(index, (command == "expand")); + return true; + } return this->Superclass::playEvent(object, command, arguments, eventType, error); } diff --git a/pqTreeViewEventPlayer.h b/pqTreeViewEventPlayer.h index 3075dc2..0b5ab49 100644 --- a/pqTreeViewEventPlayer.h +++ b/pqTreeViewEventPlayer.h @@ -7,8 +7,8 @@ All rights reserved. ParaView is a free software; you can redistribute it and/or modify it - under the terms of the ParaView license version 1.2. - + under the terms of the ParaView license version 1.2. + See License_v1.2.txt for the full ParaView license. A copy of this license can be obtained by contacting Kitware Inc. @@ -29,7 +29,7 @@ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ========================================================================*/ -#ifndef __pqTreeViewEventPlayer_h +#ifndef __pqTreeViewEventPlayer_h #define __pqTreeViewEventPlayer_h #include "pqAbstractItemViewEventPlayerBase.h" @@ -40,19 +40,18 @@ class QTTESTING_EXPORT pqTreeViewEventPlayer : public pqAbstractItemViewEventPla { Q_OBJECT typedef pqAbstractItemViewEventPlayerBase Superclass; + public: - pqTreeViewEventPlayer(QObject* parent=0); + pqTreeViewEventPlayer(QObject* parent = 0); ~pqTreeViewEventPlayer() override; using Superclass::playEvent; - bool playEvent(QObject* object, const QString& command, - const QString& arguments, int eventType, bool& error) override; + bool playEvent(QObject* object, const QString& command, const QString& arguments, int eventType, + bool& error) override; private: pqTreeViewEventPlayer(const pqTreeViewEventPlayer&); // Not implemented. - void operator=(const pqTreeViewEventPlayer&); // Not implemented. + void operator=(const pqTreeViewEventPlayer&); // Not implemented. }; #endif - - diff --git a/pqTreeViewEventTranslator.cxx b/pqTreeViewEventTranslator.cxx index a8e4cb7..b4162e0 100644 --- a/pqTreeViewEventTranslator.cxx +++ b/pqTreeViewEventTranslator.cxx @@ -32,8 +32,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "pqTreeViewEventTranslator.h" -#include <QTreeView> #include <QHeaderView> +#include <QTreeView> //----------------------------------------------------------------------------- pqTreeViewEventTranslator::pqTreeViewEventTranslator(QObject* parentObject) @@ -50,10 +50,10 @@ pqTreeViewEventTranslator::~pqTreeViewEventTranslator() void pqTreeViewEventTranslator::connectWidgetToSlots(QAbstractItemView* abstractItemView) { this->Superclass::connectWidgetToSlots(abstractItemView); - QObject::connect(abstractItemView, SIGNAL(expanded(const QModelIndex&)), - this, SLOT(onExpanded(const QModelIndex&))); - QObject::connect(abstractItemView, SIGNAL(collapsed(const QModelIndex&)), - this, SLOT(onCollapsed(const QModelIndex&))); + QObject::connect(abstractItemView, SIGNAL(expanded(const QModelIndex&)), this, + SLOT(onExpanded(const QModelIndex&))); + QObject::connect(abstractItemView, SIGNAL(collapsed(const QModelIndex&)), this, + SLOT(onCollapsed(const QModelIndex&))); } //----------------------------------------------------------------------------- @@ -62,8 +62,7 @@ void pqTreeViewEventTranslator::onExpanded(const QModelIndex& index) QTreeView* treeView = qobject_cast<QTreeView*>(this->sender()); // record the check state change if the item is user-checkable. - emit this->recordEvent(treeView, "expand", - this->getIndexAsString(index)); + emit this->recordEvent(treeView, "expand", this->getIndexAsString(index)); } //----------------------------------------------------------------------------- @@ -72,22 +71,20 @@ void pqTreeViewEventTranslator::onCollapsed(const QModelIndex& index) QTreeView* treeView = qobject_cast<QTreeView*>(this->sender()); // record the check state change if the item is user-checkable. - emit this->recordEvent(treeView, "collapse", - this->getIndexAsString(index)); + emit this->recordEvent(treeView, "collapse", this->getIndexAsString(index)); } //----------------------------------------------------------------------------- void pqTreeViewEventTranslator::onEnteredCheck(const QModelIndex& item) { - //Recover treeview + // Recover treeview QTreeView* treeView = qobject_cast<QTreeView*>(this->AbstractItemView); // Recover a visual rectangle corresponding to the item QRect visualRect = treeView->visualRect(item); // Translating it of margins, as they are missing from visual rect - visualRect.translate(treeView->contentsMargins().left(), - treeView->contentsMargins().top()); + visualRect.translate(treeView->contentsMargins().left(), treeView->contentsMargins().top()); // As well as header visualRect.translate(0, treeView->header()->height()); @@ -102,15 +99,15 @@ QAbstractItemView* pqTreeViewEventTranslator::findCorrectedAbstractItemView(QObj { // Ignore QHeaderView event specifically if (qobject_cast<QHeaderView*>(object)) - { + { return NULL; - } + } QAbstractItemView* abstractItemView = qobject_cast<QTreeView*>(object); - if(! abstractItemView) - { + if (!abstractItemView) + { // mouse events go to the viewport widget abstractItemView = qobject_cast<QTreeView*>(object->parent()); - } + } return abstractItemView; } diff --git a/pqTreeViewEventTranslator.h b/pqTreeViewEventTranslator.h index 8c7188a..46cdf42 100644 --- a/pqTreeViewEventTranslator.h +++ b/pqTreeViewEventTranslator.h @@ -41,8 +41,9 @@ class QTTESTING_EXPORT pqTreeViewEventTranslator : public pqAbstractItemViewEven { Q_OBJECT typedef pqAbstractItemViewEventTranslatorBase Superclass; + public: - pqTreeViewEventTranslator(QObject* parent=0); + pqTreeViewEventTranslator(QObject* parent = 0); ~pqTreeViewEventTranslator() override; /// Connect QTree signals to this class slots @@ -60,7 +61,7 @@ protected slots: private: pqTreeViewEventTranslator(const pqTreeViewEventTranslator&); // Not implemented. - void operator=(const pqTreeViewEventTranslator&); // Not implemented. + void operator=(const pqTreeViewEventTranslator&); // Not implemented. }; #endif diff --git a/pqWidgetEventPlayer.cxx b/pqWidgetEventPlayer.cxx index 665e909..0c8ef49 100644 --- a/pqWidgetEventPlayer.cxx +++ b/pqWidgetEventPlayer.cxx @@ -7,7 +7,7 @@ All rights reserved. ParaView is a free software; you can redistribute it and/or modify it - under the terms of the ParaView license version 1.2. + under the terms of the ParaView license version 1.2. See License_v1.2.txt for the full ParaView license. A copy of this license can be obtained by contacting @@ -35,60 +35,58 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include <QContextMenuEvent> #include <QCoreApplication> #include <QPoint> -#include <QtDebug> #include <QWidget> +#include <QtDebug> #include "pqEventTypes.h" -pqWidgetEventPlayer::pqWidgetEventPlayer(QObject* p) - : QObject(p) +pqWidgetEventPlayer::pqWidgetEventPlayer(QObject* p) + : QObject(p) { } -pqWidgetEventPlayer::~pqWidgetEventPlayer() +pqWidgetEventPlayer::~pqWidgetEventPlayer() { } bool pqWidgetEventPlayer::playEvent( - QObject* object, const QString& command, - const QString& arguments, bool& error) + QObject* object, const QString& command, const QString& arguments, bool& error) { QWidget* widget = qobject_cast<QWidget*>(object); - if(widget) + if (widget) + { + if (command == "contextMenu") { - if(command == "contextMenu") - { QPoint pt(widget->x(), widget->y()); QPoint globalPt = widget->mapToGlobal(pt); QContextMenuEvent e(QContextMenuEvent::Other, pt, globalPt); qApp->notify(widget, &e); return true; - } + } else if (command == "size") - { + { QStringList entries = arguments.split(','); if (entries.size() == 2) - { + { QSize sz = widget->size(); error = (sz.width() != entries[0].toInt() || sz.height() != entries[1].toInt()); if (error) - { + { qCritical() << "Size mismatch: (" << arguments << ") != " << sz; - } - return true; } + return true; } } + } return false; } -bool pqWidgetEventPlayer::playEvent(QObject* object, const QString& command, - const QString& arguments, int eventType, bool& error) +bool pqWidgetEventPlayer::playEvent( + QObject* object, const QString& command, const QString& arguments, int eventType, bool& error) { if (eventType == pqEventTypes::ACTION_EVENT) - { + { return this->playEvent(object, command, arguments, error); - } + } return false; } - diff --git a/pqWidgetEventPlayer.h b/pqWidgetEventPlayer.h index d2ffe3b..8596ac7 100644 --- a/pqWidgetEventPlayer.h +++ b/pqWidgetEventPlayer.h @@ -7,7 +7,7 @@ All rights reserved. ParaView is a free software; you can redistribute it and/or modify it - under the terms of the ParaView license version 1.2. + under the terms of the ParaView license version 1.2. See License_v1.2.txt for the full ParaView license. A copy of this license can be obtained by contacting @@ -58,18 +58,9 @@ public: returning "true" if they handled the command, and setting Error to "true" if there were any problems. */ virtual bool playEvent( - QObject* object, - const QString& command, - const QString& arguments, - bool& error); + QObject* object, const QString& command, const QString& arguments, bool& error); virtual bool playEvent( - QObject* object, - const QString& command, - const QString& arguments, - int eventType, - bool& error); - + QObject* object, const QString& command, const QString& arguments, int eventType, bool& error); }; #endif // !_pqWidgetEventPlayer_h - diff --git a/pqWidgetEventTranslator.cxx b/pqWidgetEventTranslator.cxx index ea7dea2..d75f218 100644 --- a/pqWidgetEventTranslator.cxx +++ b/pqWidgetEventTranslator.cxx @@ -45,27 +45,26 @@ pqWidgetEventTranslator::~pqWidgetEventTranslator() { } -bool pqWidgetEventTranslator::translateEvent( - QObject* object, QEvent* event, bool& error) +bool pqWidgetEventTranslator::translateEvent(QObject* object, QEvent* event, bool& error) { QWidget* widget = qobject_cast<QWidget*>(object); - if(!widget) - { + if (!widget) + { return false; - } + } - switch(event->type()) - { + switch (event->type()) + { case QEvent::ContextMenu: - { + { emit recordEvent(widget, "contextMenu", ""); break; - } + } default: - { + { break; - } } + } return true; } @@ -74,8 +73,8 @@ bool pqWidgetEventTranslator::translateEvent( QObject* object, QEvent* event, int eventType, bool& error) { if (eventType == pqEventTypes::ACTION_EVENT) - { + { return this->translateEvent(object, event, error); - } + } return false; } diff --git a/pqWidgetEventTranslator.h b/pqWidgetEventTranslator.h index 06b46ee..373dcbc 100644 --- a/pqWidgetEventTranslator.h +++ b/pqWidgetEventTranslator.h @@ -7,7 +7,7 @@ All rights reserved. ParaView is a free software; you can redistribute it and/or modify it - under the terms of the ParaView license version 1.2. + under the terms of the ParaView license version 1.2. See License_v1.2.txt for the full ParaView license. A copy of this license can be obtained by contacting @@ -44,16 +44,16 @@ events, for test-cases, demos, tutorials, etc. \sa pqEventTranslator */ -class QTTESTING_EXPORT pqWidgetEventTranslator : - public QObject +class QTTESTING_EXPORT pqWidgetEventTranslator : public QObject { Q_OBJECT - + typedef QObject Superclass; + public: - pqWidgetEventTranslator(QObject* p=0); + pqWidgetEventTranslator(QObject* p = 0); ~pqWidgetEventTranslator() override; - + /** Derivatives should implement this and translate events into commands, returning "true" if they handled the event, and setting Error to "true" if there were any problems. eventType allow to specify different types of events @@ -63,7 +63,8 @@ public: signals: /// Derivatives should emit this signal whenever they wish to record a high-level event - void recordEvent(QObject* Object, const QString& Command, const QString& Arguments, int eventType); + void recordEvent( + QObject* Object, const QString& Command, const QString& Arguments, int eventType); void recordEvent(QObject* Object, const QString& Command, const QString& Arguments); void specificOverlay(const QRect& geometry); @@ -73,4 +74,3 @@ protected: }; #endif // !_pqWidgetEventTranslator_h - -- GitLab