]> Git trees. - libqmvoc.git/commitdiff
Make lessons a list again.
authorFrederik Gladhorn <gladhorn@kde.org>
Thu, 6 Sep 2007 11:49:44 +0000 (11:49 +0000)
committerFrederik Gladhorn <gladhorn@kde.org>
Thu, 6 Sep 2007 11:49:44 +0000 (11:49 +0000)
QMap is too flexible. Users will kill us for changing lesson order. The flexibility of the map makes the lesson model in KVocTrain much harder to implement.
Moved the inQuery flag into the lesson class.
Fixed readers and writers. I could not verify if the keduvocvokabelnreader.cpp works.
The first lesson has 0 as index now.
A default lesson is created according to Jeremys plans, but within the document class itself, after reading the doc, so all readers profit from it.
KEduVocExpression is not initialized to lesson=-1 as default.
The old reader maps lesson 1 to 0.
Splitting and deleting lessons seems to work.
Moving lessons is not implemented (this will become interesting, when drag and drop for the lesson model is enabled).
TODO: When adding an expression, the document can automatically add it to the lesson.
  Right now we call doc->lesson.add(Exp) and doc->addExp(lesson). The later should suffice.
Fixes in KVocTrain (many +-1 are no longer needed).
CCMAIL:jeremy@scitools.com
CCMAIL:peter@peterandlinda.com

svn path=/trunk/KDE/kdeedu/libkdeedu/; revision=709026

keduvocdocument/keduvocdocument.cpp
keduvocdocument/keduvocdocument.h
keduvocdocument/keduvocexpression.cpp
keduvocdocument/keduvocexpression.h
keduvocdocument/keduvockvtml2reader.cpp
keduvocdocument/keduvockvtml2writer.cpp
keduvocdocument/keduvockvtmlreader.cpp
keduvocdocument/keduvockvtmlwriter.cpp
keduvocdocument/keduvoclesson.cpp
keduvocdocument/keduvoclesson.h
keduvocdocument/keduvocvokabelnreader.cpp

index 0582c756634358bc804c73e07446a554288abba4..f426e9a5fcfd98041ccf8932d0200574f6eda9cc 100644 (file)
@@ -80,7 +80,6 @@ public:
     QString                   m_queryorg;
     QString                   m_querytrans;
     QList<KEduVocExpression>  m_vocabulary;
-    QList<int>                m_lessonsInQuery;
 
     QStringList               m_tenseDescriptions;
     QSet<QString>             m_usages;
@@ -96,8 +95,8 @@ public:
       */
     QString                   m_category;
 
-    // make this a map so removals don't require renumbering :)
-    QMap<int, KEduVocLesson>  m_lessons;
+    // A map is too error prone. Lesson order is very important.
+    QList<KEduVocLesson>      m_lessons;
 
     KEduVocWordType*          m_wordTypes;
 
@@ -307,6 +306,23 @@ bool KEduVocDocument::open( const KUrl& url )
         f->close();
         KIO::NetAccess::removeTempFile( temporaryFile );
     }
+
+    // Additional cleanup: Put entries without a lesson into a default lesson.
+    int defaultLessonNumber = appendLesson(i18n("Default Lesson"));
+    // now make sure we don't have any orphan entries (lesson -1)
+    for (int i = 0; i < entryCount(); ++i)
+    {
+        if (entry(i)->lesson() == -1)
+        {
+            entry(i)->setLesson(defaultLessonNumber);
+            lesson(defaultLessonNumber).addEntry(i);
+        }
+    }
+    if (lesson(defaultLessonNumber).entries().size() == 0)
+    {
+        deleteLesson(defaultLessonNumber, DeleteEmptyLesson);
+    }
+
     return read;
 }
 
@@ -817,49 +833,16 @@ kDebug() << "appendIdentifier: " << i << id.name() << id.locale();
 }
 
 
-// int KEduVocDocument::appendIdentifier(const QString & name)
-// {
-//     KEduVocIdentifier identifier;
-//     identifier.setName(name);
-//     return appendIdentifier(identifier);
-// }
-
-
-
-//QString KEduVocDocument::lessonDescription(int idx) const
-//{
-//  if (idx == 0)
-//    return i18nc("@label:listbox","<placeholder>no lesson</placeholder>");
-
-//  if (idx <= 0 || idx > d->m_lessons.size() )
-//    return "";
-
-//  return d->m_lessons[idx-1].description();
-//}
-
-//int KEduVocDocument::lessonIndex(const QString &description) const
-//{
-//  return d->m_lessonDescriptions.indexOf(description) +1;
-//}
-
-
-int KEduVocDocument::addLesson( const QString &lessonName, int position )
+int KEduVocDocument::appendLesson( const QString &lessonName, bool inQuery )
 {
-    if ( position == -1 ) {
-        // no position was specified, so put it wherever there's a slot
-        position = 1;
-        while ( d->m_lessons.contains( position ) ) {
-            ++position;
-        }
-    }
-
     KEduVocLesson lesson;
     lesson.setName( lessonName );
-    d->m_lessons.insert( position, lesson );
-    return position;
+    lesson.setInQuery( inQuery );
+    d->m_lessons.append( lesson );
+    return d->m_lessons.count() - 1;
 }
 
-QMap<int, KEduVocLesson> & KEduVocDocument::lessons() const
+QList<KEduVocLesson> & KEduVocDocument::lessons() const
 {
     return d->m_lessons;
 }
@@ -869,41 +852,37 @@ KEduVocLesson & KEduVocDocument::lesson( int index )
     return d->m_lessons[index];
 }
 
-//void KEduVocDocument::renameLesson(const int lessonIndex, const QString &lessonName)
-//{
-//  d->m_lessonDescriptions.replace(lessonIndex-1, lessonName); // counting from 1
-//}
-
-
 bool KEduVocDocument::lessonInQuery( int lessonIndex ) const
 {
-    return d->m_lessonsInQuery.contains( lessonIndex );
+    return d->m_lessons.value(lessonIndex).inQuery();
 }
 
-
 void KEduVocDocument::addLessonToQuery( int lessonIndex )
 {
-    if ( !lessonInQuery( lessonIndex ) )
-        d->m_lessonsInQuery.append( lessonIndex );
+    d->m_lessons[lessonIndex].setInQuery( true );
 }
 
-
 void KEduVocDocument::removeLessonFromQuery( int lessonIndex )
 {
-    if ( lessonInQuery( lessonIndex ) )
-        d->m_lessonsInQuery.removeAt( d->m_lessonsInQuery.indexOf( lessonIndex ) );
+    d->m_lessons[lessonIndex].setInQuery( false );
 }
 
-
 QList<int> KEduVocDocument::lessonsInQuery() const
 {
-    return d->m_lessonsInQuery;
+    QList<int> lessons;
+    for ( int i = 0; i < d->m_lessons.count(); i++ ) {
+        if ( d->m_lessons.value(i).inQuery() ) {
+            lessons.append(i);
+        }
+    }
+    return lessons;
 }
 
-
 void KEduVocDocument::setLessonsInQuery( const QList<int> &lesson_iq )
 {
-    d->m_lessonsInQuery = lesson_iq;
+    for ( int i = 0; i < d->m_lessons.count(); i++ ) {
+        d->m_lessons[i].setInQuery( lesson_iq.contains(i) );
+    }
 }
 
 KUrl KEduVocDocument::url() const
@@ -1032,9 +1011,8 @@ void KEduVocDocument::setCurrentLesson( int lesson )
 QStringList KEduVocDocument::lessonNames() const
 {
     QStringList descriptions;
-    QList<KEduVocLesson> lessonObjects = lessons().values();
-    for ( int i = 0; i < lessonObjects.count(); ++i ) {
-        descriptions.append( lessonObjects[i].name() );
+    foreach ( KEduVocLesson lesson, d->m_lessons ) {
+        descriptions.append(lesson.name());
     }
     return descriptions;
 }
@@ -1046,8 +1024,7 @@ int KEduVocDocument::lessonCount() const
 }
 
 bool KEduVocDocument::deleteLesson( int lessonIndex, int deleteMode )
-{  // too bad we count from one!
-    lessonIndex++;
+{
     for ( int ent = entryCount() - 1; ent  >= 0 ; ent-- ) {
         if ( entry( ent )->lesson() == lessonIndex ) {
             if ( deleteMode == DeleteEmptyLesson )
@@ -1065,18 +1042,9 @@ bool KEduVocDocument::deleteLesson( int lessonIndex, int deleteMode )
         }
     } // reduce lesson
 
-    // finally just remove the lesson name
-    //d->m_lessonDescriptions.removeAt(lessonIndex-1); // because of the damned 0 arghh
+    // finally just remove the lesson
+    d->m_lessons.removeAt(lessonIndex);
 
-    int currentInQuery = d->m_lessonsInQuery.indexOf( lessonIndex );
-    if ( currentInQuery != -1 )
-        d->m_lessonsInQuery.removeAt( currentInQuery );
-
-    // move query entries
-    for ( int queryLesson = 0; queryLesson < d->m_lessonsInQuery.count(); queryLesson++ ) {
-        if ( d->m_lessonsInQuery.at( queryLesson ) > lessonIndex )
-            d->m_lessonsInQuery.replace( queryLesson, d->m_lessonsInQuery.at( queryLesson )-1 );
-    }
     return true;
 }
 
index 8391525ebd0736ca62292ba1efa153edba61cdb3..79a03b8900b49fcb71b6460ddaaa40a66cec27d1 100644 (file)
@@ -405,38 +405,38 @@ public:
     /** get all lesson objects
      * @returns a map of pointers to lesson objects
      */
-    QMap<int, KEduVocLesson> & lessons() const;
+    QList<KEduVocLesson> & lessons() const;
 
     /**
      * @returns                the number of lessons defined
      */
     int lessonCount() const;
 
-    /**
+    /** DEPRECATED - USE lesson.inQuery();
      * Get list of ALL lessons that are selected for query.
      * @returns a list with the lessons in the current query
      */
     QList<int> lessonsInQuery() const;
 
-    /**
+    /** DEPRECATED - USE lesson.setInQuery();
      * Sets ALL lessons in the query. Better use addLessonToQuery and removeLessonFromQuery.
      */
     void setLessonsInQuery( const QList<int> &lesson_iq );
 
-    /**
+    /** DEPRECATED - USE lesson.inQuery();
      * Check if @p lessonIndex is in the query.
      * @param lessonIndex - index of the lesson
      * @return true if in query
      */
     bool lessonInQuery( int lessonIndex ) const;
 
-    /**
+    /** DEPRECATED - USE lesson.setInQuery();
      * Add @p lessonIndex to the query.
      * @param lessonIndex - index of the lesson
      */
     void addLessonToQuery( int lessonIndex );
 
-    /**
+    /** DEPRECATED - USE lesson.setInQuery();
      * Remove @p lessonIndex from the query.
      * @param lessonIndex - index of the lesson
      */
@@ -445,10 +445,9 @@ public:
     /**
      * Append a new lesson to the list of lessons.
      * @param lessonName name for the new lesson
-     * @param position lesson number to use (-1 to find the next hole to put it in)
      * @returns the index of the new lesson
      */
-    int addLesson( const QString &lessonName, int position = -1 );
+    int appendLesson( const QString &lessonName, bool inQuery=true );
 
     /**
      * Delete a lesson.
@@ -458,46 +457,18 @@ public:
      */
     bool deleteLesson( int lessonIndex, int deleteMode );
 
-    ///**
-    // * 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 description lesson name
-     * @returns the index of the lesson (from its name)
-     * -1 if the lesson does not exist
-     */
-    //int lessonIndex(const QString &description) const;
-
-    /**
-     * Rename a lesson.
-     * @param lessonIndex index of lesson
-     * @param lessonName new name for the lesson
-     */
-    //void renameLesson(const int lessonIndex, const QString &lessonName);
-
-    /**
+    /** DEPRECATED
      * All lesson descriptions as stringlist.
      * @returns a list of defined lessons
      */
     QStringList lessonNames() const;
 
-    /**
-     * Sets the description of the lesson
-     * @param names list of all names of the lessons
-     */
-    //void setLessonDescriptions(const QStringList &names);
-
-    /**
+    /** @todo implement this?
      * 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);
+    void moveLesson(int from, int to);
 
     // *** file format specific methods ***
 
index 10b16d104ee40b7e2c833d02ced9f1d374f6b947..9462390a42d797aa2d8eae145da5392d0ba2c0a7 100644 (file)
@@ -53,7 +53,7 @@ void KEduVocExpression::KEduVocExpressionPrivate::init()
 
     m_inQuery = false;
     m_active = true;
-    m_lesson = 0;
+    m_lesson = -1;
     m_sortIndex = 0;
     m_sizeHint = 0;
 }
index c6050c011cfc36eeb9f5b1be87636ada404fc11c..10ecef4c1eebfb0ac1f900983c12c0c57a205256 100644 (file)
@@ -38,12 +38,12 @@ public:
      */
     explicit KEduVocExpression();
 
-    /** Constructor for a vocabulary expression with an original
+    /** Constructor for a vocabulary expression with one translation
      *
-     * @param expression       original
-     * @param lesson           lesson number, 0 for none
+     * @param expression       translation
+     * @param lesson           lesson number
      */
-    explicit KEduVocExpression( const QString & expression, int lesson = 0 );
+    explicit KEduVocExpression( const QString & expression, int lesson = -1 );
 
     /** Constructor for a vocabulary expression with an original and one or more translations
      *
@@ -51,17 +51,17 @@ public:
      * @param separator        expression will be split into an original and one or more translations using separator
      * @param lesson           lesson number, 0 for none
      */
-    KEduVocExpression( const QStringList & translations, int lesson = 0 );
+    KEduVocExpression( const QStringList & translations, int lesson = -1 );
 
     KEduVocExpression( const KEduVocExpression &expression );
 
     ~KEduVocExpression();
 
-    /** returns index of lesson (0 = none)
+    /** returns index of lesson (-1 = none)
      */
     int lesson() const;
 
-    /** sets index of lesson (0 = none)
+    /** sets index of lesson (-1 = none)
      */
     void setLesson( int l );
 
index 2cbf6f72540684a35669945fad48ccc4904f0ab0..52e9e3cce3fb67df27d74c4ce4ed5ffedfd0d8cf 100644 (file)
@@ -84,23 +84,6 @@ bool KEduVocKvtml2Reader::readDoc( KEduVocDocument *doc )
 
     bool result = readGroups( domElementKvtml ); // read sub-groups
 
-    int defaultLessonNumber = m_doc->addLesson(i18n("Default Lesson"));
-
-    // now make sure we don't have any orphan entries (lesson 0)
-    for (int i = 0; i < m_doc->entryCount(); ++i)
-    {
-        if (m_doc->entry(i)->lesson() == 0)
-        {
-            m_doc->entry(i)->setLesson(defaultLessonNumber);
-            m_doc->lesson(defaultLessonNumber).addEntry(i);
-        }
-    }
-    
-    if (m_doc->lesson(defaultLessonNumber).entries().size() == 0)
-    {
-        m_doc->deleteLesson(defaultLessonNumber, KEduVocDocument::DeleteEmptyLesson);
-    }
-    
     return result;
 }
 
@@ -192,11 +175,6 @@ bool KEduVocKvtml2Reader::readGroups( QDomElement &domElementParent )
     groupElement = domElementParent.firstChildElement( KVTML_ENTRIES );
     if ( !groupElement.isNull() ) {
         QDomNodeList entryList = groupElement.elementsByTagName( KVTML_ENTRY );
-        if ( entryList.length() <= 0 ) {
-            m_errorMessage = i18n( "no entries found in 'entries' tag" );
-            return false; // at least one entry is required
-        }
-
         for ( int i = 0; i < entryList.count(); ++i ) {
             currentElement = entryList.item( i ).toElement();
             if ( currentElement.parentNode() == groupElement ) {
@@ -459,12 +437,11 @@ bool KEduVocKvtml2Reader::readLesson( QDomElement &lessonElement )
 {
     // NOTE: currently this puts an identifier into the last lesson it is in, once support for multiple lessons
     // is in the entry class, all lessons that include an entry will be in there
-    int lessonId = 0;
-
+    int lessonId;
     //<name>Lesson name</name>
     QDomElement currentElement = lessonElement.firstChildElement( KVTML_NAME );
     if ( !currentElement.isNull() ) {
-        lessonId = m_doc->addLesson( currentElement.text() );
+        lessonId = m_doc->appendLesson( currentElement.text() );
     } else {
         m_errorMessage = i18n( "each lesson must have a name" );
         return false;
@@ -473,9 +450,7 @@ bool KEduVocKvtml2Reader::readLesson( QDomElement &lessonElement )
     //<query>true</query>
     currentElement = lessonElement.firstChildElement( KVTML_QUERY );
     if ( !currentElement.isNull() ) {
-        if ( currentElement.text() == KVTML_TRUE ) {
-            m_doc->addLessonToQuery( lessonId );
-        }
+        m_doc->lesson(lessonId).setInQuery(currentElement.text() == KVTML_TRUE);
     }
 
     //<current>true</current>
index 3ee224b22efd83c6482378a262aa0da14064fab2..2dc621d23324a0fdb06d66aad94fd897e4188813 100644 (file)
@@ -174,29 +174,26 @@ bool KEduVocKvtml2Writer::writeIdentifiers( QDomElement &identifiersElement )
 
 bool KEduVocKvtml2Writer::writeLessons( QDomElement &lessonsElement )
 {
-    if ( m_doc->lessonCount() == 0 )
-        return true;
-
-    QMap<int, KEduVocLesson> lessons = m_doc->lessons();
-
-    foreach( int lessonid, lessons.keys() ) {
-        KEduVocLesson thisLesson = lessons[lessonid];
-
+    for( int lessonId = 0; lessonId < m_doc->lessonCount(); lessonId++ ) {
         // make lesson element
         QDomElement thisLessonElement = m_domDoc.createElement( KVTML_LESSON );
 
         // add a name
-        thisLessonElement.appendChild( newTextElement( KVTML_NAME, thisLesson.name() ) );
+        thisLessonElement.appendChild( newTextElement( KVTML_NAME, m_doc->lesson(lessonId).name() ) );
 
         // add a inquery tag
-        thisLessonElement.appendChild( newTextElement( KVTML_QUERY, m_doc->lessonInQuery( lessonid ) ? KVTML_TRUE : KVTML_FALSE ) );
+        if ( m_doc->lesson(lessonId).inQuery() ) {
+            thisLessonElement.appendChild( newTextElement( KVTML_QUERY, KVTML_TRUE ) );
+        }
 
         // add a current tag
-        thisLessonElement.appendChild( newTextElement( KVTML_CURRENT, m_doc->currentLesson() == lessonid ? KVTML_TRUE : KVTML_FALSE ) );
+        if ( lessonId == m_doc->currentLesson() ) {
+            thisLessonElement.appendChild( newTextElement( KVTML_CURRENT, KVTML_TRUE ) );
+        }
 
         // TODO: add the entryids...
         for ( int i = 0; i < m_doc->entryCount(); ++i ) {
-            if ( m_doc->entry( i )->lesson() == lessonid ) {
+            if ( m_doc->entry( i )->lesson() == lessonId ) {
                 thisLessonElement.appendChild( newTextElement( KVTML_ENTRYID, QString::number( i ) ) );
             }
         }
index 721159573eb54de37a8ba773c89596b2a1e769d2..4f4acaabe9658e3fe753a39abb93600e2665d46c 100644 (file)
@@ -220,40 +220,38 @@ bool KEduVocKvtmlReader::readLesson( QDomElement &domElementParent )
     if ( entryList.length() <= 0 )
         return false;
 
-    QList<int> inQueryList;
-
     for ( int i = 0; i < entryList.count(); ++i ) {
         currentElement = entryList.item( i ).toElement();
         if ( currentElement.parentNode() == domElementParent ) {
-            int no = 0;
+            int no;
             bool isCurr = false;
 
             attribute = currentElement.attributeNode( KV_LESS_NO );
-            if ( !attribute.isNull() )
+            if ( !attribute.isNull() ) {
                 no = attribute.value().toInt();
+            }
 
             attribute = currentElement.attributeNode( KV_LESS_CURR );
-            if ( !attribute.isNull() )
-                isCurr = attribute.value().toInt() != 0;
-
-            if ( isCurr && no != 0 )
-                m_doc->setCurrentLesson( no );
+            if ( !attribute.isNull() ) {
+                if ( attribute.value().toInt() != 0 ) {
+                    m_doc->setCurrentLesson( no );
+                }
+            }
 
+            bool inQuery;
             attribute = currentElement.attributeNode( KV_LESS_QUERY );
-            if ( !attribute.isNull() )
-                if ( attribute.value().toInt() != 0 && no > 0 )
-                    inQueryList.append( no );
+            if ( !attribute.isNull() ) {
+                inQuery =  attribute.value().toInt() != 0;
+            }
 
             s = currentElement.text();
-            if ( s.isNull() )
-                s = "";
-            m_doc->addLesson( s, no );
+            int index = m_doc->appendLesson( s, inQuery );
+            if ( index != no-1 ) {
+                kDebug() << "Warning! Lesson order may be confused. Are all lessons in order in the file?";
+            }
         }
     }
 
-    if ( inQueryList.count() > 0 )
-        m_doc->setLessonsInQuery( inQueryList );
-
     return true;
 }
 
@@ -864,7 +862,7 @@ bool KEduVocKvtmlReader::readExpression( QDomElement &domElementParent )
     QString                   q_org;
     QString                   q_trans;
     QString                   query_id;
-    int                       lesson = 0;
+    int                       lesson = - 1;
     int                       width;
     QString                   type;
     QString                   subType;
@@ -890,13 +888,15 @@ bool KEduVocKvtmlReader::readExpression( QDomElement &domElementParent )
 
     attribute = domElementParent.attributeNode( KV_LESS_MEMBER );
     if ( !attribute.isNull() ) {
-        lesson = attribute.value().toInt();
-    }
-
-    if ( lesson && lesson > m_doc->lessonCount() ) {
-        // it's from a lesson that hasn't been added yet
-        // so make sure this lesson is in the document
-        m_doc->addLesson( QString( "#" ) + QString::number( lesson ), lesson );
+        // we start conting from 0 in new documents
+        lesson = attribute.value().toInt() - 1;
+        if ( lesson > m_doc->lessonCount() ) {
+            ///@todo can this happen? does it need a while loop?
+            // it's from a lesson that hasn't been added yet
+            // so make sure this lesson is in the document
+            kDebug() << "Warning: lesson > m_doc->lessonCount() in readExpression.";
+            m_doc->appendLesson( i18nc("A generic name for a new lesson and its number.", "Lesson %1" ), lesson );
+        }
     }
 
     attribute = domElementParent.attributeNode( KV_SELECTED );
@@ -1071,12 +1071,15 @@ bool KEduVocKvtmlReader::readExpression( QDomElement &domElementParent )
         i++;
     }
 
-    if ( m_doc->entryCount() == 0 )
+    if ( m_doc->entryCount() == 0 ) {
         m_doc->setQueryIdentifier( q_org, q_trans );
+    }
     m_doc->appendEntry( &expr );
 
     // also add this entryid to the lesson it's part of
-    m_doc->lesson( lesson ).addEntry( m_doc->entryCount() );
+    if ( lesson >= 0 ) {
+        m_doc->lesson( lesson ).addEntry( m_doc->entryCount() );
+    }
 
     return true;
 }
index 3637284df7fea4d7e175423a6129c03933307d97..5cc34bd6423150444bd8075c51bdfd3d4dfe9881 100644 (file)
@@ -299,19 +299,17 @@ bool KEduVocKvtmlWriter::writeLesson( QDomDocument &domDoc, QDomElement &domElem
     QDomElement domElementLesson = domDoc.createElement( KV_LESS_GRP );
     domElementLesson.setAttribute( KV_SIZEHINT, m_doc->sizeHint( -1 ) );
 
-    QMap<int, KEduVocLesson> lessons = m_doc->lessons();
-    QList<int> keys = lessons.keys();
-    for ( int i = 0; i < keys.size(); ++i ) {
-        int thiskey = keys[i];
+    for ( int i = 0; i < m_doc->lessonCount(); ++i ) {
         QDomElement domElementDesc = domDoc.createElement( KV_LESS_DESC );
-        QDomText domTextDesc = domDoc.createTextNode( lessons[thiskey].name() );
+        QDomText domTextDesc = domDoc.createTextNode( m_doc->lesson(i).name() );
 
-        domElementDesc.setAttribute( KV_LESS_NO, thiskey );
-        if ( m_doc->currentLesson() == thiskey )
+        domElementDesc.setAttribute( KV_LESS_NO, i );
+        if ( m_doc->currentLesson() == i ) {
             domElementDesc.setAttribute( KV_LESS_CURR, 1 );
-        if ( m_doc->lessonInQuery( thiskey ) )
+        }
+        if ( m_doc->lesson(i).inQuery() ) {
             domElementDesc.setAttribute( KV_LESS_QUERY, 1 );
-
+        }
         domElementDesc.appendChild( domTextDesc );
         domElementLesson.appendChild( domElementDesc );
     }
index 8c4d2fdf357484c7da70e2dd2de75d81e99d6a24..df3346fd47dfad8cb53eef9d2f16ae1ce8797791 100644 (file)
@@ -28,6 +28,7 @@ class KEduVocLesson::Private
 public:
     QSet<int> m_entries;
     QString m_name;
+    bool m_inQuery;
 };
 
 KEduVocLesson::KEduVocLesson()
@@ -82,3 +83,13 @@ void KEduVocLesson::removeEntry( int entryid )
 {
     d->m_entries.remove( entryid );
 }
+
+bool KEduVocLesson::inQuery()
+{
+    return d->m_inQuery;
+}
+
+void KEduVocLesson::setInQuery(bool inQuery)
+{
+    d->m_inQuery = inQuery;
+}
index 10a4b11dd82a04ba29ad3847efba54850f2d507e..cc53a56872eb40e2b25078bc0eade51c7fbc04f4 100644 (file)
@@ -62,7 +62,10 @@ public:
      * @param entryid id of the entry to remove
      */
     void removeEntry( int entryid );
-    
+
+    bool inQuery();
+    void setInQuery( bool inQuery );
+
     /** equality operator */
     bool operator==(const KEduVocLesson &other);
 
index ce342c9eaab771829f0cc69da5e7bb495e53a34e..d547f045c7fc62c84bb7b5a78a1e4da8b27f490f 100644 (file)
@@ -127,6 +127,7 @@ bool KEduVocVokabelnReader::readDoc( KEduVocDocument *doc )
         kve.setTranslation( 1, translation );
         kve.translation( 1 ).gradeFrom( 0 ).setGrade( 0 );
         kve.translation( 0 ).gradeFrom( 1 ).setGrade( 0 );
+        /// @todo lesson might need a -1. I have no specs or documents to verify.
         kve.setLesson( lesson );
 
         m_doc->appendEntry( &kve );
@@ -143,7 +144,7 @@ bool KEduVocVokabelnReader::readDoc( KEduVocDocument *doc )
         lessonDescr = inputStream.readLine();
         lessonDescr = lessonDescr.mid( 1, lessonDescr.length() - 2 );
         if ( !lessonDescr.isEmpty() )
-            m_doc->addLesson( lessonDescr );
+            m_doc->appendLesson( lessonDescr );
         else
             break;
         inputStream.readLine();