From: Marcin Kaźmierczak Date: Thu, 20 Jan 2011 12:48:36 +0000 (+0100) Subject: Restore word sorting in WordListWidget X-Git-Url: http://vcs.maemo.org/git/?a=commitdiff_plain;h=55f992f401bdf13a2dc6bdc370a56000bd2914c2;hp=94e25431e7f7a0fa6e5c07ad6e761a1c12fec346;p=mdictionary Restore word sorting in WordListWidget --- diff --git a/src/mdictionary/gui/WordListModel.cpp b/src/mdictionary/gui/WordListModel.cpp index 2999778..ba9a977 100644 --- a/src/mdictionary/gui/WordListModel.cpp +++ b/src/mdictionary/gui/WordListModel.cpp @@ -83,8 +83,8 @@ void WordListModel::setTranslations(QHash > 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()); } } - - _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) diff --git a/src/mdictionary/gui/WordListModel.h b/src/mdictionary/gui/WordListModel.h index 2db6e3b..abb128d 100644 --- a/src/mdictionary/gui/WordListModel.h +++ b/src/mdictionary/gui/WordListModel.h @@ -60,9 +60,6 @@ private: QHash _wordInBookmarks; QList _wordList; - void ascendingQuickSort(int left, int right); - void descendingQuickSort(int left, int right); - }; #endif // WORDLISTMODEL_H