Qt 4.8
Public Functions | Static Public Functions | Public Variables | List of all members
ModelNode Struct Reference

#include <qdeclarativelistmodel_p_p.h>

Public Functions

void changedProperty (const QString &name) const
 
void clear ()
 
QDeclarativeListModelmodel (const NestedListModel *model)
 
 ModelNode (NestedListModel *model)
 
ModelObjectobject (const NestedListModel *model)
 
void setListValue (const QScriptValue &valuelist)
 
bool setObjectValue (const QScriptValue &valuemap, bool writeToCache=true)
 
bool setProperty (const QString &prop, const QVariant &val)
 
void updateListIndexes ()
 
 ~ModelNode ()
 

Static Public Functions

static void dump (ModelNode *node, int ind)
 

Public Variables

bool isArray
 
int listIndex
 
NestedListModelm_model
 
QDeclarativeListModelmodelCache
 
ModelObjectobjectCache
 
QHash< QString, ModelNode * > properties
 
QList< QVariantvalues
 

Detailed Description

Definition at line 245 of file qdeclarativelistmodel_p_p.h.

Constructors and Destructors

◆ ModelNode()

ModelNode::ModelNode ( NestedListModel model)

Definition at line 1474 of file qdeclarativelistmodel.cpp.

Referenced by setListValue(), setObjectValue(), and setProperty().

1475 : modelCache(0), objectCache(0), isArray(false), m_model(model), listIndex(-1)
1476 {
1477 }
QDeclarativeListModel * modelCache
ModelObject * objectCache
NestedListModel * m_model

◆ ~ModelNode()

ModelNode::~ModelNode ( )

Definition at line 1479 of file qdeclarativelistmodel.cpp.

1480 {
1481  clear();
1482  if (modelCache) { modelCache->m_nested->_root = 0/* ==this */; delete modelCache; modelCache = 0; }
1483  if (objectCache) { delete objectCache; objectCache = 0; }
1484 }
QDeclarativeListModel * modelCache
ModelObject * objectCache

Functions

◆ changedProperty()

void ModelNode::changedProperty ( const QString name) const

Definition at line 1588 of file qdeclarativelistmodel.cpp.

Referenced by ModelNodeMetaObject::propertyWritten().

1589 {
1590  if (listIndex < 0)
1591  return;
1592 
1593  m_model->checkRoles();
1594  QList<int> roles;
1595  int role = m_model->roleStrings.indexOf(name);
1596  if (role < 0)
1597  roles = m_model->roles();
1598  else
1599  roles << role;
1601 }
QList< int > roles() const
QDeclarativeListModel * m_listModel
int indexOf(const QRegExp &rx, int from=0) const
Returns the index position of the first exact match of rx in the list, searching forward from index p...
Definition: qstringlist.h:195
#define emit
Definition: qobjectdefs.h:76
void itemsChanged(int index, int count, const QList< int > &roles)
Emit this signal when count items at index have had their roles changed.
NestedListModel * m_model

◆ clear()

void ModelNode::clear ( )

Definition at line 1486 of file qdeclarativelistmodel.cpp.

Referenced by NestedListModel::clear(), and ~ModelNode().

1487 {
1488  ModelNode *node;
1489  for (int ii = 0; ii < values.count(); ++ii) {
1490  node = qvariant_cast<ModelNode *>(values.at(ii));
1491  if (node) { delete node; node = 0; }
1492  }
1493  values.clear();
1494 
1496  properties.clear();
1497 }
void clear()
Removes all items from the hash.
Definition: qhash.h:574
QHash< QString, ModelNode * > properties
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
QList< QVariant > values
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
void clear()
Removes all items from the list.
Definition: qlist.h:764
QList< T > values() const
Returns a list containing all the values in the hash, in an arbitrary order.
Definition: qhash.h:693
T qvariant_cast(const QVariant &)
Definition: qvariant.h:571
Q_OUTOFLINE_TEMPLATE void qDeleteAll(ForwardIterator begin, ForwardIterator end)
Definition: qalgorithms.h:319

◆ dump()

void ModelNode::dump ( ModelNode node,
int  ind 
)
static

Definition at line 1603 of file qdeclarativelistmodel.cpp.

1604 {
1605  QByteArray indentBa(ind * 4, ' ');
1606  const char *indent = indentBa.constData();
1607 
1608  for (int ii = 0; ii < node->values.count(); ++ii) {
1609  ModelNode *subNode = qvariant_cast<ModelNode *>(node->values.at(ii));
1610  if (subNode) {
1611  qWarning().nospace() << indent << "Sub-node " << ii;
1612  dump(subNode, ind + 1);
1613  } else {
1614  qWarning().nospace() << indent << "Sub-node " << ii << ": " << node->values.at(ii).toString();
1615  }
1616  }
1617 
1618  for (QHash<QString, ModelNode *>::ConstIterator iter = node->properties.begin(); iter != node->properties.end(); ++iter) {
1619  qWarning().nospace() << indent << "Property " << iter.key() << ':';
1620  dump(iter.value(), ind + 1);
1621  }
1622 }
The QHash::const_iterator class provides an STL-style const iterator for QHash and QMultiHash...
Definition: qhash.h:395
QHash< QString, ModelNode * > properties
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
QString toString() const
Returns the variant as a QString if the variant has type() String , Bool , ByteArray ...
Definition: qvariant.cpp:2270
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
QList< QVariant > values
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
Q_CORE_EXPORT void qWarning(const char *,...)
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the hash...
Definition: qhash.h:467
static void dump(ModelNode *node, int ind)
iterator begin()
Returns an STL-style iterator pointing to the first item in the hash.
Definition: qhash.h:464
T qvariant_cast(const QVariant &)
Definition: qvariant.h:571

◆ model()

QDeclarativeListModel * ModelNode::model ( const NestedListModel model)

Definition at line 360 of file qdeclarativelistmodel.cpp.

Referenced by setObjectValue(), and NestedListModel::valueForNode().

361 {
362  if (!modelCache) {
365  modelCache->m_nested->_root = this; // ListModel defaults to nestable model
366 
367  for (int i=0; i<values.count(); ++i) {
368  ModelNode *subNode = qvariant_cast<ModelNode *>(values.at(i));
369  if (subNode)
370  subNode->m_model = modelCache->m_nested;
371  }
372  }
373  return modelCache;
374 }
static void setContextForObject(QObject *, QDeclarativeContext *)
Sets the QDeclarativeContext for the object to context.
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
QDeclarativeListModel * m_listModel
QList< QVariant > values
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
QDeclarativeListModel * modelCache
T qvariant_cast(const QVariant &)
Definition: qvariant.h:571
static QDeclarativeContext * contextForObject(const QObject *)
Returns the QDeclarativeContext for the object, or 0 if no context has been set.
NestedListModel * m_model

◆ object()

ModelObject * ModelNode::object ( const NestedListModel model)

Definition at line 376 of file qdeclarativelistmodel.cpp.

Referenced by NestedListModel::get(), and NestedListModel::valueForNode().

377 {
378  if (!objectCache) {
379  objectCache = new ModelObject(this,
380  const_cast<NestedListModel*>(model),
383  for (it = properties.begin(); it != properties.end(); ++it) {
384  objectCache->setValue(it.key().toUtf8(), model->valueForNode(*it));
385  }
387  }
388  return objectCache;
389 }
static QScriptEngine * getScriptEngine(QDeclarativeEngine *e)
QHash< QString, ModelNode * > properties
#define it(className, varName)
QDeclarativeListModel * m_listModel
QVariant valueForNode(ModelNode *, bool *hasNested=0) const
const Key & key() const
Returns the current item&#39;s key as a const reference.
Definition: qhash.h:347
Q_DECLARATIVE_EXPORT QDeclarativeEngine * qmlEngine(const QObject *)
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the hash...
Definition: qhash.h:467
The QHash::iterator class provides an STL-style non-const iterator for QHash and QMultiHash.
Definition: qhash.h:330
iterator begin()
Returns an STL-style iterator pointing to the first item in the hash.
Definition: qhash.h:464
void setValue(const QByteArray &name, const QVariant &val)
ModelObject * objectCache
void setNodeUpdatesEnabled(bool enable)

◆ setListValue()

void ModelNode::setListValue ( const QScriptValue valuelist)

Definition at line 1532 of file qdeclarativelistmodel.cpp.

Referenced by setListValue(), and setObjectValue().

1532  {
1533  values.clear();
1534  int size = valuelist.property(QLatin1String("length")).toInt32();
1535  for (int i=0; i<size; i++) {
1536  ModelNode *value = new ModelNode(m_model);
1537  QScriptValue v = valuelist.property(i);
1538  if (v.isArray()) {
1539  value->isArray = true;
1540  value->setListValue(v);
1541  } else if (v.isObject()) {
1542  value->listIndex = i;
1543  value->setObjectValue(v);
1544  } else {
1545  value->listIndex = i;
1546  value->values << v.toVariant();
1547  }
1549  }
1550 }
QScriptValue property(const QString &name, const ResolveFlags &mode=ResolvePrototype) const
Returns the value of this QScriptValue&#39;s property with the given name, using the given mode to resolv...
qint32 toInt32() const
Returns the signed 32-bit integer value of this QScriptValue, using the conversion rules described in...
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
bool setObjectValue(const QScriptValue &valuemap, bool writeToCache=true)
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
QList< QVariant > values
QVariant toVariant() const
Returns the QVariant value of this QScriptValue, if it can be converted to a QVariant; otherwise retu...
void clear()
Removes all items from the list.
Definition: qlist.h:764
static QVariant fromValue(const T &value)
Returns a QVariant containing a copy of value.
Definition: qvariant.h:336
void setListValue(const QScriptValue &valuelist)
NestedListModel * m_model
bool isArray() const
Returns true if this QScriptValue is an object of the Array class; otherwise returns false...
ModelNode(NestedListModel *model)
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57
bool isObject() const
Returns true if this QScriptValue is of the Object type; otherwise returns false. ...

◆ setObjectValue()

bool ModelNode::setObjectValue ( const QScriptValue valuemap,
bool  writeToCache = true 
)

Definition at line 1499 of file qdeclarativelistmodel.cpp.

Referenced by NestedListModel::insert(), ModelNodeMetaObject::propertyWritten(), NestedListModel::set(), and setListValue().

1500 {
1501  bool emitItemsChanged = false;
1502 
1503  QScriptValueIterator it(valuemap);
1504  while (it.hasNext()) {
1505  it.next();
1506  ModelNode *prev = properties.value(it.name());
1507  ModelNode *value = new ModelNode(m_model);
1508  QScriptValue v = it.value();
1509 
1510  if (v.isArray()) {
1511  value->isArray = true;
1512  value->setListValue(v);
1513  if (writeToCache && objectCache)
1514  objectCache->setValue(it.name().toUtf8(), QVariant::fromValue(value->model(m_model)));
1515  emitItemsChanged = true; // for now, too inefficient to check whether list and sublists have changed
1516  } else {
1517  value->values << v.toVariant();
1518  if (writeToCache && objectCache)
1519  objectCache->setValue(it.name().toUtf8(), value->values.last());
1520  if (!emitItemsChanged && prev && prev->values.count() == 1
1521  && prev->values[0] != value->values.last()) {
1522  emitItemsChanged = true;
1523  }
1524  }
1525  if (properties.contains(it.name()))
1526  delete properties[it.name()];
1527  properties.insert(it.name(), value);
1528  }
1529  return emitItemsChanged;
1530 }
QHash< QString, ModelNode * > properties
#define it(className, varName)
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
bool contains(const Key &key) const
Returns true if the hash contains an item with the key; otherwise returns false.
Definition: qhash.h:872
const T value(const Key &key) const
Returns the value associated with the key.
Definition: qhash.h:606
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition: qhash.h:753
QList< QVariant > values
QVariant toVariant() const
Returns the QVariant value of this QScriptValue, if it can be converted to a QVariant; otherwise retu...
static QVariant fromValue(const T &value)
Returns a QVariant containing a copy of value.
Definition: qvariant.h:336
QDeclarativeListModel * model(const NestedListModel *model)
The QScriptValueIterator class provides a Java-style iterator for QScriptValue.
T & last()
Returns a reference to the last item in the list.
Definition: qlist.h:284
void setListValue(const QScriptValue &valuelist)
void setValue(const QByteArray &name, const QVariant &val)
ModelObject * objectCache
NestedListModel * m_model
bool isArray() const
Returns true if this QScriptValue is an object of the Array class; otherwise returns false...
ModelNode(NestedListModel *model)
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57

◆ setProperty()

bool ModelNode::setProperty ( const QString prop,
const QVariant val 
)

Definition at line 1552 of file qdeclarativelistmodel.cpp.

Referenced by NestedListModel::setProperty().

1552  {
1554  bool emitItemsChanged = false;
1555  if (it != properties.end()) {
1556  if (val != (*it)->values[0])
1557  emitItemsChanged = true;
1558  (*it)->values[0] = val;
1559  } else {
1560  ModelNode *n = new ModelNode(m_model);
1561  n->values << val;
1562  properties.insert(prop,n);
1563  }
1564  if (objectCache)
1565  objectCache->setValue(prop.toUtf8(), val);
1566  return emitItemsChanged;
1567 }
The QHash::const_iterator class provides an STL-style const iterator for QHash and QMultiHash...
Definition: qhash.h:395
QHash< QString, ModelNode * > properties
#define it(className, varName)
QByteArray toUtf8() const Q_REQUIRED_RESULT
Returns a UTF-8 representation of the string as a QByteArray.
Definition: qstring.cpp:4074
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition: qhash.h:753
QList< QVariant > values
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the hash...
Definition: qhash.h:467
void setValue(const QByteArray &name, const QVariant &val)
iterator find(const Key &key)
Returns an iterator pointing to the item with the key in the hash.
Definition: qhash.h:865
ModelObject * objectCache
NestedListModel * m_model
ModelNode(NestedListModel *model)

◆ updateListIndexes()

void ModelNode::updateListIndexes ( )

Definition at line 1569 of file qdeclarativelistmodel.cpp.

Referenced by QDeclarativeListModelParser::setCustomData(), and updateListIndexes().

1570 {
1571  for (QHash<QString, ModelNode *>::ConstIterator iter = properties.begin(); iter != properties.end(); ++iter) {
1572  ModelNode *node = iter.value();
1573  if (node->isArray) {
1574  for (int i=0; i<node->values.count(); ++i) {
1575  ModelNode *subNode = qvariant_cast<ModelNode *>(node->values.at(i));
1576  if (subNode)
1577  subNode->listIndex = i;
1578  }
1579  }
1580  node->updateListIndexes();
1581  }
1582 }
The QHash::const_iterator class provides an STL-style const iterator for QHash and QMultiHash...
Definition: qhash.h:395
QHash< QString, ModelNode * > properties
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
QList< QVariant > values
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the hash...
Definition: qhash.h:467
iterator begin()
Returns an STL-style iterator pointing to the first item in the hash.
Definition: qhash.h:464
T qvariant_cast(const QVariant &)
Definition: qvariant.h:571

Properties

◆ isArray

bool ModelNode::isArray

◆ listIndex

int ModelNode::listIndex

◆ m_model

NestedListModel* ModelNode::m_model

◆ modelCache

QDeclarativeListModel* ModelNode::modelCache

Definition at line 265 of file qdeclarativelistmodel_p_p.h.

Referenced by ~ModelNode().

◆ objectCache

ModelObject* ModelNode::objectCache

Definition at line 266 of file qdeclarativelistmodel_p_p.h.

Referenced by setObjectValue(), setProperty(), and ~ModelNode().

◆ properties

QHash<QString, ModelNode *> ModelNode::properties

◆ values

QList<QVariant> ModelNode::values

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