X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/ea765ba5737074dcffc67be20d33a7f01890dd7f..d48b733:/src/kitemviews/kitemlistselectionmanager.h diff --git a/src/kitemviews/kitemlistselectionmanager.h b/src/kitemviews/kitemlistselectionmanager.h index 2761940f5..16761428b 100644 --- a/src/kitemviews/kitemlistselectionmanager.h +++ b/src/kitemviews/kitemlistselectionmanager.h @@ -23,22 +23,27 @@ #ifndef KITEMLISTSELECTIONMANAGER_H #define KITEMLISTSELECTIONMANAGER_H -#include +#include "dolphin_export.h" #include +#include #include -#include class KItemModelBase; /** * @brief Allows to select and deselect items of a KItemListView. */ -class LIBDOLPHINPRIVATE_EXPORT KItemListSelectionManager : public QObject +class DOLPHIN_EXPORT KItemListSelectionManager : public QObject { Q_OBJECT + enum RangesRemovingBehaviour { + DiscardRemovedIndex, + AdjustRemovedIndex + }; + public: enum SelectionMode { Select, @@ -52,8 +57,9 @@ public: void setCurrentItem(int current); int currentItem() const; - void setSelectedItems(const QSet& items); - QSet selectedItems() const; + void setSelectedItems(const KItemSet& items); + KItemSet selectedItems() const; + bool isSelected(int index) const; bool hasSelection() const; void setSelected(int index, int count = 1, SelectionMode mode = Select); @@ -61,30 +67,37 @@ public: void beginAnchoredSelection(int anchor); void endAnchoredSelection(); - int anchorItem() const; bool isAnchoredSelectionActive() const; KItemModelBase* model() const; signals: void currentChanged(int current, int previous); - void selectionChanged(const QSet& current, const QSet& previous); + void selectionChanged(const KItemSet& current, const KItemSet& previous); private: void setModel(KItemModelBase* model); void itemsInserted(const KItemRangeList& itemRanges); void itemsRemoved(const KItemRangeList& itemRanges); + void itemsMoved(const KItemRange& itemRange, const QList& movedToIndexes); + + + /** + * Helper method for itemsRemoved. Returns the changed index after removing + * the given range. If the index is part of the range, -1 will be returned. + */ + int indexAfterRangesRemoving(int index, const KItemRangeList& itemRanges, const RangesRemovingBehaviour behaviour) const; private: int m_currentItem; int m_anchorItem; - QSet m_selectedItems; + KItemSet m_selectedItems; bool m_isAnchoredSelectionActive; KItemModelBase* m_model; friend class KItemListController; // Calls setModel() - friend class KItemListView; // Calls itemsInserted() and itemsRemoved() + friend class KItemListView; // Calls itemsInserted(), itemsRemoved() and itemsMoved() friend class KItemListSelectionManagerTest; };