void KEduVocDocument::insertEntry( KEduVocExpression *expression, int index )
{
d->m_vocabulary.insert( index, *expression );
+
+ // now we need to go fix the entryids that are greater than index in the lessons
+ for (int i = 0; i < d->m_lessons.size(); ++i)
+ {
+ d->m_lessons[i].incrementEntriesAbove(index);
+ }
+
setModified();
}
return true;
}
-
-
void KEduVocDocument::merge( KEduVocDocument *docToMerge, bool matchIdentifiers )
{
kDebug() << "Merging of docs is not implemented"; /// @todo IMPLEMENT ME
void KEduVocDocument::removeEntry( int index )
{
- if ( index >= 0 && index < d->m_vocabulary.size() )
+ if ( index >= 0 && index < d->m_vocabulary.size() ) {
d->m_vocabulary.removeAt( index );
+ }
+
+ // now we need to go fix the entryids that are greater than index in the lessons
+ for (int i = 0; i < d->m_lessons.size(); ++i)
+ {
+ d->m_lessons[i].decrementEntriesAbove(index);
+ }
}
/**
* 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)
+ * @param deleteMode either KEduVocDocument::DeleteEmptyLesson (delete only if empty) or KEduVocDocument::DeleteEntriesAndLesson (delete including vocabulary in that lesson)
* @returns if the deletion was successful. If there are vocabularies in the lesson, but DeleteEmptyLesson, this will return false and not delete the lesson.
*/
bool deleteLesson( int lessonIndex, int deleteMode );
d->m_entries.remove( entryid );
}
+void KEduVocLesson::incrementEntriesAbove( int entryid )
+{
+ QList<int> entries = d->m_entries.toList();
+
+ // increment all entry id's above entryid
+ for (int i = 0; i < entries.size(); ++i) {
+ if (entries[i] >= entryid) {
+ entries[i] = entries[i] + 1;
+ }
+ }
+
+ // then put the new list into the set
+ d->m_entries = entries.toSet();
+}
+
+void KEduVocLesson::decrementEntriesAbove( int entryid )
+{
+ QList<int> entries = d->m_entries.toList();
+
+ // increment all entry id's above entryid
+ for (int i = 0; i < entries.size(); ++i) {
+ if (entries[i] > entryid) {
+ entries[i] = entries[i] - 1;
+ }
+ }
+
+ // then put the new list into the set
+ d->m_entries = entries.toSet();
+}
+
bool KEduVocLesson::inQuery()
{
return d->m_inQuery;
* @param entryid id of the entry to remove
*/
void removeEntry( int entryid );
+
+ /** increments all entryids > entryid, because their entryid has been incremented
+ * @param entryid id of the entry that was inserted
+ */
+ void incrementEntriesAbove( int entryid );
+
+ /** decrements all etryids > entryid, because their entryid has been decremented
+ * @param entryid id of the entry that was removed
+ */
+ void decrementEntriesAbove( int entryid );
bool inQuery();
void setInQuery( bool inQuery );