KSPM: Make the setSelectionModel method public.

Handle the possibility that there may be no selectionModel in the
implementation.
wilder
Stephen Kelly 11 years ago
parent f253ab53c0
commit 22f3b70f39
  1. 30
      src/kselectionproxymodel.cpp
  2. 2
      src/kselectionproxymodel.h

@ -430,6 +430,7 @@ class KSelectionProxyModelPrivate
public: public:
KSelectionProxyModelPrivate(KSelectionProxyModel *model) KSelectionProxyModelPrivate(KSelectionProxyModel *model)
: q_ptr(model), : q_ptr(model),
m_indexMapper(0),
m_startWithChildTrees(false), m_startWithChildTrees(false),
m_omitChildren(false), m_omitChildren(false),
m_omitDescendants(false), m_omitDescendants(false),
@ -811,7 +812,7 @@ void KSelectionProxyModelPrivate::sourceLayoutChanged()
return; return;
} }
if (!m_selectionModel.data()->hasSelection()) { if (!m_selectionModel || !m_selectionModel.data()->hasSelection()) {
return; return;
} }
@ -1026,7 +1027,7 @@ void KSelectionProxyModelPrivate::sourceRowsAboutToBeInserted(const QModelIndex
Q_ASSERT(parent.isValid() ? parent.model() == q->sourceModel() : true); Q_ASSERT(parent.isValid() ? parent.model() == q->sourceModel() : true);
if (!m_selectionModel.data()->hasSelection()) { if (!m_selectionModel || !m_selectionModel.data()->hasSelection()) {
return; return;
} }
@ -1199,7 +1200,7 @@ void KSelectionProxyModelPrivate::sourceRowsAboutToBeRemoved(const QModelIndex &
Q_ASSERT(parent.isValid() ? parent.model() == q->sourceModel() : true); Q_ASSERT(parent.isValid() ? parent.model() == q->sourceModel() : true);
if (!m_selectionModel.data()->hasSelection()) { if (!m_selectionModel || !m_selectionModel.data()->hasSelection()) {
return; return;
} }
@ -1288,7 +1289,7 @@ void KSelectionProxyModelPrivate::sourceRowsRemoved(const QModelIndex &parent, i
Q_ASSERT(parent.isValid() ? parent.model() == q->sourceModel() : true); Q_ASSERT(parent.isValid() ? parent.model() == q->sourceModel() : true);
if (!m_selectionModel.data()->hasSelection()) { if (!m_selectionModel || !m_selectionModel.data()->hasSelection()) {
return; return;
} }
@ -2148,7 +2149,9 @@ void KSelectionProxyModel::setFilterBehavior(FilterBehavior behavior)
} }
emit filterBehaviorChanged(); emit filterBehaviorChanged();
d->resetInternalData(); d->resetInternalData();
d->selectionChanged(d->m_selectionModel.data()->selection(), QItemSelection()); if (d->m_selectionModel) {
d->selectionChanged(d->m_selectionModel.data()->selection(), QItemSelection());
}
endResetModel(); endResetModel();
} }
@ -2204,9 +2207,12 @@ void KSelectionProxyModel::setSourceModel(QAbstractItemModel *_sourceModel)
d->resetInternalData(); d->resetInternalData();
QAbstractProxyModel::setSourceModel(_sourceModel); QAbstractProxyModel::setSourceModel(_sourceModel);
if (_sourceModel) { if (_sourceModel) {
d->m_indexMapper = new KModelIndexProxyMapper(_sourceModel, d->m_selectionModel.data()->model(), this); if (d->m_selectionModel) {
if (d->m_selectionModel.data()->hasSelection()) { delete d->m_indexMapper;
d->selectionChanged(d->m_selectionModel.data()->selection(), QItemSelection()); d->m_indexMapper = new KModelIndexProxyMapper(_sourceModel, d->m_selectionModel.data()->model(), this);
if (d->m_selectionModel.data()->hasSelection()) {
d->selectionChanged(d->m_selectionModel.data()->selection(), QItemSelection());
}
} }
connect(_sourceModel, SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)), connect(_sourceModel, SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)),
@ -2475,6 +2481,14 @@ void KSelectionProxyModel::setSelectionModel(QItemSelectionModel *itemSelectionM
connect(d->m_selectionModel.data(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), connect(d->m_selectionModel.data(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
SLOT(selectionChanged(QItemSelection,QItemSelection))); SLOT(selectionChanged(QItemSelection,QItemSelection)));
} }
if (sourceModel()) {
delete d->m_indexMapper;
d->m_indexMapper = new KModelIndexProxyMapper(sourceModel(), d->m_selectionModel.data()->model(), this);
if (d->m_selectionModel.data()->hasSelection()) {
d->selectionChanged(d->m_selectionModel.data()->selection(), QItemSelection());
}
}
} }
} }

@ -108,6 +108,7 @@ public:
void setSourceModel(QAbstractItemModel *sourceModel) Q_DECL_OVERRIDE; void setSourceModel(QAbstractItemModel *sourceModel) Q_DECL_OVERRIDE;
QItemSelectionModel *selectionModel() const; QItemSelectionModel *selectionModel() const;
void setSelectionModel(QItemSelectionModel *selectionModel);
enum FilterBehavior { enum FilterBehavior {
SubTrees, SubTrees,
@ -321,7 +322,6 @@ private:
//@endcond //@endcond
void setSelectionModel(QItemSelectionModel *selectionModel);
}; };
#endif #endif

Loading…
Cancel
Save