1 /***************************************************************************
2 * Copyright (C) 2005-07 by The Quassel Team *
3 * devel@quassel-irc.org *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
21 #include "selectionmodelsynchronizer.h"
24 #include <QAbstractItemModel>
25 #include "mappedselectionmodel.h"
29 SelectionModelSynchronizer::SelectionModelSynchronizer(QAbstractItemModel *parent)
35 SelectionModelSynchronizer::~SelectionModelSynchronizer() {
38 void SelectionModelSynchronizer::addSelectionModel(MappedSelectionModel *selectionmodel) {
39 if(selectionmodel->baseModel() != model()) {
40 qWarning() << "cannot Syncronize SelectionModel" << selectionmodel << "which has a different baseModel()";
44 connect(selectionmodel, SIGNAL(mappedCurrentChanged(QModelIndex)),
45 this, SLOT(_mappedCurrentChanged(QModelIndex)));
46 connect(selectionmodel, SIGNAL(mappedSelectionChanged(QItemSelection)),
47 this, SLOT(_mappedSelectionChanged(QItemSelection)));
49 connect(this, SIGNAL(setCurrentIndex(QModelIndex, QItemSelectionModel::SelectionFlags)),
50 selectionmodel, SLOT(mappedSetCurrentIndex(QModelIndex, QItemSelectionModel::SelectionFlags)));
51 connect(this, SIGNAL(select(QItemSelection, QItemSelectionModel::SelectionFlags)),
52 selectionmodel, SLOT(mappedSelect(QItemSelection, QItemSelectionModel::SelectionFlags)));
56 void SelectionModelSynchronizer::removeSelectionModel(MappedSelectionModel *model) {
57 disconnect(model, 0, this, 0);
58 disconnect(this, 0, model, 0);
61 void SelectionModelSynchronizer::_mappedCurrentChanged(const QModelIndex ¤t) {
62 emit setCurrentIndex(current, QItemSelectionModel::ClearAndSelect);
65 void SelectionModelSynchronizer::_mappedSelectionChanged(const QItemSelection &selected) {
66 emit select(selected, QItemSelectionModel::ClearAndSelect);