From a8188c22ad67b339c1c68b39da0064473fec8171 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Mon, 19 Apr 2010 13:17:51 +1000 Subject: Speed up Rectangle creation with pen or gradient slightly --- src/declarative/graphicsitems/qdeclarativerectangle.cpp | 11 +++++++++-- src/declarative/graphicsitems/qdeclarativerectangle_p_p.h | 8 +++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/declarative/graphicsitems/qdeclarativerectangle.cpp b/src/declarative/graphicsitems/qdeclarativerectangle.cpp index 54c8ab2..0328f91 100644 --- a/src/declarative/graphicsitems/qdeclarativerectangle.cpp +++ b/src/declarative/graphicsitems/qdeclarativerectangle.cpp @@ -172,6 +172,8 @@ void QDeclarativeGradient::doUpdate() \image declarative-rect.png */ +int QDeclarativeRectanglePrivate::doUpdateSlotIdx = -1; + /*! \internal \class QDeclarativeRectangle @@ -252,11 +254,16 @@ void QDeclarativeRectangle::setGradient(QDeclarativeGradient *gradient) Q_D(QDeclarativeRectangle); if (d->gradient == gradient) return; + static int updatedSignalIdx = -1; + if (updatedSignalIdx < 0) + updatedSignalIdx = QDeclarativeGradient::staticMetaObject.indexOfSignal("updated()"); + if (d->doUpdateSlotIdx < 0) + d->doUpdateSlotIdx = QDeclarativeRectangle::staticMetaObject.indexOfSlot("doUpdate()"); if (d->gradient) - disconnect(d->gradient, SIGNAL(updated()), this, SLOT(doUpdate())); + QMetaObject::disconnect(d->gradient, updatedSignalIdx, this, d->doUpdateSlotIdx); d->gradient = gradient; if (d->gradient) - connect(d->gradient, SIGNAL(updated()), this, SLOT(doUpdate())); + QMetaObject::connect(d->gradient, updatedSignalIdx, this, d->doUpdateSlotIdx); update(); } diff --git a/src/declarative/graphicsitems/qdeclarativerectangle_p_p.h b/src/declarative/graphicsitems/qdeclarativerectangle_p_p.h index 84418bc..001b018 100644 --- a/src/declarative/graphicsitems/qdeclarativerectangle_p_p.h +++ b/src/declarative/graphicsitems/qdeclarativerectangle_p_p.h @@ -81,12 +81,18 @@ public: qreal radius; qreal paintmargin; QPixmap rectImage; + static int doUpdateSlotIdx; QDeclarativePen *getPen() { if (!pen) { Q_Q(QDeclarativeRectangle); pen = new QDeclarativePen; - QObject::connect(pen, SIGNAL(penChanged()), q, SLOT(doUpdate())); + static int penChangedSignalIdx = -1; + if (penChangedSignalIdx < 0) + penChangedSignalIdx = QDeclarativePen::staticMetaObject.indexOfSignal("penChanged()"); + if (doUpdateSlotIdx < 0) + doUpdateSlotIdx = QDeclarativeRectangle::staticMetaObject.indexOfSlot("doUpdate()"); + QMetaObject::connect(pen, penChangedSignalIdx, q, doUpdateSlotIdx); } return pen; } -- cgit v0.12