Qt 4.8
Public Types | Public Functions | Properties | List of all members
QDeclarativeListAccessor Class Reference

#include <qdeclarativelistaccessor_p.h>

Public Types

enum  Type {
  Invalid, StringList, VariantList, ListProperty,
  Instance, Integer
}
 

Public Functions

QVariant at (int) const
 
int count () const
 
bool isValid () const
 
QVariant list () const
 
 QDeclarativeListAccessor ()
 
void setList (const QVariant &, QDeclarativeEngine *=0)
 
Type type () const
 
 ~QDeclarativeListAccessor ()
 

Properties

QVariant d
 
Type m_type
 

Detailed Description

Definition at line 54 of file qdeclarativelistaccessor_p.h.

Enumerations

◆ Type

Constructors and Destructors

◆ QDeclarativeListAccessor()

QDeclarativeListAccessor::QDeclarativeListAccessor ( )

◆ ~QDeclarativeListAccessor()

QDeclarativeListAccessor::~QDeclarativeListAccessor ( )

Definition at line 59 of file qdeclarativelistaccessor.cpp.

60 {
61 }

Functions

◆ at()

QVariant QDeclarativeListAccessor::at ( int  idx) const

Definition at line 113 of file qdeclarativelistaccessor.cpp.

Referenced by QDeclarativeVisualDataModelDataMetaObject::initialValue().

114 {
115  Q_ASSERT(idx >= 0 && idx < count());
116  switch(m_type) {
117  case StringList:
118  return QVariant::fromValue(qvariant_cast<QStringList>(d).at(idx));
119  case VariantList:
120  return qvariant_cast<QVariantList>(d).at(idx);
121  case ListProperty:
123  case Instance:
124  return d;
125  case Integer:
126  return QVariant(idx);
127  default:
128  case Invalid:
129  return QVariant();
130  }
131 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
The QDeclarativeListReference class allows the manipulation of QDeclarativeListProperty properties...
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
static QVariant fromValue(const T &value)
Returns a QVariant containing a copy of value.
Definition: qvariant.h:336
const void * constData() const
Definition: qvariant.cpp:3065
T qvariant_cast(const QVariant &)
Definition: qvariant.h:571

◆ count()

int QDeclarativeListAccessor::count ( ) const

Definition at line 94 of file qdeclarativelistaccessor.cpp.

Referenced by at().

95 {
96  switch(m_type) {
97  case StringList:
98  return qvariant_cast<QStringList>(d).count();
99  case VariantList:
100  return qvariant_cast<QVariantList>(d).count();
101  case ListProperty:
102  return ((QDeclarativeListReference *)d.constData())->count();
103  case Instance:
104  return 1;
105  case Integer:
106  return d.toInt();
107  default:
108  case Invalid:
109  return 0;
110  }
111 }
The QDeclarativeListReference class allows the manipulation of QDeclarativeListProperty properties...
int toInt(bool *ok=0) const
Returns the variant as an int if the variant has type() Int , Bool , ByteArray , Char ...
Definition: qvariant.cpp:2625
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
const void * constData() const
Definition: qvariant.cpp:3065
T qvariant_cast(const QVariant &)
Definition: qvariant.h:571

◆ isValid()

bool QDeclarativeListAccessor::isValid ( ) const

◆ list()

QVariant QDeclarativeListAccessor::list ( ) const

Definition at line 63 of file qdeclarativelistaccessor.cpp.

64 {
65  return d;
66 }

◆ setList()

void QDeclarativeListAccessor::setList ( const QVariant v,
QDeclarativeEngine engine = 0 
)

Definition at line 68 of file qdeclarativelistaccessor.cpp.

69 {
70  d = v;
71 
72  QDeclarativeEnginePrivate *enginePrivate = engine?QDeclarativeEnginePrivate::get(engine):0;
73 
74  if (!d.isValid()) {
75  m_type = Invalid;
76  } else if (d.userType() == QVariant::StringList) {
78  } else if (d.userType() == QMetaType::QVariantList) {
80  } else if (d.canConvert(QVariant::Int)) {
81  m_type = Integer;
82  } else if ((!enginePrivate && QDeclarativeMetaType::isQObject(d.userType())) ||
83  (enginePrivate && enginePrivate->isQObject(d.userType()))) {
84  QObject *data = enginePrivate?enginePrivate->toQObject(v):QDeclarativeMetaType::toQObject(v);
85  d = QVariant::fromValue(data);
86  m_type = Instance;
87  } else if (d.userType() == qMetaTypeId<QDeclarativeListReference>()) {
89  } else {
90  m_type = Instance;
91  }
92 }
static QObject * toQObject(const QVariant &, bool *ok=0)
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
static QDeclarativeEnginePrivate * get(QDeclarativeEngine *e)
bool canConvert(Type t) const
Returns true if the variant&#39;s type can be cast to the requested type, t.
Definition: qvariant.cpp:2886
static const char * data(const QByteArray &arr)
static QVariant fromValue(const T &value)
Returns a QVariant containing a copy of value.
Definition: qvariant.h:336
int userType() const
Returns the storage type of the value stored in the variant.
Definition: qvariant.cpp:1913
QObject * toQObject(const QVariant &, bool *ok=0) const
bool isValid() const
Returns true if the storage type of this variant is not QVariant::Invalid; otherwise returns false...
Definition: qvariant.h:485

◆ type()

Type QDeclarativeListAccessor::type ( ) const
inline

Properties

◆ d

QVariant QDeclarativeListAccessor::d
private

Definition at line 73 of file qdeclarativelistaccessor_p.h.

Referenced by at(), count(), list(), and setList().

◆ m_type

Type QDeclarativeListAccessor::m_type
private

Definition at line 72 of file qdeclarativelistaccessor_p.h.

Referenced by at(), count(), isValid(), and setList().


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