src/declarative/qml/qdeclarativedom.cpp
changeset 30 5dc02b23752f
child 33 3e2da88830cd
equal deleted inserted replaced
29:b72c6db6890b 30:5dc02b23752f
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the QtDeclarative module of the Qt Toolkit.
       
     8 **
       
     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
       
    14 ** this package.
       
    15 **
       
    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.
       
    23 **
       
    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.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 
       
    42 #include "private/qdeclarativedom_p.h"
       
    43 #include "private/qdeclarativedom_p_p.h"
       
    44 
       
    45 #include "private/qdeclarativecompositetypedata_p.h"
       
    46 #include "private/qdeclarativecompiler_p.h"
       
    47 #include "private/qdeclarativeengine_p.h"
       
    48 #include "private/qdeclarativescriptparser_p.h"
       
    49 #include "private/qdeclarativeglobal_p.h"
       
    50 
       
    51 #include <QtCore/QByteArray>
       
    52 #include <QtCore/QDebug>
       
    53 #include <QtCore/QString>
       
    54 
       
    55 QT_BEGIN_NAMESPACE
       
    56 
       
    57 QDeclarativeDomDocumentPrivate::QDeclarativeDomDocumentPrivate()
       
    58 : root(0)
       
    59 {
       
    60 }
       
    61 
       
    62 QDeclarativeDomDocumentPrivate::~QDeclarativeDomDocumentPrivate()
       
    63 {
       
    64     if (root) root->release();
       
    65 }
       
    66 
       
    67 /*!
       
    68     \class QDeclarativeDomDocument
       
    69     \internal
       
    70     \brief The QDeclarativeDomDocument class represents the root of a QML document
       
    71 
       
    72     A QML document is a self-contained snippet of QML, usually contained in a
       
    73     single file. Each document has a root object, accessible through
       
    74     QDeclarativeDomDocument::rootObject().
       
    75 
       
    76     The QDeclarativeDomDocument class allows the programmer to inspect a QML document by
       
    77     calling QDeclarativeDomDocument::load().
       
    78 
       
    79     The following example loads a QML file from disk, and prints out its root
       
    80     object type and the properties assigned in the root object.
       
    81     \code
       
    82     QFile file(inputFileName);
       
    83     file.open(QIODevice::ReadOnly);
       
    84     QByteArray xmlData = file.readAll();
       
    85 
       
    86     QDeclarativeDomDocument document;
       
    87     document.load(qmlengine, xmlData);
       
    88 
       
    89     QDeclarativeDomObject rootObject = document.rootObject();
       
    90     qDebug() << rootObject.objectType();
       
    91     foreach(QDeclarativeDomProperty property, rootObject.properties())
       
    92         qDebug() << property.propertyName();
       
    93     \endcode
       
    94 */
       
    95 
       
    96 /*!
       
    97     Construct an empty QDeclarativeDomDocument.
       
    98 */
       
    99 QDeclarativeDomDocument::QDeclarativeDomDocument()
       
   100 : d(new QDeclarativeDomDocumentPrivate)
       
   101 {
       
   102 }
       
   103 
       
   104 /*!
       
   105     Create a copy of \a other QDeclarativeDomDocument.
       
   106 */
       
   107 QDeclarativeDomDocument::QDeclarativeDomDocument(const QDeclarativeDomDocument &other)
       
   108 : d(other.d)
       
   109 {
       
   110 }
       
   111 
       
   112 /*!
       
   113     Destroy the QDeclarativeDomDocument
       
   114 */
       
   115 QDeclarativeDomDocument::~QDeclarativeDomDocument()
       
   116 {
       
   117 }
       
   118 
       
   119 /*!
       
   120     Assign \a other to this QDeclarativeDomDocument.
       
   121 */
       
   122 QDeclarativeDomDocument &QDeclarativeDomDocument::operator=(const QDeclarativeDomDocument &other)
       
   123 {
       
   124     d = other.d;
       
   125     return *this;
       
   126 }
       
   127 
       
   128 /*!
       
   129     Returns all import statements in qml.
       
   130 */
       
   131 QList<QDeclarativeDomImport> QDeclarativeDomDocument::imports() const
       
   132 {
       
   133     return d->imports;
       
   134 }
       
   135 
       
   136 /*!
       
   137     Loads a QDeclarativeDomDocument from \a data.  \a data should be valid QML
       
   138     data.  On success, true is returned.  If the \a data is malformed, false
       
   139     is returned and QDeclarativeDomDocument::errors() contains an error description.
       
   140 
       
   141     \sa QDeclarativeDomDocument::loadError()
       
   142 */
       
   143 bool QDeclarativeDomDocument::load(QDeclarativeEngine *engine, const QByteArray &data, const QUrl &url)
       
   144 {
       
   145     d->errors.clear();
       
   146     d->imports.clear();
       
   147 
       
   148     QDeclarativeCompiledData *component = new QDeclarativeCompiledData(engine);
       
   149     QDeclarativeCompiler compiler;
       
   150 
       
   151     QDeclarativeCompositeTypeData *td = ((QDeclarativeEnginePrivate *)QDeclarativeEnginePrivate::get(engine))->typeManager.getImmediate(data, url);
       
   152 
       
   153     if(td->status == QDeclarativeCompositeTypeData::Error) {
       
   154         d->errors = td->errors;
       
   155         td->release();
       
   156         component->release();
       
   157         return false;
       
   158     } else if(td->status == QDeclarativeCompositeTypeData::Waiting ||
       
   159               td->status == QDeclarativeCompositeTypeData::WaitingResources) {
       
   160         QDeclarativeError error;
       
   161         error.setDescription(QLatin1String("QDeclarativeDomDocument supports local types only"));
       
   162         d->errors << error;
       
   163         td->release();
       
   164         component->release();
       
   165         return false;
       
   166     }
       
   167 
       
   168     compiler.compile(engine, td, component);
       
   169 
       
   170     if (compiler.isError()) {
       
   171         d->errors = compiler.errors();
       
   172         td->release();
       
   173         component->release();
       
   174         return false;
       
   175     }
       
   176 
       
   177     for (int i = 0; i < td->data.imports().size(); ++i) {
       
   178         QDeclarativeScriptParser::Import parserImport = td->data.imports().at(i);
       
   179         QDeclarativeDomImport domImport;
       
   180         domImport.d->type = static_cast<QDeclarativeDomImportPrivate::Type>(parserImport.type);
       
   181         domImport.d->uri = parserImport.uri;
       
   182         domImport.d->qualifier = parserImport.qualifier;
       
   183         domImport.d->version = parserImport.version;
       
   184         d->imports += domImport;
       
   185     }
       
   186 
       
   187     if (td->data.tree()) {
       
   188         d->root = td->data.tree();
       
   189         d->root->addref();
       
   190     }
       
   191 
       
   192     component->release();
       
   193     return true;
       
   194 }
       
   195 
       
   196 /*!
       
   197     Returns the last load errors.  The load errors will be reset after a
       
   198     successful call to load().
       
   199 
       
   200     \sa load()
       
   201 */
       
   202 QList<QDeclarativeError> QDeclarativeDomDocument::errors() const
       
   203 {
       
   204     return d->errors;
       
   205 }
       
   206 
       
   207 /*!
       
   208     Returns the document's root object, or an invalid QDeclarativeDomObject if the
       
   209     document has no root.
       
   210 
       
   211     In the sample QML below, the root object will be the QDeclarativeItem type.
       
   212     \qml
       
   213 Item {
       
   214     Text {
       
   215         text: "Hello World"
       
   216     }
       
   217 }
       
   218     \endqml
       
   219 */
       
   220 QDeclarativeDomObject QDeclarativeDomDocument::rootObject() const
       
   221 {
       
   222     QDeclarativeDomObject rv;
       
   223     rv.d->object = d->root;
       
   224     if (rv.d->object) rv.d->object->addref();
       
   225     return rv;
       
   226 }
       
   227 
       
   228 QDeclarativeDomPropertyPrivate::QDeclarativeDomPropertyPrivate()
       
   229 : property(0)
       
   230 {
       
   231 }
       
   232 
       
   233 QDeclarativeDomPropertyPrivate::~QDeclarativeDomPropertyPrivate()
       
   234 {
       
   235     if (property) property->release();
       
   236 }
       
   237 
       
   238 QDeclarativeDomDynamicPropertyPrivate::QDeclarativeDomDynamicPropertyPrivate():
       
   239         valid(false)
       
   240 {
       
   241 }
       
   242 
       
   243 QDeclarativeDomDynamicPropertyPrivate::~QDeclarativeDomDynamicPropertyPrivate()
       
   244 {
       
   245     if (valid && property.defaultValue) property.defaultValue->release();
       
   246 }
       
   247 
       
   248 /*!
       
   249     \class QDeclarativeDomProperty
       
   250     \internal
       
   251     \brief The QDeclarativeDomProperty class represents one property assignment in the
       
   252     QML DOM tree
       
   253 
       
   254     Properties in QML can be assigned QML \l {QDeclarativeDomValue}{values}.
       
   255 
       
   256     \sa QDeclarativeDomObject
       
   257 */
       
   258 
       
   259 /*!
       
   260     Construct an invalid QDeclarativeDomProperty.
       
   261 */
       
   262 QDeclarativeDomProperty::QDeclarativeDomProperty()
       
   263 : d(new QDeclarativeDomPropertyPrivate)
       
   264 {
       
   265 }
       
   266 
       
   267 /*!
       
   268     Create a copy of \a other QDeclarativeDomProperty.
       
   269 */
       
   270 QDeclarativeDomProperty::QDeclarativeDomProperty(const QDeclarativeDomProperty &other)
       
   271 : d(other.d)
       
   272 {
       
   273 }
       
   274 
       
   275 /*!
       
   276     Destroy the QDeclarativeDomProperty.
       
   277 */
       
   278 QDeclarativeDomProperty::~QDeclarativeDomProperty()
       
   279 {
       
   280 }
       
   281 
       
   282 /*!
       
   283     Assign \a other to this QDeclarativeDomProperty.
       
   284 */
       
   285 QDeclarativeDomProperty &QDeclarativeDomProperty::operator=(const QDeclarativeDomProperty &other)
       
   286 {
       
   287     d = other.d;
       
   288     return *this;
       
   289 }
       
   290 
       
   291 /*!
       
   292     Returns true if this is a valid QDeclarativeDomProperty, false otherwise.
       
   293 */
       
   294 bool QDeclarativeDomProperty::isValid() const
       
   295 {
       
   296     return d->property != 0;
       
   297 }
       
   298 
       
   299 
       
   300 /*!
       
   301     Return the name of this property.
       
   302 
       
   303     \qml
       
   304 Text {
       
   305     x: 10
       
   306     y: 10
       
   307     font.bold: true
       
   308 }
       
   309     \endqml
       
   310 
       
   311     As illustrated above, a property name can be a simple string, such as "x" or
       
   312     "y", or a more complex "dot property", such as "font.bold".  In both cases
       
   313     the full name is returned ("x", "y" and "font.bold") by this method.
       
   314 
       
   315     For dot properties, a split version of the name can be accessed by calling
       
   316     QDeclarativeDomProperty::propertyNameParts().
       
   317 
       
   318     \sa QDeclarativeDomProperty::propertyNameParts()
       
   319 */
       
   320 QByteArray QDeclarativeDomProperty::propertyName() const
       
   321 {
       
   322     return d->propertyName;
       
   323 }
       
   324 
       
   325 /*!
       
   326     Return the name of this property, split into multiple parts in the case
       
   327     of dot properties.
       
   328 
       
   329     \qml
       
   330 Text {
       
   331     x: 10
       
   332     y: 10
       
   333     font.bold: true
       
   334 }
       
   335     \endqml
       
   336 
       
   337     For each of the properties shown above, this method would return ("x"),
       
   338     ("y") and ("font", "bold").
       
   339 
       
   340     \sa QDeclarativeDomProperty::propertyName()
       
   341 */
       
   342 QList<QByteArray> QDeclarativeDomProperty::propertyNameParts() const
       
   343 {
       
   344     if (d->propertyName.isEmpty()) return QList<QByteArray>();
       
   345     else return d->propertyName.split('.');
       
   346 }
       
   347 
       
   348 /*!
       
   349     Return true if this property is used as a default property in the QML
       
   350     document.
       
   351 
       
   352     \qml
       
   353 <Text text="hello"/>
       
   354 <Text>hello</Text>
       
   355     \endqml
       
   356 
       
   357     The above two examples return the same DOM tree, except that the second has
       
   358     the default property flag set on the text property.  Observe that whether
       
   359     or not a property has isDefaultProperty set is determined by how the
       
   360     property is used, and not only by whether the property is the types default
       
   361     property.
       
   362 */
       
   363 bool QDeclarativeDomProperty::isDefaultProperty() const
       
   364 {
       
   365     return d->property && d->property->isDefault;
       
   366 }
       
   367 
       
   368 /*!
       
   369     Returns the QDeclarativeDomValue that is assigned to this property, or an invalid
       
   370     QDeclarativeDomValue if no value is assigned.
       
   371 */
       
   372 QDeclarativeDomValue QDeclarativeDomProperty::value() const
       
   373 {
       
   374     QDeclarativeDomValue rv;
       
   375     if (d->property) {
       
   376         rv.d->property = d->property;
       
   377         if (d->property->values.count())
       
   378             rv.d->value = d->property->values.at(0);
       
   379         else
       
   380             rv.d->value = d->property->onValues.at(0);
       
   381         rv.d->property->addref();
       
   382         rv.d->value->addref();
       
   383     }
       
   384     return rv;
       
   385 }
       
   386 
       
   387 /*!
       
   388     Returns the position in the input data where the property ID startd, or -1 if
       
   389  the property is invalid.
       
   390 */
       
   391 int QDeclarativeDomProperty::position() const
       
   392 {
       
   393     if (d && d->property) {
       
   394         return d->property->location.range.offset;
       
   395     } else
       
   396         return -1;
       
   397 }
       
   398 
       
   399 /*!
       
   400     Returns the length in the input data from where the property ID started upto
       
   401  the end of it, or -1 if the property is invalid.
       
   402 */
       
   403 int QDeclarativeDomProperty::length() const
       
   404 {
       
   405     if (d && d->property)
       
   406         return d->property->location.range.length;
       
   407     else
       
   408         return -1;
       
   409 }
       
   410 
       
   411 /*!
       
   412     Construct an invalid QDeclarativeDomDynamicProperty.
       
   413 */
       
   414 QDeclarativeDomDynamicProperty::QDeclarativeDomDynamicProperty():
       
   415         d(new QDeclarativeDomDynamicPropertyPrivate)
       
   416 {
       
   417 }
       
   418 
       
   419 /*!
       
   420     Create a copy of \a other QDeclarativeDomDynamicProperty.
       
   421 */
       
   422 QDeclarativeDomDynamicProperty::QDeclarativeDomDynamicProperty(const QDeclarativeDomDynamicProperty &other):
       
   423         d(other.d)
       
   424 {
       
   425 }
       
   426 
       
   427 /*!
       
   428     Destroy the QDeclarativeDomDynamicProperty.
       
   429 */
       
   430 QDeclarativeDomDynamicProperty::~QDeclarativeDomDynamicProperty()
       
   431 {
       
   432 }
       
   433 
       
   434 /*!
       
   435     Assign \a other to this QDeclarativeDomDynamicProperty.
       
   436 */
       
   437 QDeclarativeDomDynamicProperty &QDeclarativeDomDynamicProperty::operator=(const QDeclarativeDomDynamicProperty &other)
       
   438 {
       
   439     d = other.d;
       
   440     return *this;
       
   441 }
       
   442 
       
   443 bool QDeclarativeDomDynamicProperty::isValid() const
       
   444 {
       
   445     return d && d->valid;
       
   446 }
       
   447 
       
   448 /*!
       
   449     Return the name of this dynamic property.
       
   450 
       
   451     \qml
       
   452 Item {
       
   453     property int count: 10;
       
   454 }
       
   455     \endqml
       
   456 
       
   457     As illustrated above, a dynamic property name can have a name and a
       
   458     default value ("10").
       
   459 */
       
   460 QByteArray QDeclarativeDomDynamicProperty::propertyName() const
       
   461 {
       
   462     if (isValid())
       
   463         return d->property.name;
       
   464     else
       
   465         return QByteArray();
       
   466 }
       
   467 
       
   468 /*!
       
   469    Returns the type of the dynamic property. Note that when the property is an
       
   470    alias property, this will return -1. Use QDeclarativeDomProperty::isAlias() to check
       
   471    if the property is an alias.
       
   472 */
       
   473 int QDeclarativeDomDynamicProperty::propertyType() const
       
   474 {
       
   475     if (isValid()) {
       
   476         switch (d->property.type) {
       
   477             case QDeclarativeParser::Object::DynamicProperty::Bool:
       
   478                 return QMetaType::type("bool");
       
   479 
       
   480             case QDeclarativeParser::Object::DynamicProperty::Color:
       
   481                 return QMetaType::type("QColor");
       
   482 
       
   483             case QDeclarativeParser::Object::DynamicProperty::Time:
       
   484                 return QMetaType::type("QTime");
       
   485 
       
   486             case QDeclarativeParser::Object::DynamicProperty::Date:
       
   487                 return QMetaType::type("QDate");
       
   488 
       
   489             case QDeclarativeParser::Object::DynamicProperty::DateTime:
       
   490                 return QMetaType::type("QDateTime");
       
   491 
       
   492             case QDeclarativeParser::Object::DynamicProperty::Int:
       
   493                 return QMetaType::type("int");
       
   494 
       
   495             case QDeclarativeParser::Object::DynamicProperty::Real:
       
   496                 return QMetaType::type("double");
       
   497 
       
   498             case QDeclarativeParser::Object::DynamicProperty::String:
       
   499                 return QMetaType::type("QString");
       
   500 
       
   501             case QDeclarativeParser::Object::DynamicProperty::Url:
       
   502                 return QMetaType::type("QUrl");
       
   503 
       
   504             case QDeclarativeParser::Object::DynamicProperty::Variant:
       
   505                 return QMetaType::type("QVariant");
       
   506 
       
   507             default:
       
   508                 break;
       
   509         }
       
   510     }
       
   511 
       
   512     return -1;
       
   513 }
       
   514 
       
   515 QByteArray QDeclarativeDomDynamicProperty::propertyTypeName() const
       
   516 {
       
   517     if (isValid())
       
   518         return d->property.customType;
       
   519 
       
   520     return QByteArray();
       
   521 }
       
   522 
       
   523 /*!
       
   524     Return true if this property is used as a default property in the QML
       
   525     document.
       
   526 
       
   527     \qml
       
   528 <Text text="hello"/>
       
   529 <Text>hello</Text>
       
   530     \endqml
       
   531 
       
   532     The above two examples return the same DOM tree, except that the second has
       
   533     the default property flag set on the text property.  Observe that whether
       
   534     or not a property has isDefaultProperty set is determined by how the
       
   535     property is used, and not only by whether the property is the types default
       
   536     property.
       
   537 */
       
   538 bool QDeclarativeDomDynamicProperty::isDefaultProperty() const
       
   539 {
       
   540     if (isValid())
       
   541         return d->property.isDefaultProperty;
       
   542     else
       
   543         return false;
       
   544 }
       
   545 
       
   546 /*!
       
   547     Returns the default value as a QDeclarativeDomProperty.
       
   548 */
       
   549 QDeclarativeDomProperty QDeclarativeDomDynamicProperty::defaultValue() const
       
   550 {
       
   551     QDeclarativeDomProperty rp;
       
   552 
       
   553     if (isValid() && d->property.defaultValue) {
       
   554         rp.d->property = d->property.defaultValue;
       
   555         rp.d->propertyName = propertyName();
       
   556         rp.d->property->addref();
       
   557     }
       
   558 
       
   559     return rp;
       
   560 }
       
   561 
       
   562 /*!
       
   563     Returns true if this dynamic property is an alias for another property,
       
   564     false otherwise.
       
   565 */
       
   566 bool QDeclarativeDomDynamicProperty::isAlias() const
       
   567 {
       
   568     if (isValid())
       
   569         return d->property.type == QDeclarativeParser::Object::DynamicProperty::Alias;
       
   570     else
       
   571         return false;
       
   572 }
       
   573 
       
   574 /*!
       
   575     Returns the position in the input data where the property ID startd, or 0 if
       
   576  the property is invalid.
       
   577 */
       
   578 int QDeclarativeDomDynamicProperty::position() const
       
   579 {
       
   580     if (isValid()) {
       
   581         return d->property.location.range.offset;
       
   582     } else
       
   583         return -1;
       
   584 }
       
   585 
       
   586 /*!
       
   587     Returns the length in the input data from where the property ID started upto
       
   588  the end of it, or 0 if the property is invalid.
       
   589 */
       
   590 int QDeclarativeDomDynamicProperty::length() const
       
   591 {
       
   592     if (isValid())
       
   593         return d->property.location.range.length;
       
   594     else
       
   595         return -1;
       
   596 }
       
   597 
       
   598 QDeclarativeDomObjectPrivate::QDeclarativeDomObjectPrivate()
       
   599 : object(0)
       
   600 {
       
   601 }
       
   602 
       
   603 QDeclarativeDomObjectPrivate::~QDeclarativeDomObjectPrivate()
       
   604 {
       
   605     if (object) object->release();
       
   606 }
       
   607 
       
   608 QDeclarativeDomObjectPrivate::Properties
       
   609 QDeclarativeDomObjectPrivate::properties() const
       
   610 {
       
   611     Properties rv;
       
   612 
       
   613     for (QHash<QByteArray, QDeclarativeParser::Property *>::ConstIterator iter =
       
   614             object->properties.begin();
       
   615             iter != object->properties.end();
       
   616             ++iter) {
       
   617 
       
   618         rv << properties(*iter);
       
   619 
       
   620     }
       
   621     return rv;
       
   622 }
       
   623 
       
   624 QDeclarativeDomObjectPrivate::Properties
       
   625 QDeclarativeDomObjectPrivate::properties(QDeclarativeParser::Property *property) const
       
   626 {
       
   627     Properties rv;
       
   628 
       
   629     if (property->value) {
       
   630 
       
   631         for (QHash<QByteArray, QDeclarativeParser::Property *>::ConstIterator iter =
       
   632                 property->value->properties.begin();
       
   633                 iter != property->value->properties.end();
       
   634                 ++iter) {
       
   635 
       
   636             rv << properties(*iter);
       
   637 
       
   638         }
       
   639 
       
   640         QByteArray name(property->name + '.');
       
   641         for (Properties::Iterator iter = rv.begin(); iter != rv.end(); ++iter)
       
   642             iter->second.prepend(name);
       
   643 
       
   644     } else {
       
   645         rv << qMakePair(property, property->name);
       
   646     }
       
   647 
       
   648     return rv;
       
   649 }
       
   650 
       
   651 /*!
       
   652     \class QDeclarativeDomObject
       
   653     \internal
       
   654     \brief The QDeclarativeDomObject class represents an object instantiation.
       
   655 
       
   656     Each object instantiated in a QML file has a corresponding QDeclarativeDomObject
       
   657     node in the QML DOM.
       
   658 
       
   659     In addition to the type information that determines the object to
       
   660     instantiate, QDeclarativeDomObject's also have a set of associated QDeclarativeDomProperty's.
       
   661     Each QDeclarativeDomProperty represents a QML property assignment on the instantiated
       
   662     object.  For example,
       
   663 
       
   664     \qml
       
   665 QGraphicsWidget {
       
   666     opacity: 0.5
       
   667     size: "100x100"
       
   668 }
       
   669     \endqml
       
   670 
       
   671     describes a single QDeclarativeDomObject - "QGraphicsWidget" - with two properties,
       
   672     "opacity" and "size".  Obviously QGraphicsWidget has many more properties than just
       
   673     these two, but the QML DOM representation only contains those assigned
       
   674     values (or bindings) in the QML file.
       
   675 */
       
   676 
       
   677 /*!
       
   678     Construct an invalid QDeclarativeDomObject.
       
   679 */
       
   680 QDeclarativeDomObject::QDeclarativeDomObject()
       
   681 : d(new QDeclarativeDomObjectPrivate)
       
   682 {
       
   683 }
       
   684 
       
   685 /*!
       
   686     Create a copy of \a other QDeclarativeDomObject.
       
   687 */
       
   688 QDeclarativeDomObject::QDeclarativeDomObject(const QDeclarativeDomObject &other)
       
   689 : d(other.d)
       
   690 {
       
   691 }
       
   692 
       
   693 /*!
       
   694     Destroy the QDeclarativeDomObject.
       
   695 */
       
   696 QDeclarativeDomObject::~QDeclarativeDomObject()
       
   697 {
       
   698 }
       
   699 
       
   700 /*!
       
   701     Assign \a other to this QDeclarativeDomObject.
       
   702 */
       
   703 QDeclarativeDomObject &QDeclarativeDomObject::operator=(const QDeclarativeDomObject &other)
       
   704 {
       
   705     d = other.d;
       
   706     return *this;
       
   707 }
       
   708 
       
   709 /*!
       
   710     Returns true if this is a valid QDeclarativeDomObject, false otherwise.
       
   711 */
       
   712 bool QDeclarativeDomObject::isValid() const
       
   713 {
       
   714     return d->object != 0;
       
   715 }
       
   716 
       
   717 /*!
       
   718     Returns the fully-qualified type name of this object.
       
   719 
       
   720     For example, the type of this object would be "Qt/4.6/Rectangle".
       
   721     \qml
       
   722 Rectangle { }
       
   723     \endqml
       
   724 */
       
   725 QByteArray QDeclarativeDomObject::objectType() const
       
   726 {
       
   727     if (d->object) return d->object->typeName;
       
   728     else return QByteArray();
       
   729 }
       
   730 
       
   731 /*!
       
   732     Returns the type name as referenced in the qml file.
       
   733 
       
   734     For example, the type of this object would be "Rectangle".
       
   735     \qml
       
   736 Rectangle { }
       
   737     \endqml
       
   738 */
       
   739 QByteArray QDeclarativeDomObject::objectClassName() const
       
   740 {
       
   741     if (d->object)
       
   742         return d->object->className;
       
   743     else
       
   744         return QByteArray();
       
   745 }
       
   746 
       
   747 int QDeclarativeDomObject::objectTypeMajorVersion() const
       
   748 {
       
   749     if (d->object)
       
   750         return d->object->majorVersion;
       
   751     else
       
   752         return -1;
       
   753 }
       
   754 
       
   755 int QDeclarativeDomObject::objectTypeMinorVersion() const
       
   756 {
       
   757     if (d->object)
       
   758         return d->object->minorVersion;
       
   759     else
       
   760         return -1;
       
   761 }
       
   762 
       
   763 /*!
       
   764     Returns the QML id assigned to this object, or an empty QByteArray if no id
       
   765     has been assigned.
       
   766 
       
   767     For example, the object id of this object would be "MyText".
       
   768     \qml
       
   769 Text { id: myText }
       
   770     \endqml
       
   771 */
       
   772 QString QDeclarativeDomObject::objectId() const
       
   773 {
       
   774     if (d->object) {
       
   775         return d->object->id;
       
   776     } else {
       
   777         return QString();
       
   778     }
       
   779 }
       
   780 
       
   781 /*!
       
   782     Returns the list of assigned properties on this object.
       
   783 
       
   784     In the following example, "text" and "x" properties would be returned.
       
   785     \qml
       
   786 Text {
       
   787     text: "Hello world!"
       
   788     x: 100
       
   789 }
       
   790     \endqml
       
   791 */
       
   792 QList<QDeclarativeDomProperty> QDeclarativeDomObject::properties() const
       
   793 {
       
   794     QList<QDeclarativeDomProperty> rv;
       
   795 
       
   796     if (!d->object || isComponent())
       
   797         return rv;
       
   798 
       
   799     QDeclarativeDomObjectPrivate::Properties properties = d->properties();
       
   800     for (int ii = 0; ii < properties.count(); ++ii) {
       
   801 
       
   802         QDeclarativeDomProperty domProperty;
       
   803         domProperty.d->property = properties.at(ii).first;
       
   804         domProperty.d->property->addref();
       
   805         domProperty.d->propertyName = properties.at(ii).second;
       
   806         rv << domProperty;
       
   807 
       
   808     }
       
   809 
       
   810     if (d->object->defaultProperty) {
       
   811         QDeclarativeDomProperty domProperty;
       
   812         domProperty.d->property = d->object->defaultProperty;
       
   813         domProperty.d->property->addref();
       
   814         domProperty.d->propertyName = d->object->defaultProperty->name;
       
   815         rv << domProperty;
       
   816     }
       
   817 
       
   818     return rv;
       
   819 }
       
   820 
       
   821 /*!
       
   822     Returns the object's \a name property if a value has been assigned to
       
   823     it, or an invalid QDeclarativeDomProperty otherwise.
       
   824 
       
   825     In the example below, \c {object.property("source")} would return a valid
       
   826     QDeclarativeDomProperty, and \c {object.property("tile")} an invalid QDeclarativeDomProperty.
       
   827 
       
   828     \qml
       
   829 Image { source: "sample.jpg" }
       
   830     \endqml
       
   831 */
       
   832 QDeclarativeDomProperty QDeclarativeDomObject::property(const QByteArray &name) const
       
   833 {
       
   834     QList<QDeclarativeDomProperty> props = properties();
       
   835     for (int ii = 0; ii < props.count(); ++ii)
       
   836         if (props.at(ii).propertyName() == name)
       
   837             return props.at(ii);
       
   838     return QDeclarativeDomProperty();
       
   839 }
       
   840 
       
   841 QList<QDeclarativeDomDynamicProperty> QDeclarativeDomObject::dynamicProperties() const
       
   842 {
       
   843     QList<QDeclarativeDomDynamicProperty> properties;
       
   844 
       
   845     for (int i = 0; i < d->object->dynamicProperties.size(); ++i) {
       
   846         QDeclarativeDomDynamicProperty p;
       
   847         p.d = new QDeclarativeDomDynamicPropertyPrivate;
       
   848         p.d->property = d->object->dynamicProperties.at(i);
       
   849         p.d->valid = true;
       
   850 
       
   851         if (p.d->property.defaultValue)
       
   852             p.d->property.defaultValue->addref();
       
   853 
       
   854         properties.append(p);
       
   855     }
       
   856 
       
   857     return properties;
       
   858 }
       
   859 
       
   860 QDeclarativeDomDynamicProperty QDeclarativeDomObject::dynamicProperty(const QByteArray &name) const
       
   861 {
       
   862     QDeclarativeDomDynamicProperty p;
       
   863 
       
   864     if (!isValid())
       
   865         return p;
       
   866 
       
   867     for (int i = 0; i < d->object->dynamicProperties.size(); ++i) {
       
   868         if (d->object->dynamicProperties.at(i).name == name) {
       
   869             p.d = new QDeclarativeDomDynamicPropertyPrivate;
       
   870             p.d->property = d->object->dynamicProperties.at(i);
       
   871             if (p.d->property.defaultValue) p.d->property.defaultValue->addref();
       
   872             p.d->valid = true;
       
   873         }
       
   874     }
       
   875 
       
   876     return p;
       
   877 }
       
   878 
       
   879 /*!
       
   880     Returns true if this object is a custom type.  Custom types are special
       
   881     types that allow embeddeding non-QML data, such as SVG or HTML data,
       
   882     directly into QML files.
       
   883 
       
   884     \note Currently this method will always return false, and is a placekeeper
       
   885     for future functionality.
       
   886 
       
   887     \sa QDeclarativeDomObject::customTypeData()
       
   888 */
       
   889 bool QDeclarativeDomObject::isCustomType() const
       
   890 {
       
   891     return false;
       
   892 }
       
   893 
       
   894 /*!
       
   895     If this object represents a custom type, returns the data associated with
       
   896     the custom type, otherwise returns an empty QByteArray().
       
   897     QDeclarativeDomObject::isCustomType() can be used to check if this object represents
       
   898     a custom type.
       
   899 */
       
   900 QByteArray QDeclarativeDomObject::customTypeData() const
       
   901 {
       
   902     return QByteArray();
       
   903 }
       
   904 
       
   905 /*!
       
   906     Returns true if this object is a sub-component object.  Sub-component
       
   907     objects can be converted into QDeclarativeDomComponent instances by calling
       
   908     QDeclarativeDomObject::toComponent().
       
   909 
       
   910     \sa QDeclarativeDomObject::toComponent()
       
   911 */
       
   912 bool QDeclarativeDomObject::isComponent() const
       
   913 {
       
   914     return (d->object && d->object->typeName == "Qt/Component");
       
   915 }
       
   916 
       
   917 /*!
       
   918     Returns a QDeclarativeDomComponent for this object if it is a sub-component, or
       
   919     an invalid QDeclarativeDomComponent if not.  QDeclarativeDomObject::isComponent() can be used
       
   920     to check if this object represents a sub-component.
       
   921 
       
   922     \sa QDeclarativeDomObject::isComponent()
       
   923 */
       
   924 QDeclarativeDomComponent QDeclarativeDomObject::toComponent() const
       
   925 {
       
   926     QDeclarativeDomComponent rv;
       
   927     if (isComponent())
       
   928         rv.d = d;
       
   929     return rv;
       
   930 }
       
   931 
       
   932 /*!
       
   933     Returns the position in the input data where the property assignment started
       
   934 , or -1 if the property is invalid.
       
   935 */
       
   936 int QDeclarativeDomObject::position() const
       
   937 {
       
   938     if (d && d->object)
       
   939         return d->object->location.range.offset;
       
   940     else
       
   941         return -1;
       
   942 }
       
   943 
       
   944 /*!
       
   945     Returns the length in the input data from where the property assignment star
       
   946 ted upto the end of it, or -1 if the property is invalid.
       
   947 */
       
   948 int QDeclarativeDomObject::length() const
       
   949 {
       
   950     if (d && d->object)
       
   951         return d->object->location.range.length;
       
   952     else
       
   953         return -1;
       
   954 }
       
   955 
       
   956 // Returns the URL of the type, if it is an external type, or an empty URL if
       
   957 // not
       
   958 QUrl QDeclarativeDomObject::url() const
       
   959 {
       
   960     if (d && d->object)
       
   961         return d->object->url;
       
   962     else
       
   963         return QUrl();
       
   964 }
       
   965 
       
   966 QDeclarativeDomBasicValuePrivate::QDeclarativeDomBasicValuePrivate()
       
   967 : value(0)
       
   968 {
       
   969 }
       
   970 
       
   971 QDeclarativeDomBasicValuePrivate::~QDeclarativeDomBasicValuePrivate()
       
   972 {
       
   973     if (value) value->release();
       
   974 }
       
   975 
       
   976 /*!
       
   977     \class QDeclarativeDomValueLiteral
       
   978     \internal
       
   979     \brief The QDeclarativeDomValueLiteral class represents a literal value.
       
   980 
       
   981     A literal value is a simple value, written inline with the QML.  In the
       
   982     example below, the "x", "y" and "color" properties are being assigned
       
   983     literal values.
       
   984 
       
   985     \qml
       
   986 Rectangle {
       
   987     x: 10
       
   988     y: 10
       
   989     color: "red"
       
   990 }
       
   991     \endqml
       
   992 */
       
   993 
       
   994 /*!
       
   995     Construct an empty QDeclarativeDomValueLiteral.
       
   996 */
       
   997 QDeclarativeDomValueLiteral::QDeclarativeDomValueLiteral():
       
   998     d(new QDeclarativeDomBasicValuePrivate)
       
   999 {
       
  1000 }
       
  1001 
       
  1002 /*!
       
  1003     Create a copy of \a other QDeclarativeDomValueLiteral.
       
  1004 */
       
  1005 QDeclarativeDomValueLiteral::QDeclarativeDomValueLiteral(const QDeclarativeDomValueLiteral &other)
       
  1006 : d(other.d)
       
  1007 {
       
  1008 }
       
  1009 
       
  1010 /*!
       
  1011     Destroy the QDeclarativeDomValueLiteral.
       
  1012 */
       
  1013 QDeclarativeDomValueLiteral::~QDeclarativeDomValueLiteral()
       
  1014 {
       
  1015 }
       
  1016 
       
  1017 /*!
       
  1018     Assign \a other to this QDeclarativeDomValueLiteral.
       
  1019 */
       
  1020 QDeclarativeDomValueLiteral &QDeclarativeDomValueLiteral::operator=(const QDeclarativeDomValueLiteral &other)
       
  1021 {
       
  1022     d = other.d;
       
  1023     return *this;
       
  1024 }
       
  1025 
       
  1026 /*!
       
  1027     Return the literal value.
       
  1028 
       
  1029     In the example below, the literal value will be the string "10".
       
  1030     \qml
       
  1031 Rectangle { x: 10 }
       
  1032     \endqml
       
  1033 */
       
  1034 QString QDeclarativeDomValueLiteral::literal() const
       
  1035 {
       
  1036     if (d->value) return d->value->primitive();
       
  1037     else return QString();
       
  1038 }
       
  1039 
       
  1040 /*!
       
  1041     \class QDeclarativeDomValueBinding
       
  1042     \internal
       
  1043     \brief The QDeclarativeDomValueBinding class represents a property binding.
       
  1044 
       
  1045     A property binding is an ECMAScript expression assigned to a property.  In
       
  1046     the example below, the "x" property is being assigned a property binding.
       
  1047 
       
  1048     \qml
       
  1049 Rectangle { x: Other.x }
       
  1050     \endqml
       
  1051 */
       
  1052 
       
  1053 /*!
       
  1054     Construct an empty QDeclarativeDomValueBinding.
       
  1055 */
       
  1056 QDeclarativeDomValueBinding::QDeclarativeDomValueBinding():
       
  1057         d(new QDeclarativeDomBasicValuePrivate)
       
  1058 {
       
  1059 }
       
  1060 
       
  1061 /*!
       
  1062     Create a copy of \a other QDeclarativeDomValueBinding.
       
  1063 */
       
  1064 QDeclarativeDomValueBinding::QDeclarativeDomValueBinding(const QDeclarativeDomValueBinding &other)
       
  1065 : d(other.d)
       
  1066 {
       
  1067 }
       
  1068 
       
  1069 /*!
       
  1070     Destroy the QDeclarativeDomValueBinding.
       
  1071 */
       
  1072 QDeclarativeDomValueBinding::~QDeclarativeDomValueBinding()
       
  1073 {
       
  1074 }
       
  1075 
       
  1076 /*!
       
  1077     Assign \a other to this QDeclarativeDomValueBinding.
       
  1078 */
       
  1079 QDeclarativeDomValueBinding &QDeclarativeDomValueBinding::operator=(const QDeclarativeDomValueBinding &other)
       
  1080 {
       
  1081     d = other.d;
       
  1082     return *this;
       
  1083 }
       
  1084 
       
  1085 /*!
       
  1086     Return the binding expression.
       
  1087 
       
  1088     In the example below, the string "Other.x" will be returned.
       
  1089     \qml
       
  1090 Rectangle { x: Other.x }
       
  1091     \endqml
       
  1092 */
       
  1093 QString QDeclarativeDomValueBinding::binding() const
       
  1094 {
       
  1095     if (d->value)
       
  1096         return d->value->value.asScript();
       
  1097     else
       
  1098         return QString();
       
  1099 }
       
  1100 
       
  1101 /*!
       
  1102     \class QDeclarativeDomValueValueSource
       
  1103     \internal
       
  1104     \brief The QDeclarativeDomValueValueSource class represents a value source assignment value.
       
  1105 
       
  1106     In QML, value sources are special value generating types that may be
       
  1107     assigned to properties.  Value sources inherit the QDeclarativePropertyValueSource
       
  1108     class.  In the example below, the "x" property is being assigned the
       
  1109     NumberAnimation value source.
       
  1110 
       
  1111     \qml
       
  1112 Rectangle {
       
  1113     x: NumberAnimation {
       
  1114         from: 0
       
  1115         to: 100
       
  1116         loops: Animation.Infinite
       
  1117     }
       
  1118 }
       
  1119     \endqml
       
  1120 */
       
  1121 
       
  1122 /*!
       
  1123     Construct an empty QDeclarativeDomValueValueSource.
       
  1124 */
       
  1125 QDeclarativeDomValueValueSource::QDeclarativeDomValueValueSource():
       
  1126         d(new QDeclarativeDomBasicValuePrivate)
       
  1127 {
       
  1128 }
       
  1129 
       
  1130 /*!
       
  1131     Create a copy of \a other QDeclarativeDomValueValueSource.
       
  1132 */
       
  1133 QDeclarativeDomValueValueSource::QDeclarativeDomValueValueSource(const QDeclarativeDomValueValueSource &other)
       
  1134 : d(other.d)
       
  1135 {
       
  1136 }
       
  1137 
       
  1138 /*!
       
  1139     Destroy the QDeclarativeDomValueValueSource.
       
  1140 */
       
  1141 QDeclarativeDomValueValueSource::~QDeclarativeDomValueValueSource()
       
  1142 {
       
  1143 }
       
  1144 
       
  1145 /*!
       
  1146     Assign \a other to this QDeclarativeDomValueValueSource.
       
  1147 */
       
  1148 QDeclarativeDomValueValueSource &QDeclarativeDomValueValueSource::operator=(const QDeclarativeDomValueValueSource &other)
       
  1149 {
       
  1150     d = other.d;
       
  1151     return *this;
       
  1152 }
       
  1153 
       
  1154 /*!
       
  1155     Return the value source object.
       
  1156 
       
  1157     In the example below, an object representing the NumberAnimation will be
       
  1158     returned.
       
  1159     \qml
       
  1160 Rectangle {
       
  1161     x: NumberAnimation {
       
  1162         from: 0
       
  1163         to: 100
       
  1164         loops: Animation.Infinite
       
  1165     }
       
  1166 }
       
  1167     \endqml
       
  1168 */
       
  1169 QDeclarativeDomObject QDeclarativeDomValueValueSource::object() const
       
  1170 {
       
  1171     QDeclarativeDomObject rv;
       
  1172     if (d->value) {
       
  1173         rv.d->object = d->value->object;
       
  1174         rv.d->object->addref();
       
  1175     }
       
  1176     return rv;
       
  1177 }
       
  1178 
       
  1179 /*!
       
  1180     \class QDeclarativeDomValueValueInterceptor
       
  1181     \internal
       
  1182     \brief The QDeclarativeDomValueValueInterceptor class represents a value interceptor assignment value.
       
  1183 
       
  1184     In QML, value interceptor are special write-intercepting types that may be
       
  1185     assigned to properties.  Value interceptor inherit the QDeclarativePropertyValueInterceptor
       
  1186     class.  In the example below, the "x" property is being assigned the
       
  1187     Behavior value interceptor.
       
  1188 
       
  1189     \qml
       
  1190 Rectangle {
       
  1191     Behavior on x { NumberAnimation { duration: 500 } }
       
  1192 }
       
  1193     \endqml
       
  1194 */
       
  1195 
       
  1196 /*!
       
  1197     Construct an empty QDeclarativeDomValueValueInterceptor.
       
  1198 */
       
  1199 QDeclarativeDomValueValueInterceptor::QDeclarativeDomValueValueInterceptor():
       
  1200         d(new QDeclarativeDomBasicValuePrivate)
       
  1201 {
       
  1202 }
       
  1203 
       
  1204 /*!
       
  1205     Create a copy of \a other QDeclarativeDomValueValueInterceptor.
       
  1206 */
       
  1207 QDeclarativeDomValueValueInterceptor::QDeclarativeDomValueValueInterceptor(const QDeclarativeDomValueValueInterceptor &other)
       
  1208 : d(other.d)
       
  1209 {
       
  1210 }
       
  1211 
       
  1212 /*!
       
  1213     Destroy the QDeclarativeDomValueValueInterceptor.
       
  1214 */
       
  1215 QDeclarativeDomValueValueInterceptor::~QDeclarativeDomValueValueInterceptor()
       
  1216 {
       
  1217 }
       
  1218 
       
  1219 /*!
       
  1220     Assign \a other to this QDeclarativeDomValueValueInterceptor.
       
  1221 */
       
  1222 QDeclarativeDomValueValueInterceptor &QDeclarativeDomValueValueInterceptor::operator=(const QDeclarativeDomValueValueInterceptor &other)
       
  1223 {
       
  1224     d = other.d;
       
  1225     return *this;
       
  1226 }
       
  1227 
       
  1228 /*!
       
  1229     Return the value interceptor object.
       
  1230 
       
  1231     In the example below, an object representing the Behavior will be
       
  1232     returned.
       
  1233     \qml
       
  1234 Rectangle {
       
  1235     Behavior on x { NumberAnimation { duration: 500 } }
       
  1236 }
       
  1237     \endqml
       
  1238 */
       
  1239 QDeclarativeDomObject QDeclarativeDomValueValueInterceptor::object() const
       
  1240 {
       
  1241     QDeclarativeDomObject rv;
       
  1242     if (d->value) {
       
  1243         rv.d->object = d->value->object;
       
  1244         rv.d->object->addref();
       
  1245     }
       
  1246     return rv;
       
  1247 }
       
  1248 
       
  1249 QDeclarativeDomValuePrivate::QDeclarativeDomValuePrivate()
       
  1250 : property(0), value(0)
       
  1251 {
       
  1252 }
       
  1253 
       
  1254 QDeclarativeDomValuePrivate::~QDeclarativeDomValuePrivate()
       
  1255 {
       
  1256     if (property) property->release();
       
  1257     if (value) value->release();
       
  1258 }
       
  1259 
       
  1260 /*!
       
  1261     \class QDeclarativeDomValue
       
  1262     \internal
       
  1263     \brief The QDeclarativeDomValue class represents a generic Qml value.
       
  1264 
       
  1265     QDeclarativeDomValue's can be assigned to QML \l {QDeclarativeDomProperty}{properties}.  In
       
  1266     QML, properties can be assigned various different values, including basic
       
  1267     literals, property bindings, property value sources, objects and lists of
       
  1268     values.  The QDeclarativeDomValue class allows a programmer to determine the specific
       
  1269     value type being assigned and access more detailed information through a
       
  1270     corresponding value type class.
       
  1271 
       
  1272     For example, in the following example,
       
  1273 
       
  1274     \qml
       
  1275 Text {
       
  1276     text: "Hello World!"
       
  1277     y: Other.y
       
  1278 }
       
  1279     \endqml
       
  1280 
       
  1281     The text property is being assigned a literal, and the y property a property
       
  1282     binding.  To output the values assigned to the text and y properties in the
       
  1283     above example from C++,
       
  1284 
       
  1285     \code
       
  1286     QDeclarativeDomDocument document;
       
  1287     QDeclarativeDomObject root = document.rootObject();
       
  1288 
       
  1289     QDeclarativeDomProperty text = root.property("text");
       
  1290     if (text.value().isLiteral()) {
       
  1291         QDeclarativeDomValueLiteral literal = text.value().toLiteral();
       
  1292         qDebug() << literal.literal();
       
  1293     }
       
  1294 
       
  1295     QDeclarativeDomProperty y = root.property("y");
       
  1296     if (y.value().isBinding()) {
       
  1297         QDeclarativeDomValueBinding binding = y.value().toBinding();
       
  1298         qDebug() << binding.binding();
       
  1299     }
       
  1300     \endcode
       
  1301 */
       
  1302 
       
  1303 /*!
       
  1304     Construct an invalid QDeclarativeDomValue.
       
  1305 */
       
  1306 QDeclarativeDomValue::QDeclarativeDomValue()
       
  1307 : d(new QDeclarativeDomValuePrivate)
       
  1308 {
       
  1309 }
       
  1310 
       
  1311 /*!
       
  1312     Create a copy of \a other QDeclarativeDomValue.
       
  1313 */
       
  1314 QDeclarativeDomValue::QDeclarativeDomValue(const QDeclarativeDomValue &other)
       
  1315 : d(other.d)
       
  1316 {
       
  1317 }
       
  1318 
       
  1319 /*!
       
  1320     Destroy the QDeclarativeDomValue
       
  1321 */
       
  1322 QDeclarativeDomValue::~QDeclarativeDomValue()
       
  1323 {
       
  1324 }
       
  1325 
       
  1326 /*!
       
  1327     Assign \a other to this QDeclarativeDomValue.
       
  1328 */
       
  1329 QDeclarativeDomValue &QDeclarativeDomValue::operator=(const QDeclarativeDomValue &other)
       
  1330 {
       
  1331     d = other.d;
       
  1332     return *this;
       
  1333 }
       
  1334 
       
  1335 /*!
       
  1336     \enum QDeclarativeDomValue::Type
       
  1337 
       
  1338     The type of the QDeclarativeDomValue node.
       
  1339 
       
  1340     \value Invalid The QDeclarativeDomValue is invalid.
       
  1341     \value Literal The QDeclarativeDomValue is a literal value assignment.  Use QDeclarativeDomValue::toLiteral() to access the type instance.
       
  1342     \value PropertyBinding The QDeclarativeDomValue is a property binding.  Use QDeclarativeDomValue::toBinding() to access the type instance.
       
  1343     \value ValueSource The QDeclarativeDomValue is a property value source.  Use QDeclarativeDomValue::toValueSource() to access the type instance.
       
  1344     \value ValueInterceptor The QDeclarativeDomValue is a property value interceptor.  Use QDeclarativeDomValue::toValueInterceptor() to access the type instance.
       
  1345     \value Object The QDeclarativeDomValue is an object assignment.  Use QDeclarativeDomValue::toObject() to access the type instnace.
       
  1346     \value List The QDeclarativeDomValue is a list of other values.  Use QDeclarativeDomValue::toList() to access the type instance.
       
  1347 */
       
  1348 
       
  1349 /*!
       
  1350     Returns the type of this QDeclarativeDomValue.
       
  1351 */
       
  1352 QDeclarativeDomValue::Type QDeclarativeDomValue::type() const
       
  1353 {
       
  1354     if (d->property)
       
  1355         if (QDeclarativeMetaType::isList(d->property->type) ||
       
  1356            (d->property && (d->property->values.count() + d->property->onValues.count()) > 1))
       
  1357             return List;
       
  1358 
       
  1359     QDeclarativeParser::Value *value = d->value;
       
  1360     if (!value && !d->property)
       
  1361         return Invalid;
       
  1362 
       
  1363     switch(value->type) {
       
  1364     case QDeclarativeParser::Value::Unknown:
       
  1365         return Invalid;
       
  1366     case QDeclarativeParser::Value::Literal:
       
  1367         return Literal;
       
  1368     case QDeclarativeParser::Value::PropertyBinding:
       
  1369         return PropertyBinding;
       
  1370     case QDeclarativeParser::Value::ValueSource:
       
  1371         return ValueSource;
       
  1372     case QDeclarativeParser::Value::ValueInterceptor:
       
  1373         return ValueInterceptor;
       
  1374     case QDeclarativeParser::Value::CreatedObject:
       
  1375         return Object;
       
  1376     case QDeclarativeParser::Value::SignalObject:
       
  1377         return Invalid;
       
  1378     case QDeclarativeParser::Value::SignalExpression:
       
  1379         return Literal;
       
  1380     case QDeclarativeParser::Value::Id:
       
  1381         return Literal;
       
  1382     }
       
  1383     return Invalid;
       
  1384 }
       
  1385 
       
  1386 /*!
       
  1387     Returns true if this is an invalid value, otherwise false.
       
  1388 */
       
  1389 bool QDeclarativeDomValue::isInvalid() const
       
  1390 {
       
  1391     return type() == Invalid;
       
  1392 }
       
  1393 
       
  1394 /*!
       
  1395     Returns true if this is a literal value, otherwise false.
       
  1396 */
       
  1397 bool QDeclarativeDomValue::isLiteral() const
       
  1398 {
       
  1399     return type() == Literal;
       
  1400 }
       
  1401 
       
  1402 /*!
       
  1403     Returns true if this is a property binding value, otherwise false.
       
  1404 */
       
  1405 bool QDeclarativeDomValue::isBinding() const
       
  1406 {
       
  1407     return type() == PropertyBinding;
       
  1408 }
       
  1409 
       
  1410 /*!
       
  1411     Returns true if this is a value source value, otherwise false.
       
  1412 */
       
  1413 bool QDeclarativeDomValue::isValueSource() const
       
  1414 {
       
  1415     return type() == ValueSource;
       
  1416 }
       
  1417 
       
  1418 /*!
       
  1419     Returns true if this is a value interceptor value, otherwise false.
       
  1420 */
       
  1421 bool QDeclarativeDomValue::isValueInterceptor() const
       
  1422 {
       
  1423     return type() == ValueInterceptor;
       
  1424 }
       
  1425 
       
  1426 /*!
       
  1427     Returns true if this is an object value, otherwise false.
       
  1428 */
       
  1429 bool QDeclarativeDomValue::isObject() const
       
  1430 {
       
  1431     return type() == Object;
       
  1432 }
       
  1433 
       
  1434 /*!
       
  1435     Returns true if this is a list value, otherwise false.
       
  1436 */
       
  1437 bool QDeclarativeDomValue::isList() const
       
  1438 {
       
  1439     return type() == List;
       
  1440 }
       
  1441 
       
  1442 /*!
       
  1443     Returns a QDeclarativeDomValueLiteral if this value is a literal type, otherwise
       
  1444     returns an invalid QDeclarativeDomValueLiteral.
       
  1445 
       
  1446     \sa QDeclarativeDomValue::type()
       
  1447 */
       
  1448 QDeclarativeDomValueLiteral QDeclarativeDomValue::toLiteral() const
       
  1449 {
       
  1450     QDeclarativeDomValueLiteral rv;
       
  1451     if (type() == Literal) {
       
  1452         rv.d->value = d->value;
       
  1453         rv.d->value->addref();
       
  1454     }
       
  1455     return rv;
       
  1456 }
       
  1457 
       
  1458 /*!
       
  1459     Returns a QDeclarativeDomValueBinding if this value is a property binding type,
       
  1460     otherwise returns an invalid QDeclarativeDomValueBinding.
       
  1461 
       
  1462     \sa QDeclarativeDomValue::type()
       
  1463 */
       
  1464 QDeclarativeDomValueBinding QDeclarativeDomValue::toBinding() const
       
  1465 {
       
  1466     QDeclarativeDomValueBinding rv;
       
  1467     if (type() == PropertyBinding) {
       
  1468         rv.d->value = d->value;
       
  1469         rv.d->value->addref();
       
  1470     }
       
  1471     return rv;
       
  1472 }
       
  1473 
       
  1474 /*!
       
  1475     Returns a QDeclarativeDomValueValueSource if this value is a property value source
       
  1476     type, otherwise returns an invalid QDeclarativeDomValueValueSource.
       
  1477 
       
  1478     \sa QDeclarativeDomValue::type()
       
  1479 */
       
  1480 QDeclarativeDomValueValueSource QDeclarativeDomValue::toValueSource() const
       
  1481 {
       
  1482     QDeclarativeDomValueValueSource rv;
       
  1483     if (type() == ValueSource) {
       
  1484         rv.d->value = d->value;
       
  1485         rv.d->value->addref();
       
  1486     }
       
  1487     return rv;
       
  1488 }
       
  1489 
       
  1490 /*!
       
  1491     Returns a QDeclarativeDomValueValueInterceptor if this value is a property value interceptor
       
  1492     type, otherwise returns an invalid QDeclarativeDomValueValueInterceptor.
       
  1493 
       
  1494     \sa QDeclarativeDomValue::type()
       
  1495 */
       
  1496 QDeclarativeDomValueValueInterceptor QDeclarativeDomValue::toValueInterceptor() const
       
  1497 {
       
  1498     QDeclarativeDomValueValueInterceptor rv;
       
  1499     if (type() == ValueInterceptor) {
       
  1500         rv.d->value = d->value;
       
  1501         rv.d->value->addref();
       
  1502     }
       
  1503     return rv;
       
  1504 }
       
  1505 
       
  1506 /*!
       
  1507     Returns a QDeclarativeDomObject if this value is an object assignment type, otherwise
       
  1508     returns an invalid QDeclarativeDomObject.
       
  1509 
       
  1510     \sa QDeclarativeDomValue::type()
       
  1511 */
       
  1512 QDeclarativeDomObject QDeclarativeDomValue::toObject() const
       
  1513 {
       
  1514     QDeclarativeDomObject rv;
       
  1515     if (type() == Object) {
       
  1516         rv.d->object = d->value->object;
       
  1517         rv.d->object->addref();
       
  1518     }
       
  1519     return rv;
       
  1520 }
       
  1521 
       
  1522 /*!
       
  1523     Returns a QDeclarativeDomList if this value is a list type, otherwise returns an
       
  1524     invalid QDeclarativeDomList.
       
  1525 
       
  1526     \sa QDeclarativeDomValue::type()
       
  1527 */
       
  1528 QDeclarativeDomList QDeclarativeDomValue::toList() const
       
  1529 {
       
  1530     QDeclarativeDomList rv;
       
  1531     if (type() == List) {
       
  1532         rv.d = d;
       
  1533     }
       
  1534     return rv;
       
  1535 }
       
  1536 
       
  1537 /*!
       
  1538     Returns the position in the input data where the property value startd, or -1
       
  1539  if the value is invalid.
       
  1540 */
       
  1541 int QDeclarativeDomValue::position() const
       
  1542 {
       
  1543     if (type() == Invalid)
       
  1544         return -1;
       
  1545     else
       
  1546         return d->value->location.range.offset;
       
  1547 }
       
  1548 
       
  1549 /*!
       
  1550     Returns the length in the input data from where the property value started u
       
  1551 pto the end of it, or -1 if the value is invalid.
       
  1552 */
       
  1553 int QDeclarativeDomValue::length() const
       
  1554 {
       
  1555     if (type() == Invalid)
       
  1556         return -1;
       
  1557     else
       
  1558         return d->value->location.range.length;
       
  1559 }
       
  1560 
       
  1561 /*!
       
  1562     \class QDeclarativeDomList
       
  1563     \internal
       
  1564     \brief The QDeclarativeDomList class represents a list of values assigned to a QML property.
       
  1565 
       
  1566     Lists of values can be assigned to properties.  For example, the following
       
  1567     example assigns multiple objects to Item's "children" property
       
  1568     \qml
       
  1569 Item {
       
  1570     children: [
       
  1571         Text { },
       
  1572         Rectangle { }
       
  1573     ]
       
  1574 }
       
  1575     \endqml
       
  1576 
       
  1577     Lists can also be implicitly created by assigning multiple
       
  1578     \l {QDeclarativeDomValueValueSource}{value sources} or constants to a property.
       
  1579     \qml
       
  1580 Item {
       
  1581     x: 10
       
  1582     x: NumberAnimation {
       
  1583         running: false
       
  1584         from: 0
       
  1585         to: 100
       
  1586     }
       
  1587 }
       
  1588     \endqml
       
  1589 */
       
  1590 
       
  1591 /*!
       
  1592     Construct an empty QDeclarativeDomList.
       
  1593 */
       
  1594 QDeclarativeDomList::QDeclarativeDomList()
       
  1595 {
       
  1596 }
       
  1597 
       
  1598 /*!
       
  1599     Create a copy of \a other QDeclarativeDomList.
       
  1600 */
       
  1601 QDeclarativeDomList::QDeclarativeDomList(const QDeclarativeDomList &other)
       
  1602 : d(other.d)
       
  1603 {
       
  1604 }
       
  1605 
       
  1606 /*!
       
  1607     Destroy the QDeclarativeDomList.
       
  1608 */
       
  1609 QDeclarativeDomList::~QDeclarativeDomList()
       
  1610 {
       
  1611 }
       
  1612 
       
  1613 /*!
       
  1614     Assign \a other to this QDeclarativeDomList.
       
  1615 */
       
  1616 QDeclarativeDomList &QDeclarativeDomList::operator=(const QDeclarativeDomList &other)
       
  1617 {
       
  1618     d = other.d;
       
  1619     return *this;
       
  1620 }
       
  1621 
       
  1622 /*!
       
  1623     Returns the list of QDeclarativeDomValue's.
       
  1624 */
       
  1625 QList<QDeclarativeDomValue> QDeclarativeDomList::values() const
       
  1626 {
       
  1627     QList<QDeclarativeDomValue> rv;
       
  1628     if (!d->property)
       
  1629         return rv;
       
  1630 
       
  1631     for (int ii = 0; ii < d->property->values.count(); ++ii) {
       
  1632         QDeclarativeDomValue v;
       
  1633         v.d->value = d->property->values.at(ii);
       
  1634         v.d->value->addref();
       
  1635         rv << v;
       
  1636     }
       
  1637 
       
  1638     for (int ii = 0; ii < d->property->onValues.count(); ++ii) {
       
  1639         QDeclarativeDomValue v;
       
  1640         v.d->value = d->property->onValues.at(ii);
       
  1641         v.d->value->addref();
       
  1642         rv << v;
       
  1643     }
       
  1644 
       
  1645     return rv;
       
  1646 }
       
  1647 
       
  1648 /*!
       
  1649     Returns the position in the input data where the list started, or -1 if
       
  1650  the property is invalid.
       
  1651 */
       
  1652 int QDeclarativeDomList::position() const
       
  1653 {
       
  1654     if (d && d->property) {
       
  1655         return d->property->listValueRange.offset;
       
  1656     } else
       
  1657         return -1;
       
  1658 }
       
  1659 
       
  1660 /*!
       
  1661     Returns the length in the input data from where the list started upto
       
  1662  the end of it, or 0 if the property is invalid.
       
  1663 */
       
  1664 int QDeclarativeDomList::length() const
       
  1665 {
       
  1666     if (d && d->property)
       
  1667         return d->property->listValueRange.length;
       
  1668     else
       
  1669         return -1;
       
  1670 }
       
  1671 
       
  1672 /*!
       
  1673   Returns a list of positions of the commas in the QML file.
       
  1674 */
       
  1675 QList<int> QDeclarativeDomList:: commaPositions() const
       
  1676 {
       
  1677     if (d && d->property)
       
  1678         return d->property->listCommaPositions;
       
  1679     else
       
  1680         return QList<int>();
       
  1681 }
       
  1682 
       
  1683 /*!
       
  1684     \class QDeclarativeDomComponent
       
  1685     \internal
       
  1686     \brief The QDeclarativeDomComponent class represents sub-component within a QML document.
       
  1687 
       
  1688     Sub-components are QDeclarativeComponents defined within a QML document.  The
       
  1689     following example shows the definition of a sub-component with the id
       
  1690     "listDelegate".
       
  1691 
       
  1692     \qml
       
  1693 Item {
       
  1694     Component {
       
  1695         id: listDelegate
       
  1696         Text {
       
  1697             text: modelData.text
       
  1698         }
       
  1699     }
       
  1700 }
       
  1701     \endqml
       
  1702 
       
  1703     Like QDeclarativeDomDocument's, components contain a single root object.
       
  1704 */
       
  1705 
       
  1706 /*!
       
  1707     Construct an empty QDeclarativeDomComponent.
       
  1708 */
       
  1709 QDeclarativeDomComponent::QDeclarativeDomComponent()
       
  1710 {
       
  1711 }
       
  1712 
       
  1713 /*!
       
  1714     Create a copy of \a other QDeclarativeDomComponent.
       
  1715 */
       
  1716 QDeclarativeDomComponent::QDeclarativeDomComponent(const QDeclarativeDomComponent &other)
       
  1717 : QDeclarativeDomObject(other)
       
  1718 {
       
  1719 }
       
  1720 
       
  1721 /*!
       
  1722     Destroy the QDeclarativeDomComponent.
       
  1723 */
       
  1724 QDeclarativeDomComponent::~QDeclarativeDomComponent()
       
  1725 {
       
  1726 }
       
  1727 
       
  1728 /*!
       
  1729     Assign \a other to this QDeclarativeDomComponent.
       
  1730 */
       
  1731 QDeclarativeDomComponent &QDeclarativeDomComponent::operator=(const QDeclarativeDomComponent &other)
       
  1732 {
       
  1733     static_cast<QDeclarativeDomObject &>(*this) = other;
       
  1734     return *this;
       
  1735 }
       
  1736 
       
  1737 /*!
       
  1738     Returns the component's root object.
       
  1739 
       
  1740     In the example below, the root object is the "Text" object.
       
  1741     \qml
       
  1742 Item {
       
  1743     Component {
       
  1744         id: listDelegate
       
  1745         Text {
       
  1746             text: modelData.text
       
  1747         }
       
  1748     }
       
  1749 }
       
  1750     \endqml
       
  1751 */
       
  1752 QDeclarativeDomObject QDeclarativeDomComponent::componentRoot() const
       
  1753 {
       
  1754     QDeclarativeDomObject rv;
       
  1755     if (d->object) {
       
  1756         QDeclarativeParser::Object *obj = 0;
       
  1757         if (d->object->defaultProperty &&
       
  1758            d->object->defaultProperty->values.count() == 1 &&
       
  1759            d->object->defaultProperty->values.at(0)->object)
       
  1760             obj = d->object->defaultProperty->values.at(0)->object;
       
  1761 
       
  1762         if (obj) {
       
  1763             rv.d->object = obj;
       
  1764             rv.d->object->addref();
       
  1765         }
       
  1766     }
       
  1767 
       
  1768     return rv;
       
  1769 }
       
  1770 
       
  1771 QDeclarativeDomImportPrivate::QDeclarativeDomImportPrivate()
       
  1772 : type(File)
       
  1773 {
       
  1774 }
       
  1775 
       
  1776 QDeclarativeDomImportPrivate::~QDeclarativeDomImportPrivate()
       
  1777 {
       
  1778 }
       
  1779 
       
  1780 /*!
       
  1781     \class QDeclarativeDomImport
       
  1782     \internal
       
  1783     \brief The QDeclarativeDomImport class represents an import statement.
       
  1784 */
       
  1785 
       
  1786 /*!
       
  1787     Construct an empty QDeclarativeDomImport.
       
  1788 */
       
  1789 QDeclarativeDomImport::QDeclarativeDomImport()
       
  1790 : d(new QDeclarativeDomImportPrivate)
       
  1791 {
       
  1792 }
       
  1793 
       
  1794 /*!
       
  1795     Create a copy of \a other QDeclarativeDomImport.
       
  1796 */
       
  1797 QDeclarativeDomImport::QDeclarativeDomImport(const QDeclarativeDomImport &other)
       
  1798 : d(other.d)
       
  1799 {
       
  1800 }
       
  1801 
       
  1802 /*!
       
  1803     Destroy the QDeclarativeDomImport.
       
  1804 */
       
  1805 QDeclarativeDomImport::~QDeclarativeDomImport()
       
  1806 {
       
  1807 }
       
  1808 
       
  1809 /*!
       
  1810     Assign \a other to this QDeclarativeDomImport.
       
  1811 */
       
  1812 QDeclarativeDomImport &QDeclarativeDomImport::operator=(const QDeclarativeDomImport &other)
       
  1813 {
       
  1814     d = other.d;
       
  1815     return *this;
       
  1816 }
       
  1817 
       
  1818 /*!
       
  1819   Returns the type of the import.
       
  1820   */
       
  1821 QDeclarativeDomImport::Type QDeclarativeDomImport::type() const
       
  1822 {
       
  1823     return static_cast<QDeclarativeDomImport::Type>(d->type);
       
  1824 }
       
  1825 
       
  1826 /*!
       
  1827   Returns the URI of the import (e.g. 'subdir' or 'com.nokia.Qt')
       
  1828   */
       
  1829 QString QDeclarativeDomImport::uri() const
       
  1830 {
       
  1831     return d->uri;
       
  1832 }
       
  1833 
       
  1834 /*!
       
  1835   Returns the version specified by the import. An empty string if no version was specified.
       
  1836   */
       
  1837 QString QDeclarativeDomImport::version() const
       
  1838 {
       
  1839     return d->version;
       
  1840 }
       
  1841 
       
  1842 /*!
       
  1843   Returns the (optional) qualifier string (the token following the 'as' keyword) of the import.
       
  1844   */
       
  1845 QString QDeclarativeDomImport::qualifier() const
       
  1846 {
       
  1847     return d->qualifier;
       
  1848 }
       
  1849 
       
  1850 QT_END_NAMESPACE