]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/kitemviews/kitemmodelbase.h
Fix selection rect after porting from QFontMetrics::width()
[dolphin.git] / src / kitemviews / kitemmodelbase.h
index 7545192da411dbe79724775f7e1331efa02e55fa..a6ba3f7c4ec888adb461bd5b893afc1862dda13d 100644 (file)
@@ -1,8 +1,7 @@
 /***************************************************************************
  *   Copyright (C) 2011 by Peter Penz <peter.penz19@gmail.com>             *
  *                                                                         *
- *   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  *
 #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.
  *
@@ -57,14 +48,14 @@ typedef QList<KItemRange> 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, QObject* parent = nullptr);
+    ~KItemModelBase() override;
 
     /** @return The number of items. */
     virtual int count() const = 0;
@@ -93,8 +84,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;
 
     /**
@@ -157,7 +149,7 @@ public:
      *         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
@@ -180,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
@@ -250,8 +266,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& current, const QByteArray& previous, bool resortItems = true);
 
     /**
      * Is invoked if the sort order has been changed by KItemModelBase::setSortOrder(). Allows