Qt 4.8
Public Functions | Properties | Friends | List of all members
QDeclarativeDomObject Class Reference

The QDeclarativeDomObject class represents an object instantiation. More...

#include <qdeclarativedom_p.h>

Inheritance diagram for QDeclarativeDomObject:
QDeclarativeDomComponent

Public Functions

QByteArray customTypeData () const
 If this object represents a custom type, returns the data associated with the custom type, otherwise returns an empty QByteArray(). More...
 
QList< QDeclarativeDomDynamicPropertydynamicProperties () const
 
QDeclarativeDomDynamicProperty dynamicProperty (const QByteArray &) const
 
bool isComponent () const
 Returns true if this object is a sub-component object. More...
 
bool isCustomType () const
 Returns true if this object is a custom type. More...
 
bool isValid () const
 Returns true if this is a valid QDeclarativeDomObject, false otherwise. More...
 
int length () const
 
Returns the length in the input data from where the property assignment star

ted upto the end of it, or -1 if the property is invalid. More...

 
QByteArray objectClassName () const
 Returns the type name as referenced in the qml file. More...
 
QString objectId () const
 Returns the QML id assigned to this object, or an empty QByteArray if no id has been assigned. More...
 
QByteArray objectType () const
 Returns the fully-qualified type name of this object. More...
 
int objectTypeMajorVersion () const
 
int objectTypeMinorVersion () const
 
QDeclarativeDomObjectoperator= (const QDeclarativeDomObject &)
 Assign other to this QDeclarativeDomObject. More...
 
int position () const
 
Returns the position in the input data where the property assignment started

, or -1 if the property is invalid. More...

 
QList< QDeclarativeDomPropertyproperties () const
 Returns the list of assigned properties on this object. More...
 
QDeclarativeDomProperty property (const QByteArray &) const
 Returns the object's name property if a value has been assigned to it, or an invalid QDeclarativeDomProperty otherwise. More...
 
 QDeclarativeDomObject ()
 Construct an invalid QDeclarativeDomObject. More...
 
 QDeclarativeDomObject (const QDeclarativeDomObject &)
 Create a copy of other QDeclarativeDomObject. More...
 
QDeclarativeDomComponent toComponent () const
 Returns a QDeclarativeDomComponent for this object if it is a sub-component, or an invalid QDeclarativeDomComponent if not. More...
 
QUrl url () const
 
 ~QDeclarativeDomObject ()
 Destroy the QDeclarativeDomObject. More...
 

Properties

QSharedDataPointer< QDeclarativeDomObjectPrivated
 

Friends

class QDeclarativeDomComponent
 
class QDeclarativeDomDocument
 
class QDeclarativeDomValue
 
class QDeclarativeDomValueValueInterceptor
 
class QDeclarativeDomValueValueSource
 

Detailed Description

The QDeclarativeDomObject class represents an object instantiation.

Warning
This function is not part of the public interface.
Each object instantiated in a QML file has a corresponding QDeclarativeDomObject
node in the QML DOM.

In addition to the type information that determines the object to
instantiate, QDeclarativeDomObject's also have a set of associated QDeclarativeDomProperty's.
Each QDeclarativeDomProperty represents a QML property assignment on the instantiated
object.  For example,
opacity: 0.5
size: "100x100"
}

describes a single QDeclarativeDomObject - "QGraphicsWidget" - with two properties, "opacity" and "size". Obviously QGraphicsWidget has many more properties than just these two, but the QML DOM representation only contains those assigned values (or bindings) in the QML file.

Definition at line 156 of file qdeclarativedom_p.h.

Constructors and Destructors

◆ QDeclarativeDomObject() [1/2]

QDeclarativeDomObject::QDeclarativeDomObject ( )

Construct an invalid QDeclarativeDomObject.

Definition at line 674 of file qdeclarativedom.cpp.

676 {
677 }
QSharedDataPointer< QDeclarativeDomObjectPrivate > d

◆ QDeclarativeDomObject() [2/2]

QDeclarativeDomObject::QDeclarativeDomObject ( const QDeclarativeDomObject other)

Create a copy of other QDeclarativeDomObject.

Definition at line 682 of file qdeclarativedom.cpp.

683 : d(other.d)
684 {
685 }
QSharedDataPointer< QDeclarativeDomObjectPrivate > d

◆ ~QDeclarativeDomObject()

QDeclarativeDomObject::~QDeclarativeDomObject ( )

Destroy the QDeclarativeDomObject.

Definition at line 690 of file qdeclarativedom.cpp.

691 {
692 }

Functions

◆ customTypeData()

QByteArray QDeclarativeDomObject::customTypeData ( ) const

If this object represents a custom type, returns the data associated with the custom type, otherwise returns an empty QByteArray().

QDeclarativeDomObject::isCustomType() can be used to check if this object represents a custom type.

Definition at line 894 of file qdeclarativedom.cpp.

895 {
896  return QByteArray();
897 }
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135

◆ dynamicProperties()

QList< QDeclarativeDomDynamicProperty > QDeclarativeDomObject::dynamicProperties ( ) const

Definition at line 835 of file qdeclarativedom.cpp.

836 {
838 
839  for (int i = 0; i < d->object->dynamicProperties.size(); ++i) {
842  p.d->property = d->object->dynamicProperties.at(i);
843  p.d->valid = true;
844 
845  if (p.d->property.defaultValue)
847 
848  properties.append(p);
849  }
850 
851  return properties;
852 }
QList< QDeclarativeDomProperty > properties() const
Returns the list of assigned properties on this object.
QDeclarativeParser::Object::DynamicProperty property
QDeclarativeParser::Object * object
QSharedDataPointer< QDeclarativeDomObjectPrivate > d
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
QList< DynamicProperty > dynamicProperties
QSharedDataPointer< QDeclarativeDomDynamicPropertyPrivate > d
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ dynamicProperty()

QDeclarativeDomDynamicProperty QDeclarativeDomObject::dynamicProperty ( const QByteArray name) const

Definition at line 854 of file qdeclarativedom.cpp.

855 {
857 
858  if (!isValid())
859  return p;
860 
861  for (int i = 0; i < d->object->dynamicProperties.size(); ++i) {
862  if (d->object->dynamicProperties.at(i).name == name) {
864  p.d->property = d->object->dynamicProperties.at(i);
866  p.d->valid = true;
867  }
868  }
869 
870  return p;
871 }
bool isValid() const
Returns true if this is a valid QDeclarativeDomObject, false otherwise.
QDeclarativeParser::Object::DynamicProperty property
QDeclarativeParser::Object * object
QSharedDataPointer< QDeclarativeDomObjectPrivate > d
QList< DynamicProperty > dynamicProperties
const char * name
QSharedDataPointer< QDeclarativeDomDynamicPropertyPrivate > d

◆ isComponent()

bool QDeclarativeDomObject::isComponent ( ) const

Returns true if this object is a sub-component object.

Sub-component objects can be converted into QDeclarativeDomComponent instances by calling QDeclarativeDomObject::toComponent().

See also
QDeclarativeDomObject::toComponent()

Definition at line 906 of file qdeclarativedom.cpp.

Referenced by properties(), and toComponent().

907 {
908  return (d->object && (d->object->typeName == "Qt/Component" || d->object->typeName == "QtQuick/Component"));
909 }
QDeclarativeParser::Object * object
QSharedDataPointer< QDeclarativeDomObjectPrivate > d

◆ isCustomType()

bool QDeclarativeDomObject::isCustomType ( ) const

Returns true if this object is a custom type.

Custom types are special types that allow embeddeding non-QML data, such as SVG or HTML data, directly into QML files.

Note
Currently this method will always return false, and is a placekeeper for future functionality.
See also
QDeclarativeDomObject::customTypeData()

Definition at line 883 of file qdeclarativedom.cpp.

884 {
885  return false;
886 }

◆ isValid()

bool QDeclarativeDomObject::isValid ( ) const

Returns true if this is a valid QDeclarativeDomObject, false otherwise.

Definition at line 706 of file qdeclarativedom.cpp.

Referenced by dynamicProperty().

707 {
708  return d->object != 0;
709 }
QDeclarativeParser::Object * object
QSharedDataPointer< QDeclarativeDomObjectPrivate > d

◆ length()

int QDeclarativeDomObject::length ( ) const

Returns the length in the input data from where the property assignment star

ted upto the end of it, or -1 if the property is invalid.

Definition at line 942 of file qdeclarativedom.cpp.

943 {
944  if (d && d->object)
945  return d->object->location.range.length;
946  else
947  return -1;
948 }
QDeclarativeParser::Object * object
QSharedDataPointer< QDeclarativeDomObjectPrivate > d

◆ objectClassName()

QByteArray QDeclarativeDomObject::objectClassName ( ) const

Returns the type name as referenced in the qml file.

For example, the type of this object would be "Rectangle".

Definition at line 733 of file qdeclarativedom.cpp.

734 {
735  if (d->object)
736  return d->object->className;
737  else
738  return QByteArray();
739 }
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
QDeclarativeParser::Object * object
QSharedDataPointer< QDeclarativeDomObjectPrivate > d

◆ objectId()

QString QDeclarativeDomObject::objectId ( ) const

Returns the QML id assigned to this object, or an empty QByteArray if no id has been assigned.

For example, the object id of this object would be "MyText".

Text { id: myText }

Definition at line 766 of file qdeclarativedom.cpp.

767 {
768  if (d->object) {
769  return d->object->id;
770  } else {
771  return QString();
772  }
773 }
The QString class provides a Unicode character string.
Definition: qstring.h:83
QDeclarativeParser::Object * object
QSharedDataPointer< QDeclarativeDomObjectPrivate > d

◆ objectType()

QByteArray QDeclarativeDomObject::objectType ( ) const

Returns the fully-qualified type name of this object.

For example, the type of this object would be "Qt/4.6/Rectangle".

Definition at line 719 of file qdeclarativedom.cpp.

720 {
721  if (d->object) return d->object->typeName;
722  else return QByteArray();
723 }
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
QDeclarativeParser::Object * object
QSharedDataPointer< QDeclarativeDomObjectPrivate > d

◆ objectTypeMajorVersion()

int QDeclarativeDomObject::objectTypeMajorVersion ( ) const

Definition at line 741 of file qdeclarativedom.cpp.

742 {
743  if (d->object)
744  return d->object->majorVersion;
745  else
746  return -1;
747 }
QDeclarativeParser::Object * object
QSharedDataPointer< QDeclarativeDomObjectPrivate > d

◆ objectTypeMinorVersion()

int QDeclarativeDomObject::objectTypeMinorVersion ( ) const

Definition at line 749 of file qdeclarativedom.cpp.

750 {
751  if (d->object)
752  return d->object->minorVersion;
753  else
754  return -1;
755 }
QDeclarativeParser::Object * object
QSharedDataPointer< QDeclarativeDomObjectPrivate > d

◆ operator=()

QDeclarativeDomObject & QDeclarativeDomObject::operator= ( const QDeclarativeDomObject other)

Assign other to this QDeclarativeDomObject.

Definition at line 697 of file qdeclarativedom.cpp.

698 {
699  d = other.d;
700  return *this;
701 }
QSharedDataPointer< QDeclarativeDomObjectPrivate > d

◆ position()

int QDeclarativeDomObject::position ( ) const

Returns the position in the input data where the property assignment started

, or -1 if the property is invalid.

Definition at line 930 of file qdeclarativedom.cpp.

931 {
932  if (d && d->object)
933  return d->object->location.range.offset;
934  else
935  return -1;
936 }
QDeclarativeParser::Object * object
QSharedDataPointer< QDeclarativeDomObjectPrivate > d

◆ properties()

QList< QDeclarativeDomProperty > QDeclarativeDomObject::properties ( ) const

Returns the list of assigned properties on this object.

In the following example, "text" and "x" properties would be returned.

text: "Hello world!"
x: 100
}

Definition at line 786 of file qdeclarativedom.cpp.

Referenced by dynamicProperties(), and property().

787 {
789 
790  if (!d->object || isComponent())
791  return rv;
792 
794  for (int ii = 0; ii < properties.count(); ++ii) {
795 
796  QDeclarativeDomProperty domProperty;
797  domProperty.d->property = properties.at(ii).first;
798  domProperty.d->property->addref();
799  domProperty.d->propertyName = properties.at(ii).second;
800  rv << domProperty;
801 
802  }
803 
804  if (d->object->defaultProperty) {
805  QDeclarativeDomProperty domProperty;
806  domProperty.d->property = d->object->defaultProperty;
807  domProperty.d->property->addref();
808  domProperty.d->propertyName = d->object->defaultProperty->name;
809  rv << domProperty;
810  }
811 
812  return rv;
813 }
The QDeclarativeDomProperty class represents one property assignment in the QML DOM tree...
QList< QDeclarativeDomProperty > properties() const
Returns the list of assigned properties on this object.
bool isComponent() const
Returns true if this object is a sub-component object.
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
QDeclarativeParser::Object * object
QSharedDataPointer< QDeclarativeDomObjectPrivate > d
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
QSharedDataPointer< QDeclarativeDomPropertyPrivate > d
QDeclarativeParser::Property * property
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ property()

QDeclarativeDomProperty QDeclarativeDomObject::property ( const QByteArray name) const

Returns the object's name property if a value has been assigned to it, or an invalid QDeclarativeDomProperty otherwise.

In the example below, {object.property("source")} would return a valid QDeclarativeDomProperty, and {object.property("tile")} an invalid QDeclarativeDomProperty.

Image { source: "sample.jpg" }

Definition at line 826 of file qdeclarativedom.cpp.

827 {
829  for (int ii = 0; ii < props.count(); ++ii)
830  if (props.at(ii).propertyName() == name)
831  return props.at(ii);
832  return QDeclarativeDomProperty();
833 }
The QDeclarativeDomProperty class represents one property assignment in the QML DOM tree...
QList< QDeclarativeDomProperty > properties() const
Returns the list of assigned properties on this object.
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
QByteArray propertyName() const
Return the name of this property.
const char * name
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ toComponent()

QDeclarativeDomComponent QDeclarativeDomObject::toComponent ( ) const

Returns a QDeclarativeDomComponent for this object if it is a sub-component, or an invalid QDeclarativeDomComponent if not.

QDeclarativeDomObject::isComponent() can be used to check if this object represents a sub-component.

See also
QDeclarativeDomObject::isComponent()

Definition at line 918 of file qdeclarativedom.cpp.

919 {
921  if (isComponent())
922  rv.d = d;
923  return rv;
924 }
bool isComponent() const
Returns true if this object is a sub-component object.
The QDeclarativeDomComponent class represents sub-component within a QML document.
QSharedDataPointer< QDeclarativeDomObjectPrivate > d

◆ url()

QUrl QDeclarativeDomObject::url ( ) const

Definition at line 952 of file qdeclarativedom.cpp.

953 {
954  if (d && d->object)
955  return d->object->url;
956  else
957  return QUrl();
958 }
The QUrl class provides a convenient interface for working with URLs.
Definition: qurl.h:61
QDeclarativeParser::Object * object
QSharedDataPointer< QDeclarativeDomObjectPrivate > d

Friends and Related Functions

◆ QDeclarativeDomComponent

Definition at line 192 of file qdeclarativedom_p.h.

◆ QDeclarativeDomDocument

Definition at line 191 of file qdeclarativedom_p.h.

◆ QDeclarativeDomValue

friend class QDeclarativeDomValue
friend

Definition at line 193 of file qdeclarativedom_p.h.

◆ QDeclarativeDomValueValueInterceptor

Definition at line 195 of file qdeclarativedom_p.h.

◆ QDeclarativeDomValueValueSource

Definition at line 194 of file qdeclarativedom_p.h.

Properties

◆ d

QSharedDataPointer<QDeclarativeDomObjectPrivate> QDeclarativeDomObject::d
private

The documentation for this class was generated from the following files: