summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--doc/src/declarative/qdeclarativeperformance.qdoc12
-rw-r--r--src/declarative/graphicsitems/qdeclarativeborderimage.cpp5
-rw-r--r--src/declarative/graphicsitems/qdeclarativeborderimage_p.h1
-rw-r--r--src/declarative/graphicsitems/qdeclarativeborderimage_p_p.h11
-rw-r--r--src/declarative/graphicsitems/qdeclarativeflickable.cpp21
-rw-r--r--src/declarative/graphicsitems/qdeclarativeitem.cpp9
-rw-r--r--src/declarative/graphicsitems/qdeclarativerepeater.cpp13
-rw-r--r--src/declarative/util/qdeclarativexmllistmodel.cpp71
-rw-r--r--tests/auto/declarative/qdeclarativeitem/data/childrenRectBug2.qml53
-rw-r--r--tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp27
-rw-r--r--tests/auto/declarative/qdeclarativeqt/data/createComponent_lib.js7
-rw-r--r--tests/auto/declarative/qdeclarativeqt/data/createComponent_lib.qml10
-rw-r--r--tests/auto/declarative/qdeclarativeqt/tst_qdeclarativeqt.cpp11
13 files changed, 202 insertions, 49 deletions
diff --git a/doc/src/declarative/qdeclarativeperformance.qdoc b/doc/src/declarative/qdeclarativeperformance.qdoc
index b535e4b..c866724 100644
--- a/doc/src/declarative/qdeclarativeperformance.qdoc
+++ b/doc/src/declarative/qdeclarativeperformance.qdoc
@@ -117,4 +117,16 @@ a Loader as needed.
\o Fast data access - ensure the data model is as fast as possible.
\endlist
+\section1 Image resources over composition
+
+If possible, provide a single image resource, rather than using composition
+of a number of elements. For example, a frame with a shadow could be created using
+a Rectangle placed over an Image providing the shadow. It is more efficient to
+provide an image that includes the frame and the shadow.
+
+\section1 Limit JavaScript
+
+Avoid running JavaScript during animation. For example, running a complex
+JavaScript expression for each frame of an x property animation.
+
*/
diff --git a/src/declarative/graphicsitems/qdeclarativeborderimage.cpp b/src/declarative/graphicsitems/qdeclarativeborderimage.cpp
index cf458da..d4ca9eb 100644
--- a/src/declarative/graphicsitems/qdeclarativeborderimage.cpp
+++ b/src/declarative/graphicsitems/qdeclarativeborderimage.cpp
@@ -449,6 +449,11 @@ void QDeclarativeBorderImage::sciRequestFinished()
}
}
+void QDeclarativeBorderImage::doUpdate()
+{
+ update();
+}
+
void QDeclarativeBorderImage::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *)
{
Q_D(QDeclarativeBorderImage);
diff --git a/src/declarative/graphicsitems/qdeclarativeborderimage_p.h b/src/declarative/graphicsitems/qdeclarativeborderimage_p.h
index 5e725ca..07f049e 100644
--- a/src/declarative/graphicsitems/qdeclarativeborderimage_p.h
+++ b/src/declarative/graphicsitems/qdeclarativeborderimage_p.h
@@ -91,6 +91,7 @@ private:
void setGridScaledImage(const QDeclarativeGridScaledImage& sci);
private Q_SLOTS:
+ void doUpdate();
void requestFinished();
void sciRequestFinished();
diff --git a/src/declarative/graphicsitems/qdeclarativeborderimage_p_p.h b/src/declarative/graphicsitems/qdeclarativeborderimage_p_p.h
index 3535109..01e4a00 100644
--- a/src/declarative/graphicsitems/qdeclarativeborderimage_p_p.h
+++ b/src/declarative/graphicsitems/qdeclarativeborderimage_p_p.h
@@ -77,11 +77,20 @@ public:
{
}
+
QDeclarativeScaleGrid *getScaleGrid()
{
Q_Q(QDeclarativeBorderImage);
- if (!border)
+ if (!border) {
border = new QDeclarativeScaleGrid(q);
+ static int borderChangedSignalIdx = -1;
+ static int doUpdateSlotIdx = -1;
+ if (borderChangedSignalIdx < 0)
+ borderChangedSignalIdx = QDeclarativeScaleGrid::staticMetaObject.indexOfSignal("borderChanged()");
+ if (doUpdateSlotIdx < 0)
+ doUpdateSlotIdx = QDeclarativeBorderImage::staticMetaObject.indexOfSlot("doUpdate()");
+ QMetaObject::connect(border, borderChangedSignalIdx, q, doUpdateSlotIdx);
+ }
return border;
}
diff --git a/src/declarative/graphicsitems/qdeclarativeflickable.cpp b/src/declarative/graphicsitems/qdeclarativeflickable.cpp
index 6dfd4d9..3f681b7 100644
--- a/src/declarative/graphicsitems/qdeclarativeflickable.cpp
+++ b/src/declarative/graphicsitems/qdeclarativeflickable.cpp
@@ -914,8 +914,14 @@ void QDeclarativeFlickable::timerEvent(QTimerEvent *event)
d->delayedPressTimer.stop();
if (d->delayedPressEvent) {
QDeclarativeItem *grabber = scene() ? qobject_cast<QDeclarativeItem*>(scene()->mouseGrabberItem()) : 0;
- if (!grabber || grabber != this)
- scene()->sendEvent(d->delayedPressTarget, d->delayedPressEvent);
+ if (!grabber || grabber != this) {
+ // We replay the mouse press but the grabber we had might not be interessted by the event (e.g. overlay)
+ // so we reset the grabber
+ if (scene()->mouseGrabberItem() == d->delayedPressTarget)
+ d->delayedPressTarget->ungrabMouse();
+ //Use the event handler that will take care of finding the proper item to propagate the event
+ QApplication::sendEvent(scene(), d->delayedPressEvent);
+ }
delete d->delayedPressEvent;
d->delayedPressEvent = 0;
}
@@ -1206,8 +1212,17 @@ bool QDeclarativeFlickable::sendMouseEvent(QGraphicsSceneMouseEvent *event)
break;
case QEvent::GraphicsSceneMouseRelease:
if (d->delayedPressEvent) {
- scene()->sendEvent(d->delayedPressTarget, d->delayedPressEvent);
+ // We replay the mouse press but the grabber we had might not be interessted by the event (e.g. overlay)
+ // so we reset the grabber
+ if (s->mouseGrabberItem() == d->delayedPressTarget)
+ d->delayedPressTarget->ungrabMouse();
+ //Use the event handler that will take care of finding the proper item to propagate the event
+ QApplication::sendEvent(scene(), d->delayedPressEvent);
d->clearDelayedPress();
+ // We send the release
+ scene()->sendEvent(s->mouseGrabberItem(), event);
+ // And the event has been consumed
+ return true;
}
d->handleMouseReleaseEvent(&mouseEvent);
break;
diff --git a/src/declarative/graphicsitems/qdeclarativeitem.cpp b/src/declarative/graphicsitems/qdeclarativeitem.cpp
index 42b370b..336010f 100644
--- a/src/declarative/graphicsitems/qdeclarativeitem.cpp
+++ b/src/declarative/graphicsitems/qdeclarativeitem.cpp
@@ -345,10 +345,11 @@ void QDeclarativeContents::complete()
void QDeclarativeContents::itemGeometryChanged(QDeclarativeItem *changed, const QRectF &newGeometry, const QRectF &oldGeometry)
{
- if (newGeometry.width() != oldGeometry.width())
- calcWidth(changed);
- if (newGeometry.height() != oldGeometry.height())
- calcHeight(changed);
+ //### we can only pass changed if the left edge has moved left, or the right edge has moved right
+ if (newGeometry.width() != oldGeometry.width() || newGeometry.x() != oldGeometry.x())
+ calcWidth(/*changed*/);
+ if (newGeometry.height() != oldGeometry.height() || newGeometry.y() != oldGeometry.y())
+ calcHeight(/*changed*/);
}
void QDeclarativeContents::itemDestroyed(QDeclarativeItem *item)
diff --git a/src/declarative/graphicsitems/qdeclarativerepeater.cpp b/src/declarative/graphicsitems/qdeclarativerepeater.cpp
index 995e22a..87da904 100644
--- a/src/declarative/graphicsitems/qdeclarativerepeater.cpp
+++ b/src/declarative/graphicsitems/qdeclarativerepeater.cpp
@@ -83,17 +83,10 @@ QDeclarativeRepeaterPrivate::~QDeclarativeRepeaterPrivate()
\image repeater-simple.png
- The \l model of a Repeater can be specified as a model object, a number, a string list
- or an object list. If a model object is used, the
- \l delegate can access the model roles as named properties, just as for view elements like
- ListView and GridView.
+ The \l model of a Repeater can be any of the supported \l {qmlmodels}{Data Models}.
- The \l delegate can also access two additional properties:
-
- \list
- \o \c index - the index of the delegate's item
- \o \c modelData - the data element for the delegate, which is useful where the \l model is a string or object list
- \endlist
+ The index of a delegate is exposed as an accessible \c index property in the delegate.
+ Properties of the model are also available depending upon the type of \l {qmlmodels}{Data Model}.
Here is a Repeater that uses the \c index property inside the instantiated items:
diff --git a/src/declarative/util/qdeclarativexmllistmodel.cpp b/src/declarative/util/qdeclarativexmllistmodel.cpp
index 4adef25..bfd25be 100644
--- a/src/declarative/util/qdeclarativexmllistmodel.cpp
+++ b/src/declarative/util/qdeclarativexmllistmodel.cpp
@@ -148,6 +148,7 @@ public:
QDeclarativeXmlQuery(QObject *parent=0)
: QThread(parent), m_quit(false), m_abortQueryId(-1), m_queryIds(XMLLISTMODEL_CLEAR_ID + 1) {
qRegisterMetaType<QDeclarativeXmlQueryResult>("QDeclarativeXmlQueryResult");
+ m_currentJob.queryId = -1;
}
~QDeclarativeXmlQuery() {
@@ -161,6 +162,13 @@ public:
void abort(int id) {
QMutexLocker locker(&m_mutex);
+ QQueue<XmlQueryJob>::iterator it;
+ for (it = m_jobs.begin(); it != m_jobs.end(); ++it) {
+ if ((*it).queryId == id) {
+ m_jobs.erase(it);
+ return;
+ }
+ }
m_abortQueryId = id;
}
@@ -188,7 +196,7 @@ public:
m_queryIds++;
if (!isRunning())
- start();
+ start(QThread::IdlePriority);
else
m_condition.wakeOne();
return job.queryId;
@@ -202,24 +210,28 @@ protected:
void run() {
while (!m_quit) {
m_mutex.lock();
- doQueryJob();
- doSubQueryJob();
+ if (!m_jobs.isEmpty())
+ m_currentJob = m_jobs.dequeue();
m_mutex.unlock();
- m_mutex.lock();
- const XmlQueryJob &job = m_jobs.dequeue();
- if (m_abortQueryId != job.queryId) {
- QDeclarativeXmlQueryResult r;
- r.queryId = job.queryId;
+ QDeclarativeXmlQueryResult r;
+ if (m_currentJob.queryId != -1) {
+ doQueryJob();
+ doSubQueryJob();
+ r.queryId = m_currentJob.queryId;
r.size = m_size;
r.data = m_modelData;
r.inserted = m_insertedItemRanges;
r.removed = m_removedItemRanges;
- r.keyRoleResultsCache = job.keyRoleResultsCache;
- emit queryCompleted(r);
+ r.keyRoleResultsCache = m_currentJob.keyRoleResultsCache;
}
+
+ m_mutex.lock();
+ if (m_currentJob.queryId != -1 && m_abortQueryId != m_currentJob.queryId)
+ emit queryCompleted(r);
if (m_jobs.isEmpty())
m_condition.wait(&m_mutex);
+ m_currentJob.queryId = -1;
m_abortQueryId = -1;
m_mutex.unlock();
}
@@ -235,6 +247,7 @@ private:
QMutex m_mutex;
QWaitCondition m_condition;
QQueue<XmlQueryJob> m_jobs;
+ XmlQueryJob m_currentJob;
bool m_quit;
int m_abortQueryId;
QString m_prefix;
@@ -249,15 +262,14 @@ Q_GLOBAL_STATIC(QDeclarativeXmlQuery, globalXmlQuery)
void QDeclarativeXmlQuery::doQueryJob()
{
- Q_ASSERT(!m_jobs.isEmpty());
- XmlQueryJob &job = m_jobs.head();
+ Q_ASSERT(m_currentJob.queryId != -1);
QString r;
QXmlQuery query;
- QBuffer buffer(&job.data);
+ QBuffer buffer(&m_currentJob.data);
buffer.open(QIODevice::ReadOnly);
query.bindVariable(QLatin1String("src"), &buffer);
- query.setQuery(job.namespaces + job.query);
+ query.setQuery(m_currentJob.namespaces + m_currentJob.query);
query.evaluateTo(&r);
//always need a single root element
@@ -265,9 +277,9 @@ void QDeclarativeXmlQuery::doQueryJob()
QBuffer b(&xml);
b.open(QIODevice::ReadOnly);
- QString namespaces = QLatin1String("declare namespace dummy=\"http://qtsotware.com/dummy\";\n") + job.namespaces;
+ QString namespaces = QLatin1String("declare namespace dummy=\"http://qtsotware.com/dummy\";\n") + m_currentJob.namespaces;
QString prefix = QLatin1String("doc($inputDocument)/dummy:items") +
- job.query.mid(job.query.lastIndexOf(QLatin1Char('/')));
+ m_currentJob.query.mid(m_currentJob.query.lastIndexOf(QLatin1Char('/')));
//figure out how many items we are dealing with
int count = -1;
@@ -282,7 +294,7 @@ void QDeclarativeXmlQuery::doQueryJob()
count = item.toAtomicValue().toInt();
}
- job.data = xml;
+ m_currentJob.data = xml;
m_prefix = namespaces + prefix + QLatin1Char('/');
m_size = 0;
if (count > 0)
@@ -291,9 +303,9 @@ void QDeclarativeXmlQuery::doQueryJob()
void QDeclarativeXmlQuery::getValuesOfKeyRoles(QStringList *values, QXmlQuery *query) const
{
- Q_ASSERT(!m_jobs.isEmpty());
+ Q_ASSERT(m_currentJob.queryId != -1);
- const QStringList &keysQueries = m_jobs.head().keyRoleQueries;
+ const QStringList &keysQueries = m_currentJob.keyRoleQueries;
QString keysQuery;
if (keysQueries.count() == 1)
keysQuery = m_prefix + keysQueries[0];
@@ -323,11 +335,10 @@ void QDeclarativeXmlQuery::addIndexToRangeList(QList<QDeclarativeXmlListRange> *
void QDeclarativeXmlQuery::doSubQueryJob()
{
- Q_ASSERT(!m_jobs.isEmpty());
- XmlQueryJob &job = m_jobs.head();
+ Q_ASSERT(m_currentJob.queryId != -1);
m_modelData.clear();
- QBuffer b(&job.data);
+ QBuffer b(&m_currentJob.data);
b.open(QIODevice::ReadOnly);
QXmlQuery subquery;
@@ -340,16 +351,16 @@ void QDeclarativeXmlQuery::doSubQueryJob()
m_insertedItemRanges.clear();
m_removedItemRanges.clear();
- if (job.keyRoleResultsCache.isEmpty()) {
+ if (m_currentJob.keyRoleResultsCache.isEmpty()) {
m_insertedItemRanges << qMakePair(0, m_size);
} else {
- if (keyRoleResults != job.keyRoleResultsCache) {
+ if (keyRoleResults != m_currentJob.keyRoleResultsCache) {
QStringList temp;
- for (int i=0; i<job.keyRoleResultsCache.count(); i++) {
- if (!keyRoleResults.contains(job.keyRoleResultsCache[i]))
+ for (int i=0; i<m_currentJob.keyRoleResultsCache.count(); i++) {
+ if (!keyRoleResults.contains(m_currentJob.keyRoleResultsCache[i]))
addIndexToRangeList(&m_removedItemRanges, i);
else
- temp << job.keyRoleResultsCache[i];
+ temp << m_currentJob.keyRoleResultsCache[i];
}
for (int i=0; i<keyRoleResults.count(); i++) {
@@ -360,11 +371,11 @@ void QDeclarativeXmlQuery::doSubQueryJob()
}
}
}
- job.keyRoleResultsCache = keyRoleResults;
+ m_currentJob.keyRoleResultsCache = keyRoleResults;
// Get the new values for each role.
//### we might be able to condense even further (query for everything in one go)
- const QStringList &queries = job.roleQueries;
+ const QStringList &queries = m_currentJob.roleQueries;
for (int i = 0; i < queries.size(); ++i) {
QList<QVariant> resultList;
if (!queries[i].isEmpty()) {
@@ -378,7 +389,7 @@ void QDeclarativeXmlQuery::doSubQueryJob()
item = resultItems.next();
}
} else {
- emit error(job.roleQueryErrorId.at(i), queries[i]);
+ emit error(m_currentJob.roleQueryErrorId.at(i), queries[i]);
}
}
//### should warn here if things have gone wrong.
diff --git a/tests/auto/declarative/qdeclarativeitem/data/childrenRectBug2.qml b/tests/auto/declarative/qdeclarativeitem/data/childrenRectBug2.qml
new file mode 100644
index 0000000..225d8d4
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeitem/data/childrenRectBug2.qml
@@ -0,0 +1,53 @@
+import Qt 4.7
+
+Rectangle {
+ width:360;
+ height: 200
+
+ Item {
+ objectName: "theItem"
+ anchors.centerIn: parent
+ width: childrenRect.width
+ height: childrenRect.height
+ Rectangle {
+ id: header1
+ anchors.horizontalCenter: parent.horizontalCenter
+ anchors.top: parent.top
+ width: 100; height: 50
+ color: "green"
+ }
+ Rectangle {
+ id: text1
+ anchors.top: header1.bottom
+ anchors.topMargin: 10
+ anchors.horizontalCenter: parent.horizontalCenter
+ width: 100; height: 50
+ color: "blue"
+ }
+ }
+
+ states: [
+ State {
+ name: "row"
+ AnchorChanges {
+ target: header1
+ anchors.horizontalCenter: undefined
+ anchors.verticalCenter: parent.verticalCenter
+ anchors.left: parent.left
+ anchors.top: undefined
+ }
+ AnchorChanges {
+ target: text1
+ anchors.horizontalCenter: undefined
+ anchors.verticalCenter: parent.verticalCenter
+ anchors.top: undefined
+ anchors.left: header1.right
+ }
+ PropertyChanges {
+ target: text1
+ anchors.leftMargin: 10
+ anchors.topMargin: 0
+ }
+ }
+ ]
+}
diff --git a/tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp b/tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp
index 0a66245..4a57def 100644
--- a/tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp
+++ b/tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp
@@ -44,7 +44,8 @@
#include <QtDeclarative/qdeclarativecomponent.h>
#include <QtDeclarative/qdeclarativecontext.h>
#include <QtDeclarative/qdeclarativeview.h>
-#include <QtDeclarative/qdeclarativeitem.h>
+#include <private/qdeclarativerectangle_p.h>
+#include <private/qdeclarativeitem_p.h>
#include "../../../shared/util.h"
#ifdef Q_OS_SYMBIAN
@@ -73,6 +74,7 @@ private slots:
void transforms_data();
void childrenRect();
void childrenRectBug();
+ void childrenRectBug2();
void childrenProperty();
void resourcesProperty();
@@ -753,6 +755,29 @@ void tst_QDeclarativeItem::childrenRectBug()
delete canvas;
}
+// QTBUG-11465
+void tst_QDeclarativeItem::childrenRectBug2()
+{
+ QDeclarativeView *canvas = new QDeclarativeView(0);
+ canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/childrenRectBug2.qml"));
+ canvas->show();
+
+ QDeclarativeRectangle *rect = qobject_cast<QDeclarativeRectangle*>(canvas->rootObject());
+ QVERIFY(rect);
+ QDeclarativeItem *item = rect->findChild<QDeclarativeItem*>("theItem");
+ QCOMPARE(item->width(), qreal(100));
+ QCOMPARE(item->height(), qreal(110));
+ QCOMPARE(item->x(), qreal(130));
+
+ QDeclarativeItemPrivate *rectPrivate = QDeclarativeItemPrivate::get(rect);
+ rectPrivate->setState("row");
+ QCOMPARE(item->width(), qreal(210));
+ QCOMPARE(item->height(), qreal(50));
+ QCOMPARE(item->x(), qreal(75));
+
+ delete canvas;
+}
+
template<typename T>
T *tst_QDeclarativeItem::findItem(QGraphicsObject *parent, const QString &objectName)
{
diff --git a/tests/auto/declarative/qdeclarativeqt/data/createComponent_lib.js b/tests/auto/declarative/qdeclarativeqt/data/createComponent_lib.js
new file mode 100644
index 0000000..c165e29
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeqt/data/createComponent_lib.js
@@ -0,0 +1,7 @@
+.pragma library
+
+function loadComponent() {
+ var component = Qt.createComponent("createComponentData.qml");
+ return component.status;
+}
+
diff --git a/tests/auto/declarative/qdeclarativeqt/data/createComponent_lib.qml b/tests/auto/declarative/qdeclarativeqt/data/createComponent_lib.qml
new file mode 100644
index 0000000..aae7a91
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeqt/data/createComponent_lib.qml
@@ -0,0 +1,10 @@
+import Qt 4.7
+import "createComponent_lib.js" as Test
+
+Item {
+ property int status: Component.Null
+
+ Component.onCompleted: {
+ status = Test.loadComponent()
+ }
+}
diff --git a/tests/auto/declarative/qdeclarativeqt/tst_qdeclarativeqt.cpp b/tests/auto/declarative/qdeclarativeqt/tst_qdeclarativeqt.cpp
index 06561fa..e3e0ba0 100644
--- a/tests/auto/declarative/qdeclarativeqt/tst_qdeclarativeqt.cpp
+++ b/tests/auto/declarative/qdeclarativeqt/tst_qdeclarativeqt.cpp
@@ -76,6 +76,7 @@ private slots:
void openUrlExternally();
void md5();
void createComponent();
+ void createComponent_pragmaLibrary();
void createQmlObject();
void consoleLog();
void formatting();
@@ -361,6 +362,16 @@ void tst_qdeclarativeqt::createComponent()
delete object;
}
+void tst_qdeclarativeqt::createComponent_pragmaLibrary()
+{
+ QDeclarativeComponent component(&engine, TEST_FILE("createComponent_lib.qml"));
+ QObject *object = component.create();
+ QVERIFY(object != 0);
+
+ QEXPECT_FAIL("", "QTBUG-11507", Continue);
+ QCOMPARE(object->property("status").toInt(), int(QDeclarativeComponent::Ready));
+}
+
void tst_qdeclarativeqt::createQmlObject()
{
QDeclarativeComponent component(&engine, TEST_FILE("createQmlObject.qml"));