diff options
author | David Boddie <dboddie@trolltech.com> | 2010-08-24 14:08:28 (GMT) |
---|---|---|
committer | David Boddie <dboddie@trolltech.com> | 2010-08-24 14:08:28 (GMT) |
commit | c408dd8a80d509f18ec3c3bc8a74891f541f6fdd (patch) | |
tree | a29369b3d1e03f8f688b128e231c004081028bb6 /src/declarative | |
parent | ef9cc109f1a6fe84ca27a6c8a53f1783b8bdf14d (diff) | |
parent | a8030e0c543e538652605557843b845f89b11589 (diff) | |
download | Qt-c408dd8a80d509f18ec3c3bc8a74891f541f6fdd.zip Qt-c408dd8a80d509f18ec3c3bc8a74891f541f6fdd.tar.gz Qt-c408dd8a80d509f18ec3c3bc8a74891f541f6fdd.tar.bz2 |
Merge branch '4.7' into qmldocs
Diffstat (limited to 'src/declarative')
12 files changed, 111 insertions, 118 deletions
diff --git a/src/declarative/graphicsitems/qdeclarativeloader.cpp b/src/declarative/graphicsitems/qdeclarativeloader.cpp index 4c6268f..2fde4c8 100644 --- a/src/declarative/graphicsitems/qdeclarativeloader.cpp +++ b/src/declarative/graphicsitems/qdeclarativeloader.cpp @@ -115,53 +115,76 @@ void QDeclarativeLoaderPrivate::initResize() \brief The Loader item allows dynamically loading an Item-based subtree from a URL or Component. - The Loader element instantiates an item from a component. The component to - be instantiated may be specified directly by the \l sourceComponent - property, or loaded from a URL via the \l source property. + Loader is used to dynamically load visual QML components. It can load a + QML file (using the \l source property) or a \l Component object (using + the \l sourceComponent property). It is useful for delaying the creation + of a component until it is required: for example, when a component should + be created on demand, or when a component should not be created + unnecessarily for performance reasons. - Loader can be used to delay the creation of a component until it - is required. For example, this loads "Page1.qml" as a component - into the Loader element, when the \l MouseArea is clicked: + Here is a Loader that loads "Page1.qml" as a component when the + \l MouseArea is clicked: - \code - import Qt 4.7 + \snippet doc/src/snippets/declarative/loader/simple.qml 0 - Item { - width: 200; height: 200 + The loaded item can be accessed using the \l item property. - MouseArea { - anchors.fill: parent - onClicked: pageLoader.source = "Page1.qml" - } + Loader is like any other visual item and must be positioned and sized + accordingly to become visible. Once the component is loaded, the Loader + is automatically resized to the size of the component. - Loader { id: pageLoader } - } - \endcode + If the \l source or \l sourceComponent changes, any previously instantiated + items are destroyed. Setting \l source to an empty string or setting + \l sourceComponent to \c undefined destroys the currently loaded item, + freeing resources and leaving the Loader empty. + + + \section2 Receiving signals from loaded items - Note that Loader is like any other graphical Item and needs to be positioned - and sized accordingly to become visible. When a component is loaded, the - Loader is automatically resized to the size of the component. + Any signals emitted from the loaded item can be received using the + \l Connections element. For example, the following \c application.qml + loads \c MyItem.qml, and is able to receive the \c message signal from + the loaded item through a \l Connections object: - If the Loader source is changed, any previous items instantiated - will be destroyed. Setting \l source to an empty string, or setting - sourceComponent to \e undefined - will destroy the currently instantiated items, freeing resources - and leaving the Loader empty. For example: + \table + \row + \o application.qml + \o MyItem.qml + \row + \o \snippet doc/src/snippets/declarative/loader/connections.qml 0 + \o \snippet doc/src/snippets/declarative/loader/MyItem.qml 0 + \endtable - \code - pageLoader.source = "" - \endcode + Alternatively, since \c MyItem.qml is loaded within the scope of the + Loader, it could also directly call any function defined in the Loader or + its parent \l Item. - or - \code - pageLoader.sourceComponent = undefined - \endcode + \section2 Focus and key events - unloads "Page1.qml" and frees resources consumed by it. + Loader is a focus scope. Its \l {Item::}{focus} property must be set to + \c true for any of its children to get the \e {active focus}. (See + \l{qmlfocus#Acquiring Focus and Focus Scopes}{the focus documentation page} + for more details.) Any key events received in the loaded item should likely + also be \l {KeyEvent::}{accepted} so they are not propagated to the Loader. - Note that Loader is a focus scope. Its \c focus property must be set to \c true for any of its children - to get the \e {active focus} (see \l{qmlfocus#Acquiring Focus and Focus Scopes}{the focus documentation page} for more details). + For example, the following \c application.qml loads \c KeyReader.qml when + the \l MouseArea is clicked. Notice the \l {Item::}{focus} property is + set to \c true for the Loader as well as the \l Item in the dynamically + loaded object: + + \table + \row + \o application.qml + \o KeyReader.qml + \row + \o \snippet doc/src/snippets/declarative/loader/focus.qml 0 + \o \snippet doc/src/snippets/declarative/loader/KeyReader.qml 0 + \endtable + + Once \c KeyReader.qml is loaded, it accepts key events and sets + \c event.accepted to \c true so that the event is not propagated to the + parent \l Rectangle. \sa {dynamic-object-creation}{Dynamic Object Creation} */ @@ -198,8 +221,13 @@ QDeclarativeLoader::~QDeclarativeLoader() /*! \qmlproperty url Loader::source - This property holds the URL of the QML component to - instantiate. + This property holds the URL of the QML component to instantiate. + + Note the QML component must be an \l Item-based component. Loader cannot + load non-visual components. + + To unload the currently loaded item, set this property to an empty string, + or set \l sourceComponent to \c undefined. \sa sourceComponent, status, progress */ @@ -258,7 +286,8 @@ void QDeclarativeLoader::setSource(const QUrl &url) } \endqml - Note this value must hold a \l Component object; it cannot be a \l Item. + To unload the currently loaded item, set this property to an empty string, + or set \l sourceComponent to \c undefined. \sa source, progress */ @@ -477,7 +506,7 @@ void QDeclarativeLoaderPrivate::_q_updateSize(bool loaderGeometryChanged) /*! \qmlproperty Item Loader::item - This property holds the top-level item created from source. + This property holds the top-level item that is currently loaded. */ QGraphicsObject *QDeclarativeLoader::item() const { diff --git a/src/declarative/graphicsitems/qdeclarativepath_p.h b/src/declarative/graphicsitems/qdeclarativepath_p.h index 5ab5cfd..195057c 100644 --- a/src/declarative/graphicsitems/qdeclarativepath_p.h +++ b/src/declarative/graphicsitems/qdeclarativepath_p.h @@ -190,7 +190,7 @@ private: class Q_AUTOTEST_EXPORT QDeclarativePathPercent : public QDeclarativePathElement { Q_OBJECT - Q_PROPERTY(qreal value READ value WRITE setValue NOTIFY changed) + Q_PROPERTY(qreal value READ value WRITE setValue) public: QDeclarativePathPercent(QObject *parent=0) : QDeclarativePathElement(parent) {} diff --git a/src/declarative/graphicsitems/qdeclarativepathview.cpp b/src/declarative/graphicsitems/qdeclarativepathview.cpp index 535fb90..4b97505 100644 --- a/src/declarative/graphicsitems/qdeclarativepathview.cpp +++ b/src/declarative/graphicsitems/qdeclarativepathview.cpp @@ -480,7 +480,8 @@ void QDeclarativePathView::setModel(const QVariant &model) connect(d->model, SIGNAL(modelReset()), this, SLOT(modelReset())); connect(d->model, SIGNAL(createdItem(int, QDeclarativeItem*)), this, SLOT(createdItem(int,QDeclarativeItem*))); } - d->offset = qmlMod(d->offset, qreal(d->model->count())); + if (d->model->count()) + d->offset = qmlMod(d->offset, qreal(d->model->count())); if (d->offset < 0) d->offset = d->model->count() + d->offset; d->regenerate(); diff --git a/src/declarative/graphicsitems/qdeclarativetextinput.cpp b/src/declarative/graphicsitems/qdeclarativetextinput.cpp index bd8d404..b4f36f4 100644 --- a/src/declarative/graphicsitems/qdeclarativetextinput.cpp +++ b/src/declarative/graphicsitems/qdeclarativetextinput.cpp @@ -277,8 +277,10 @@ void QDeclarativeTextInput::setSelectionColor(const QColor &color) QPalette p = d->control->palette(); p.setColor(QPalette::Highlight, d->selectionColor); d->control->setPalette(p); - clearCache(); - update(); + if (d->control->hasSelectedText()) { + clearCache(); + update(); + } emit selectionColorChanged(color); } @@ -303,8 +305,10 @@ void QDeclarativeTextInput::setSelectedTextColor(const QColor &color) QPalette p = d->control->palette(); p.setColor(QPalette::HighlightedText, d->selectedTextColor); d->control->setPalette(p); - clearCache(); - update(); + if (d->control->hasSelectedText()) { + clearCache(); + update(); + } emit selectedTextColorChanged(color); } @@ -1233,8 +1237,12 @@ void QDeclarativeTextInput::setPasswordCharacter(const QString &str) Q_D(QDeclarativeTextInput); if(str.length() < 1) return; - emit passwordCharacterChanged(); d->control->setPasswordCharacter(str.constData()[0]); + EchoMode echoMode_ = echoMode(); + if (echoMode_ == Password || echoMode_ == PasswordEchoOnEdit) { + updateSize(); + } + emit passwordCharacterChanged(); } /*! diff --git a/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp b/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp index 764676a..50a0a33 100644 --- a/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp +++ b/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp @@ -238,20 +238,6 @@ QString QDeclarativeVisualItemModel::stringValue(int index, const QString &name) return QDeclarativeEngine::contextForObject(d->children.at(index).item)->contextProperty(name).toString(); } -QVariant QDeclarativeVisualItemModel::evaluate(int index, const QString &expression, QObject *objectContext) -{ - Q_D(QDeclarativeVisualItemModel); - if (index < 0 || index >= d->children.count()) - return QVariant(); - QDeclarativeContext *ccontext = qmlContext(this); - QDeclarativeContext *ctxt = new QDeclarativeContext(ccontext); - ctxt->setContextObject(d->children.at(index).item); - QDeclarativeExpression e(ctxt, objectContext, expression); - QVariant value = e.evaluate(); - delete ctxt; - return value; -} - int QDeclarativeVisualItemModel::indexOf(QDeclarativeItem *item, QObject *) const { Q_D(const QDeclarativeVisualItemModel); @@ -728,6 +714,7 @@ void QDeclarativeVisualDataModel::setModel(const QVariant &model) QObject::disconnect(d->m_abstractItemModel, SIGNAL(rowsMoved(const QModelIndex&,int,int,const QModelIndex&,int)), this, SLOT(_q_rowsMoved(const QModelIndex&,int,int,const QModelIndex&,int))); QObject::disconnect(d->m_abstractItemModel, SIGNAL(modelReset()), this, SLOT(_q_modelReset())); + d->m_abstractItemModel = 0; } else if (d->m_visualItemModel) { QObject::disconnect(d->m_visualItemModel, SIGNAL(itemsInserted(int,int)), this, SIGNAL(itemsInserted(int,int))); @@ -1167,38 +1154,6 @@ QString QDeclarativeVisualDataModel::stringValue(int index, const QString &name) return val; } -QVariant QDeclarativeVisualDataModel::evaluate(int index, const QString &expression, QObject *objectContext) -{ - Q_D(QDeclarativeVisualDataModel); - if (d->m_visualItemModel) - return d->m_visualItemModel->evaluate(index, expression, objectContext); - - if ((!d->m_listModelInterface && !d->m_abstractItemModel) || !d->m_delegate) - return QVariant(); - - QVariant value; - QObject *nobj = d->m_cache.item(index); - if (nobj) { - QDeclarativeItem *item = qobject_cast<QDeclarativeItem *>(nobj); - if (item) { - QDeclarativeExpression e(qmlContext(item), objectContext, expression); - value = e.evaluate(); - } - } else { - QDeclarativeContext *ccontext = d->m_context; - if (!ccontext) ccontext = qmlContext(this); - QDeclarativeContext *ctxt = new QDeclarativeContext(ccontext); - QDeclarativeVisualDataModelData *data = new QDeclarativeVisualDataModelData(index, this); - ctxt->setContextObject(data); - QDeclarativeExpression e(ctxt, objectContext, expression); - value = e.evaluate(); - delete data; - delete ctxt; - } - - return value; -} - int QDeclarativeVisualDataModel::indexOf(QDeclarativeItem *item, QObject *) const { QVariant val = QDeclarativeEngine::contextForObject(item)->contextProperty(QLatin1String("index")); diff --git a/src/declarative/graphicsitems/qdeclarativevisualitemmodel_p.h b/src/declarative/graphicsitems/qdeclarativevisualitemmodel_p.h index d5c0de2..50d2c53 100644 --- a/src/declarative/graphicsitems/qdeclarativevisualitemmodel_p.h +++ b/src/declarative/graphicsitems/qdeclarativevisualitemmodel_p.h @@ -79,7 +79,6 @@ public: virtual ReleaseFlags release(QDeclarativeItem *item) = 0; virtual bool completePending() const = 0; virtual void completeItem() = 0; - virtual QVariant evaluate(int index, const QString &expression, QObject *objectContext) = 0; virtual QString stringValue(int, const QString &) { return QString(); } virtual int indexOf(QDeclarativeItem *item, QObject *objectContext) const = 0; @@ -122,7 +121,6 @@ public: virtual bool completePending() const; virtual void completeItem(); virtual QString stringValue(int index, const QString &role); - virtual QVariant evaluate(int index, const QString &expression, QObject *objectContext); virtual int indexOf(QDeclarativeItem *item, QObject *objectContext) const; @@ -177,7 +175,6 @@ public: bool completePending() const; void completeItem(); virtual QString stringValue(int index, const QString &role); - QVariant evaluate(int index, const QString &expression, QObject *objectContext); int indexOf(QDeclarativeItem *item, QObject *objectContext) const; diff --git a/src/declarative/qml/qdeclarativeengine.cpp b/src/declarative/qml/qdeclarativeengine.cpp index 513fc65..cedf9d5 100644 --- a/src/declarative/qml/qdeclarativeengine.cpp +++ b/src/declarative/qml/qdeclarativeengine.cpp @@ -551,7 +551,7 @@ QDeclarativeEngine::~QDeclarativeEngine() } /*! \fn void QDeclarativeEngine::quit() - This signal is emitted when the QDeclarativeEngine quits. + This signal is emitted when the QML loaded by the engine would like to quit. */ /*! \fn void QDeclarativeEngine::warnings(const QList<QDeclarativeError> &warnings) @@ -674,7 +674,7 @@ void QDeclarativeEngine::addImageProvider(const QString &providerId, QDeclarativ { Q_D(QDeclarativeEngine); QMutexLocker locker(&d->mutex); - d->imageProviders.insert(providerId, provider); + d->imageProviders.insert(providerId, QSharedPointer<QDeclarativeImageProvider>(provider)); } /*! @@ -684,7 +684,7 @@ QDeclarativeImageProvider *QDeclarativeEngine::imageProvider(const QString &prov { Q_D(const QDeclarativeEngine); QMutexLocker locker(&d->mutex); - return d->imageProviders.value(providerId); + return d->imageProviders.value(providerId).data(); } /*! @@ -698,13 +698,14 @@ void QDeclarativeEngine::removeImageProvider(const QString &providerId) { Q_D(QDeclarativeEngine); QMutexLocker locker(&d->mutex); - delete d->imageProviders.take(providerId); + d->imageProviders.take(providerId); } QDeclarativeImageProvider::ImageType QDeclarativeEnginePrivate::getImageProviderType(const QUrl &url) { QMutexLocker locker(&mutex); - QDeclarativeImageProvider *provider = imageProviders.value(url.host()); + QSharedPointer<QDeclarativeImageProvider> provider = imageProviders.value(url.host()); + locker.unlock(); if (provider) return provider->imageType(); return static_cast<QDeclarativeImageProvider::ImageType>(-1); @@ -714,7 +715,8 @@ QImage QDeclarativeEnginePrivate::getImageFromProvider(const QUrl &url, QSize *s { QMutexLocker locker(&mutex); QImage image; - QDeclarativeImageProvider *provider = imageProviders.value(url.host()); + QSharedPointer<QDeclarativeImageProvider> provider = imageProviders.value(url.host()); + locker.unlock(); if (provider) image = provider->requestImage(url.path().mid(1), size, req_size); return image; @@ -724,7 +726,8 @@ QPixmap QDeclarativeEnginePrivate::getPixmapFromProvider(const QUrl &url, QSize { QMutexLocker locker(&mutex); QPixmap pixmap; - QDeclarativeImageProvider *provider = imageProviders.value(url.host()); + QSharedPointer<QDeclarativeImageProvider> provider = imageProviders.value(url.host()); + locker.unlock(); if (provider) pixmap = provider->requestPixmap(url.path().mid(1), size, req_size); return pixmap; diff --git a/src/declarative/qml/qdeclarativeengine_p.h b/src/declarative/qml/qdeclarativeengine_p.h index 3b5dd5a..db2db35 100644 --- a/src/declarative/qml/qdeclarativeengine_p.h +++ b/src/declarative/qml/qdeclarativeengine_p.h @@ -232,7 +232,7 @@ public: mutable QNetworkAccessManager *networkAccessManager; mutable QDeclarativeNetworkAccessManagerFactory *networkAccessManagerFactory; - QHash<QString,QDeclarativeImageProvider*> imageProviders; + QHash<QString,QSharedPointer<QDeclarativeImageProvider> > imageProviders; QDeclarativeImageProvider::ImageType getImageProviderType(const QUrl &url); QImage getImageFromProvider(const QUrl &url, QSize *size, const QSize& req_size); QPixmap getPixmapFromProvider(const QUrl &url, QSize *size, const QSize& req_size); diff --git a/src/declarative/qml/qdeclarativeenginedebug.cpp b/src/declarative/qml/qdeclarativeenginedebug.cpp index ed98e3c..688e0fc 100644 --- a/src/declarative/qml/qdeclarativeenginedebug.cpp +++ b/src/declarative/qml/qdeclarativeenginedebug.cpp @@ -264,8 +264,7 @@ void QDeclarativeEngineDebugServer::buildObjectList(QDataStream &message, QDecla QDeclarativeContextData *child = p->childContexts; while (child) { - if (!child->isInternal) - ++count; + ++count; child = child->nextChild; } @@ -273,8 +272,7 @@ void QDeclarativeEngineDebugServer::buildObjectList(QDataStream &message, QDecla child = p->childContexts; while (child) { - if (!child->isInternal) - buildObjectList(message, child->asQDeclarativeContext()); + buildObjectList(message, child->asQDeclarativeContext()); child = child->nextChild; } diff --git a/src/declarative/qml/qdeclarativeimageprovider.cpp b/src/declarative/qml/qdeclarativeimageprovider.cpp index ea68327..ef31be7 100644 --- a/src/declarative/qml/qdeclarativeimageprovider.cpp +++ b/src/declarative/qml/qdeclarativeimageprovider.cpp @@ -161,7 +161,9 @@ QDeclarativeImageProvider::QDeclarativeImageProvider(ImageType type) } /*! - \internal + Destroys the QDeclarativeImageProvider + + \note The destructor of your derived class need to be thread safe. */ QDeclarativeImageProvider::~QDeclarativeImageProvider() { diff --git a/src/declarative/util/qdeclarativeanimation_p.h b/src/declarative/util/qdeclarativeanimation_p.h index 481c36c..d15d1f6 100644 --- a/src/declarative/util/qdeclarativeanimation_p.h +++ b/src/declarative/util/qdeclarativeanimation_p.h @@ -74,7 +74,7 @@ class Q_AUTOTEST_EXPORT QDeclarativeAbstractAnimation : public QObject, public Q Q_PROPERTY(bool running READ isRunning WRITE setRunning NOTIFY runningChanged) Q_PROPERTY(bool paused READ isPaused WRITE setPaused NOTIFY pausedChanged) Q_PROPERTY(bool alwaysRunToEnd READ alwaysRunToEnd WRITE setAlwaysRunToEnd NOTIFY alwaysRunToEndChanged) - Q_PROPERTY(int loops READ loops WRITE setLoops NOTIFY loopsChanged) + Q_PROPERTY(int loops READ loops WRITE setLoops NOTIFY loopCountChanged) Q_CLASSINFO("DefaultMethod", "start()") public: @@ -301,8 +301,8 @@ class Q_AUTOTEST_EXPORT QDeclarativeColorAnimation : public QDeclarativeProperty { Q_OBJECT Q_DECLARE_PRIVATE(QDeclarativePropertyAnimation) - Q_PROPERTY(QColor from READ from WRITE setFrom NOTIFY fromChanged) - Q_PROPERTY(QColor to READ to WRITE setTo NOTIFY toChanged) + Q_PROPERTY(QColor from READ from WRITE setFrom) + Q_PROPERTY(QColor to READ to WRITE setTo) public: QDeclarativeColorAnimation(QObject *parent=0); @@ -320,8 +320,8 @@ class Q_AUTOTEST_EXPORT QDeclarativeNumberAnimation : public QDeclarativePropert Q_OBJECT Q_DECLARE_PRIVATE(QDeclarativePropertyAnimation) - Q_PROPERTY(qreal from READ from WRITE setFrom NOTIFY fromChanged) - Q_PROPERTY(qreal to READ to WRITE setTo NOTIFY toChanged) + Q_PROPERTY(qreal from READ from WRITE setFrom) + Q_PROPERTY(qreal to READ to WRITE setTo) public: QDeclarativeNumberAnimation(QObject *parent=0); @@ -345,8 +345,8 @@ class Q_AUTOTEST_EXPORT QDeclarativeVector3dAnimation : public QDeclarativePrope Q_OBJECT Q_DECLARE_PRIVATE(QDeclarativePropertyAnimation) - Q_PROPERTY(QVector3D from READ from WRITE setFrom NOTIFY fromChanged) - Q_PROPERTY(QVector3D to READ to WRITE setTo NOTIFY toChanged) + Q_PROPERTY(QVector3D from READ from WRITE setFrom) + Q_PROPERTY(QVector3D to READ to WRITE setTo) public: QDeclarativeVector3dAnimation(QObject *parent=0); @@ -366,8 +366,8 @@ class Q_AUTOTEST_EXPORT QDeclarativeRotationAnimation : public QDeclarativePrope Q_DECLARE_PRIVATE(QDeclarativeRotationAnimation) Q_ENUMS(RotationDirection) - Q_PROPERTY(qreal from READ from WRITE setFrom NOTIFY fromChanged) - Q_PROPERTY(qreal to READ to WRITE setTo NOTIFY toChanged) + Q_PROPERTY(qreal from READ from WRITE setFrom) + Q_PROPERTY(qreal to READ to WRITE setTo) Q_PROPERTY(RotationDirection direction READ direction WRITE setDirection NOTIFY directionChanged) public: diff --git a/src/declarative/util/qdeclarativefontloader_p.h b/src/declarative/util/qdeclarativefontloader_p.h index 6947547..a5fbb8f 100644 --- a/src/declarative/util/qdeclarativefontloader_p.h +++ b/src/declarative/util/qdeclarativefontloader_p.h @@ -60,7 +60,7 @@ class Q_AUTOTEST_EXPORT QDeclarativeFontLoader : public QObject Q_DECLARE_PRIVATE(QDeclarativeFontLoader) Q_ENUMS(Status) - Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged) + Q_PROPERTY(QUrl source READ source WRITE setSource) Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) Q_PROPERTY(Status status READ status NOTIFY statusChanged) |