Move lesson specific stuff out of there.
Next: Start the word type class.
svn path=/branches/work/kdeedu_parley/libkdeedu/; revision=742271
keduvocidentifier.cpp
keduvocexpression.cpp
keduvoctranslation.cpp
+ keduvoccontainer.cpp
keduvoclesson.cpp
keduvocgrade.cpp
keduvocgrammar.cpp
--- /dev/null
+/***************************************************************************
+
+ Copyright 2007 Jeremy Whiting <jeremywhiting@scitools.com>
+ Copyright 2007 Frederik Gladhorn <frederik.gladhorn@kdemail.net>
+
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#include "keduvoccontainer.h"
+
+#include "keduvocexpression.h"
+
+#include <QList>
+
+/** private class to store information about a lesson */
+class KEduVocContainer::Private
+{
+public:
+ ~Private();
+
+ // properties for this lesson
+ QString m_name;
+ bool m_inPractice;
+
+ // other lessons in the tree
+ KEduVocContainer *m_parentContainer;
+ QList<KEduVocContainer*> m_childContainers;
+
+ EnumContainerType m_type;
+
+ /// Image url
+ KUrl m_imageUrl;
+};
+
+KEduVocContainer::Private::~ Private()
+{
+ qDeleteAll(m_childContainers);
+}
+
+KEduVocContainer::KEduVocContainer(const QString& name, EnumContainerType type, KEduVocContainer *parent)
+ : d( new Private )
+{
+ d->m_parentContainer = parent;
+ d->m_name = name;
+ d->m_inPractice = false;
+ d->m_type = type;
+}
+
+KEduVocContainer::KEduVocContainer( const KEduVocContainer &other )
+ : d( new Private )
+{
+ d->m_name = other.d->m_name;
+ d->m_inPractice = other.d->m_inPractice;
+}
+
+KEduVocContainer::~KEduVocContainer()
+{
+ delete d;
+}
+
+void KEduVocContainer::appendChildContainer(KEduVocContainer * child)
+{
+ d->m_childContainers.append(child);
+}
+
+KEduVocContainer * KEduVocContainer::childContainer(int row)
+{
+ return d->m_childContainers.value(row);
+}
+
+int KEduVocContainer::childContainerCount() const
+{
+ return d->m_childContainers.count();
+}
+
+int KEduVocContainer::row() const
+{
+ if (d->m_parentContainer) {
+ return d->m_parentContainer->d->m_childContainers.indexOf(const_cast<KEduVocContainer*>(this));
+ }
+ return 0;
+}
+
+
+KEduVocContainer& KEduVocContainer::operator= ( const KEduVocContainer &other )
+{
+ d->m_name = other.d->m_name;
+ d->m_inPractice = other.d->m_inPractice;
+ return *this;
+}
+
+bool KEduVocContainer::operator==(const KEduVocContainer &other)
+{
+ return d->m_name == other.d->m_name &&
+ d->m_inPractice == other.d->m_inPractice;;
+}
+
+void KEduVocContainer::setName( const QString &name )
+{
+ d->m_name = name;
+}
+
+QString KEduVocContainer::name()
+{
+ return d->m_name;
+}
+
+bool KEduVocContainer::inPractice()
+{
+ return d->m_inPractice;
+}
+
+void KEduVocContainer::setInPractice(bool inPractice)
+{
+ d->m_inPractice = inPractice;
+}
+
+void KEduVocContainer::removeTranslation(int translation)
+{
+ foreach(KEduVocContainer *childContainer, d->m_childContainers) {
+ childContainer->removeTranslation(translation);
+ }
+
+ foreach(KEduVocExpression *entry, entries() ) {
+ entry->removeTranslation( translation );
+ }
+}
+
+QList< KEduVocExpression * > KEduVocContainer::entriesRecursive()
+{
+ QList< KEduVocExpression * > entryList = entries();
+ foreach(KEduVocContainer *childContainer, d->m_childContainers) {
+ foreach(KEduVocExpression *childEntry, childContainer->entriesRecursive()) {
+ if(!entryList.contains(childEntry)) {
+ entryList.append(childEntry);
+ }
+ }
+ }
+ return entryList;
+}
+
+QList< KEduVocContainer * > KEduVocContainer::childContainers()
+{
+ return d->m_childContainers;
+}
+
+KEduVocContainer * KEduVocContainer::parent()
+{
+ return d->m_parentContainer;
+}
+
+// KEduVocContainer * KEduVocContainer::childContainer(const QString & name)
+// {
+// for(int i = 0; i<d->m_childContainers.count(); i++){
+// if(d->m_childContainers.value(i)->name() == name) {
+// return d->m_childContainers[i];
+// }
+// }
+// return 0;
+// }
+
+void KEduVocContainer::setContainerType(KEduVocContainer::EnumContainerType type)
+{
+ d->m_type = type;
+}
+
+KEduVocContainer::EnumContainerType KEduVocContainer::containerType()
+{
+ return d->m_type;
+}
+
+
+KUrl KEduVocContainer::imageUrl()
+{
+ return d->m_imageUrl;
+}
+
+void KEduVocContainer::setImageUrl(const KUrl &url)
+{
+ d->m_imageUrl = url;
+}
+
+
--- /dev/null
+/***************************************************************************
+
+ Copyright 2007 Jeremy Whiting <jeremywhiting@scitools.com>
+ Copyright 2007 Frederik Gladhorn <frederik.gladhorn@kdemail.net>
+
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#ifndef KEDUVOCCONTAINER_H
+#define KEDUVOCCONTAINER_H
+
+#include "libkeduvocdocument_export.h"
+
+#include <KDE/KUrl>
+
+#include <QtCore/QList>
+#include <QtCore/QString>
+
+class KEduVocExpression;
+
+/** class to store information about a lesson */
+class KEDUVOCDOCUMENT_EXPORT KEduVocContainer
+{
+public:
+ enum EnumContainerType{
+ LessonContainer,
+ LeitnerContainer,
+ WordTypeContainer,
+ WordTypeNounContainer,
+ WordTypeNounMaleContainer,
+ WordTypeNounFemaleContainer,
+ WordTypeNounNeutralContainer,
+ WordTypeVerbContainer,
+ WordTypeAdjectiveContainer,
+ WordTypeAdverbContainer
+ };
+
+ /** default constructor */
+ explicit KEduVocContainer(const QString& name, EnumContainerType type = LessonContainer, KEduVocContainer *parent = 0);
+
+ void appendChildContainer(KEduVocContainer *child);
+
+ QList<KEduVocContainer *> childContainers();
+
+ KEduVocContainer *childContainer(int row);
+
+ /**
+ * Find a child container
+ * @param name
+ * @return
+ */
+// KEduVocContainer *childContainer(const QString& name);
+
+ int childContainerCount() const;
+
+ int row() const;
+ KEduVocContainer *parent();
+
+ /** copy constructor for d-pointer safe copying */
+ KEduVocContainer( const KEduVocContainer &other );
+
+ /** destructor */
+ ~KEduVocContainer();
+
+ /** assignment operator */
+ KEduVocContainer& operator= ( const KEduVocContainer& );
+
+ /** set the container name
+ * @param name text to set for the name
+ */
+ void setName( const QString &name );
+
+ /** get the container name */
+ QString name();
+
+ /** get a list of all entries in the container */
+ virtual QList < KEduVocExpression* > entries() =0;
+
+ /** get a list of all entries in the container and its child containers */
+ QList < KEduVocExpression* > entriesRecursive();
+
+ /**
+ * Removes a translation. This has to be called when a language is removed from a document.
+ * @param translation
+ */
+ void removeTranslation(int translation);
+
+ bool inPractice();
+ void setInPractice( bool inPractice );
+
+ /** equality operator */
+ bool operator==(const KEduVocContainer &other);
+
+ /**
+ * The type of this container. @see EnumContainerType
+ * @return
+ */
+ KEduVocContainer::EnumContainerType containerType();
+
+ /**
+ * Set the type of container.
+ * For convenience by default this is taken over from the parent, so no need to set.
+ * @param type the new type
+ */
+ void setContainerType(KEduVocContainer::EnumContainerType type);
+
+ /** get the image url for this container if it exists */
+ KUrl imageUrl();
+
+ /** set the image url for this container
+ * @param url url of the image
+ */
+ void setImageUrl(const KUrl &url);
+
+private:
+ class Private;
+ Private * const d;
+};
+
+#endif
int languageCount = 0;
KEduVocLesson* lesson = new KEduVocLesson( i18n("Vocabulary"), m_doc->lesson());
- m_doc->lesson()->appendChildLesson(lesson);
+ m_doc->lesson()->appendChildContainer(lesson);
while ( !inputStream.atEnd() ) {
QString s = inputStream.readLine();
*/
void addLesson( KEduVocLesson * l );
void removeLesson( KEduVocLesson * l );
+
friend class KEduVocLesson;
};
if (defaultLesson->entryCount() > 0)
{
- m_doc->lesson()->appendChildLesson(defaultLesson);
+ m_doc->lesson()->appendChildContainer(defaultLesson);
} else {
delete defaultLesson;
}
//<name>Lesson name</name>
QDomElement currentElement = lessonElement.firstChildElement( KVTML_NAME );
KEduVocLesson * lesson = new KEduVocLesson(currentElement.text(), parentLesson);
- parentLesson->appendChildLesson( lesson );
+ parentLesson->appendChildContainer( lesson );
readChildLessons( lesson, lessonElement );
typeElement.firstChildElement( KVTML_NAME ).text();
KEduVocLesson * wordTypeContainer = new KEduVocLesson(typeName, parentContainer);
- parentContainer->appendChildLesson(wordTypeContainer);
+ parentContainer->appendChildContainer(wordTypeContainer);
QString specialType = typeElement.firstChildElement( KVTML_SPECIALWORDTYPE ).text();
if ( !specialType.isEmpty() ) {
{
// iterate over child lessons.
// the first time this is called with the root lesson which does not have a <lesson> entry.
- for( int i = 0; i < parentLesson->childLessonCount(); i++ ) {
- KEduVocLesson *lesson = parentLesson->childLesson(i);
+ for( int i = 0; i < parentLesson->childContainerCount(); i++ ) {
+ KEduVocLesson *lesson = static_cast<KEduVocLesson*>(parentLesson->childContainer(i));
// make lesson element
QDomElement thisLessonElement = m_domDoc.createElement( KVTML_CONTAINER );
bool KEduVocKvtml2Writer::writeWordTypes( QDomElement &typesElement, KEduVocLesson* parentContainer )
{
- foreach( KEduVocLesson* wordType, parentContainer->childLessons() ) {
+ foreach( KEduVocContainer* container, parentContainer->childContainers() ) {
+ KEduVocLesson* wordType = static_cast<KEduVocLesson*>(container);
+
kDebug() << "Writing type: " << wordType->name();
QDomElement typeDefinitionElement = m_domDoc.createElement( KVTML_CONTAINER );
/***************************************************************************
- manage lessons
- -----------------------------------------------------------------------
- begin : August 11, 2007
+ Copyright 2007 Jeremy Whiting <jeremywhiting@scitools.com>
+ Copyright 2007 Frederik Gladhorn <frederik.gladhorn@kdemail.net>
- copyright : (C) 2007 Jeremy Whiting <jeremywhiting@scitools.com>
-
- -----------------------------------------------------------------------
***************************************************************************/
/***************************************************************************
public:
~Private();
- // properties for this lesson
- QString m_name;
- bool m_inPractice;
-
- // other lessons in the tree
- KEduVocLesson *m_parentLesson;
- QList<KEduVocLesson*> m_childLessons;
-
// entries
QList<KEduVocExpression*> m_entries;
-
- EnumContainerType m_type;
};
KEduVocLesson::Private::~ Private()
{
- qDeleteAll(m_childLessons);
-
///@todo delete children here???? is this a 1:1 mapping?
qDeleteAll(m_entries);
}
KEduVocLesson::KEduVocLesson(const QString& name, KEduVocLesson *parent)
- : d( new Private )
+ : d( new Private ), KEduVocContainer(name, LessonContainer, parent)
{
- d->m_parentLesson = parent;
- d->m_name = name;
- d->m_inPractice = false;
- if(parent) {
- d->m_type = parent->containerType();
- } else {
- d->m_type = LessonContainer;
- }
}
KEduVocLesson::KEduVocLesson( const KEduVocLesson &other )
- : d( new Private )
+ : d( new Private ), KEduVocContainer(other)
{
d->m_entries = other.d->m_entries;
- d->m_name = other.d->m_name;
- d->m_inPractice = other.d->m_inPractice;
}
KEduVocLesson::~KEduVocLesson()
delete d;
}
-void KEduVocLesson::appendChildLesson(KEduVocLesson * child)
-{
- d->m_childLessons.append(child);
-}
-
-KEduVocLesson * KEduVocLesson::childLesson(int row)
-{
- return d->m_childLessons.value(row);
-}
-
-int KEduVocLesson::childLessonCount() const
-{
- return d->m_childLessons.count();
-}
-
-int KEduVocLesson::row() const
-{
- if (d->m_parentLesson) {
- return d->m_parentLesson->d->m_childLessons.indexOf(const_cast<KEduVocLesson*>(this));
- }
- return 0;
-}
-
-
-KEduVocLesson& KEduVocLesson::operator= ( const KEduVocLesson &other )
-{
- d->m_entries = other.d->m_entries;
- d->m_name = other.d->m_name;
- d->m_inPractice = other.d->m_inPractice;
- return *this;
-}
-
-bool KEduVocLesson::operator==(const KEduVocLesson &other)
-{
- return d->m_entries == other.d->m_entries &&
- d->m_name == other.d->m_name &&
- d->m_inPractice == other.d->m_inPractice;;
-}
-
-void KEduVocLesson::setName( const QString &name )
-{
- d->m_name = name;
-}
-
-QString KEduVocLesson::name()
-{
- return d->m_name;
-}
QList<KEduVocExpression*> KEduVocLesson::entries()
{
void KEduVocLesson::addEntry(KEduVocExpression* entry)
{
d->m_entries.append( entry );
- if(d->m_type == LessonContainer) {
- entry->addLesson(this);
- }
+ entry->addLesson(this);
}
void KEduVocLesson::removeEntry(KEduVocExpression* entry)
entry->removeLesson(this);
}
-
-bool KEduVocLesson::inPractice()
-{
- return d->m_inPractice;
-}
-
-void KEduVocLesson::setInPractice(bool inPractice)
-{
- d->m_inPractice = inPractice;
-}
-
-void KEduVocLesson::removeTranslation(int translation)
-{
- foreach(KEduVocLesson *childLesson, d->m_childLessons) {
- childLesson->removeTranslation(translation);
- }
-
- foreach(KEduVocExpression *entry, d->m_entries ) {
- entry->removeTranslation( translation );
- }
-}
-
-QList< KEduVocExpression * > KEduVocLesson::entriesRecursive()
-{
- QList< KEduVocExpression * > entryList = entries();
- foreach(KEduVocLesson *childLesson, d->m_childLessons) {
- foreach(KEduVocExpression *childEntry, childLesson->entriesRecursive()) {
- if(!entryList.contains(childEntry)) {
- entryList.append(childEntry);
- }
- }
- }
- return entryList;
-}
-
-QList< KEduVocLesson * > KEduVocLesson::childLessons()
-{
- return d->m_childLessons;
-}
-
KEduVocExpression * KEduVocLesson::entry(int row)
{
return d->m_entries.value(row);
}
-KEduVocLesson * KEduVocLesson::parent()
-{
- return d->m_parentLesson;
-}
-
-KEduVocLesson * KEduVocLesson::childLesson(const QString & name)
-{
- for(int i = 0; i<d->m_childLessons.count(); i++){
- if(d->m_childLessons.value(i)->name() == name) {
- return d->m_childLessons[i];
- }
- }
-
- KEduVocLesson* newLesson = new KEduVocLesson(name, this);
- appendChildLesson(newLesson);
- return newLesson;
-}
-
-void KEduVocLesson::setContainerType(KEduVocLesson::EnumContainerType type)
-{
- d->m_type = type;
-}
-
-KEduVocLesson::EnumContainerType KEduVocLesson::containerType()
-{
- return d->m_type;
-}
-
/***************************************************************************
- manage lessons
- -----------------------------------------------------------------------
- begin : August 11, 2007
+ Copyright 2007 Jeremy Whiting <jeremywhiting@scitools.com>
+ Copyright 2007 Frederik Gladhorn <frederik.gladhorn@kdemail.net>
- copyright : (C) 2007 Jeremy Whiting <jeremywhiting@scitools.com>
-
- -----------------------------------------------------------------------
***************************************************************************/
/***************************************************************************
#include "libkeduvocdocument_export.h"
+#include "keduvoccontainer.h"
+
#include <QtCore/QList>
#include <QtCore/QString>
class KEduVocExpression;
/** class to store information about a lesson */
-class KEDUVOCDOCUMENT_EXPORT KEduVocLesson
+class KEDUVOCDOCUMENT_EXPORT KEduVocLesson :public KEduVocContainer
{
public:
- enum EnumContainerType{
- LessonContainer,
- LeitnerContainer,
- WordTypeContainer,
- WordTypeNounContainer,
- WordTypeNounMaleContainer,
- WordTypeNounFemaleContainer,
- WordTypeNounNeutralContainer,
- WordTypeVerbContainer,
- WordTypeAdjectiveContainer,
- WordTypeAdverbContainer
- };
-
/** default constructor */
explicit KEduVocLesson(const QString& name, KEduVocLesson *parent = 0);
- void appendChildLesson(KEduVocLesson *child);
+// void appendChildLesson(KEduVocLesson *child);
- QList<KEduVocLesson *> childLessons();
- KEduVocLesson *childLesson(int row);
- /**
- * Find a child lesson, creates a new lesson it if it does not exist!
- * @param name
- * @return
- */
- KEduVocLesson *childLesson(const QString& name);
- int childLessonCount() const;
+// QList<KEduVocLesson *> childLessons();
+// KEduVocLesson *childLesson(int row);
+
+// int childLessonCount() const;
- int row() const;
- KEduVocLesson *parent();
+// int row() const;
+// KEduVocLesson *parent();
/** copy constructor for d-pointer safe copying */
KEduVocLesson( const KEduVocLesson &other );
/** assignment operator */
KEduVocLesson& operator= ( const KEduVocLesson& );
- /** set the lesson name
- * @param name text to set for the name
- */
- void setName( const QString &name );
-
- /** get the lesson name */
- QString name();
KEduVocExpression* entry(int row);
/** get a list of all entries in the lesson */
QList < KEduVocExpression* > entries();
- /** get a list of all entries in the lesson and its child lessons */
- QList < KEduVocExpression* > entriesRecursive();
-
/** get the number of entries in the lesson */
int entryCount();
*/
void removeEntry(KEduVocExpression* entry);
-
- void removeTranslation(int translation);
-
- //void resetGrades()?
-
- bool inPractice();
- void setInPractice( bool inPractice );
-
- /** equality operator */
- bool operator==(const KEduVocLesson &other);
-
-
- /**
- * The type of this container. @see EnumContainerType
- * @return
- */
- KEduVocLesson::EnumContainerType containerType();
-
- /**
- * Set the type of container.
- * For convenience by default this is taken over from the parent, so no need to set.
- * @param type the new type
- */
- void setContainerType(KEduVocLesson::EnumContainerType type);
-
private:
class Private;
Private * const d;
}
KEduVocLesson* lesson = new KEduVocLesson(i18n("Vocabulary"), m_doc->lesson());
- m_doc->lesson()->appendChildLesson(lesson);
+ m_doc->lesson()->appendChildContainer(lesson);
KEduVocExpression* expr = new KEduVocExpression( QStringList() << front << back);
lesson->addEntry( expr );
QString lesson3 = QString::fromLatin1( "Lesson 3" );
KEduVocDocument doc;
- doc.lesson()->appendChildLesson(new KEduVocLesson(lesson1, doc.lesson()));
- QCOMPARE(doc.lesson()->childLessonCount(), 1);
+ doc.lesson()->appendChildContainer(new KEduVocLesson(lesson1, doc.lesson()));
+ QCOMPARE(doc.lesson()->childContainerCount(), 1);
/*
QCOMPARE(doc.lesson(indexLesson1).name(), lesson1);