testlib: Remove widgets dependency when only using gui
There's api in testlib that should only be available if the application links against widgets. Change-Id: I22e382c6710690866ed8ffed81bae27b548dc830 Reviewed-on: http://codereview.qt-project.org/5094 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Jo Asplin <jo.asplin@nokia.com> Reviewed-by: Matthew Cattell <matthew.cattell@nokia.com>bb10
parent
a097825b21
commit
d372a9f370
|
|
@ -74,6 +74,7 @@ QT_MODULE(Test)
|
|||
namespace QTest
|
||||
{
|
||||
|
||||
#ifdef QT_WIDGETS_LIB
|
||||
template<>
|
||||
inline bool qCompare(QIcon const &t1, QIcon const &t2, const char *actual, const char *expected,
|
||||
const char *file, int line)
|
||||
|
|
@ -82,6 +83,7 @@ inline bool qCompare(QIcon const &t1, QIcon const &t2, const char *actual, const
|
|||
return qCompare<void *>(*reinterpret_cast<void * const *>(&t1),
|
||||
*reinterpret_cast<void * const *>(&t2), actual, expected, file, line);
|
||||
}
|
||||
#endif
|
||||
|
||||
template<>
|
||||
inline bool qCompare(QPixmap const &t1, QPixmap const &t2, const char *actual, const char *expected,
|
||||
|
|
|
|||
|
|
@ -67,7 +67,9 @@ QT_MODULE(Test)
|
|||
class QTestEvent
|
||||
{
|
||||
public:
|
||||
#ifdef QT_WIDGETS_LIB
|
||||
virtual void simulate(QWidget *w) = 0;
|
||||
#endif
|
||||
virtual QTestEvent *clone() const = 0;
|
||||
|
||||
virtual ~QTestEvent() {}
|
||||
|
|
@ -84,6 +86,7 @@ public:
|
|||
_ascii(ascii), _key(Qt::Key_unknown) {}
|
||||
inline QTestEvent *clone() const { return new QTestKeyEvent(*this); }
|
||||
|
||||
#ifdef QT_WIDGETS_LIB
|
||||
inline void simulate(QWidget *w)
|
||||
{
|
||||
if (_ascii == 0)
|
||||
|
|
@ -91,6 +94,7 @@ public:
|
|||
else
|
||||
QTest::keyEvent(_action, w, _ascii, _modifiers, _delay);
|
||||
}
|
||||
#endif
|
||||
|
||||
protected:
|
||||
QTest::KeyAction _action;
|
||||
|
|
@ -107,10 +111,12 @@ public:
|
|||
: _keys(keys), _modifiers(modifiers), _delay(delay) {}
|
||||
inline QTestEvent *clone() const { return new QTestKeyClicksEvent(*this); }
|
||||
|
||||
#ifdef QT_WIDGETS_LIB
|
||||
inline void simulate(QWidget *w)
|
||||
{
|
||||
QTest::keyClicks(w, _keys, _modifiers, _delay);
|
||||
}
|
||||
#endif
|
||||
|
||||
private:
|
||||
QString _keys;
|
||||
|
|
@ -126,10 +132,12 @@ public:
|
|||
: _action(action), _button(button), _modifiers(modifiers), _pos(position), _delay(delay) {}
|
||||
inline QTestEvent *clone() const { return new QTestMouseEvent(*this); }
|
||||
|
||||
#ifdef QT_WIDGETS_LIB
|
||||
inline void simulate(QWidget *w)
|
||||
{
|
||||
QTest::mouseEvent(_action, w, _button, _modifiers, _pos, _delay);
|
||||
}
|
||||
#endif
|
||||
|
||||
private:
|
||||
QTest::MouseAction _action;
|
||||
|
|
@ -147,7 +155,9 @@ public:
|
|||
inline QTestDelayEvent(int msecs): _delay(msecs) {}
|
||||
inline QTestEvent *clone() const { return new QTestDelayEvent(*this); }
|
||||
|
||||
#ifdef QT_WIDGETS_LIB
|
||||
inline void simulate(QWidget * /*w*/) { QTest::qWait(_delay); }
|
||||
#endif
|
||||
|
||||
private:
|
||||
int _delay;
|
||||
|
|
@ -205,11 +215,13 @@ public:
|
|||
inline void addDelay(int msecs)
|
||||
{ append(new QTestDelayEvent(msecs)); }
|
||||
|
||||
#ifdef QT_WIDGETS_LIB
|
||||
inline void simulate(QWidget *w)
|
||||
{
|
||||
for (int i = 0; i < count(); ++i)
|
||||
at(i)->simulate(w);
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
|
|
|||
|
|
@ -68,6 +68,7 @@ namespace QTest
|
|||
{
|
||||
enum KeyAction { Press, Release, Click };
|
||||
|
||||
#ifdef QT_WIDGETS_LIB
|
||||
static void simulateEvent(QWidget *widget, bool press, int code,
|
||||
Qt::KeyboardModifiers modifier, QString text, bool repeat, int delay=-1)
|
||||
{
|
||||
|
|
@ -84,6 +85,7 @@ namespace QTest
|
|||
if (!qApp->notify(widget, &a))
|
||||
QTest::qWarn("Keyboard event not accepted by receiving widget");
|
||||
}
|
||||
#endif
|
||||
//QWindow overload
|
||||
static void simulateEvent(QWindow *window, bool press, int code,
|
||||
Qt::KeyboardModifiers modifier, QString text, bool repeat, int delay=-1)
|
||||
|
|
@ -93,6 +95,7 @@ namespace QTest
|
|||
QWindowSystemInterface::handleKeyEvent(window, type, code, modifier, text, repeat, delay);
|
||||
}
|
||||
|
||||
#ifdef QT_WIDGETS_LIB
|
||||
static void sendKeyEvent(KeyAction action, QWidget *widget, Qt::Key code,
|
||||
QString text, Qt::KeyboardModifiers modifier, int delay=-1)
|
||||
{
|
||||
|
|
@ -156,6 +159,7 @@ namespace QTest
|
|||
simulateEvent(widget, false, Qt::Key_Shift, modifier & Qt::ShiftModifier, QString(), false, delay);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
//QWindow overload
|
||||
static void sendKeyEvent(KeyAction action, QWindow *window, Qt::Key code,
|
||||
QString text, Qt::KeyboardModifiers modifier, int delay=-1)
|
||||
|
|
@ -203,6 +207,7 @@ namespace QTest
|
|||
}
|
||||
}
|
||||
|
||||
#ifdef QT_WIDGETS_LIB
|
||||
// Convenience function
|
||||
static void sendKeyEvent(KeyAction action, QWidget *widget, Qt::Key code,
|
||||
char ascii, Qt::KeyboardModifiers modifier, int delay=-1)
|
||||
|
|
@ -212,6 +217,7 @@ namespace QTest
|
|||
text = QString(QChar::fromLatin1(ascii));
|
||||
sendKeyEvent(action, widget, code, text, modifier, delay);
|
||||
}
|
||||
#endif
|
||||
// QWindow convenience function
|
||||
static void sendKeyEvent(KeyAction action, QWindow *window, Qt::Key code,
|
||||
char ascii, Qt::KeyboardModifiers modifier, int delay=-1)
|
||||
|
|
@ -222,12 +228,14 @@ namespace QTest
|
|||
sendKeyEvent(action, window, code, text, modifier, delay);
|
||||
}
|
||||
|
||||
#ifdef QT_WIDGETS_LIB
|
||||
inline static void keyEvent(KeyAction action, QWidget *widget, char ascii,
|
||||
Qt::KeyboardModifiers modifier = Qt::NoModifier, int delay=-1)
|
||||
{ sendKeyEvent(action, widget, asciiToKey(ascii), ascii, modifier, delay); }
|
||||
inline static void keyEvent(KeyAction action, QWidget *widget, Qt::Key key,
|
||||
Qt::KeyboardModifiers modifier = Qt::NoModifier, int delay=-1)
|
||||
{ sendKeyEvent(action, widget, key, keyToAscii(key), modifier, delay); }
|
||||
#endif
|
||||
|
||||
//Support QWindow
|
||||
inline static void keyEvent(KeyAction action, QWindow *window, char ascii,
|
||||
|
|
@ -237,6 +245,7 @@ namespace QTest
|
|||
Qt::KeyboardModifiers modifier = Qt::NoModifier, int delay=-1)
|
||||
{ sendKeyEvent(action, window, key, keyToAscii(key), modifier, delay); }
|
||||
///////////////
|
||||
#ifdef QT_WIDGETS_LIB
|
||||
inline static void keyClicks(QWidget *widget, const QString &sequence,
|
||||
Qt::KeyboardModifiers modifier = Qt::NoModifier, int delay=-1)
|
||||
{
|
||||
|
|
@ -256,6 +265,7 @@ namespace QTest
|
|||
{ keyEvent(Release, widget, key, modifier, delay); }
|
||||
inline static void keyClick(QWidget *widget, Qt::Key key, Qt::KeyboardModifiers modifier = Qt::NoModifier, int delay=-1)
|
||||
{ keyEvent(Click, widget, key, modifier, delay); }
|
||||
#endif
|
||||
//Support QWindow
|
||||
inline static void keyClick(QWindow *window, Qt::Key key, Qt::KeyboardModifiers modifier = Qt::NoModifier, int delay=-1)
|
||||
{ keyEvent(Click, window, key, modifier, delay); }
|
||||
|
|
|
|||
|
|
@ -68,6 +68,7 @@ namespace QTest
|
|||
{
|
||||
enum MouseAction { MousePress, MouseRelease, MouseClick, MouseDClick, MouseMove };
|
||||
|
||||
#ifdef QT_WIDGETS_LIB
|
||||
static void mouseEvent(MouseAction action, QWidget *widget, Qt::MouseButton button,
|
||||
Qt::KeyboardModifiers stateKey, QPoint pos, int delay=-1)
|
||||
{
|
||||
|
|
@ -125,6 +126,7 @@ namespace QTest
|
|||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
static void mouseEvent(MouseAction action, QWindow *window, Qt::MouseButton button,
|
||||
Qt::KeyboardModifiers stateKey, QPoint pos, int delay=-1)
|
||||
|
|
@ -186,6 +188,7 @@ namespace QTest
|
|||
}
|
||||
}
|
||||
|
||||
#ifdef QT_WIDGETS_LIB
|
||||
inline void mousePress(QWidget *widget, Qt::MouseButton button, Qt::KeyboardModifiers stateKey = 0,
|
||||
QPoint pos = QPoint(), int delay=-1)
|
||||
{ mouseEvent(MousePress, widget, button, stateKey, pos, delay); }
|
||||
|
|
@ -200,6 +203,7 @@ namespace QTest
|
|||
{ mouseEvent(MouseDClick, widget, button, stateKey, pos, delay); }
|
||||
inline void mouseMove(QWidget *widget, QPoint pos = QPoint(), int delay=-1)
|
||||
{ mouseEvent(MouseMove, widget, Qt::NoButton, 0, pos, delay); }
|
||||
#endif
|
||||
|
||||
//Support QWindow
|
||||
inline void mousePress(QWindow *window, Qt::MouseButton button, Qt::KeyboardModifiers stateKey = 0,
|
||||
|
|
|
|||
|
|
@ -62,9 +62,11 @@ QT_BEGIN_NAMESPACE
|
|||
|
||||
QT_MODULE(Test)
|
||||
|
||||
#ifdef QT_WIDGETS_LIB
|
||||
extern Q_GUI_EXPORT void qt_translateRawTouchEvent(QWidget *window,
|
||||
QTouchEvent::DeviceType deviceType,
|
||||
const QList<QTouchEvent::TouchPoint> &touchPoints);
|
||||
#endif
|
||||
|
||||
namespace QTest
|
||||
{
|
||||
|
|
@ -77,6 +79,7 @@ namespace QTest
|
|||
commit();
|
||||
points.clear();
|
||||
}
|
||||
#ifdef QT_WIDGETS_LIB
|
||||
QTouchEventSequence& press(int touchId, const QPoint &pt, QWidget *widget = 0)
|
||||
{
|
||||
QTouchEvent::TouchPoint &p = point(touchId);
|
||||
|
|
@ -84,6 +87,7 @@ namespace QTest
|
|||
p.setState(Qt::TouchPointPressed);
|
||||
return *this;
|
||||
}
|
||||
#endif
|
||||
QTouchEventSequence& press(int touchId, const QPoint &pt, QWindow *window = 0)
|
||||
{
|
||||
QTouchEvent::TouchPoint &p = point(touchId);
|
||||
|
|
@ -92,6 +96,7 @@ namespace QTest
|
|||
return *this;
|
||||
}
|
||||
|
||||
#ifdef QT_WIDGETS_LIB
|
||||
QTouchEventSequence& move(int touchId, const QPoint &pt, QWidget *widget = 0)
|
||||
{
|
||||
QTouchEvent::TouchPoint &p = point(touchId);
|
||||
|
|
@ -99,6 +104,7 @@ namespace QTest
|
|||
p.setState(Qt::TouchPointMoved);
|
||||
return *this;
|
||||
}
|
||||
#endif
|
||||
QTouchEventSequence& move(int touchId, const QPoint &pt, QWindow *window = 0)
|
||||
{
|
||||
QTouchEvent::TouchPoint &p = point(touchId);
|
||||
|
|
@ -106,6 +112,7 @@ namespace QTest
|
|||
p.setState(Qt::TouchPointMoved);
|
||||
return *this;
|
||||
}
|
||||
#ifdef QT_WIDGETS_LIB
|
||||
QTouchEventSequence& release(int touchId, const QPoint &pt, QWidget *widget = 0)
|
||||
{
|
||||
QTouchEvent::TouchPoint &p = point(touchId);
|
||||
|
|
@ -113,6 +120,7 @@ namespace QTest
|
|||
p.setState(Qt::TouchPointReleased);
|
||||
return *this;
|
||||
}
|
||||
#endif
|
||||
QTouchEventSequence& release(int touchId, const QPoint &pt, QWindow *window = 0)
|
||||
{
|
||||
QTouchEvent::TouchPoint &p = point(touchId);
|
||||
|
|
@ -128,12 +136,18 @@ namespace QTest
|
|||
}
|
||||
|
||||
private:
|
||||
#ifdef QT_WIDGETS_LIB
|
||||
QTouchEventSequence(QWidget *widget, QTouchEvent::DeviceType aDeviceType)
|
||||
: targetWidget(widget), targetWindow(0), deviceType(aDeviceType)
|
||||
{
|
||||
}
|
||||
#endif
|
||||
QTouchEventSequence(QWindow *window, QTouchEvent::DeviceType aDeviceType)
|
||||
: targetWidget(0), targetWindow(window), deviceType(aDeviceType)
|
||||
:
|
||||
#ifdef QT_WIDGETS_LIB
|
||||
targetWidget(0),
|
||||
#endif
|
||||
targetWindow(window), deviceType(aDeviceType)
|
||||
{
|
||||
}
|
||||
QTouchEventSequence(const QTouchEventSequence &v);
|
||||
|
|
@ -145,12 +159,14 @@ namespace QTest
|
|||
points[touchId] = QTouchEvent::TouchPoint(touchId);
|
||||
return points[touchId];
|
||||
}
|
||||
#ifdef QT_WIDGETS_LIB
|
||||
QPoint mapToScreen(QWidget *widget, const QPoint &pt)
|
||||
{
|
||||
if (widget)
|
||||
return widget->mapToGlobal(pt);
|
||||
return targetWidget ? targetWidget->mapToGlobal(pt) : pt;
|
||||
}
|
||||
#endif
|
||||
QPoint mapToScreen(QWindow *window, const QPoint &pt)
|
||||
{
|
||||
if(window)
|
||||
|
|
@ -186,27 +202,35 @@ namespace QTest
|
|||
QTest::qWait(10);
|
||||
targetWindow = 0;
|
||||
}
|
||||
#ifdef QT_WIDGETS_LIB
|
||||
else if(targetWidget)
|
||||
{
|
||||
qt_translateRawTouchEvent(targetWidget, deviceType, points.values());
|
||||
targetWidget = 0;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
QMap<int, QTouchEvent::TouchPoint> points;
|
||||
#ifdef QT_WIDGETS_LIB
|
||||
QWidget *targetWidget;
|
||||
#endif
|
||||
QWindow *targetWindow;
|
||||
QTouchEvent::DeviceType deviceType;
|
||||
#ifdef QT_WIDGETS_LIB
|
||||
friend QTouchEventSequence touchEvent(QWidget *, QTouchEvent::DeviceType);
|
||||
#endif
|
||||
friend QTouchEventSequence touchEvent(QWindow *, QTouchEvent::DeviceType);
|
||||
};
|
||||
|
||||
#ifdef QT_WIDGETS_LIB
|
||||
inline
|
||||
QTouchEventSequence touchEvent(QWidget *widget = 0,
|
||||
QTouchEvent::DeviceType deviceType = QTouchEvent::TouchScreen)
|
||||
{
|
||||
return QTouchEventSequence(widget, deviceType);
|
||||
}
|
||||
#endif
|
||||
inline
|
||||
QTouchEventSequence touchEvent(QWindow *window = 0,
|
||||
QTouchEvent::DeviceType deviceType = QTouchEvent::TouchScreen)
|
||||
|
|
|
|||
Loading…
Reference in New Issue