From a2f83283a64460ca26530321f8eb64f3ddfe4c8b Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Mon, 23 Aug 2010 13:44:12 +0200 Subject: Fix assignment of a container included in the container itself Task-number: QTBUG-13079 Reviewed-by: Joao --- src/corelib/tools/qhash.h | 5 +- src/corelib/tools/qlinkedlist.h | 5 +- src/corelib/tools/qlist.h | 5 +- src/corelib/tools/qmap.h | 5 +- src/corelib/tools/qvector.h | 5 +- tests/auto/collections/tst_collections.cpp | 87 ++++++++++++++++++++++++++++++ 6 files changed, 102 insertions(+), 10 deletions(-) diff --git a/src/corelib/tools/qhash.h b/src/corelib/tools/qhash.h index 0777f06..c7e4bc1 100644 --- a/src/corelib/tools/qhash.h +++ b/src/corelib/tools/qhash.h @@ -589,10 +589,11 @@ template Q_INLINE_TEMPLATE QHash &QHash::operator=(const QHash &other) { if (d != other.d) { - other.d->ref.ref(); + QHashData *o = other.d; + o->ref.ref(); if (!d->ref.deref()) freeData(d); - d = other.d; + d = o; if (!d->sharable) detach_helper(); } diff --git a/src/corelib/tools/qlinkedlist.h b/src/corelib/tools/qlinkedlist.h index d145fe3..9b3efa3 100644 --- a/src/corelib/tools/qlinkedlist.h +++ b/src/corelib/tools/qlinkedlist.h @@ -312,10 +312,11 @@ template QLinkedList &QLinkedList::operator=(const QLinkedList &l) { if (d != l.d) { - l.d->ref.ref(); + QLinkedListData *o = l.d; + o->ref.ref(); if (!d->ref.deref()) free(d); - d = l.d; + d = o; if (!d->sharable) detach_helper(); } diff --git a/src/corelib/tools/qlist.h b/src/corelib/tools/qlist.h index 722744c..d843cbe 100644 --- a/src/corelib/tools/qlist.h +++ b/src/corelib/tools/qlist.h @@ -424,10 +424,11 @@ template Q_INLINE_TEMPLATE QList &QList::operator=(const QList &l) { if (d != l.d) { - l.d->ref.ref(); + QListData::Data *o = l.d; + o->ref.ref(); if (!d->ref.deref()) free(d); - d = l.d; + d = o; if (!d->sharable) detach_helper(); } diff --git a/src/corelib/tools/qmap.h b/src/corelib/tools/qmap.h index e4b73a1..1c2aad3 100644 --- a/src/corelib/tools/qmap.h +++ b/src/corelib/tools/qmap.h @@ -426,10 +426,11 @@ template Q_INLINE_TEMPLATE QMap &QMap::operator=(const QMap &other) { if (d != other.d) { - other.d->ref.ref(); + QMapData* o = other.d; + o->ref.ref(); if (!d->ref.deref()) freeData(d); - d = other.d; + d = o; if (!d->sharable) detach_helper(); } diff --git a/src/corelib/tools/qvector.h b/src/corelib/tools/qvector.h index c2e2485..b762b8a 100644 --- a/src/corelib/tools/qvector.h +++ b/src/corelib/tools/qvector.h @@ -377,10 +377,11 @@ inline void QVector::replace(int i, const T &t) template QVector &QVector::operator=(const QVector &v) { - v.d->ref.ref(); + QVectorData *o = v.d; + o->ref.ref(); if (!d->ref.deref()) free(p); - d = v.d; + d = o; if (!d->sharable) detach_helper(); return *this; diff --git a/tests/auto/collections/tst_collections.cpp b/tests/auto/collections/tst_collections.cpp index d092c34..8617e02 100644 --- a/tests/auto/collections/tst_collections.cpp +++ b/tests/auto/collections/tst_collections.cpp @@ -165,6 +165,7 @@ private slots: void containerTypedefs(); void forwardDeclared(); void alignment(); + void QTBUG13079_collectionInsideCollection(); }; struct LargeStatic { @@ -3589,5 +3590,91 @@ void tst_Collections::alignment() } #endif +#ifndef QT_NO_TEMPLATE_TEMPLATE_PARAMETERS + +template class C> +struct QTBUG13079_Node { + C children; + QString s; + + ~QTBUG13079_Node() { + children.begin(); //play with memory + } +}; +template class C> void QTBUG13079_collectionInsideCollectionImpl() +{ + C > nodeList; + nodeList << QTBUG13079_Node(); + nodeList.first().s = "parent"; + nodeList.first().children << QTBUG13079_Node(); + nodeList.first().children.first().s = "child"; + + nodeList = nodeList.first().children; + QCOMPARE(nodeList.first().s, QString::fromLatin1("child")); + + nodeList = nodeList.first().children; + QCOMPARE(nodeList.count(), 0); + nodeList << QTBUG13079_Node(); +} + +template class C> +struct QTBUG13079_NodeAssoc { + C children; + QString s; + + ~QTBUG13079_NodeAssoc() { + children.begin(); //play with memory + } +}; +template class C> void QTBUG13079_collectionInsideCollectionAssocImpl() +{ + C > nodeMap; + nodeMap[18] = QTBUG13079_NodeAssoc(); + nodeMap[18].s = "parent"; + nodeMap[18].children[12] = QTBUG13079_NodeAssoc(); + nodeMap[18].children[12].s = "child"; + + nodeMap = nodeMap[18].children; + QCOMPARE(nodeMap[12].s, QString::fromLatin1("child")); + + nodeMap = nodeMap[12].children; + QCOMPARE(nodeMap.count(), 0); + nodeMap[42] = QTBUG13079_NodeAssoc(); +} + + +static quint32 qHash(const QTBUG13079_Node &) +{ + return 0; +} + +bool operator==(const QTBUG13079_Node &a, const QTBUG13079_Node &b) +{ + return a.s == b.s && a.children == b.children; +} + +#endif + +void tst_Collections::QTBUG13079_collectionInsideCollection() +{ +#ifndef QT_NO_TEMPLATE_TEMPLATE_PARAMETERS + QTBUG13079_collectionInsideCollectionImpl(); + QTBUG13079_collectionInsideCollectionImpl(); + QTBUG13079_collectionInsideCollectionImpl(); + QTBUG13079_collectionInsideCollectionImpl(); + QTBUG13079_collectionInsideCollectionImpl(); + + { + QSet > nodeSet; + nodeSet << QTBUG13079_Node(); + nodeSet = nodeSet.begin()->children; + QCOMPARE(nodeSet.count(), 0); + } + + QTBUG13079_collectionInsideCollectionAssocImpl(); + QTBUG13079_collectionInsideCollectionAssocImpl(); +#endif +} + QTEST_APPLESS_MAIN(tst_Collections) #include "tst_collections.moc" -- cgit v0.12 From 6d8c9c3fddbe1fe0736a015164d5713d49a296d8 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Mon, 23 Aug 2010 15:47:21 +0200 Subject: Fix assignment of a Q(Explicitly)SharedDataPointer included in the data itself Task-number: related to QTBUG-13079 Reviewed-by: Joao --- src/corelib/tools/qshareddata.h | 20 ++++++++------ tests/auto/collections/tst_collections.cpp | 42 ++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 8 deletions(-) diff --git a/src/corelib/tools/qshareddata.h b/src/corelib/tools/qshareddata.h index 7e9934d..6483c90 100644 --- a/src/corelib/tools/qshareddata.h +++ b/src/corelib/tools/qshareddata.h @@ -95,9 +95,10 @@ public: if (o.d != d) { if (o.d) o.d->ref.ref(); - if (d && !d->ref.deref()) - delete d; + T *old = d; d = o.d; + if (old && !old->ref.deref()) + delete old; } return *this; } @@ -105,9 +106,10 @@ public: if (o != d) { if (o) o->ref.ref(); - if (d && !d->ref.deref()) - delete d; + T *old = d; d = o; + if (old && !old->ref.deref()) + delete old; } return *this; } @@ -174,9 +176,10 @@ public: if (o.d != d) { if (o.d) o.d->ref.ref(); - if (d && !d->ref.deref()) - delete d; + T *old = d; d = o.d; + if (old && !old->ref.deref()) + delete old; } return *this; } @@ -184,9 +187,10 @@ public: if (o != d) { if (o) o->ref.ref(); - if (d && !d->ref.deref()) - delete d; + T *old = d; d = o; + if (old && !old->ref.deref()) + delete old; } return *this; } diff --git a/tests/auto/collections/tst_collections.cpp b/tests/auto/collections/tst_collections.cpp index 8617e02..2dc41aa 100644 --- a/tests/auto/collections/tst_collections.cpp +++ b/tests/auto/collections/tst_collections.cpp @@ -3653,6 +3653,44 @@ bool operator==(const QTBUG13079_Node &a, const QTBUG13079_Node &b) return a.s == b.s && a.children == b.children; } +template class C> +struct QTBUG13079_NodePtr : QSharedData { + C child; + QTBUG13079_NodePtr *next; + QString s; + + ~QTBUG13079_NodePtr() { + child.data(); //play with memory + next = 0; + } +}; +template class C> void QTBUG13079_collectionInsidePtrImpl() +{ + typedef C > Ptr; + { + Ptr nodePtr; + nodePtr = Ptr(new QTBUG13079_NodePtr()); + nodePtr->s = "parent"; + nodePtr->child = Ptr(new QTBUG13079_NodePtr()); + nodePtr->child->s = "child"; + nodePtr = nodePtr->child; + QCOMPARE(nodePtr->s, QString::fromLatin1("child")); + nodePtr = nodePtr->child; + QVERIFY(!nodePtr); + } + { + Ptr nodePtr; + nodePtr = Ptr(new QTBUG13079_NodePtr()); + nodePtr->s = "parent"; + nodePtr->next = new QTBUG13079_NodePtr(); + nodePtr->next->s = "next"; + nodePtr = Ptr(nodePtr->next); + QCOMPARE(nodePtr->s, QString::fromLatin1("next")); + nodePtr = Ptr(nodePtr->next); + QVERIFY(!nodePtr); + } +} + #endif void tst_Collections::QTBUG13079_collectionInsideCollection() @@ -3673,6 +3711,10 @@ void tst_Collections::QTBUG13079_collectionInsideCollection() QTBUG13079_collectionInsideCollectionAssocImpl(); QTBUG13079_collectionInsideCollectionAssocImpl(); + + QTBUG13079_collectionInsidePtrImpl(); + QTBUG13079_collectionInsidePtrImpl(); + QTBUG13079_collectionInsidePtrImpl(); #endif } -- cgit v0.12 From 337f2562c5b3b5dc99f62b406f13021e502791e7 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Tue, 24 Aug 2010 10:57:42 +0200 Subject: Fix tst_Collections::QTBUG13079_collectionInsideCollection the 'next' was not initialized --- tests/auto/collections/tst_collections.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/auto/collections/tst_collections.cpp b/tests/auto/collections/tst_collections.cpp index 2dc41aa..f81535e 100644 --- a/tests/auto/collections/tst_collections.cpp +++ b/tests/auto/collections/tst_collections.cpp @@ -3659,9 +3659,9 @@ struct QTBUG13079_NodePtr : QSharedData { QTBUG13079_NodePtr *next; QString s; + QTBUG13079_NodePtr() : next(0) {} ~QTBUG13079_NodePtr() { - child.data(); //play with memory - next = 0; + next = child.data(); //play with memory } }; template class C> void QTBUG13079_collectionInsidePtrImpl() -- cgit v0.12 From 7a5fa8af2d0c3329dd1962d6b053388a960f8305 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Thu, 19 Aug 2010 16:00:57 +0200 Subject: QGraphicsView: Fix assert that may occurs if there are 'empty' item to draw, and changed() signal connected Reviewed-by: bnilsen --- src/gui/graphicsview/qgraphicsscene.cpp | 4 +++- tests/auto/qgraphicsscene/tst_qgraphicsscene.cpp | 26 ++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/gui/graphicsview/qgraphicsscene.cpp b/src/gui/graphicsview/qgraphicsscene.cpp index a98ce6f..3c23884 100644 --- a/src/gui/graphicsview/qgraphicsscene.cpp +++ b/src/gui/graphicsview/qgraphicsscene.cpp @@ -5126,7 +5126,9 @@ void QGraphicsScenePrivate::processDirtyItemsRecursive(QGraphicsItem *item, bool q->update(itemBoundingRect.translated(item->d_ptr->sceneTransform.dx(), item->d_ptr->sceneTransform.dy())); } else { - q->update(item->d_ptr->sceneTransform.mapRect(itemBoundingRect)); + QRectF rect = item->d_ptr->sceneTransform.mapRect(itemBoundingRect); + if (!rect.isEmpty()) + q->update(rect); } } else { QRectF dirtyRect; diff --git a/tests/auto/qgraphicsscene/tst_qgraphicsscene.cpp b/tests/auto/qgraphicsscene/tst_qgraphicsscene.cpp index 903977c..7ee2a48 100644 --- a/tests/auto/qgraphicsscene/tst_qgraphicsscene.cpp +++ b/tests/auto/qgraphicsscene/tst_qgraphicsscene.cpp @@ -276,6 +276,7 @@ private slots: void isActive(); void siblingIndexAlwaysValid(); void removeFullyTransparentItem(); + void zeroScale(); // task specific tests below me void task139710_bspTreeCrash(); @@ -4564,5 +4565,30 @@ void tst_QGraphicsScene::taskQTBUG_7863_paintIntoCacheWithTransparentParts() } } +void tst_QGraphicsScene::zeroScale() +{ + //should not crash + QGraphicsScene scene; + scene.setSceneRect(-100, -100, 100, 100); + QGraphicsView view(&scene); + + ChangedListener cl; + connect(&scene, SIGNAL(changed(const QList &)), &cl, SLOT(changed(const QList &))); + + QGraphicsRectItem *rect1 = new QGraphicsRectItem(0, 0, 0.0000001, 0.00000001); + scene.addItem(rect1); + rect1->setRotation(82); + rect1->setScale(0.00000001); + + QApplication::processEvents(); + QCOMPARE(cl.changes.count(), 1); + QGraphicsRectItem *rect2 = new QGraphicsRectItem(-0.0000001, -0.0000001, 0.0000001, 0.0000001); + rect2->setScale(0.00000001); + scene.addItem(rect2); + rect1->setPos(20,20); + QApplication::processEvents(); + QCOMPARE(cl.changes.count(), 2); +} + QTEST_MAIN(tst_QGraphicsScene) #include "tst_qgraphicsscene.moc" -- cgit v0.12 From acf678e57ed088f3e56a551cac6c7c3322005750 Mon Sep 17 00:00:00 2001 From: Gunnar Sletta Date: Wed, 19 May 2010 07:18:27 +0200 Subject: Use binarysort to find items. Task: http://bugreports.qt.nokia.com/browse/QTBUG-231 Reviwed-by: Eskil --- src/gui/text/qtextengine.cpp | 19 ++++++++++++------- src/gui/text/qtextlayout.cpp | 24 +++++++++++++++++------- 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/src/gui/text/qtextengine.cpp b/src/gui/text/qtextengine.cpp index 5670e29..8d6dd6c 100644 --- a/src/gui/text/qtextengine.cpp +++ b/src/gui/text/qtextengine.cpp @@ -1561,14 +1561,19 @@ bool QTextEngine::isRightToLeft() const int QTextEngine::findItem(int strPos) const { itemize(); - - // ##### use binary search - int item; - for (item = layoutData->items.size()-1; item > 0; --item) { - if (layoutData->items[item].position <= strPos) - break; + int left = 0; + int right = layoutData->items.size()-1; + while(left <= right) { + int middle = ((right-left)/2)+left; + if (strPos > layoutData->items[middle].position) + left = middle+1; + else if(strPos < layoutData->items[middle].position) + right = middle-1; + else { + return middle; + } } - return item; + return right; } QFixed QTextEngine::width(int from, int len) const diff --git a/src/gui/text/qtextlayout.cpp b/src/gui/text/qtextlayout.cpp index 5a11c87..f07c35e 100644 --- a/src/gui/text/qtextlayout.cpp +++ b/src/gui/text/qtextlayout.cpp @@ -1217,7 +1217,7 @@ void QTextLayout::draw(QPainter *p, const QPointF &pos, const QVectorlayoutData->items.size()-1; newItem > 0; --newItem) { - if (eng->layoutData->items[newItem].position <= line.from) + int newItem = -1; + int left = 0; + int right = eng->layoutData->items.size()-1; + while(left <= right) { + int middle = ((right-left)/2)+left; + if (line.from > eng->layoutData->items[middle].position) + left = middle+1; + else if(line.from < eng->layoutData->items[middle].position) + right = middle-1; + else { + newItem = middle; break; + } } + if (newItem == -1) + newItem = right; LB_DEBUG("from: %d: item=%d, total %d, width available %f", line.from, newItem, eng->layoutData->items.size(), line.width.toReal()); @@ -1960,7 +1970,7 @@ void QTextLine::layout_helper(int maxGlyphs) } LB_DEBUG("reached end of line"); lbh.checkFullOtherwiseExtend(line); -found: +found: if (lbh.rightBearing > 0 && !lbh.whiteSpaceOrObject) // If right bearing has not yet been adjusted lbh.adjustRightBearing(); line.textAdvance = line.textWidth; -- cgit v0.12 From f3771c5d91995b2beaa73bd3e3c783b76a887b50 Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Tue, 24 Aug 2010 15:06:39 +0200 Subject: Fix mispositioned text with QStaticText and OpenVG graphics system The OpenVG paint engine, like the OpenGL2 paint engine, supports caching the untransformed glyphs and transforming them as they are drawn. Since we would pretransform the positions of the glyphs, the transformation would be applied twice, thus making the glyphs appear in the wrong location when the painter had a transform set. Task-number: QTBUG-13049 Reviewed-by: Gunnar --- src/gui/painting/qpainter.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/gui/painting/qpainter.cpp b/src/gui/painting/qpainter.cpp index b694d9c..be90006 100644 --- a/src/gui/painting/qpainter.cpp +++ b/src/gui/painting/qpainter.cpp @@ -5862,10 +5862,13 @@ void QPainter::drawStaticText(const QPointF &topLeftPosition, const QStaticText return; } - if (d->extended->type() == QPaintEngine::OpenGL2 && !staticText_d->untransformedCoordinates) { + bool paintEngineSupportsTransformations = d->extended->type() == QPaintEngine::OpenGL2 + || d->extended->type() == QPaintEngine::OpenVG; + + if (paintEngineSupportsTransformations && !staticText_d->untransformedCoordinates) { staticText_d->untransformedCoordinates = true; staticText_d->needsRelayout = true; - } else if (d->extended->type() != QPaintEngine::OpenGL2 && staticText_d->untransformedCoordinates) { + } else if (!paintEngineSupportsTransformations && staticText_d->untransformedCoordinates) { staticText_d->untransformedCoordinates = false; staticText_d->needsRelayout = true; } -- cgit v0.12