]> Git trees. - libqmvoc.git/commitdiff
Make lesson handling easier, add functions to add/remove an individual lesson. Use...
authorFrederik Gladhorn <gladhorn@kde.org>
Sun, 25 Mar 2007 22:04:57 +0000 (22:04 +0000)
committerFrederik Gladhorn <gladhorn@kde.org>
Sun, 25 Mar 2007 22:04:57 +0000 (22:04 +0000)
svn path=/trunk/KDE/kdeedu/libkdeedu/; revision=646498

kdeeducore/keduvocdocument.cpp
kdeeducore/keduvocdocument.h
kdeeducore/keduvockvtmlwriter.cpp

index 3fa6b840b90f11c786ade4bb72a936fdca344f01..77a3bedbd2ab14e0afc6d953880d5ac63c30183a 100644 (file)
@@ -70,7 +70,7 @@ public:
   QString                   m_queryorg;
   QString                   m_querytrans;
   QList<KEduVocExpression>  m_vocabulary;
-  QList<bool>               m_lessonsInQuery;
+  QList<int>                m_lessonsInQuery;
   QStringList               m_lessonDescriptions;
   QStringList               m_typeDescriptions;
   QStringList               m_tenseDescriptions;
@@ -1074,30 +1074,40 @@ int KEduVocDocument::lessonIndex(const QString description) const
 }
 
 
-QList<int> KEduVocDocument::lessonsInQuery() const
+bool KEduVocDocument::lessonInQuery(int lessonIndex) const
 {
-  QList<int> iqvec;
-  for (int i = 0; i < d->m_lessonsInQuery.size(); i++)
-    if (d->m_lessonsInQuery[i]) {
-      iqvec.push_back(i+1);   // Offset <no lesson>
-//      cout << "getliq: " << i+1 << endl;
-    }
-  return iqvec;
+  if (d->m_lessonsInQuery.contains(lessonIndex))
+    return true;
+  else
+    return false;
 }
 
 
-void KEduVocDocument::setLessonsInQuery(const QList<int> &lesson_iq)
+void KEduVocDocument::addLessonToQuery(int lessonIndex)
+{
+  if(!lessonInQuery(lessonIndex))
+    d->m_lessonsInQuery.append(lessonIndex);
+}
+
+
+void KEduVocDocument::removeLessonFromQuery(int lessonIndex)
 {
-  d->m_lessonsInQuery.clear();
-  for (int i = 0; i < d->m_lessonDescriptions.count(); i++)
-    d->m_lessonsInQuery.append(false);
+  if(lessonInQuery(lessonIndex))
+    d->m_lessonsInQuery.removeAt(d->m_lessonsInQuery.indexOf(lessonIndex));
+}
 
-  foreach(int i, lesson_iq)
-    if (i <= d->m_lessonsInQuery.count())
-      d->m_lessonsInQuery[i - 1] = true;
+
+QList<int> KEduVocDocument::lessonsInQuery() const
+{
+  return d->m_lessonsInQuery;
 }
 
 
+void KEduVocDocument::setLessonsInQuery(const QList<int> &lesson_iq)
+{
+  d->m_lessonsInQuery = lesson_iq;
+}
+
 KUrl KEduVocDocument::url() const
 {
   return d->m_url;
@@ -1253,6 +1263,37 @@ void KEduVocDocument::setLessonDescriptions(const QStringList &names)
   d->m_lessonDescriptions = names;
 }
 
+void KEduVocDocument::moveLesson(int from, int to)
+{
+  // still counting from 1
+  d->m_lessonDescriptions.move(from -1, to -1);
+
+  /*
+  to > from?
+    lesson >= from && lesson < to: lesson++
+  to < from?
+    lesson >= to && lesson < from: lesson++
+  */
+  for (int ent = 0; ent < entryCount(); ent++) {
+    // put from directly to to
+    if (entry(ent)->lesson() == from) {
+      entry(ent)->setLesson(to);
+    }
+    else
+    {
+      if(to > from)
+      {
+        if(entry(ent)->lesson() >= from && entry(ent)->lesson() < to)
+          entry(ent)->setLesson(entry(ent)->lesson()-1);
+      }
+      else
+      {
+        if(entry(ent)->lesson() >= to && entry(ent)->lesson() < from)
+          entry(ent)->setLesson(entry(ent)->lesson()+1);
+      }
+    }
+  }
+}
 
 int KEduVocDocument::search(const QString &substr, int id, int first, int last, bool word_start)
 {
index db9d2bd21f3d896916372cb09a68d134ffe0fd41..c53ab37d528c99a6e7a67d5ed77e328e9446c6ac 100644 (file)
@@ -451,26 +451,52 @@ public:
   void setCurrentLesson(int lesson);
 
   /**
-   * @returns the description of the lesson
+   * Get the real name of a lesson from it's index as QString.
+   * @param index lesson index
+   * @returns the description (Name) of the lesson with index @p index .
    */
   QString lessonDescription(int index) const;
 
   /**
+   * Get the index from the long name of a lesson.
+   * @param index lesson index
    * @returns the index of the lesson (from its name)
    * -1 if the lesson does not exist
    */
   int lessonIndex(const QString description) const;
 
   /**
+   * Get list of ALL lessons that are selected for query.
    * @returns a list with the lessons in the current query
    */
   QList<int> lessonsInQuery() const;
 
   /**
-   * Sets the lessons in the current query
+   * Sets ALL lessons in the query. Better use addLessonToQuery and removeLessonFromQuery.
    */
   void setLessonsInQuery(const QList<int> &lesson_iq);
 
+  /**
+   * Check if @p lessonIndex is in the query.
+   * @param lessonIndex - index of the lesson
+   * @return true if in query
+   */
+  bool lessonInQuery(int lessonIndex) const;
+
+  /**
+   * Add @p lessonIndex to the query.
+   * @param lessonIndex - index of the lesson
+   */
+  void addLessonToQuery(int lessonIndex);
+
+  /**
+   * Remove @p lessonIndex from the query.
+   * @param lessonIndex - index of the lesson
+   */
+  void removeLessonFromQuery(int lessonIndex);
+
+
+
   /**
    * @returns                a list of defined lessons
    */
@@ -490,9 +516,17 @@ public:
 
   /**
    * Sets the description of the lesson
+   * @param names list of all names of the lessons
    */
   void setLessonDescriptions(const QStringList &names);
 
+  /**
+   * Moves the lesson at index position from to index position to.
+   * @param from the lesson to be moved
+   * @param to the new position
+   */
+  void moveLesson(int from, int to);
+
   /**
    * @param index            index of translation
    * @returns                a pointer to conjugations if available
index 027dc0d9536dda28019c92c7ed83a76594e564a5..8934dcdd51b7577ce7989864d701c199dc3b254b 100644 (file)
@@ -316,13 +316,7 @@ bool KEduVocKvtmlWriter::writeLesson(QDomDocument &domDoc, QDomElement &domEleme
       domElementDesc.setAttribute(KV_LESS_NO, count);
       if (m_doc->currentLesson() == count)
         domElementDesc.setAttribute(KV_LESS_CURR, 1);
-      bool inQuery = false;
-      ///@todo check that this is working
-      foreach(int liq, m_doc->lessonsInQuery())
-        if (liq == count - 1)
-          inQuery = true;
-
-      if (count - 1 < m_doc->lessonsInQuery().count() && inQuery)
+      if (m_doc->lessonInQuery(count))
         domElementDesc.setAttribute(KV_LESS_QUERY, 1);
 
       domElementDesc.appendChild(domTextDesc);