1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the QtDeclarative module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** No Commercial Usage
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
16 ** GNU Lesser General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU Lesser
18 ** General Public License version 2.1 as published by the Free Software
19 ** Foundation and appearing in the file LICENSE.LGPL included in the
20 ** packaging of this file. Please review the following information to
21 ** ensure the GNU Lesser General Public License version 2.1 requirements
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 ** In addition, as a special exception, Nokia gives you certain additional
25 ** rights. These rights are described in the Nokia Qt LGPL Exception
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
40 ****************************************************************************/
42 #include "private/qdeclarativedom_p.h"
43 #include "private/qdeclarativedom_p_p.h"
45 #include "private/qdeclarativecompiler_p.h"
46 #include "private/qdeclarativeengine_p.h"
47 #include "private/qdeclarativescriptparser_p.h"
48 #include "private/qdeclarativeglobal_p.h"
50 #include <QtCore/QByteArray>
51 #include <QtCore/QDebug>
52 #include <QtCore/QString>
56 QDeclarativeDomDocumentPrivate::QDeclarativeDomDocumentPrivate()
61 QDeclarativeDomDocumentPrivate::~QDeclarativeDomDocumentPrivate()
63 if (root) root->release();
67 \class QDeclarativeDomDocument
69 \brief The QDeclarativeDomDocument class represents the root of a QML document
71 A QML document is a self-contained snippet of QML, usually contained in a
72 single file. Each document has a root object, accessible through
73 QDeclarativeDomDocument::rootObject().
75 The QDeclarativeDomDocument class allows the programmer to inspect a QML document by
76 calling QDeclarativeDomDocument::load().
78 The following example loads a QML file from disk, and prints out its root
79 object type and the properties assigned in the root object.
81 QFile file(inputFileName);
82 file.open(QIODevice::ReadOnly);
83 QByteArray xmlData = file.readAll();
85 QDeclarativeDomDocument document;
86 document.load(qmlengine, xmlData);
88 QDeclarativeDomObject rootObject = document.rootObject();
89 qDebug() << rootObject.objectType();
90 foreach(QDeclarativeDomProperty property, rootObject.properties())
91 qDebug() << property.propertyName();
96 Construct an empty QDeclarativeDomDocument.
98 QDeclarativeDomDocument::QDeclarativeDomDocument()
99 : d(new QDeclarativeDomDocumentPrivate)
104 Create a copy of \a other QDeclarativeDomDocument.
106 QDeclarativeDomDocument::QDeclarativeDomDocument(const QDeclarativeDomDocument &other)
112 Destroy the QDeclarativeDomDocument
114 QDeclarativeDomDocument::~QDeclarativeDomDocument()
119 Assign \a other to this QDeclarativeDomDocument.
121 QDeclarativeDomDocument &QDeclarativeDomDocument::operator=(const QDeclarativeDomDocument &other)
128 Returns all import statements in qml.
130 QList<QDeclarativeDomImport> QDeclarativeDomDocument::imports() const
136 Loads a QDeclarativeDomDocument from \a data. \a data should be valid QML
137 data. On success, true is returned. If the \a data is malformed, false
138 is returned and QDeclarativeDomDocument::errors() contains an error description.
140 \sa QDeclarativeDomDocument::loadError()
142 bool QDeclarativeDomDocument::load(QDeclarativeEngine *engine, const QByteArray &data, const QUrl &url)
147 QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(engine);
148 QDeclarativeTypeData *td = ep->typeLoader.get(data, url, QDeclarativeTypeLoader::PreserveParser);
151 d->errors = td->errors();
154 } else if(!td->isCompleteOrError()) {
155 QDeclarativeError error;
156 error.setDescription(QLatin1String("QDeclarativeDomDocument supports local types only"));
162 for (int i = 0; i < td->parser().imports().size(); ++i) {
163 QDeclarativeScriptParser::Import parserImport = td->parser().imports().at(i);
164 QDeclarativeDomImport domImport;
165 domImport.d->type = static_cast<QDeclarativeDomImportPrivate::Type>(parserImport.type);
166 domImport.d->uri = parserImport.uri;
167 domImport.d->qualifier = parserImport.qualifier;
168 domImport.d->version = parserImport.version;
169 d->imports += domImport;
172 if (td->parser().tree()) {
173 d->root = td->parser().tree();
182 Returns the last load errors. The load errors will be reset after a
183 successful call to load().
187 QList<QDeclarativeError> QDeclarativeDomDocument::errors() const
193 Returns the document's root object, or an invalid QDeclarativeDomObject if the
194 document has no root.
196 In the sample QML below, the root object will be the QDeclarativeItem type.
205 QDeclarativeDomObject QDeclarativeDomDocument::rootObject() const
207 QDeclarativeDomObject rv;
208 rv.d->object = d->root;
209 if (rv.d->object) rv.d->object->addref();
213 QDeclarativeDomPropertyPrivate::QDeclarativeDomPropertyPrivate()
218 QDeclarativeDomPropertyPrivate::~QDeclarativeDomPropertyPrivate()
220 if (property) property->release();
223 QDeclarativeDomDynamicPropertyPrivate::QDeclarativeDomDynamicPropertyPrivate():
228 QDeclarativeDomDynamicPropertyPrivate::~QDeclarativeDomDynamicPropertyPrivate()
230 if (valid && property.defaultValue) property.defaultValue->release();
234 \class QDeclarativeDomProperty
236 \brief The QDeclarativeDomProperty class represents one property assignment in the
239 Properties in QML can be assigned QML \l {QDeclarativeDomValue}{values}.
241 \sa QDeclarativeDomObject
245 Construct an invalid QDeclarativeDomProperty.
247 QDeclarativeDomProperty::QDeclarativeDomProperty()
248 : d(new QDeclarativeDomPropertyPrivate)
253 Create a copy of \a other QDeclarativeDomProperty.
255 QDeclarativeDomProperty::QDeclarativeDomProperty(const QDeclarativeDomProperty &other)
261 Destroy the QDeclarativeDomProperty.
263 QDeclarativeDomProperty::~QDeclarativeDomProperty()
268 Assign \a other to this QDeclarativeDomProperty.
270 QDeclarativeDomProperty &QDeclarativeDomProperty::operator=(const QDeclarativeDomProperty &other)
277 Returns true if this is a valid QDeclarativeDomProperty, false otherwise.
279 bool QDeclarativeDomProperty::isValid() const
281 return d->property != 0;
286 Return the name of this property.
296 As illustrated above, a property name can be a simple string, such as "x" or
297 "y", or a more complex "dot property", such as "font.bold". In both cases
298 the full name is returned ("x", "y" and "font.bold") by this method.
300 For dot properties, a split version of the name can be accessed by calling
301 QDeclarativeDomProperty::propertyNameParts().
303 \sa QDeclarativeDomProperty::propertyNameParts()
305 QByteArray QDeclarativeDomProperty::propertyName() const
307 return d->propertyName;
311 Return the name of this property, split into multiple parts in the case
322 For each of the properties shown above, this method would return ("x"),
323 ("y") and ("font", "bold").
325 \sa QDeclarativeDomProperty::propertyName()
327 QList<QByteArray> QDeclarativeDomProperty::propertyNameParts() const
329 if (d->propertyName.isEmpty()) return QList<QByteArray>();
330 else return d->propertyName.split('.');
334 Return true if this property is used as a default property in the QML
342 The above two examples return the same DOM tree, except that the second has
343 the default property flag set on the text property. Observe that whether
344 or not a property has isDefaultProperty set is determined by how the
345 property is used, and not only by whether the property is the types default
348 bool QDeclarativeDomProperty::isDefaultProperty() const
350 return d->property && d->property->isDefault;
354 Returns the QDeclarativeDomValue that is assigned to this property, or an invalid
355 QDeclarativeDomValue if no value is assigned.
357 QDeclarativeDomValue QDeclarativeDomProperty::value() const
359 QDeclarativeDomValue rv;
361 rv.d->property = d->property;
362 if (d->property->values.count())
363 rv.d->value = d->property->values.at(0);
365 rv.d->value = d->property->onValues.at(0);
366 rv.d->property->addref();
367 rv.d->value->addref();
373 Returns the position in the input data where the property ID startd, or -1 if
374 the property is invalid.
376 int QDeclarativeDomProperty::position() const
378 if (d && d->property) {
379 return d->property->location.range.offset;
385 Returns the length in the input data from where the property ID started upto
386 the end of it, or -1 if the property is invalid.
388 int QDeclarativeDomProperty::length() const
390 if (d && d->property)
391 return d->property->location.range.length;
397 Construct an invalid QDeclarativeDomDynamicProperty.
399 QDeclarativeDomDynamicProperty::QDeclarativeDomDynamicProperty():
400 d(new QDeclarativeDomDynamicPropertyPrivate)
405 Create a copy of \a other QDeclarativeDomDynamicProperty.
407 QDeclarativeDomDynamicProperty::QDeclarativeDomDynamicProperty(const QDeclarativeDomDynamicProperty &other):
413 Destroy the QDeclarativeDomDynamicProperty.
415 QDeclarativeDomDynamicProperty::~QDeclarativeDomDynamicProperty()
420 Assign \a other to this QDeclarativeDomDynamicProperty.
422 QDeclarativeDomDynamicProperty &QDeclarativeDomDynamicProperty::operator=(const QDeclarativeDomDynamicProperty &other)
428 bool QDeclarativeDomDynamicProperty::isValid() const
430 return d && d->valid;
434 Return the name of this dynamic property.
438 property int count: 10;
442 As illustrated above, a dynamic property name can have a name and a
443 default value ("10").
445 QByteArray QDeclarativeDomDynamicProperty::propertyName() const
448 return d->property.name;
454 Returns the type of the dynamic property. Note that when the property is an
455 alias property, this will return -1. Use QDeclarativeDomProperty::isAlias() to check
456 if the property is an alias.
458 int QDeclarativeDomDynamicProperty::propertyType() const
461 switch (d->property.type) {
462 case QDeclarativeParser::Object::DynamicProperty::Bool:
463 return QMetaType::type("bool");
465 case QDeclarativeParser::Object::DynamicProperty::Color:
466 return QMetaType::type("QColor");
468 case QDeclarativeParser::Object::DynamicProperty::Time:
469 return QMetaType::type("QTime");
471 case QDeclarativeParser::Object::DynamicProperty::Date:
472 return QMetaType::type("QDate");
474 case QDeclarativeParser::Object::DynamicProperty::DateTime:
475 return QMetaType::type("QDateTime");
477 case QDeclarativeParser::Object::DynamicProperty::Int:
478 return QMetaType::type("int");
480 case QDeclarativeParser::Object::DynamicProperty::Real:
481 return sizeof(qreal) == sizeof(double) ? QMetaType::type("double") : QMetaType::type("float");
483 case QDeclarativeParser::Object::DynamicProperty::String:
484 return QMetaType::type("QString");
486 case QDeclarativeParser::Object::DynamicProperty::Url:
487 return QMetaType::type("QUrl");
489 case QDeclarativeParser::Object::DynamicProperty::Variant:
490 return QMetaType::type("QVariant");
500 QByteArray QDeclarativeDomDynamicProperty::propertyTypeName() const
503 return d->property.customType;
509 Return true if this property is used as a default property in the QML
517 The above two examples return the same DOM tree, except that the second has
518 the default property flag set on the text property. Observe that whether
519 or not a property has isDefaultProperty set is determined by how the
520 property is used, and not only by whether the property is the types default
523 bool QDeclarativeDomDynamicProperty::isDefaultProperty() const
526 return d->property.isDefaultProperty;
532 Returns the default value as a QDeclarativeDomProperty.
534 QDeclarativeDomProperty QDeclarativeDomDynamicProperty::defaultValue() const
536 QDeclarativeDomProperty rp;
538 if (isValid() && d->property.defaultValue) {
539 rp.d->property = d->property.defaultValue;
540 rp.d->propertyName = propertyName();
541 rp.d->property->addref();
548 Returns true if this dynamic property is an alias for another property,
551 bool QDeclarativeDomDynamicProperty::isAlias() const
554 return d->property.type == QDeclarativeParser::Object::DynamicProperty::Alias;
560 Returns the position in the input data where the property ID startd, or 0 if
561 the property is invalid.
563 int QDeclarativeDomDynamicProperty::position() const
566 return d->property.location.range.offset;
572 Returns the length in the input data from where the property ID started upto
573 the end of it, or 0 if the property is invalid.
575 int QDeclarativeDomDynamicProperty::length() const
578 return d->property.location.range.length;
583 QDeclarativeDomObjectPrivate::QDeclarativeDomObjectPrivate()
588 QDeclarativeDomObjectPrivate::~QDeclarativeDomObjectPrivate()
590 if (object) object->release();
593 QDeclarativeDomObjectPrivate::Properties
594 QDeclarativeDomObjectPrivate::properties() const
598 for (QHash<QByteArray, QDeclarativeParser::Property *>::ConstIterator iter =
599 object->properties.begin();
600 iter != object->properties.end();
603 rv << properties(*iter);
609 QDeclarativeDomObjectPrivate::Properties
610 QDeclarativeDomObjectPrivate::properties(QDeclarativeParser::Property *property) const
614 if (property->value) {
616 for (QHash<QByteArray, QDeclarativeParser::Property *>::ConstIterator iter =
617 property->value->properties.begin();
618 iter != property->value->properties.end();
621 rv << properties(*iter);
625 QByteArray name(property->name + '.');
626 for (Properties::Iterator iter = rv.begin(); iter != rv.end(); ++iter)
627 iter->second.prepend(name);
630 rv << qMakePair(property, property->name);
637 \class QDeclarativeDomObject
639 \brief The QDeclarativeDomObject class represents an object instantiation.
641 Each object instantiated in a QML file has a corresponding QDeclarativeDomObject
644 In addition to the type information that determines the object to
645 instantiate, QDeclarativeDomObject's also have a set of associated QDeclarativeDomProperty's.
646 Each QDeclarativeDomProperty represents a QML property assignment on the instantiated
656 describes a single QDeclarativeDomObject - "QGraphicsWidget" - with two properties,
657 "opacity" and "size". Obviously QGraphicsWidget has many more properties than just
658 these two, but the QML DOM representation only contains those assigned
659 values (or bindings) in the QML file.
663 Construct an invalid QDeclarativeDomObject.
665 QDeclarativeDomObject::QDeclarativeDomObject()
666 : d(new QDeclarativeDomObjectPrivate)
671 Create a copy of \a other QDeclarativeDomObject.
673 QDeclarativeDomObject::QDeclarativeDomObject(const QDeclarativeDomObject &other)
679 Destroy the QDeclarativeDomObject.
681 QDeclarativeDomObject::~QDeclarativeDomObject()
686 Assign \a other to this QDeclarativeDomObject.
688 QDeclarativeDomObject &QDeclarativeDomObject::operator=(const QDeclarativeDomObject &other)
695 Returns true if this is a valid QDeclarativeDomObject, false otherwise.
697 bool QDeclarativeDomObject::isValid() const
699 return d->object != 0;
703 Returns the fully-qualified type name of this object.
705 For example, the type of this object would be "Qt/4.6/Rectangle".
710 QByteArray QDeclarativeDomObject::objectType() const
712 if (d->object) return d->object->typeName;
713 else return QByteArray();
717 Returns the type name as referenced in the qml file.
719 For example, the type of this object would be "Rectangle".
724 QByteArray QDeclarativeDomObject::objectClassName() const
727 return d->object->className;
732 int QDeclarativeDomObject::objectTypeMajorVersion() const
735 return d->object->majorVersion;
740 int QDeclarativeDomObject::objectTypeMinorVersion() const
743 return d->object->minorVersion;
749 Returns the QML id assigned to this object, or an empty QByteArray if no id
752 For example, the object id of this object would be "MyText".
757 QString QDeclarativeDomObject::objectId() const
760 return d->object->id;
767 Returns the list of assigned properties on this object.
769 In the following example, "text" and "x" properties would be returned.
777 QList<QDeclarativeDomProperty> QDeclarativeDomObject::properties() const
779 QList<QDeclarativeDomProperty> rv;
781 if (!d->object || isComponent())
784 QDeclarativeDomObjectPrivate::Properties properties = d->properties();
785 for (int ii = 0; ii < properties.count(); ++ii) {
787 QDeclarativeDomProperty domProperty;
788 domProperty.d->property = properties.at(ii).first;
789 domProperty.d->property->addref();
790 domProperty.d->propertyName = properties.at(ii).second;
795 if (d->object->defaultProperty) {
796 QDeclarativeDomProperty domProperty;
797 domProperty.d->property = d->object->defaultProperty;
798 domProperty.d->property->addref();
799 domProperty.d->propertyName = d->object->defaultProperty->name;
807 Returns the object's \a name property if a value has been assigned to
808 it, or an invalid QDeclarativeDomProperty otherwise.
810 In the example below, \c {object.property("source")} would return a valid
811 QDeclarativeDomProperty, and \c {object.property("tile")} an invalid QDeclarativeDomProperty.
814 Image { source: "sample.jpg" }
817 QDeclarativeDomProperty QDeclarativeDomObject::property(const QByteArray &name) const
819 QList<QDeclarativeDomProperty> props = properties();
820 for (int ii = 0; ii < props.count(); ++ii)
821 if (props.at(ii).propertyName() == name)
823 return QDeclarativeDomProperty();
826 QList<QDeclarativeDomDynamicProperty> QDeclarativeDomObject::dynamicProperties() const
828 QList<QDeclarativeDomDynamicProperty> properties;
830 for (int i = 0; i < d->object->dynamicProperties.size(); ++i) {
831 QDeclarativeDomDynamicProperty p;
832 p.d = new QDeclarativeDomDynamicPropertyPrivate;
833 p.d->property = d->object->dynamicProperties.at(i);
836 if (p.d->property.defaultValue)
837 p.d->property.defaultValue->addref();
839 properties.append(p);
845 QDeclarativeDomDynamicProperty QDeclarativeDomObject::dynamicProperty(const QByteArray &name) const
847 QDeclarativeDomDynamicProperty p;
852 for (int i = 0; i < d->object->dynamicProperties.size(); ++i) {
853 if (d->object->dynamicProperties.at(i).name == name) {
854 p.d = new QDeclarativeDomDynamicPropertyPrivate;
855 p.d->property = d->object->dynamicProperties.at(i);
856 if (p.d->property.defaultValue) p.d->property.defaultValue->addref();
865 Returns true if this object is a custom type. Custom types are special
866 types that allow embeddeding non-QML data, such as SVG or HTML data,
867 directly into QML files.
869 \note Currently this method will always return false, and is a placekeeper
870 for future functionality.
872 \sa QDeclarativeDomObject::customTypeData()
874 bool QDeclarativeDomObject::isCustomType() const
880 If this object represents a custom type, returns the data associated with
881 the custom type, otherwise returns an empty QByteArray().
882 QDeclarativeDomObject::isCustomType() can be used to check if this object represents
885 QByteArray QDeclarativeDomObject::customTypeData() const
891 Returns true if this object is a sub-component object. Sub-component
892 objects can be converted into QDeclarativeDomComponent instances by calling
893 QDeclarativeDomObject::toComponent().
895 \sa QDeclarativeDomObject::toComponent()
897 bool QDeclarativeDomObject::isComponent() const
899 return (d->object && (d->object->typeName == "Qt/Component" || d->object->typeName == "QtQuick/Component"));
903 Returns a QDeclarativeDomComponent for this object if it is a sub-component, or
904 an invalid QDeclarativeDomComponent if not. QDeclarativeDomObject::isComponent() can be used
905 to check if this object represents a sub-component.
907 \sa QDeclarativeDomObject::isComponent()
909 QDeclarativeDomComponent QDeclarativeDomObject::toComponent() const
911 QDeclarativeDomComponent rv;
918 Returns the position in the input data where the property assignment started
919 , or -1 if the property is invalid.
921 int QDeclarativeDomObject::position() const
924 return d->object->location.range.offset;
930 Returns the length in the input data from where the property assignment star
931 ted upto the end of it, or -1 if the property is invalid.
933 int QDeclarativeDomObject::length() const
936 return d->object->location.range.length;
941 // Returns the URL of the type, if it is an external type, or an empty URL if
943 QUrl QDeclarativeDomObject::url() const
946 return d->object->url;
951 QDeclarativeDomBasicValuePrivate::QDeclarativeDomBasicValuePrivate()
956 QDeclarativeDomBasicValuePrivate::~QDeclarativeDomBasicValuePrivate()
958 if (value) value->release();
962 \class QDeclarativeDomValueLiteral
964 \brief The QDeclarativeDomValueLiteral class represents a literal value.
966 A literal value is a simple value, written inline with the QML. In the
967 example below, the "x", "y" and "color" properties are being assigned
980 Construct an empty QDeclarativeDomValueLiteral.
982 QDeclarativeDomValueLiteral::QDeclarativeDomValueLiteral():
983 d(new QDeclarativeDomBasicValuePrivate)
988 Create a copy of \a other QDeclarativeDomValueLiteral.
990 QDeclarativeDomValueLiteral::QDeclarativeDomValueLiteral(const QDeclarativeDomValueLiteral &other)
996 Destroy the QDeclarativeDomValueLiteral.
998 QDeclarativeDomValueLiteral::~QDeclarativeDomValueLiteral()
1003 Assign \a other to this QDeclarativeDomValueLiteral.
1005 QDeclarativeDomValueLiteral &QDeclarativeDomValueLiteral::operator=(const QDeclarativeDomValueLiteral &other)
1012 Return the literal value.
1014 In the example below, the literal value will be the string "10".
1019 QString QDeclarativeDomValueLiteral::literal() const
1021 if (d->value) return d->value->primitive();
1022 else return QString();
1026 \class QDeclarativeDomValueBinding
1028 \brief The QDeclarativeDomValueBinding class represents a property binding.
1030 A property binding is an ECMAScript expression assigned to a property. In
1031 the example below, the "x" property is being assigned a property binding.
1034 Rectangle { x: Other.x }
1039 Construct an empty QDeclarativeDomValueBinding.
1041 QDeclarativeDomValueBinding::QDeclarativeDomValueBinding():
1042 d(new QDeclarativeDomBasicValuePrivate)
1047 Create a copy of \a other QDeclarativeDomValueBinding.
1049 QDeclarativeDomValueBinding::QDeclarativeDomValueBinding(const QDeclarativeDomValueBinding &other)
1055 Destroy the QDeclarativeDomValueBinding.
1057 QDeclarativeDomValueBinding::~QDeclarativeDomValueBinding()
1062 Assign \a other to this QDeclarativeDomValueBinding.
1064 QDeclarativeDomValueBinding &QDeclarativeDomValueBinding::operator=(const QDeclarativeDomValueBinding &other)
1071 Return the binding expression.
1073 In the example below, the string "Other.x" will be returned.
1075 Rectangle { x: Other.x }
1078 QString QDeclarativeDomValueBinding::binding() const
1081 return d->value->value.asScript();
1087 \class QDeclarativeDomValueValueSource
1089 \brief The QDeclarativeDomValueValueSource class represents a value source assignment value.
1091 In QML, value sources are special value generating types that may be
1092 assigned to properties. Value sources inherit the QDeclarativePropertyValueSource
1093 class. In the example below, the "x" property is being assigned the
1094 NumberAnimation value source.
1098 x: NumberAnimation {
1101 loops: Animation.Infinite
1108 Construct an empty QDeclarativeDomValueValueSource.
1110 QDeclarativeDomValueValueSource::QDeclarativeDomValueValueSource():
1111 d(new QDeclarativeDomBasicValuePrivate)
1116 Create a copy of \a other QDeclarativeDomValueValueSource.
1118 QDeclarativeDomValueValueSource::QDeclarativeDomValueValueSource(const QDeclarativeDomValueValueSource &other)
1124 Destroy the QDeclarativeDomValueValueSource.
1126 QDeclarativeDomValueValueSource::~QDeclarativeDomValueValueSource()
1131 Assign \a other to this QDeclarativeDomValueValueSource.
1133 QDeclarativeDomValueValueSource &QDeclarativeDomValueValueSource::operator=(const QDeclarativeDomValueValueSource &other)
1140 Return the value source object.
1142 In the example below, an object representing the NumberAnimation will be
1146 x: NumberAnimation {
1149 loops: Animation.Infinite
1154 QDeclarativeDomObject QDeclarativeDomValueValueSource::object() const
1156 QDeclarativeDomObject rv;
1158 rv.d->object = d->value->object;
1159 rv.d->object->addref();
1165 \class QDeclarativeDomValueValueInterceptor
1167 \brief The QDeclarativeDomValueValueInterceptor class represents a value interceptor assignment value.
1169 In QML, value interceptor are special write-intercepting types that may be
1170 assigned to properties. Value interceptor inherit the QDeclarativePropertyValueInterceptor
1171 class. In the example below, the "x" property is being assigned the
1172 Behavior value interceptor.
1176 Behavior on x { NumberAnimation { duration: 500 } }
1182 Construct an empty QDeclarativeDomValueValueInterceptor.
1184 QDeclarativeDomValueValueInterceptor::QDeclarativeDomValueValueInterceptor():
1185 d(new QDeclarativeDomBasicValuePrivate)
1190 Create a copy of \a other QDeclarativeDomValueValueInterceptor.
1192 QDeclarativeDomValueValueInterceptor::QDeclarativeDomValueValueInterceptor(const QDeclarativeDomValueValueInterceptor &other)
1198 Destroy the QDeclarativeDomValueValueInterceptor.
1200 QDeclarativeDomValueValueInterceptor::~QDeclarativeDomValueValueInterceptor()
1205 Assign \a other to this QDeclarativeDomValueValueInterceptor.
1207 QDeclarativeDomValueValueInterceptor &QDeclarativeDomValueValueInterceptor::operator=(const QDeclarativeDomValueValueInterceptor &other)
1214 Return the value interceptor object.
1216 In the example below, an object representing the Behavior will be
1220 Behavior on x { NumberAnimation { duration: 500 } }
1224 QDeclarativeDomObject QDeclarativeDomValueValueInterceptor::object() const
1226 QDeclarativeDomObject rv;
1228 rv.d->object = d->value->object;
1229 rv.d->object->addref();
1234 QDeclarativeDomValuePrivate::QDeclarativeDomValuePrivate()
1235 : property(0), value(0)
1239 QDeclarativeDomValuePrivate::~QDeclarativeDomValuePrivate()
1241 if (property) property->release();
1242 if (value) value->release();
1246 \class QDeclarativeDomValue
1248 \brief The QDeclarativeDomValue class represents a generic Qml value.
1250 QDeclarativeDomValue's can be assigned to QML \l {QDeclarativeDomProperty}{properties}. In
1251 QML, properties can be assigned various different values, including basic
1252 literals, property bindings, property value sources, objects and lists of
1253 values. The QDeclarativeDomValue class allows a programmer to determine the specific
1254 value type being assigned and access more detailed information through a
1255 corresponding value type class.
1257 For example, in the following example,
1261 text: "Hello World!"
1266 The text property is being assigned a literal, and the y property a property
1267 binding. To output the values assigned to the text and y properties in the
1268 above example from C++,
1271 QDeclarativeDomDocument document;
1272 QDeclarativeDomObject root = document.rootObject();
1274 QDeclarativeDomProperty text = root.property("text");
1275 if (text.value().isLiteral()) {
1276 QDeclarativeDomValueLiteral literal = text.value().toLiteral();
1277 qDebug() << literal.literal();
1280 QDeclarativeDomProperty y = root.property("y");
1281 if (y.value().isBinding()) {
1282 QDeclarativeDomValueBinding binding = y.value().toBinding();
1283 qDebug() << binding.binding();
1289 Construct an invalid QDeclarativeDomValue.
1291 QDeclarativeDomValue::QDeclarativeDomValue()
1292 : d(new QDeclarativeDomValuePrivate)
1297 Create a copy of \a other QDeclarativeDomValue.
1299 QDeclarativeDomValue::QDeclarativeDomValue(const QDeclarativeDomValue &other)
1305 Destroy the QDeclarativeDomValue
1307 QDeclarativeDomValue::~QDeclarativeDomValue()
1312 Assign \a other to this QDeclarativeDomValue.
1314 QDeclarativeDomValue &QDeclarativeDomValue::operator=(const QDeclarativeDomValue &other)
1321 \enum QDeclarativeDomValue::Type
1323 The type of the QDeclarativeDomValue node.
1325 \value Invalid The QDeclarativeDomValue is invalid.
1326 \value Literal The QDeclarativeDomValue is a literal value assignment. Use QDeclarativeDomValue::toLiteral() to access the type instance.
1327 \value PropertyBinding The QDeclarativeDomValue is a property binding. Use QDeclarativeDomValue::toBinding() to access the type instance.
1328 \value ValueSource The QDeclarativeDomValue is a property value source. Use QDeclarativeDomValue::toValueSource() to access the type instance.
1329 \value ValueInterceptor The QDeclarativeDomValue is a property value interceptor. Use QDeclarativeDomValue::toValueInterceptor() to access the type instance.
1330 \value Object The QDeclarativeDomValue is an object assignment. Use QDeclarativeDomValue::toObject() to access the type instnace.
1331 \value List The QDeclarativeDomValue is a list of other values. Use QDeclarativeDomValue::toList() to access the type instance.
1335 Returns the type of this QDeclarativeDomValue.
1337 QDeclarativeDomValue::Type QDeclarativeDomValue::type() const
1340 if (QDeclarativeMetaType::isList(d->property->type) ||
1341 (d->property && (d->property->values.count() + d->property->onValues.count()) > 1))
1344 QDeclarativeParser::Value *value = d->value;
1345 if (!value && !d->property)
1348 switch(value->type) {
1349 case QDeclarativeParser::Value::Unknown:
1351 case QDeclarativeParser::Value::Literal:
1353 case QDeclarativeParser::Value::PropertyBinding:
1354 return PropertyBinding;
1355 case QDeclarativeParser::Value::ValueSource:
1357 case QDeclarativeParser::Value::ValueInterceptor:
1358 return ValueInterceptor;
1359 case QDeclarativeParser::Value::CreatedObject:
1361 case QDeclarativeParser::Value::SignalObject:
1363 case QDeclarativeParser::Value::SignalExpression:
1365 case QDeclarativeParser::Value::Id:
1372 Returns true if this is an invalid value, otherwise false.
1374 bool QDeclarativeDomValue::isInvalid() const
1376 return type() == Invalid;
1380 Returns true if this is a literal value, otherwise false.
1382 bool QDeclarativeDomValue::isLiteral() const
1384 return type() == Literal;
1388 Returns true if this is a property binding value, otherwise false.
1390 bool QDeclarativeDomValue::isBinding() const
1392 return type() == PropertyBinding;
1396 Returns true if this is a value source value, otherwise false.
1398 bool QDeclarativeDomValue::isValueSource() const
1400 return type() == ValueSource;
1404 Returns true if this is a value interceptor value, otherwise false.
1406 bool QDeclarativeDomValue::isValueInterceptor() const
1408 return type() == ValueInterceptor;
1412 Returns true if this is an object value, otherwise false.
1414 bool QDeclarativeDomValue::isObject() const
1416 return type() == Object;
1420 Returns true if this is a list value, otherwise false.
1422 bool QDeclarativeDomValue::isList() const
1424 return type() == List;
1428 Returns a QDeclarativeDomValueLiteral if this value is a literal type, otherwise
1429 returns an invalid QDeclarativeDomValueLiteral.
1431 \sa QDeclarativeDomValue::type()
1433 QDeclarativeDomValueLiteral QDeclarativeDomValue::toLiteral() const
1435 QDeclarativeDomValueLiteral rv;
1436 if (type() == Literal) {
1437 rv.d->value = d->value;
1438 rv.d->value->addref();
1444 Returns a QDeclarativeDomValueBinding if this value is a property binding type,
1445 otherwise returns an invalid QDeclarativeDomValueBinding.
1447 \sa QDeclarativeDomValue::type()
1449 QDeclarativeDomValueBinding QDeclarativeDomValue::toBinding() const
1451 QDeclarativeDomValueBinding rv;
1452 if (type() == PropertyBinding) {
1453 rv.d->value = d->value;
1454 rv.d->value->addref();
1460 Returns a QDeclarativeDomValueValueSource if this value is a property value source
1461 type, otherwise returns an invalid QDeclarativeDomValueValueSource.
1463 \sa QDeclarativeDomValue::type()
1465 QDeclarativeDomValueValueSource QDeclarativeDomValue::toValueSource() const
1467 QDeclarativeDomValueValueSource rv;
1468 if (type() == ValueSource) {
1469 rv.d->value = d->value;
1470 rv.d->value->addref();
1476 Returns a QDeclarativeDomValueValueInterceptor if this value is a property value interceptor
1477 type, otherwise returns an invalid QDeclarativeDomValueValueInterceptor.
1479 \sa QDeclarativeDomValue::type()
1481 QDeclarativeDomValueValueInterceptor QDeclarativeDomValue::toValueInterceptor() const
1483 QDeclarativeDomValueValueInterceptor rv;
1484 if (type() == ValueInterceptor) {
1485 rv.d->value = d->value;
1486 rv.d->value->addref();
1492 Returns a QDeclarativeDomObject if this value is an object assignment type, otherwise
1493 returns an invalid QDeclarativeDomObject.
1495 \sa QDeclarativeDomValue::type()
1497 QDeclarativeDomObject QDeclarativeDomValue::toObject() const
1499 QDeclarativeDomObject rv;
1500 if (type() == Object) {
1501 rv.d->object = d->value->object;
1502 rv.d->object->addref();
1508 Returns a QDeclarativeDomList if this value is a list type, otherwise returns an
1509 invalid QDeclarativeDomList.
1511 \sa QDeclarativeDomValue::type()
1513 QDeclarativeDomList QDeclarativeDomValue::toList() const
1515 QDeclarativeDomList rv;
1516 if (type() == List) {
1523 Returns the position in the input data where the property value startd, or -1
1524 if the value is invalid.
1526 int QDeclarativeDomValue::position() const
1528 if (type() == Invalid)
1531 return d->value->location.range.offset;
1535 Returns the length in the input data from where the property value started u
1536 pto the end of it, or -1 if the value is invalid.
1538 int QDeclarativeDomValue::length() const
1540 if (type() == Invalid)
1543 return d->value->location.range.length;
1547 \class QDeclarativeDomList
1549 \brief The QDeclarativeDomList class represents a list of values assigned to a QML property.
1551 Lists of values can be assigned to properties. For example, the following
1552 example assigns multiple objects to Item's "children" property
1562 Lists can also be implicitly created by assigning multiple
1563 \l {QDeclarativeDomValueValueSource}{value sources} or constants to a property.
1567 x: NumberAnimation {
1577 Construct an empty QDeclarativeDomList.
1579 QDeclarativeDomList::QDeclarativeDomList()
1584 Create a copy of \a other QDeclarativeDomList.
1586 QDeclarativeDomList::QDeclarativeDomList(const QDeclarativeDomList &other)
1592 Destroy the QDeclarativeDomList.
1594 QDeclarativeDomList::~QDeclarativeDomList()
1599 Assign \a other to this QDeclarativeDomList.
1601 QDeclarativeDomList &QDeclarativeDomList::operator=(const QDeclarativeDomList &other)
1608 Returns the list of QDeclarativeDomValue's.
1610 QList<QDeclarativeDomValue> QDeclarativeDomList::values() const
1612 QList<QDeclarativeDomValue> rv;
1616 for (int ii = 0; ii < d->property->values.count(); ++ii) {
1617 QDeclarativeDomValue v;
1618 v.d->value = d->property->values.at(ii);
1619 v.d->value->addref();
1623 for (int ii = 0; ii < d->property->onValues.count(); ++ii) {
1624 QDeclarativeDomValue v;
1625 v.d->value = d->property->onValues.at(ii);
1626 v.d->value->addref();
1634 Returns the position in the input data where the list started, or -1 if
1635 the property is invalid.
1637 int QDeclarativeDomList::position() const
1639 if (d && d->property) {
1640 return d->property->listValueRange.offset;
1646 Returns the length in the input data from where the list started upto
1647 the end of it, or 0 if the property is invalid.
1649 int QDeclarativeDomList::length() const
1651 if (d && d->property)
1652 return d->property->listValueRange.length;
1658 Returns a list of positions of the commas in the QML file.
1660 QList<int> QDeclarativeDomList:: commaPositions() const
1662 if (d && d->property)
1663 return d->property->listCommaPositions;
1665 return QList<int>();
1669 \class QDeclarativeDomComponent
1671 \brief The QDeclarativeDomComponent class represents sub-component within a QML document.
1673 Sub-components are QDeclarativeComponents defined within a QML document. The
1674 following example shows the definition of a sub-component with the id
1682 text: modelData.text
1688 Like QDeclarativeDomDocument's, components contain a single root object.
1692 Construct an empty QDeclarativeDomComponent.
1694 QDeclarativeDomComponent::QDeclarativeDomComponent()
1699 Create a copy of \a other QDeclarativeDomComponent.
1701 QDeclarativeDomComponent::QDeclarativeDomComponent(const QDeclarativeDomComponent &other)
1702 : QDeclarativeDomObject(other)
1707 Destroy the QDeclarativeDomComponent.
1709 QDeclarativeDomComponent::~QDeclarativeDomComponent()
1714 Assign \a other to this QDeclarativeDomComponent.
1716 QDeclarativeDomComponent &QDeclarativeDomComponent::operator=(const QDeclarativeDomComponent &other)
1718 static_cast<QDeclarativeDomObject &>(*this) = other;
1723 Returns the component's root object.
1725 In the example below, the root object is the "Text" object.
1731 text: modelData.text
1737 QDeclarativeDomObject QDeclarativeDomComponent::componentRoot() const
1739 QDeclarativeDomObject rv;
1741 QDeclarativeParser::Object *obj = 0;
1742 if (d->object->defaultProperty &&
1743 d->object->defaultProperty->values.count() == 1 &&
1744 d->object->defaultProperty->values.at(0)->object)
1745 obj = d->object->defaultProperty->values.at(0)->object;
1749 rv.d->object->addref();
1756 QDeclarativeDomImportPrivate::QDeclarativeDomImportPrivate()
1761 QDeclarativeDomImportPrivate::~QDeclarativeDomImportPrivate()
1766 \class QDeclarativeDomImport
1768 \brief The QDeclarativeDomImport class represents an import statement.
1772 Construct an empty QDeclarativeDomImport.
1774 QDeclarativeDomImport::QDeclarativeDomImport()
1775 : d(new QDeclarativeDomImportPrivate)
1780 Create a copy of \a other QDeclarativeDomImport.
1782 QDeclarativeDomImport::QDeclarativeDomImport(const QDeclarativeDomImport &other)
1788 Destroy the QDeclarativeDomImport.
1790 QDeclarativeDomImport::~QDeclarativeDomImport()
1795 Assign \a other to this QDeclarativeDomImport.
1797 QDeclarativeDomImport &QDeclarativeDomImport::operator=(const QDeclarativeDomImport &other)
1804 Returns the type of the import.
1806 QDeclarativeDomImport::Type QDeclarativeDomImport::type() const
1808 return static_cast<QDeclarativeDomImport::Type>(d->type);
1812 Returns the URI of the import (e.g. 'subdir' or 'com.nokia.Qt')
1814 QString QDeclarativeDomImport::uri() const
1820 Returns the version specified by the import. An empty string if no version was specified.
1822 QString QDeclarativeDomImport::version() const
1828 Returns the (optional) qualifier string (the token following the 'as' keyword) of the import.
1830 QString QDeclarativeDomImport::qualifier() const
1832 return d->qualifier;