diff options
author | Christopher Ham <christopher.ham@nokia.com> | 2011-01-27 06:34:07 (GMT) |
---|---|---|
committer | Christopher Ham <christopher.ham@nokia.com> | 2011-01-27 06:41:07 (GMT) |
commit | aa40f956bab22678b62f630af97f51f9e8fab9f8 (patch) | |
tree | 1c06245f0bde3c0bb9e475d4d0f80fc7765263c1 /src/declarative/qml | |
parent | 80f74d3801ddece4d34b4a663bf1bdc23ecc4a67 (diff) | |
download | Qt-aa40f956bab22678b62f630af97f51f9e8fab9f8.zip Qt-aa40f956bab22678b62f630af97f51f9e8fab9f8.tar.gz Qt-aa40f956bab22678b62f630af97f51f9e8fab9f8.tar.bz2 |
Fix righ-to-left support in text components.
In text, textEdit and textInput, the layout of the text should
automatically align to the right if the it is deemed to be
right-to-left text.
Task-number: QTBUG-15880
Reviewed-by: Bea Lam
Diffstat (limited to 'src/declarative/qml')
-rw-r--r-- | src/declarative/qml/qdeclarativecomponent.cpp | 67 | ||||
-rw-r--r-- | src/declarative/qml/qdeclarativecomponent.h | 1 | ||||
-rw-r--r-- | src/declarative/qml/qdeclarativecomponent_p.h | 2 |
3 files changed, 57 insertions, 13 deletions
diff --git a/src/declarative/qml/qdeclarativecomponent.cpp b/src/declarative/qml/qdeclarativecomponent.cpp index 8865ddd..bd6e2d8 100644 --- a/src/declarative/qml/qdeclarativecomponent.cpp +++ b/src/declarative/qml/qdeclarativecomponent.cpp @@ -54,11 +54,13 @@ #include "private/qdeclarativescriptparser_p.h" #include "private/qdeclarativedebugtrace_p.h" #include "private/qdeclarativeenginedebug_p.h" +#include <QtScript/qscriptvalueiterator.h> #include <QStack> #include <QStringList> #include <QtCore/qdebug.h> #include <QApplication> +#include <qdeclarativeinfo.h> QT_BEGIN_NAMESPACE @@ -613,7 +615,7 @@ QDeclarativeComponent::QDeclarativeComponent(QDeclarativeComponentPrivate &dd, Q } /*! - \qmlmethod object Component::createObject(Item parent) + \qmlmethod object Component::createObject(Item parent, Script valuemap = null) Creates and returns an object instance of this component that will have the given \a parent. Returns null if object creation fails. @@ -631,6 +633,12 @@ QDeclarativeComponent::QDeclarativeComponent(QDeclarativeComponentPrivate &dd, Q it is not destroyed by the garbage collector. This is regardless of Item.parent being set afterwards, since setting the Item parent does not change object ownership; only the graphical parent is changed. + Since QtQuick 1.1, a map of property values can be optionally passed to the method that applies values to the object's properties + before its creation is finalised. This will avoid binding issues that can occur when the object is + instantiated before property bindings have been set. For example: + + \code component.createObject(parent, {"x": 100, "y": 100, "specialProperty": someObject}); \endcode + Dynamically created instances can be deleted with the \c destroy() method. See \l {Dynamic Object Management in QML} for more information. */ @@ -646,25 +654,46 @@ QDeclarativeComponent::QDeclarativeComponent(QDeclarativeComponentPrivate &dd, Q QScriptValue QDeclarativeComponent::createObject(QObject* parent) { Q_D(QDeclarativeComponent); - QDeclarativeContext* ctxt = creationContext(); - if(!ctxt && d->engine) - ctxt = d->engine->rootContext(); + return d->createObject(parent, QScriptValue(QScriptValue::NullValue)); +} + +/*! + \internal + Overloadable method allows properties to be set during creation +*/ +QScriptValue QDeclarativeComponent::createObject(QObject* parent, const QScriptValue& valuemap) +{ + Q_D(QDeclarativeComponent); + + if (valuemap.isObject() && !valuemap.isArray()) { + qmlInfo(this) << tr("creatObject: value is not an object"); + return QScriptValue(QScriptValue::NullValue); + } + return d->createObject(parent, valuemap); +} + +QScriptValue QDeclarativeComponentPrivate::createObject(QObject *publicParent, const QScriptValue valuemap) +{ + Q_Q(QDeclarativeComponent); + QDeclarativeContext* ctxt = q->creationContext(); + if(!ctxt && engine) + ctxt = engine->rootContext(); if (!ctxt) return QScriptValue(QScriptValue::NullValue); - QObject* ret = beginCreate(ctxt); + QObject* ret = q->beginCreate(ctxt); if (!ret) { - completeCreate(); + q->completeCreate(); return QScriptValue(QScriptValue::NullValue); } - if (parent) { - ret->setParent(parent); + if (publicParent) { + ret->setParent(publicParent); QList<QDeclarativePrivate::AutoParentFunction> functions = QDeclarativeMetaType::parentFunctions(); bool needParent = false; for (int ii = 0; ii < functions.count(); ++ii) { - QDeclarativePrivate::AutoParentResult res = functions.at(ii)(ret, parent); + QDeclarativePrivate::AutoParentResult res = functions.at(ii)(ret, publicParent); if (res == QDeclarativePrivate::Parented) { needParent = false; break; @@ -673,14 +702,26 @@ QScriptValue QDeclarativeComponent::createObject(QObject* parent) } } - if (needParent) + if (needParent) qWarning("QDeclarativeComponent: Created graphical object was not placed in the graphics scene."); } - completeCreate(); - QDeclarativeEnginePrivate *priv = QDeclarativeEnginePrivate::get(d->engine); + QDeclarativeEnginePrivate *priv = QDeclarativeEnginePrivate::get(engine); QDeclarativeData::get(ret, true)->setImplicitDestructible(); - return priv->objectClass->newQObject(ret, QMetaType::QObjectStar); + QScriptValue newObject = priv->objectClass->newQObject(ret, QMetaType::QObjectStar); + + if (valuemap.isObject() && !valuemap.isArray()) { + //Iterate through and assign properties + QScriptValueIterator it(valuemap); + while (it.hasNext()) { + it.next(); + newObject.setProperty(it.name(), it.value(), QScriptValue::KeepExistingFlags); + } + } + + q->completeCreate(); + + return newObject; } /*! diff --git a/src/declarative/qml/qdeclarativecomponent.h b/src/declarative/qml/qdeclarativecomponent.h index 6f28f2e..3d318c3 100644 --- a/src/declarative/qml/qdeclarativecomponent.h +++ b/src/declarative/qml/qdeclarativecomponent.h @@ -110,6 +110,7 @@ Q_SIGNALS: protected: QDeclarativeComponent(QDeclarativeComponentPrivate &dd, QObject* parent); Q_INVOKABLE QScriptValue createObject(QObject* parent); + Q_INVOKABLE QScriptValue createObject(QObject* parent, const QScriptValue& valuemap); //XXX Versioning private: QDeclarativeComponent(QDeclarativeEngine *, QDeclarativeCompiledData *, int, int, QObject *parent); diff --git a/src/declarative/qml/qdeclarativecomponent_p.h b/src/declarative/qml/qdeclarativecomponent_p.h index 02a6ce8..f8bec2b 100644 --- a/src/declarative/qml/qdeclarativecomponent_p.h +++ b/src/declarative/qml/qdeclarativecomponent_p.h @@ -116,6 +116,8 @@ public: ConstructionState *state); static void complete(QDeclarativeEnginePrivate *enginePriv, ConstructionState *state); + QScriptValue createObject(QObject *publicParent, const QScriptValue valuemap); + QDeclarativeEngine *engine; QDeclarativeGuardedContextData creationContext; |