outputStream.setDevice(m_outputFile);
outputStream.setCodec("UTF-8");
- outputStream << i18n("! Title:") << separator << m_doc->title() << "\n";
- outputStream << i18n("! Author:") << separator << m_doc->author() << "\n";
+ outputStream << i18nc("@item:intable the title of the document will be written here", "! Title:") << separator << m_doc->title() << "\n";
+ outputStream << i18nc("@item:intable the author will be written here", "! Author:") << separator << m_doc->author() << "\n";
KEduVocExpression *expression;
int idCount = m_doc->identifierCount();
#include <kfilterdev.h>
#include "keduvocexpression.h"
+#include "keduvoclesson.h"
#include "keduvockvtmlwriter.h"
#include "keduvockvtml2writer.h"
#include "keduvoccsvreader.h"
QString m_querytrans;
QList<KEduVocExpression> m_vocabulary;
QList<int> m_lessonsInQuery;
- QStringList m_lessonDescriptions;
+ //QStringList m_lessonDescriptions;
QStringList m_typeDescriptions;
QStringList m_tenseDescriptions;
QStringList m_usageDescriptions;
QList<KEduVocArticle> m_articles;
QList<KEduVocConjugation> m_conjugations;
+
+ // make this a map so removals don't require renumbering :)
+ QMap<int, KEduVocLesson*> m_lessons;
LeitnerSystem* m_leitnerSystem;
bool m_activeLeitnerSystem;
void KEduVocDocument::KEduVocDocumentPrivate::init()
{
- m_lessonDescriptions.clear();
+ m_lessons.clear();
m_articles.clear();
m_typeDescriptions.clear();
m_tenseDescriptions.clear();
return d->m_identifiers.count(); // number of translations
}
-
int KEduVocDocument::appendIdentifier(const QString & id)
{
d->m_identifiers.append(id);
return d->m_identifiers.size() - 1;
}
+//QString KEduVocDocument::lessonDescription(int idx) const
+//{
+// if (idx == 0)
+// return i18nc("@label:listbox","<placeholder>no lesson</placeholder>");
-QString KEduVocDocument::lessonDescription(int idx) const
-{
- if (idx == 0)
- return i18n("<no lesson>");
+// if (idx <= 0 || idx > d->m_lessons.size() )
+// return "";
- if (idx <= 0 || idx > d->m_lessonDescriptions.size() )
- return "";
+// return d->m_lessons[idx-1].description();
+//}
- return d->m_lessonDescriptions[idx-1];
-}
+//int KEduVocDocument::lessonIndex(const QString &description) const
+//{
+// return d->m_lessonDescriptions.indexOf(description) +1;
+//}
-int KEduVocDocument::lessonIndex(const QString &description) const
+
+int KEduVocDocument::addLesson(const QString &lessonName, int position)
{
- return d->m_lessonDescriptions.indexOf(description) +1;
+ 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 = new KEduVocLesson;
+ lesson->setDescription(lessonName);
+ d->m_lessons.insert(position, lesson);
+ return position;
}
-
-int KEduVocDocument::appendLesson(const QString &lessonName)
+const QMap<int, KEduVocLesson *> &KEduVocDocument::lessons() const
{
- d->m_lessonDescriptions.append(lessonName);
- return d->m_lessonDescriptions.count(); // counting from 1
+ return d->m_lessons;
}
-
-void KEduVocDocument::renameLesson(const int lessonIndex, const QString &lessonName)
+KEduVocLesson * KEduVocDocument::lesson(int index)
{
- d->m_lessonDescriptions.replace(lessonIndex-1, lessonName); // counting from 1
+ KEduVocLesson * retval(NULL);
+ if (d->m_lessons.contains(index))
+ {
+ retval = d->m_lessons[index];
+ }
+ return retval;
}
+//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
{
QStringList KEduVocDocument::lessonDescriptions() const
{
- return d->m_lessonDescriptions;
+ QStringList descriptions;
+ QList<KEduVocLesson*> lessonObjects = lessons().values();
+ for (int i = 0; i < lessonObjects.count(); ++i)
+ {
+ descriptions.append(lessonObjects[i]->description());
+ }
+ return descriptions;
}
int KEduVocDocument::lessonCount() const
{
- return d->m_lessonDescriptions.count();
+ return d->m_lessons.count();
}
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
+ //d->m_lessonDescriptions.removeAt(lessonIndex-1); // because of the damned 0 arghh
int currentInQuery = d->m_lessonsInQuery.indexOf(lessonIndex);
if(currentInQuery != -1)
}
-void KEduVocDocument::setLessonDescriptions(const QStringList &names)
-{
- d->m_lessonDescriptions = names;
-}
-
-void KEduVocDocument::moveLesson(int from, int to)
-{
-///@todo move in query as well!
- // 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);
- }
- }
- }
-}
+//void KEduVocDocument::setLessonDescriptions(const QStringList &names)
+//{
+// d->m_lessonDescriptions = names;
+//}
+
+//void KEduVocDocument::moveLesson(int from, int to)
+//{
+/////@todo move in query as well!
+// // 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)
{
class QStringList;
class KEduVocExpression;
+class KEduVocLesson;
class LeitnerSystem;
/**
*/
void setCurrentLesson(int 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 description lesson name
- * @returns the index of the lesson (from its name)
- * -1 if the lesson does not exist
+ /** get a lesson object
+ * @returns a pointer to the lesson object at the specified index or NULL if there isn't one
*/
- int lessonIndex(const QString &description) const;
-
- /**
- * Append a new lesson to the list of lessons.
- * @param lessonName name for the new lesson
- * @returns the index of the new lesson
+ KEduVocLesson *lesson(int index);
+
+ /** get all lesson objects
+ * @returns a map of pointers to lesson objects
*/
- int appendLesson(const QString &lessonName);
+ const QMap<int, KEduVocLesson *> &lessons() const;
/**
- * Rename a lesson.
- * @param lessonIndex index of lesson
- * @param lessonName new name for the lesson
+ * @returns the number of lessons defined
*/
- void renameLesson(const int lessonIndex, const QString &lessonName);
+ int lessonCount() const;
/**
* Get list of ALL lessons that are selected for query.
void removeLessonFromQuery(int lessonIndex);
/**
- * All lesson descriptions as stringlist.
- * @returns a list of defined lessons
- */
- QStringList lessonDescriptions() const;
-
- /**
- * @returns the number of lessons defined
+ * 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 lessonCount() const;
+ int addLesson(const QString &lessonName, int position = -1);
/**
* Delete a lesson.
*/
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);
+
+ /**
+ * All lesson descriptions as stringlist.
+ * @returns a list of defined lessons
+ */
+ QStringList lessonDescriptions() const;
+
/**
* Sets the description of the lesson
* @param names list of all names of the lessons
*/
- void setLessonDescriptions(const QStringList &names);
+ //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);
+ //void moveLesson(int from, int to);
// *** conjugation methods ***
#include <klocale.h>
#include "keduvocdocument.h"
+#include "keduvoclesson.h"
#include "kvtml2defs.h"
#include "kvtmldefs.h"
#include "keduvockvtmlreader.h"
}
// TODO: probably should insert at id position with a check to see if it exists
+ // may be useful for detecting corrupt documents
m_doc->insertEntry(&expr, id);
return result;
}
QDomElement currentElement = lessonElement.firstChildElement(KVTML_NAME);
if (!currentElement.isNull())
{
- lessonId = m_doc->appendLesson(currentElement.text());
+ lessonId = m_doc->addLesson(currentElement.text());
}
else
{
// TODO: once we have a lesson class, add each of these entryids to the lesson
// set this lesson for the given enty
m_doc->entry(entryId)->setLesson(lessonId);
+ m_doc->lesson(lessonId)->addEntry(entryId);
currentElement = currentElement.nextSiblingElement(KVTML_ENTRYID);
}
#include "keduvocdocument.h"
#include "keduvocexpression.h"
+#include "keduvoclesson.h"
#include "kvtmldefs.h"
#include "kvtml2defs.h"
bool KEduVocKvtml2Writer::writeLessons(QDomElement &lessonsElement)
{
- if (m_doc->lessonDescriptions().count() == 0)
+ if (m_doc->lessonCount() == 0)
return true;
- int count = 1; // this starts at 1 because appendLesson returns the count of the lessondescriptions
- // instead of the index the lesson was appended at (size() - 1)
- foreach(QString lesson, m_doc->lessonDescriptions())
+ QMap<int, KEduVocLesson*> lessons = m_doc->lessons();
+
+ foreach(int lessonid, lessons.keys())
{
+ KEduVocLesson * thisLesson = lessons[lessonid];
+
// make lesson element
- QDomElement thisLesson = m_domDoc.createElement(KVTML_LESSON);
-
+ QDomElement thisLessonElement = m_domDoc.createElement(KVTML_LESSON);
+
// add a name
- thisLesson.appendChild(newTextElement(KVTML_NAME, lesson));
+ thisLessonElement.appendChild(newTextElement(KVTML_NAME, thisLesson->description()));
// add a inquery tag
- thisLesson.appendChild(newTextElement(KVTML_QUERY, m_doc->lessonInQuery(count) ? KVTML_TRUE : KVTML_FALSE));
+ thisLessonElement.appendChild(newTextElement(KVTML_QUERY, m_doc->lessonInQuery(lessonid) ? KVTML_TRUE : KVTML_FALSE));
// add a current tag
- thisLesson.appendChild(newTextElement(KVTML_CURRENT, m_doc->currentLesson() == count ? KVTML_TRUE : KVTML_FALSE));
+ thisLessonElement.appendChild(newTextElement(KVTML_CURRENT, m_doc->currentLesson() == lessonid ? KVTML_TRUE : KVTML_FALSE));
// TODO: add the entryids...
for (int i = 0; i < m_doc->entryCount(); ++i)
{
- if (m_doc->entry(i)->lesson() == count)
+ if (m_doc->entry(i)->lesson() == lessonid)
{
- thisLesson.appendChild(newTextElement(KVTML_ENTRYID, QString::number(i)));
+ thisLessonElement.appendChild(newTextElement(KVTML_ENTRYID, QString::number(i)));
}
}
- lessonsElement.appendChild(thisLesson);
- ++count;
+ lessonsElement.appendChild(thisLessonElement);
}
return true;
#include <klocale.h>
#include "keduvocdocument.h"
+#include "keduvoclesson.h"
#include "kvtmldefs.h"
KEduVocKvtmlReader::KEduVocKvtmlReader(QIODevice *file)
bool KEduVocKvtmlReader::readLesson(QDomElement &domElementParent)
{
QString s;
- QStringList descriptions;
QDomAttr attribute;
QDomElement currentElement;
if (entryList.length() <= 0)
return false;
- descriptions.clear();
QList<int> inQueryList;
- inQueryList.clear();
for (int i = 0; i < entryList.count(); ++i) {
currentElement = entryList.item(i).toElement();
s = currentElement.text();
if (s.isNull())
s = "";
- descriptions.append(s);
+ m_doc->addLesson(s, no);
}
}
if (inQueryList.count() > 0)
m_doc->setLessonsInQuery(inQueryList);
- m_doc->setLessonDescriptions(descriptions);
return true;
}
attribute = domElementParent.attributeNode(KV_LESS_MEMBER);
if (!attribute.isNull())
+ {
lesson = attribute.value().toInt();
+ }
- if (lesson && lesson > m_doc->lessonDescriptions().count())
+ if (lesson && lesson > m_doc->lessonCount())
{
- // description missing ?
- QString s;
- QStringList sl = m_doc->lessonDescriptions();
- for (int i = m_doc->lessonDescriptions().count(); i < lesson; i++)
- {
- s.setNum(i + 1);
- s.prepend("#"); //create descriptions from number
- sl.append(s);
- }
- m_doc->setLessonDescriptions(sl);
+ // 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);
}
-
+
attribute = domElementParent.attributeNode(KV_SELECTED);
if (!attribute.isNull())
inquery = attribute.value() == "1" ? true : false;
expr.translation(i).gradeFrom(0).setQueryDate(qdate);
expr.translation(0).gradeFrom(i).setQueryDate(r_qdate);
}
-//kDebug() << "KEduVocKvtmlReader::readExpression(): id: " << i << " translation: " << textstr;
// Next translation
currentElement = currentElement.nextSiblingElement(KV_TRANS);
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());
+
return true;
}
#include <kdebug.h>
#include "keduvocdocument.h"
+#include "keduvoclesson.h"
#include "keduvocexpression.h"
#include "kvtmldefs.h"
if (entry->lesson() != 0)
{
int lm = entry->lesson();
- if (lm > m_doc->lessonDescriptions().count())
+ if (lm > m_doc->lessonCount())
{
// should not be
kError() << "index of lesson member too high: " << lm << endl;
bool KEduVocKvtmlWriter::writeLesson(QDomDocument &domDoc, QDomElement &domElementParent)
{
- if (m_doc->lessonDescriptions().count() == 0)
+ if (m_doc->lessonCount() == 0)
return true;
QDomElement domElementLesson = domDoc.createElement(KV_LESS_GRP);
domElementLesson.setAttribute(KV_SIZEHINT, m_doc->sizeHint(-1));
- int count = 1;
- foreach(QString lesson, m_doc->lessonDescriptions())
+ const QMap<int, KEduVocLesson*> lessons = m_doc->lessons();
+ QList<int> keys = lessons.keys();
+ for (int i = 0; i < keys.size(); ++i)
{
- if (!lesson.isNull())
- {
- QDomElement domElementDesc = domDoc.createElement(KV_LESS_DESC);
- QDomText domTextDesc = domDoc.createTextNode(lesson);
-
- domElementDesc.setAttribute(KV_LESS_NO, count);
- if (m_doc->currentLesson() == count)
- domElementDesc.setAttribute(KV_LESS_CURR, 1);
- if (m_doc->lessonInQuery(count))
- domElementDesc.setAttribute(KV_LESS_QUERY, 1);
-
- domElementDesc.appendChild(domTextDesc);
- domElementLesson.appendChild(domElementDesc);
- count++;
- }
+ int thiskey = keys[i];
+ QDomElement domElementDesc = domDoc.createElement(KV_LESS_DESC);
+ QDomText domTextDesc = domDoc.createTextNode(lessons[thiskey]->description());
+
+ domElementDesc.setAttribute(KV_LESS_NO, thiskey);
+ if (m_doc->currentLesson() == thiskey)
+ domElementDesc.setAttribute(KV_LESS_CURR, 1);
+ if (m_doc->lessonInQuery(thiskey))
+ domElementDesc.setAttribute(KV_LESS_QUERY, 1);
+
+ domElementDesc.appendChild(domTextDesc);
+ domElementLesson.appendChild(domElementDesc);
}
domElementParent.appendChild(domElementLesson);
QStringList titles,
languages,
- words,
- lessonDescriptions;
+ words;
bool keepGoing = true;
lessonDescr = inputStream.readLine();
lessonDescr = lessonDescr.mid(1, lessonDescr.length() - 2);
if (!lessonDescr.isEmpty())
- lessonDescriptions.append(lessonDescr);
+ m_doc->addLesson(lessonDescr);
else
break;
inputStream.readLine();
}
- if (lessonDescriptions.count() > 0)
- m_doc->setLessonDescriptions(lessonDescriptions);
-
return true;
}
if(!id1.isNull())
m_doc->appendIdentifier(id1.toString().toLower());
else
- m_doc->appendIdentifier(i18n("Original"));
+ m_doc->appendIdentifier(i18nc("@title:column the original language column", "Original"));
QStringRef id2 = attributes().value("lang_to");
if(!id2.isNull())
m_doc->appendIdentifier(id2.toString().toLower());
else
- m_doc->appendIdentifier(i18n("Translation"));
+ m_doc->appendIdentifier(i18nc("@title:column one of the translation columns", "Translation"));
while (!atEnd()) {
readNext();