src: Mark symbols to be exported where needed
[quassel.git] / src / client / selectionmodelsynchronizer.h
1 /***************************************************************************
2  *   Copyright (C) 2005-2018 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  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
19  ***************************************************************************/
20
21 #pragma once
22
23 #include "client-export.h"
24
25 #include <QObject>
26 #include <QItemSelectionModel>
27
28 class QAbstractItemModel;
29
30 class CLIENT_EXPORT SelectionModelSynchronizer : public QObject
31 {
32     Q_OBJECT
33
34 public:
35     SelectionModelSynchronizer(QAbstractItemModel *parent = 0);
36
37     void synchronizeSelectionModel(QItemSelectionModel *selectionModel);
38     void removeSelectionModel(QItemSelectionModel *selectionModel);
39
40     inline QAbstractItemModel *model() { return _model; }
41     inline QItemSelectionModel *selectionModel() const { return const_cast<QItemSelectionModel *>(&_selectionModel); }
42     inline QModelIndex currentIndex() const { return _selectionModel.currentIndex(); }
43     inline QItemSelection currentSelection() const { return _selectionModel.selection(); }
44
45 private slots:
46     void syncedCurrentChanged(const QModelIndex &current, const QModelIndex &previous);
47     void syncedSelectionChanged(const QItemSelection &selected, const QItemSelection &previous);
48
49     void setCurrentIndex(const QModelIndex &index);
50     void setCurrentSelection(const QItemSelection &selection);
51
52     void currentChanged(const QModelIndex &current, const QModelIndex &previous);
53     void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
54
55     void selectionModelDestroyed(QObject *object);
56
57 private:
58     QAbstractItemModel *_model;
59     QItemSelectionModel _selectionModel;
60     bool _changeCurrentEnabled;
61     bool _changeSelectionEnabled;
62
63     bool checkBaseModel(QItemSelectionModel *model);
64     QModelIndex mapFromSource(const QModelIndex &sourceIndex, const QItemSelectionModel *selectionModel);
65     QItemSelection mapSelectionFromSource(const QItemSelection &sourceSelection, const QItemSelectionModel *selectionModel);
66     QModelIndex mapToSource(const QModelIndex &index, QItemSelectionModel *selectionModel);
67     QItemSelection mapSelectionToSource(const QItemSelection &selection, QItemSelectionModel *selectionModel);
68
69     QSet<QItemSelectionModel *> _selectionModels;
70 };