Qt 4.8
qdeclarativevisualitemmodel.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtDeclarative module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include "private/qdeclarativevisualitemmodel_p.h"
43 
44 #include "qdeclarativeitem.h"
45 
46 #include <qdeclarativecontext.h>
47 #include <qdeclarativecontext_p.h>
48 #include <qdeclarativeengine.h>
49 #include <qdeclarativeexpression.h>
50 #include <qdeclarativepackage_p.h>
53 #include <qdeclarativeinfo.h>
54 #include <qdeclarativedata_p.h>
56 #include <qdeclarativeguard_p.h>
57 #include <qdeclarativeglobal_p.h>
58 
59 #include <qgraphicsscene.h>
60 #include <qlistmodelinterface_p.h>
61 #include <qhash.h>
62 #include <qlist.h>
63 #include <qmetaobjectbuilder_p.h>
64 #include <QtCore/qdebug.h>
65 
66 #include <private/qobject_p.h>
67 
69 
71 
72 
74 {
76 public:
78 
81  static_cast<QDeclarativeVisualItemModelPrivate *>(prop->data)->children.append(Item(item));
82  static_cast<QDeclarativeVisualItemModelPrivate *>(prop->data)->itemAppended();
84  }
85 
87  return static_cast<QDeclarativeVisualItemModelPrivate *>(prop->data)->children.count();
88  }
89 
91  return static_cast<QDeclarativeVisualItemModelPrivate *>(prop->data)->children.at(index).item;
92  }
93 
94  void itemAppended() {
97  attached->setIndex(children.count()-1);
98  emit q->itemsInserted(children.count()-1, 1);
99  emit q->countChanged();
100  }
101 
104  emit q->childrenChanged();
105  }
106 
107  int indexOf(QDeclarativeItem *item) const {
108  for (int i = 0; i < children.count(); ++i)
109  if (children.at(i).item == item)
110  return i;
111  return -1;
112  }
113 
114  class Item {
115  public:
116  Item(QDeclarativeItem *i) : item(i), ref(0) {}
117 
118  void addRef() { ++ref; }
119  bool deref() { return --ref == 0; }
120 
122  int ref;
123  };
124 
126 };
127 
128 
171 {
172 }
173 
185 {
187  return QDeclarativeListProperty<QDeclarativeItem>(this, d, d->children_append,
188  d->children_count, d->children_at);
189 }
190 
200 {
202  return d->children.count();
203 }
204 
206 {
207  return true;
208 }
209 
211 {
214  item.addRef();
215  return item.item;
216 }
217 
218 QDeclarativeVisualModel::ReleaseFlags QDeclarativeVisualItemModel::release(QDeclarativeItem *item)
219 {
221  int idx = d->indexOf(item);
222  if (idx >= 0) {
223  if (d->children[idx].deref()) {
224  if (item->scene())
225  item->scene()->removeItem(item);
226  QDeclarative_setParent_noEvent(item, this);
227  }
228  }
229  return 0;
230 }
231 
233 {
234  return false;
235 }
236 
238 {
239  // Nothing to do
240 }
241 
243 {
245  if (index < 0 || index >= d->children.count())
246  return QString();
247  return QDeclarativeEngine::contextForObject(d->children.at(index).item)->contextProperty(name).toString();
248 }
249 
251 {
253  return d->indexOf(item);
254 }
255 
257 {
259 }
260 
261 //============================================================================
262 
264 {
265 public:
267 
269  prop.setWritable(false);
270  }
271 };
272 
276 {
277 public:
279 
282  }
283 
288 
293  void ensureRoles() {
294  if (m_roleNames.isEmpty()) {
295  if (m_listModelInterface) {
296  m_roles = m_listModelInterface->roles();
297  for (int ii = 0; ii < m_roles.count(); ++ii)
298  m_roleNames.insert(m_listModelInterface->toString(m_roles.at(ii)).toUtf8(), m_roles.at(ii));
299  } else if (m_abstractItemModel) {
300  for (QHash<int,QByteArray>::const_iterator it = m_abstractItemModel->roleNames().begin();
301  it != m_abstractItemModel->roleNames().end(); ++it) {
302  m_roles.append(it.key());
303  m_roleNames.insert(*it, it.key());
304  }
305  if (m_roles.count())
306  m_roleNames.insert("hasModelChildren", -1);
307  } else if (m_listAccessor) {
308  m_roleNames.insert("modelData", 0);
309  if (m_listAccessor->type() == QDeclarativeListAccessor::Instance) {
310  if (QObject *object = m_listAccessor->at(0).value<QObject*>()) {
311  int count = object->metaObject()->propertyCount();
312  for (int ii = 1; ii < count; ++ii) {
313  const QMetaProperty &prop = object->metaObject()->property(ii);
314  m_roleNames.insert(prop.name(), 0);
315  }
316  }
317  }
318  }
319  }
320  }
321 
324  void createMetaData() {
325  if (!m_metaDataCreated) {
326  ensureRoles();
327  if (m_roleNames.count()) {
329  while (it != m_roleNames.end()) {
330  int propId = m_delegateDataType->createProperty(it.key()) - m_delegateDataType->propertyOffset();
331  m_roleToPropId.insert(*it, propId);
332  ++it;
333  }
334  // Add modelData property
335  if (m_roles.count() == 1)
336  m_modelDataPropId = m_delegateDataType->createProperty("modelData") - m_delegateDataType->propertyOffset();
337  m_metaDataCreated = true;
338  }
339  }
340  }
341 
342  struct ObjectRef {
343  ObjectRef(QObject *object=0) : obj(object), ref(1) {}
345  int ref;
346  };
347  class Cache : public QHash<int, ObjectRef> {
348  public:
350  QObject *item = 0;
351  QHash<int,ObjectRef>::iterator it = find(index);
352  if (it != end()) {
353  (*it).ref++;
354  item = (*it).obj;
355  }
356  return item;
357  }
359  QObject *item = 0;
361  if (it != end())
362  item = (*it).obj;
363  return item;
364  }
365  void insertItem(int index, QObject *obj) {
366  insert(index, ObjectRef(obj));
367  }
368  bool releaseItem(QObject *obj) {
370  for (; it != end(); ++it) {
371  ObjectRef &objRef = *it;
372  if (objRef.obj == obj) {
373  if (--objRef.ref == 0) {
374  erase(it);
375  return true;
376  }
377  break;
378  }
379  }
380  return false;
381  }
382  };
383 
384  int modelCount() const {
385  if (m_visualItemModel)
386  return m_visualItemModel->count();
387  if (m_listModelInterface)
388  return m_listModelInterface->count();
389  if (m_abstractItemModel)
390  return m_abstractItemModel->rowCount(m_root);
391  if (m_listAccessor)
392  return m_listAccessor->count();
393  return 0;
394  }
395 
398 
400  friend class QDeclarativeVisualItemParts;
401 
408 
410 
413 
417 };
418 
420 {
421 public:
423  : QDeclarativeOpenMetaObject(parent, type) {}
424 
425  virtual QVariant initialValue(int);
426  virtual int createProperty(const char *, const char *);
427 
428 private:
430 };
431 
433 {
434 Q_OBJECT
435 public:
438 
439  int index;
440  int index() const;
441  void setIndex(int index);
442 
443  int propForRole(int) const;
444  int modelDataPropertyId() const {
446  return model->m_modelDataPropId;
447  }
448 
449  void setValue(int, const QVariant &);
450  bool hasValue(int id) const {
451  return m_meta->hasValue(id);
452  }
453 
454  void ensureProperties();
455 
456 Q_SIGNALS:
457  void indexChanged();
458 
459 private:
461  int m_index;
464 };
465 
467 {
470  if (it != model->m_roleToPropId.end())
471  return *it;
472 
473  return -1;
474 }
475 
477 {
478  m_meta->setValue(id, val);
479 }
480 
482 {
484  static_cast<QDeclarativeVisualDataModelData *>(object());
485 
486  if (!data->m_model)
487  return -1;
488 
490  if (data->m_index < 0 || data->m_index >= model->modelCount())
491  return -1;
492 
493  if ((!model->m_listModelInterface || !model->m_abstractItemModel) && model->m_listAccessor) {
495  model->ensureRoles();
496  if (qstrcmp(name,"modelData") == 0)
498  }
499  }
500  return -1;
501 }
502 
504 {
506  static_cast<QDeclarativeVisualDataModelData *>(object());
507 
508  Q_ASSERT(data->m_model);
510 
511  QByteArray propName = name(propId);
512  if ((!model->m_listModelInterface || !model->m_abstractItemModel) && model->m_listAccessor) {
513  if (propName == "modelData") {
515  QObject *object = model->m_listAccessor->at(0).value<QObject*>();
516  return object->metaObject()->property(1).read(object); // the first property after objectName
517  }
518  return model->m_listAccessor->at(data->m_index);
519  } else {
520  // return any property of a single object instance.
521  QObject *object = model->m_listAccessor->at(data->m_index).value<QObject*>();
522  return object->property(propName);
523  }
524  } else if (model->m_listModelInterface) {
525  model->ensureRoles();
527  if (it != model->m_roleNames.end()) {
528  QVariant value = model->m_listModelInterface->data(data->m_index, *it);
529  return value;
530  } else if (model->m_roles.count() == 1 && propName == "modelData") {
531  //for compatibility with other lists, assign modelData if there is only a single role
532  QVariant value = model->m_listModelInterface->data(data->m_index, model->m_roles.first());
533  return value;
534  }
535  } else if (model->m_abstractItemModel) {
536  model->ensureRoles();
537  QModelIndex index = model->m_abstractItemModel->index(data->m_index, 0, model->m_root);
538  if (propName == "hasModelChildren") {
539  return model->m_abstractItemModel->hasChildren(index);
540  } else {
542  if (it != model->m_roleNames.end()) {
543  return model->m_abstractItemModel->data(index, *it);
544  } else if (model->m_roles.count() == 1 && propName == "modelData") {
545  //for compatibility with other lists, assign modelData if there is only a single role
546  return model->m_abstractItemModel->data(index, model->m_roles.first());
547  }
548  }
549  }
550  Q_ASSERT(!"Can never be reached");
551  return QVariant();
552 }
553 
556 : m_index(index), m_model(model),
557 m_meta(new QDeclarativeVisualDataModelDataMetaObject(this, QDeclarativeVisualDataModelPrivate::get(model)->m_delegateDataType))
558 {
560 }
561 
563 {
564 }
565 
567 {
569  if (modelPriv->m_metaDataCacheable) {
570  if (!modelPriv->m_metaDataCreated)
571  modelPriv->createMetaData();
572  if (modelPriv->m_metaDataCreated)
573  m_meta->setCached(true);
574  }
575 }
576 
578 {
579  return m_index;
580 }
581 
582 // This is internal only - it should not be set from qml
584 {
585  m_index = index;
586  emit indexChanged();
587 }
588 
589 //---------------------------------------------------------------------------
590 
592 {
593 public:
595  : QDeclarativeOpenMetaObject(parent) {}
596 
597  virtual void propertyCreated(int, QMetaPropertyBuilder &);
598  virtual QVariant initialValue(int);
599 };
600 
602 {
603 Q_OBJECT
604 public:
606 
607 private:
610 };
611 
613 {
614  prop.setWritable(false);
615 }
616 
618 {
620  m->setParent(object());
621  m->setPart(QString::fromUtf8(name(id)));
622  m->setModel(QVariant::fromValue(static_cast<QDeclarativeVisualDataModelParts *>(object())->model));
623 
625  return var;
626 }
627 
629 : QObject(parent), model(parent)
630 {
632 }
633 
635 : m_listModelInterface(0), m_abstractItemModel(0), m_visualItemModel(0), m_delegate(0)
636 , m_context(ctxt), m_modelDataPropId(-1), m_parts(0), m_delegateDataType(0), m_metaDataCreated(false)
637 , m_metaDataCacheable(false), m_delegateValidated(false), m_completePending(false), m_listAccessor(0)
638 {
639 }
640 
642 {
645  Q_ASSERT(dataItem);
646  return dataItem;
647 }
648 
649 //---------------------------------------------------------------------------
650 
675 {
676 }
677 
680 {
681 }
682 
684 {
686  if (d->m_listAccessor)
687  delete d->m_listAccessor;
688  if (d->m_delegateDataType)
689  d->m_delegateDataType->release();
690 }
691 
709 {
711  return d->m_modelVariant;
712 }
713 
715 {
717  delete d->m_listAccessor;
718  d->m_listAccessor = 0;
719  d->m_modelVariant = model;
720  if (d->m_listModelInterface) {
721  // Assume caller has released all items.
722  QObject::disconnect(d->m_listModelInterface, SIGNAL(itemsChanged(int,int,QList<int>)),
723  this, SLOT(_q_itemsChanged(int,int,QList<int>)));
724  QObject::disconnect(d->m_listModelInterface, SIGNAL(itemsInserted(int,int)),
725  this, SLOT(_q_itemsInserted(int,int)));
726  QObject::disconnect(d->m_listModelInterface, SIGNAL(itemsRemoved(int,int)),
727  this, SLOT(_q_itemsRemoved(int,int)));
728  QObject::disconnect(d->m_listModelInterface, SIGNAL(itemsMoved(int,int,int)),
729  this, SLOT(_q_itemsMoved(int,int,int)));
730  d->m_listModelInterface = 0;
731  } else if (d->m_abstractItemModel) {
732  QObject::disconnect(d->m_abstractItemModel, SIGNAL(rowsInserted(QModelIndex,int,int)),
733  this, SLOT(_q_rowsInserted(QModelIndex,int,int)));
734  QObject::disconnect(d->m_abstractItemModel, SIGNAL(rowsRemoved(QModelIndex,int,int)),
735  this, SLOT(_q_rowsRemoved(QModelIndex,int,int)));
736  QObject::disconnect(d->m_abstractItemModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
738  QObject::disconnect(d->m_abstractItemModel, SIGNAL(rowsMoved(QModelIndex,int,int,QModelIndex,int)),
739  this, SLOT(_q_rowsMoved(QModelIndex,int,int,QModelIndex,int)));
740  QObject::disconnect(d->m_abstractItemModel, SIGNAL(modelReset()), this, SLOT(_q_modelReset()));
741  QObject::disconnect(d->m_abstractItemModel, SIGNAL(layoutChanged()), this, SLOT(_q_layoutChanged()));
742  d->m_abstractItemModel = 0;
743  } else if (d->m_visualItemModel) {
744  QObject::disconnect(d->m_visualItemModel, SIGNAL(itemsInserted(int,int)),
745  this, SIGNAL(itemsInserted(int,int)));
746  QObject::disconnect(d->m_visualItemModel, SIGNAL(itemsRemoved(int,int)),
747  this, SIGNAL(itemsRemoved(int,int)));
748  QObject::disconnect(d->m_visualItemModel, SIGNAL(itemsMoved(int,int,int)),
749  this, SIGNAL(itemsMoved(int,int,int)));
754  d->m_visualItemModel = 0;
755  }
756 
757  d->m_roles.clear();
758  d->m_roleNames.clear();
759  if (d->m_delegateDataType)
760  d->m_delegateDataType->release();
761  d->m_metaDataCreated = 0;
762  d->m_metaDataCacheable = false;
763  d->m_delegateDataType = new VDMDelegateDataType(&QDeclarativeVisualDataModelData::staticMetaObject, d->m_context?d->m_context->engine():qmlEngine(this));
764 
765  QObject *object = qvariant_cast<QObject *>(model);
766  if (object && (d->m_listModelInterface = qobject_cast<QListModelInterface *>(object))) {
767  QObject::connect(d->m_listModelInterface, SIGNAL(itemsChanged(int,int,QList<int>)),
768  this, SLOT(_q_itemsChanged(int,int,QList<int>)));
769  QObject::connect(d->m_listModelInterface, SIGNAL(itemsInserted(int,int)),
770  this, SLOT(_q_itemsInserted(int,int)));
771  QObject::connect(d->m_listModelInterface, SIGNAL(itemsRemoved(int,int)),
772  this, SLOT(_q_itemsRemoved(int,int)));
773  QObject::connect(d->m_listModelInterface, SIGNAL(itemsMoved(int,int,int)),
774  this, SLOT(_q_itemsMoved(int,int,int)));
775  d->m_metaDataCacheable = true;
776  if (d->m_delegate && d->m_listModelInterface->count())
777  emit itemsInserted(0, d->m_listModelInterface->count());
778  return;
779  } else if (object && (d->m_abstractItemModel = qobject_cast<QAbstractItemModel *>(object))) {
780  QObject::connect(d->m_abstractItemModel, SIGNAL(rowsInserted(QModelIndex,int,int)),
781  this, SLOT(_q_rowsInserted(QModelIndex,int,int)));
782  QObject::connect(d->m_abstractItemModel, SIGNAL(rowsRemoved(QModelIndex,int,int)),
783  this, SLOT(_q_rowsRemoved(QModelIndex,int,int)));
784  QObject::connect(d->m_abstractItemModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
786  QObject::connect(d->m_abstractItemModel, SIGNAL(rowsMoved(QModelIndex,int,int,QModelIndex,int)),
787  this, SLOT(_q_rowsMoved(QModelIndex,int,int,QModelIndex,int)));
788  QObject::connect(d->m_abstractItemModel, SIGNAL(modelReset()), this, SLOT(_q_modelReset()));
789  QObject::connect(d->m_abstractItemModel, SIGNAL(layoutChanged()), this, SLOT(_q_layoutChanged()));
790  d->m_metaDataCacheable = true;
791  if (d->m_abstractItemModel->canFetchMore(d->m_root))
792  d->m_abstractItemModel->fetchMore(d->m_root);
793  return;
794  }
795  if ((d->m_visualItemModel = qvariant_cast<QDeclarativeVisualDataModel *>(model))) {
796  QObject::connect(d->m_visualItemModel, SIGNAL(itemsInserted(int,int)),
797  this, SIGNAL(itemsInserted(int,int)));
798  QObject::connect(d->m_visualItemModel, SIGNAL(itemsRemoved(int,int)),
799  this, SIGNAL(itemsRemoved(int,int)));
800  QObject::connect(d->m_visualItemModel, SIGNAL(itemsMoved(int,int,int)),
801  this, SIGNAL(itemsMoved(int,int,int)));
802  QObject::connect(d->m_visualItemModel, SIGNAL(createdPackage(int,QDeclarativePackage*)),
806  return;
807  }
808  d->m_listAccessor = new QDeclarativeListAccessor;
809  d->m_listAccessor->setList(model, d->m_context?d->m_context->engine():qmlEngine(this));
810  if (d->m_listAccessor->type() != QDeclarativeListAccessor::ListProperty)
811  d->m_metaDataCacheable = true;
812  if (d->m_delegate && d->modelCount()) {
813  emit itemsInserted(0, d->modelCount());
814  emit countChanged();
815  }
816 }
817 
829 {
831  if (d->m_visualItemModel)
832  return d->m_visualItemModel->delegate();
833  return d->m_delegate;
834 }
835 
837 {
839  bool wasValid = d->m_delegate != 0;
840  d->m_delegate = delegate;
841  d->m_delegateValidated = false;
842  if (!wasValid && d->modelCount() && d->m_delegate) {
843  emit itemsInserted(0, d->modelCount());
844  emit countChanged();
845  }
846  if (wasValid && !d->m_delegate && d->modelCount()) {
847  emit itemsRemoved(0, d->modelCount());
848  emit countChanged();
849  }
850 }
851 
885 {
887  return QVariant::fromValue(d->m_root);
888 }
889 
891 {
894  if (d->m_root != modelIndex) {
895  int oldCount = d->modelCount();
896  d->m_root = modelIndex;
897  if (d->m_abstractItemModel && d->m_abstractItemModel->canFetchMore(modelIndex))
898  d->m_abstractItemModel->fetchMore(modelIndex);
899  int newCount = d->modelCount();
900  if (d->m_delegate && oldCount)
901  emit itemsRemoved(0, oldCount);
902  if (d->m_delegate && newCount)
903  emit itemsInserted(0, newCount);
904  if (newCount != oldCount)
905  emit countChanged();
907  }
908 }
909 
910 
927 {
929  if (d->m_abstractItemModel)
930  return QVariant::fromValue(d->m_abstractItemModel->index(idx, 0, d->m_root));
932 }
933 
950 {
952  if (d->m_abstractItemModel)
953  return QVariant::fromValue(d->m_abstractItemModel->parent(d->m_root));
955 }
956 
958 {
960  return d->m_part;
961 }
962 
964 {
966  d->m_part = part;
967 }
968 
970 {
972  if (d->m_visualItemModel)
973  return d->m_visualItemModel->count();
974  if (!d->m_delegate)
975  return 0;
976  return d->modelCount();
977 }
978 
980 {
982  if (d->m_visualItemModel)
983  return d->m_visualItemModel->item(index, d->m_part.toUtf8(), complete);
984  return item(index, QByteArray(), complete);
985 }
986 
987 /*
988  Returns ReleaseStatus flags.
989 */
990 QDeclarativeVisualDataModel::ReleaseFlags QDeclarativeVisualDataModel::release(QDeclarativeItem *item)
991 {
993  if (d->m_visualItemModel)
994  return d->m_visualItemModel->release(item);
995 
996  ReleaseFlags stat = 0;
997  QObject *obj = item;
998  bool inPackage = false;
999 
1000  QHash<QObject*,QDeclarativePackage*>::iterator it = d->m_packaged.find(item);
1001  if (it != d->m_packaged.end()) {
1002  QDeclarativePackage *package = *it;
1003  d->m_packaged.erase(it);
1004  if (d->m_packaged.contains(item))
1005  stat |= Referenced;
1006  inPackage = true;
1007  obj = package; // fall through and delete
1008  }
1009 
1010  if (d->m_cache.releaseItem(obj)) {
1011  // Remove any bindings to avoid warnings due to parent change.
1014  QDeclarativeData *d = static_cast<QDeclarativeData*>(p->declarativeData);
1015  if (d->ownContext && d->context)
1016  d->context->clearContext();
1017 
1018  if (inPackage) {
1019  emit destroyingPackage(qobject_cast<QDeclarativePackage*>(obj));
1020  } else {
1021  if (item->scene())
1022  item->scene()->removeItem(item);
1023  }
1024  stat |= Destroyed;
1025  obj->deleteLater();
1026  } else if (!inPackage) {
1027  stat |= Referenced;
1028  }
1029 
1030  return stat;
1031 }
1032 
1064 {
1066  if (!d->m_parts)
1067  d->m_parts = new QDeclarativeVisualDataModelParts(this);
1068  return d->m_parts;
1069 }
1070 
1072 {
1074  if (d->m_visualItemModel)
1075  return d->m_visualItemModel->item(index, viewId, complete);
1076 
1077  if (d->modelCount() <= 0 || !d->m_delegate)
1078  return 0;
1079  QObject *nobj = d->m_cache.getItem(index);
1080  bool needComplete = false;
1081  if (!nobj) {
1082  QDeclarativeContext *ccontext = d->m_context;
1083  if (!ccontext) ccontext = qmlContext(this);
1084  QDeclarativeContext *ctxt = new QDeclarativeContext(ccontext);
1086  if ((!d->m_listModelInterface || !d->m_abstractItemModel) && d->m_listAccessor
1087  && d->m_listAccessor->type() == QDeclarativeListAccessor::ListProperty) {
1088  QDeclarativeContext *objCtxt = ctxt;
1089  objCtxt->setContextObject(d->m_listAccessor->at(index).value<QObject*>());
1090  ctxt = new QDeclarativeContext(ctxt);
1091  QDeclarative_setParent_noEvent(objCtxt, ctxt);
1092  }
1093  ctxt->setContextProperty(QLatin1String("model"), data);
1094  ctxt->setContextObject(data);
1095  d->m_completePending = false;
1096  nobj = d->m_delegate->beginCreate(ctxt);
1097  if (complete) {
1098  d->m_delegate->completeCreate();
1099  } else {
1100  d->m_completePending = true;
1101  needComplete = true;
1102  }
1103  if (nobj) {
1104  QDeclarative_setParent_noEvent(ctxt, nobj);
1105  QDeclarative_setParent_noEvent(data, nobj);
1106  d->m_cache.insertItem(index, nobj);
1107  if (QDeclarativePackage *package = qobject_cast<QDeclarativePackage *>(nobj))
1108  emit createdPackage(index, package);
1109  } else {
1110  delete data;
1111  delete ctxt;
1112  qmlInfo(this, d->m_delegate->errors()) << "Error creating delegate";
1113  }
1114  }
1116  if (!item) {
1117  QDeclarativePackage *package = qobject_cast<QDeclarativePackage *>(nobj);
1118  if (package) {
1119  QObject *o = package->part(QString::fromUtf8(viewId));
1120  item = qobject_cast<QDeclarativeItem *>(o);
1121  if (item)
1122  d->m_packaged.insertMulti(item, package);
1123  }
1124  }
1125  if (!item) {
1126  if (needComplete)
1127  d->m_delegate->completeCreate();
1128  d->m_cache.releaseItem(nobj);
1129  if (!d->m_delegateValidated) {
1130  qmlInfo(d->m_delegate) << QDeclarativeVisualDataModel::tr("Delegate component must be Item type.");
1131  d->m_delegateValidated = true;
1132  }
1133  }
1134  if (d->modelCount()-1 == index && d->m_abstractItemModel && d->m_abstractItemModel->canFetchMore(d->m_root))
1135  d->m_abstractItemModel->fetchMore(d->m_root);
1136 
1137  return item;
1138 }
1139 
1141 {
1143  if (d->m_visualItemModel)
1144  return d->m_visualItemModel->completePending();
1145  return d->m_completePending;
1146 }
1147 
1149 {
1151  if (d->m_visualItemModel) {
1152  d->m_visualItemModel->completeItem();
1153  return;
1154  }
1155 
1156  d->m_delegate->completeCreate();
1157  d->m_completePending = false;
1158 }
1159 
1161 {
1163  if (d->m_visualItemModel)
1164  return d->m_visualItemModel->stringValue(index, name);
1165 
1166  if ((!d->m_listModelInterface || !d->m_abstractItemModel) && d->m_listAccessor) {
1167  if (QObject *object = d->m_listAccessor->at(index).value<QObject*>())
1168  return object->property(name.toUtf8()).toString();
1169  }
1170 
1171  if ((!d->m_listModelInterface && !d->m_abstractItemModel) || !d->m_delegate)
1172  return QString();
1173 
1174  QString val;
1175  QObject *data = 0;
1176  bool tempData = false;
1177 
1178  if (QObject *nobj = d->m_cache.item(index))
1179  data = d->data(nobj);
1180  if (!data) {
1181  data = new QDeclarativeVisualDataModelData(index, this);
1182  tempData = true;
1183  }
1184 
1185  QDeclarativeData *ddata = QDeclarativeData::get(data);
1186  if (ddata && ddata->propertyCache) {
1188  if (prop) {
1189  if (prop->propType == QVariant::String) {
1190  void *args[] = { &val, 0 };
1192  } else if (prop->propType == qMetaTypeId<QVariant>()) {
1193  QVariant v;
1194  void *args[] = { &v, 0 };
1196  val = v.toString();
1197  }
1198  } else {
1199  val = data->property(name.toUtf8()).toString();
1200  }
1201  } else {
1202  val = data->property(name.toUtf8()).toString();
1203  }
1204 
1205  if (tempData)
1206  delete data;
1207 
1208  return val;
1209 }
1210 
1212 {
1214  return val.toInt();
1215  return -1;
1216 }
1217 
1219 {
1221  d->watchedRoles = roles;
1222  d->watchedRoleIds.clear();
1223 }
1224 
1226  const QList<int> &roles)
1227 {
1229  bool changed = false;
1230  if (!d->watchedRoles.isEmpty() && d->watchedRoleIds.isEmpty()) {
1231  foreach (QByteArray r, d->watchedRoles) {
1232  if (d->m_roleNames.contains(r))
1233  d->watchedRoleIds << d->m_roleNames.value(r);
1234  }
1235  }
1236 
1238  iter != d->m_cache.end(); ++iter) {
1239  const int idx = iter.key();
1240 
1241  if (idx >= index && idx < index+count) {
1243  QDeclarativeVisualDataModelData *data = d->data(objRef.obj);
1244  for (int roleIdx = 0; roleIdx < roles.count(); ++roleIdx) {
1245  int role = roles.at(roleIdx);
1246  if (!changed && !d->watchedRoleIds.isEmpty() && d->watchedRoleIds.contains(role))
1247  changed = true;
1248  int propId = data->propForRole(role);
1249  if (propId != -1) {
1250  if (data->hasValue(propId)) {
1251  if (d->m_listModelInterface) {
1252  data->setValue(propId, d->m_listModelInterface->data(idx, role));
1253  } else if (d->m_abstractItemModel) {
1254  QModelIndex index = d->m_abstractItemModel->index(idx, 0, d->m_root);
1255  data->setValue(propId, d->m_abstractItemModel->data(index, role));
1256  }
1257  }
1258  } else {
1259  QString roleName;
1260  if (d->m_listModelInterface)
1261  roleName = d->m_listModelInterface->toString(role);
1262  else if (d->m_abstractItemModel)
1263  roleName = QString::fromUtf8(d->m_abstractItemModel->roleNames().value(role));
1264  qmlInfo(this) << "Changing role not present in item: " << roleName;
1265  }
1266  }
1267  if (d->m_roles.count() == 1) {
1268  // Handle the modelData role we add if there is just one role.
1269  int propId = data->modelDataPropertyId();
1270  if (data->hasValue(propId)) {
1271  int role = d->m_roles.at(0);
1272  if (d->m_listModelInterface) {
1273  data->setValue(propId, d->m_listModelInterface->data(idx, role));
1274  } else if (d->m_abstractItemModel) {
1275  QModelIndex index = d->m_abstractItemModel->index(idx, 0, d->m_root);
1276  data->setValue(propId, d->m_abstractItemModel->data(index, role));
1277  }
1278  }
1279  }
1280  }
1281  }
1282  if (changed)
1283  emit itemsChanged(index, count);
1284 }
1285 
1287 {
1289  if (!count)
1290  return;
1291  // XXX - highly inefficient
1294  iter != d->m_cache.end(); ) {
1295 
1296  if (iter.key() >= index) {
1298  int index = iter.key() + count;
1299  iter = d->m_cache.erase(iter);
1300 
1301  items.insert(index, objRef);
1302 
1303  QDeclarativeVisualDataModelData *data = d->data(objRef.obj);
1304  data->setIndex(index);
1305  } else {
1306  ++iter;
1307  }
1308  }
1309  d->m_cache.unite(items);
1310 
1311  emit itemsInserted(index, count);
1312  emit countChanged();
1313 }
1314 
1316 {
1318  if (!count)
1319  return;
1320  // XXX - highly inefficient
1323  iter != d->m_cache.end(); ) {
1324  if (iter.key() >= index && iter.key() < index + count) {
1326  iter = d->m_cache.erase(iter);
1327  items.insertMulti(-1, objRef); //XXX perhaps better to maintain separately
1328  QDeclarativeVisualDataModelData *data = d->data(objRef.obj);
1329  data->setIndex(-1);
1330  } else if (iter.key() >= index + count) {
1332  int index = iter.key() - count;
1333  iter = d->m_cache.erase(iter);
1334  items.insert(index, objRef);
1335  QDeclarativeVisualDataModelData *data = d->data(objRef.obj);
1336  data->setIndex(index);
1337  } else {
1338  ++iter;
1339  }
1340  }
1341 
1342  d->m_cache.unite(items);
1343  emit itemsRemoved(index, count);
1344  emit countChanged();
1345 }
1346 
1348 {
1350  // XXX - highly inefficient
1353  iter != d->m_cache.end(); ) {
1354 
1355  if (iter.key() >= from && iter.key() < from + count) {
1357  int index = iter.key() - from + to;
1358  iter = d->m_cache.erase(iter);
1359 
1360  items.insert(index, objRef);
1361 
1362  QDeclarativeVisualDataModelData *data = d->data(objRef.obj);
1363  data->setIndex(index);
1364  } else {
1365  ++iter;
1366  }
1367  }
1369  iter != d->m_cache.end(); ) {
1370 
1371  int diff = from > to ? count : -count;
1372  if (iter.key() >= qMin(from,to) && iter.key() < qMax(from+count,to+count)) {
1374  int index = iter.key() + diff;
1375  iter = d->m_cache.erase(iter);
1376 
1377  items.insert(index, objRef);
1378 
1379  QDeclarativeVisualDataModelData *data = d->data(objRef.obj);
1380  data->setIndex(index);
1381  } else {
1382  ++iter;
1383  }
1384  }
1385  d->m_cache.unite(items);
1386 
1387  emit itemsMoved(from, to, count);
1388 }
1389 
1391 {
1393  if (parent == d->m_root)
1394  _q_itemsInserted(begin, end - begin + 1);
1395 }
1396 
1398 {
1400  if (parent == d->m_root)
1401  _q_itemsRemoved(begin, end - begin + 1);
1402 }
1403 
1404 void QDeclarativeVisualDataModel::_q_rowsMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationRow)
1405 {
1407  const int count = sourceEnd - sourceStart + 1;
1408  if (destinationParent == d->m_root && sourceParent == d->m_root) {
1409  _q_itemsMoved(sourceStart, sourceStart > destinationRow ? destinationRow : destinationRow-count, count);
1410  } else if (sourceParent == d->m_root) {
1411  _q_itemsRemoved(sourceStart, count);
1412  } else if (destinationParent == d->m_root) {
1413  _q_itemsInserted(destinationRow, count);
1414  }
1415 }
1416 
1418 {
1420  if (begin.parent() == d->m_root)
1421  _q_itemsChanged(begin.row(), end.row() - begin.row() + 1, d->m_roles);
1422 }
1423 
1425 {
1427  _q_itemsChanged(0, count(), d->m_roles);
1428 }
1429 
1431 {
1433  d->m_root = QModelIndex();
1434  emit modelReset();
1436  if (d->m_abstractItemModel && d->m_abstractItemModel->canFetchMore(d->m_root))
1437  d->m_abstractItemModel->fetchMore(d->m_root);
1438 }
1439 
1441 {
1443  emit createdItem(index, qobject_cast<QDeclarativeItem*>(package->part(d->m_part)));
1444 }
1445 
1447 {
1449  emit destroyingItem(qobject_cast<QDeclarativeItem*>(package->part(d->m_part)));
1450 }
1451 
1453 
1455 
1456 #include <qdeclarativevisualitemmodel.moc>
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
double d
Definition: qnumeric_p.h:62
The QMetaObject class contains meta-information about Qt objects.
Definition: qobjectdefs.h:304
virtual QVariant data(int index, int role) const =0
Returns the data at the given index for the specified roles.
QDeclarativeContextData * context
QDeclarativeVisualDataModelData * data(QObject *item)
QDeclarativePropertyCache * propertyCache
void itemsMoved(int from, int to, int count)
void destroyingItem(QDeclarativeItem *item)
QDeclarativeComponent * delegate() const
static QDeclarativeData * get(const QObject *object, bool create=false)
The QHash::const_iterator class provides an STL-style const iterator for QHash and QMultiHash...
Definition: qhash.h:395
virtual void propertyCreated(int, QMetaPropertyBuilder &)
int type
Definition: qmetatype.cpp:239
void itemsInserted(int index, int count)
void _q_itemsRemoved(int index, int count)
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
void _q_rowsInserted(const QModelIndex &, int, int)
#define QML_DECLARE_TYPE(TYPE)
Definition: qdeclarative.h:56
void _q_rowsMoved(const QModelIndex &, int, int, const QModelIndex &, int)
QDeclarativeGuard< QDeclarativeContext > m_context
#define it(className, varName)
virtual int count() const =0
Returns the number of data entries in the model.
The QMetaPropertyBuilder class enables modifications to a property definition on a meta object builde...
QByteArray toUtf8() const Q_REQUIRED_RESULT
Returns a UTF-8 representation of the string as a QByteArray.
Definition: qstring.cpp:4074
static int metacall(QObject *, Call, int, void **)
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const =0
Returns the number of rows under the given parent.
int indexOf(QDeclarativeItem *item, QObject *objectContext) const
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
#define SLOT(a)
Definition: qobjectdefs.h:226
QString toString() const
Returns the variant as a QString if the variant has type() String , Bool , ByteArray ...
Definition: qvariant.cpp:2270
QDeclarativeVisualDataModelParts(QDeclarativeVisualDataModel *parent)
virtual int createProperty(const char *, const char *)
static const QMetaObject staticMetaObject
This variable stores the meta-object for the class.
Definition: qobject.h:128
ReleaseFlags release(QDeclarativeItem *item)
static QString tr(const char *sourceText, const char *comment=0, int n=-1)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
void _q_itemsMoved(int from, int to, int count)
void _q_createdPackage(int index, QDeclarativePackage *package)
virtual QString toString(int role) const =0
Returns a string description of the specified role.
virtual int indexOf(QDeclarativeItem *item, QObject *objectContext) const
The QString class provides a Unicode character string.
Definition: qstring.h:83
T * qobject_cast(QObject *object)
Definition: qobject.h:375
The QHash class is a template class that provides a hash-table-based dictionary.
Definition: qdatastream.h:66
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
Q_DECLARATIVE_EXPORT QDeclarativeContext * qmlContext(const QObject *)
#define Q_D(Class)
Definition: qglobal.h:2482
#define Q_SIGNALS
Definition: qobjectdefs.h:72
static const uint base
Definition: qurl.cpp:268
static QObjectPrivate * get(QObject *o)
Definition: qobject_p.h:177
QModelIndex parent() const
Returns the parent of the model index, or QModelIndex() if it has no parent.
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
static QDeclarativeVisualDataModelPrivate * get(QDeclarativeVisualDataModel *m)
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition: qhash.h:753
void setParent(QObject *)
Makes the object a child of parent.
Definition: qobject.cpp:1950
QDeclarativeGuard< QDeclarativeVisualDataModel > m_visualItemModel
#define Q_Q(Class)
Definition: qglobal.h:2483
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
Q_INVOKABLE QVariant parentModelIndex() const
virtual ReleaseFlags release(QDeclarativeItem *item)
virtual int createProperty(const char *, const char *)
void setContextObject(QObject *)
Set the context object.
QVariant value(const QByteArray &) const
virtual QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const =0
Returns the index of the item in the model specified by the given row, column and parent index...
static QDeclarativeItem * children_at(QDeclarativeListProperty< QDeclarativeItem > *prop, int index)
#define SIGNAL(a)
Definition: qobjectdefs.h:227
static QString toString(Register *reg, int type, bool *ok=0)
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
QDeclarativeItem * item(int index, bool complete=true)
Q_INVOKABLE QVariant modelIndex(int idx) const
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
VDMDelegateDataType(const QMetaObject *base, QDeclarativeEngine *engine)
int indexOf(QDeclarativeItem *item) const
The QDeclarativeComponent class encapsulates a QML component definition.
The QDeclarativeItem class provides the most basic of all visual items in QML.
void createdPackage(int index, QDeclarativePackage *package)
virtual bool hasChildren(const QModelIndex &parent=QModelIndex()) const
Returns true if parent has any children; otherwise returns false.
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
Definition: qobject.cpp:2580
void removeItem(QGraphicsItem *item)
Removes the item item and all its children from the scene.
int row() const
Returns the row this model index refers to.
const char * name
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
#define emit
Definition: qobjectdefs.h:76
Data * property(const QScriptDeclarativeClass::Identifier &id) const
static QString fromUtf8(const char *, int size=-1)
Returns a QString initialized with the first size bytes of the UTF-8 string str.
Definition: qstring.cpp:4302
bool isEmpty() const
Returns true if the hash contains no items; otherwise returns false.
Definition: qhash.h:297
static const char * data(const QByteArray &arr)
QDeclarativeGuard< QAbstractItemModel > m_abstractItemModel
static Bigint * diff(Bigint *a, Bigint *b)
T findChild(const QString &aName=QString()) const
Returns the child of this object that can be cast into type T and that is called name, or 0 if there is no such object.
Definition: qobject.h:158
void _q_dataChanged(const QModelIndex &, const QModelIndex &)
static void children_append(QDeclarativeListProperty< QDeclarativeItem > *prop, QDeclarativeItem *item)
The QListModelInterface class can be subclassed to provide C++ models to QDeclarativeGraphics Views...
QVariant contextProperty(const QString &) const
Returns the value of the name property for this context as a QVariant.
virtual QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const =0
Returns the data stored under the given role for the item referred to by the index.
QObject * part(const QString &=QString())
static QVariant fromValue(const T &value)
Returns a QVariant containing a copy of value.
Definition: qvariant.h:336
virtual QString stringValue(int index, const QString &role)
QAbstractDeclarativeData * declarativeData
Definition: qobject_p.h:214
#define Q_OBJECT
Definition: qobjectdefs.h:157
static QHash< QObject *, QDeclarativeVisualItemModelAttached * > attachedProperties
virtual QDeclarativeItem * item(int index, bool complete=true)
static QDeclarativeVisualItemModelAttached * qmlAttachedProperties(QObject *obj)
void setContextProperty(const QString &, QObject *)
Set the value of the name property on this context.
T & first()
Returns a reference to the first item in the list.
Definition: qlist.h:282
static bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *member)
Disconnects signal in object sender from method in object receiver.
Definition: qobject.cpp:2895
void setRootIndex(const QVariant &root)
const QHash< int, QByteArray > & roleNames() const
Returns the model&#39;s role names.
#define Q_DECLARE_PUBLIC(Class)
Definition: qglobal.h:2477
QDeclarativeGuard< QDeclarativeVisualDataModel > m_model
static int children_count(QDeclarativeListProperty< QDeclarativeItem > *prop)
virtual void setWatchedRoles(QList< QByteArray > roles)
QHash< QObject *, QDeclarativePackage * > m_packaged
QDeclarativeVisualDataModelDataMetaObject * m_meta
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
const char * name() const
Returns this property&#39;s name.
QDeclarativeGuard< QListModelInterface > m_listModelInterface
The QDeclarativeEngine class provides an environment for instantiating QML components.
void destroyingPackage(QDeclarativePackage *package)
void _q_itemsChanged(int, int, const QList< int > &)
void QDeclarative_setParent_noEvent(QObject *object, QObject *parent)
Makes the object a child of parent.
virtual QList< int > roles() const =0
Returns the list of roles for which the list model interface provides data.
const Key key(const T &value) const
Returns the first key mapped to value.
Definition: qhash.h:674
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
T & last()
Returns a reference to the last item in the list.
Definition: qlist.h:284
The QHash::iterator class provides an STL-style non-const iterator for QHash and QMultiHash.
Definition: qhash.h:330
The QModelIndex class is used to locate data in a data model.
if(void) toggleToolbarShown
QVariant read(const QObject *obj) const
Reads the property&#39;s value from the given object.
void _q_rowsRemoved(const QModelIndex &, int, int)
iterator begin()
Returns an STL-style iterator pointing to the first item in the hash.
Definition: qhash.h:464
QDeclarativeListProperty< QDeclarativeItem > children()
static const char * get(QDBusError::ErrorType code)
Definition: qdbuserror.cpp:141
T qvariant_cast(const QVariant &)
Definition: qvariant.h:571
static void setIndex(int *index, int candidate, int min, int max, bool isIncreasing)
Definition: qmdiarea.cpp:226
The QDeclarativeContext class defines a context within a QML engine.
QDeclarativeVisualDataModelParts * m_parts
quint16 index
QVariant property(const char *name) const
Returns the value of the object&#39;s name property.
Definition: qobject.cpp:3807
QObject * parent
Definition: qobject.h:92
int count(const Key &key) const
Returns the number of items associated with the key.
Definition: qhash.h:719
The QMetaProperty class provides meta-data about a property.
Definition: qmetaobject.h:176
int qstrcmp(const QByteArray &str1, const char *str2)
Definition: qbytearray.cpp:336
QGraphicsScene * scene() const
Returns the current scene for the item, or 0 if the item is not stored in a scene.
void setDelegate(QDeclarativeComponent *)
void _q_destroyingPackage(QDeclarativePackage *package)
static QDeclarativeVisualItemModelAttached * properties(QObject *obj)
static QDeclarativeContext * contextForObject(const QObject *)
Returns the QDeclarativeContext for the object, or 0 if no context has been set.
QDeclarativeVisualDataModelDataMetaObject(QObject *parent, QDeclarativeOpenMetaObjectType *type)
iterator find(const Key &key)
Returns an iterator pointing to the item with the key in the hash.
Definition: qhash.h:865
void itemsChanged(int index, int count)
void setWritable(bool value)
Sets this property to writable if value is true.
iterator insertMulti(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition: qhash.h:772
QDeclarativeInfo qmlInfo(const QObject *me)
T value() const
Returns the stored value converted to the template type T.
Definition: qvariant.h:332
QDeclarativeVisualDataModelData(int index, QDeclarativeVisualDataModel *model)
virtual QString stringValue(int index, const QString &role)
static const KeyPair *const end
void _q_itemsInserted(int index, int count)
void createdItem(int index, QDeclarativeItem *item)
void deleteLater()
Schedules this object for deletion.
Definition: qobject.cpp:2145
void propertyCreated(int, QMetaPropertyBuilder &prop)
QVariant rootIndex() const
void itemsRemoved(int index, int count)
virtual const QMetaObject * metaObject() const
Returns a pointer to the meta-object of this object.
QMetaProperty property(int index) const
Returns the meta-data for the property with the given index.