Paste

URL To paste - | raw - Sat Feb 03 2018 12:21:05 GMT+0000 (Coordinated Universal Time)
diff --git a/src/kitemviews/kfileitemmodel.cpp b/src/kitemviews/kfileitemmodel.cpp
index a5422a7bf..4facc7b8b 100644
--- a/src/kitemviews/kfileitemmodel.cpp
+++ b/src/kitemviews/kfileitemmodel.cpp
@@ -43,6 +43,7 @@
 KFileItemModel::KFileItemModel(QObject* parent) :
     KItemModelBase("text", parent),
     m_dirLister(nullptr),
+    m_collator(),
     m_sortDirsFirst(true),
     m_sortRole(NameRole),
     m_sortingProgressPercent(-1),
@@ -1226,7 +1227,7 @@ void KFileItemModel::insertItems(QList& newItems)
 
         while (sourceIndexNewItems >= 0) {
             ItemData* newItem = newItems.at(sourceIndexNewItems);
-            if (sourceIndexExistingItems >= 0 && lessThan(newItem, m_itemData.at(sourceIndexExistingItems), m_collator)) {
+            if (sourceIndexExistingItems >= 0 && lessThan(newItem, m_itemData.at(sourceIndexExistingItems))) {
                 // Move an existing item to its new position. If any new items
                 // are behind it, push the item range to itemRanges.
                 if (rangeCount > 0) {
@@ -1443,14 +1444,14 @@ void KFileItemModel::emitItemsChangedAndTriggerResorting(const KItemRangeList& i
             // (b)  the successor of the last item is "lessThan" the last item, or
             // (c)  the internal order of the items in the range is incorrect.
             if (first > 0
-                && lessThan(m_itemData.at(first), m_itemData.at(first - 1), m_collator)) {
+                && lessThan(m_itemData.at(first), m_itemData.at(first - 1))) {
                 needsResorting = true;
             } else if (last < count() - 1
-                && lessThan(m_itemData.at(last + 1), m_itemData.at(last), m_collator)) {
+                && lessThan(m_itemData.at(last + 1), m_itemData.at(last))) {
                 needsResorting = true;
             } else {
                 for (int index = first; index < last; ++index) {
-                    if (lessThan(m_itemData.at(index + 1), m_itemData.at(index), m_collator)) {
+                    if (lessThan(m_itemData.at(index + 1), m_itemData.at(index))) {
                         needsResorting = true;
                         break;
                     }
@@ -1667,7 +1668,7 @@ QHash KFileItemModel::retrieveData(const KFileItem& item,
     return data;
 }
 
-bool KFileItemModel::lessThan(const ItemData* a, const ItemData* b, const QCollator& collator) const
+bool KFileItemModel::lessThan(const ItemData* a, const ItemData* b) const
 {
     int result = 0;
 
@@ -1712,7 +1713,7 @@ bool KFileItemModel::lessThan(const ItemData* a, const ItemData* b, const QColla
         }
     }
 
-    result = sortRoleCompare(a, b, collator);
+    result = sortRoleCompare(a, b);
 
     return (sortOrder() == Qt::AscendingOrder) ? result < 0 : result > 0;
 }
@@ -1723,46 +1724,24 @@ bool KFileItemModel::lessThan(const ItemData* a, const ItemData* b, const QColla
 class KFileItemModelLessThan
 {
 public:
-    KFileItemModelLessThan(const KFileItemModel* model, const QCollator& collator) :
-        m_model(model),
-        m_collator(collator)
+    KFileItemModelLessThan(const KFileItemModel* model) :
+        m_model(model)
     {
     }
 
-    KFileItemModelLessThan(const KFileItemModelLessThan& other) :
-        m_model(other.m_model),
-        m_collator()
-    {
-        m_collator.setCaseSensitivity(other.m_collator.caseSensitivity());
-        m_collator.setIgnorePunctuation(other.m_collator.ignorePunctuation());
-        m_collator.setLocale(other.m_collator.locale());
-        m_collator.setNumericMode(other.m_collator.numericMode());
-    }
-
-    ~KFileItemModelLessThan() = default;
-    //We do not delete m_model as the pointer was passed from outside ant it will be deleted elsewhere.
-
-    KFileItemModelLessThan& operator=(const KFileItemModelLessThan& other)
-    {
-        m_model = other.m_model;
-        m_collator = other.m_collator;
-        return *this;
-    }
-
     bool operator()(const KFileItemModel::ItemData* a, const KFileItemModel::ItemData* b) const
     {
-        return m_model->lessThan(a, b, m_collator);
+        return m_model->lessThan(a, b);
     }
 
 private:
     const KFileItemModel* m_model;
-    QCollator m_collator;
 };
 
 void KFileItemModel::sort(QList::iterator begin,
                           QList::iterator end) const
 {
-    KFileItemModelLessThan lessThan(this, m_collator);
+    KFileItemModelLessThan lessThan(this);
 
     if (m_sortRole == NameRole) {
         // Sorting by name can be expensive, in particular if natural sorting is
@@ -1777,7 +1756,7 @@ void KFileItemModel::sort(QList::iterator begin,
     }
 }
 
-int KFileItemModel::sortRoleCompare(const ItemData* a, const ItemData* b, const QCollator& collator) const
+int KFileItemModel::sortRoleCompare(const ItemData* a, const ItemData* b) const
 {
     const KFileItem& itemA = a->item;
     const KFileItem& itemB = b->item;
@@ -1862,7 +1841,7 @@ int KFileItemModel::sortRoleCompare(const ItemData* a, const ItemData* b, const
     case ImageSizeRole: {
         // Alway use a natural comparing to interpret the numbers of a string like
         // "1600 x 1200" for having a correct sorting.
-        result = collator.compare(a->values.value("imageSize").toString(),
+        result = m_collator.compare(a->values.value("imageSize").toString(),
                                   b->values.value("imageSize").toString());
         break;
     }
@@ -1882,13 +1861,13 @@ int KFileItemModel::sortRoleCompare(const ItemData* a, const ItemData* b, const
     }
 
     // Fallback #1: Compare the text of the items
-    result = stringCompare(itemA.text(), itemB.text(), collator);
+    result = stringCompare(itemA.text(), itemB.text());
     if (result != 0) {
         return result;
     }
 
     // Fallback #2: KFileItem::text() may not be unique in case UDS_DISPLAY_NAME is used
-    result = stringCompare(itemA.name(), itemB.name(), collator);
+    result = stringCompare(itemA.name(), itemB.name());
     if (result != 0) {
         return result;
     }
@@ -1899,14 +1878,14 @@ int KFileItemModel::sortRoleCompare(const ItemData* a, const ItemData* b, const
     return QString::compare(itemA.url().url(), itemB.url().url(), Qt::CaseSensitive);
 }
 
-int KFileItemModel::stringCompare(const QString& a, const QString& b, const QCollator& collator) const
+int KFileItemModel::stringCompare(const QString& a, const QString& b) const
 {
     if (m_naturalSorting) {
-        return collator.compare(a, b);
+        return m_collator.compare(a, b);
     }
 
-    const int result = QString::compare(a, b, collator.caseSensitivity());
-    if (result != 0 || collator.caseSensitivity() == Qt::CaseSensitive) {
+    const int result = QString::compare(a, b, m_collator.caseSensitivity());
+    if (result != 0 || m_collator.caseSensitivity() == Qt::CaseSensitive) {
         // Only return the result, if the strings are not equal. If they are equal by a case insensitive
         // comparison, still a deterministic sort order is required. A case sensitive
         // comparison is done as fallback.
@@ -2393,7 +2372,7 @@ bool KFileItemModel::isConsistent() const
         }
 
         // Check if the items are sorted correctly.
-        if (i > 0 && !lessThan(m_itemData.at(i - 1), m_itemData.at(i), m_collator)) {
+        if (i > 0 && !lessThan(m_itemData.at(i - 1), m_itemData.at(i))) {
             qCWarning(DolphinDebug) << "The order of items" << i - 1 << "and" << i << "is wrong:"
                 << fileItem(i - 1) << fileItem(i);
             return false;
diff --git a/src/kitemviews/kfileitemmodel.h b/src/kitemviews/kfileitemmodel.h
index 4589b5422..30c3863a8 100644
--- a/src/kitemviews/kfileitemmodel.h
+++ b/src/kitemviews/kfileitemmodel.h
@@ -364,7 +364,7 @@ private:
      * @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 QCollator& collator) const;
+    bool lessThan(const ItemData* a, const ItemData* b) const;
 
     /**
      * Sorts the items between \a begin and \a end using the comparison
@@ -377,9 +377,9 @@ 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 QCollator& collator) const;
+    int sortRoleCompare(const ItemData* a, const ItemData* b) const;
 
-    int stringCompare(const QString& a, const QString& b, const QCollator& collator) const;
+    int stringCompare(const QString& a, const QString& b) const;
 
     bool useMaximumUpdateInterval() const;