From caabf33daa734606d034ea65f733da5ba020f3e2 Mon Sep 17 00:00:00 2001 From: Peter Hedlund Date: Wed, 20 Jul 2005 03:09:14 +0000 Subject: [PATCH] Basic vocabulary sorting now works again svn path=/branches/work/kwordquiz/src/keduvocdocument.h; revision=436611 --- kwordquiz/keduvocdocument.cpp | 55 ++++++++++++++++++++++++++--------- kwordquiz/keduvocdocument.h | 2 +- 2 files changed, 43 insertions(+), 14 deletions(-) diff --git a/kwordquiz/keduvocdocument.cpp b/kwordquiz/keduvocdocument.cpp index 39811f7..53cbc95 100644 --- a/kwordquiz/keduvocdocument.cpp +++ b/kwordquiz/keduvocdocument.cpp @@ -18,29 +18,23 @@ #include "keduvocdocument.h" +#include + #include #include #include #include #include -#include - -#include -#include -#include using namespace std; #include -#include - #include "keduvockvtmlwriter.h" #include "keduvockvtmlreader.h" #include "keduvocwqlwriter.h" #include "keduvocwqlreader.h" #include "leitnersystem.h" -//#include "prefs.h" //******************************************************** // KEduVocDocument @@ -75,7 +69,7 @@ void KEduVocDocument::Init () m_typeDescriptions.clear(); m_tenseDescriptions.clear(); m_identifiers.clear(); - m_sortLanguage.clear(); + m_sortIdentifier.clear(); m_extraSizeHints.clear(); m_sizeHints.clear(); m_vocabulary.clear(); @@ -527,7 +521,7 @@ void KEduVocDocument::setOriginalIdentifier(const QString &id) } } - +/* class sortByOrg : public binary_function { @@ -637,10 +631,44 @@ public: int index; bool dir; }; +*/ +/**@todo implement sorting based on lesson index and name. + * Will be done when KVocTrain is ported to this class +*/ +int sortIndex; +bool sortAscending; + +bool operator< (const KEduVocExpression &e1, const KEduVocExpression &e2) +{ + if (sortAscending) + if (sortIndex == 0) + return ! (e1.original() > e2.original()); + else + return ! (e1.translation(sortIndex) > e2.translation(sortIndex)); + else + if (sortIndex == 0) + return ! (e1.original() < e2.original()); + else + return ! (e1.translation(sortIndex) < e2.translation(sortIndex)); +} - -bool KEduVocDocument::sort (int index) +bool KEduVocDocument::sort(int index) { + bool result = false; + if (m_enableSorting && index < numIdentifiers()) + { + if (m_sortIdentifier.count() < m_identifiers.count()) + for (int i = m_sortIdentifier.count(); i < (int) m_identifiers.count(); i++) + m_sortIdentifier.append(false); + + sortAscending = m_sortIdentifier[index]; + sortIndex = index; + qHeapSort(m_vocabulary); + m_sortIdentifier[index] = !m_sortIdentifier[index]; + result = m_sortIdentifier[index]; + } + return result; + /*if (!sort_allowed) return false; @@ -1136,7 +1164,8 @@ int KEduVocDocument::cleanUp() f_ent_percent = to_delete.size () / 100.0; emit progressChanged(this, 0); - std::sort (to_delete.begin(), to_delete.end() ); + qHeapSort(to_delete.begin(), to_delete.end()); + //std::sort (to_delete.begin(), to_delete.end() ); for (int i = (int) to_delete.size()-1; i >= 0; i--) { ent_no++; if (ent_percent != 0 && (ent_no % ent_percent) == 0 ) diff --git a/kwordquiz/keduvocdocument.h b/kwordquiz/keduvocdocument.h index 063cba2..fc8b4b3 100644 --- a/kwordquiz/keduvocdocument.h +++ b/kwordquiz/keduvocdocument.h @@ -659,7 +659,7 @@ protected: private: bool m_dirty; KURL m_url; - QValueList m_sortLanguage; + QValueList m_sortIdentifier; bool m_sortLesson; bool m_unknownAttribute; bool m_unknownElement; -- 2.47.3