X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/ac73b172fc5c08163b21d7edaf61aba46a899276..b65576a131eb59eaab4d33af830bdb2d2f9fde9f:/src/kitemviews/kitemlistselectionmanager.h diff --git a/src/kitemviews/kitemlistselectionmanager.h b/src/kitemviews/kitemlistselectionmanager.h index 43d0dcb80..6b0435139 100644 --- a/src/kitemviews/kitemlistselectionmanager.h +++ b/src/kitemviews/kitemlistselectionmanager.h @@ -1,8 +1,7 @@ /*************************************************************************** * Copyright (C) 2011 by Peter Penz * * * - * Based on the Itemviews NG project from Trolltech Labs: * - * http://qt.gitorious.org/qt-labs/itemviews-ng * + * Based on the Itemviews NG project from Trolltech Labs * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * @@ -23,22 +22,26 @@ #ifndef KITEMLISTSELECTIONMANAGER_H #define KITEMLISTSELECTIONMANAGER_H -#include - -#include +#include "dolphin_export.h" +#include "kitemviews/kitemmodelbase.h" +#include "kitemviews/kitemset.h" #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, @@ -46,18 +49,25 @@ public: Toggle }; - KItemListSelectionManager(QObject* parent = 0); - virtual ~KItemListSelectionManager(); + explicit KItemListSelectionManager(QObject* parent = nullptr); + ~KItemListSelectionManager() override; 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); + /** + * Equivalent to: + * clearSelection(); + * setSelected(index, count); + * but emitting once only selectionChanged signal + */ + void replaceSelection(int index, int count = 1); void clearSelection(); void beginAnchoredSelection(int anchor); @@ -68,7 +78,7 @@ public: 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); @@ -81,12 +91,12 @@ private: * 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; + 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;