1 /***************************************************************************
2 * Copyright (C) 2011 by Peter Penz <peter.penz19@gmail.com> *
4 * Based on the Itemviews NG project from Trolltech Labs *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the *
18 * Free Software Foundation, Inc., *
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
20 ***************************************************************************/
22 #ifndef KITEMLISTSELECTIONMANAGER_H
23 #define KITEMLISTSELECTIONMANAGER_H
25 #include "dolphin_export.h"
26 #include "kitemviews/kitemmodelbase.h"
27 #include "kitemviews/kitemset.h"
34 * @brief Allows to select and deselect items of a KItemListView.
36 class DOLPHIN_EXPORT KItemListSelectionManager
: public QObject
40 enum RangesRemovingBehaviour
{
52 explicit KItemListSelectionManager(QObject
* parent
= nullptr);
53 ~KItemListSelectionManager() override
;
55 void setCurrentItem(int current
);
56 int currentItem() const;
58 void setSelectedItems(const KItemSet
& items
);
59 KItemSet
selectedItems() const;
60 bool isSelected(int index
) const;
61 bool hasSelection() const;
63 void setSelected(int index
, int count
= 1, SelectionMode mode
= Select
);
67 * setSelected(index, count);
68 * but emitting once only selectionChanged signal
70 void replaceSelection(int index
, int count
= 1);
71 void clearSelection();
73 void beginAnchoredSelection(int anchor
);
74 void endAnchoredSelection();
75 bool isAnchoredSelectionActive() const;
77 KItemModelBase
* model() const;
80 void currentChanged(int current
, int previous
);
81 void selectionChanged(const KItemSet
& current
, const KItemSet
& previous
);
84 void setModel(KItemModelBase
* model
);
85 void itemsInserted(const KItemRangeList
& itemRanges
);
86 void itemsRemoved(const KItemRangeList
& itemRanges
);
87 void itemsMoved(const KItemRange
& itemRange
, const QList
<int>& movedToIndexes
);
91 * Helper method for itemsRemoved. Returns the changed index after removing
92 * the given range. If the index is part of the range, -1 will be returned.
94 int indexAfterRangesRemoving(int index
, const KItemRangeList
& itemRanges
, const RangesRemovingBehaviour behaviour
) const;
99 KItemSet m_selectedItems
;
100 bool m_isAnchoredSelectionActive
;
102 KItemModelBase
* m_model
;
104 friend class KItemListController
; // Calls setModel()
105 friend class KItemListView
; // Calls itemsInserted(), itemsRemoved() and itemsMoved()
106 friend class KItemListSelectionManagerTest
;