QString roleDescription(const QByteArray &role) const override;
- QList<QPair<int, QVariant>> groups() const override;
-
/**
* @return The file-item for the index \a index. If the index is in a valid
* range it is assured that the file-item is not null. The runtime
/**
* @return Provides static information for a role that is supported
- * by KFileItemModel. Some roles can only be determined if
+ * by KFileItemModel. Some roles can only be determined if
* Baloo is enabled and/or the Baloo indexing is enabled.
*/
static RoleInfo roleInformation(const QByteArray &role);
*/
static QList<RoleInfo> rolesInformation();
+ QList<QPair<int, QVariant>> groups() const override;
+
/** set to true to hide application/x-trash files */
void setShowTrashMime(bool show);
ItemData *parent;
};
+ struct ItemGroupInfo {
+ int comparable;
+ QString text;
+
+ bool operator==(const ItemGroupInfo &other) const;
+ bool operator!=(const ItemGroupInfo &other) const;
+ bool operator<(const ItemGroupInfo &other) const;
+ };
+
enum RemoveItemsBehavior { KeepItemData, DeleteItemData, DeleteItemDataIfUnfiltered };
void insertItems(QList<ItemData *> &items);
*/
int sortRoleCompare(const ItemData *a, const ItemData *b, const QCollator &collator) const;
+ /**
+ * Helper method for lessThan() and expandedParentsCountCompare(): Compares
+ * the passed item-data using m_groupRole as criteria. Both items must
+ * have the same parent item, otherwise the comparison will be wrong.
+ */
+ int groupRoleCompare(const ItemData *a, const ItemData *b, const QCollator &collator) const;
+
int stringCompare(const QString &a, const QString &b, const QCollator &collator) const;
+ ItemGroupInfo nameRoleGroup(const ItemData *itemData, bool withString = true) const;
+ ItemGroupInfo sizeRoleGroup(const ItemData *itemData, bool withString = true) const;
+ ItemGroupInfo timeRoleGroup(const std::function<QDateTime(const ItemData *)> &fileTimeCb, const ItemData *itemData, bool withString = true) const;
+ ItemGroupInfo permissionRoleGroup(const ItemData *itemData, bool withString = true) const;
+ ItemGroupInfo ratingRoleGroup(const ItemData *itemData, bool withString = true) const;
+ QString genericStringRoleGroup(const QByteArray &role, const ItemData *itemData) const;
+
QList<QPair<int, QVariant>> nameRoleGroups() const;
QList<QPair<int, QVariant>> sizeRoleGroups() const;
QList<QPair<int, QVariant>> timeRoleGroups(const std::function<QDateTime(const ItemData *)> &fileTimeCb) const;
}
}
+inline bool KFileItemModel::ItemGroupInfo::operator==(const ItemGroupInfo &other) const
+{
+ return comparable == other.comparable && text == other.text;
+}
+
+inline bool KFileItemModel::ItemGroupInfo::operator!=(const ItemGroupInfo &other) const
+{
+ return comparable != other.comparable || text != other.text;
+}
+
+inline bool KFileItemModel::ItemGroupInfo::operator<(const ItemGroupInfo &other) const
+{
+ if (comparable == other.comparable) {
+ return text < other.text;
+ } else {
+ return comparable < other.comparable;
+ }
+}
+
#endif