QString m_queryorg;
QString m_querytrans;
QList<KEduVocExpression> m_vocabulary;
- QList<bool> m_lessonsInQuery;
+ QList<int> m_lessonsInQuery;
QStringList m_lessonDescriptions;
QStringList m_typeDescriptions;
QStringList m_tenseDescriptions;
}
-QList<int> KEduVocDocument::lessonsInQuery() const
+bool KEduVocDocument::lessonInQuery(int lessonIndex) const
{
- QList<int> iqvec;
- for (int i = 0; i < d->m_lessonsInQuery.size(); i++)
- if (d->m_lessonsInQuery[i]) {
- iqvec.push_back(i+1); // Offset <no lesson>
-// cout << "getliq: " << i+1 << endl;
- }
- return iqvec;
+ if (d->m_lessonsInQuery.contains(lessonIndex))
+ return true;
+ else
+ return false;
}
-void KEduVocDocument::setLessonsInQuery(const QList<int> &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<int> KEduVocDocument::lessonsInQuery() const
+{
+ return d->m_lessonsInQuery;
}
+void KEduVocDocument::setLessonsInQuery(const QList<int> &lesson_iq)
+{
+ d->m_lessonsInQuery = lesson_iq;
+}
+
KUrl KEduVocDocument::url() const
{
return d->m_url;
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)
{
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<int> lessonsInQuery() const;
/**
- * Sets the lessons in the current query
+ * Sets ALL lessons in the query. Better use addLessonToQuery and removeLessonFromQuery.
*/
void setLessonsInQuery(const QList<int> &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
*/
/**
* 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
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);