]> Git trees. - libqmvoc.git/commitdiff
Add function to delete lessons, optionally with contents.
authorFrederik Gladhorn <gladhorn@kde.org>
Thu, 15 Mar 2007 21:42:31 +0000 (21:42 +0000)
committerFrederik Gladhorn <gladhorn@kde.org>
Thu, 15 Mar 2007 21:42:31 +0000 (21:42 +0000)
svn path=/trunk/KDE/kdeedu/libkdeedu/; revision=642940

kdeeducore/keduvocdocument.cpp
kdeeducore/keduvocdocument.h

index ea12aebffaf34adddd0c37d0754ba01a27ed3d0e..a890ebe66a645c5c0a58f60d28fcfdc7d7f9ee59 100644 (file)
@@ -1210,6 +1210,31 @@ int KEduVocDocument::lessonCount() const
   return d->m_lessonDescriptions.count();
 }
 
+bool KEduVocDocument::deleteLesson(int lessonIndex, int deleteMode)
+{  // too bad we count from one!
+  lessonIndex++;
+  for (int ent = 0; ent < entryCount(); ent++) {
+    if (entry(ent)->lesson() == lessonIndex) {
+      if (deleteMode == DeleteEmptyLesson)
+        return false; // stop if there are vocabs left in the lesson
+      if (deleteMode == DeleteEntriesAndLesson)
+        // delete entries of this lesson with this lesson
+        removeEntry(ent);
+    }
+  }//for entries
+
+  // for all above this lesson number - reduce lesson by one.
+  for (int ent = 0; ent < entryCount(); ent++) {
+    if (entry(ent)->lesson() > lessonIndex) {
+      entry(ent)->setLesson(entry(ent)->lesson()-1);
+    }
+  } // reduce lesson
+
+  // finally just remove the lesson name
+  d->m_lessonDescriptions.removeAt(lessonIndex-1); // because of the damned 0 arghh
+  return true;
+}
+
 
 void KEduVocDocument::setLessonDescriptions(const QStringList &names)
 {
index 25a253d907705f6b6e45e33d732986c8437d24e2..117604c91b6f56b2bd22e2cc750700bd67eb32ef 100644 (file)
@@ -479,6 +479,13 @@ public:
    * @returns                the number of lessons defined
    */
   int lessonCount() const;
+  /**
+   * Delete a lesson.
+   * @param lessonIndex which lesson
+   * @param deleteMode either KVocDocument::DeleteEmptyLesson (delete only if empty) or KVocDocument::DeleteEntriesAndLesson (delete including vocabulary in that lesson)
+   * @returns if the deletion was successfull. If there are vocabularies in the lesson, but DeleteEmptyLesson, this will return false and not delete the lesson.
+   */
+  bool deleteLesson(int lessonIndex, int deleteMode);
 
   /**
    * Sets the description of the lesson
@@ -567,6 +574,11 @@ public:
     Writing
   };
 
+  enum LessonDeletion {
+    DeleteEmptyLesson,
+    DeleteEntriesAndLesson
+  };
+
   /**
    * Create a string with the supported document types, that can be used
    * as filter in KFileDialog. It includes also an entry to match all the
@@ -582,6 +594,7 @@ Q_SIGNALS:
   void docModified (bool mod);
 
 private:
+  // The private data of this - see KEduVocDocument::Private, implemented in keduvocdocument.cpp
   class Private;
   Private* const d;