Fixed active state for statusBuffer and Queries
[quassel.git] / src / client / mappedselectionmodel.h
1 /***************************************************************************
2  *   Copyright (C) 2005-08 by the Quassel Project                          *
3  *   devel@quassel-irc.org                                                 *
4  *                                                                         *
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) version 3.                                           *
9  *                                                                         *
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.                          *
14  *                                                                         *
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  ***************************************************************************/
20
21 #ifndef _MAPPEDSELECTIONMODEL_H_
22 #define _MAPPEDSELECTIONMODEL_H_
23
24 #include <QObject>
25 #include <QModelIndex>
26 #include <QItemSelection>
27 #include <QItemSelectionModel>
28
29 class QAbstractProxyModel;
30
31 class MappedSelectionModel : public QItemSelectionModel {
32   Q_OBJECT
33
34 public:
35   MappedSelectionModel(QAbstractItemModel *model = 0);
36   virtual ~MappedSelectionModel();
37
38   inline bool isProxyModel() const { return _isProxyModel; }
39
40   const QAbstractItemModel *baseModel() const;
41   const QAbstractProxyModel *proxyModel() const;
42   
43   QModelIndex mapFromSource(const QModelIndex &sourceIndex);
44   QItemSelection mapSelectionFromSource(const QItemSelection &sourceSelection);
45                                     
46   QModelIndex mapToSource(const QModelIndex &proxyIndex);
47   QItemSelection mapSelectionToSource(const QItemSelection &proxySelection);
48                                                                         
49 public slots:
50   void mappedSelect(const QModelIndex &index, QItemSelectionModel::SelectionFlags command);
51   void mappedSelect(const QItemSelection &selection, QItemSelectionModel::SelectionFlags command);
52   void mappedSetCurrentIndex(const QModelIndex &index, QItemSelectionModel::SelectionFlags command);
53
54 private slots:
55   void _currentChanged(const QModelIndex &current, const QModelIndex &previous);
56   void _selectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
57   
58 signals:
59   void mappedCurrentChanged(const QModelIndex &current);
60   void mappedSelectionChanged(const QItemSelection &selected);
61
62 private:
63   bool _isProxyModel;
64
65 };
66
67 #endif