Changeset View
Changeset View
Standalone View
Standalone View
src/kitemviews/kfileitemmodel.cpp
Show First 20 Lines • Show All 298 Lines • ▼ Show 20 Line(s) | |||||
299 | 299 | | |||
300 | QString KFileItemModel::roleDescription(const QByteArray& role) const | 300 | QString KFileItemModel::roleDescription(const QByteArray& role) const | ||
301 | { | 301 | { | ||
302 | static QHash<QByteArray, QString> description; | 302 | static QHash<QByteArray, QString> description; | ||
303 | if (description.isEmpty()) { | 303 | if (description.isEmpty()) { | ||
304 | int count = 0; | 304 | int count = 0; | ||
305 | const RoleInfoMap* map = rolesInfoMap(count); | 305 | const RoleInfoMap* map = rolesInfoMap(count); | ||
306 | for (int i = 0; i < count; ++i) { | 306 | for (int i = 0; i < count; ++i) { | ||
307 | if (!map[i].roleTranslation) { | ||||
308 | continue; | ||||
309 | } | ||||
307 | description.insert(map[i].role, i18nc(map[i].roleTranslationContext, map[i].roleTranslation)); | 310 | description.insert(map[i].role, i18nc(map[i].roleTranslationContext, map[i].roleTranslation)); | ||
308 | } | 311 | } | ||
309 | } | 312 | } | ||
310 | 313 | | |||
311 | return description.value(role); | 314 | return description.value(role); | ||
312 | } | 315 | } | ||
313 | 316 | | |||
314 | QList<QPair<int, QVariant> > KFileItemModel::groups() const | 317 | QList<QPair<int, QVariant> > KFileItemModel::groups() const | ||
▲ Show 20 Lines • Show All 466 Lines • ▼ Show 20 Line(s) | |||||
781 | } | 784 | } | ||
782 | 785 | | |||
783 | void KFileItemModel::onGroupedSortingChanged(bool current) | 786 | void KFileItemModel::onGroupedSortingChanged(bool current) | ||
784 | { | 787 | { | ||
785 | Q_UNUSED(current); | 788 | Q_UNUSED(current); | ||
786 | m_groups.clear(); | 789 | m_groups.clear(); | ||
787 | } | 790 | } | ||
788 | 791 | | |||
789 | void KFileItemModel::onSortRoleChanged(const QByteArray& current, const QByteArray& previous) | 792 | void KFileItemModel::onSortRoleChanged(const QByteArray& current, const QByteArray& previous, bool resortItems) | ||
790 | { | 793 | { | ||
791 | Q_UNUSED(previous); | 794 | Q_UNUSED(previous); | ||
792 | m_sortRole = typeForRole(current); | 795 | m_sortRole = typeForRole(current); | ||
793 | 796 | | |||
794 | if (!m_requestRole[m_sortRole]) { | 797 | if (!m_requestRole[m_sortRole]) { | ||
795 | QSet<QByteArray> newRoles = m_roles; | 798 | QSet<QByteArray> newRoles = m_roles; | ||
796 | newRoles << current; | 799 | newRoles << current; | ||
797 | setRoles(newRoles); | 800 | setRoles(newRoles); | ||
798 | } | 801 | } | ||
799 | 802 | | |||
803 | if (resortItems) { | ||||
800 | resortAllItems(); | 804 | resortAllItems(); | ||
801 | } | 805 | } | ||
806 | } | ||||
802 | 807 | | |||
803 | void KFileItemModel::onSortOrderChanged(Qt::SortOrder current, Qt::SortOrder previous) | 808 | void KFileItemModel::onSortOrderChanged(Qt::SortOrder current, Qt::SortOrder previous) | ||
804 | { | 809 | { | ||
805 | Q_UNUSED(current); | 810 | Q_UNUSED(current); | ||
806 | Q_UNUSED(previous); | 811 | Q_UNUSED(previous); | ||
807 | resortAllItems(); | 812 | resortAllItems(); | ||
808 | } | 813 | } | ||
809 | 814 | | |||
▲ Show 20 Lines • Show All 897 Lines • ▼ Show 20 Line(s) | 1705 | if (m_sortDirsFirst || m_sortRole == SizeRole) { | |||
1707 | } | 1712 | } | ||
1708 | } | 1713 | } | ||
1709 | 1714 | | |||
1710 | result = sortRoleCompare(a, b, collator); | 1715 | result = sortRoleCompare(a, b, collator); | ||
1711 | 1716 | | |||
1712 | return (sortOrder() == Qt::AscendingOrder) ? result < 0 : result > 0; | 1717 | return (sortOrder() == Qt::AscendingOrder) ? result < 0 : result > 0; | ||
1713 | } | 1718 | } | ||
1714 | 1719 | | |||
1715 | void KFileItemModel::sort(QList<KFileItemModel::ItemData*>::iterator begin, | 1720 | void KFileItemModel::sort(const QList<KFileItemModel::ItemData*>::iterator &begin, | ||
1716 | QList<KFileItemModel::ItemData*>::iterator end) const | 1721 | const QList<KFileItemModel::ItemData*>::iterator &end) const | ||
1717 | { | 1722 | { | ||
1718 | auto lambdaLessThan = [&] (const KFileItemModel::ItemData* a, const KFileItemModel::ItemData* b) | 1723 | auto lambdaLessThan = [&] (const KFileItemModel::ItemData* a, const KFileItemModel::ItemData* b) | ||
1719 | { | 1724 | { | ||
1720 | return lessThan(a, b, m_collator); | 1725 | return lessThan(a, b, m_collator); | ||
1721 | }; | 1726 | }; | ||
1722 | 1727 | | |||
1723 | if (m_sortRole == NameRole) { | 1728 | if (m_sortRole == NameRole) { | ||
1724 | // Sorting by name can be expensive, in particular if natural sorting is | 1729 | // Sorting by name can be expensive, in particular if natural sorting is | ||
▲ Show 20 Lines • Show All 247 Lines • ▼ Show 20 Line(s) | 1976 | if (newGroupValue != groupValue) { | |||
1972 | groupValue = newGroupValue; | 1977 | groupValue = newGroupValue; | ||
1973 | groups.append(QPair<int, QVariant>(i, newGroupValue)); | 1978 | groups.append(QPair<int, QVariant>(i, newGroupValue)); | ||
1974 | } | 1979 | } | ||
1975 | } | 1980 | } | ||
1976 | 1981 | | |||
1977 | return groups; | 1982 | return groups; | ||
1978 | } | 1983 | } | ||
1979 | 1984 | | |||
1980 | QList<QPair<int, QVariant> > KFileItemModel::timeRoleGroups(std::function<QDateTime(const ItemData *)> fileTimeCb) const | 1985 | QList<QPair<int, QVariant> > KFileItemModel::timeRoleGroups(const std::function<QDateTime(const ItemData *)> &fileTimeCb) const | ||
1981 | { | 1986 | { | ||
1982 | Q_ASSERT(!m_itemData.isEmpty()); | 1987 | Q_ASSERT(!m_itemData.isEmpty()); | ||
1983 | 1988 | | |||
1984 | const int maxIndex = count() - 1; | 1989 | const int maxIndex = count() - 1; | ||
1985 | QList<QPair<int, QVariant> > groups; | 1990 | QList<QPair<int, QVariant> > groups; | ||
1986 | 1991 | | |||
1987 | const QDate currentDate = QDate::currentDate(); | 1992 | const QDate currentDate = QDate::currentDate(); | ||
1988 | 1993 | | |||
▲ Show 20 Lines • Show All 387 Lines • Show Last 20 Lines |