Allow model to be set to 0

This commit is contained in:
Aurélien Gâteau 2012-08-28 18:08:47 +02:00
parent 91313b5eb5
commit bfcc27e01d

View File

@ -67,13 +67,21 @@ int SortFilterModel::roleNameToId(const QString &name)
void SortFilterModel::setModel(QObject *source)
{
QAbstractItemModel *model = qobject_cast<QAbstractItemModel *>(source);
if (!model) {
kWarning() << "Error: QAbstractItemModel type expected";
return;
QAbstractItemModel *model = 0;
if (source) {
model = qobject_cast<QAbstractItemModel *>(source);
if (!model) {
kWarning() << "Error: QAbstractItemModel type expected";
return;
}
}
connect(model, SIGNAL(modelReset()), this, SLOT(syncRoleNames()));
if (sourceModel()) {
disconnect(sourceModel(), SIGNAL(modelReset()), this, SLOT(syncRoleNames()));
}
if (model) {
connect(model, SIGNAL(modelReset()), this, SLOT(syncRoleNames()));
}
QSortFilterProxyModel::setSourceModel(model);
sourceModelChanged(model);
}