]> Git trees. - libqmvoc.git/commitdiff
Improvements to sorting
authorPeter Hedlund <peter@peterandlinda.com>
Thu, 6 Apr 2006 21:51:06 +0000 (21:51 +0000)
committerPeter Hedlund <peter@peterandlinda.com>
Thu, 6 Apr 2006 21:51:06 +0000 (21:51 +0000)
svn path=/trunk/KDE/kdeedu/libkdeedu/; revision=527111

kdeeducore/keduvocdocument.cpp
kdeeducore/keduvocdocument.h
kdeeducore/keduvocexpression.cpp
kdeeducore/keduvocexpression.h

index 71514f1932492a9c189d05fff43479b833f7bc3f..4d8c4acdb8186b434bb1a10ee6ecd3e4aa5245dd 100644 (file)
@@ -640,18 +640,31 @@ bool sortAscending;
 
 bool operator< (const KEduVocExpression &e1, const KEduVocExpression &e2)
 {
-  int i;
   if (sortAscending)
     if (sortIndex == 0)
-      i = QString::localeAwareCompare(e1.original(), e2.original());
+      return e1.original() < e2.original();
     else
-      i = QString::localeAwareCompare(e1.translation(sortIndex), e2.translation(sortIndex));
+      return e1.translation(sortIndex) < e2.translation(sortIndex);
   else
     if (sortIndex == 0)
-      i = QString::localeAwareCompare(e2.original(), e1.original());
+      return !(e1.original() < e2.original());
     else
-      i = QString::localeAwareCompare(e2.translation(sortIndex), e2.translation(sortIndex));
-  return (i >= 0);
+      return !(e1.translation(sortIndex) < e2.translation(sortIndex));
+}
+
+bool KEduVocDocument::sort(int index, Qt::SortOrder order)
+{
+  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);
+
+    m_sortIdentifier[index] = (order == Qt::AscendingOrder);
+    result = sort(index);
+  }
+  return result;
 }
 
 bool KEduVocDocument::sort(int index)
@@ -665,7 +678,7 @@ bool KEduVocDocument::sort(int index)
 
     sortAscending = m_sortIdentifier[index];
     sortIndex = index;
-    qStableSort(m_vocabulary);
+    qSort(m_vocabulary);
     m_sortIdentifier[index] = !m_sortIdentifier[index];
     result = m_sortIdentifier[index];
   }
index ea1b120ed94f56927a2e65fadbfee5eaf82795ba..fc5c074b177527c9fa631be7cf10ebbabbffef07 100644 (file)
@@ -314,11 +314,20 @@ class KEduVocDocument : public QObject
   /**
    * Sorts vocabulary alphabetically
    *
-   * @param  index            index expression
+   * @param index             index identifier (0 = original, 1..n = translations
    * @returns                 the direction of sorting: true = ascending
    */
   bool sort(int index);
 
+  /**
+   * Sorts vocabulary alphabetically
+   *
+   * @param index             index identifier (0 = original, 1..n = translations
+   * @param order             the order used when sorting
+   * @returns                 the direction of sorting: true = ascending
+   */
+  bool sort(int index, Qt::SortOrder order);
+
   /**
    * Removes equal entries (original plus all translations)
    *
index eed7a07c38d9721686954a33d27d73ff257118af..f9cb23b49dd10a13b5755566bf56225a3f971687 100644 (file)
@@ -3,7 +3,7 @@
     -----------------------------------------------------------------------
     copyright            : (C) 1999-2001 Ewald Arnold
                            (C) 2001 The KDE-EDU team
-                           (C) 2005 Peter Hedlund
+                           (C) 2005-2006 Peter Hedlund
     email                : peter.hedlund@kdemail.net
  ***************************************************************************/
 
@@ -32,6 +32,7 @@ void KEduVocExpression::Init()
   m_queryDates.append(dt);
   m_reverseQueryDates.append(dt);
   m_lesson = 0;
+  m_sortIndex = 0;
 }
 
 KEduVocExpression::KEduVocExpression ()
@@ -796,11 +797,11 @@ void KEduVocExpression::setType (int idx, const QString &type)
 
 void KEduVocExpression::setLeitnerBox( const QString& box )
 {
-       m_leitnerBox = box;
+  m_leitnerBox = box;
 }
 
 QString& KEduVocExpression::leitnerBox()
 {
-       return m_leitnerBox;
+  return m_leitnerBox;
 }
 
index bb4d91bda200c6c3bd0a39e609c60e2179a575f0..62107e50dbe070c8939e4a1c424996e97fde45a4 100644 (file)
@@ -3,7 +3,7 @@
     -----------------------------------------------------------------------
     copyright            : (C) 1999-2001 Ewald Arnold
                            (C) 2001 The KDE-EDU team
-                           (C) 2005 Peter Hedlund
+                           (C) 2005-2006 Peter Hedlund
     email                : peter.hedlund@kdemail.net
  ***************************************************************************/
 
@@ -436,11 +436,11 @@ public:
    */
   QString& leitnerBox();
 
- protected:
+protected:
 
   void Init();
 
- private:
+private:
   QString m_original;
 
   // all these vectors must be deleted in removeTranslation()
@@ -468,6 +468,7 @@ public:
   QList<KEduVocMultipleChoice> m_multipleChoices;
 
   QString m_leitnerBox;
+  int m_sortIndex;
   int m_lesson;
   bool m_inQuery;
   bool m_active;