diff options
author | Aaron McCarthy <aaron.mccarthy@jollamobile.com> | 2015-08-18 13:00:58 +1000 |
---|---|---|
committer | Aaron McCarthy <mccarthy.aaron@gmail.com> | 2015-09-07 00:45:51 +0000 |
commit | 8fb58aa448de42ebeb17bc5d9c74e6ee78319292 (patch) | |
tree | 28e985b1f576c28ee4e7155efb85f70083b05069 /src | |
parent | 8e47405edb5112e2b0403e536aaecd5c14f09966 (diff) | |
download | qtlocation-8fb58aa448de42ebeb17bc5d9c74e6ee78319292.tar.gz |
Use a shared dynamic meta object for model data
Change-Id: Ibc3100064a356399ba9898aac84570eaab609a0b
Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/imports/location/qdeclarativegeomapitemview.cpp | 37 | ||||
-rw-r--r-- | src/imports/location/qdeclarativegeomapitemview_p.h | 4 |
2 files changed, 31 insertions, 10 deletions
diff --git a/src/imports/location/qdeclarativegeomapitemview.cpp b/src/imports/location/qdeclarativegeomapitemview.cpp index 85f3f642..624d2983 100644 --- a/src/imports/location/qdeclarativegeomapitemview.cpp +++ b/src/imports/location/qdeclarativegeomapitemview.cpp @@ -73,13 +73,15 @@ QT_BEGIN_NAMESPACE QDeclarativeGeoMapItemView::QDeclarativeGeoMapItemView(QQuickItem *parent) : QObject(parent), componentCompleted_(false), delegate_(0), - itemModel_(0), map_(0), fitViewport_(false) + itemModel_(0), map_(0), fitViewport_(false), m_metaObjectType(0) { } QDeclarativeGeoMapItemView::~QDeclarativeGeoMapItemView() { removeInstantiatedItems(); + if (m_metaObjectType) + m_metaObjectType->release(); } /*! @@ -118,6 +120,10 @@ void QDeclarativeGeoMapItemView::setModel(const QVariant &model) disconnect(itemModel_, SIGNAL(dataChanged(QModelIndex,QModelIndex,QVector<int>)), this, SLOT(itemModelDataChanged(QModelIndex,QModelIndex,QVector<int>))); + removeInstantiatedItems(); + m_metaObjectType->release(); + m_metaObjectType = 0; + itemModel_ = 0; } @@ -132,9 +138,14 @@ void QDeclarativeGeoMapItemView::setModel(const QVariant &model) this, SLOT(itemModelRowsMoved(QModelIndex,int,int,QModelIndex,int))); connect(itemModel_, SIGNAL(dataChanged(QModelIndex,QModelIndex,QVector<int>)), this, SLOT(itemModelDataChanged(QModelIndex,QModelIndex,QVector<int>))); + + m_metaObjectType = new QQmlOpenMetaObjectType(&QObject::staticMetaObject, 0); + foreach (const QByteArray &name, itemModel_->roleNames()) + m_metaObjectType->createProperty(name); + + instantiateAllItems(); } - repopulate(); emit modelChanged(); } @@ -314,17 +325,14 @@ void QDeclarativeGeoMapItemView::removeInstantiatedItems() /*! \internal - Removes and repopulates all items. + + Instantiates all items. */ -void QDeclarativeGeoMapItemView::repopulate() +void QDeclarativeGeoMapItemView::instantiateAllItems() { - // Free any earlier instances - removeInstantiatedItems(); - if (!componentCompleted_ || !map_ || !delegate_ || !itemModel_) return; - // Iterate model data and instantiate delegates. for (int i = 0; i < itemModel_->rowCount(); ++i) { const QModelIndex index = itemModel_->index(i, 0); ItemData *itemData = createItemForIndex(index); @@ -341,6 +349,16 @@ void QDeclarativeGeoMapItemView::repopulate() /*! \internal + Removes and repopulates all items. +*/ +void QDeclarativeGeoMapItemView::repopulate() +{ + removeInstantiatedItems(); + instantiateAllItems(); +} + +/*! + \internal */ QDeclarativeGeoMapItemView::ItemData *QDeclarativeGeoMapItemView::createItemForIndex(const QModelIndex &index) { @@ -351,7 +369,7 @@ QDeclarativeGeoMapItemView::ItemData *QDeclarativeGeoMapItemView::createItemForI ItemData *itemData = new ItemData; itemData->modelData = new QObject; - itemData->modelDataMeta = new QQmlOpenMetaObject(itemData->modelData); + itemData->modelDataMeta = new QQmlOpenMetaObject(itemData->modelData, m_metaObjectType, false); itemData->context = new QQmlContext(qmlContext(this)); QHashIterator<int, QByteArray> iterator(itemModel_->roleNames()); @@ -395,7 +413,6 @@ QDeclarativeGeoMapItemView::ItemData::~ItemData() delete item; delete context; delete modelData; - //delete modelDataMeta; } #include "moc_qdeclarativegeomapitemview_p.cpp" diff --git a/src/imports/location/qdeclarativegeomapitemview_p.h b/src/imports/location/qdeclarativegeomapitemview_p.h index 1103fbe2..fa91e3ad 100644 --- a/src/imports/location/qdeclarativegeomapitemview_p.h +++ b/src/imports/location/qdeclarativegeomapitemview_p.h @@ -51,6 +51,7 @@ class QQuickItem; class QDeclarativeGeoMap; class QDeclarativeGeoMapItemBase; class QQmlOpenMetaObject; +class QQmlOpenMetaObjectType; class QDeclarativeGeoMapItemView : public QObject, public QQmlParserStatus { @@ -78,6 +79,7 @@ public: void setMap(QDeclarativeGeoMap *); void repopulate(); void removeInstantiatedItems(); + void instantiateAllItems(); qreal zValue(); void setZValue(qreal zValue); @@ -125,6 +127,8 @@ private: QVector<ItemData *> m_itemData; bool fitViewport_; + QQmlOpenMetaObjectType *m_metaObjectType; + friend class QTypeInfo<ItemData>; }; |