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

The QDeclarativeListReference class allows the manipulation of QDeclarativeListProperty properties. More...

#include <qdeclarativelist.h>

Public Functions

bool append (QObject *) const
 Appends object to the list. More...
 
QObjectat (int) const
 Returns the list element at index, or 0 if the operation failed. More...
 
bool canAppend () const
 Returns true if the list property can be appended to, otherwise false. More...
 
bool canAt () const
 Returns true if the list property can queried by index, otherwise false. More...
 
bool canClear () const
 Returns true if the list property can be cleared, otherwise false. More...
 
bool canCount () const
 Returns true if the list property can be queried for its element count, otherwise false. More...
 
bool clear () const
 Clears the list. More...
 
int count () const
 Returns the number of objects in the list, or 0 if the operation failed. More...
 
bool isValid () const
 Returns true if the instance refers to a valid list property, otherwise false. More...
 
const QMetaObjectlistElementType () const
 Returns the QMetaObject for the elements stored in the list property. More...
 
QObjectobject () const
 Returns the list property's object. More...
 
QDeclarativeListReferenceoperator= (const QDeclarativeListReference &)
 
 QDeclarativeListReference ()
 Constructs an invalid instance. More...
 
 QDeclarativeListReference (QObject *, const char *property, QDeclarativeEngine *=0)
 Constructs a QDeclarativeListReference for object's property. More...
 
 QDeclarativeListReference (const QDeclarativeListReference &)
 
 ~QDeclarativeListReference ()
 

Properties

QDeclarativeListReferencePrivated
 

Friends

class QDeclarativeListReferencePrivate
 

Detailed Description

The QDeclarativeListReference class allows the manipulation of QDeclarativeListProperty properties.

Since
4.7 QtDeclarative

QDeclarativeListReference allows C++ programs to read from, and assign values to a QML list property in a simple and type safe way. A QDeclarativeListReference can be created by passing an object and property name or through a QDeclarativeProperty instance. These two are equivalant:

QDeclarativeListReference ref1(object, "children");
QDeclarativeProperty ref2(object, "children");

Not all QML list properties support all operations. A set of methods, canAppend(), canAt(), canClear() and canCount() allow programs to query whether an operation is supported on a given property.

QML list properties are typesafe. Only QObject's that derive from the correct base class can be assigned to the list. The listElementType() method can be used to query the QMetaObject of the QObject type supported. Attempting to add objects of the incorrect type to a list property will fail.

Like with normal lists, when accessing a list element by index, it is the callers responsibility to ensure that it does not request an out of range element using the count() method before calling at().

Definition at line 117 of file qdeclarativelist.h.

Constructors and Destructors

◆ QDeclarativeListReference() [1/3]

QDeclarativeListReference::QDeclarativeListReference ( )

Constructs an invalid instance.

Definition at line 122 of file qdeclarativelist.cpp.

123 : d(0)
124 {
125 }
QDeclarativeListReferencePrivate * d

◆ QDeclarativeListReference() [2/3]

QDeclarativeListReference::QDeclarativeListReference ( QObject object,
const char *  property,
QDeclarativeEngine engine = 0 
)

Constructs a QDeclarativeListReference for object's property.

If property is not a list property, an invalid QDeclarativeListReference is created. If object is destroyed after the reference is constructed, it will automatically become invalid. That is, it is safe to hold QDeclarativeListReference instances even after object is deleted.

Passing engine is required to access some QML created list properties. If in doubt, and an engine is available, pass it.

Definition at line 136 of file qdeclarativelist.cpp.

137 : d(0)
138 {
139  if (!object || !property) return;
140 
144 
145  if (!data || !(data->flags & QDeclarativePropertyCache::Data::IsQList)) return;
146 
148 
149  int listType = p?p->listType(data->propType):QDeclarativeMetaType::listType(data->propType);
150  if (listType == -1) return;
151 
153  d->object = object;
155  d->propertyType = data->propType;
156 
157  void *args[] = { &d->property, 0 };
159 }
QObject * object() const
Returns the list property&#39;s object.
friend class QDeclarativeListReferencePrivate
static int metacall(QObject *, Call, int, void **)
static QDeclarativeType * qmlType(const QByteArray &, int, int)
Returns the type (if any) of URI-qualified named name in version specified by version_major and versi...
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
const QMetaObject * baseMetaObject() const
static QDeclarativeEnginePrivate * get(QDeclarativeEngine *e)
Data * property(const QScriptDeclarativeClass::Identifier &id) const
static const char * data(const QByteArray &arr)
QDeclarativeListProperty< QObject > property
const char * property
Definition: qwizard.cpp:138
QDeclarativeListReferencePrivate * d
QDeclarativeGuard< QObject > object
const QMetaObject * rawMetaObjectForType(int) const

◆ QDeclarativeListReference() [3/3]

QDeclarativeListReference::QDeclarativeListReference ( const QDeclarativeListReference o)
Warning
This function is not part of the public interface.

Definition at line 162 of file qdeclarativelist.cpp.

163 : d(o.d)
164 {
165  if (d) d->addref();
166 }
QDeclarativeListReferencePrivate * d

◆ ~QDeclarativeListReference()

QDeclarativeListReference::~QDeclarativeListReference ( )
Warning
This function is not part of the public interface.

Definition at line 178 of file qdeclarativelist.cpp.

179 {
180  if (d) d->release();
181 }
QDeclarativeListReferencePrivate * d

Functions

◆ append()

bool QDeclarativeListReference::append ( QObject object) const

Appends object to the list.

Returns true if the operation succeeded, otherwise false.

See also
canAppend()

Definition at line 262 of file qdeclarativelist.cpp.

263 {
264  if (!canAppend()) return false;
265 
267  return false;
268 
269  d->property.append(&d->property, object);
270 
271  return true;
272 }
QDeclarativeListProperty< QObject > property
bool canAppend() const
Returns true if the list property can be appended to, otherwise false.
static bool canConvert(const QMetaObject *from, const QMetaObject *to)
Returns true if from inherits to.
QDeclarativeListReferencePrivate * d
virtual const QMetaObject * metaObject() const
Returns a pointer to the meta-object of this object.

◆ at()

QObject * QDeclarativeListReference::at ( int  index) const

Returns the list element at index, or 0 if the operation failed.

See also
canAt()

Definition at line 279 of file qdeclarativelist.cpp.

280 {
281  if (!canAt()) return 0;
282 
283  return d->property.at(&d->property, index);
284 }
QDeclarativeListProperty< QObject > property
quint16 index
QDeclarativeListReferencePrivate * d
bool canAt() const
Returns true if the list property can queried by index, otherwise false.

◆ canAppend()

bool QDeclarativeListReference::canAppend ( ) const

Returns true if the list property can be appended to, otherwise false.

Returns false if the reference is invalid.

See also
append()

Definition at line 219 of file qdeclarativelist.cpp.

Referenced by append().

220 {
221  return (isValid() && d->property.append);
222 }
QDeclarativeListProperty< QObject > property
bool isValid() const
Returns true if the instance refers to a valid list property, otherwise false.
QDeclarativeListReferencePrivate * d

◆ canAt()

bool QDeclarativeListReference::canAt ( ) const

Returns true if the list property can queried by index, otherwise false.

Returns false if the reference is invalid.

See also
at()

Definition at line 230 of file qdeclarativelist.cpp.

Referenced by at().

231 {
232  return (isValid() && d->property.at);
233 }
QDeclarativeListProperty< QObject > property
bool isValid() const
Returns true if the instance refers to a valid list property, otherwise false.
QDeclarativeListReferencePrivate * d

◆ canClear()

bool QDeclarativeListReference::canClear ( ) const

Returns true if the list property can be cleared, otherwise false.

Returns false if the reference is invalid.

See also
clear()

Definition at line 241 of file qdeclarativelist.cpp.

Referenced by clear().

242 {
243  return (isValid() && d->property.clear);
244 }
QDeclarativeListProperty< QObject > property
bool isValid() const
Returns true if the instance refers to a valid list property, otherwise false.
QDeclarativeListReferencePrivate * d

◆ canCount()

bool QDeclarativeListReference::canCount ( ) const

Returns true if the list property can be queried for its element count, otherwise false.

Returns false if the reference is invalid.

See also
count()

Definition at line 252 of file qdeclarativelist.cpp.

Referenced by count().

253 {
254  return (isValid() && d->property.count);
255 }
QDeclarativeListProperty< QObject > property
bool isValid() const
Returns true if the instance refers to a valid list property, otherwise false.
QDeclarativeListReferencePrivate * d

◆ clear()

bool QDeclarativeListReference::clear ( ) const

Clears the list.

Returns true if the operation succeeded, otherwise false.

See also
canClear()

Definition at line 291 of file qdeclarativelist.cpp.

292 {
293  if (!canClear()) return false;
294 
295  d->property.clear(&d->property);
296 
297  return true;
298 }
bool canClear() const
Returns true if the list property can be cleared, otherwise false.
QDeclarativeListProperty< QObject > property
QDeclarativeListReferencePrivate * d

◆ count()

int QDeclarativeListReference::count ( ) const

Returns the number of objects in the list, or 0 if the operation failed.

Definition at line 303 of file qdeclarativelist.cpp.

304 {
305  if (!canCount()) return 0;
306 
307  return d->property.count(&d->property);
308 }
QDeclarativeListProperty< QObject > property
QDeclarativeListReferencePrivate * d
bool canCount() const
Returns true if the list property can be queried for its element count, otherwise false...

◆ isValid()

bool QDeclarativeListReference::isValid ( ) const

Returns true if the instance refers to a valid list property, otherwise false.

Definition at line 186 of file qdeclarativelist.cpp.

Referenced by canAppend(), canAt(), canClear(), canCount(), listElementType(), and object().

187 {
188  return d && d->object;
189 }
QDeclarativeListReferencePrivate * d
QDeclarativeGuard< QObject > object

◆ listElementType()

const QMetaObject * QDeclarativeListReference::listElementType ( ) const

Returns the QMetaObject for the elements stored in the list property.

Returns 0 if the reference is invalid.

The QMetaObject can be used ahead of time to determine whether a given instance can be added to a list.

Definition at line 207 of file qdeclarativelist.cpp.

208 {
209  if (isValid()) return d->elementType;
210  else return 0;
211 }
bool isValid() const
Returns true if the instance refers to a valid list property, otherwise false.
QDeclarativeListReferencePrivate * d

◆ object()

QObject * QDeclarativeListReference::object ( ) const

Returns the list property's object.

Returns 0 if the reference is invalid.

Definition at line 194 of file qdeclarativelist.cpp.

Referenced by QDeclarativeListReference().

195 {
196  if (isValid()) return d->object;
197  else return 0;
198 }
bool isValid() const
Returns true if the instance refers to a valid list property, otherwise false.
QDeclarativeListReferencePrivate * d
QDeclarativeGuard< QObject > object

◆ operator=()

QDeclarativeListReference & QDeclarativeListReference::operator= ( const QDeclarativeListReference o)
Warning
This function is not part of the public interface.

Definition at line 169 of file qdeclarativelist.cpp.

170 {
171  if (o.d) o.d->addref();
172  if (d) d->release();
173  d = o.d;
174  return *this;
175 }
QDeclarativeListReferencePrivate * d

Friends and Related Functions

◆ QDeclarativeListReferencePrivate

Definition at line 142 of file qdeclarativelist.h.

Referenced by QDeclarativeListReference().

Properties

◆ d

QDeclarativeListReferencePrivate* QDeclarativeListReference::d
private

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