diff options
author | Andrew den Exter <andrew.den-exter@nokia.com> | 2012-07-10 17:01:52 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-07-25 02:15:15 +0200 |
commit | 7daab8039abc32ab5be5706a08cb58905fe0e0b6 (patch) | |
tree | 9ceb8afdeb37ac4d9bc089545e73e31040b847e4 /src/quick/items/qquickvisualadaptormodel.cpp | |
parent | b355aacb6e5c4f9b7ebb317125409ea0959d11d6 (diff) |
Remove QListModelInterface.
Implement ListModel and XmlListModel using QAbstractListModel
instead.
Task-number: QTBUG-15728
Change-Id: I14e03d90883d341f4b1d89c1e9fc9dc1534fde78
Reviewed-by: Glenn Watson <glenn.watson@nokia.com>
Diffstat (limited to 'src/quick/items/qquickvisualadaptormodel.cpp')
-rw-r--r-- | src/quick/items/qquickvisualadaptormodel.cpp | 140 |
1 files changed, 5 insertions, 135 deletions
diff --git a/src/quick/items/qquickvisualadaptormodel.cpp b/src/quick/items/qquickvisualadaptormodel.cpp index f7cd3e2764..b17ab26373 100644 --- a/src/quick/items/qquickvisualadaptormodel.cpp +++ b/src/quick/items/qquickvisualadaptormodel.cpp @@ -153,7 +153,7 @@ public: const QList<QQuickVisualDataModelItem *> &items, int index, int count, - const QList<int> &roles) const + const QVector<int> &roles) const { bool changed = roles.isEmpty() && !watchedRoles.isEmpty(); if (!changed && !watchedRoles.isEmpty() && watchedRoleIds.isEmpty()) { @@ -461,8 +461,8 @@ public: vdm, SLOT(_q_rowsInserted(QModelIndex,int,int))); QObject::disconnect(aim, SIGNAL(rowsRemoved(QModelIndex,int,int)), vdm, SLOT(_q_rowsRemoved(QModelIndex,int,int))); - QObject::disconnect(aim, SIGNAL(dataChanged(QModelIndex,QModelIndex)), - vdm, SLOT(_q_dataChanged(QModelIndex,QModelIndex))); + QObject::disconnect(aim, SIGNAL(dataChanged(QModelIndex,QModelIndex,QVector<int>)), + vdm, SLOT(_q_dataChanged(QModelIndex,QModelIndex,QVector<int>))); QObject::disconnect(aim, SIGNAL(rowsMoved(QModelIndex,int,int,QModelIndex,int)), vdm, SLOT(_q_rowsMoved(QModelIndex,int,int,QModelIndex,int))); QObject::disconnect(aim, SIGNAL(modelReset()), @@ -553,123 +553,6 @@ public: }; //----------------------------------------------------------------- -// QListModelInterface -//----------------------------------------------------------------- - -class QQuickVDMListModelInterfaceData : public QQuickVDMCachedModelData -{ -public: - QQuickVDMListModelInterfaceData(QQuickVisualDataModelItemMetaType *metaType, VDMModelDelegateDataType *dataType, int index) - : QQuickVDMCachedModelData(metaType, dataType, index) - { - } - - QVariant value(int role) const - { - return type->model->lmi()->data(index, role); - } - - void setValue(int, const QVariant &) {} - - v8::Handle<v8::Value> get() - { - if (type->constructor.IsEmpty()) { - v8::HandleScope handleScope; - v8::Context::Scope contextScope(engine->context()); - type->initializeConstructor(engineData(engine)); - } - v8::Local<v8::Object> data = type->constructor->NewInstance(); - data->SetExternalResource(this); - ++scriptRef; - return data; - } -}; - -class VDMListModelInterfaceDataType : public VDMModelDelegateDataType -{ -public: - VDMListModelInterfaceDataType(QQuickVisualAdaptorModel *model) - : VDMModelDelegateDataType(model) - { - } - - int count(const QQuickVisualAdaptorModel &model) const - { - return model.lmi()->count(); - } - - void cleanup(QQuickVisualAdaptorModel &model, QQuickVisualDataModel *vdm) const - { - QListModelInterface *lmi = model.lmi(); - if (lmi && vdm) { - QObject::disconnect(lmi, SIGNAL(itemsChanged(int,int,QList<int>)), - vdm, SLOT(_q_itemsChanged(int,int,QList<int>))); - QObject::disconnect(lmi, SIGNAL(itemsInserted(int,int)), - vdm, SLOT(_q_itemsInserted(int,int))); - QObject::disconnect(lmi, SIGNAL(itemsRemoved(int,int)), - vdm, SLOT(_q_itemsRemoved(int,int))); - QObject::disconnect(lmi, SIGNAL(itemsMoved(int,int,int)), - vdm, SLOT(_q_itemsMoved(int,int,int))); - } - const_cast<VDMListModelInterfaceDataType *>(this)->release(); - } - - QVariant value(const QQuickVisualAdaptorModel &model, int index, const QString &role) const - { - QHash<QByteArray, int>::const_iterator it = roleNames.find(role.toUtf8()); - return it != roleNames.end() && model - ? model.lmi()->data(index, *it) - : QVariant(); - } - - QQuickVisualDataModelItem *createItem( - QQuickVisualAdaptorModel &model, - QQuickVisualDataModelItemMetaType *metaType, - QQmlEngine *engine, - int index) const - { - VDMListModelInterfaceDataType *dataType = const_cast<VDMListModelInterfaceDataType *>(this); - if (!metaObject) - dataType->initializeMetaType(model, engine); - return new QQuickVDMListModelInterfaceData(metaType, dataType, index); - } - - void initializeMetaType(QQuickVisualAdaptorModel &model, QQmlEngine *engine) - { - QMetaObjectBuilder builder; - setModelDataType<QQuickVDMListModelInterfaceData>(&builder, this); - - const QByteArray propertyType = QByteArrayLiteral("QVariant"); - - const QListModelInterface * const listModelInterface = model.lmi(); - const QList<int> roles = listModelInterface->roles(); - for (int propertyId = 0; propertyId < roles.count(); ++propertyId) { - const int role = roles.at(propertyId); - const QString roleName = listModelInterface->toString(role); - const QByteArray propertyName = roleName.toUtf8(); - - propertyRoles.append(role); - roleNames.insert(propertyName, role); - addProperty(&builder, propertyId, propertyName, propertyType); - - } - if (propertyRoles.count() == 1) { - hasModelData = true; - const int role = roles.first(); - const QByteArray propertyName = QByteArrayLiteral("modelData"); - - propertyRoles.append(role); - roleNames.insert(propertyName, role); - addProperty(&builder, 1, propertyName, propertyType); - } - - metaObject = builder.toMetaObject(); - *static_cast<QMetaObject *>(this) = *metaObject; - propertyCache = new QQmlPropertyCache(engine, metaObject); - } -}; - -//----------------------------------------------------------------- // QQuickListAccessor //----------------------------------------------------------------- @@ -1015,25 +898,14 @@ void QQuickVisualAdaptorModel::setModel(const QVariant &variant, QQuickVisualDat vdm, QQuickVisualDataModel, SLOT(_q_rowsInserted(QModelIndex,int,int))); qmlobject_connect(model, QAbstractItemModel, SIGNAL(rowsRemoved(QModelIndex,int,int)), vdm, QQuickVisualDataModel, SLOT(_q_rowsRemoved(QModelIndex,int,int))); - qmlobject_connect(model, QAbstractItemModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), - vdm, QQuickVisualDataModel, SLOT(_q_dataChanged(QModelIndex,QModelIndex))); + qmlobject_connect(model, QAbstractItemModel, SIGNAL(dataChanged(QModelIndex,QModelIndex,QVector<int>)), + vdm, QQuickVisualDataModel, SLOT(_q_dataChanged(QModelIndex,QModelIndex,QVector<int>))); qmlobject_connect(model, QAbstractItemModel, SIGNAL(rowsMoved(QModelIndex,int,int,QModelIndex,int)), vdm, QQuickVisualDataModel, SLOT(_q_rowsMoved(QModelIndex,int,int,QModelIndex,int))); qmlobject_connect(model, QAbstractItemModel, SIGNAL(modelReset()), vdm, QQuickVisualDataModel, SLOT(_q_modelReset())); qmlobject_connect(model, QAbstractItemModel, SIGNAL(layoutChanged()), vdm, QQuickVisualDataModel, SLOT(_q_layoutChanged())); - } else if (QListModelInterface *model = qobject_cast<QListModelInterface *>(object)) { - accessors = new VDMListModelInterfaceDataType(this); - - qmlobject_connect(model, QListModelInterface, SIGNAL(itemsChanged(int,int,QList<int>)), - vdm, QQuickVisualDataModel, SLOT(_q_itemsChanged(int,int,QList<int>))); - qmlobject_connect(model, QListModelInterface, SIGNAL(itemsInserted(int,int)), - vdm, QQuickVisualDataModel, SLOT(_q_itemsInserted(int,int))); - qmlobject_connect(model, QListModelInterface, SIGNAL(itemsRemoved(int,int)), - vdm, QQuickVisualDataModel, SLOT(_q_itemsRemoved(int,int))); - qmlobject_connect(model, QListModelInterface, SIGNAL(itemsMoved(int,int,int)), - vdm, QQuickVisualDataModel, SLOT(_q_itemsMoved(int,int,int))); } else { accessors = new VDMObjectDelegateDataType; } @@ -1080,6 +952,4 @@ QQuickVisualAdaptorModelEngineData::~QQuickVisualAdaptorModelEngineData() QT_END_NAMESPACE -QML_DECLARE_TYPE(QListModelInterface) - #include <qquickvisualadaptormodel.moc> |