]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/kitemviews/kitemmodelbase.h
Merge remote-tracking branch 'fork/work/zakharafoniam/useful-groups'
[dolphin.git] / src / kitemviews / kitemmodelbase.h
index 4e1fd8a8fe59b9613705a75645fe58dfbe9ad791..bc8ab64427d40577b300bcf82935b1f632fc33b6 100644 (file)
@@ -41,7 +41,7 @@ class DOLPHIN_EXPORT KItemModelBase : public QObject
 
 public:
     explicit KItemModelBase(QObject *parent = nullptr);
-    explicit KItemModelBase(const QByteArray &sortRole, QObject *parent = nullptr);
+    explicit KItemModelBase(const QByteArray &sortRole, const QByteArray &groupRole, QObject *parent = nullptr);
     ~KItemModelBase() override;
 
     /** @return The number of items. */
@@ -84,6 +84,23 @@ 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.
@@ -159,6 +176,15 @@ public:
     // decision whether it accepts the drop?
     virtual bool supportsDropping(int index) const;
 
+    /**
+     * @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.
@@ -238,6 +264,8 @@ Q_SIGNALS:
     void groupedSortingChanged(bool current);
     void sortRoleChanged(const QByteArray &current, const QByteArray &previous);
     void sortOrderChanged(Qt::SortOrder current, Qt::SortOrder previous);
+    void groupRoleChanged(const QByteArray &current, const QByteArray &previous);
+    void groupOrderChanged(Qt::SortOrder current, Qt::SortOrder previous);
 
 protected:
     /**
@@ -267,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 &current, 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
@@ -278,4 +329,9 @@ inline Qt::SortOrder KItemModelBase::sortOrder() const
     return m_sortOrder;
 }
 
+inline Qt::SortOrder KItemModelBase::groupOrder() const
+{
+    return m_groupOrder;
+}
+
 #endif