Restore word sorting in WordListWidget
authorMarcin Kaźmierczak <marcin@marcin-desktop.(none)>
Thu, 20 Jan 2011 12:48:36 +0000 (13:48 +0100)
committerMarcin Kaźmierczak <marcin@marcin-desktop.(none)>
Thu, 20 Jan 2011 12:48:36 +0000 (13:48 +0100)
src/mdictionary/gui/WordListModel.cpp
src/mdictionary/gui/WordListModel.h

index 2999778..ba9a977 100644 (file)
@@ -83,8 +83,8 @@ void WordListModel::setTranslations(QHash<QString, QList<Translation *> > transl
         i.next();
         addWord(i.key(), i.value(), wordsInBookmarks[i.key()]);
     }
-    //todo: repair sorting
-//    sort(0);
+
+    sort(0);
 
 }
 
@@ -94,41 +94,15 @@ void WordListModel::sort(int column, Qt::SortOrder order)
         return;
 
     int left = 0;
-    int right = _wordList.count();
+    int right = _wordList.count() - 1;
 
     if (left < right){
         if (order == Qt::AscendingOrder){
-            ascendingQuickSort(left, right);
+            qSort(_wordList.begin(), _wordList.end());
         } else if (order == Qt::DescendingOrder) {
-            descendingQuickSort(left, right);
-        }
-    }
-}
-
-void WordListModel::ascendingQuickSort(int left, int right){
-    int m = left;
-    for(int i = left+1; i < right; i++){
-        if(_wordList[i] < _wordList[left]){
-            _wordList.swap(++m, i);
+            qSort(_wordList.begin(), _wordList.end(), qGreater<QString>());
         }
     }
-
-    _wordList.swap(left, m);
-    ascendingQuickSort(left, m - 1);
-    ascendingQuickSort(m + 1, right);
-}
-
-void WordListModel::descendingQuickSort(int left, int right){
-    int m = left;
-    for(int i = left+1; i < right; i++){
-        if(_wordList[i] > _wordList[left]){
-            _wordList.swap(++m, i);
-        }
-    }
-
-    _wordList.swap(left, m);
-    ascendingQuickSort(left, m - 1);
-    ascendingQuickSort(m + 1, right);
 }
 
 void WordListModel::setModelProperty(int index, const QVariant value, QString role)
index 2db6e3b..abb128d 100644 (file)
@@ -60,9 +60,6 @@ private:
     QHash<QString, bool > _wordInBookmarks;
     QList<QString> _wordList;
 
-    void ascendingQuickSort(int left, int right);
-    void descendingQuickSort(int left, int right);
-
 };
 
 #endif // WORDLISTMODEL_H