]> cloud.milkyroute.net Git - dolphin.git/blob - src/kitemviews/kitemlistselectionmanager.h
get rid of unused warnings
[dolphin.git] / src / kitemviews / kitemlistselectionmanager.h
1 /***************************************************************************
2 * Copyright (C) 2011 by Peter Penz <peter.penz19@gmail.com> *
3 * *
4 * Based on the Itemviews NG project from Trolltech Labs: *
5 * http://qt.gitorious.org/qt-labs/itemviews-ng *
6 * *
7 * This program is free software; you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation; either version 2 of the License, or *
10 * (at your option) any later version. *
11 * *
12 * This program is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU General Public License *
18 * along with this program; if not, write to the *
19 * Free Software Foundation, Inc., *
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
21 ***************************************************************************/
22
23 #ifndef KITEMLISTSELECTIONMANAGER_H
24 #define KITEMLISTSELECTIONMANAGER_H
25
26 #include <libdolphin_export.h>
27
28 #include <kitemviews/kitemmodelbase.h>
29 #include <kitemviews/kitemset.h>
30
31 #include <QObject>
32
33 class KItemModelBase;
34
35 /**
36 * @brief Allows to select and deselect items of a KItemListView.
37 */
38 class LIBDOLPHINPRIVATE_EXPORT KItemListSelectionManager : public QObject
39 {
40 Q_OBJECT
41
42 enum RangesRemovingBehaviour {
43 DiscardRemovedIndex,
44 AdjustRemovedIndex
45 };
46
47 public:
48 enum SelectionMode {
49 Select,
50 Deselect,
51 Toggle
52 };
53
54 KItemListSelectionManager(QObject* parent = 0);
55 virtual ~KItemListSelectionManager();
56
57 void setCurrentItem(int current);
58 int currentItem() const;
59
60 void setSelectedItems(const KItemSet& items);
61 KItemSet selectedItems() const;
62 bool isSelected(int index) const;
63 bool hasSelection() const;
64
65 void setSelected(int index, int count = 1, SelectionMode mode = Select);
66 void clearSelection();
67
68 void beginAnchoredSelection(int anchor);
69 void endAnchoredSelection();
70 bool isAnchoredSelectionActive() const;
71
72 KItemModelBase* model() const;
73
74 signals:
75 void currentChanged(int current, int previous);
76 void selectionChanged(const KItemSet& current, const KItemSet& previous);
77
78 private:
79 void setModel(KItemModelBase* model);
80 void itemsInserted(const KItemRangeList& itemRanges);
81 void itemsRemoved(const KItemRangeList& itemRanges);
82 void itemsMoved(const KItemRange& itemRange, const QList<int>& movedToIndexes);
83
84
85 /**
86 * Helper method for itemsRemoved. Returns the changed index after removing
87 * the given range. If the index is part of the range, -1 will be returned.
88 */
89 int indexAfterRangesRemoving(int index, const KItemRangeList& itemRanges, const RangesRemovingBehaviour behaviour) const;
90
91 private:
92 int m_currentItem;
93 int m_anchorItem;
94 KItemSet m_selectedItems;
95 bool m_isAnchoredSelectionActive;
96
97 KItemModelBase* m_model;
98
99 friend class KItemListController; // Calls setModel()
100 friend class KItemListView; // Calls itemsInserted(), itemsRemoved() and itemsMoved()
101 friend class KItemListSelectionManagerTest;
102 };
103
104 #endif