summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorQt Forward Merge Bot <qt_forward_merge_bot@qt-project.org>2018-02-21 09:41:46 +0100
committerQt Forward Merge Bot <qt_forward_merge_bot@qt-project.org>2018-02-21 09:41:47 +0100
commitb949c447831d65fcf1a00feea151cd94a1021ed3 (patch)
treeb34704f92cb8b439e3f74930abf8cbf1b79b2c63 /tests/auto
parent24ccb402e56d7b2728ceb68cccf12d68e6f7d11f (diff)
parent8dbd245979dac890c9317a27067a43205314a4f0 (diff)
Merge remote-tracking branch 'origin/5.11' into dev
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/corelib/tools/qstring/tst_qstring.cpp8
-rw-r--r--tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp121
-rw-r--r--tests/auto/sql/models/qsqlrelationaltablemodel/tst_qsqlrelationaltablemodel.cpp33
-rw-r--r--tests/auto/sql/models/qsqltablemodel/tst_qsqltablemodel.cpp2
-rw-r--r--tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp225
-rw-r--r--tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp76
-rw-r--r--tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp1
7 files changed, 316 insertions, 150 deletions
diff --git a/tests/auto/corelib/tools/qstring/tst_qstring.cpp b/tests/auto/corelib/tools/qstring/tst_qstring.cpp
index c22998f804..6aa3c498aa 100644
--- a/tests/auto/corelib/tools/qstring/tst_qstring.cpp
+++ b/tests/auto/corelib/tools/qstring/tst_qstring.cpp
@@ -6091,8 +6091,14 @@ void tst_QString::compare_data()
QTest::addColumn<int>("csr"); // case sensitive result
QTest::addColumn<int>("cir"); // case insensitive result
-
// null strings
+ QTest::newRow("null-null") << QString() << QString() << 0 << 0;
+ QTest::newRow("text-null") << QString("a") << QString() << 1 << 1;
+ QTest::newRow("null-text") << QString() << QString("a") << -1 << -1;
+ QTest::newRow("null-empty") << QString() << QString("") << 0 << 0;
+ QTest::newRow("empty-null") << QString("") << QString() << 0 << 0;
+
+ // empty strings
QTest::newRow("data0") << QString("") << QString("") << 0 << 0;
QTest::newRow("data1") << QString("a") << QString("") << 1 << 1;
QTest::newRow("data2") << QString("") << QString("a") << -1 << -1;
diff --git a/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp b/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp
index baf2551dfb..aba99a9e20 100644
--- a/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp
+++ b/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp
@@ -370,7 +370,8 @@ void tst_QSqlQuery::dropTestTables( QSqlDatabase db )
<< qTableName("task_234422", __FILE__, db)
<< qTableName("test141895", __FILE__, db)
<< qTableName("qtest_oraOCINumber", __FILE__, db)
- << qTableName("bug2192", __FILE__, db);
+ << qTableName("bug2192", __FILE__, db)
+ << qTableName("tst_record", __FILE__, db);
if (dbType == QSqlDriver::PostgreSQL)
tablenames << qTableName("task_233829", __FILE__, db);
@@ -1009,6 +1010,29 @@ void tst_QSqlQuery::value()
}
}
+#define SETUP_RECORD_TABLE \
+ do { \
+ QVERIFY_SQL(q, exec("CREATE TABLE " + tst_record + " (id integer, extra varchar(50))")); \
+ for (int i = 0; i < 3; ++i) \
+ QVERIFY_SQL(q, exec(QString("INSERT INTO " + tst_record + " VALUES(%1, 'extra%1')").arg(i))); \
+ } while (0)
+
+#define CHECK_RECORD \
+ do { \
+ QVERIFY_SQL(q, exec(QString("select %1.id, %1.t_varchar, %1.t_char, %2.id, %2.extra from %1, %2 where " \
+ "%1.id = %2.id order by %1.id").arg(lowerQTest).arg(tst_record))); \
+ QCOMPARE(q.record().fieldName(0).toLower(), QString("id")); \
+ QCOMPARE(q.record().field(0).tableName().toLower(), lowerQTest); \
+ QCOMPARE(q.record().fieldName(1).toLower(), QString("t_varchar")); \
+ QCOMPARE(q.record().field(1).tableName().toLower(), lowerQTest); \
+ QCOMPARE(q.record().fieldName(2).toLower(), QString("t_char")); \
+ QCOMPARE(q.record().field(2).tableName().toLower(), lowerQTest); \
+ QCOMPARE(q.record().fieldName(3).toLower(), QString("id")); \
+ QCOMPARE(q.record().field(3).tableName().toLower(), tst_record); \
+ QCOMPARE(q.record().fieldName(4).toLower(), QString("extra")); \
+ QCOMPARE(q.record().field(4).tableName().toLower(), tst_record); \
+ } while (0)
+
void tst_QSqlQuery::record()
{
QFETCH( QString, dbName );
@@ -1030,6 +1054,26 @@ void tst_QSqlQuery::record()
QCOMPARE( q.record().fieldName( 0 ).toLower(), QString( "id" ) );
QCOMPARE( q.value( 0 ).toInt(), 2 );
+
+ const QSqlDriver::DbmsType dbType = tst_Databases::getDatabaseType(db);
+ if (dbType == QSqlDriver::Oracle)
+ QSKIP("Getting the tablename is not supported in Oracle");
+ const auto lowerQTest = qtest.toLower();
+ for (int i = 0; i < 3; ++i)
+ QCOMPARE(q.record().field(i).tableName().toLower(), lowerQTest);
+ q.clear();
+ const auto tst_record = qTableName("tst_record", __FILE__, db).toLower();
+ SETUP_RECORD_TABLE;
+ CHECK_RECORD;
+ q.clear();
+
+ // Recreate the tables, in a different order
+ const QStringList tables = { qtest, tst_record, qTableName("qtest_null", __FILE__, db) };
+ tst_Databases::safeDropTables(db, tables);
+ SETUP_RECORD_TABLE;
+ createTestTables(db);
+ populateTestTables(db);
+ CHECK_RECORD;
}
void tst_QSqlQuery::isValid()
@@ -2667,8 +2711,22 @@ void tst_QSqlQuery::lastInsertId()
QSqlQuery q( db );
- QVERIFY_SQL( q, exec( "insert into " + qtest + " values (41, 'VarChar41', 'Char41')" ) );
-
+ const QSqlDriver::DbmsType dbType = tst_Databases::getDatabaseType(db);
+ // PostgreSQL >= 8.1 relies on lastval() which does not work if a value is
+ // manually inserted to the serial field, so we create a table specifically
+ if (dbType == QSqlDriver::PostgreSQL) {
+ const auto tst_lastInsertId = qTableName("tst_lastInsertId", __FILE__, db);
+ tst_Databases::safeDropTable(db, tst_lastInsertId);
+ QVERIFY_SQL(q, exec(QStringLiteral("create table ") + tst_lastInsertId +
+ QStringLiteral(" (id serial not null, t_varchar "
+ "varchar(20), t_char char(20), primary key(id))")));
+ QVERIFY_SQL(q, exec(QStringLiteral("insert into ") + tst_lastInsertId +
+ QStringLiteral(" (t_varchar, t_char) values "
+ "('VarChar41', 'Char41')")));
+ } else {
+ QVERIFY_SQL(q, exec(QStringLiteral("insert into ") + qtest +
+ QStringLiteral(" values (41, 'VarChar41', 'Char41')")));
+ }
QVariant v = q.lastInsertId();
QVERIFY( v.isValid() );
@@ -3225,10 +3283,19 @@ void tst_QSqlQuery::timeStampParsing()
const QString tableName(qTableName("timeStampParsing", __FILE__, db));
tst_Databases::safeDropTable(db, tableName);
QSqlQuery q(db);
- QVERIFY_SQL(q, exec(QStringLiteral("CREATE TABLE ") + tableName
- + QStringLiteral(" (id integer, datefield timestamp)")));
- QVERIFY_SQL(q, exec(QStringLiteral("INSERT INTO ") + tableName
- + QStringLiteral(" (datefield) VALUES (current_timestamp)")));
+ QSqlDriver::DbmsType dbType = tst_Databases::getDatabaseType(db);
+ if (dbType == QSqlDriver::PostgreSQL) {
+ QVERIFY_SQL(q, exec(QStringLiteral("CREATE TABLE ") + tableName + QStringLiteral("("
+ "id serial NOT NULL, "
+ "datefield timestamp, primary key(id));")));
+ } else {
+ QVERIFY_SQL(q, exec(QStringLiteral("CREATE TABLE ") + tableName + QStringLiteral("("
+ "\"id\" integer NOT NULL PRIMARY KEY AUTOINCREMENT,"
+ "\"datefield\" timestamp);")));
+ }
+ QVERIFY_SQL(q, exec(
+ QStringLiteral("INSERT INTO ") + tableName + QStringLiteral(" (datefield) VALUES (current_timestamp);"
+ )));
QVERIFY_SQL(q, exec(QStringLiteral("SELECT * FROM ") + tableName));
while (q.next())
QVERIFY(q.value(1).toDateTime().isValid());
@@ -3599,15 +3666,17 @@ void tst_QSqlQuery::QTBUG_18435()
void tst_QSqlQuery::QTBUG_5251()
{
+ // Since QSqlTableModel will escape the identifiers, we need to escape
+ // them for databases that are case sensitive
QFETCH( QString, dbName );
QSqlDatabase db = QSqlDatabase::database( dbName );
CHECK_DATABASE( db );
const QString timetest(qTableName("timetest", __FILE__, db));
-
+ tst_Databases::safeDropTable(db, timetest);
QSqlQuery q(db);
- q.exec("DROP TABLE " + timetest);
- QVERIFY_SQL(q, exec("CREATE TABLE " + timetest + " (t TIME)"));
- QVERIFY_SQL(q, exec("INSERT INTO " + timetest + " VALUES ('1:2:3.666')"));
+ QVERIFY_SQL(q, exec(QStringLiteral("CREATE TABLE \"") + timetest + QStringLiteral("\" (t TIME)")));
+ QVERIFY_SQL(q, exec(QStringLiteral("INSERT INTO \"") + timetest +
+ QStringLiteral("\" VALUES ('1:2:3.666')")));
QSqlTableModel timetestModel(0,db);
timetestModel.setEditStrategy(QSqlTableModel::OnManualSubmit);
@@ -3620,7 +3689,8 @@ void tst_QSqlQuery::QTBUG_5251()
QVERIFY_SQL(timetestModel, submitAll());
QCOMPARE(timetestModel.record(0).field(0).value().toTime().toString("HH:mm:ss.zzz"), QString("00:12:34.500"));
- QVERIFY_SQL(q, exec("UPDATE " + timetest + " SET t = '0:11:22.33'"));
+ QVERIFY_SQL(q, exec(QStringLiteral("UPDATE \"") + timetest +
+ QStringLiteral("\" SET t = '0:11:22.33'")));
QVERIFY_SQL(timetestModel, select());
QCOMPARE(timetestModel.record(0).field(0).value().toTime().toString("HH:mm:ss.zzz"), QString("00:11:22.330"));
@@ -4197,12 +4267,18 @@ void tst_QSqlQuery::aggregateFunctionTypes()
QSqlDatabase db = QSqlDatabase::database(dbName);
CHECK_DATABASE(db);
QVariant::Type intType = QVariant::Int;
+ QVariant::Type sumType = intType;
+ QVariant::Type countType = intType;
// QPSQL uses LongLong for manipulation of integers
const QSqlDriver::DbmsType dbType = tst_Databases::getDatabaseType(db);
- if (dbType == QSqlDriver::PostgreSQL)
- intType = QVariant::LongLong;
- else if (dbType == QSqlDriver::Oracle)
- intType = QVariant::Double;
+ if (dbType == QSqlDriver::PostgreSQL) {
+ sumType = countType = QVariant::LongLong;
+ } else if (dbType == QSqlDriver::Oracle) {
+ intType = sumType = countType = QVariant::Double;
+ } else if (dbType == QSqlDriver::MySqlServer) {
+ sumType = QVariant::Double;
+ countType = QVariant::LongLong;
+ }
{
const QString tableName(qTableName("numericFunctionsWithIntValues", __FILE__, db));
tst_Databases::safeDropTable( db, tableName );
@@ -4215,10 +4291,8 @@ void tst_QSqlQuery::aggregateFunctionTypes()
QVERIFY(q.next());
if (dbType == QSqlDriver::SQLite)
QCOMPARE(q.record().field(0).type(), QVariant::Invalid);
- else if (dbType == QSqlDriver::MySqlServer)
- QCOMPARE(q.record().field(0).type(), QVariant::Double);
else
- QCOMPARE(q.record().field(0).type(), intType);
+ QCOMPARE(q.record().field(0).type(), sumType);
QVERIFY_SQL(q, exec("INSERT INTO " + tableName + " (id) VALUES (1)"));
QVERIFY_SQL(q, exec("INSERT INTO " + tableName + " (id) VALUES (2)"));
@@ -4226,10 +4300,7 @@ void tst_QSqlQuery::aggregateFunctionTypes()
QVERIFY_SQL(q, exec("SELECT SUM(id) FROM " + tableName));
QVERIFY(q.next());
QCOMPARE(q.value(0).toInt(), 3);
- if (dbType == QSqlDriver::MySqlServer)
- QCOMPARE(q.record().field(0).type(), QVariant::Double);
- else
- QCOMPARE(q.record().field(0).type(), intType);
+ QCOMPARE(q.record().field(0).type(), sumType);
QVERIFY_SQL(q, exec("SELECT AVG(id) FROM " + tableName));
QVERIFY(q.next());
@@ -4245,7 +4316,7 @@ void tst_QSqlQuery::aggregateFunctionTypes()
QVERIFY_SQL(q, exec("SELECT COUNT(id) FROM " + tableName));
QVERIFY(q.next());
QCOMPARE(q.value(0).toInt(), 2);
- QCOMPARE(q.record().field(0).type(), dbType != QSqlDriver::MySqlServer ? intType : QVariant::LongLong);
+ QCOMPARE(q.record().field(0).type(), countType);
QVERIFY_SQL(q, exec("SELECT MIN(id) FROM " + tableName));
QVERIFY(q.next());
@@ -4288,7 +4359,7 @@ void tst_QSqlQuery::aggregateFunctionTypes()
QVERIFY_SQL(q, exec("SELECT COUNT(id) FROM " + tableName));
QVERIFY(q.next());
QCOMPARE(q.value(0).toInt(), 2);
- QCOMPARE(q.record().field(0).type(), dbType != QSqlDriver::MySqlServer ? intType : QVariant::LongLong);
+ QCOMPARE(q.record().field(0).type(), countType);
QVERIFY_SQL(q, exec("SELECT MIN(id) FROM " + tableName));
QVERIFY(q.next());
diff --git a/tests/auto/sql/models/qsqlrelationaltablemodel/tst_qsqlrelationaltablemodel.cpp b/tests/auto/sql/models/qsqlrelationaltablemodel/tst_qsqlrelationaltablemodel.cpp
index 84cca482fb..f1c55df1ef 100644
--- a/tests/auto/sql/models/qsqlrelationaltablemodel/tst_qsqlrelationaltablemodel.cpp
+++ b/tests/auto/sql/models/qsqlrelationaltablemodel/tst_qsqlrelationaltablemodel.cpp
@@ -385,6 +385,7 @@ void tst_QSqlRelationalTableModel::setData()
model.setRelation(1, QSqlRelation(reltest5, "title", "abbrev"));
model.setEditStrategy(QSqlTableModel::OnManualSubmit);
model.setJoinMode(QSqlRelationalTableModel::LeftJoin);
+ model.setSort(0, Qt::AscendingOrder);
QVERIFY_SQL(model, select());
QCOMPARE(model.data(model.index(0,1)).toString(), QString("Mr"));
@@ -783,24 +784,32 @@ void tst_QSqlRelationalTableModel::sort()
QVERIFY_SQL(model, select());
QCOMPARE(model.rowCount(), 6);
- QCOMPARE(model.data(model.index(0, 2)).toString(), QString("mister"));
- QCOMPARE(model.data(model.index(1, 2)).toString(), QString("mister"));
- QCOMPARE(model.data(model.index(2, 2)).toString(), QString("herr"));
- QCOMPARE(model.data(model.index(3, 2)).toString(), QString("herr"));
- QCOMPARE(model.data(model.index(4, 2)).toString(), QString(""));
- QCOMPARE(model.data(model.index(5, 2)).toString(), QString(""));
+
+ QStringList stringsInDatabaseOrder;
+ // PostgreSQL puts the null ones (from the table with the original value) first in descending order
+ // which translate to empty strings in the related table
+ if (dbType == QSqlDriver::PostgreSQL)
+ stringsInDatabaseOrder << "" << "" << "mister" << "mister" << "herr" << "herr";
+ else
+ stringsInDatabaseOrder << "mister" << "mister" << "herr" << "herr" << "" << "";
+ for (int i = 0; i < 6; ++i)
+ QCOMPARE(model.data(model.index(i, 2)).toString(), stringsInDatabaseOrder.at(i));
model.setSort(3, Qt::AscendingOrder);
QVERIFY_SQL(model, select());
+ // PostgreSQL puts the null ones (from the table with the original value) first in descending order
+ // which translate to empty strings in the related table
+ stringsInDatabaseOrder.clear();
+ if (dbType == QSqlDriver::PostgreSQL)
+ stringsInDatabaseOrder << "herr" << "mister" << "mister" << "mister" << "mister" << "";
+ else if (dbType != QSqlDriver::Sybase)
+ stringsInDatabaseOrder << "" << "herr" << "mister" << "mister" << "mister" << "mister";
+
if (dbType != QSqlDriver::Sybase) {
QCOMPARE(model.rowCount(), 6);
- QCOMPARE(model.data(model.index(0, 3)).toString(), QString(""));
- QCOMPARE(model.data(model.index(1, 3)).toString(), QString("herr"));
- QCOMPARE(model.data(model.index(2, 3)).toString(), QString("mister"));
- QCOMPARE(model.data(model.index(3, 3)).toString(), QString("mister"));
- QCOMPARE(model.data(model.index(4, 3)).toString(), QString("mister"));
- QCOMPARE(model.data(model.index(5, 3)).toString(), QString("mister"));
+ for (int i = 0; i < 6; ++i)
+ QCOMPARE(model.data(model.index(i, 3)).toString(), stringsInDatabaseOrder.at(i));
} else {
QCOMPARE(model.data(model.index(0, 3)).toInt(), 1);
QCOMPARE(model.data(model.index(1, 3)).toInt(), 2);
diff --git a/tests/auto/sql/models/qsqltablemodel/tst_qsqltablemodel.cpp b/tests/auto/sql/models/qsqltablemodel/tst_qsqltablemodel.cpp
index bf76ed2bb6..ded360ef8d 100644
--- a/tests/auto/sql/models/qsqltablemodel/tst_qsqltablemodel.cpp
+++ b/tests/auto/sql/models/qsqltablemodel/tst_qsqltablemodel.cpp
@@ -275,7 +275,7 @@ void tst_QSqlTableModel::init()
void tst_QSqlTableModel::cleanup()
{
- repopulateTestTables();
+ recreateTestTables();
}
void tst_QSqlTableModel::select()
diff --git a/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp
index 26831002ce..4f4a11a79c 100644
--- a/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp
+++ b/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp
@@ -38,6 +38,7 @@
#include <QAbstractTextDocumentLayout>
#include <QBitmap>
#include <QCursor>
+#include <QDesktopWidget>
#include <QScreen>
#include <QLabel>
#include <QDial>
@@ -54,10 +55,13 @@
#include <QPushButton>
#include <QLineEdit>
#include <QGraphicsLinearLayout>
+#include <QTransform>
#include <float.h>
#include <QStyleHints>
Q_DECLARE_METATYPE(QPainterPath)
+Q_DECLARE_METATYPE(QSizeF)
+Q_DECLARE_METATYPE(QTransform)
#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT)
#include <windows.h>
@@ -435,6 +439,8 @@ private slots:
void focusHandling();
void touchEventPropagation_data();
void touchEventPropagation();
+ void touchEventTransformation_data();
+ void touchEventTransformation();
void deviceCoordinateCache_simpleRotations();
void resolvePaletteForItemChildren();
@@ -465,6 +471,7 @@ private slots:
private:
QList<QGraphicsItem *> paintedItems;
+ QTouchDevice *m_touchDevice = nullptr;
};
void tst_QGraphicsItem::construction()
@@ -10945,6 +10952,95 @@ void tst_QGraphicsItem::focusHandling()
QCOMPARE(scene.focusItem(), focusableUnder);
}
+class TouchEventTestee : public QGraphicsRectItem
+{
+public:
+ TouchEventTestee(const QSizeF &size = QSizeF(100, 100)) :
+ QGraphicsRectItem(QRectF(QPointF(), size))
+ {
+ setAcceptTouchEvents(true);
+ setFlag(QGraphicsItem::ItemIsFocusable, false);
+ }
+
+ QList<QTouchEvent::TouchPoint> touchBeginPoints() const { return m_touchBeginPoints; }
+ int touchBeginEventCount() const { return m_touchBeginPoints.size(); }
+
+ QList<QTouchEvent::TouchPoint> touchUpdatePoints() const { return m_touchUpdatePoints; }
+ int touchUpdateEventCount() const { return m_touchUpdatePoints.size(); }
+
+protected:
+ bool sceneEvent(QEvent *ev) override
+ {
+ switch (ev->type()) {
+ case QEvent::TouchBegin:
+ m_touchBeginPoints.append(static_cast<const QTouchEvent *>(ev)->touchPoints().constFirst());
+ ev->accept();
+ return true;
+ case QEvent::TouchUpdate:
+ m_touchUpdatePoints.append(static_cast<const QTouchEvent *>(ev)->touchPoints().constFirst());
+ ev->accept();
+ return true;
+ default:
+ break;
+ }
+
+ return QGraphicsRectItem::sceneEvent(ev);
+ }
+
+private:
+ QList<QTouchEvent::TouchPoint> m_touchBeginPoints;
+ QList<QTouchEvent::TouchPoint> m_touchUpdatePoints;
+};
+
+static QList<QTouchEvent::TouchPoint>
+ createTouchPoints(const QGraphicsView &view,
+ const QPointF &scenePos,
+ const QSizeF &ellipseDiameters,
+ Qt::TouchPointState state = Qt::TouchPointPressed)
+{
+ QTouchEvent::TouchPoint tp(0);
+ tp.setState(state);
+ tp.setScenePos(scenePos);
+ tp.setStartScenePos(scenePos);
+ tp.setLastScenePos(scenePos);
+ const QPointF screenPos = view.viewport()->mapToGlobal(view.mapFromScene(scenePos));
+ tp.setScreenPos(screenPos);
+ tp.setStartScreenPos(screenPos);
+ tp.setLastScreenPos(screenPos);
+ tp.setEllipseDiameters(ellipseDiameters);
+ const QSizeF screenSize = QApplication::desktop()->screenGeometry(&view).size();
+ tp.setNormalizedPos(QPointF(screenPos.x() / screenSize.width(), screenPos.y() / screenSize.height()));
+ return QList<QTouchEvent::TouchPoint>() << tp;
+}
+
+static bool comparePointF(const QPointF &p1, const QPointF &p2)
+{
+ return qFuzzyCompare(p1.x(), p2.x()) && qFuzzyCompare(p1.y(), p2.y());
+}
+
+static bool compareSizeF(const QSizeF &s1, const QSizeF &s2)
+{
+ return qFuzzyCompare(s1.width(), s2.width()) && qFuzzyCompare(s1.height(), s2.height());
+}
+
+static QByteArray msgPointFComparisonFailed(const QPointF &p1, const QPointF &p2)
+{
+ return QByteArray::number(p1.x()) + ", " + QByteArray::number(p1.y())
+ + " != " + QByteArray::number(p2.x()) + ", " + QByteArray::number(p2.y());
+}
+
+static QByteArray msgSizeFComparisonFailed(const QSizeF &s1, const QSizeF &s2)
+{
+ return QByteArray::number(s1.width()) + 'x' + QByteArray::number(s1.height())
+ + " != " + QByteArray::number(s2.width()) + 'x' + QByteArray::number(s2.height());
+}
+
+#define COMPARE_POINTF(ACTUAL, EXPECTED) \
+ QVERIFY2(comparePointF(ACTUAL, EXPECTED), msgPointFComparisonFailed(ACTUAL, EXPECTED).constData())
+
+#define COMPARE_SIZEF(ACTUAL, EXPECTED) \
+ QVERIFY2(compareSizeF(ACTUAL, EXPECTED), msgSizeFComparisonFailed(ACTUAL, EXPECTED).constData())
+
void tst_QGraphicsItem::touchEventPropagation_data()
{
QTest::addColumn<QGraphicsItem::GraphicsItemFlag>("flag");
@@ -10963,29 +11059,7 @@ void tst_QGraphicsItem::touchEventPropagation()
QFETCH(QGraphicsItem::GraphicsItemFlag, flag);
QFETCH(int, expectedCount);
- class Testee : public QGraphicsRectItem
- {
- public:
- int touchBeginEventCount;
-
- Testee()
- : QGraphicsRectItem(0, 0, 100, 100)
- , touchBeginEventCount(0)
- {
- setAcceptTouchEvents(true);
- setFlag(QGraphicsItem::ItemIsFocusable, false);
- }
-
- bool sceneEvent(QEvent *ev)
- {
- if (ev->type() == QEvent::TouchBegin)
- ++touchBeginEventCount;
-
- return QGraphicsRectItem::sceneEvent(ev);
- }
- };
-
- Testee *touchEventReceiver = new Testee;
+ TouchEventTestee *touchEventReceiver = new TouchEventTestee;
QGraphicsItem *topMost = new QGraphicsRectItem(touchEventReceiver->boundingRect());
QGraphicsScene scene;
@@ -10998,26 +11072,107 @@ void tst_QGraphicsItem::touchEventPropagation()
topMost->setFlag(flag, true);
QGraphicsView view(&scene);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()) + QLatin1String("::")
+ + QLatin1String(QTest::currentDataTag()));
view.setSceneRect(touchEventReceiver->boundingRect());
view.show();
QVERIFY(QTest::qWaitForWindowExposed(&view));
- QCOMPARE(touchEventReceiver->touchBeginEventCount, 0);
+ QCOMPARE(touchEventReceiver->touchBeginEventCount(), 0);
- QTouchEvent::TouchPoint tp(0);
- tp.setState(Qt::TouchPointPressed);
- tp.setScenePos(view.sceneRect().center());
- tp.setLastScenePos(view.sceneRect().center());
+ const QPointF scenePos = view.sceneRect().center();
+ sendMousePress(&scene, scenePos);
+ if (m_touchDevice == nullptr)
+ m_touchDevice = QTest::createTouchDevice();
+ QTouchEvent touchBegin(QEvent::TouchBegin, m_touchDevice, Qt::NoModifier, Qt::TouchPointPressed,
+ createTouchPoints(view, scenePos, QSizeF(10, 10)));
+ touchBegin.setTarget(view.viewport());
- QList<QTouchEvent::TouchPoint> touchPoints;
- touchPoints << tp;
+ qApp->sendEvent(&scene, &touchBegin);
+ QCOMPARE(touchEventReceiver->touchBeginEventCount(), expectedCount);
+}
- sendMousePress(&scene, tp.scenePos());
- QTouchDevice *device = QTest::createTouchDevice();
- QTouchEvent touchBegin(QEvent::TouchBegin, device, Qt::NoModifier, Qt::TouchPointPressed, touchPoints);
+void tst_QGraphicsItem::touchEventTransformation_data()
+{
+ QTest::addColumn<QGraphicsItem::GraphicsItemFlag>("flag");
+ QTest::addColumn<QTransform>("viewTransform");
+ QTest::addColumn<QPointF>("touchScenePos");
+ QTest::addColumn<QSizeF>("ellipseDiameters");
+ QTest::addColumn<QPointF>("expectedItemPos");
+
+ QTest::newRow("notransform")
+ << QGraphicsItem::ItemIsSelectable << QTransform()
+ << QPointF(150, 150) << QSizeF(7, 8) << QPointF(50, 50);
+ QTest::newRow("scaled")
+ << QGraphicsItem::ItemIsSelectable << QTransform::fromScale(0.5, 0.5)
+ << QPointF(150, 150) << QSizeF(7, 8) << QPointF(50, 50);
+ // QTBUG-66192: When the item ignores the downscaling transformation,
+ // it will receive the touch point at 25,25 instead of 50,50.
+ QTest::newRow("scaled/ItemIgnoresTransformations")
+ << QGraphicsItem::ItemIgnoresTransformations << QTransform::fromScale(0.5, 0.5)
+ << QPointF(150, 150) << QSizeF(7, 8) << QPointF(25, 25);
+}
+
+void tst_QGraphicsItem::touchEventTransformation()
+{
+ QFETCH(QGraphicsItem::GraphicsItemFlag, flag);
+ QFETCH(QTransform, viewTransform);
+ QFETCH(QPointF, touchScenePos);
+ QFETCH(QSizeF, ellipseDiameters);
+ QFETCH(QPointF, expectedItemPos);
+
+ TouchEventTestee *touchEventReceiver = new TouchEventTestee;
+
+ QGraphicsScene scene;
+ scene.addItem(touchEventReceiver);
+ const QPointF itemPos(100, 100);
+
+ touchEventReceiver->setPos(itemPos);
+
+ touchEventReceiver->setFlag(flag, true);
+
+ QGraphicsView view(&scene);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()) + QLatin1String("::")
+ + QLatin1String(QTest::currentDataTag()));
+ view.setSceneRect(QRectF(QPointF(0, 0), QSizeF(300, 300)));
+ view.setTransform(viewTransform);
+ view.show();
+ QVERIFY(QTest::qWaitForWindowExposed(&view));
+
+ QCOMPARE(touchEventReceiver->touchBeginEventCount(), 0);
+
+ if (m_touchDevice == nullptr)
+ m_touchDevice = QTest::createTouchDevice();
+ QTouchEvent touchBegin(QEvent::TouchBegin, m_touchDevice, Qt::NoModifier, Qt::TouchPointPressed,
+ createTouchPoints(view, touchScenePos, ellipseDiameters));
+ touchBegin.setTarget(view.viewport());
+
+ QCoreApplication::sendEvent(&scene, &touchBegin);
+ QCOMPARE(touchEventReceiver->touchBeginEventCount(), 1);
+
+ const QTouchEvent::TouchPoint touchBeginPoint = touchEventReceiver->touchBeginPoints().constFirst();
+
+ COMPARE_POINTF(touchBeginPoint.scenePos(), touchScenePos);
+ COMPARE_POINTF(touchBeginPoint.startScenePos(), touchScenePos);
+ COMPARE_POINTF(touchBeginPoint.lastScenePos(), touchScenePos);
+ COMPARE_POINTF(touchBeginPoint.pos(), expectedItemPos);
+ COMPARE_SIZEF(touchBeginPoint.ellipseDiameters(), ellipseDiameters); // Must remain untransformed
+
+ QTouchEvent touchUpdate(QEvent::TouchUpdate, m_touchDevice, Qt::NoModifier, Qt::TouchPointMoved,
+ createTouchPoints(view, touchScenePos, ellipseDiameters, Qt::TouchPointMoved));
+ touchUpdate.setTarget(view.viewport());
+
+ QCoreApplication::sendEvent(&scene, &touchUpdate);
+ QCOMPARE(touchEventReceiver->touchUpdateEventCount(), 1);
+
+ const QTouchEvent::TouchPoint touchUpdatePoint = touchEventReceiver->touchUpdatePoints().constFirst();
+
+ COMPARE_POINTF(touchUpdatePoint.scenePos(), touchScenePos);
+ COMPARE_POINTF(touchBeginPoint.startScenePos(), touchScenePos);
+ COMPARE_POINTF(touchUpdatePoint.lastScenePos(), touchScenePos);
+ COMPARE_POINTF(touchUpdatePoint.pos(), expectedItemPos);
+ COMPARE_SIZEF(touchUpdatePoint.ellipseDiameters(), ellipseDiameters); // Must remain untransformed
- qApp->sendEvent(&scene, &touchBegin);
- QCOMPARE(touchEventReceiver->touchBeginEventCount, expectedCount);
}
void tst_QGraphicsItem::deviceCoordinateCache_simpleRotations()
diff --git a/tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp b/tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp
index fe8571abf1..3b340d06ab 100644
--- a/tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp
+++ b/tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp
@@ -254,7 +254,6 @@ private slots:
void zeroScale();
void focusItemChangedSignal();
void minimumRenderSize();
- void checkTouchPointsEllipseDiameters();
// task specific tests below me
void task139710_bspTreeCrash();
@@ -4765,81 +4764,6 @@ void tst_QGraphicsScene::minimumRenderSize()
QVERIFY(smallChild->repaints > smallerGrandChild->repaints);
}
-class TouchItem : public QGraphicsRectItem
-{
-public:
- TouchItem() : QGraphicsRectItem(QRectF(-10, -10, 20, 20)),
- seenTouch(false)
- {
- setAcceptTouchEvents(true);
- setFlag(QGraphicsItem::ItemIgnoresTransformations);
- }
- bool seenTouch;
- QList<QTouchEvent::TouchPoint> touchPoints;
-protected:
- bool sceneEvent(QEvent *event) override
- {
- switch (event->type()) {
- case QEvent::TouchBegin:
- case QEvent::TouchUpdate:
- case QEvent::TouchEnd:
- seenTouch = true;
- touchPoints = static_cast<QTouchEvent *>(event)->touchPoints();
- event->accept();
- return true;
- default:
- break;
- }
- return QGraphicsRectItem::sceneEvent(event);
- }
-};
-
-void tst_QGraphicsScene::checkTouchPointsEllipseDiameters()
-{
- QGraphicsScene scene;
- QGraphicsView view(&scene);
- scene.setSceneRect(1, 1, 198, 198);
- view.scale(1.5, 1.5);
- view.setFocus();
- TouchItem *rect = new TouchItem;
- scene.addItem(rect);
- view.show();
- QApplication::setActiveWindow(&view);
- QVERIFY(QTest::qWaitForWindowActive(&view));
-
- const QSizeF ellipseDiameters(10.0, 10.0);
- QTouchEvent::TouchPoint touchPoint(0);
- touchPoint.setState(Qt::TouchPointPressed);
- touchPoint.setPos(view.mapFromScene(rect->mapToScene(rect->boundingRect().center())));
- touchPoint.setScreenPos(view.mapToGlobal(touchPoint.pos().toPoint()));
- touchPoint.setEllipseDiameters(ellipseDiameters);
-
- QList<QTouchEvent::TouchPoint> touchPoints = { touchPoint };
-
- QTouchDevice *testDevice = QTest::createTouchDevice(QTouchDevice::TouchPad);
- QTouchEvent touchEvent(QEvent::TouchBegin,
- testDevice,
- Qt::NoModifier,
- Qt::TouchPointPressed,
- touchPoints);
- QApplication::sendEvent(view.viewport(), &touchEvent);
- QVERIFY(rect->seenTouch);
- QVERIFY(rect->touchPoints.size() == 1);
- QCOMPARE(ellipseDiameters, rect->touchPoints.first().ellipseDiameters());
-
- rect->seenTouch = false;
- rect->touchPoints.clear();
- QTouchEvent touchUpdateEvent(QEvent::TouchUpdate,
- testDevice,
- Qt::NoModifier,
- Qt::TouchPointMoved,
- touchPoints);
- QApplication::sendEvent(view.viewport(), &touchEvent);
- QVERIFY(rect->seenTouch);
- QVERIFY(rect->touchPoints.size() == 1);
- QCOMPARE(ellipseDiameters, rect->touchPoints.first().ellipseDiameters());
-}
-
void tst_QGraphicsScene::taskQTBUG_15977_renderWithDeviceCoordinateCache()
{
QGraphicsScene scene;
diff --git a/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp b/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp
index 045c242fb4..9015c03f3f 100644
--- a/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp
+++ b/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp
@@ -411,6 +411,7 @@ void tst_QLineEdit::cleanup()
{
delete m_testWidget;
m_testWidget = 0;
+ m_platformInputContext.m_commitString.clear();
}
void tst_QLineEdit::experimental()