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
This commit is contained in:
parent
5220782be1
commit
24f7593788
@ -84,6 +84,7 @@ void CoreBindingsPlugin::registerTypes(const char *uri)
|
||||
qRegisterMetaType<Plasma::Service*>("Service");
|
||||
qmlRegisterInterface<Plasma::ServiceJob>("ServiceJob");
|
||||
qRegisterMetaType<Plasma::ServiceJob*>("ServiceJob");
|
||||
qmlRegisterType<QAbstractItemModel>();
|
||||
|
||||
/*qmlRegisterInterface<Plasma::DataSource>("DataSource");
|
||||
qRegisterMetaType<Plasma::DataSource*>("DataSource");*/
|
||||
|
@ -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<QAbstractItemModel *>(source);
|
||||
if (!model) {
|
||||
kWarning() << "Error: QAbstractItemModel type expected";
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (sourceModel()) {
|
||||
disconnect(sourceModel(), SIGNAL(modelReset()), this, SLOT(syncRoleNames()));
|
||||
}
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user