summaryrefslogtreecommitdiffstats
path: root/src/declarative
diff options
context:
space:
mode:
Diffstat (limited to 'src/declarative')
-rw-r--r--src/declarative/QmlChanges.txt2
-rw-r--r--src/declarative/graphicsitems/qdeclarativeitem.cpp4
-rw-r--r--src/declarative/graphicsitems/qdeclarativepathview.cpp44
-rw-r--r--src/declarative/graphicsitems/qdeclarativepathview_p_p.h1
-rw-r--r--src/declarative/graphicsitems/qdeclarativepositioners.cpp3
-rw-r--r--src/declarative/qml/qdeclarativecontext.cpp85
-rw-r--r--src/declarative/util/qdeclarativepixmapcache.cpp16
7 files changed, 95 insertions, 60 deletions
diff --git a/src/declarative/QmlChanges.txt b/src/declarative/QmlChanges.txt
index 6ab77a7..847f1f5 100644
--- a/src/declarative/QmlChanges.txt
+++ b/src/declarative/QmlChanges.txt
@@ -62,7 +62,7 @@ MouseArea {
becomes
-Import “foo.js” as Foo
+import “foo.js” as Foo
MouseArea {
onClicked: Foo.foo()
}
diff --git a/src/declarative/graphicsitems/qdeclarativeitem.cpp b/src/declarative/graphicsitems/qdeclarativeitem.cpp
index 611535c..e8f3652 100644
--- a/src/declarative/graphicsitems/qdeclarativeitem.cpp
+++ b/src/declarative/graphicsitems/qdeclarativeitem.cpp
@@ -1438,10 +1438,6 @@ QDeclarativeItem::~QDeclarativeItem()
*/
void QDeclarativeItem::setParentItem(QDeclarativeItem *parent)
{
- QDeclarativeItem *oldParent = parentItem();
- if (parent == oldParent || !parent) return;
-
- QObject::setParent(parent);
QGraphicsObject::setParentItem(parent);
}
diff --git a/src/declarative/graphicsitems/qdeclarativepathview.cpp b/src/declarative/graphicsitems/qdeclarativepathview.cpp
index 9b548d4..dd1edd6 100644
--- a/src/declarative/graphicsitems/qdeclarativepathview.cpp
+++ b/src/declarative/graphicsitems/qdeclarativepathview.cpp
@@ -501,6 +501,7 @@ void QDeclarativePathView::setCurrentIndex(int idx)
}
}
}
+ d->currentItem = 0;
d->moveReason = QDeclarativePathViewPrivate::SetIndex;
d->currentIndex = idx;
if (d->model->count()) {
@@ -508,9 +509,9 @@ void QDeclarativePathView::setCurrentIndex(int idx)
d->snapToCurrent();
int itemIndex = (idx - d->firstIndex + d->model->count()) % d->model->count();
if (itemIndex < d->items.count()) {
- QDeclarativeItem *item = d->items.at(itemIndex);
- item->setFocus(true);
- if (QDeclarativePathViewAttached *att = d->attached(item))
+ d->currentItem = d->items.at(itemIndex);
+ d->currentItem->setFocus(true);
+ if (QDeclarativePathViewAttached *att = d->attached(d->currentItem))
att->setIsCurrentItem(true);
}
d->currentItemOffset = d->positionOfIndex(d->currentIndex);
@@ -1083,6 +1084,7 @@ void QDeclarativePathView::refill()
att->setIsCurrentItem(true);
currentVisible = true;
d->currentItemOffset = pos;
+ d->currentItem = item;
}
if (d->items.count() == 0)
d->firstIndex = idx;
@@ -1109,6 +1111,7 @@ void QDeclarativePathView::refill()
att->setIsCurrentItem(true);
currentVisible = true;
d->currentItemOffset = pos;
+ d->currentItem = item;
}
d->items.prepend(item);
d->updateItem(item, pos);
@@ -1161,15 +1164,32 @@ void QDeclarativePathView::itemsRemoved(int modelIndex, int count)
if (!d->isValid() || !isComponentComplete())
return;
+ // fix current
+ bool currentChanged = false;
+ if (d->currentIndex >= modelIndex + count) {
+ d->currentIndex -= count;
+ currentChanged = true;
+ } else if (d->currentIndex >= modelIndex && d->currentIndex < modelIndex + count) {
+ // current item has been removed.
+ d->currentIndex = qMin(modelIndex, d->model->count()-1);
+ if (d->currentItem) {
+ if (QDeclarativePathViewAttached *att = d->attached(d->currentItem))
+ att->setIsCurrentItem(true);
+ }
+ currentChanged = true;
+ }
+
QList<QDeclarativeItem *> removedItems = d->items;
d->items.clear();
if (d->offset >= d->model->count())
d->offset = d->model->count() - 1;
- //XXX update currentIndex
+
d->regenerate();
while (removedItems.count())
d->releaseItem(removedItems.takeLast());
d->updateCurrent();
+ if (currentChanged)
+ emit currentIndexChanged();
emit countChanged();
}
@@ -1181,10 +1201,17 @@ void QDeclarativePathView::itemsMoved(int from, int to, int count)
QList<QDeclarativeItem *> removedItems = d->items;
d->items.clear();
- //XXX update currentIndex
d->regenerate();
while (removedItems.count())
d->releaseItem(removedItems.takeLast());
+
+ // Fix current index
+ if (d->currentIndex >= 0 && d->currentItem) {
+ int oldCurrent = d->currentIndex;
+ d->currentIndex = d->model->indexOf(d->currentItem, this);
+ if (oldCurrent != d->currentIndex)
+ emit currentIndexChanged();
+ }
d->updateCurrent();
}
@@ -1247,11 +1274,12 @@ void QDeclarativePathViewPrivate::updateCurrent()
}
}
currentIndex = idx;
+ currentItem = 0;
itemIndex = (idx - firstIndex + model->count()) % model->count();
if (itemIndex < items.count()) {
- QDeclarativeItem *item = items.at(itemIndex);
- item->setFocus(true);
- if (QDeclarativePathViewAttached *att = attached(item))
+ currentItem = items.at(itemIndex);
+ currentItem->setFocus(true);
+ if (QDeclarativePathViewAttached *att = attached(currentItem))
att->setIsCurrentItem(true);
}
emit q->currentIndexChanged();
diff --git a/src/declarative/graphicsitems/qdeclarativepathview_p_p.h b/src/declarative/graphicsitems/qdeclarativepathview_p_p.h
index 90216c0..26ec4e5 100644
--- a/src/declarative/graphicsitems/qdeclarativepathview_p_p.h
+++ b/src/declarative/graphicsitems/qdeclarativepathview_p_p.h
@@ -124,6 +124,7 @@ public:
QDeclarativePath *path;
int currentIndex;
+ QDeclarativeGuard<QDeclarativeItem> currentItem;
qreal currentItemOffset;
qreal startPc;
QPointF startPoint;
diff --git a/src/declarative/graphicsitems/qdeclarativepositioners.cpp b/src/declarative/graphicsitems/qdeclarativepositioners.cpp
index 5e91224..b23b8c9 100644
--- a/src/declarative/graphicsitems/qdeclarativepositioners.cpp
+++ b/src/declarative/graphicsitems/qdeclarativepositioners.cpp
@@ -820,6 +820,9 @@ public:
QDeclarativeFlow::QDeclarativeFlow(QDeclarativeItem *parent)
: QDeclarativeBasePositioner(*(new QDeclarativeFlowPrivate), Both, parent)
{
+ Q_D(QDeclarativeFlow);
+ // Flow layout requires relayout if its own size changes too.
+ d->addItemChangeListener(d, QDeclarativeItemPrivate::Geometry);
}
/*!
diff --git a/src/declarative/qml/qdeclarativecontext.cpp b/src/declarative/qml/qdeclarativecontext.cpp
index 2b8cf70..a9224ad 100644
--- a/src/declarative/qml/qdeclarativecontext.cpp
+++ b/src/declarative/qml/qdeclarativecontext.cpp
@@ -71,31 +71,30 @@ QDeclarativeContextPrivate::QDeclarativeContextPrivate()
Contexts allow data to be exposed to the QML components instantiated by the
QML engine.
- Each QDeclarativeContext contains a set of properties, distinct from
- its QObject properties, that allow data to be
- explicitly bound to a context by name. The context properties are defined or
- updated by calling QDeclarativeContext::setContextProperty(). The following example shows
- a Qt model being bound to a context and then accessed from a QML file.
+ Each QDeclarativeContext contains a set of properties, distinct from its QObject
+ properties, that allow data to be explicitly bound to a context by name. The
+ context properties are defined and updated by calling
+ QDeclarativeContext::setContextProperty(). The following example shows a Qt model
+ being bound to a context and then accessed from a QML file.
\code
QDeclarativeEngine engine;
- QDeclarativeContext context(engine.rootContext());
- context.setContextProperty("myModel", modelData);
+ QDeclarativeContext *context = new QDeclarativeContext(engine.rootContext());
+ context->setContextProperty("myModel", modelData);
QDeclarativeComponent component(&engine, "ListView { model=myModel }");
- component.create(&context);
+ component.create(context);
\endcode
- To simplify binding and maintaining larger data sets, QObject's can be
- added to a QDeclarativeContext. These objects are known as the context's default
- objects. In this case all the properties of the QObject are
- made available by name in the context, as though they were all individually
- added by calling QDeclarativeContext::setContextProperty(). Changes to the property's
- values are detected through the property's notify signal. This method is
- also slightly more faster than manually adding property values.
+ To simplify binding and maintaining larger data sets, a context object can be set
+ on a QDeclarativeContext. All the properties of the context object are available
+ by name in the context, as though they were all individually added through calls
+ to QDeclarativeContext::setContextProperty(). Changes to the property's values are
+ detected through the property's notify signal. Setting a context object is both
+ faster and easier than manually adding and maintaing context property values.
- The following example has the same effect as the one above, but it is
- achieved using a default object.
+ The following example has the same effect as the previous one, but it uses a context
+ object.
\code
class MyDataSet : ... {
@@ -104,46 +103,42 @@ QDeclarativeContextPrivate::QDeclarativeContextPrivate()
...
};
- MyDataSet myDataSet;
+ MyDataSet *myDataSet = new MyDataSet;
QDeclarativeEngine engine;
- QDeclarativeContext context(engine.rootContext());
- context.setContextObject(&myDataSet);
+ QDeclarativeContext *context = new QDeclarativeContext(engine.rootContext());
+ context->setContextObject(myDataSet);
QDeclarativeComponent component(&engine, "ListView { model=myModel }");
- component.create(&context);
+ component.create(context);
\endcode
- Default objects added first take precedence over those added later. All properties
- added explicitly by QDeclarativeContext::setContextProperty() take precedence over default
- object properties.
+ All properties added explicitly by QDeclarativeContext::setContextProperty() take
+ precedence over context object's properties.
- Contexts are hierarchal, with the \l {QDeclarativeEngine::rootContext()}{root context}
- being created by the QDeclarativeEngine. A component instantiated in a given context
- has access to that context's data, as well as the data defined by its
- ancestor contexts. Data values (including those added implicitly by the
- default objects) in a context override those in ancestor contexts. Data
- that should be available to all components instantiated by the QDeclarativeEngine
- should be added to the \l {QDeclarativeEngine::rootContext()}{root context}.
+ Contexts form a hierarchy. The root of this heirarchy is the QDeclarativeEngine's
+ \l {QDeclarativeEngine::rootContext()}{root context}. A component instance can
+ access the data in its own context, as well as all its ancestor contexts. Data
+ can be made available to all instances by modifying the
+ \l {QDeclarativeEngine::rootContext()}{root context}.
- In the following example,
+ The following example defines two contexts - \c context1 and \c context2. The
+ second context overrides the "b" context property inherited from the first with a
+ new value.
\code
QDeclarativeEngine engine;
- QDeclarativeContext context1(engine.rootContext());
- QDeclarativeContext context2(&context1);
- QDeclarativeContext context3(&context2);
-
- context1.setContextProperty("a", 12);
- context2.setContextProperty("b", 13);
- context3.setContextProperty("a", 14);
- context3.setContextProperty("c", 14);
+ QDeclarativeContext *context1 = new QDeclarativeContext(engine.rootContext());
+ QDeclarativeContext *context2 = new QDeclarativeContext(context1);
+
+ context1->setContextProperty("a", 12);
+ context1->setContextProperty("b", 12);
+
+ context2->setContextProperty("b", 15);
\endcode
- a QML component instantiated in context1 would have access to the "a" data,
- a QML component instantiated in context2 would have access to the "a" and
- "b" data, and a QML component instantiated in context3 would have access to
- the "a", "b" and "c" data - although its "a" data would return 14, unlike
- that in context1 or context2.
+ While QML objects instantiated in a context are not strictly owned by that
+ context, their bindings are. If a context is destroyed, the property bindings of
+ outstanding QML objects will stop evaluating.
*/
/*! \internal */
diff --git a/src/declarative/util/qdeclarativepixmapcache.cpp b/src/declarative/util/qdeclarativepixmapcache.cpp
index 1d90bf8..fe5863f 100644
--- a/src/declarative/util/qdeclarativepixmapcache.cpp
+++ b/src/declarative/util/qdeclarativepixmapcache.cpp
@@ -114,6 +114,7 @@ private:
QList<QDeclarativePixmapReply*> cancelled;
QDeclarativeEngine *engine;
QDeclarativeImageRequestHandler *handler;
+ QWaitCondition started;
QMutex mutex;
static QHash<QDeclarativeEngine *,QDeclarativeImageReader*> readers;
@@ -370,8 +371,15 @@ QDeclarativeImageReader::~QDeclarativeImageReader()
readers.remove(engine);
readerMutex.unlock();
- quit();
- wait();
+ if (isRunning()) {
+ quit();
+ while (!wait(100)) {
+ // It is possible to for the quit to happen before exec()
+ // Need to wait until the event loop starts so that we
+ // can stop it. Particularly likely with an idle thread.
+ quit();
+ }
+ }
}
QDeclarativeImageReader *QDeclarativeImageReader::instance(QDeclarativeEngine *engine)
@@ -380,6 +388,7 @@ QDeclarativeImageReader *QDeclarativeImageReader::instance(QDeclarativeEngine *e
QDeclarativeImageReader *reader = readers.value(engine);
if (!reader) {
reader = new QDeclarativeImageReader(engine);
+ reader->started.wait(&readerMutex);
readers.insert(engine, reader);
}
readerMutex.unlock();
@@ -414,7 +423,10 @@ void QDeclarativeImageReader::cancel(QDeclarativePixmapReply *reply)
void QDeclarativeImageReader::run()
{
+ readerMutex.lock();
handler = new QDeclarativeImageRequestHandler(this, engine);
+ started.wakeAll();
+ readerMutex.unlock();
exec();