1 /***************************************************************************
2 * Copyright (C) 2011 by Peter Penz <peter.penz19@gmail.com> *
4 * Based on the Itemviews NG project from Trolltech Labs: *
5 * http://qt.gitorious.org/qt-labs/itemviews-ng *
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. *
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. *
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 ***************************************************************************/
23 #ifndef KITEMLISTSELECTIONMANAGER_H
24 #define KITEMLISTSELECTIONMANAGER_H
26 #include "dolphin_export.h"
27 #include "kitemviews/kitemmodelbase.h"
28 #include "kitemviews/kitemset.h"
35 * @brief Allows to select and deselect items of a KItemListView.
37 class DOLPHIN_EXPORT KItemListSelectionManager
: public QObject
41 enum RangesRemovingBehaviour
{
53 explicit KItemListSelectionManager(QObject
* parent
= nullptr);
54 ~KItemListSelectionManager() override
;
56 void setCurrentItem(int current
);
57 int currentItem() const;
59 void setSelectedItems(const KItemSet
& items
);
60 KItemSet
selectedItems() const;
61 bool isSelected(int index
) const;
62 bool hasSelection() const;
64 void setSelected(int index
, int count
= 1, SelectionMode mode
= Select
);
65 void clearSelection();
67 void beginAnchoredSelection(int anchor
);
68 void endAnchoredSelection();
69 bool isAnchoredSelectionActive() const;
71 KItemModelBase
* model() const;
74 void currentChanged(int current
, int previous
);
75 void selectionChanged(const KItemSet
& current
, const KItemSet
& previous
);
78 void setModel(KItemModelBase
* model
);
79 void itemsInserted(const KItemRangeList
& itemRanges
);
80 void itemsRemoved(const KItemRangeList
& itemRanges
);
81 void itemsMoved(const KItemRange
& itemRange
, const QList
<int>& movedToIndexes
);
85 * Helper method for itemsRemoved. Returns the changed index after removing
86 * the given range. If the index is part of the range, -1 will be returned.
88 int indexAfterRangesRemoving(int index
, const KItemRangeList
& itemRanges
, const RangesRemovingBehaviour behaviour
) const;
93 KItemSet m_selectedItems
;
94 bool m_isAnchoredSelectionActive
;
96 KItemModelBase
* m_model
;
98 friend class KItemListController
; // Calls setModel()
99 friend class KItemListView
; // Calls itemsInserted(), itemsRemoved() and itemsMoved()
100 friend class KItemListSelectionManagerTest
;