mirror of
https://invent.kde.org/system/dolphin
synced 2024-06-30 23:46:46 +00:00
Implemented the possibility for sorting/grouping behaviors that are not tied to roles. Reintroducedd the original grouping as one of grouping options.
This commit is contained in:
parent
e9b056dcf0
commit
91273c8b03
|
@ -34,7 +34,7 @@ Q_GLOBAL_STATIC(QRecursiveMutex, s_collatorMutex)
|
|||
// #define KFILEITEMMODEL_DEBUG
|
||||
|
||||
KFileItemModel::KFileItemModel(QObject *parent)
|
||||
: KItemModelBase("text", "text", parent)
|
||||
: KItemModelBase("text", "none", parent)
|
||||
, m_dirLister(nullptr)
|
||||
, m_sortDirsFirst(true)
|
||||
, m_sortHiddenLast(false)
|
||||
|
@ -387,7 +387,14 @@ QList<QPair<int, QVariant>> KFileItemModel::groups() const
|
|||
QElapsedTimer timer;
|
||||
timer.start();
|
||||
#endif
|
||||
switch (typeForRole(groupRole())) {
|
||||
QByteArray role = groupRole();
|
||||
if (typeForRole(role) == NoRole) {
|
||||
// Handle extra grouping information
|
||||
if (m_groupExtraInfo == "followSort") {
|
||||
role = sortRole();
|
||||
}
|
||||
}
|
||||
switch (typeForRole(role)) {
|
||||
case NoRole:
|
||||
m_groups.clear();
|
||||
break;
|
||||
|
@ -424,7 +431,7 @@ QList<QPair<int, QVariant>> KFileItemModel::groups() const
|
|||
m_groups = ratingRoleGroups();
|
||||
break;
|
||||
default:
|
||||
m_groups = genericStringRoleGroups(groupRole());
|
||||
m_groups = genericStringRoleGroups(role);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -949,6 +956,13 @@ void KFileItemModel::onSortRoleChanged(const QByteArray ¤t, const QByteArr
|
|||
{
|
||||
Q_UNUSED(previous)
|
||||
m_sortRole = typeForRole(current);
|
||||
if (m_sortRole == NoRole) {
|
||||
// Requested role not in list of roles. This could
|
||||
// be used for indicating non-trivial sorting behavior
|
||||
m_sortExtraInfo = current;
|
||||
} else {
|
||||
m_sortExtraInfo.clear();
|
||||
}
|
||||
|
||||
if (!m_requestRole[m_sortRole]) {
|
||||
QSet<QByteArray> newRoles = m_roles;
|
||||
|
@ -975,8 +989,15 @@ void KFileItemModel::onGroupRoleChanged(const QByteArray ¤t, const QByteAr
|
|||
{
|
||||
Q_UNUSED(previous)
|
||||
m_groupRole = typeForRole(current);
|
||||
if (m_groupRole == NoRole) {
|
||||
// Requested role not in list of roles. This could
|
||||
// be used for indicating non-trivial grouping behavior
|
||||
m_groupExtraInfo = current;
|
||||
} else {
|
||||
m_groupExtraInfo.clear();
|
||||
}
|
||||
|
||||
if (!m_requestRole[m_sortRole]) {
|
||||
if (!m_requestRole[m_groupRole]) {
|
||||
QSet<QByteArray> newRoles = m_roles;
|
||||
newRoles << current;
|
||||
setRoles(newRoles);
|
||||
|
@ -2293,7 +2314,8 @@ int KFileItemModel::groupRoleCompare(const ItemData *a, const ItemData *b, const
|
|||
int groupA, groupB;
|
||||
switch (m_groupRole) {
|
||||
case NoRole:
|
||||
break;
|
||||
// Non-trivial grouping behavior might be handled there in the future.
|
||||
return 0;
|
||||
case NameRole:
|
||||
groupA = nameRoleGroup(a, false).comparable;
|
||||
groupB = nameRoleGroup(b, false).comparable;
|
||||
|
|
|
@ -575,6 +575,9 @@ private:
|
|||
|
||||
RoleType m_sortRole;
|
||||
RoleType m_groupRole;
|
||||
QByteArray m_sortExtraInfo;
|
||||
QByteArray m_groupExtraInfo;
|
||||
|
||||
int m_sortingProgressPercent; // Value of directorySortingProgress() signal
|
||||
QSet<QByteArray> m_roles;
|
||||
|
||||
|
|
|
@ -2185,7 +2185,7 @@ void KItemListView::updateGroupHeaderForWidget(KItemListWidget *widget)
|
|||
const int groupIndex = groupIndexForItem(index);
|
||||
Q_ASSERT(groupIndex >= 0);
|
||||
groupHeader->setData(groups.at(groupIndex).second);
|
||||
groupHeader->setRole(model()->sortRole());
|
||||
groupHeader->setRole(model()->groupRole());
|
||||
groupHeader->setStyleOption(m_styleOption);
|
||||
groupHeader->setScrollOrientation(scrollOrientation());
|
||||
groupHeader->setItemIndex(index);
|
||||
|
|
|
@ -302,6 +302,18 @@ void DolphinViewActionHandler::createActions(SelectionMode::ActionTextHelper *ac
|
|||
// View -> Group By
|
||||
QActionGroup *groupByActionGroup = createFileItemRolesActionGroup(QStringLiteral("group_by_"));
|
||||
|
||||
KToggleAction *groupAsNone = m_actionCollection->add<KToggleAction>(QStringLiteral("group_none"));
|
||||
groupAsNone->setData("none");
|
||||
groupAsNone->setActionGroup(groupByActionGroup);
|
||||
groupAsNone->setText(i18nc("@label", "No grouping"));
|
||||
m_groupByActions.insert("none", groupAsNone);
|
||||
|
||||
KToggleAction *groupAsFollowSort = m_actionCollection->add<KToggleAction>(QStringLiteral("group_followSort"));
|
||||
groupAsFollowSort->setData("followSort");
|
||||
groupAsFollowSort->setActionGroup(groupByActionGroup);
|
||||
groupAsFollowSort->setText(i18nc("@label", "Follow sorting"));
|
||||
m_groupByActions.insert("followSort", groupAsFollowSort);
|
||||
|
||||
KActionMenu *groupByActionMenu = m_actionCollection->add<KActionMenu>(QStringLiteral("group"));
|
||||
groupByActionMenu->setIcon(QIcon::fromTheme(QStringLiteral("view-group")));
|
||||
groupByActionMenu->setText(i18nc("@action:inmenu View", "Group By"));
|
||||
|
@ -404,9 +416,6 @@ QActionGroup *DolphinViewActionHandler::createFileItemRolesActionGroup(const QSt
|
|||
#endif
|
||||
|
||||
QList<KFileItemModel::RoleInfo> rolesInfo = KFileItemModel::rolesInformation();
|
||||
// Unlike sorting, grouping is optional. If creating for group_by_, include a None role.
|
||||
if (isGroupGroup)
|
||||
rolesInfo.append(KFileItemModel::roleInformation(nullptr));
|
||||
|
||||
for (const KFileItemModel::RoleInfo &info : rolesInfo) {
|
||||
if (!isSortGroup && !isGroupGroup && info.role == "text") {
|
||||
|
|
|
@ -410,6 +410,8 @@ void ViewProperties::setDirProperties(const ViewProperties &props)
|
|||
setGroupedSorting(props.groupedSorting());
|
||||
setSortRole(props.sortRole());
|
||||
setSortOrder(props.sortOrder());
|
||||
setGroupRole(props.groupRole());
|
||||
setGroupOrder(props.groupOrder());
|
||||
setSortFoldersFirst(props.sortFoldersFirst());
|
||||
setSortHiddenLast(props.sortHiddenLast());
|
||||
setVisibleRoles(props.visibleRoles());
|
||||
|
|
Loading…
Reference in New Issue
Block a user