X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/4416377eae06e70f5f841e94347f2d0b31113524..0aed243bebae72d85aa06032bdf2d6ba2b58141d:/src/kitemviews/kfileitemmodel.h diff --git a/src/kitemviews/kfileitemmodel.h b/src/kitemviews/kfileitemmodel.h index c87ee9736..dc5746a89 100644 --- a/src/kitemviews/kfileitemmodel.h +++ b/src/kitemviews/kfileitemmodel.h @@ -20,13 +20,15 @@ #ifndef KFILEITEMMODEL_H #define KFILEITEMMODEL_H -#include -#include -#include +#include "dolphin_export.h" +#include +#include #include #include +#include #include +#include class KFileItemModelDirLister; class QTimer; @@ -41,7 +43,7 @@ class QTimer; * Recursive expansion of sub-directories is supported by * KFileItemModel::setExpanded(). */ -class LIBDOLPHINPRIVATE_EXPORT KFileItemModel : public KItemModelBase +class DOLPHIN_EXPORT KFileItemModel : public KItemModelBase { Q_OBJECT @@ -55,13 +57,13 @@ public: * indicate the current state of the loading process. The items * of the directory are added after the loading has been completed. */ - void loadDirectory(const KUrl& url); + void loadDirectory(const QUrl& url); /** * Throws away all currently loaded items and refreshes the directory * by reloading all items again. */ - void refreshDirectory(const KUrl& url); + void refreshDirectory(const QUrl& url); /** * @return Parent directory of the items that are shown. In case @@ -69,7 +71,7 @@ public: * the root-parent of all items. * @see rootItem() */ - KUrl directory() const; + QUrl directory() const; /** * Cancels the loading of a directory which has been started by either @@ -77,9 +79,9 @@ public: */ void cancelDirectoryLoading(); - virtual int count() const; - virtual QHash data(int index) const; - virtual bool setData(int index, const QHash& values); + virtual int count() const Q_DECL_OVERRIDE; + virtual QHash data(int index) const Q_DECL_OVERRIDE; + virtual bool setData(int index, const QHash& values) Q_DECL_OVERRIDE; /** * Sets a separate sorting with directories first (true) or a mixed @@ -98,20 +100,15 @@ public: void setShowDirectoriesOnly(bool enabled); bool showDirectoriesOnly() const; - /** @reimp */ - virtual QMimeData* createMimeData(const QSet& indexes) const; + virtual QMimeData* createMimeData(const KItemSet& indexes) const Q_DECL_OVERRIDE; - /** @reimp */ - virtual int indexForKeyboardSearch(const QString& text, int startFromIndex = 0) const; + virtual int indexForKeyboardSearch(const QString& text, int startFromIndex = 0) const Q_DECL_OVERRIDE; - /** @reimp */ - virtual bool supportsDropping(int index) const; + virtual bool supportsDropping(int index) const Q_DECL_OVERRIDE; - /** @reimp */ - virtual QString roleDescription(const QByteArray& role) const; + virtual QString roleDescription(const QByteArray& role) const Q_DECL_OVERRIDE; - /** @reimp */ - virtual QList > groups() const; + virtual QList > groups() const Q_DECL_OVERRIDE; /** * @return The file-item for the index \a index. If the index is in a valid @@ -125,20 +122,20 @@ public: * URL is found KFileItem::isNull() will be true for the returned * file-item. The runtime complexity of this call is O(1). */ - KFileItem fileItem(const KUrl& url) const; + KFileItem fileItem(const QUrl& url) const; /** * @return The index for the file-item \a item. -1 is returned if no file-item - * is found or if the file-item is null. The runtime + * is found or if the file-item is null. The amortized runtime * complexity of this call is O(1). */ int index(const KFileItem& item) const; /** * @return The index for the URL \a url. -1 is returned if no file-item - * is found. The runtime complexity of this call is O(1). + * is found. The amortized runtime complexity of this call is O(1). */ - int index(const KUrl& url) const; + int index(const QUrl &url) const; /** * @return Root item of all items representing the item @@ -157,24 +154,24 @@ public: void setRoles(const QSet& roles); QSet roles() const; - virtual bool setExpanded(int index, bool expanded); - virtual bool isExpanded(int index) const; - virtual bool isExpandable(int index) const; - virtual int expandedParentsCount(int index) const; + virtual bool setExpanded(int index, bool expanded) Q_DECL_OVERRIDE; + virtual bool isExpanded(int index) const Q_DECL_OVERRIDE; + virtual bool isExpandable(int index) const Q_DECL_OVERRIDE; + virtual int expandedParentsCount(int index) const Q_DECL_OVERRIDE; - QSet expandedDirectories() const; + QSet expandedDirectories() const; /** * Marks the URLs in \a urls as sub-directories which were expanded previously. * After calling loadDirectory() or refreshDirectory() the marked sub-directories * will be expanded step-by-step. */ - void restoreExpandedDirectories(const QSet& urls); + void restoreExpandedDirectories(const QSet& urls); /** * Expands all parent-directories of the item \a url. */ - void expandParentDirectories(const KUrl& url); + void expandParentDirectories(const QUrl& url); void setNameFilter(const QString& nameFilter); QString nameFilter() const; @@ -186,14 +183,14 @@ public: { QByteArray role; QString translation; QString group; - bool requiresNepomuk; + bool requiresBaloo; bool requiresIndexer; }; /** * @return Provides static information for all available roles that * are supported by KFileItemModel. Some roles can only be - * determined if Nepomuk is enabled and/or the Nepomuk + * determined if Baloo is enabled and/or the Baloo * indexing is enabled. */ static QList rolesInformation(); @@ -250,18 +247,18 @@ signals: * Is emitted if a redirection from the current URL \a oldUrl * to the new URL \a newUrl has been done. */ - void directoryRedirection(const KUrl& oldUrl, const KUrl& newUrl); + void directoryRedirection(const QUrl& oldUrl, const QUrl& newUrl); /** * Is emitted when the URL passed by KFileItemModel::setUrl() represents a file. * In this case no signal errorMessage() will be emitted. */ - void urlIsFileError(const KUrl& url); + void urlIsFileError(const QUrl& url); protected: - virtual void onGroupedSortingChanged(bool current); - virtual void onSortRoleChanged(const QByteArray& current, const QByteArray& previous); - virtual void onSortOrderChanged(Qt::SortOrder current, Qt::SortOrder previous); + virtual void onGroupedSortingChanged(bool current) Q_DECL_OVERRIDE; + virtual void onSortRoleChanged(const QByteArray& current, const QByteArray& previous) Q_DECL_OVERRIDE; + virtual void onSortOrderChanged(Qt::SortOrder current, Qt::SortOrder previous) Q_DECL_OVERRIDE; private slots: /** @@ -272,24 +269,23 @@ private slots: void slotCompleted(); void slotCanceled(); - void slotItemsAdded(const KUrl& directoryUrl, const KFileItemList& items); + void slotItemsAdded(const QUrl& directoryUrl, const KFileItemList& items); void slotItemsDeleted(const KFileItemList& items); void slotRefreshItems(const QList >& items); void slotClear(); - void slotClear(const KUrl& url); - void slotNaturalSortingChanged(); + void slotSortingChoiceChanged(); void dispatchPendingItemsToInsert(); private: enum RoleType { // User visible roles: - NoRole, NameRole, SizeRole, DateRole, PermissionsRole, OwnerRole, + NoRole, NameRole, SizeRole, ModificationTimeRole, AccessTimeRole, PermissionsRole, OwnerRole, GroupRole, TypeRole, DestinationRole, PathRole, - // User visible roles available with Nepomuk: + // User visible roles available with Baloo: CommentRole, TagsRole, RatingRole, ImageSizeRole, OrientationRole, - WordCountRole, LineCountRole, ArtistRole, AlbumRole, DurationRole, TrackRole, - CopiedFromRole, + WordCountRole, TitleRole, LineCountRole, ArtistRole, AlbumRole, DurationRole, TrackRole, + OriginUrlRole, // Non-visible roles: IsDirRole, IsLinkRole, IsExpandedRole, IsExpandableRole, ExpandedParentsCountRole, // Mandatory last entry: @@ -309,7 +305,7 @@ private: }; void insertItems(QList& items); - void removeItems(const KFileItemList& items, RemoveItemsBehavior behavior); + void removeItems(const KItemRangeList& itemRanges, RemoveItemsBehavior behavior); /** * Helper method for insertItems() and removeItems(): Creates @@ -317,7 +313,16 @@ private: * Note that the ItemData instances are created dynamically and * must be deleted by the caller. */ - QList createItemDataList(const KUrl& parentUrl, const KFileItemList& items) const; + QList createItemDataList(const QUrl& parentUrl, const KFileItemList& items) const; + + /** + * Prepares the items for sorting. Normally, the hash 'values' in ItemData is filled + * lazily to save time and memory, but for some sort roles, it is expected that the + * sort role data is stored in 'values'. + */ + void prepareItemsForSorting(QList& itemDataList); + + static int expandedParentsCount(const ItemData* data); void removeExpandedItems(); @@ -347,11 +352,17 @@ private: QHash retrieveData(const KFileItem& item, const ItemData* parent) const; + /** + * @return True if \a a has a KFileItem whose text is 'less than' the one + * of \a b according to QString::operator<(const QString&). + */ + static bool nameLessThan(const ItemData* a, const ItemData* b); + /** * @return True if the item-data \a a should be ordered before the item-data * \b. The item-data may have different parent-items. */ - bool lessThan(const ItemData* a, const ItemData* b) const; + bool lessThan(const ItemData* a, const ItemData* b, const QCollator& collator) const; /** * Sorts the items between \a begin and \a end using the comparison @@ -364,15 +375,15 @@ private: * the passed item-data using m_sortRole as criteria. Both items must * have the same parent item, otherwise the comparison will be wrong. */ - int sortRoleCompare(const ItemData* a, const ItemData* b) const; + int sortRoleCompare(const ItemData* a, const ItemData* b, const QCollator& collator) const; - int stringCompare(const QString& a, const QString& b) const; + int stringCompare(const QString& a, const QString& b, const QCollator& collator) const; bool useMaximumUpdateInterval() const; QList > nameRoleGroups() const; QList > sizeRoleGroups() const; - QList > dateRoleGroups() const; + QList > timeRoleGroups(KFileItem::FileTimes which) const; QList > permissionRoleGroups() const; QList > ratingRoleGroups() const; QList > genericStringRoleGroups(const QByteArray& typeForRole) const; @@ -387,11 +398,6 @@ private: */ bool isChildItem(int index) const; - /** - * @return Recursive list of child items that have \a item as upper most parent. - */ - KFileItemList childItems(const KFileItem& item) const; - /** * Is invoked by KFileItemModelRolesUpdater and results in emitting the * sortProgress signal with a percent-value of the progress. @@ -407,7 +413,12 @@ private: * Removes filtered items whose expanded parents have been deleted * or collapsed via setExpanded(parentIndex, false). */ - void removeFilteredChildren(const KFileItemList& parentsList); + void removeFilteredChildren(const KItemRangeList& parents); + + /** + * Loads the selected choice of sorting method from Dolphin General Settings + */ + void loadSortingSettings(); /** * Maps the QByteArray-roles to RoleTypes and provides translation- and @@ -421,7 +432,7 @@ private: const char* const roleTranslation; const char* const groupTranslationContext; const char* const groupTranslation; - const bool requiresNepomuk; + const bool requiresBaloo; const bool requiresIndexer; }; @@ -450,16 +461,21 @@ private: private: KFileItemModelDirLister* m_dirLister; + QCollator m_collator; bool m_naturalSorting; bool m_sortDirsFirst; RoleType m_sortRole; int m_sortingProgressPercent; // Value of directorySortingProgress() signal QSet m_roles; - Qt::CaseSensitivity m_caseSensitivity; QList m_itemData; - QHash m_items; // Allows O(1) access for KFileItemModel::index(const KFileItem& item) + + // m_items is a cache for the method index(const QUrl&). If it contains N + // entries, it is guaranteed that these correspond to the first N items in + // the model, i.e., that (for every i between 0 and N - 1) + // m_items.value(fileItem(i).url()) == i + mutable QHash m_items; KFileItemModelFilter m_filter; QHash m_filteredItems; // Items that got hidden by KFileItemModel::setNameFilter() @@ -474,11 +490,11 @@ private: mutable QList > m_groups; // Stores the URLs (key: target url, value: url) of the expanded directories. - QHash m_expandedDirs; + QHash m_expandedDirs; // URLs that must be expanded. The expanding is initially triggered in setExpanded() // and done step after step in slotCompleted(). - QSet m_urlsToExpand; + QSet m_urlsToExpand; friend class KFileItemModelLessThan; // Accesses lessThan() method friend class KFileItemModelRolesUpdater; // Accesses emitSortProgress() method @@ -488,9 +504,19 @@ private: friend class DolphinPart; // Accesses m_dirLister }; +inline bool KFileItemModel::nameLessThan(const ItemData* a, const ItemData* b) +{ + return a->item.text() < b->item.text(); +} + + inline bool KFileItemModel::isChildItem(int index) const { - return m_requestRole[ExpandedParentsCountRole] && m_itemData.at(index)->values.value("expandedParentsCount").toInt() > 0; + if (m_itemData.at(index)->parent) { + return true; + } else { + return false; + } } #endif