summaryrefslogtreecommitdiffstats
path: root/src/declarative/util
diff options
context:
space:
mode:
authorQt Continuous Integration System <qt-info@nokia.com>2010-03-30 01:21:48 (GMT)
committerQt Continuous Integration System <qt-info@nokia.com>2010-03-30 01:21:48 (GMT)
commitc4f59859a589b76419e9133110eda850223f03dd (patch)
tree051b589cc93c609f0668a5c748efec854723b487 /src/declarative/util
parent4fb6cae4dd0c6a90008780df606abb8a9e73cb2c (diff)
parent1494bc444f43e98250f9d29c50a128e5cf4ca328 (diff)
downloadQt-c4f59859a589b76419e9133110eda850223f03dd.zip
Qt-c4f59859a589b76419e9133110eda850223f03dd.tar.gz
Qt-c4f59859a589b76419e9133110eda850223f03dd.tar.bz2
Merge branch '4.7' of scm.dev.nokia.troll.no:qt/qt-qml into 4.7-integration
* '4.7' of scm.dev.nokia.troll.no:qt/qt-qml: (136 commits) Make QDeclarativeListProperty a class Fix qdeclarativedom::loadDynamicProperty test Correctly parent repeater items. Make sure cursor delegate is parented. Allow just one dimension to be set, the other scaled accordingly Simplify import path. Removed unneeded code. Update autotest a little Improve QML compiler statistics Use error enum not numbers Pass test. doc test error code too QDeclarativeItem::setParentItem should not modify the QObject parent Doc Ensure currentIndex is updated when PathView items are removed/moved Visual test fixes. Doc Relayout items when Flow size changes. Make sure the image reader thread is shutdown properly ...
Diffstat (limited to 'src/declarative/util')
-rw-r--r--src/declarative/util/qdeclarativeanimation_p_p.h26
-rw-r--r--src/declarative/util/qdeclarativebehavior.cpp12
-rw-r--r--src/declarative/util/qdeclarativelistmodel.cpp19
-rw-r--r--src/declarative/util/qdeclarativelistmodel_p.h2
-rw-r--r--src/declarative/util/qdeclarativelistmodelworkeragent.cpp2
-rw-r--r--src/declarative/util/qdeclarativeopenmetaobject.cpp12
-rw-r--r--src/declarative/util/qdeclarativeopenmetaobject_p.h2
-rw-r--r--src/declarative/util/qdeclarativepixmapcache.cpp215
-rw-r--r--src/declarative/util/qdeclarativepixmapcache_p.h9
-rw-r--r--src/declarative/util/qdeclarativepropertymap.cpp31
-rw-r--r--src/declarative/util/qdeclarativepropertymap.h2
-rw-r--r--src/declarative/util/qdeclarativestategroup.cpp26
-rw-r--r--src/declarative/util/qdeclarativestateoperations.cpp474
-rw-r--r--src/declarative/util/qdeclarativestateoperations_p.h123
-rw-r--r--src/declarative/util/qdeclarativeutilmodule.cpp1
-rw-r--r--src/declarative/util/qdeclarativeview.cpp5
-rw-r--r--src/declarative/util/qdeclarativexmllistmodel.cpp173
-rw-r--r--src/declarative/util/qdeclarativexmllistmodel_p.h3
18 files changed, 723 insertions, 414 deletions
diff --git a/src/declarative/util/qdeclarativeanimation_p_p.h b/src/declarative/util/qdeclarativeanimation_p_p.h
index 3908e50..2a66c8a 100644
--- a/src/declarative/util/qdeclarativeanimation_p_p.h
+++ b/src/declarative/util/qdeclarativeanimation_p_p.h
@@ -100,17 +100,11 @@ class QActionAnimation : public QAbstractAnimation
{
Q_OBJECT
public:
- QActionAnimation(QObject *parent = 0) : QAbstractAnimation(parent), animAction(0), policy(KeepWhenStopped), running(false) {}
+ QActionAnimation(QObject *parent = 0) : QAbstractAnimation(parent), animAction(0), policy(KeepWhenStopped) {}
QActionAnimation(QAbstractAnimationAction *action, QObject *parent = 0)
- : QAbstractAnimation(parent), animAction(action), policy(KeepWhenStopped), running(false) {}
+ : QAbstractAnimation(parent), animAction(action), policy(KeepWhenStopped) {}
~QActionAnimation() { if (policy == DeleteWhenStopped) { delete animAction; animAction = 0; } }
virtual int duration() const { return 0; }
- void clearAnimAction()
- {
- if (policy == DeleteWhenStopped)
- delete animAction;
- animAction = 0;
- }
void setAnimAction(QAbstractAnimationAction *action, DeletionPolicy p)
{
if (state() == Running)
@@ -127,26 +121,18 @@ protected:
{
if (newState == Running) {
if (animAction) {
- running = true;
animAction->doAction();
- running = false;
if (state() == Stopped && policy == DeleteWhenStopped) {
delete animAction;
animAction = 0;
}
}
- } /*else if (newState == Stopped && policy == DeleteWhenStopped) {
- if (!running) {
- delete animAction;
- animAction = 0;
- }
- }*/
+ }
}
private:
QAbstractAnimationAction *animAction;
DeletionPolicy policy;
- bool running;
};
class QDeclarativeBulkValueUpdater
@@ -192,11 +178,7 @@ protected:
//check for new from every loop
if (fromSourced)
*fromSourced = false;
- } /*else if (newState == Stopped && policy == DeleteWhenStopped) {
- delete animValue;
- animValue = 0;
- }*/ //### we get a stop each loop if we are in a group
- //### top-level animation is the only reliable one for this
+ }
}
private:
diff --git a/src/declarative/util/qdeclarativebehavior.cpp b/src/declarative/util/qdeclarativebehavior.cpp
index 1e000df..7181777 100644
--- a/src/declarative/util/qdeclarativebehavior.cpp
+++ b/src/declarative/util/qdeclarativebehavior.cpp
@@ -47,15 +47,12 @@
#include <qdeclarativecontext.h>
#include <qdeclarativeinfo.h>
#include <qdeclarativeproperty_p.h>
-
-#include <QtCore/qparallelanimationgroup.h>
+#include <qdeclarativeguard_p.h>
#include <private/qobject_p.h>
QT_BEGIN_NAMESPACE
-
-
class QDeclarativeBehaviorPrivate : public QObjectPrivate
{
Q_DECLARE_PUBLIC(QDeclarativeBehavior)
@@ -64,7 +61,7 @@ public:
QDeclarativeProperty property;
QVariant currentValue;
- QDeclarativeAbstractAnimation *animation;
+ QDeclarativeGuard<QDeclarativeAbstractAnimation> animation;
bool enabled;
};
@@ -176,11 +173,10 @@ void QDeclarativeBehavior::write(const QVariant &value)
actions << action;
QList<QDeclarativeProperty> after;
- if (d->animation)
- d->animation->transition(actions, after, QDeclarativeAbstractAnimation::Forward);
+ d->animation->transition(actions, after, QDeclarativeAbstractAnimation::Forward);
d->animation->qtAnimation()->start();
if (!after.contains(d->property))
- QDeclarativePropertyPrivate::write(d->property, value, QDeclarativePropertyPrivate::BypassInterceptor | QDeclarativePropertyPrivate::DontRemoveBinding);
+ QDeclarativePropertyPrivate::write(d->property, value, QDeclarativePropertyPrivate::BypassInterceptor | QDeclarativePropertyPrivate::DontRemoveBinding);
}
void QDeclarativeBehavior::setTarget(const QDeclarativeProperty &property)
diff --git a/src/declarative/util/qdeclarativelistmodel.cpp b/src/declarative/util/qdeclarativelistmodel.cpp
index 3e25234..1a28176 100644
--- a/src/declarative/util/qdeclarativelistmodel.cpp
+++ b/src/declarative/util/qdeclarativelistmodel.cpp
@@ -365,7 +365,7 @@ void QDeclarativeListModel::clear()
if (!m_isWorkerCopy) {
emit itemsRemoved(0, cleared);
- emit countChanged(0);
+ emit countChanged();
}
}
@@ -390,7 +390,7 @@ void QDeclarativeListModel::remove(int index)
if (!m_isWorkerCopy) {
emit itemsRemoved(index, 1);
- emit countChanged(this->count());
+ emit countChanged();
}
}
@@ -424,7 +424,7 @@ void QDeclarativeListModel::insert(int index, const QScriptValue& valuemap)
bool ok = m_flat ? m_flat->insert(index, valuemap) : m_nested->insert(index, valuemap);
if (ok && !m_isWorkerCopy) {
emit itemsInserted(index, 1);
- emit countChanged(this->count());
+ emit countChanged();
}
}
@@ -1250,14 +1250,9 @@ ModelNode::ModelNode()
ModelNode::~ModelNode()
{
- ModelNode *node;
-
- QList<ModelNode *> nodeValues = properties.values();
- for (int ii = 0; ii < nodeValues.count(); ++ii) {
- node = nodeValues[ii];
- if (node) { delete node; node = 0; }
- }
+ qDeleteAll(properties.values());
+ ModelNode *node;
for (int ii = 0; ii < values.count(); ++ii) {
node = qvariant_cast<ModelNode *>(values.at(ii));
if (node) { delete node; node = 0; }
@@ -1279,7 +1274,9 @@ void ModelNode::setObjectValue(const QScriptValue& valuemap) {
} else {
value->values << v.toVariant();
}
- properties.insert(it.name(),value);
+ if (properties.contains(it.name()))
+ delete properties[it.name()];
+ properties.insert(it.name(), value);
}
}
diff --git a/src/declarative/util/qdeclarativelistmodel_p.h b/src/declarative/util/qdeclarativelistmodel_p.h
index 6a0426b..d09062e 100644
--- a/src/declarative/util/qdeclarativelistmodel_p.h
+++ b/src/declarative/util/qdeclarativelistmodel_p.h
@@ -91,7 +91,7 @@ public:
QDeclarativeListModelWorkerAgent *agent();
Q_SIGNALS:
- void countChanged(int);
+ void countChanged();
private:
friend class QDeclarativeListModelParser;
diff --git a/src/declarative/util/qdeclarativelistmodelworkeragent.cpp b/src/declarative/util/qdeclarativelistmodelworkeragent.cpp
index 2951262..0e38632 100644
--- a/src/declarative/util/qdeclarativelistmodelworkeragent.cpp
+++ b/src/declarative/util/qdeclarativelistmodelworkeragent.cpp
@@ -229,7 +229,7 @@ bool QDeclarativeListModelWorkerAgent::event(QEvent *e)
}
if (cc)
- emit m_orig->countChanged(m_copy->count());
+ emit m_orig->countChanged();
}
}
diff --git a/src/declarative/util/qdeclarativeopenmetaobject.cpp b/src/declarative/util/qdeclarativeopenmetaobject.cpp
index 8c23354..6611885 100644
--- a/src/declarative/util/qdeclarativeopenmetaobject.cpp
+++ b/src/declarative/util/qdeclarativeopenmetaobject.cpp
@@ -222,9 +222,10 @@ int QDeclarativeOpenMetaObject::metaCall(QMetaObject::Call c, int id, void **a)
propertyRead(propId);
*reinterpret_cast<QVariant *>(a[0]) = d->getData(propId);
} else if (c == QMetaObject::WriteProperty) {
- if (d->data[propId].first != *reinterpret_cast<QVariant *>(a[0])) {
+ if (propId <= d->data.count() || d->data[propId].first != *reinterpret_cast<QVariant *>(a[0])) {
propertyWrite(propId);
d->writeData(propId, *reinterpret_cast<QVariant *>(a[0]));
+ propertyWritten(propId);
activate(d->object, d->type->d->signalOffset + propId, 0);
}
}
@@ -270,6 +271,11 @@ QVariant &QDeclarativeOpenMetaObject::operator[](const QByteArray &name)
return d->getData(*iter);
}
+QVariant &QDeclarativeOpenMetaObject::operator[](int id)
+{
+ return d->getData(id);
+}
+
void QDeclarativeOpenMetaObject::setValue(const QByteArray &name, const QVariant &val)
{
QHash<QByteArray, int>::ConstIterator iter = d->type->d->names.find(name);
@@ -326,6 +332,10 @@ void QDeclarativeOpenMetaObject::propertyWrite(int)
{
}
+void QDeclarativeOpenMetaObject::propertyWritten(int)
+{
+}
+
void QDeclarativeOpenMetaObject::propertyCreated(int, QMetaPropertyBuilder &)
{
}
diff --git a/src/declarative/util/qdeclarativeopenmetaobject_p.h b/src/declarative/util/qdeclarativeopenmetaobject_p.h
index ec5ac17..9bb4c34 100644
--- a/src/declarative/util/qdeclarativeopenmetaobject_p.h
+++ b/src/declarative/util/qdeclarativeopenmetaobject_p.h
@@ -90,6 +90,7 @@ public:
QVariant value(int) const;
void setValue(int, const QVariant &);
QVariant &operator[](const QByteArray &);
+ QVariant &operator[](int);
int count() const;
QByteArray name(int) const;
@@ -109,6 +110,7 @@ protected:
virtual void propertyRead(int);
virtual void propertyWrite(int);
+ virtual void propertyWritten(int);
virtual void propertyCreated(int, QMetaPropertyBuilder &);
QAbstractDynamicMetaObject *parent() const;
diff --git a/src/declarative/util/qdeclarativepixmapcache.cpp b/src/declarative/util/qdeclarativepixmapcache.cpp
index e78fdf1..a9c30f8 100644
--- a/src/declarative/util/qdeclarativepixmapcache.cpp
+++ b/src/declarative/util/qdeclarativepixmapcache.cpp
@@ -60,11 +60,6 @@
#include <private/qobject_p.h>
#include <QSslError>
-#ifdef Q_OS_LINUX
-#include <pthread.h>
-#include <linux/sched.h>
-#endif
-
// Maximum number of simultaneous image requests to send.
static const int maxImageRequestCount = 8;
@@ -106,7 +101,7 @@ public:
QDeclarativeImageReader(QDeclarativeEngine *eng);
~QDeclarativeImageReader();
- QDeclarativePixmapReply *getImage(const QUrl &url);
+ QDeclarativePixmapReply *getImage(const QUrl &url, int req_width, int req_height);
void cancel(QDeclarativePixmapReply *rep);
static QDeclarativeImageReader *instance(QDeclarativeEngine *engine);
@@ -119,6 +114,7 @@ private:
QList<QDeclarativePixmapReply*> cancelled;
QDeclarativeEngine *engine;
QDeclarativeImageRequestHandler *handler;
+ QWaitCondition started;
QMutex mutex;
static QHash<QDeclarativeEngine *,QDeclarativeImageReader*> readers;
@@ -140,7 +136,7 @@ public:
QCoreApplication::postEvent(this, new QEvent(QEvent::User));
}
- QDeclarativePixmapReply *getImage(const QUrl &url);
+ QDeclarativePixmapReply *getImage(const QUrl &url, int req_width, int req_height);
void cancel(QDeclarativePixmapReply *reply);
protected:
@@ -170,11 +166,58 @@ private:
//===========================================================================
+static bool readImage(const QUrl& url, QIODevice *dev, QImage *image, QString *errorString, QSize *impsize, int req_width, int req_height)
+{
+ QImageReader imgio(dev);
+
+ bool force_scale = false;
+ if (url.path().endsWith(QLatin1String(".svg"),Qt::CaseInsensitive)) {
+ imgio.setFormat("svg"); // QSvgPlugin::capabilities bug QTBUG-9053
+ force_scale = true;
+ }
+
+ bool scaled = false;
+ if (req_width > 0 || req_height > 0) {
+ QSize s = imgio.size();
+ if (req_width && (force_scale || req_width < s.width())) {
+ if (req_height <= 0)
+ s.setHeight(s.height()*req_width/s.width());
+ s.setWidth(req_width); scaled = true;
+ }
+ if (req_height && (force_scale || req_height < s.height())) {
+ if (req_width <= 0)
+ s.setWidth(s.width()*req_height/s.height());
+ s.setHeight(req_height); scaled = true;
+ }
+ if (scaled) { imgio.setScaledSize(s); }
+ }
+
+ if (impsize)
+ *impsize = imgio.size();
+
+ if (imgio.read(image)) {
+ if (impsize && impsize->width() < 0)
+ *impsize = image->size();
+ return true;
+ } else {
+ if (errorString)
+ *errorString = QLatin1String("Error decoding: ") + url.toString()
+ + QLatin1String(" \"") + imgio.errorString() + QLatin1String("\"");
+ return false;
+ }
+}
+
+
+//===========================================================================
+
int QDeclarativeImageRequestHandler::replyDownloadProgress = -1;
int QDeclarativeImageRequestHandler::replyFinished = -1;
int QDeclarativeImageRequestHandler::downloadProgress = -1;
int QDeclarativeImageRequestHandler::thisNetworkRequestDone = -1;
+typedef QHash<QUrl, QSize> QDeclarativePixmapSizeHash;
+Q_GLOBAL_STATIC(QDeclarativePixmapSizeHash, qmlOriginalSizes);
+
bool QDeclarativeImageRequestHandler::event(QEvent *event)
{
if (event->type() == QEvent::User) {
@@ -221,7 +264,9 @@ bool QDeclarativeImageRequestHandler::event(QEvent *event)
// fetch
if (url.scheme() == QLatin1String("image")) {
// Use QmlImageProvider
- QImage image = QDeclarativeEnginePrivate::get(engine)->getImageFromProvider(url);
+ QSize read_impsize;
+ QImage image = QDeclarativeEnginePrivate::get(engine)->getImageFromProvider(url, &read_impsize, QSize(runningJob->forcedWidth(),runningJob->forcedHeight()));
+ qmlOriginalSizes()->insert(url, read_impsize);
QDeclarativeImageReaderEvent::ReadError errorCode = QDeclarativeImageReaderEvent::NoError;
QString errorStr;
if (image.isNull()) {
@@ -238,10 +283,10 @@ bool QDeclarativeImageRequestHandler::event(QEvent *event)
QString errorStr;
QFile f(lf);
if (f.open(QIODevice::ReadOnly)) {
- QImageReader imgio(&f);
- if (!imgio.read(&image)) {
- errorStr = QLatin1String("Error decoding: ") + url.toString()
- + QLatin1String(" \"") + imgio.errorString() + QLatin1String("\"");
+ QSize read_impsize;
+ if (readImage(url, &f, &image, &errorStr, &read_impsize, runningJob->forcedWidth(),runningJob->forcedHeight())) {
+ qmlOriginalSizes()->insert(url, read_impsize);
+ } else {
errorCode = QDeclarativeImageReaderEvent::Loading;
}
} else {
@@ -303,12 +348,11 @@ void QDeclarativeImageRequestHandler::networkRequestDone()
error = QDeclarativeImageReaderEvent::Loading;
errorString = reply->errorString();
} else {
- QImageReader imgio(reply);
- if (imgio.read(&image)) {
+ QSize read_impsize;
+ if (readImage(reply->url(), reply, &image, &errorString, &read_impsize, job->forcedWidth(), job->forcedHeight())) {
+ qmlOriginalSizes()->insert(reply->url(), read_impsize);
error = QDeclarativeImageReaderEvent::NoError;
} else {
- errorString = QLatin1String("Error decoding: ") + reply->url().toString()
- + QLatin1String(" \"") + imgio.errorString() + QLatin1String("\"");
error = QDeclarativeImageReaderEvent::Decoding;
}
}
@@ -326,7 +370,7 @@ void QDeclarativeImageRequestHandler::networkRequestDone()
QDeclarativeImageReader::QDeclarativeImageReader(QDeclarativeEngine *eng)
: QThread(eng), engine(eng), handler(0)
{
- start(QThread::LowPriority);
+ start(QThread::IdlePriority);
}
QDeclarativeImageReader::~QDeclarativeImageReader()
@@ -335,8 +379,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)
@@ -345,6 +396,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();
@@ -352,10 +404,10 @@ QDeclarativeImageReader *QDeclarativeImageReader::instance(QDeclarativeEngine *e
return reader;
}
-QDeclarativePixmapReply *QDeclarativeImageReader::getImage(const QUrl &url)
+QDeclarativePixmapReply *QDeclarativeImageReader::getImage(const QUrl &url, int req_width, int req_height)
{
mutex.lock();
- QDeclarativePixmapReply *reply = new QDeclarativePixmapReply(this, url);
+ QDeclarativePixmapReply *reply = new QDeclarativePixmapReply(this, url, req_width, req_height);
reply->addRef();
reply->setLoading();
jobs.append(reply);
@@ -379,15 +431,10 @@ void QDeclarativeImageReader::cancel(QDeclarativePixmapReply *reply)
void QDeclarativeImageReader::run()
{
-#if defined(Q_OS_LINUX) && defined(SCHED_IDLE)
- struct sched_param param;
- int policy;
-
- pthread_getschedparam(pthread_self(), &policy, &param);
- pthread_setschedparam(pthread_self(), SCHED_IDLE, &param);
-#endif
-
+ readerMutex.lock();
handler = new QDeclarativeImageRequestHandler(this, engine);
+ started.wakeAll();
+ readerMutex.unlock();
exec();
@@ -397,40 +444,6 @@ void QDeclarativeImageReader::run()
//===========================================================================
-static bool readImage(QIODevice *dev, QPixmap *pixmap, QString &errorString)
-{
- QImageReader imgio(dev);
-
-//#define QT_TEST_SCALED_SIZE
-#ifdef QT_TEST_SCALED_SIZE
- /*
- Some mechanism is needed for loading images at a limited size, especially
- for remote images. Loading only thumbnails of remote progressive JPEG
- images can be efficient. (Qt jpeg handler does not do so currently)
- */
-
- QSize limit(60,60);
- QSize sz = imgio.size();
- if (sz.width() > limit.width() || sz.height() > limit.height()) {
- sz.scale(limit,Qt::KeepAspectRatio);
- imgio.setScaledSize(sz);
- }
-#endif
-
- QImage img;
- if (imgio.read(&img)) {
-#ifdef QT_TEST_SCALED_SIZE
- if (!sz.isValid())
- img = img.scaled(limit,Qt::KeepAspectRatio);
-#endif
- *pixmap = QPixmap::fromImage(img);
- return true;
- } else {
- errorString = imgio.errorString();
- return false;
- }
-}
-
/*!
\internal
\class QDeclarativePixmapCache
@@ -447,8 +460,10 @@ class QDeclarativePixmapReplyPrivate : public QObjectPrivate
Q_DECLARE_PUBLIC(QDeclarativePixmapReply)
public:
- QDeclarativePixmapReplyPrivate(QDeclarativeImageReader *r, const QUrl &u)
- : QObjectPrivate(), refCount(1), url(u), status(QDeclarativePixmapReply::Loading), loading(false), reader(r) {
+ QDeclarativePixmapReplyPrivate(QDeclarativeImageReader *r, const QUrl &u, int req_width, int req_height)
+ : QObjectPrivate(), refCount(1), url(u), status(QDeclarativePixmapReply::Loading), loading(false), reader(r),
+ forced_width(req_width), forced_height(req_height)
+ {
}
int refCount;
@@ -457,11 +472,12 @@ public:
QDeclarativePixmapReply::Status status;
bool loading;
QDeclarativeImageReader *reader;
+ int forced_width, forced_height;
};
-QDeclarativePixmapReply::QDeclarativePixmapReply(QDeclarativeImageReader *reader, const QUrl &url)
- : QObject(*new QDeclarativePixmapReplyPrivate(reader, url), 0)
+QDeclarativePixmapReply::QDeclarativePixmapReply(QDeclarativeImageReader *reader, const QUrl &url, int req_width, int req_height)
+ : QObject(*new QDeclarativePixmapReplyPrivate(reader, url, req_width, req_height), 0)
{
}
@@ -475,6 +491,28 @@ const QUrl &QDeclarativePixmapReply::url() const
return d->url;
}
+int QDeclarativePixmapReply::forcedWidth() const
+{
+ Q_D(const QDeclarativePixmapReply);
+ return d->forced_width;
+}
+
+int QDeclarativePixmapReply::forcedHeight() const
+{
+ Q_D(const QDeclarativePixmapReply);
+ return d->forced_height;
+}
+
+QSize QDeclarativePixmapReply::implicitSize() const
+{
+ Q_D(const QDeclarativePixmapReply);
+ QDeclarativePixmapSizeHash::Iterator iter = qmlOriginalSizes()->find(d->url);
+ if (iter != qmlOriginalSizes()->end())
+ return *iter;
+ else
+ return QSize();
+}
+
bool QDeclarativePixmapReply::event(QEvent *event)
{
Q_D(QDeclarativePixmapReply);
@@ -554,13 +592,25 @@ bool QDeclarativePixmapReply::release(bool defer)
If \a async is false the image will be loaded and decoded immediately;
otherwise the image will be loaded and decoded in a separate thread.
+ If \a req_width and \a req_height are non-zero, they are used for
+ the size of the rendered pixmap rather than the intrinsic size of the image.
+ Different request sizes add different cache items.
+
Note that images sourced from the network will always be loaded and
decoded asynchonously.
*/
-QDeclarativePixmapReply::Status QDeclarativePixmapCache::get(const QUrl& url, QPixmap *pixmap, bool async)
+QDeclarativePixmapReply::Status QDeclarativePixmapCache::get(const QUrl& url, QPixmap *pixmap, QSize *impsize, bool async, int req_width, int req_height)
{
QDeclarativePixmapReply::Status status = QDeclarativePixmapReply::Unrequested;
QByteArray key = url.toEncoded(QUrl::FormattingOption(0x100));
+
+ if (req_width > 0 || req_height > 0) {
+ key += ':';
+ key += QByteArray::number(req_width);
+ key += 'x';
+ key += QByteArray::number(req_height);
+ }
+
QString strKey = QString::fromLatin1(key.constData(), key.count());
#ifndef QT_NO_LOCALFILE_OPTIMIZED_QML
@@ -570,11 +620,13 @@ QDeclarativePixmapReply::Status QDeclarativePixmapCache::get(const QUrl& url, QP
status = QDeclarativePixmapReply::Ready;
if (!QPixmapCache::find(strKey,pixmap)) {
QFile f(lf);
+ QSize read_impsize;
if (f.open(QIODevice::ReadOnly)) {
QString errorString;
- if (!readImage(&f, pixmap, errorString)) {
- errorString = QLatin1String("Error decoding: ") + url.toString()
- + QLatin1String(" \"") + errorString + QLatin1String("\"");
+ QImage image;
+ if (readImage(url, &f, &image, &errorString, &read_impsize, req_width, req_height)) {
+ *pixmap = QPixmap::fromImage(image);
+ } else {
qWarning() << errorString;
*pixmap = QPixmap();
status = QDeclarativePixmapReply::Error;
@@ -584,8 +636,18 @@ QDeclarativePixmapReply::Status QDeclarativePixmapCache::get(const QUrl& url, QP
*pixmap = QPixmap();
status = QDeclarativePixmapReply::Error;
}
- if (status == QDeclarativePixmapReply::Ready)
+ if (status == QDeclarativePixmapReply::Ready) {
QPixmapCache::insert(strKey, *pixmap);
+ qmlOriginalSizes()->insert(url, read_impsize);
+ }
+ if (impsize)
+ *impsize = read_impsize;
+ } else {
+ if (impsize) {
+ QDeclarativePixmapSizeHash::Iterator iter = qmlOriginalSizes()->find(url);
+ if (iter != qmlOriginalSizes()->end())
+ *impsize = *iter;
+ }
}
return status;
}
@@ -608,6 +670,11 @@ QDeclarativePixmapReply::Status QDeclarativePixmapCache::get(const QUrl& url, QP
} else if (iter != qmlActivePixmapReplies()->end()) {
status = QDeclarativePixmapReply::Loading;
}
+ if (impsize) {
+ QDeclarativePixmapSizeHash::Iterator iter = qmlOriginalSizes()->find(url);
+ if (iter != qmlOriginalSizes()->end())
+ *impsize = *iter;
+ }
return status;
}
@@ -621,12 +688,12 @@ QDeclarativePixmapReply::Status QDeclarativePixmapCache::get(const QUrl& url, QP
The returned QDeclarativePixmapReply will be deleted when all request() calls are
matched by a corresponding get() call.
*/
-QDeclarativePixmapReply *QDeclarativePixmapCache::request(QDeclarativeEngine *engine, const QUrl &url)
+QDeclarativePixmapReply *QDeclarativePixmapCache::request(QDeclarativeEngine *engine, const QUrl &url, int req_width, int req_height)
{
QDeclarativePixmapReplyHash::Iterator iter = qmlActivePixmapReplies()->find(url);
if (iter == qmlActivePixmapReplies()->end()) {
QDeclarativeImageReader *reader = QDeclarativeImageReader::instance(engine);
- QDeclarativePixmapReply *item = reader->getImage(url);
+ QDeclarativePixmapReply *item = reader->getImage(url, req_width, req_height);
iter = qmlActivePixmapReplies()->insert(url, item);
} else {
(*iter)->addRef();
diff --git a/src/declarative/util/qdeclarativepixmapcache_p.h b/src/declarative/util/qdeclarativepixmapcache_p.h
index b8949db..df71d65 100644
--- a/src/declarative/util/qdeclarativepixmapcache_p.h
+++ b/src/declarative/util/qdeclarativepixmapcache_p.h
@@ -66,6 +66,9 @@ public:
Status status() const;
const QUrl &url() const;
+ int forcedWidth() const;
+ int forcedHeight() const;
+ QSize implicitSize() const;
Q_SIGNALS:
void finished();
@@ -81,7 +84,7 @@ private:
void setLoading();
private:
- QDeclarativePixmapReply(QDeclarativeImageReader *reader, const QUrl &url);
+ QDeclarativePixmapReply(QDeclarativeImageReader *reader, const QUrl &url, int req_width, int req_height);
Q_DISABLE_COPY(QDeclarativePixmapReply)
Q_DECLARE_PRIVATE(QDeclarativePixmapReply)
friend class QDeclarativeImageRequestHandler;
@@ -92,8 +95,8 @@ private:
class Q_DECLARATIVE_EXPORT QDeclarativePixmapCache
{
public:
- static QDeclarativePixmapReply::Status get(const QUrl& url, QPixmap *pixmap, bool async=false);
- static QDeclarativePixmapReply *request(QDeclarativeEngine *, const QUrl& url);
+ static QDeclarativePixmapReply::Status get(const QUrl& url, QPixmap *pixmap, QSize *impsize=0, bool async=false, int req_width=0, int req_height=0);
+ static QDeclarativePixmapReply *request(QDeclarativeEngine *, const QUrl& url, int req_width=0, int req_height=0);
static void cancel(const QUrl& url, QObject *obj);
static int pendingRequests();
};
diff --git a/src/declarative/util/qdeclarativepropertymap.cpp b/src/declarative/util/qdeclarativepropertymap.cpp
index fcea515..0bdd91b 100644
--- a/src/declarative/util/qdeclarativepropertymap.cpp
+++ b/src/declarative/util/qdeclarativepropertymap.cpp
@@ -41,6 +41,7 @@
#include "qdeclarativepropertymap.h"
+#include <private/qmetaobjectbuilder_p.h>
#include "qdeclarativeopenmetaobject_p.h"
#include <QDebug>
@@ -55,7 +56,8 @@ public:
QDeclarativePropertyMapMetaObject(QDeclarativePropertyMap *obj, QDeclarativePropertyMapPrivate *objPriv);
protected:
- virtual void propertyWrite(int index);
+ virtual void propertyWritten(int index);
+ virtual void propertyCreated(int, QMetaPropertyBuilder &);
private:
QDeclarativePropertyMap *map;
@@ -68,13 +70,13 @@ class QDeclarativePropertyMapPrivate : public QObjectPrivate
public:
QDeclarativePropertyMapMetaObject *mo;
QStringList keys;
- void emitChanged(const QString &key);
+ void emitChanged(const QString &key, const QVariant &value);
};
-void QDeclarativePropertyMapPrivate::emitChanged(const QString &key)
+void QDeclarativePropertyMapPrivate::emitChanged(const QString &key, const QVariant &value)
{
Q_Q(QDeclarativePropertyMap);
- emit q->valueChanged(key);
+ emit q->valueChanged(key, value);
}
QDeclarativePropertyMapMetaObject::QDeclarativePropertyMapMetaObject(QDeclarativePropertyMap *obj, QDeclarativePropertyMapPrivate *objPriv) : QDeclarativeOpenMetaObject(obj)
@@ -83,14 +85,19 @@ QDeclarativePropertyMapMetaObject::QDeclarativePropertyMapMetaObject(QDeclarativ
priv = objPriv;
}
-void QDeclarativePropertyMapMetaObject::propertyWrite(int index)
+void QDeclarativePropertyMapMetaObject::propertyWritten(int index)
{
- priv->emitChanged(QString::fromUtf8(name(index)));
+ priv->emitChanged(QString::fromUtf8(name(index)), operator[](index));
+}
+
+void QDeclarativePropertyMapMetaObject::propertyCreated(int, QMetaPropertyBuilder &b)
+{
+ priv->keys.append(QString::fromUtf8(b.name()));
}
/*!
\class QDeclarativePropertyMap
- \since 4.7
+ \since 4.7
\brief The QDeclarativePropertyMap class allows you to set key-value pairs that can be used in bindings.
QDeclarativePropertyMap provides a convenient way to expose domain data to the UI layer.
@@ -172,8 +179,6 @@ QVariant QDeclarativePropertyMap::value(const QString &key) const
void QDeclarativePropertyMap::insert(const QString &key, const QVariant &value)
{
Q_D(QDeclarativePropertyMap);
- if (!d->keys.contains(key))
- d->keys.append(key);
d->mo->setValue(key.toUtf8(), value);
}
@@ -249,10 +254,8 @@ QVariant &QDeclarativePropertyMap::operator[](const QString &key)
//### optimize
Q_D(QDeclarativePropertyMap);
QByteArray utf8key = key.toUtf8();
- if (!d->keys.contains(key)) {
- d->keys.append(key);
+ if (!d->keys.contains(key))
d->mo->setValue(utf8key, QVariant()); //force creation -- needed below
- }
return (*(d->mo))[utf8key];
}
@@ -268,9 +271,9 @@ const QVariant QDeclarativePropertyMap::operator[](const QString &key) const
}
/*!
- \fn void QDeclarativePropertyMap::valueChanged(const QString &key)
+ \fn void QDeclarativePropertyMap::valueChanged(const QString &key, const QVariant &value)
This signal is emitted whenever one of the values in the map is changed. \a key
- is the key corresponding to the value that was changed.
+ is the key corresponding to the \a value that was changed.
\note valueChanged() is \bold NOT emitted when changes are made by calling insert()
or clear() - it is only emitted when a value is updated from QML.
diff --git a/src/declarative/util/qdeclarativepropertymap.h b/src/declarative/util/qdeclarativepropertymap.h
index 513089f..e0b7ce3 100644
--- a/src/declarative/util/qdeclarativepropertymap.h
+++ b/src/declarative/util/qdeclarativepropertymap.h
@@ -76,7 +76,7 @@ public:
const QVariant operator[](const QString &key) const;
Q_SIGNALS:
- void valueChanged(const QString &key);
+ void valueChanged(const QString &key, const QVariant &value);
private:
Q_DECLARE_PRIVATE(QDeclarativePropertyMap)
diff --git a/src/declarative/util/qdeclarativestategroup.cpp b/src/declarative/util/qdeclarativestategroup.cpp
index 083e87d..258a9e9 100644
--- a/src/declarative/util/qdeclarativestategroup.cpp
+++ b/src/declarative/util/qdeclarativestategroup.cpp
@@ -69,6 +69,7 @@ public:
static void append_state(QDeclarativeListProperty<QDeclarativeState> *list, QDeclarativeState *state);
static int count_state(QDeclarativeListProperty<QDeclarativeState> *list);
static QDeclarativeState *at_state(QDeclarativeListProperty<QDeclarativeState> *list, int index);
+ static void clear_states(QDeclarativeListProperty<QDeclarativeState> *list);
QList<QDeclarativeState *> states;
QList<QDeclarativeTransition *> transitions;
@@ -150,7 +151,8 @@ QDeclarativeListProperty<QDeclarativeState> QDeclarativeStateGroup::statesProper
Q_D(QDeclarativeStateGroup);
return QDeclarativeListProperty<QDeclarativeState>(this, &d->states, &QDeclarativeStateGroupPrivate::append_state,
&QDeclarativeStateGroupPrivate::count_state,
- &QDeclarativeStateGroupPrivate::at_state);
+ &QDeclarativeStateGroupPrivate::at_state,
+ &QDeclarativeStateGroupPrivate::clear_states);
}
void QDeclarativeStateGroupPrivate::append_state(QDeclarativeListProperty<QDeclarativeState> *list, QDeclarativeState *state)
@@ -175,6 +177,16 @@ QDeclarativeState *QDeclarativeStateGroupPrivate::at_state(QDeclarativeListPrope
return _this->d_func()->states.at(index);
}
+void QDeclarativeStateGroupPrivate::clear_states(QDeclarativeListProperty<QDeclarativeState> *list)
+{
+ QDeclarativeStateGroup *_this = static_cast<QDeclarativeStateGroup *>(list->object);
+ _this->d_func()->setCurrentStateInternal(QString(), true);
+ for (int i = 0; i < _this->d_func()->states.count(); ++i) {
+ _this->d_func()->states.at(i)->setStateGroup(0);
+ }
+ _this->d_func()->states.clear();
+}
+
/*!
\qmlproperty list<Transition> StateGroup::transitions
This property holds a list of transitions defined by the state group.
@@ -206,13 +218,11 @@ QDeclarativeListProperty<QDeclarativeTransition> QDeclarativeStateGroup::transit
example:
\qml
- Script {
- function toggle() {
- if (button.state == 'On')
- button.state = 'Off';
- else
- button.state = 'On';
- }
+ function toggle() {
+ if (button.state == 'On')
+ button.state = 'Off';
+ else
+ button.state = 'On';
}
\endqml
diff --git a/src/declarative/util/qdeclarativestateoperations.cpp b/src/declarative/util/qdeclarativestateoperations.cpp
index 0bc81ee..3469136 100644
--- a/src/declarative/util/qdeclarativestateoperations.cpp
+++ b/src/declarative/util/qdeclarativestateoperations.cpp
@@ -609,209 +609,343 @@ QString QDeclarativeStateChangeScript::typeName() const
For more information on anchors see \l {anchor-layout}{Anchor Layouts}.
*/
-
-
-class QDeclarativeAnchorChangesPrivate : public QObjectPrivate
+class QDeclarativeAnchorSetPrivate : public QObjectPrivate
{
+ Q_DECLARE_PUBLIC(QDeclarativeAnchorSet)
public:
- QDeclarativeAnchorChangesPrivate() : target(0) {}
+ QDeclarativeAnchorSetPrivate()
+ : usedAnchors(0), fill(0),
+ centerIn(0)/*, leftMargin(0), rightMargin(0), topMargin(0), bottomMargin(0),
+ margins(0), vCenterOffset(0), hCenterOffset(0), baselineOffset(0)*/
+ {
+ }
- QDeclarativeItem *target;
- QString resetString;
+ QDeclarativeAnchors::UsedAnchors usedAnchors;
+ //### change to QDeclarativeAnchors::UsedAnchors resetAnchors
QStringList resetList;
+ QDeclarativeItem *fill;
+ QDeclarativeItem *centerIn;
+
QDeclarativeAnchorLine left;
QDeclarativeAnchorLine right;
- QDeclarativeAnchorLine horizontalCenter;
QDeclarativeAnchorLine top;
QDeclarativeAnchorLine bottom;
- QDeclarativeAnchorLine verticalCenter;
+ QDeclarativeAnchorLine vCenter;
+ QDeclarativeAnchorLine hCenter;
QDeclarativeAnchorLine baseline;
- QDeclarativeAnchorLine origLeft;
- QDeclarativeAnchorLine origRight;
- QDeclarativeAnchorLine origHCenter;
- QDeclarativeAnchorLine origTop;
- QDeclarativeAnchorLine origBottom;
- QDeclarativeAnchorLine origVCenter;
- QDeclarativeAnchorLine origBaseline;
-
- QDeclarativeAnchorLine rewindLeft;
- QDeclarativeAnchorLine rewindRight;
- QDeclarativeAnchorLine rewindHCenter;
- QDeclarativeAnchorLine rewindTop;
- QDeclarativeAnchorLine rewindBottom;
- QDeclarativeAnchorLine rewindVCenter;
- QDeclarativeAnchorLine rewindBaseline;
+ /*qreal leftMargin;
+ qreal rightMargin;
+ qreal topMargin;
+ qreal bottomMargin;
+ qreal margins;
+ qreal vCenterOffset;
+ qreal hCenterOffset;
+ qreal baselineOffset;*/
+};
- qreal fromX;
- qreal fromY;
- qreal fromWidth;
- qreal fromHeight;
+QDeclarativeAnchorSet::QDeclarativeAnchorSet(QObject *parent)
+ : QObject(*new QDeclarativeAnchorSetPrivate, parent)
+{
+}
- qreal toX;
- qreal toY;
- qreal toWidth;
- qreal toHeight;
+QDeclarativeAnchorSet::~QDeclarativeAnchorSet()
+{
+}
- qreal rewindX;
- qreal rewindY;
- qreal rewindWidth;
- qreal rewindHeight;
+QDeclarativeAnchorLine QDeclarativeAnchorSet::top() const
+{
+ Q_D(const QDeclarativeAnchorSet);
+ return d->top;
+}
- bool applyOrigLeft;
- bool applyOrigRight;
- bool applyOrigHCenter;
- bool applyOrigTop;
- bool applyOrigBottom;
- bool applyOrigVCenter;
- bool applyOrigBaseline;
-};
+void QDeclarativeAnchorSet::setTop(const QDeclarativeAnchorLine &edge)
+{
+ Q_D(QDeclarativeAnchorSet);
+ d->usedAnchors |= QDeclarativeAnchors::HasTopAnchor;
+ d->top = edge;
+}
-/*!
- \qmlproperty Item AnchorChanges::target
- This property holds the Item whose anchors will change
-*/
+void QDeclarativeAnchorSet::resetTop()
+{
+ Q_D(QDeclarativeAnchorSet);
+ d->usedAnchors &= ~QDeclarativeAnchors::HasTopAnchor;
+ d->top = QDeclarativeAnchorLine();
+ d->resetList << QLatin1String("top");
+}
-QDeclarativeAnchorChanges::QDeclarativeAnchorChanges(QObject *parent)
- : QDeclarativeStateOperation(*(new QDeclarativeAnchorChangesPrivate), parent)
+QDeclarativeAnchorLine QDeclarativeAnchorSet::bottom() const
{
+ Q_D(const QDeclarativeAnchorSet);
+ return d->bottom;
}
-QDeclarativeAnchorChanges::~QDeclarativeAnchorChanges()
+void QDeclarativeAnchorSet::setBottom(const QDeclarativeAnchorLine &edge)
{
+ Q_D(QDeclarativeAnchorSet);
+ d->usedAnchors |= QDeclarativeAnchors::HasBottomAnchor;
+ d->bottom = edge;
}
-QDeclarativeAnchorChanges::ActionList QDeclarativeAnchorChanges::actions()
+void QDeclarativeAnchorSet::resetBottom()
{
- QDeclarativeAction a;
- a.event = this;
- return ActionList() << a;
+ Q_D(QDeclarativeAnchorSet);
+ d->usedAnchors &= ~QDeclarativeAnchors::HasBottomAnchor;
+ d->bottom = QDeclarativeAnchorLine();
+ d->resetList << QLatin1String("bottom");
}
-QDeclarativeItem *QDeclarativeAnchorChanges::object() const
+QDeclarativeAnchorLine QDeclarativeAnchorSet::verticalCenter() const
{
- Q_D(const QDeclarativeAnchorChanges);
- return d->target;
+ Q_D(const QDeclarativeAnchorSet);
+ return d->vCenter;
}
-void QDeclarativeAnchorChanges::setObject(QDeclarativeItem *target)
+void QDeclarativeAnchorSet::setVerticalCenter(const QDeclarativeAnchorLine &edge)
{
- Q_D(QDeclarativeAnchorChanges);
- d->target = target;
+ Q_D(QDeclarativeAnchorSet);
+ d->usedAnchors |= QDeclarativeAnchors::HasVCenterAnchor;
+ d->vCenter = edge;
}
-QString QDeclarativeAnchorChanges::reset() const
+void QDeclarativeAnchorSet::resetVerticalCenter()
{
- Q_D(const QDeclarativeAnchorChanges);
- return d->resetString;
+ Q_D(QDeclarativeAnchorSet);
+ d->usedAnchors &= ~QDeclarativeAnchors::HasVCenterAnchor;
+ d->vCenter = QDeclarativeAnchorLine();
+ d->resetList << QLatin1String("verticalCenter");
}
-void QDeclarativeAnchorChanges::setReset(const QString &reset)
+QDeclarativeAnchorLine QDeclarativeAnchorSet::baseline() const
{
- Q_D(QDeclarativeAnchorChanges);
- d->resetString = reset;
- d->resetList = d->resetString.split(QLatin1Char(','));
- for (int i = 0; i < d->resetList.count(); ++i)
- d->resetList[i] = d->resetList.at(i).trimmed();
+ Q_D(const QDeclarativeAnchorSet);
+ return d->baseline;
}
-/*!
- \qmlproperty AnchorLine AnchorChanges::left
- \qmlproperty AnchorLine AnchorChanges::right
- \qmlproperty AnchorLine AnchorChanges::horizontalCenter
- \qmlproperty AnchorLine AnchorChanges::top
- \qmlproperty AnchorLine AnchorChanges::bottom
- \qmlproperty AnchorLine AnchorChanges::verticalCenter
- \qmlproperty AnchorLine AnchorChanges::baseline
+void QDeclarativeAnchorSet::setBaseline(const QDeclarativeAnchorLine &edge)
+{
+ Q_D(QDeclarativeAnchorSet);
+ d->usedAnchors |= QDeclarativeAnchors::HasBaselineAnchor;
+ d->baseline = edge;
+}
- These properties change the respective anchors of the item.
-*/
+void QDeclarativeAnchorSet::resetBaseline()
+{
+ Q_D(QDeclarativeAnchorSet);
+ d->usedAnchors &= ~QDeclarativeAnchors::HasBaselineAnchor;
+ d->baseline = QDeclarativeAnchorLine();
+ d->resetList << QLatin1String("baseline");
+}
-QDeclarativeAnchorLine QDeclarativeAnchorChanges::left() const
+QDeclarativeAnchorLine QDeclarativeAnchorSet::left() const
{
- Q_D(const QDeclarativeAnchorChanges);
+ Q_D(const QDeclarativeAnchorSet);
return d->left;
}
-void QDeclarativeAnchorChanges::setLeft(const QDeclarativeAnchorLine &edge)
+void QDeclarativeAnchorSet::setLeft(const QDeclarativeAnchorLine &edge)
{
- Q_D(QDeclarativeAnchorChanges);
+ Q_D(QDeclarativeAnchorSet);
+ d->usedAnchors |= QDeclarativeAnchors::HasLeftAnchor;
d->left = edge;
}
-QDeclarativeAnchorLine QDeclarativeAnchorChanges::right() const
+void QDeclarativeAnchorSet::resetLeft()
{
- Q_D(const QDeclarativeAnchorChanges);
+ Q_D(QDeclarativeAnchorSet);
+ d->usedAnchors &= ~QDeclarativeAnchors::HasLeftAnchor;
+ d->left = QDeclarativeAnchorLine();
+ d->resetList << QLatin1String("left");
+}
+
+QDeclarativeAnchorLine QDeclarativeAnchorSet::right() const
+{
+ Q_D(const QDeclarativeAnchorSet);
return d->right;
}
-void QDeclarativeAnchorChanges::setRight(const QDeclarativeAnchorLine &edge)
+void QDeclarativeAnchorSet::setRight(const QDeclarativeAnchorLine &edge)
{
- Q_D(QDeclarativeAnchorChanges);
+ Q_D(QDeclarativeAnchorSet);
+ d->usedAnchors |= QDeclarativeAnchors::HasRightAnchor;
d->right = edge;
}
-QDeclarativeAnchorLine QDeclarativeAnchorChanges::horizontalCenter() const
+void QDeclarativeAnchorSet::resetRight()
{
- Q_D(const QDeclarativeAnchorChanges);
- return d->horizontalCenter;
+ Q_D(QDeclarativeAnchorSet);
+ d->usedAnchors &= ~QDeclarativeAnchors::HasRightAnchor;
+ d->right = QDeclarativeAnchorLine();
+ d->resetList << QLatin1String("right");
}
-void QDeclarativeAnchorChanges::setHorizontalCenter(const QDeclarativeAnchorLine &edge)
+QDeclarativeAnchorLine QDeclarativeAnchorSet::horizontalCenter() const
{
- Q_D(QDeclarativeAnchorChanges);
- d->horizontalCenter = edge;
+ Q_D(const QDeclarativeAnchorSet);
+ return d->hCenter;
}
-QDeclarativeAnchorLine QDeclarativeAnchorChanges::top() const
+void QDeclarativeAnchorSet::setHorizontalCenter(const QDeclarativeAnchorLine &edge)
{
- Q_D(const QDeclarativeAnchorChanges);
- return d->top;
+ Q_D(QDeclarativeAnchorSet);
+ d->usedAnchors |= QDeclarativeAnchors::HasHCenterAnchor;
+ d->hCenter = edge;
}
-void QDeclarativeAnchorChanges::setTop(const QDeclarativeAnchorLine &edge)
+void QDeclarativeAnchorSet::resetHorizontalCenter()
{
- Q_D(QDeclarativeAnchorChanges);
- d->top = edge;
+ Q_D(QDeclarativeAnchorSet);
+ d->usedAnchors &= ~QDeclarativeAnchors::HasHCenterAnchor;
+ d->hCenter = QDeclarativeAnchorLine();
+ d->resetList << QLatin1String("horizontalCenter");
}
-QDeclarativeAnchorLine QDeclarativeAnchorChanges::bottom() const
+QDeclarativeItem *QDeclarativeAnchorSet::fill() const
{
- Q_D(const QDeclarativeAnchorChanges);
- return d->bottom;
+ Q_D(const QDeclarativeAnchorSet);
+ return d->fill;
}
-void QDeclarativeAnchorChanges::setBottom(const QDeclarativeAnchorLine &edge)
+void QDeclarativeAnchorSet::setFill(QDeclarativeItem *f)
{
- Q_D(QDeclarativeAnchorChanges);
- d->bottom = edge;
+ Q_D(QDeclarativeAnchorSet);
+ d->fill = f;
}
-QDeclarativeAnchorLine QDeclarativeAnchorChanges::verticalCenter() const
+void QDeclarativeAnchorSet::resetFill()
{
- Q_D(const QDeclarativeAnchorChanges);
- return d->verticalCenter;
+ setFill(0);
+}
+
+QDeclarativeItem *QDeclarativeAnchorSet::centerIn() const
+{
+ Q_D(const QDeclarativeAnchorSet);
+ return d->centerIn;
}
-void QDeclarativeAnchorChanges::setVerticalCenter(const QDeclarativeAnchorLine &edge)
+void QDeclarativeAnchorSet::setCenterIn(QDeclarativeItem* c)
+{
+ Q_D(QDeclarativeAnchorSet);
+ d->centerIn = c;
+}
+
+void QDeclarativeAnchorSet::resetCenterIn()
+{
+ setCenterIn(0);
+}
+
+
+class QDeclarativeAnchorChangesPrivate : public QObjectPrivate
+{
+public:
+ QDeclarativeAnchorChangesPrivate()
+ : target(0), anchorSet(new QDeclarativeAnchorSet) {}
+ ~QDeclarativeAnchorChangesPrivate() { delete anchorSet; }
+
+ QDeclarativeItem *target;
+ QDeclarativeAnchorSet *anchorSet;
+
+ QDeclarativeAnchorLine origLeft;
+ QDeclarativeAnchorLine origRight;
+ QDeclarativeAnchorLine origHCenter;
+ QDeclarativeAnchorLine origTop;
+ QDeclarativeAnchorLine origBottom;
+ QDeclarativeAnchorLine origVCenter;
+ QDeclarativeAnchorLine origBaseline;
+
+ QDeclarativeAnchorLine rewindLeft;
+ QDeclarativeAnchorLine rewindRight;
+ QDeclarativeAnchorLine rewindHCenter;
+ QDeclarativeAnchorLine rewindTop;
+ QDeclarativeAnchorLine rewindBottom;
+ QDeclarativeAnchorLine rewindVCenter;
+ QDeclarativeAnchorLine rewindBaseline;
+
+ qreal fromX;
+ qreal fromY;
+ qreal fromWidth;
+ qreal fromHeight;
+
+ qreal toX;
+ qreal toY;
+ qreal toWidth;
+ qreal toHeight;
+
+ qreal rewindX;
+ qreal rewindY;
+ qreal rewindWidth;
+ qreal rewindHeight;
+
+ bool applyOrigLeft;
+ bool applyOrigRight;
+ bool applyOrigHCenter;
+ bool applyOrigTop;
+ bool applyOrigBottom;
+ bool applyOrigVCenter;
+ bool applyOrigBaseline;
+};
+
+/*!
+ \qmlproperty Item AnchorChanges::target
+ This property holds the Item whose anchors will change
+*/
+
+QDeclarativeAnchorChanges::QDeclarativeAnchorChanges(QObject *parent)
+ : QDeclarativeStateOperation(*(new QDeclarativeAnchorChangesPrivate), parent)
+{
+}
+
+QDeclarativeAnchorChanges::~QDeclarativeAnchorChanges()
+{
+}
+
+QDeclarativeAnchorChanges::ActionList QDeclarativeAnchorChanges::actions()
+{
+ QDeclarativeAction a;
+ a.event = this;
+ return ActionList() << a;
+}
+
+QDeclarativeAnchorSet *QDeclarativeAnchorChanges::anchors()
{
Q_D(QDeclarativeAnchorChanges);
- d->verticalCenter = edge;
+ return d->anchorSet;
}
-QDeclarativeAnchorLine QDeclarativeAnchorChanges::baseline() const
+QDeclarativeItem *QDeclarativeAnchorChanges::object() const
{
Q_D(const QDeclarativeAnchorChanges);
- return d->baseline;
+ return d->target;
}
-void QDeclarativeAnchorChanges::setBaseline(const QDeclarativeAnchorLine &edge)
+void QDeclarativeAnchorChanges::setObject(QDeclarativeItem *target)
{
Q_D(QDeclarativeAnchorChanges);
- d->baseline = edge;
+ d->target = target;
}
+/*!
+ \qmlproperty AnchorLine AnchorChanges::anchors.left
+ \qmlproperty AnchorLine AnchorChanges::anchors.right
+ \qmlproperty AnchorLine AnchorChanges::anchors.horizontalCenter
+ \qmlproperty AnchorLine AnchorChanges::anchors.top
+ \qmlproperty AnchorLine AnchorChanges::anchors.bottom
+ \qmlproperty AnchorLine AnchorChanges::anchors.verticalCenter
+ \qmlproperty AnchorLine AnchorChanges::anchors.baseline
+
+ These properties change the respective anchors of the item.
+
+ To reset an anchor you can assign \c undefined:
+ \qml
+ AnchorChanges {
+ target: myItem
+ left: undefined //remove myItem's left anchor
+ right: otherItem.right
+ }
+ \endqml
+*/
+
void QDeclarativeAnchorChanges::execute()
{
Q_D(QDeclarativeAnchorChanges);
@@ -835,36 +969,36 @@ void QDeclarativeAnchorChanges::execute()
d->target->anchors()->setBaseline(d->origBaseline);
//reset any anchors that have been specified
- if (d->resetList.contains(QLatin1String("left")))
+ if (d->anchorSet->d_func()->resetList .contains(QLatin1String("left")))
d->target->anchors()->resetLeft();
- if (d->resetList.contains(QLatin1String("right")))
+ if (d->anchorSet->d_func()->resetList .contains(QLatin1String("right")))
d->target->anchors()->resetRight();
- if (d->resetList.contains(QLatin1String("horizontalCenter")))
+ if (d->anchorSet->d_func()->resetList .contains(QLatin1String("horizontalCenter")))
d->target->anchors()->resetHorizontalCenter();
- if (d->resetList.contains(QLatin1String("top")))
+ if (d->anchorSet->d_func()->resetList .contains(QLatin1String("top")))
d->target->anchors()->resetTop();
- if (d->resetList.contains(QLatin1String("bottom")))
+ if (d->anchorSet->d_func()->resetList .contains(QLatin1String("bottom")))
d->target->anchors()->resetBottom();
- if (d->resetList.contains(QLatin1String("verticalCenter")))
+ if (d->anchorSet->d_func()->resetList .contains(QLatin1String("verticalCenter")))
d->target->anchors()->resetVerticalCenter();
- if (d->resetList.contains(QLatin1String("baseline")))
+ if (d->anchorSet->d_func()->resetList .contains(QLatin1String("baseline")))
d->target->anchors()->resetBaseline();
//set any anchors that have been specified
- if (d->left.anchorLine != QDeclarativeAnchorLine::Invalid)
- d->target->anchors()->setLeft(d->left);
- if (d->right.anchorLine != QDeclarativeAnchorLine::Invalid)
- d->target->anchors()->setRight(d->right);
- if (d->horizontalCenter.anchorLine != QDeclarativeAnchorLine::Invalid)
- d->target->anchors()->setHorizontalCenter(d->horizontalCenter);
- if (d->top.anchorLine != QDeclarativeAnchorLine::Invalid)
- d->target->anchors()->setTop(d->top);
- if (d->bottom.anchorLine != QDeclarativeAnchorLine::Invalid)
- d->target->anchors()->setBottom(d->bottom);
- if (d->verticalCenter.anchorLine != QDeclarativeAnchorLine::Invalid)
- d->target->anchors()->setVerticalCenter(d->verticalCenter);
- if (d->baseline.anchorLine != QDeclarativeAnchorLine::Invalid)
- d->target->anchors()->setBaseline(d->baseline);
+ if (d->anchorSet->d_func()->left.anchorLine != QDeclarativeAnchorLine::Invalid)
+ d->target->anchors()->setLeft(d->anchorSet->d_func()->left);
+ if (d->anchorSet->d_func()->right.anchorLine != QDeclarativeAnchorLine::Invalid)
+ d->target->anchors()->setRight(d->anchorSet->d_func()->right);
+ if (d->anchorSet->d_func()->hCenter.anchorLine != QDeclarativeAnchorLine::Invalid)
+ d->target->anchors()->setHorizontalCenter(d->anchorSet->d_func()->hCenter);
+ if (d->anchorSet->d_func()->top.anchorLine != QDeclarativeAnchorLine::Invalid)
+ d->target->anchors()->setTop(d->anchorSet->d_func()->top);
+ if (d->anchorSet->d_func()->bottom.anchorLine != QDeclarativeAnchorLine::Invalid)
+ d->target->anchors()->setBottom(d->anchorSet->d_func()->bottom);
+ if (d->anchorSet->d_func()->vCenter.anchorLine != QDeclarativeAnchorLine::Invalid)
+ d->target->anchors()->setVerticalCenter(d->anchorSet->d_func()->vCenter);
+ if (d->anchorSet->d_func()->baseline.anchorLine != QDeclarativeAnchorLine::Invalid)
+ d->target->anchors()->setBaseline(d->anchorSet->d_func()->baseline);
}
bool QDeclarativeAnchorChanges::isReversable()
@@ -879,19 +1013,19 @@ void QDeclarativeAnchorChanges::reverse()
return;
//reset any anchors set by the state
- if (d->left.anchorLine != QDeclarativeAnchorLine::Invalid)
+ if (d->anchorSet->d_func()->left.anchorLine != QDeclarativeAnchorLine::Invalid)
d->target->anchors()->resetLeft();
- if (d->right.anchorLine != QDeclarativeAnchorLine::Invalid)
+ if (d->anchorSet->d_func()->right.anchorLine != QDeclarativeAnchorLine::Invalid)
d->target->anchors()->resetRight();
- if (d->horizontalCenter.anchorLine != QDeclarativeAnchorLine::Invalid)
+ if (d->anchorSet->d_func()->hCenter.anchorLine != QDeclarativeAnchorLine::Invalid)
d->target->anchors()->resetHorizontalCenter();
- if (d->top.anchorLine != QDeclarativeAnchorLine::Invalid)
+ if (d->anchorSet->d_func()->top.anchorLine != QDeclarativeAnchorLine::Invalid)
d->target->anchors()->resetTop();
- if (d->bottom.anchorLine != QDeclarativeAnchorLine::Invalid)
+ if (d->anchorSet->d_func()->bottom.anchorLine != QDeclarativeAnchorLine::Invalid)
d->target->anchors()->resetBottom();
- if (d->verticalCenter.anchorLine != QDeclarativeAnchorLine::Invalid)
+ if (d->anchorSet->d_func()->vCenter.anchorLine != QDeclarativeAnchorLine::Invalid)
d->target->anchors()->resetVerticalCenter();
- if (d->baseline.anchorLine != QDeclarativeAnchorLine::Invalid)
+ if (d->anchorSet->d_func()->baseline.anchorLine != QDeclarativeAnchorLine::Invalid)
d->target->anchors()->resetBaseline();
//restore previous anchors
@@ -977,26 +1111,26 @@ void QDeclarativeAnchorChanges::copyOriginals(QDeclarativeActionEvent *other)
QDeclarativeAnchorChangesPrivate *acp = ac->d_func();
//probably also need to revert some things
- d->applyOrigLeft = (acp->left.anchorLine != QDeclarativeAnchorLine::Invalid ||
- acp->resetList.contains(QLatin1String("left")));
+ d->applyOrigLeft = (acp->anchorSet->d_func()->left.anchorLine != QDeclarativeAnchorLine::Invalid ||
+ acp->anchorSet->d_func()->resetList.contains(QLatin1String("left")));
- d->applyOrigRight = (acp->right.anchorLine != QDeclarativeAnchorLine::Invalid ||
- acp->resetList.contains(QLatin1String("right")));
+ d->applyOrigRight = (acp->anchorSet->d_func()->right.anchorLine != QDeclarativeAnchorLine::Invalid ||
+ acp->anchorSet->d_func()->resetList.contains(QLatin1String("right")));
- d->applyOrigHCenter = (acp->horizontalCenter.anchorLine != QDeclarativeAnchorLine::Invalid ||
- acp->resetList.contains(QLatin1String("horizontalCenter")));
+ d->applyOrigHCenter = (acp->anchorSet->d_func()->hCenter.anchorLine != QDeclarativeAnchorLine::Invalid ||
+ acp->anchorSet->d_func()->resetList.contains(QLatin1String("horizontalCenter")));
- d->applyOrigTop = (acp->top.anchorLine != QDeclarativeAnchorLine::Invalid ||
- acp->resetList.contains(QLatin1String("top")));
+ d->applyOrigTop = (acp->anchorSet->d_func()->top.anchorLine != QDeclarativeAnchorLine::Invalid ||
+ acp->anchorSet->d_func()->resetList.contains(QLatin1String("top")));
- d->applyOrigBottom = (acp->bottom.anchorLine != QDeclarativeAnchorLine::Invalid ||
- acp->resetList.contains(QLatin1String("bottom")));
+ d->applyOrigBottom = (acp->anchorSet->d_func()->bottom.anchorLine != QDeclarativeAnchorLine::Invalid ||
+ acp->anchorSet->d_func()->resetList.contains(QLatin1String("bottom")));
- d->applyOrigVCenter = (acp->verticalCenter.anchorLine != QDeclarativeAnchorLine::Invalid ||
- acp->resetList.contains(QLatin1String("verticalCenter")));
+ d->applyOrigVCenter = (acp->anchorSet->d_func()->vCenter.anchorLine != QDeclarativeAnchorLine::Invalid ||
+ acp->anchorSet->d_func()->resetList.contains(QLatin1String("verticalCenter")));
- d->applyOrigBaseline = (acp->baseline.anchorLine != QDeclarativeAnchorLine::Invalid ||
- acp->resetList.contains(QLatin1String("baseline")));
+ d->applyOrigBaseline = (acp->anchorSet->d_func()->baseline.anchorLine != QDeclarativeAnchorLine::Invalid ||
+ acp->anchorSet->d_func()->resetList.contains(QLatin1String("baseline")));
d->origLeft = ac->d_func()->origLeft;
d->origRight = ac->d_func()->origRight;
@@ -1034,35 +1168,35 @@ void QDeclarativeAnchorChanges::clearBindings()
d->target->anchors()->resetBaseline();
//reset any anchors that have been specified
- if (d->resetList.contains(QLatin1String("left")))
+ if (d->anchorSet->d_func()->resetList .contains(QLatin1String("left")))
d->target->anchors()->resetLeft();
- if (d->resetList.contains(QLatin1String("right")))
+ if (d->anchorSet->d_func()->resetList .contains(QLatin1String("right")))
d->target->anchors()->resetRight();
- if (d->resetList.contains(QLatin1String("horizontalCenter")))
+ if (d->anchorSet->d_func()->resetList .contains(QLatin1String("horizontalCenter")))
d->target->anchors()->resetHorizontalCenter();
- if (d->resetList.contains(QLatin1String("top")))
+ if (d->anchorSet->d_func()->resetList .contains(QLatin1String("top")))
d->target->anchors()->resetTop();
- if (d->resetList.contains(QLatin1String("bottom")))
+ if (d->anchorSet->d_func()->resetList .contains(QLatin1String("bottom")))
d->target->anchors()->resetBottom();
- if (d->resetList.contains(QLatin1String("verticalCenter")))
+ if (d->anchorSet->d_func()->resetList .contains(QLatin1String("verticalCenter")))
d->target->anchors()->resetVerticalCenter();
- if (d->resetList.contains(QLatin1String("baseline")))
+ if (d->anchorSet->d_func()->resetList .contains(QLatin1String("baseline")))
d->target->anchors()->resetBaseline();
//reset any anchors that we'll be setting in the state
- if (d->left.anchorLine != QDeclarativeAnchorLine::Invalid)
+ if (d->anchorSet->d_func()->left.anchorLine != QDeclarativeAnchorLine::Invalid)
d->target->anchors()->resetLeft();
- if (d->right.anchorLine != QDeclarativeAnchorLine::Invalid)
+ if (d->anchorSet->d_func()->right.anchorLine != QDeclarativeAnchorLine::Invalid)
d->target->anchors()->resetRight();
- if (d->horizontalCenter.anchorLine != QDeclarativeAnchorLine::Invalid)
+ if (d->anchorSet->d_func()->hCenter.anchorLine != QDeclarativeAnchorLine::Invalid)
d->target->anchors()->resetHorizontalCenter();
- if (d->top.anchorLine != QDeclarativeAnchorLine::Invalid)
+ if (d->anchorSet->d_func()->top.anchorLine != QDeclarativeAnchorLine::Invalid)
d->target->anchors()->resetTop();
- if (d->bottom.anchorLine != QDeclarativeAnchorLine::Invalid)
+ if (d->anchorSet->d_func()->bottom.anchorLine != QDeclarativeAnchorLine::Invalid)
d->target->anchors()->resetBottom();
- if (d->verticalCenter.anchorLine != QDeclarativeAnchorLine::Invalid)
+ if (d->anchorSet->d_func()->vCenter.anchorLine != QDeclarativeAnchorLine::Invalid)
d->target->anchors()->resetVerticalCenter();
- if (d->baseline.anchorLine != QDeclarativeAnchorLine::Invalid)
+ if (d->anchorSet->d_func()->baseline.anchorLine != QDeclarativeAnchorLine::Invalid)
d->target->anchors()->resetBaseline();
}
diff --git a/src/declarative/util/qdeclarativestateoperations_p.h b/src/declarative/util/qdeclarativestateoperations_p.h
index 66a8717..c97b2da 100644
--- a/src/declarative/util/qdeclarativestateoperations_p.h
+++ b/src/declarative/util/qdeclarativestateoperations_p.h
@@ -143,54 +143,132 @@ public:
virtual void execute();
};
-class QDeclarativeAnchorChangesPrivate;
-class Q_DECLARATIVE_EXPORT QDeclarativeAnchorChanges : public QDeclarativeStateOperation, public QDeclarativeActionEvent
+class QDeclarativeAnchorChanges;
+class QDeclarativeAnchorSetPrivate;
+class Q_AUTOTEST_EXPORT QDeclarativeAnchorSet : public QObject
{
Q_OBJECT
- Q_DECLARE_PRIVATE(QDeclarativeAnchorChanges)
- Q_PROPERTY(QDeclarativeItem *target READ object WRITE setObject)
- Q_PROPERTY(QString reset READ reset WRITE setReset)
- Q_PROPERTY(QDeclarativeAnchorLine left READ left WRITE setLeft)
- Q_PROPERTY(QDeclarativeAnchorLine right READ right WRITE setRight)
- Q_PROPERTY(QDeclarativeAnchorLine horizontalCenter READ horizontalCenter WRITE setHorizontalCenter)
- Q_PROPERTY(QDeclarativeAnchorLine top READ top WRITE setTop)
- Q_PROPERTY(QDeclarativeAnchorLine bottom READ bottom WRITE setBottom)
- Q_PROPERTY(QDeclarativeAnchorLine verticalCenter READ verticalCenter WRITE setVerticalCenter)
- Q_PROPERTY(QDeclarativeAnchorLine baseline READ baseline WRITE setBaseline)
+ Q_PROPERTY(QDeclarativeAnchorLine left READ left WRITE setLeft RESET resetLeft)
+ Q_PROPERTY(QDeclarativeAnchorLine right READ right WRITE setRight RESET resetRight)
+ Q_PROPERTY(QDeclarativeAnchorLine horizontalCenter READ horizontalCenter WRITE setHorizontalCenter RESET resetHorizontalCenter)
+ Q_PROPERTY(QDeclarativeAnchorLine top READ top WRITE setTop RESET resetTop)
+ Q_PROPERTY(QDeclarativeAnchorLine bottom READ bottom WRITE setBottom RESET resetBottom)
+ Q_PROPERTY(QDeclarativeAnchorLine verticalCenter READ verticalCenter WRITE setVerticalCenter RESET resetVerticalCenter)
+ Q_PROPERTY(QDeclarativeAnchorLine baseline READ baseline WRITE setBaseline RESET resetBaseline)
+ //Q_PROPERTY(QDeclarativeItem *fill READ fill WRITE setFill RESET resetFill)
+ //Q_PROPERTY(QDeclarativeItem *centerIn READ centerIn WRITE setCenterIn RESET resetCenterIn)
+
+ /*Q_PROPERTY(qreal margins READ margins WRITE setMargins NOTIFY marginsChanged)
+ Q_PROPERTY(qreal leftMargin READ leftMargin WRITE setLeftMargin NOTIFY leftMarginChanged)
+ Q_PROPERTY(qreal rightMargin READ rightMargin WRITE setRightMargin NOTIFY rightMarginChanged)
+ Q_PROPERTY(qreal horizontalCenterOffset READ horizontalCenterOffset WRITE setHorizontalCenterOffset NOTIFY horizontalCenterOffsetChanged())
+ Q_PROPERTY(qreal topMargin READ topMargin WRITE setTopMargin NOTIFY topMarginChanged)
+ Q_PROPERTY(qreal bottomMargin READ bottomMargin WRITE setBottomMargin NOTIFY bottomMarginChanged)
+ Q_PROPERTY(qreal verticalCenterOffset READ verticalCenterOffset WRITE setVerticalCenterOffset NOTIFY verticalCenterOffsetChanged())
+ Q_PROPERTY(qreal baselineOffset READ baselineOffset WRITE setBaselineOffset NOTIFY baselineOffsetChanged())*/
public:
- QDeclarativeAnchorChanges(QObject *parent=0);
- ~QDeclarativeAnchorChanges();
-
- virtual ActionList actions();
-
- QDeclarativeItem *object() const;
- void setObject(QDeclarativeItem *);
-
- QString reset() const;
- void setReset(const QString &);
+ QDeclarativeAnchorSet(QObject *parent=0);
+ virtual ~QDeclarativeAnchorSet();
QDeclarativeAnchorLine left() const;
void setLeft(const QDeclarativeAnchorLine &edge);
+ void resetLeft();
QDeclarativeAnchorLine right() const;
void setRight(const QDeclarativeAnchorLine &edge);
+ void resetRight();
QDeclarativeAnchorLine horizontalCenter() const;
void setHorizontalCenter(const QDeclarativeAnchorLine &edge);
+ void resetHorizontalCenter();
QDeclarativeAnchorLine top() const;
void setTop(const QDeclarativeAnchorLine &edge);
+ void resetTop();
QDeclarativeAnchorLine bottom() const;
void setBottom(const QDeclarativeAnchorLine &edge);
+ void resetBottom();
QDeclarativeAnchorLine verticalCenter() const;
void setVerticalCenter(const QDeclarativeAnchorLine &edge);
+ void resetVerticalCenter();
QDeclarativeAnchorLine baseline() const;
void setBaseline(const QDeclarativeAnchorLine &edge);
+ void resetBaseline();
+
+ QDeclarativeItem *fill() const;
+ void setFill(QDeclarativeItem *);
+ void resetFill();
+
+ QDeclarativeItem *centerIn() const;
+ void setCenterIn(QDeclarativeItem *);
+ void resetCenterIn();
+
+ /*qreal leftMargin() const;
+ void setLeftMargin(qreal);
+
+ qreal rightMargin() const;
+ void setRightMargin(qreal);
+
+ qreal horizontalCenterOffset() const;
+ void setHorizontalCenterOffset(qreal);
+
+ qreal topMargin() const;
+ void setTopMargin(qreal);
+
+ qreal bottomMargin() const;
+ void setBottomMargin(qreal);
+
+ qreal margins() const;
+ void setMargins(qreal);
+
+ qreal verticalCenterOffset() const;
+ void setVerticalCenterOffset(qreal);
+
+ qreal baselineOffset() const;
+ void setBaselineOffset(qreal);*/
+
+ QDeclarativeAnchors::UsedAnchors usedAnchors() const;
+
+/*Q_SIGNALS:
+ void leftMarginChanged();
+ void rightMarginChanged();
+ void topMarginChanged();
+ void bottomMarginChanged();
+ void marginsChanged();
+ void verticalCenterOffsetChanged();
+ void horizontalCenterOffsetChanged();
+ void baselineOffsetChanged();*/
+
+private:
+ friend class QDeclarativeAnchorChanges;
+ Q_DISABLE_COPY(QDeclarativeAnchorSet)
+ Q_DECLARE_PRIVATE(QDeclarativeAnchorSet)
+};
+
+class QDeclarativeAnchorChangesPrivate;
+class Q_DECLARATIVE_EXPORT QDeclarativeAnchorChanges : public QDeclarativeStateOperation, public QDeclarativeActionEvent
+{
+ Q_OBJECT
+ Q_DECLARE_PRIVATE(QDeclarativeAnchorChanges)
+
+ Q_PROPERTY(QDeclarativeItem *target READ object WRITE setObject)
+ Q_PROPERTY(QDeclarativeAnchorSet *anchors READ anchors CONSTANT)
+
+public:
+ QDeclarativeAnchorChanges(QObject *parent=0);
+ ~QDeclarativeAnchorChanges();
+
+ virtual ActionList actions();
+
+ QDeclarativeAnchorSet *anchors();
+
+ QDeclarativeItem *object() const;
+ void setObject(QDeclarativeItem *);
virtual void execute();
virtual bool isReversable();
@@ -212,6 +290,7 @@ QT_END_NAMESPACE
QML_DECLARE_TYPE(QDeclarativeParentChange)
QML_DECLARE_TYPE(QDeclarativeStateChangeScript)
+QML_DECLARE_TYPE(QDeclarativeAnchorSet)
QML_DECLARE_TYPE(QDeclarativeAnchorChanges)
QT_END_HEADER
diff --git a/src/declarative/util/qdeclarativeutilmodule.cpp b/src/declarative/util/qdeclarativeutilmodule.cpp
index d79c6ba..2a02ffe 100644
--- a/src/declarative/util/qdeclarativeutilmodule.cpp
+++ b/src/declarative/util/qdeclarativeutilmodule.cpp
@@ -140,6 +140,7 @@ void QDeclarativeUtilModule::defineModule()
qmlRegisterType<QDeclarativeAnchors>();
qmlRegisterType<QDeclarativeStateOperation>();
+ qmlRegisterType<QDeclarativeAnchorSet>();
qmlRegisterTypeEnums<QDeclarativeAbstractAnimation>("Animation");
diff --git a/src/declarative/util/qdeclarativeview.cpp b/src/declarative/util/qdeclarativeview.cpp
index d97fb5f..138fe3c 100644
--- a/src/declarative/util/qdeclarativeview.cpp
+++ b/src/declarative/util/qdeclarativeview.cpp
@@ -289,7 +289,6 @@ QDeclarativeView::~QDeclarativeView()
void QDeclarativeView::setSource(const QUrl& url)
{
d->source = url;
- d->engine.setBaseUrl(url);
d->execute();
}
@@ -448,8 +447,8 @@ void QDeclarativeView::setRootObject(QObject *obj)
d->root = item;
d->qmlRoot = item;
- connect(item, SIGNAL(widthChanged(qreal)), this, SLOT(sizeChanged()));
- connect(item, SIGNAL(heightChanged(qreal)), this, SLOT(sizeChanged()));
+ connect(item, SIGNAL(widthChanged()), this, SLOT(sizeChanged()));
+ connect(item, SIGNAL(heightChanged()), this, SLOT(sizeChanged()));
if (d->initialSize.height() <= 0 && d->qmlRoot->width() > 0)
d->initialSize.setWidth(d->qmlRoot->width());
if (d->initialSize.height() <= 0 && d->qmlRoot->height() > 0)
diff --git a/src/declarative/util/qdeclarativexmllistmodel.cpp b/src/declarative/util/qdeclarativexmllistmodel.cpp
index f7beeaa..efc614b 100644
--- a/src/declarative/util/qdeclarativexmllistmodel.cpp
+++ b/src/declarative/util/qdeclarativexmllistmodel.cpp
@@ -57,6 +57,7 @@
#include <QBuffer>
#include <QNetworkRequest>
#include <QNetworkReply>
+#include <QTimer>
#include <private/qobject_p.h>
@@ -67,6 +68,8 @@ QT_BEGIN_NAMESPACE
typedef QPair<int, int> QDeclarativeXmlListRange;
+#define XMLLISTMODEL_CLEAR_ID 0
+
/*!
\qmlclass XmlRole QDeclarativeXmlListModelRole
\since 4.7
@@ -127,9 +130,10 @@ class QDeclarativeXmlQuery : public QThread
Q_OBJECT
public:
QDeclarativeXmlQuery(QObject *parent=0)
- : QThread(parent), m_quit(false), m_abortQueryId(-1), m_queryIds(0) {
+ : QThread(parent), m_quit(false), m_abortQueryId(-1), m_queryIds(XMLLISTMODEL_CLEAR_ID + 1) {
qRegisterMetaType<QDeclarativeXmlQueryResult>("QDeclarativeXmlQueryResult");
}
+
~QDeclarativeXmlQuery() {
m_mutex.lock();
m_quit = true;
@@ -173,22 +177,6 @@ public:
return job.queryId;
}
- QList<QList<QVariant> > modelData() {
- QMutexLocker locker(&m_mutex);
- return m_modelData;
- }
-
- QList<QDeclarativeXmlListRange> insertedItemRanges() {
- QMutexLocker locker(&m_mutex);
- return m_insertedItemRanges;
- }
-
- QList<QDeclarativeXmlListRange> removedItemRanges() {
- QMutexLocker locker(&m_mutex);
- return m_removedItemRanges;
- }
-
-
Q_SIGNALS:
void queryCompleted(const QDeclarativeXmlQueryResult &);
@@ -254,13 +242,10 @@ void QDeclarativeXmlQuery::doQueryJob()
query.setQuery(job.namespaces + job.query);
query.evaluateTo(&r);
- //qDebug() << r;
-
//always need a single root element
QByteArray xml = "<dummy:items xmlns:dummy=\"http://qtsotware.com/dummy\">\n" + r.toUtf8() + "</dummy:items>";
QBuffer b(&xml);
b.open(QIODevice::ReadOnly);
- //qDebug() << xml;
QString namespaces = QLatin1String("declare namespace dummy=\"http://qtsotware.com/dummy\";\n") + job.namespaces;
QString prefix = QLatin1String("doc($inputDocument)/dummy:items") +
@@ -278,7 +263,6 @@ void QDeclarativeXmlQuery::doQueryJob()
if (item.isAtomicValue())
count = item.toAtomicValue().toInt();
}
- //qDebug() << count;
job.data = xml;
m_prefix = namespaces + prefix + QLatin1Char('/');
@@ -552,7 +536,7 @@ QHash<int,QVariant> QDeclarativeXmlListModel::data(int index, const QList<int> &
for (int i = 0; i < roles.size(); ++i) {
int role = roles.at(i);
int roleIndex = d->roles.indexOf(role);
- rv.insert(role, roleIndex == -1 ? QVariant() : d->data.at(roleIndex).at(index));
+ rv.insert(role, roleIndex == -1 ? QVariant() : d->data.value(roleIndex).value(index));
}
return rv;
}
@@ -561,7 +545,7 @@ QVariant QDeclarativeXmlListModel::data(int index, int role) const
{
Q_D(const QDeclarativeXmlListModel);
int roleIndex = d->roles.indexOf(role);
- return (roleIndex == -1) ? QVariant() : d->data.at(roleIndex).at(index);
+ return (roleIndex == -1) ? QVariant() : d->data.value(roleIndex).value(index);
}
/*!
@@ -606,7 +590,8 @@ void QDeclarativeXmlListModel::setSource(const QUrl &src)
Q_D(QDeclarativeXmlListModel);
if (d->src != src) {
d->src = src;
- reload();
+ if (d->xml.isEmpty()) // src is only used if d->xml is not set
+ reload();
emit sourceChanged();
}
}
@@ -683,23 +668,13 @@ void QDeclarativeXmlListModel::setNamespaceDeclarations(const QString &declarati
/*!
\qmlproperty enum XmlListModel::status
+ Specifies the model loading status, which can be one of the following:
- This property holds the status of data source loading. It can be one of:
- \list
- \o Null - no data source has been set
- \o Ready - the data source has been loaded
- \o Loading - the data source is currently being loaded
- \o Error - an error occurred while loading the data source
- \endlist
-
- Note that a change in the status property does not cause anything to happen
- (although it reflects what has happened to the XmlListModel internally). If you wish
- to react to the change in status you need to do it yourself, for example in one
- of the following ways:
\list
- \o Create a state, so that a state change occurs, e.g. State{name: 'loaded'; when: xmlListModel.status = XmlListModel.Ready;}
- \o Do something inside the onStatusChanged signal handler, e.g. XmlListModel{id: xmlListModel; onStatusChanged: if(xmlListModel.status == XmlListModel.Ready) console.log('Loaded');}
- \o Bind to the status variable somewhere, e.g. Text{text: if(xmlListModel.status!=XmlListModel.Ready){'Not Loaded';}else{'Loaded';}}
+ \o Null - No XML data has been set for this model.
+ \o Ready - The XML data has been loaded into the model.
+ \o Loading - The model is in the process of reading and loading XML data.
+ \o Error - An error occurred while the model was loading.
\endlist
\sa progress
@@ -714,10 +689,17 @@ QDeclarativeXmlListModel::Status QDeclarativeXmlListModel::status() const
/*!
\qmlproperty real XmlListModel::progress
- This property holds the progress of data source loading, from 0.0 (nothing loaded)
- to 1.0 (finished).
+ This indicates the current progress of the downloading of the XML data
+ source. This value ranges from 0.0 (no data downloaded) to
+ 1.0 (all data downloaded). If the XML data is not from a remote source,
+ the progress becomes 1.0 as soon as the data is read.
+
+ Note that when the progress is 1.0, the XML data has been downloaded, but
+ it is yet to be loaded into the model at this point. Use the status
+ property to find out when the XML data has been read and loaded into
+ the model.
- \sa status
+ \sa status, source
*/
qreal QDeclarativeXmlListModel::progress() const
{
@@ -748,6 +730,8 @@ void QDeclarativeXmlListModel::componentComplete()
Otherwise, items are only added if the model does not already
contain items with matching key role values.
+
+ \sa XmlRole::isKey
*/
void QDeclarativeXmlListModel::reload()
{
@@ -759,27 +743,8 @@ void QDeclarativeXmlListModel::reload()
globalXmlQuery()->abort(d->queryId);
d->queryId = -1;
- int count = d->size;
- if (count < 0)
+ if (d->size < 0)
d->size = 0;
- bool hasKeys = false;
- for (int i=0; i<d->roleObjects.count(); i++) {
- if (d->roleObjects[i]->isKey()) {
- hasKeys = true;
- break;
- }
- }
- if (!hasKeys) {
- d->data.clear();
- d->size = 0;
- if (count > 0) {
- emit itemsRemoved(0, count);
- emit countChanged();
- }
- }
-
- if (d->src.isEmpty() && d->xml.isEmpty())
- return;
if (d->reply) {
d->reply->abort();
@@ -790,9 +755,19 @@ void QDeclarativeXmlListModel::reload()
if (!d->xml.isEmpty()) {
d->queryId = globalXmlQuery()->doQuery(d->query, d->namespaces, d->xml.toUtf8(), &d->roleObjects, d->keyRoleResultsCache);
d->progress = 1.0;
- d->status = Ready;
+ d->status = Loading;
+ emit progressChanged(d->progress);
+ emit statusChanged(d->status);
+ return;
+ }
+
+ if (d->src.isEmpty()) {
+ d->queryId = XMLLISTMODEL_CLEAR_ID;
+ d->progress = 1.0;
+ d->status = Loading;
emit progressChanged(d->progress);
emit statusChanged(d->status);
+ QTimer::singleShot(0, this, SLOT(dataCleared()));
return;
}
@@ -831,18 +806,33 @@ void QDeclarativeXmlListModel::requestFinished()
disconnect(d->reply, 0, this, 0);
d->reply->deleteLater();
d->reply = 0;
+
+ int count = this->count();
+ d->data.clear();
+ d->size = 0;
+ if (count > 0) {
+ emit itemsRemoved(0, count);
+ emit countChanged();
+ }
+
d->status = Error;
+ d->queryId = -1;
+ emit statusChanged(d->status);
} else {
- d->status = Ready;
QByteArray data = d->reply->readAll();
- d->queryId = globalXmlQuery()->doQuery(d->query, d->namespaces, data, &d->roleObjects, d->keyRoleResultsCache);
+ if (data.isEmpty()) {
+ d->queryId = XMLLISTMODEL_CLEAR_ID;
+ QTimer::singleShot(0, this, SLOT(dataCleared()));
+ } else {
+ d->queryId = globalXmlQuery()->doQuery(d->query, d->namespaces, data, &d->roleObjects, d->keyRoleResultsCache);
+ }
disconnect(d->reply, 0, this, 0);
d->reply->deleteLater();
d->reply = 0;
+
+ d->progress = 1.0;
+ emit progressChanged(d->progress);
}
- d->progress = 1.0;
- emit progressChanged(d->progress);
- emit statusChanged(d->status);
}
void QDeclarativeXmlListModel::requestProgress(qint64 received, qint64 total)
@@ -854,23 +844,58 @@ void QDeclarativeXmlListModel::requestProgress(qint64 received, qint64 total)
}
}
+void QDeclarativeXmlListModel::dataCleared()
+{
+ Q_D(QDeclarativeXmlListModel);
+ QDeclarativeXmlQueryResult r;
+ r.queryId = XMLLISTMODEL_CLEAR_ID;
+ r.size = 0;
+ r.removed << qMakePair(0, count());
+ r.keyRoleResultsCache = d->keyRoleResultsCache;
+ queryCompleted(r);
+}
+
void QDeclarativeXmlListModel::queryCompleted(const QDeclarativeXmlQueryResult &result)
{
Q_D(QDeclarativeXmlListModel);
if (result.queryId != d->queryId)
return;
+
+ int origCount = d->size;
bool sizeChanged = result.size != d->size;
+
d->size = result.size;
d->data = result.data;
d->keyRoleResultsCache = result.keyRoleResultsCache;
+ d->status = Ready;
+ d->queryId = -1;
+
+ bool hasKeys = false;
+ for (int i=0; i<d->roleObjects.count(); i++) {
+ if (d->roleObjects[i]->isKey()) {
+ hasKeys = true;
+ break;
+ }
+ }
+ if (!hasKeys) {
+ if (!(origCount == 0 && d->size == 0)) {
+ emit itemsRemoved(0, origCount);
+ emit itemsInserted(0, d->size);
+ emit countChanged();
+ }
+
+ } else {
- for (int i=0; i<result.removed.count(); i++)
- emit itemsRemoved(result.removed[i].first, result.removed[i].second);
- for (int i=0; i<result.inserted.count(); i++)
- emit itemsInserted(result.inserted[i].first, result.inserted[i].second);
+ for (int i=0; i<result.removed.count(); i++)
+ emit itemsRemoved(result.removed[i].first, result.removed[i].second);
+ for (int i=0; i<result.inserted.count(); i++)
+ emit itemsInserted(result.inserted[i].first, result.inserted[i].second);
- if (sizeChanged)
- emit countChanged();
+ if (sizeChanged)
+ emit countChanged();
+ }
+
+ emit statusChanged(d->status);
}
QT_END_NAMESPACE
diff --git a/src/declarative/util/qdeclarativexmllistmodel_p.h b/src/declarative/util/qdeclarativexmllistmodel_p.h
index 7bb0f0e..7b85476 100644
--- a/src/declarative/util/qdeclarativexmllistmodel_p.h
+++ b/src/declarative/util/qdeclarativexmllistmodel_p.h
@@ -117,7 +117,7 @@ public:
virtual void componentComplete();
Q_SIGNALS:
- void statusChanged(Status);
+ void statusChanged(QDeclarativeXmlListModel::Status);
void progressChanged(qreal progress);
void countChanged();
void sourceChanged();
@@ -135,6 +135,7 @@ public Q_SLOTS:
private Q_SLOTS:
void requestFinished();
void requestProgress(qint64,qint64);
+ void dataCleared();
void queryCompleted(const QDeclarativeXmlQueryResult &);
private: