-void SelectionModelSynchronizer::addSelectionModel(QItemSelectionModel *selectionModel) {
- if(!checkBaseModel(selectionModel)) {
- qWarning() << "cannot Syncronize SelectionModel" << selectionModel << "which has a different baseModel()";
- return;
- }
-
- connect(selectionModel, SIGNAL(currentChanged(QModelIndex, QModelIndex)),
- this, SLOT(mappedCurrentChanged(QModelIndex, QModelIndex)));
- connect(selectionModel, SIGNAL(selectionChanged(QItemSelection, QItemSelection)),
- this, SLOT(mappedSelectionChanged(QItemSelection, QItemSelection)));
-
- if(qobject_cast<MappedSelectionModel *>(selectionModel)) {
- connect(this, SIGNAL(setCurrentIndex(QModelIndex, QItemSelectionModel::SelectionFlags)),
- selectionModel, SLOT(mappedSetCurrentIndex(QModelIndex, QItemSelectionModel::SelectionFlags)));
- connect(this, SIGNAL(select(QItemSelection, QItemSelectionModel::SelectionFlags)),
- selectionModel, SLOT(mappedSelect(QItemSelection, QItemSelectionModel::SelectionFlags)));
- } else {
- connect(this, SIGNAL(setCurrentIndex(QModelIndex, QItemSelectionModel::SelectionFlags)),
- selectionModel, SLOT(setCurrentIndex(QModelIndex, QItemSelectionModel::SelectionFlags)));
- connect(this, SIGNAL(select(QItemSelection, QItemSelectionModel::SelectionFlags)),
- selectionModel, SLOT(select(QItemSelection, QItemSelectionModel::SelectionFlags)));
- }
+
+void SelectionModelSynchronizer::synchronizeSelectionModel(QItemSelectionModel *selectionModel)
+{
+ if (!checkBaseModel(selectionModel)) {
+ qWarning() << "cannot Synchronize SelectionModel" << selectionModel << "which has a different baseModel()";
+ return;
+ }
+
+ if (_selectionModels.contains(selectionModel)) {
+ selectionModel->setCurrentIndex(mapFromSource(currentIndex(), selectionModel), QItemSelectionModel::Current);
+ selectionModel->select(mapSelectionFromSource(currentSelection(), selectionModel), QItemSelectionModel::ClearAndSelect);
+ return;
+ }
+
+ connect(selectionModel, SIGNAL(currentChanged(QModelIndex, QModelIndex)),
+ this, SLOT(syncedCurrentChanged(QModelIndex, QModelIndex)));
+ connect(selectionModel, SIGNAL(selectionChanged(QItemSelection, QItemSelection)),
+ this, SLOT(syncedSelectionChanged(QItemSelection, QItemSelection)));
+
+ connect(selectionModel, SIGNAL(destroyed(QObject *)), this, SLOT(selectionModelDestroyed(QObject *)));
+
+ _selectionModels << selectionModel;