summaryrefslogtreecommitdiffstats
path: root/tests/auto/qgraphicsitem
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/qgraphicsitem')
-rw-r--r--tests/auto/qgraphicsitem/nestedClipping_reference.pngbin638 -> 0 bytes
-rw-r--r--tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp171
2 files changed, 169 insertions, 2 deletions
diff --git a/tests/auto/qgraphicsitem/nestedClipping_reference.png b/tests/auto/qgraphicsitem/nestedClipping_reference.png
deleted file mode 100644
index 3bd4fe7..0000000
--- a/tests/auto/qgraphicsitem/nestedClipping_reference.png
+++ /dev/null
Binary files differ
diff --git a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp
index bec4950..03ce45a 100644
--- a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp
+++ b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp
@@ -61,6 +61,7 @@
#include <QScrollBar>
#include <QVBoxLayout>
#include <QGraphicsEffect>
+#include <QInputContext>
#include "../../shared/util.h"
@@ -424,6 +425,7 @@ private slots:
void modality_keyEvents();
void itemIsInFront();
void scenePosChange();
+ void updateMicroFocus();
// task specific tests below me
void task141694_textItemEnsureVisible();
@@ -4318,6 +4320,21 @@ protected:
break;
case QGraphicsItem::ItemScenePositionHasChanged:
break;
+ case QGraphicsItem::ItemRotationChange:
+ oldValues << rotation();
+ break;
+ case QGraphicsItem::ItemRotationHasChanged:
+ break;
+ case QGraphicsItem::ItemScaleChange:
+ oldValues << scale();
+ break;
+ case QGraphicsItem::ItemScaleHasChanged:
+ break;
+ case QGraphicsItem::ItemTransformOriginPointChange:
+ oldValues << transformOriginPoint();
+ break;
+ case QGraphicsItem::ItemTransformOriginPointHasChanged:
+ break;
}
return itemChangeReturnValue.isValid() ? itemChangeReturnValue : value;
}
@@ -4414,6 +4431,48 @@ void tst_QGraphicsItem::itemChange()
QCOMPARE(tester.zValue(), qreal(2.0));
}
{
+ // ItemRotationChange / ItemRotationHasChanged
+ tester.itemChangeReturnValue = qreal(15.0);
+ tester.setRotation(10.0);
+ ++changeCount; // notification sent too
+ ++changeCount;
+ QCOMPARE(tester.changes.size(), changeCount);
+ QCOMPARE(tester.changes.at(tester.changes.size() - 2), QGraphicsItem::ItemRotationChange);
+ QCOMPARE(tester.changes.at(tester.changes.size() - 1), QGraphicsItem::ItemRotationHasChanged);
+ QCOMPARE(tester.values.at(tester.changes.size() - 2), QVariant(qreal(10.0)));
+ QCOMPARE(tester.values.at(tester.changes.size() - 1), QVariant(qreal(15.0)));
+ QCOMPARE(tester.oldValues.last(), QVariant(qreal(0.0)));
+ QCOMPARE(tester.rotation(), qreal(15.0));
+ }
+ {
+ // ItemScaleChange / ItemScaleHasChanged
+ tester.itemChangeReturnValue = qreal(2.0);
+ tester.setScale(1.5);
+ ++changeCount; // notification sent too
+ ++changeCount;
+ QCOMPARE(tester.changes.size(), changeCount);
+ QCOMPARE(tester.changes.at(tester.changes.size() - 2), QGraphicsItem::ItemScaleChange);
+ QCOMPARE(tester.changes.at(tester.changes.size() - 1), QGraphicsItem::ItemScaleHasChanged);
+ QCOMPARE(tester.values.at(tester.changes.size() - 2), QVariant(qreal(1.5)));
+ QCOMPARE(tester.values.at(tester.changes.size() - 1), QVariant(qreal(2.0)));
+ QCOMPARE(tester.oldValues.last(), QVariant(qreal(1.0)));
+ QCOMPARE(tester.scale(), qreal(2.0));
+ }
+ {
+ // ItemTransformOriginPointChange / ItemTransformOriginPointHasChanged
+ tester.itemChangeReturnValue = QPointF(2.0, 2.0);
+ tester.setTransformOriginPoint(1.0, 1.0);
+ ++changeCount; // notification sent too
+ ++changeCount;
+ QCOMPARE(tester.changes.size(), changeCount);
+ QCOMPARE(tester.changes.at(tester.changes.size() - 2), QGraphicsItem::ItemTransformOriginPointChange);
+ QCOMPARE(tester.changes.at(tester.changes.size() - 1), QGraphicsItem::ItemTransformOriginPointHasChanged);
+ QCOMPARE(tester.values.at(tester.changes.size() - 2), QVariant(QPointF(1.0, 1.0)));
+ QCOMPARE(tester.values.at(tester.changes.size() - 1), QVariant(QPointF(2.0, 2.0)));
+ QCOMPARE(tester.oldValues.last(), QVariant(QPointF(0.0, 0.0)));
+ QCOMPARE(tester.transformOriginPoint(), QPointF(2.0, 2.0));
+ }
+ {
// ItemFlagsChange
tester.itemChangeReturnValue = QGraphicsItem::ItemIsSelectable;
tester.setFlag(QGraphicsItem::ItemIsSelectable, false);
@@ -7460,10 +7519,19 @@ void tst_QGraphicsItem::itemSendsGeometryChanges()
QTransform x = QTransform().rotate(45);
QPointF pos(10, 10);
qreal o(0.5);
+ qreal r(10.0);
+ qreal s(1.5);
+ QPointF origin(1.0, 1.0);
item.setTransform(x);
item.setPos(pos);
+ item.setRotation(r);
+ item.setScale(s);
+ item.setTransformOriginPoint(origin);
QCOMPARE(item.transform(), x);
QCOMPARE(item.pos(), pos);
+ QCOMPARE(item.rotation(), r);
+ QCOMPARE(item.scale(), s);
+ QCOMPARE(item.transformOriginPoint(), origin);
QCOMPARE(item.changes.size(), 0);
item.setOpacity(o);
@@ -7477,6 +7545,13 @@ void tst_QGraphicsItem::itemSendsGeometryChanges()
QCOMPARE(item.transform(), QTransform());
QCOMPARE(item.pos(), QPointF());
QCOMPARE(item.opacity(), o);
+ item.setRotation(0.0);
+ item.setScale(1.0);
+ item.setTransformOriginPoint(0.0, 0.0);
+ QCOMPARE(item.changes.size(), 14); // rotation + scale + origin
+ QCOMPARE(item.rotation(), qreal(0.0));
+ QCOMPARE(item.scale(), qreal(1.0));
+ QCOMPARE(item.transformOriginPoint(), QPointF(0.0, 0.0));
QCOMPARE(item.changes, QList<QGraphicsItem::GraphicsItemChange>()
<< QGraphicsItem::ItemOpacityChange
@@ -7486,7 +7561,13 @@ void tst_QGraphicsItem::itemSendsGeometryChanges()
<< QGraphicsItem::ItemTransformChange
<< QGraphicsItem::ItemTransformHasChanged
<< QGraphicsItem::ItemPositionChange
- << QGraphicsItem::ItemPositionHasChanged);
+ << QGraphicsItem::ItemPositionHasChanged
+ << QGraphicsItem::ItemRotationChange
+ << QGraphicsItem::ItemRotationHasChanged
+ << QGraphicsItem::ItemScaleChange
+ << QGraphicsItem::ItemScaleHasChanged
+ << QGraphicsItem::ItemTransformOriginPointChange
+ << QGraphicsItem::ItemTransformOriginPointHasChanged);
}
// Make sure we update moved items correctly.
@@ -7794,7 +7875,7 @@ void tst_QGraphicsItem::hitTestGraphicsEffectItem()
QTest::qWait(50);
// Make sure all visible items are repainted.
- QCOMPARE(item1->repaints, 0);
+ QCOMPARE(item1->repaints, 1);
QCOMPARE(item2->repaints, 1);
QCOMPARE(item3->repaints, 1);
@@ -9842,6 +9923,9 @@ void tst_QGraphicsItem::scenePosChange()
child1->setFlag(QGraphicsItem::ItemSendsScenePositionChanges, true);
grandChild2->setFlag(QGraphicsItem::ItemSendsScenePositionChanges, true);
+ QVERIFY(child1->flags() & QGraphicsItem::ItemSendsScenePositionChanges);
+ QVERIFY(grandChild2->flags() & QGraphicsItem::ItemSendsScenePositionChanges);
+
QGraphicsScene scene;
scene.addItem(root);
@@ -9891,6 +9975,89 @@ void tst_QGraphicsItem::scenePosChange()
QCOMPARE(child1->changes.count(QGraphicsItem::ItemScenePositionHasChanged), 4);
QCOMPARE(grandChild1->changes.count(QGraphicsItem::ItemScenePositionHasChanged), 1);
QCOMPARE(child2->changes.count(QGraphicsItem::ItemScenePositionHasChanged), 0);
+
+ root->setX(1);
+ QCOMPARE(child1->changes.count(QGraphicsItem::ItemScenePositionHasChanged), 5);
+ QCOMPARE(grandChild1->changes.count(QGraphicsItem::ItemScenePositionHasChanged), 1);
+ QCOMPARE(child2->changes.count(QGraphicsItem::ItemScenePositionHasChanged), 0);
+
+ root->setY(1);
+ QCOMPARE(child1->changes.count(QGraphicsItem::ItemScenePositionHasChanged), 6);
+ QCOMPARE(grandChild1->changes.count(QGraphicsItem::ItemScenePositionHasChanged), 1);
+ QCOMPARE(child2->changes.count(QGraphicsItem::ItemScenePositionHasChanged), 0);
+}
+
+class MyInputContext : public QInputContext
+{
+public:
+ MyInputContext() : nbUpdates(0) {}
+ ~MyInputContext() {}
+
+ QString identifierName() { return QString(); }
+ QString language() { return QString(); }
+
+ void reset() {}
+
+ bool isComposing() const { return false; }
+
+ void update() { nbUpdates++; }
+
+ bool nbUpdates;
+};
+
+class MyInputWidget : public QGraphicsWidget
+{
+public:
+ MyInputWidget()
+ {
+ setFlag(QGraphicsItem::ItemIsFocusable, true);
+ setFlag(QGraphicsItem::ItemAcceptsInputMethod, true);
+ }
+ void mousePressEvent(QGraphicsSceneMouseEvent *event)
+ {
+ event->accept();
+ }
+
+ void doUpdateMicroFocus()
+ {
+ updateMicroFocus();
+ }
+};
+
+void tst_QGraphicsItem::updateMicroFocus()
+{
+#if defined Q_OS_WIN || defined Q_OS_MAC
+ QSKIP("QTBUG-9578", SkipAll);
+ return;
+#endif
+ QGraphicsScene scene;
+ QWidget parent;
+ QGridLayout layout;
+ parent.setLayout(&layout);
+ QGraphicsView view(&scene);
+ QGraphicsView view2(&scene);
+ layout.addWidget(&view, 0, 0);
+ layout.addWidget(&view2, 0, 1);
+ MyInputContext ic2;
+ view2.setInputContext(&ic2);
+ MyInputContext ic;
+ view.setInputContext(&ic);
+ MyInputWidget input;
+ input.setPos(0, 0);
+ input.resize(150, 150);
+ scene.addItem(&input);
+ input.setFocus();
+ parent.show();
+ view.setFocus();
+ qApp->setAutoSipEnabled(true);
+ QApplication::setActiveWindow(&parent);
+ QTest::qWaitForWindowShown(&parent);
+ QTRY_COMPARE(QApplication::activeWindow(), static_cast<QWidget *>(&parent));
+ input.doUpdateMicroFocus();
+ QApplication::processEvents();
+ QTRY_COMPARE(ic.nbUpdates, 1);
+ //No update since view2 does not have the focus.
+ QTRY_COMPARE(ic2.nbUpdates, 0);
}
void tst_QGraphicsItem::QTBUG_5418_textItemSetDefaultColor()