Commit 3d77505b authored by Benjamin Long's avatar Benjamin Long

Added Testing to QtTesting and 2 Tests, following QtTest style

Added two first test :
  pqEventTranslatorTest following "QtTest" style.
  pqEventPlayerTest following "QtTest" style.

Renamed ctkTest.h into pqTest.h to have the same syntax as qttesting.

Fixed bugs in pqEventPlayer/Translator, to not be able to add twice a
same Player/Translator.
parent 58ff7a8d
......@@ -258,8 +258,14 @@ INSTALL(TARGETS QtTesting
LIBRARY DESTINATION ${QtTesting_INSTALL_LIB_DIR} COMPONENT Runtime
ARCHIVE DESTINATION ${QtTesting_INSTALL_LIB_DIR} COMPONENT Development)
add_subdirectory(Examples)
include(CTest)
IF(BUILD_TESTING)
add_subdirectory(Testing)
ENDIF()
export(TARGETS QtTesting FILE ${QtTesting_BINARY_DIR}/QtTestingExports.cmake)
# Set up the build export configuration
......
# QT4_GENERATE_MOCS(inputfile1 [inputfile2 ...])
macro(QT4_GENERATE_MOCS)
foreach(file ${ARGN})
set(moc_file moc_${file})
QT4_GENERATE_MOC(${file} ${moc_file})
macro_add_file_dependencies(${file} ${CMAKE_CURRENT_BINARY_DIR}/${moc_file})
endforeach()
endmacro()
add_subdirectory(Cpp)
include(../CMake/qtTestingMacroGenerateMocs.cmake)
set(KIT ${PROJECT_NAME})
set(TEST_SOURCES
pqEventPlayerTest.cpp
pqEventTranslatorTest.cpp
)
create_test_sourcelist(Tests ${KIT}CppTests.cxx
${TEST_SOURCES}
)
set(TestsToRun ${Tests})
remove(TestsToRun ${KIT}CppTests.cxx)
include_directories(
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_SOURCE_DIR}
)
QT4_GENERATE_MOCS(${TEST_SOURCES})
add_executable(${KIT}CppTests ${Tests})
target_link_libraries(${KIT}CppTests ${PROJECT_NAME} ${QT_QTTEST_LIBRARY})
macro(SIMPLE_TEST testname)
add_test(NAME ${testname} COMMAND $<TARGET_FILE:${KIT}CppTests> ${Testname} ${ARGN})
endmacro()
#
# Add Tests
#
SIMPLE_TEST( pqEventPlayerTest )
SIMPLE_TEST( pqEventTranslatorTest )
/*=========================================================================
Program: ParaView
Module: pqEventPlayer.h
Copyright (c) 2005-2008 Sandia Corporation, Kitware Inc.
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.
See License_v1.2.txt for the full ParaView license.
A copy of this license can be obtained by contacting
Kitware Inc.
28 Corporate Drive
Clifton Park, NY 12065
USA
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=========================================================================*/
// Qt includes
#include <QApplication>
// QtTesting includes
#include "pqCommentEventPlayer.h"
#include "pqEventPlayer.h"
#include "pqTestUtility.h"
#include "pqTreeViewEventPlayer.h"
#include "pqTest.h"
// ----------------------------------------------------------------------------
class pqEventPlayerTester: public QObject
{
Q_OBJECT
private Q_SLOTS:
void testDefaults();
void testAddWidgetEventPlayer();
void testAddWidgetEventPlayer_data();
void testRemoveWidgetEventPlayer();
void testRemoveWidgetEventPlayer_data();
void testGetWidgetEventPlayer();
void testAddDefaultWidgetEventPlayers();
void testAddDefaultWidgetEventPlayers_data();
};
// ----------------------------------------------------------------------------
void pqEventPlayerTester::testDefaults()
{
pqEventPlayer eventPlayer;
QCOMPARE(eventPlayer.players().count(), 0);
}
// ----------------------------------------------------------------------------
void pqEventPlayerTester::testAddWidgetEventPlayer()
{
pqEventPlayer eventPlayer;
QFETCH(QObject*, widget1);
QFETCH(int, newCount1);
QFETCH(QObject*, widget2);
QFETCH(int, newCount2);
// When we add the widgetEventPlayer into the eventPlayer, it is automaticaly
// reparented to the eventPlayer. So its deletion would be automatic.
eventPlayer.addWidgetEventPlayer(qobject_cast<pqWidgetEventPlayer*>(widget1));
QCOMPARE(eventPlayer.players().count(), newCount1);
eventPlayer.addWidgetEventPlayer(qobject_cast<pqWidgetEventPlayer*>(widget2));
QCOMPARE(eventPlayer.players().count(), newCount2);
}
// ----------------------------------------------------------------------------
void pqEventPlayerTester::testAddWidgetEventPlayer_data()
{
QTest::addColumn<QObject*>("widget1");
QTest::addColumn<int>("newCount1");
QTest::addColumn<QObject*>("widget2");
QTest::addColumn<int>("newCount2");
pqWidgetEventPlayer* nullWidget = NULL;
QTest::newRow("empty_empty")
<< qobject_cast<QObject*>(nullWidget) << 0
<< qobject_cast<QObject*>(nullWidget) << 0;
QTest::newRow("empty_pqComment")
<< qobject_cast<QObject*>(nullWidget) << 0
<< qobject_cast<QObject*>(new pqCommentEventPlayer()) << 1;
QTest::newRow("pqComment_pqComment")
<< qobject_cast<QObject*>(new pqCommentEventPlayer()) << 1
<< qobject_cast<QObject*>(new pqCommentEventPlayer()) << 1;
QTest::newRow("pqComment_pqTreeView")
<< qobject_cast<QObject*>(new pqCommentEventPlayer()) << 1
<< qobject_cast<QObject*>(new pqTreeViewEventPlayer()) << 2;
}
// ----------------------------------------------------------------------------
void pqEventPlayerTester::testRemoveWidgetEventPlayer()
{
pqEventPlayer eventPlayer;
QFETCH(QString, nameToRemove);
QFETCH(bool, firstResult);
QFETCH(bool, secondResult);
QFETCH(int, newCount);
QFETCH(bool, thirdResult);
QCOMPARE(eventPlayer.removeWidgetEventPlayer(nameToRemove),
firstResult);
// When we add the widgetEventPlayer into the eventPlayer, it is automaticaly
// reparented to the eventPlayer. So its deletion would be automatic.
pqCommentEventPlayer* commentPlayer = new pqCommentEventPlayer();
eventPlayer.addWidgetEventPlayer(commentPlayer);
QCOMPARE(eventPlayer.players().count(), 1);
QCOMPARE(eventPlayer.removeWidgetEventPlayer(nameToRemove),
secondResult);
QCOMPARE(eventPlayer.players().count(), newCount);
QCOMPARE(eventPlayer.removeWidgetEventPlayer(nameToRemove),
thirdResult);
}
// ----------------------------------------------------------------------------
void pqEventPlayerTester::testRemoveWidgetEventPlayer_data()
{
QTest::addColumn<QString>("nameToRemove");
QTest::addColumn<bool>("firstResult");
QTest::addColumn<bool>("secondResult");
QTest::addColumn<int>("newCount");
QTest::addColumn<bool>("thirdResult");
QTest::newRow("empty") << "" << false << false << 1 << false;
QTest::newRow("wrong") << "pqTreeViewEventPlayer" << false << false << 1 << false;
QTest::newRow("right") << "pqCommentEventPlayer" << false << true << 0 << false;
}
// ----------------------------------------------------------------------------
void pqEventPlayerTester::testGetWidgetEventPlayer()
{
pqEventPlayer eventPlayer;
pqWidgetEventPlayer* nullWidget = NULL;
QCOMPARE(eventPlayer.getWidgetEventPlayer(0),
nullWidget);
QCOMPARE(eventPlayer.getWidgetEventPlayer("pqCommentEventPlayer"),
nullWidget);
// When we add the widgetEventPlayer into the eventPlayer, it is automaticaly
// reparented to the eventPlayer. So its deletion would be automatic.
pqCommentEventPlayer* comment = new pqCommentEventPlayer();
eventPlayer.addWidgetEventPlayer(comment);
QCOMPARE(eventPlayer.getWidgetEventPlayer(0),
nullWidget);
QCOMPARE(eventPlayer.getWidgetEventPlayer("pqTreeViewEventPlayer"),
nullWidget);
QCOMPARE(eventPlayer.getWidgetEventPlayer("pqCommentEventPlayer"),
comment);
}
// ----------------------------------------------------------------------------
void pqEventPlayerTester::testAddDefaultWidgetEventPlayers()
{
pqEventPlayer eventPlayer;
pqTestUtility testUtility;
eventPlayer.addDefaultWidgetEventPlayers(&testUtility);
QList<pqWidgetEventPlayer*> players = eventPlayer.players();
QFETCH(QString, widgetEventPlayerName);
QFETCH(int, index);
QCOMPARE(QString(players.at(index)->metaObject()->className()),
widgetEventPlayerName);
}
// ----------------------------------------------------------------------------
void pqEventPlayerTester::testAddDefaultWidgetEventPlayers_data()
{
QTest::addColumn<int>("index");
QTest::addColumn<QString>("widgetEventPlayerName");
QTest::newRow("0") << 0 << "pqNativeFileDialogEventPlayer";
QTest::newRow("1") << 1 << "pq3DViewEventPlayer";
QTest::newRow("2") << 2 << "pqAbstractMiscellaneousEventPlayer";
QTest::newRow("3") << 3 << "pqTreeViewEventPlayer";
QTest::newRow("4") << 4 << "pqTabBarEventPlayer";
QTest::newRow("5") << 5 << "pqAbstractStringEventPlayer";
QTest::newRow("6") << 6 << "pqAbstractItemViewEventPlayer";
QTest::newRow("7") << 7 << "pqAbstractIntEventPlayer";
QTest::newRow("8") << 8 << "pqAbstractDoubleEventPlayer";
QTest::newRow("9") << 9 << "pqAbstractBooleanEventPlayer";
QTest::newRow("10") << 10 << "pqAbstractActivateEventPlayer";
QTest::newRow("11") << 11 << "pqBasicWidgetEventPlayer";
QTest::newRow("12") << 12 << "pqCommentEventPlayer";
}
// ----------------------------------------------------------------------------
CTK_TEST_MAIN(pqEventPlayerTest)
#include "moc_pqEventPlayerTest.cpp"
/*=========================================================================
Program: ParaView
Module: pqEventPlayer.h
Copyright (c) 2005-2008 Sandia Corporation, Kitware Inc.
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.
See License_v1.2.txt for the full ParaView license.
A copy of this license can be obtained by contacting
Kitware Inc.
28 Corporate Drive
Clifton Park, NY 12065
USA
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=========================================================================*/
// Qt includes
#include <QApplication>
// QtTesting includes
#include "pqEventTranslator.h"
#include "pqSpinBoxEventTranslator.h"
#include "pqTestUtility.h"
#include "pqTreeViewEventTranslator.h"
#include "pqTest.h"
// ----------------------------------------------------------------------------
class pqEventTranslatorTester : public QObject
{
Q_OBJECT
private Q_SLOTS:
void testDefaults();
void testAddWidgetEventTranslator();
void testAddWidgetEventTranslator_data();
void testRemoveWidgetEventTranslator();
void testRemoveWidgetEventTranslator_data();
void testGetWidgetEventTranslator();
void testAddDefaultWidgetEventTranslators();
void testAddDefaultWidgetEventTranslators_data();
};
// ----------------------------------------------------------------------------
void pqEventTranslatorTester::testDefaults()
{
pqEventTranslator eventTranslator;
QCOMPARE(eventTranslator.translators().count(), 0);
}
// ----------------------------------------------------------------------------
void pqEventTranslatorTester::testAddWidgetEventTranslator()
{
pqEventTranslator eventTranslator;
QFETCH(QObject*, widget1);
QFETCH(int, newCount1);
QFETCH(QObject*, widget2);
QFETCH(int, newCount2);
// When we add the widgetEventPlayer into the eventPlayer, it is automaticaly
// reparented to the eventPlayer. So its deletion would be automatic.
eventTranslator.addWidgetEventTranslator(
dynamic_cast<pqWidgetEventTranslator*>(widget1));
QCOMPARE(eventTranslator.translators().count(), newCount1);
eventTranslator.addWidgetEventTranslator(
dynamic_cast<pqWidgetEventTranslator*>(widget2));
QCOMPARE(eventTranslator.translators().count(), newCount2);
}
// ----------------------------------------------------------------------------
void pqEventTranslatorTester::testAddWidgetEventTranslator_data()
{
QTest::addColumn<QObject*>("widget1");
QTest::addColumn<int>("newCount1");
QTest::addColumn<QObject*>("widget2");
QTest::addColumn<int>("newCount2");
pqWidgetEventTranslator* nullWidget = NULL;
QTest::newRow("empty_empty")
<< qobject_cast<QObject*>(nullWidget) << 0
<< qobject_cast<QObject*>(nullWidget) << 0;
QTest::newRow("empty_pqSpinBox")
<< qobject_cast<QObject*>(nullWidget) << 0
<< qobject_cast<QObject*>(new pqSpinBoxEventTranslator()) << 1;
QTest::newRow("pqSpinBox_pqSpinBox")
<< qobject_cast<QObject*>(new pqSpinBoxEventTranslator()) << 1
<< qobject_cast<QObject*>(new pqSpinBoxEventTranslator()) << 1;
QTest::newRow("pqSpinBox_pqTreeView")
<< qobject_cast<QObject*>(new pqSpinBoxEventTranslator()) << 1
<< qobject_cast<QObject*>(new pqTreeViewEventTranslator()) << 2;
}
// ----------------------------------------------------------------------------
void pqEventTranslatorTester::testRemoveWidgetEventTranslator()
{
pqEventTranslator eventTranslator;
QFETCH(QString, nameToRemove);
QFETCH(bool, firstResult);
QFETCH(bool, secondResult);
QFETCH(int, newCount);
QFETCH(bool, thirdResult);
QCOMPARE(eventTranslator.removeWidgetEventTranslator(nameToRemove),
firstResult);
// When we add the widgetEventPlayer into the eventPlayer, it is automaticaly
// reparented to the eventPlayer. So its deletion would be automatic.
pqTreeViewEventTranslator* treeView = new pqTreeViewEventTranslator();
eventTranslator.addWidgetEventTranslator(treeView);
QCOMPARE(eventTranslator.translators().count(), 1);
QCOMPARE(eventTranslator.removeWidgetEventTranslator(nameToRemove),
secondResult);
QCOMPARE(eventTranslator.translators().count(), newCount);
QCOMPARE(eventTranslator.removeWidgetEventTranslator(nameToRemove),
thirdResult);
}
// ----------------------------------------------------------------------------
void pqEventTranslatorTester::testRemoveWidgetEventTranslator_data()
{
QTest::addColumn<QString>("nameToRemove");
QTest::addColumn<bool>("firstResult");
QTest::addColumn<bool>("secondResult");
QTest::addColumn<int>("newCount");
QTest::addColumn<bool>("thirdResult");
QTest::newRow("empty") << "" << false << false << 1 << false;
QTest::newRow("wrong") << "pqSpinBoxEventTranslator" << false << false << 1 << false;
QTest::newRow("right") << "pqTreeViewEventTranslator" << false << true << 0 << false;
}
// ----------------------------------------------------------------------------
void pqEventTranslatorTester::testGetWidgetEventTranslator()
{
pqEventTranslator eventTranslator;
pqSpinBoxEventTranslator* nullWidget = NULL;
QCOMPARE(eventTranslator.getWidgetEventTranslator(0),
nullWidget);
QCOMPARE(eventTranslator.getWidgetEventTranslator("pqSpinBoxEventTranslator"),
nullWidget);
// When we add the widgetEventPlayer into the eventPlayer, it is automaticaly
// reparented to the eventPlayer. So its deletion would be automatic.
pqSpinBoxEventTranslator* spinBox = new pqSpinBoxEventTranslator();
eventTranslator.addWidgetEventTranslator(spinBox);
QCOMPARE(eventTranslator.getWidgetEventTranslator(0),
nullWidget);
QCOMPARE(eventTranslator.getWidgetEventTranslator("pqTreeViewEventTranslator"),
nullWidget);
QCOMPARE(eventTranslator.getWidgetEventTranslator("pqSpinBoxEventTranslator"),
spinBox);
}
// ----------------------------------------------------------------------------
void pqEventTranslatorTester::testAddDefaultWidgetEventTranslators()
{
pqEventTranslator eventTranslator;
pqTestUtility testUtility;
eventTranslator.addDefaultWidgetEventTranslators(&testUtility);
QList<pqWidgetEventTranslator*> translators = eventTranslator.translators();
QFETCH(int, index);
QFETCH(QString, widgetEventTranslatorName);
QCOMPARE(QString(translators.at(index)->metaObject()->className()),
widgetEventTranslatorName);
}
// ----------------------------------------------------------------------------
void pqEventTranslatorTester::testAddDefaultWidgetEventTranslators_data()
{
QTest::addColumn<int>("index");
QTest::addColumn<QString>("widgetEventTranslatorName");
QTest::newRow("0") << 0 << "pqNativeFileDialogEventTranslator";
QTest::newRow("1") << 1 << "pq3DViewEventTranslator";
QTest::newRow("2") << 2 << "pqTreeViewEventTranslator";
QTest::newRow("3") << 3 << "pqTabBarEventTranslator";
QTest::newRow("4") << 4 << "pqSpinBoxEventTranslator";
QTest::newRow("5") << 5 << "pqMenuEventTranslator";
QTest::newRow("6") << 6 << "pqLineEditEventTranslator";
QTest::newRow("7") << 7 << "pqDoubleSpinBoxEventTranslator";
QTest::newRow("8") << 8 << "pqComboBoxEventTranslator";
QTest::newRow("9") << 9 << "pqAbstractSliderEventTranslator";
QTest::newRow("10") << 10 << "pqAbstractItemViewEventTranslator";
QTest::newRow("11") << 11 << "pqAbstractButtonEventTranslator";
QTest::newRow("12") << 12 << "pqBasicWidgetEventTranslator";
}
// ----------------------------------------------------------------------------
CTK_TEST_MAIN(pqEventTranslatorTest)
#include "moc_pqEventTranslatorTest.cpp"
/*=========================================================================
Library: CTK
Copyright (c) Kitware Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0.txt
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
=========================================================================*/
/*=========================================================================
Program: ParaView
Module: pqEventPlayer.h
Copyright (c) 2005-2008 Sandia Corporation, Kitware Inc.
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.
See License_v1.2.txt for the full ParaView license.
A copy of this license can be obtained by contacting
Kitware Inc.
28 Corporate Drive
Clifton Park, NY 12065
USA
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=========================================================================*/
// Qt includes
#include <QtTest/QtTest>
#define CTK_TEST_NOOP_MAIN(TestObject) \
int TestObject(int argc, char *argv[]) \
{ \
QObject tc; \
return QTest::qExec(&tc, argc, argv); \
}
#ifdef QT_GUI_LIB
//-----------------------------------------------------------------------------
#define CTK_TEST_MAIN(TestObject) \
int TestObject(int argc, char *argv[]) \
{ \
QApplication app(argc, argv); \
TestObject##er tc; \
return QTest::qExec(&tc, argc, argv); \
}
#else
//-----------------------------------------------------------------------------
#define CTK_TEST_MAIN(TestObject) \
int TestObject(int argc, char *argv[]) \
{ \
QCoreApplication app(argc, argv); \
QTEST_DISABLE_KEYPAD_NAVIGATION \
TestObject##er tc; \
return QTest::qExec(&tc, argc, argv); \
}
#endif // QT_GUI_LIB
namespace ctkTest
{
static void mouseEvent(QTest::MouseAction action, QWidget *widget, Qt::MouseButton button,
Qt::KeyboardModifiers stateKey, QPoint pos, int delay=-1)
{
if (action != QTest::MouseMove)
{
QTest::mouseEvent(action, widget, button, stateKey, pos, delay);
return;
}
QTEST_ASSERT(widget);
//extern int Q_TESTLIB_EXPORT defaultMouseDelay();
//if (delay == -1 || delay < defaultMouseDelay())
// delay = defaultMouseDelay();
if (delay > 0)
QTest::qWait(delay);
if (pos.isNull())
pos = widget->rect().center();
QTEST_ASSERT(button == Qt::NoButton || button & Qt::MouseButtonMask);
QTEST_ASSERT(stateKey == 0 || stateKey & Qt::KeyboardModifierMask);
stateKey &= static_cast<unsigned int>(Qt::KeyboardModifierMask);
QMouseEvent me(QEvent::User, QPoint(), Qt::LeftButton, button, stateKey);
me = QMouseEvent(QEvent::MouseMove, pos, widget->mapToGlobal(pos), button, button, stateKey);
QSpontaneKeyEvent::setSpontaneous(&me);
if (!qApp->notify(widget, &me))
{
static const char *mouseActionNames[] =
{ "MousePress", "MouseRelease", "MouseClick", "MouseDClick", "MouseMove" };
QString warning = QString::fromLatin1("Mouse event \"%1\" not accepted by receiving widget");
QTest::qWarn(warning.arg(QString::fromLatin1(mouseActionNames[static_cast<int>(action)])).toAscii().data());
}
}
inline void mouseMove(QWidget *widget, Qt::MouseButton button, Qt::KeyboardModifiers stateKey = 0,
QPoint pos = QPoint(), int delay=-1)
{ ctkTest::mouseEvent(QTest::MouseMove, widget, button, stateKey, pos, delay); }
}
......@@ -76,7 +76,13 @@ void pqEventPlayer::addDefaultWidgetEventPlayers(pqTestUtility* util)
addWidgetEventPlayer(new pqTreeViewEventPlayer());
addWidgetEventPlayer(new pqAbstractMiscellaneousEventPlayer());
addWidgetEventPlayer(new pq3DViewEventPlayer("QGLWidget"));
//addWidgetEventPlayer(new pqNativeFileDialogEventPlayer(util));
addWidgetEventPlayer(new pqNativeFileDialogEventPlayer(util));
}
// ----------------------------------------------------------------------------
QList<pqWidgetEventPlayer*> pqEventPlayer::players() const
{
return this->Players;
}
// ----------------------------------------------------------------------------
......@@ -84,6 +90,14 @@ void pqEventPlayer::addWidgetEventPlayer(pqWidgetEventPlayer* Player)
{
if(Player)
{
// We Check if the Player has already been added previously
int index =
this->getWidgetEventPlayerIndex(QString(Player->metaObject()->className()));
if (index != -1)
{
return;
}
this->Players.push_front(Player);
Player->setParent(this);
}
......
......@@ -90,16 +90,19 @@ public:
/** Method to get a specific player */
pqWidgetEventPlayer* getWidgetEventPlayer(const QString& className);
/** Method to return the list of widget event players added previously*/
QList<pqWidgetEventPlayer*> players() const;
/** This method is called with each high-level ParaView event, which
will invoke the corresponding low-level Qt functionality in-turn.
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). */
void playEvent(const QString& Object,
const QString& Command,
const QString& Arguments,
bool& Error);
void playEvent(const QString& Object,
const QString& Command,
const QString& Arguments,
bool& Error);
signals:
void eventAboutToBePlayed(const QString& Object,
......
......@@ -62,7 +62,7 @@ struct pqEventTranslator::pqImplementation
}
/// Stores the working set of widget translators
QVector<pqWidgetEventTranslator*> Translators;
QList<pqWidgetEventTranslator*> Translators;
/// Stores the set of objects that should be ignored when translating events
QSet<QObject*> IgnoredObjects;
......@@ -117,7 +117,7 @@ void pqEventTranslator::addDefaultWidgetEventTranslators(pqTestUtility* util)
addWidgetEventTranslator(new pqTabBarEventTranslator());
addWidgetEventTranslator(new pqTreeViewEventTranslator());
addWidgetEventTranslator(new pq3DViewEventTranslator("QGLWidget"));
//addWidgetEventTranslator(new pqNativeFileDialogEventTranslator(util));
addWidgetEventTranslator(new pqNativeFileDialogEventTranslator(util));
}
// ----------------------------------------------------------------------------
......@@ -125,6 +125,14 @@ void pqEventTranslator::addWidgetEventTranslator(pqWidgetEventTranslator* Transl
{
if(Translator)
{
// We Check if the translator has already been added previously.
int index =
this->getWidgetEventTranslatorIndex(Translator->metaObject()->className());
if (index != -1)
{
return;
}
this->Implementation->Translators.push_front(Translator);
Translator->setParent(this);
......@@ -145,7 +153,7 @@ bool pqEventTranslator::removeWidgetEventTranslator(const QString& className)
return false;
}
this->Implementation->Translators.remove(index);
this->Implementation->Translators.removeAt(index);
return true;