1// Qt includes
2#include <QDebug>
3
4// CTKTesting includes
5#include "ctkQtTestingUtility.h"
6#include <pqEventSource.h>  // for pqEventTypes
7
8@CTK_ADD_HEADER_EVENT_PLAYERS@
9
10@CTK_ADD_HEADER_EVENT_TRANSLATORS@
11
12//-----------------------------------------------------------------------------
13ctkQtTestingUtility::ctkQtTestingUtility(QObject* p)
14  : Superclass(p)
15{
16  this->addDefaultCTKWidgetEventTranslatorsToTranslator(this);
17  this->addDefaultCTKWidgetEventPlayersToPlayer(this);
18}
19
20//-----------------------------------------------------------------------------
21ctkQtTestingUtility::~ctkQtTestingUtility()
22{
23}
24
25//-----------------------------------------------------------------------------
26void ctkQtTestingUtility::addDefaultCTKWidgetEventTranslatorsToTranslator(pqTestUtility* util)
27{
28  Q_UNUSED(util);
29@CTK_ADD_WIDGET_EVENT_TRANSLATORS@
30  pqWidgetEventTranslator* translator = this->eventTranslator()->getWidgetEventTranslator(
31    QLatin1String("pqNativeFileDialogEventTranslator"));
32  if (translator)
33    {
34    this->eventTranslator()->removeWidgetEventTranslator(
35      QLatin1String("pqNativeFileDialogEventTranslator"));
36    delete translator;
37    }
38}
39
40//-----------------------------------------------------------------------------
41void ctkQtTestingUtility::addDefaultCTKWidgetEventPlayersToPlayer(pqTestUtility* util)
42{
43  Q_UNUSED(util);
44@CTK_ADD_WIDGET_EVENT_PLAYERS@
45  pqWidgetEventPlayer* player = this->eventPlayer()->getWidgetEventPlayer(
46    QLatin1String("pqNativeFileDialogEventPlayer"));
47  if (player)
48    {
49    this->eventPlayer()->removeWidgetEventPlayer(
50      QLatin1String("pqNativeFileDialogEventPlayer"));
51    delete player;
52    }
53}
54
55//-----------------------------------------------------------------------------
56void ctkQtTestingUtility::addTranslator(pqWidgetEventTranslator* translator)
57{
58  if(translator)
59    {
60    this->eventTranslator()->addWidgetEventTranslator(translator);
61    }
62}
63
64//-----------------------------------------------------------------------------
65void ctkQtTestingUtility::addPlayer(pqWidgetEventPlayer* player)
66{
67  if(player)
68    {
69    this->eventPlayer()->addWidgetEventPlayer(player);
70    }
71}
72
73//-----------------------------------------------------------------------------
74QString ctkQtTestingUtility::eventTypeToString(int eventType)
75{
76  switch (eventType)
77    {
78    case pqEventTypes::ACTION_EVENT:
79      return QString("action");
80    case pqEventTypes::CHECK_EVENT:
81      return QString("check");
82    default:
83      return QString("unknown");
84    }
85}
86
87//-----------------------------------------------------------------------------
88int ctkQtTestingUtility::eventTypeFromString(const QString& eventTypeStr)
89{
90  if (!eventTypeStr.compare("action", Qt::CaseInsensitive))
91    {
92    return pqEventTypes::ACTION_EVENT;
93    }
94  else if (!eventTypeStr.compare("check", Qt::CaseInsensitive))
95    {
96    return pqEventTypes::CHECK_EVENT;
97    }
98  else
99    {
100    // unknown event type name
101    return -1;
102    }
103}
104