X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/258f0f60feb76876c846294c23121d41997ddc34..refs/heads/master:/src/kitemviews/kitemmodelbase.h diff --git a/src/kitemviews/kitemmodelbase.h b/src/kitemviews/kitemmodelbase.h index 7545192da..bc8ab6442 100644 --- a/src/kitemviews/kitemmodelbase.h +++ b/src/kitemviews/kitemmodelbase.h @@ -1,47 +1,25 @@ -/*************************************************************************** - * Copyright (C) 2011 by Peter Penz * - * * - * Based on the Itemviews NG project from Trolltech Labs: * - * http://qt.gitorious.org/qt-labs/itemviews-ng * - * * - * 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 * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ +/* + * SPDX-FileCopyrightText: 2011 Peter Penz + * + * Based on the Itemviews NG project from Trolltech Labs + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ #ifndef KITEMMODELBASE_H #define KITEMMODELBASE_H -#include +#include "dolphin_export.h" +#include "kitemviews/kitemrange.h" +#include "kitemviews/kitemset.h" #include #include -#include +#include #include class QMimeData; -struct KItemRange -{ - KItemRange(int index = 0, int count = 0); - int index; - int count; - - bool operator == (const KItemRange& other) const; -}; -typedef QList KItemRangeList; - /** * @brief Base class for model implementations used by KItemListView and KItemListController. * @@ -57,14 +35,14 @@ typedef QList KItemRangeList; * Also optionally it is possible to provide a tree of items by implementing the methods * setExpanded(), isExpanded(), isExpandable() and expandedParentsCount(). */ -class LIBDOLPHINPRIVATE_EXPORT KItemModelBase : public QObject +class DOLPHIN_EXPORT KItemModelBase : public QObject { Q_OBJECT public: - KItemModelBase(QObject* parent = 0); - explicit KItemModelBase(const QByteArray& sortRole, QObject* parent = 0); - virtual ~KItemModelBase(); + explicit KItemModelBase(QObject *parent = nullptr); + explicit KItemModelBase(const QByteArray &sortRole, const QByteArray &groupRole, QObject *parent = nullptr); + ~KItemModelBase() override; /** @return The number of items. */ virtual int count() const = 0; @@ -78,7 +56,7 @@ public: * The default implementation does not set the data, and will always return * false. */ - virtual bool setData(int index, const QHash& values); + virtual bool setData(int index, const QHash &values); /** * Enables/disables the grouped sorting. The method KItemModelBase::onGroupedSortingChanged() will be @@ -93,8 +71,9 @@ public: * Sets the sort-role to \a role. The method KItemModelBase::onSortRoleChanged() will be * called so that model-implementations can react on the sort-role change. Afterwards the * signal sortRoleChanged() will be emitted. + * The implementation should resort only if \a resortItems is true. */ - void setSortRole(const QByteArray& role); + void setSortRole(const QByteArray &role, bool resortItems = true); QByteArray sortRole() const; /** @@ -105,11 +84,28 @@ public: void setSortOrder(Qt::SortOrder order); Qt::SortOrder sortOrder() const; + /** + * Sets the group-role to \a role. The method KItemModelBase::onGroupRoleChanged() will be + * called so that model-implementations can react on the group-role change. Afterwards the + * signal groupRoleChanged() will be emitted. + * The implementation should regroup only if \a regroupItems is true. + */ + void setGroupRole(const QByteArray &role, bool regroupItems = true); + QByteArray groupRole() const; + + /** + * Sets the group order to \a order. The method KItemModelBase::onGroupOrderChanged() will be + * called so that model-implementations can react on the group order change. Afterwards the + * signal groupOrderChanged() will be emitted. + */ + void setGroupOrder(Qt::SortOrder order); + Qt::SortOrder groupOrder() const; + /** * @return Translated description for the \p role. The description is e.g. used * for the header in KItemListView. */ - virtual QString roleDescription(const QByteArray& role) const; + virtual QString roleDescription(const QByteArray &role) const; /** * @return List of group headers. Each list-item consists of the index of the item @@ -117,7 +113,7 @@ public: * as QVariant. The value is shown by an instance of KItemListGroupHeader. * Per default an empty list is returned. */ - virtual QList > groups() const; + virtual QList> groups() const; /** * Expands the item with the index \a index if \a expanded is true. @@ -157,7 +153,7 @@ public: * caller of this method. The method must be implemented if dragging of * items should be possible. */ - virtual QMimeData* createMimeData(const QSet& indexes) const; + virtual QMimeData *createMimeData(const KItemSet &indexes) const; /** * @return Reimplement this to return the index for the first item @@ -165,7 +161,7 @@ public: * @param text the text which has been typed in through the keyboard * @param startFromIndex the index from which to start searching from */ - virtual int indexForKeyboardSearch(const QString& text, int startFromIndex = 0) const; + virtual int indexForKeyboardSearch(const QString &text, int startFromIndex = 0) const; /** * @return True, if the item with the index \a index basically supports dropping. @@ -180,7 +176,40 @@ public: // decision whether it accepts the drop? virtual bool supportsDropping(int index) const; -signals: + /** + * @return True, if the item with the index \a index can be entered in during hover actions. + * Per default false is returned. + * + * This is used to check that if the item + * we're hovering on is either directory or a desktop file. + */ + virtual bool canEnterOnHover(int index) const; + + /** + * @return An internal mimetype to signal that an itemDropEvent() should be rejected by + * the receiving model. + * + * This mimeType can be used in createMimeData() to notify that the + * drop-onto-items events should be ignored, while the drop-between-items + * ones should be still accepted. + */ + QString blacklistItemDropEventMimeType() const; + + /** + * @return URL of the item at the specified index + */ + virtual QUrl url(int index) const; + + /** + * @return True, if item at specified index is a directory + */ + virtual bool isDir(int index) const; + + /** + * @return Parent directory of the items that are shown + */ + virtual QUrl directory() const; +Q_SIGNALS: /** * Is emitted if one or more items have been inserted. Each item-range consists * of: @@ -193,7 +222,7 @@ signals: * - They don't overlap * - The index of item-range n is smaller than the index of item-range n + 1. */ - void itemsInserted(const KItemRangeList& itemRanges); + void itemsInserted(const KItemRangeList &itemRanges); /** * Is emitted if one or more items have been removed. Each item-range consists @@ -207,7 +236,7 @@ signals: * - They don't overlap * - The index of item-range n is smaller than the index of item-range n + 1. */ - void itemsRemoved(const KItemRangeList& itemRanges); + void itemsRemoved(const KItemRangeList &itemRanges); /** * Is emitted if one ore more items get moved. @@ -222,9 +251,9 @@ signals: * This signal implies that the groups might have changed. Therefore, * gropusChanged() is not emitted if this signal is emitted. */ - void itemsMoved(const KItemRange& itemRange, const QList& movedToIndexes); + void itemsMoved(const KItemRange &itemRange, const QList &movedToIndexes); - void itemsChanged(const KItemRangeList& itemRanges, const QSet& roles); + void itemsChanged(const KItemRangeList &itemRanges, const QSet &roles); /** * Is emitted if the groups have changed, even though the order of the @@ -233,8 +262,10 @@ signals: void groupsChanged(); void groupedSortingChanged(bool current); - void sortRoleChanged(const QByteArray& current, const QByteArray& previous); + void sortRoleChanged(const QByteArray ¤t, const QByteArray &previous); void sortOrderChanged(Qt::SortOrder current, Qt::SortOrder previous); + void groupRoleChanged(const QByteArray ¤t, const QByteArray &previous); + void groupOrderChanged(Qt::SortOrder current, Qt::SortOrder previous); protected: /** @@ -250,8 +281,9 @@ protected: * Usually the most efficient way is to emit a * itemsRemoved() signal for all items, reorder the items internally and to emit a * itemsInserted() signal afterwards. + * The implementation should resort only if \a resortItems is true. */ - virtual void onSortRoleChanged(const QByteArray& current, const QByteArray& previous); + virtual void onSortRoleChanged(const QByteArray ¤t, const QByteArray &previous, bool resortItems = true); /** * Is invoked if the sort order has been changed by KItemModelBase::setSortOrder(). Allows @@ -263,10 +295,33 @@ protected: */ virtual void onSortOrderChanged(Qt::SortOrder current, Qt::SortOrder previous); + /** + * Is invoked if the sort role has been changed by KItemModelBase::setSortRole(). Allows + * to react on the changed sort role before the signal sortRoleChanged() will be emitted. + * The implementation must assure that the items are sorted by the role given by \a current. + * Usually the most efficient way is to emit a + * itemsRemoved() signal for all items, reorder the items internally and to emit a + * itemsInserted() signal afterwards. + * The implementation should resort only if \a regroupItems is true. + */ + virtual void onGroupRoleChanged(const QByteArray ¤t, const QByteArray &previous, bool regroupItems = true); + + /** + * Is invoked if the sort order has been changed by KItemModelBase::setSortOrder(). Allows + * to react on the changed sort order before the signal sortOrderChanged() will be emitted. + * The implementation must assure that the items are sorted by the order given by \a current. + * Usually the most efficient way is to emit a + * itemsRemoved() signal for all items, reorder the items internally and to emit a + * itemsInserted() signal afterwards. + */ + virtual void onGroupOrderChanged(Qt::SortOrder current, Qt::SortOrder previous); + private: bool m_groupedSorting; QByteArray m_sortRole; Qt::SortOrder m_sortOrder; + QByteArray m_groupRole; + Qt::SortOrder m_groupOrder; }; inline Qt::SortOrder KItemModelBase::sortOrder() const @@ -274,6 +329,9 @@ inline Qt::SortOrder KItemModelBase::sortOrder() const return m_sortOrder; } -#endif - +inline Qt::SortOrder KItemModelBase::groupOrder() const +{ + return m_groupOrder; +} +#endif