From: Frederik Gladhorn Date: Thu, 15 Mar 2007 21:42:31 +0000 (+0000) Subject: Add function to delete lessons, optionally with contents. X-Git-Tag: v3.90.1~29 X-Git-Url: https://git.rmz.fi/?a=commitdiff_plain;h=f589bae552a5113c0906c68ed1b8e26d16649529;p=libqmvoc.git Add function to delete lessons, optionally with contents. svn path=/trunk/KDE/kdeedu/libkdeedu/; revision=642940 --- diff --git a/kdeeducore/keduvocdocument.cpp b/kdeeducore/keduvocdocument.cpp index ea12aeb..a890ebe 100644 --- a/kdeeducore/keduvocdocument.cpp +++ b/kdeeducore/keduvocdocument.cpp @@ -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) { diff --git a/kdeeducore/keduvocdocument.h b/kdeeducore/keduvocdocument.h index 25a253d..117604c 100644 --- a/kdeeducore/keduvocdocument.h +++ b/kdeeducore/keduvocdocument.h @@ -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;