Add findViewDelegateItem function to visualtestutils.h
This helper function finds an item view delegate instance at a given index, ensuring that the view is polished and positioned at the correct index if necessary. Change-Id: Ib133914df723251835be3812c1d0654c07a99f14 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
This commit is contained in:
parent
2a65d8127d
commit
a0c95852fe
|
@ -31,6 +31,7 @@ qt_internal_add_test(tst_accessibility
|
||||||
Qt::QuickControls2Private
|
Qt::QuickControls2Private
|
||||||
Qt::QuickPrivate
|
Qt::QuickPrivate
|
||||||
Qt::QuickTemplates2Private
|
Qt::QuickTemplates2Private
|
||||||
|
Qt::QuickTest
|
||||||
Qt::TestPrivate
|
Qt::TestPrivate
|
||||||
TESTDATA ${test_data}
|
TESTDATA ${test_data}
|
||||||
)
|
)
|
||||||
|
|
|
@ -27,6 +27,7 @@ qt_internal_add_test(tst_cursor
|
||||||
Qt::QuickControls2Private
|
Qt::QuickControls2Private
|
||||||
Qt::QuickPrivate
|
Qt::QuickPrivate
|
||||||
Qt::QuickTemplates2Private
|
Qt::QuickTemplates2Private
|
||||||
|
Qt::QuickTest
|
||||||
Qt::TestPrivate
|
Qt::TestPrivate
|
||||||
TESTDATA ${test_data}
|
TESTDATA ${test_data}
|
||||||
)
|
)
|
||||||
|
|
|
@ -27,6 +27,7 @@ qt_internal_add_test(tst_customization
|
||||||
Qt::QuickControls2Private
|
Qt::QuickControls2Private
|
||||||
Qt::QuickPrivate
|
Qt::QuickPrivate
|
||||||
Qt::QuickTemplates2Private
|
Qt::QuickTemplates2Private
|
||||||
|
Qt::QuickTest
|
||||||
Qt::TestPrivate
|
Qt::TestPrivate
|
||||||
TESTDATA ${test_data}
|
TESTDATA ${test_data}
|
||||||
)
|
)
|
||||||
|
|
|
@ -27,6 +27,7 @@ qt_internal_add_test(tst_focus
|
||||||
Qt::QuickControls2Private
|
Qt::QuickControls2Private
|
||||||
Qt::QuickPrivate
|
Qt::QuickPrivate
|
||||||
Qt::QuickTemplates2Private
|
Qt::QuickTemplates2Private
|
||||||
|
Qt::QuickTest
|
||||||
Qt::TestPrivate
|
Qt::TestPrivate
|
||||||
TESTDATA ${test_data}
|
TESTDATA ${test_data}
|
||||||
)
|
)
|
||||||
|
|
|
@ -27,6 +27,7 @@ qt_internal_add_test(tst_font
|
||||||
Qt::QuickControls2Private
|
Qt::QuickControls2Private
|
||||||
Qt::QuickPrivate
|
Qt::QuickPrivate
|
||||||
Qt::QuickTemplates2Private
|
Qt::QuickTemplates2Private
|
||||||
|
Qt::QuickTest
|
||||||
Qt::TestPrivate
|
Qt::TestPrivate
|
||||||
TESTDATA ${test_data}
|
TESTDATA ${test_data}
|
||||||
)
|
)
|
||||||
|
|
|
@ -27,6 +27,7 @@ qt_internal_add_test(tst_palette
|
||||||
Qt::QuickControls2Private
|
Qt::QuickControls2Private
|
||||||
Qt::QuickPrivate
|
Qt::QuickPrivate
|
||||||
Qt::QuickTemplates2Private
|
Qt::QuickTemplates2Private
|
||||||
|
Qt::QuickTest
|
||||||
Qt::TestPrivate
|
Qt::TestPrivate
|
||||||
TESTDATA ${test_data}
|
TESTDATA ${test_data}
|
||||||
)
|
)
|
||||||
|
|
|
@ -27,6 +27,7 @@ qt_internal_add_test(tst_qquickapplicationwindow
|
||||||
Qt::QuickControls2Private
|
Qt::QuickControls2Private
|
||||||
Qt::QuickPrivate
|
Qt::QuickPrivate
|
||||||
Qt::QuickTemplates2Private
|
Qt::QuickTemplates2Private
|
||||||
|
Qt::QuickTest
|
||||||
Qt::TestPrivate
|
Qt::TestPrivate
|
||||||
TESTDATA ${test_data}
|
TESTDATA ${test_data}
|
||||||
)
|
)
|
||||||
|
|
|
@ -27,6 +27,7 @@ qt_internal_add_test(tst_qquickcontrol
|
||||||
Qt::QuickControls2Private
|
Qt::QuickControls2Private
|
||||||
Qt::QuickPrivate
|
Qt::QuickPrivate
|
||||||
Qt::QuickTemplates2Private
|
Qt::QuickTemplates2Private
|
||||||
|
Qt::QuickTest
|
||||||
Qt::TestPrivate
|
Qt::TestPrivate
|
||||||
TESTDATA ${test_data}
|
TESTDATA ${test_data}
|
||||||
)
|
)
|
||||||
|
|
|
@ -27,6 +27,7 @@ qt_internal_add_test(tst_qquickdrawer
|
||||||
Qt::QuickControls2Private
|
Qt::QuickControls2Private
|
||||||
Qt::QuickPrivate
|
Qt::QuickPrivate
|
||||||
Qt::QuickTemplates2Private
|
Qt::QuickTemplates2Private
|
||||||
|
Qt::QuickTest
|
||||||
Qt::TestPrivate
|
Qt::TestPrivate
|
||||||
TESTDATA ${test_data}
|
TESTDATA ${test_data}
|
||||||
)
|
)
|
||||||
|
|
|
@ -28,6 +28,7 @@ qt_internal_add_test(tst_qquickheaderview
|
||||||
Qt::QuickPrivate
|
Qt::QuickPrivate
|
||||||
Qt::QuickTemplates2
|
Qt::QuickTemplates2
|
||||||
Qt::QuickTemplates2Private
|
Qt::QuickTemplates2Private
|
||||||
|
Qt::QuickTest
|
||||||
Qt::TestPrivate
|
Qt::TestPrivate
|
||||||
TESTDATA ${test_data}
|
TESTDATA ${test_data}
|
||||||
)
|
)
|
||||||
|
|
|
@ -36,6 +36,7 @@ qt_internal_add_test(tst_qquickiconimage
|
||||||
Qt::QuickControls2Private
|
Qt::QuickControls2Private
|
||||||
Qt::QuickPrivate
|
Qt::QuickPrivate
|
||||||
Qt::QuickTemplates2Private
|
Qt::QuickTemplates2Private
|
||||||
|
Qt::QuickTest
|
||||||
Qt::TestPrivate
|
Qt::TestPrivate
|
||||||
TESTDATA ${test_data}
|
TESTDATA ${test_data}
|
||||||
)
|
)
|
||||||
|
|
|
@ -32,6 +32,7 @@ qt_internal_add_test(tst_qquickiconlabel
|
||||||
Qt::QuickControls2Private
|
Qt::QuickControls2Private
|
||||||
Qt::QuickPrivate
|
Qt::QuickPrivate
|
||||||
Qt::QuickTemplates2Private
|
Qt::QuickTemplates2Private
|
||||||
|
Qt::QuickTest
|
||||||
Qt::TestPrivate
|
Qt::TestPrivate
|
||||||
TESTDATA ${test_data}
|
TESTDATA ${test_data}
|
||||||
)
|
)
|
||||||
|
|
|
@ -27,6 +27,7 @@ qt_internal_add_test(tst_qquickmaterialstyleconf
|
||||||
Qt::QuickControls2Private
|
Qt::QuickControls2Private
|
||||||
Qt::QuickPrivate
|
Qt::QuickPrivate
|
||||||
Qt::QuickTemplates2Private
|
Qt::QuickTemplates2Private
|
||||||
|
Qt::QuickTest
|
||||||
Qt::TestPrivate
|
Qt::TestPrivate
|
||||||
TESTDATA ${test_data}
|
TESTDATA ${test_data}
|
||||||
)
|
)
|
||||||
|
|
|
@ -27,6 +27,7 @@ qt_internal_add_test(tst_qquickmenu
|
||||||
Qt::QuickControls2Private
|
Qt::QuickControls2Private
|
||||||
Qt::QuickPrivate
|
Qt::QuickPrivate
|
||||||
Qt::QuickTemplates2Private
|
Qt::QuickTemplates2Private
|
||||||
|
Qt::QuickTest
|
||||||
Qt::TestPrivate
|
Qt::TestPrivate
|
||||||
TESTDATA ${test_data}
|
TESTDATA ${test_data}
|
||||||
)
|
)
|
||||||
|
|
|
@ -27,6 +27,7 @@ qt_internal_add_test(tst_qquickmenubar
|
||||||
Qt::QuickControls2Private
|
Qt::QuickControls2Private
|
||||||
Qt::QuickPrivate
|
Qt::QuickPrivate
|
||||||
Qt::QuickTemplates2Private
|
Qt::QuickTemplates2Private
|
||||||
|
Qt::QuickTest
|
||||||
Qt::TestPrivate
|
Qt::TestPrivate
|
||||||
TESTDATA ${test_data}
|
TESTDATA ${test_data}
|
||||||
)
|
)
|
||||||
|
|
|
@ -37,6 +37,7 @@ qt_internal_add_test(tst_qquickninepatchimage
|
||||||
Qt::QuickControls2Private
|
Qt::QuickControls2Private
|
||||||
Qt::QuickPrivate
|
Qt::QuickPrivate
|
||||||
Qt::QuickTemplates2Private
|
Qt::QuickTemplates2Private
|
||||||
|
Qt::QuickTest
|
||||||
Qt::TestPrivate
|
Qt::TestPrivate
|
||||||
TESTDATA ${test_data}
|
TESTDATA ${test_data}
|
||||||
)
|
)
|
||||||
|
|
|
@ -27,6 +27,7 @@ qt_internal_add_test(tst_qquickpopup
|
||||||
Qt::QuickControls2Private
|
Qt::QuickControls2Private
|
||||||
Qt::QuickPrivate
|
Qt::QuickPrivate
|
||||||
Qt::QuickTemplates2Private
|
Qt::QuickTemplates2Private
|
||||||
|
Qt::QuickTest
|
||||||
Qt::TestPrivate
|
Qt::TestPrivate
|
||||||
TESTDATA ${test_data}
|
TESTDATA ${test_data}
|
||||||
)
|
)
|
||||||
|
|
|
@ -31,6 +31,7 @@ qt_internal_add_test(tst_qquickstyle
|
||||||
Qt::QuickControls2Private
|
Qt::QuickControls2Private
|
||||||
Qt::QuickPrivate
|
Qt::QuickPrivate
|
||||||
Qt::QuickTemplates2Private
|
Qt::QuickTemplates2Private
|
||||||
|
Qt::QuickTest
|
||||||
Qt::TestPrivate
|
Qt::TestPrivate
|
||||||
TESTDATA ${test_data}
|
TESTDATA ${test_data}
|
||||||
)
|
)
|
||||||
|
|
|
@ -27,6 +27,7 @@ qt_internal_add_test(tst_qquickuniversalstyleconf
|
||||||
Qt::QuickControls2Private
|
Qt::QuickControls2Private
|
||||||
Qt::QuickPrivate
|
Qt::QuickPrivate
|
||||||
Qt::QuickTemplates2Private
|
Qt::QuickTemplates2Private
|
||||||
|
Qt::QuickTest
|
||||||
Qt::TestPrivate
|
Qt::TestPrivate
|
||||||
TESTDATA ${test_data}
|
TESTDATA ${test_data}
|
||||||
)
|
)
|
||||||
|
|
|
@ -22,6 +22,7 @@ qt_internal_add_test(tst_sanity
|
||||||
Qt::QuickControls2Private
|
Qt::QuickControls2Private
|
||||||
Qt::QuickPrivate
|
Qt::QuickPrivate
|
||||||
Qt::QuickTemplates2Private
|
Qt::QuickTemplates2Private
|
||||||
|
Qt::QuickTest
|
||||||
Qt::TestPrivate
|
Qt::TestPrivate
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
QT += testlib-private core-private gui-private qml-private quick-private quicktemplates2-private quickcontrols2 quickcontrols2-private
|
QT += testlib-private core-private gui-private qml-private quick-private qmltest quicktemplates2-private quickcontrols2 quickcontrols2-private
|
||||||
|
|
||||||
HEADERS += $$PWD/visualtestutil.h \
|
HEADERS += $$PWD/visualtestutil.h \
|
||||||
$$PWD/util.h \
|
$$PWD/util.h \
|
||||||
|
|
|
@ -96,6 +96,35 @@ void QQuickVisualTestUtil::centerOnScreen(QQuickWindow *window)
|
||||||
window->setFramePosition(screenGeometry.center() - offset);
|
window->setFramePosition(screenGeometry.center() - offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\internal
|
||||||
|
|
||||||
|
Finds the delegate at \c index belonging to \c itemView, using the given \c flags.
|
||||||
|
|
||||||
|
If the view needs to be polished, the function will wait for it to be done before continuing,
|
||||||
|
and returns \c nullptr if the polish didn't happen.
|
||||||
|
*/
|
||||||
|
QQuickItem *QQuickVisualTestUtil::findViewDelegateItem(QQuickItemView *itemView, int index, FindViewDelegateItemFlags flags)
|
||||||
|
{
|
||||||
|
if (QQuickTest::qIsPolishScheduled(itemView)) {
|
||||||
|
if (!QQuickTest::qWaitForItemPolished(itemView)) {
|
||||||
|
qWarning() << "failed to polish" << itemView;
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Do this after the polish, just in case the count changes after a polish...
|
||||||
|
if (index <= -1 || index >= itemView->count()) {
|
||||||
|
qWarning() << "index" << index << "is out of bounds for" << itemView;
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (flags.testFlag(FindViewDelegateItemFlag::PositionViewAtIndex))
|
||||||
|
itemView->positionViewAtIndex(index, QQuickItemView::Center);
|
||||||
|
|
||||||
|
return itemView->itemAtIndex(index);
|
||||||
|
}
|
||||||
|
|
||||||
void QQuickVisualTestUtil::forEachControl(QQmlEngine *engine, const QString &sourcePath, const QString &targetPath, const QStringList &skipList, QQuickVisualTestUtil::ForEachCallback callback)
|
void QQuickVisualTestUtil::forEachControl(QQmlEngine *engine, const QString &sourcePath, const QString &targetPath, const QStringList &skipList, QQuickVisualTestUtil::ForEachCallback callback)
|
||||||
{
|
{
|
||||||
// We cannot use QQmlComponent to load QML files directly from the source tree.
|
// We cannot use QQmlComponent to load QML files directly from the source tree.
|
||||||
|
|
|
@ -43,6 +43,8 @@
|
||||||
#include <QtQuick/QQuickItem>
|
#include <QtQuick/QQuickItem>
|
||||||
#include <QtQml/QQmlExpression>
|
#include <QtQml/QQmlExpression>
|
||||||
#include <QtQuick/private/qquickitem_p.h>
|
#include <QtQuick/private/qquickitem_p.h>
|
||||||
|
#include <QtQuick/private/qquickitemview_p.h>
|
||||||
|
#include <QtQuickTest/quicktest.h>
|
||||||
#include <QtQuickControls2/qquickstyle.h>
|
#include <QtQuickControls2/qquickstyle.h>
|
||||||
#include <QtQuickTemplates2/private/qquickapplicationwindow_p.h>
|
#include <QtQuickTemplates2/private/qquickapplicationwindow_p.h>
|
||||||
#include <QtQuickTemplates2/private/qquickabstractbutton_p.h>
|
#include <QtQuickTemplates2/private/qquickabstractbutton_p.h>
|
||||||
|
@ -116,6 +118,15 @@ namespace QQuickVisualTestUtil
|
||||||
return items;
|
return items;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum class FindViewDelegateItemFlag {
|
||||||
|
None = 0x0,
|
||||||
|
PositionViewAtIndex = 0x01
|
||||||
|
};
|
||||||
|
Q_DECLARE_FLAGS(FindViewDelegateItemFlags, FindViewDelegateItemFlag)
|
||||||
|
|
||||||
|
QQuickItem* findViewDelegateItem(QQuickItemView *itemView, int index,
|
||||||
|
FindViewDelegateItemFlags flags = FindViewDelegateItemFlag::PositionViewAtIndex);
|
||||||
|
|
||||||
class QQuickApplicationHelper
|
class QQuickApplicationHelper
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -28,6 +28,7 @@ qt_internal_add_test(tst_styleimports
|
||||||
Qt::QuickControls2Private
|
Qt::QuickControls2Private
|
||||||
Qt::QuickPrivate
|
Qt::QuickPrivate
|
||||||
Qt::QuickTemplates2Private
|
Qt::QuickTemplates2Private
|
||||||
|
Qt::QuickTest
|
||||||
Qt::TestPrivate
|
Qt::TestPrivate
|
||||||
TESTDATA ${test_data}
|
TESTDATA ${test_data}
|
||||||
)
|
)
|
||||||
|
|
|
@ -27,6 +27,7 @@ qt_internal_add_test(tst_styleimportscompiletimematerial
|
||||||
Qt::QuickControls2Private
|
Qt::QuickControls2Private
|
||||||
Qt::QuickPrivate
|
Qt::QuickPrivate
|
||||||
Qt::QuickTemplates2Private
|
Qt::QuickTemplates2Private
|
||||||
|
Qt::QuickTest
|
||||||
Qt::TestPrivate
|
Qt::TestPrivate
|
||||||
TESTDATA ${test_data}
|
TESTDATA ${test_data}
|
||||||
)
|
)
|
||||||
|
|
|
@ -27,6 +27,7 @@ qt_internal_add_test(tst_styleimportscompiletimeqmlonly
|
||||||
Qt::QuickControls2Private
|
Qt::QuickControls2Private
|
||||||
Qt::QuickPrivate
|
Qt::QuickPrivate
|
||||||
Qt::QuickTemplates2Private
|
Qt::QuickTemplates2Private
|
||||||
|
Qt::QuickTest
|
||||||
Qt::TestPrivate
|
Qt::TestPrivate
|
||||||
TESTDATA ${test_data}
|
TESTDATA ${test_data}
|
||||||
)
|
)
|
||||||
|
|
|
@ -27,6 +27,7 @@ qt_internal_add_test(tst_translation
|
||||||
Qt::QuickControls2Private
|
Qt::QuickControls2Private
|
||||||
Qt::QuickPrivate
|
Qt::QuickPrivate
|
||||||
Qt::QuickTemplates2Private
|
Qt::QuickTemplates2Private
|
||||||
|
Qt::QuickTest
|
||||||
Qt::TestPrivate
|
Qt::TestPrivate
|
||||||
TESTDATA ${test_data}
|
TESTDATA ${test_data}
|
||||||
)
|
)
|
||||||
|
|
|
@ -22,6 +22,7 @@ qt_internal_add_test(tst_creationtime
|
||||||
Qt::QuickControls2Private
|
Qt::QuickControls2Private
|
||||||
Qt::QuickPrivate
|
Qt::QuickPrivate
|
||||||
Qt::QuickTemplates2Private
|
Qt::QuickTemplates2Private
|
||||||
|
Qt::QuickTest
|
||||||
Qt::TestPrivate
|
Qt::TestPrivate
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,7 @@ qt_internal_add_test(tst_objectcount
|
||||||
Qt::QuickControls2Private
|
Qt::QuickControls2Private
|
||||||
Qt::QuickPrivate
|
Qt::QuickPrivate
|
||||||
Qt::QuickTemplates2Private
|
Qt::QuickTemplates2Private
|
||||||
|
Qt::QuickTest
|
||||||
Qt::TestPrivate
|
Qt::TestPrivate
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue