]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/kitemviews/kitemmodelbase.h
[KStandardItemListWidget] Pass icon state to overlay painter
[dolphin.git] / src / kitemviews / kitemmodelbase.h
index de847a9a45bccf0e6cccdf26dbaaae5eb15e8a55..257872f9ca91f1058299030e9116f0c683ab9e45 100644 (file)
 #ifndef KITEMMODELBASE_H
 #define KITEMMODELBASE_H
 
-#include <libdolphin_export.h>
+#include "dolphin_export.h"
+#include "kitemviews/kitemrange.h"
+#include "kitemviews/kitemset.h"
 
 #include <QHash>
 #include <QObject>
-#include <QSet>
+#include <QUrl>
 #include <QVariant>
 
 class QMimeData;
 
-struct KItemRange
-{
-    KItemRange(int index = 0, int count = 0);
-    int index;
-    int count;
-
-    bool operator == (const KItemRange& other) const;
-};
-typedef QList<KItemRange> KItemRangeList;
-
 /**
  * @brief Base class for model implementations used by KItemListView and KItemListController.
  *
- * A item-model consists of a variable number of items. The number of items
+ * An item-model consists of a variable number of items. The number of items
  * is given by KItemModelBase::count(). The data of an item is accessed by a unique index
  * with KItemModelBase::data(). The indexes are integer-values counting from 0 to the
  * KItemModelBase::count() - 1.
@@ -55,16 +47,16 @@ typedef QList<KItemRange> KItemRangeList;
  * A model can optionally provide sorting- and grouping-capabilities.
  *
  * Also optionally it is possible to provide a tree of items by implementing the methods
- * setExpanded(), isExpanded() and isExpandable().
+ * setExpanded(), isExpanded(), isExpandable() and expandedParentsCount().
  */
-class LIBDOLPHINPRIVATE_EXPORT KItemModelBase : public QObject
+class DOLPHIN_EXPORT KItemModelBase : public QObject
 {
     Q_OBJECT
 
 public:
-    KItemModelBase(QObject* parent = 0);
-    KItemModelBase(const QByteArray& sortRole, QObject* parent = 0);
-    virtual ~KItemModelBase();
+    explicit KItemModelBase(QObject* parent = nullptr);
+    explicit KItemModelBase(const QByteArray& sortRole, QObject* parent = nullptr);
+    ~KItemModelBase() override;
 
     /** @return The number of items. */
     virtual int count() const = 0;
@@ -154,9 +146,10 @@ public:
     /**
      * @return MIME-data for the items given by \a indexes. The default implementation
      *         returns 0. The ownership of the returned instance is in the hand of the
-     *         caller of this method.
+     *         caller of this method. The method must be implemented if dragging of
+     *         items should be possible.
      */
-    virtual QMimeData* createMimeData(const QSet<int>& indexes) const;
+    virtual QMimeData* createMimeData(const KItemSet& indexes) const;
 
     /**
      * @return Reimplement this to return the index for the first item
@@ -179,6 +172,30 @@ public:
     // decision whether it accepts the drop?
     virtual bool supportsDropping(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;
 signals:
     /**
      * Is emitted if one or more items have been inserted. Each item-range consists
@@ -217,11 +234,20 @@ signals:
      * with the items 5 and 6 then the parameters look like this:
      * - itemRange: has the index 0 and a count of 7.
      * - movedToIndexes: Contains the seven values 5, 6, 2, 3, 4, 0, 1
+     *
+     * 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<int>& movedToIndexes);
 
     void itemsChanged(const KItemRangeList& itemRanges, const QSet<QByteArray>& roles);
 
+    /**
+     * Is emitted if the groups have changed, even though the order of the
+     * items has not been modified.
+     */
+    void groupsChanged();
+
     void groupedSortingChanged(bool current);
     void sortRoleChanged(const QByteArray& current, const QByteArray& previous);
     void sortOrderChanged(Qt::SortOrder current, Qt::SortOrder previous);