From 24f7593788644515368f629b42786ffd309b58d9 Mon Sep 17 00:00:00 2001 From: Aleix Pol Date: Wed, 29 Aug 2012 17:35:56 +0200 Subject: [PATCH] Improve QAbstractItemModel integration in Plasma.Core QML components Introduces QAbstractItemModel to QDeclarative when setting up the plasma core components. This way we don't have to cast to the type ourselves and produce proper QML errors if the type is not correct. This happened with Plasma::SortProxyModel. REVIEW: 106267 --- declarativeimports/core/corebindingsplugin.cpp | 1 + declarativeimports/core/datamodel.cpp | 13 ++----------- declarativeimports/core/datamodel.h | 5 ++--- 3 files changed, 5 insertions(+), 14 deletions(-) diff --git a/declarativeimports/core/corebindingsplugin.cpp b/declarativeimports/core/corebindingsplugin.cpp index f08d8b36d..92d0befba 100644 --- a/declarativeimports/core/corebindingsplugin.cpp +++ b/declarativeimports/core/corebindingsplugin.cpp @@ -84,6 +84,7 @@ void CoreBindingsPlugin::registerTypes(const char *uri) qRegisterMetaType("Service"); qmlRegisterInterface("ServiceJob"); qRegisterMetaType("ServiceJob"); + qmlRegisterType(); /*qmlRegisterInterface("DataSource"); qRegisterMetaType("DataSource");*/ diff --git a/declarativeimports/core/datamodel.cpp b/declarativeimports/core/datamodel.cpp index b0c18a6fc..c1ed999fc 100644 --- a/declarativeimports/core/datamodel.cpp +++ b/declarativeimports/core/datamodel.cpp @@ -65,21 +65,12 @@ int SortFilterModel::roleNameToId(const QString &name) return m_roleIds.value(name); } -void SortFilterModel::setModel(QObject *source) +void SortFilterModel::setModel(QAbstractItemModel* model) { - if (source == sourceModel()) { + if (model == sourceModel()) { return; } - QAbstractItemModel *model = 0; - if (source) { - model = qobject_cast(source); - if (!model) { - kWarning() << "Error: QAbstractItemModel type expected"; - return; - } - } - if (sourceModel()) { disconnect(sourceModel(), SIGNAL(modelReset()), this, SLOT(syncRoleNames())); } diff --git a/declarativeimports/core/datamodel.h b/declarativeimports/core/datamodel.h index 803a3e4c4..0943b6827 100644 --- a/declarativeimports/core/datamodel.h +++ b/declarativeimports/core/datamodel.h @@ -41,7 +41,7 @@ class SortFilterModel : public QSortFilterProxyModel /** * The source model of this sorting proxy model. It has to inherit QAbstractItemModel (ListModel is not supported) */ - Q_PROPERTY(QObject *sourceModel READ sourceModel WRITE setModel NOTIFY sourceModelChanged) + Q_PROPERTY(QAbstractItemModel *sourceModel READ sourceModel WRITE setModel NOTIFY sourceModelChanged) /** * The regular expression for the filter, only items with their filterRole matching filterRegExp will be displayed @@ -74,8 +74,7 @@ public: SortFilterModel(QObject* parent=0); ~SortFilterModel(); - //FIXME: find a way to make QML understnd QAbstractItemModel - void setModel(QObject *source); + void setModel(QAbstractItemModel *source); void setFilterRegExp(const QString &exp); QString filterRegExp() const;