X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fclient%2Fselectionmodelsynchronizer.cpp;h=ef0b94789c0186c4f266f57763af4254e69ee62d;hp=2975f7975feb621034d4e879b49c5747b991528d;hb=fd7c2c4a41b5bb9cffcfe7a8f86a28ab7f38ac27;hpb=974b7adc16b798eda66e1fff1442b73b748f12f9 diff --git a/src/client/selectionmodelsynchronizer.cpp b/src/client/selectionmodelsynchronizer.cpp index 2975f797..ef0b9478 100644 --- a/src/client/selectionmodelsynchronizer.cpp +++ b/src/client/selectionmodelsynchronizer.cpp @@ -1,11 +1,11 @@ /*************************************************************************** - * Copyright (C) 2005-07 by The Quassel Team * + * Copyright (C) 2005-08 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * + * (at your option) version 3. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * @@ -36,6 +36,11 @@ SelectionModelSynchronizer::~SelectionModelSynchronizer() { } void SelectionModelSynchronizer::addSelectionModel(MappedSelectionModel *selectionmodel) { + if(selectionmodel->model() == model()) { + addRegularSelectionModel(selectionmodel); + return; + } + if(selectionmodel->baseModel() != model()) { qWarning() << "cannot Syncronize SelectionModel" << selectionmodel << "which has a different baseModel()"; return; @@ -50,6 +55,22 @@ void SelectionModelSynchronizer::addSelectionModel(MappedSelectionModel *selecti selectionmodel, SLOT(mappedSetCurrentIndex(QModelIndex, QItemSelectionModel::SelectionFlags))); connect(this, SIGNAL(select(QItemSelection, QItemSelectionModel::SelectionFlags)), selectionmodel, SLOT(mappedSelect(QItemSelection, QItemSelectionModel::SelectionFlags))); +} + +void SelectionModelSynchronizer::addRegularSelectionModel(QItemSelectionModel *selectionmodel) { + if(selectionmodel->model() != model()) { + qWarning() << "cannot Syncronize QItemSelectionModel" << selectionmodel << "which has a different model()"; + return; + } + connect(selectionmodel, SIGNAL(currentChanged(QModelIndex, QModelIndex)), + this, SLOT(_regularCurrentChanged(QModelIndex, QModelIndex))); + connect(selectionmodel, SIGNAL(selectionChanged(QItemSelection, QItemSelection)), + this, SLOT(_regularSelectionChanged(QItemSelection, QItemSelection))); + + 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))); } @@ -65,3 +86,15 @@ void SelectionModelSynchronizer::_mappedCurrentChanged(const QModelIndex ¤ void SelectionModelSynchronizer::_mappedSelectionChanged(const QItemSelection &selected) { emit select(selected, QItemSelectionModel::ClearAndSelect); } + +void SelectionModelSynchronizer::_regularCurrentChanged(const QModelIndex &newCurrent, const QModelIndex &oldCurrent) { + Q_UNUSED(oldCurrent) + emit setCurrentIndex(newCurrent, QItemSelectionModel::ClearAndSelect); +} + +void SelectionModelSynchronizer::_regularSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected) { + Q_UNUSED(selected) + Q_UNUSED(deselected) + QItemSelectionModel *selectionModel = qobject_cast(sender()); + emit select(selectionModel->selection(), QItemSelectionModel::ClearAndSelect); +}