From: Frederik Gladhorn Date: Sun, 25 Mar 2007 22:04:57 +0000 (+0000) Subject: Make lesson handling easier, add functions to add/remove an individual lesson. Use... X-Git-Tag: v3.90.1~23 X-Git-Url: https://git.rmz.fi/?a=commitdiff_plain;h=38d38bd4361cb60c5b3d38ea83b1f8d47572b673;p=libqmvoc.git Make lesson handling easier, add functions to add/remove an individual lesson. Use QList instead of QList m_lessonsInQuery. Make saving and loading lessons work and simplify keduvockvtmlwriter.cpp to use the new functions. svn path=/trunk/KDE/kdeedu/libkdeedu/; revision=646498 --- diff --git a/kdeeducore/keduvocdocument.cpp b/kdeeducore/keduvocdocument.cpp index 3fa6b84..77a3bed 100644 --- a/kdeeducore/keduvocdocument.cpp +++ b/kdeeducore/keduvocdocument.cpp @@ -70,7 +70,7 @@ public: QString m_queryorg; QString m_querytrans; QList m_vocabulary; - QList m_lessonsInQuery; + QList m_lessonsInQuery; QStringList m_lessonDescriptions; QStringList m_typeDescriptions; QStringList m_tenseDescriptions; @@ -1074,30 +1074,40 @@ int KEduVocDocument::lessonIndex(const QString description) const } -QList KEduVocDocument::lessonsInQuery() const +bool KEduVocDocument::lessonInQuery(int lessonIndex) const { - QList iqvec; - for (int i = 0; i < d->m_lessonsInQuery.size(); i++) - if (d->m_lessonsInQuery[i]) { - iqvec.push_back(i+1); // Offset -// cout << "getliq: " << i+1 << endl; - } - return iqvec; + if (d->m_lessonsInQuery.contains(lessonIndex)) + return true; + else + return false; } -void KEduVocDocument::setLessonsInQuery(const QList &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 KEduVocDocument::lessonsInQuery() const +{ + return d->m_lessonsInQuery; } +void KEduVocDocument::setLessonsInQuery(const QList &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) { diff --git a/kdeeducore/keduvocdocument.h b/kdeeducore/keduvocdocument.h index db9d2bd..c53ab37 100644 --- a/kdeeducore/keduvocdocument.h +++ b/kdeeducore/keduvocdocument.h @@ -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 lessonsInQuery() const; /** - * Sets the lessons in the current query + * Sets ALL lessons in the query. Better use addLessonToQuery and removeLessonFromQuery. */ void setLessonsInQuery(const QList &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 diff --git a/kdeeducore/keduvockvtmlwriter.cpp b/kdeeducore/keduvockvtmlwriter.cpp index 027dc0d..8934dcd 100644 --- a/kdeeducore/keduvockvtmlwriter.cpp +++ b/kdeeducore/keduvockvtmlwriter.cpp @@ -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);