• Skip to content
  • Skip to link menu
KDE 4.4 API Reference
  • KDE API Reference
  • kdeedu
  • Sitemap
  • Contact Us
 

parley

lesson.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002 
00003     Copyright 2008 Avgoustinos Kadis <avgoustinos.kadis@kdemail.net>
00004 
00005  ***************************************************************************/
00006 
00007 /***************************************************************************
00008  *                                                                         *
00009  *   This program is free software; you can redistribute it and/or modify  *
00010  *   it under the terms of the GNU General Public License as published by  *
00011  *   the Free Software Foundation; either version 2 of the License, or     *
00012  *   (at your option) any later version.                                   *
00013  *                                                                         *
00014  ***************************************************************************/
00015 #include "lesson.h"
00016 #include "expression.h"
00017 
00018 #include <keduvocexpression.h>
00019 
00020 #include <KDebug>
00021 
00022 namespace Scripting
00023 {
00024     Lesson::Lesson ( KEduVocLesson * lesson )
00025             : Container ( lesson ), m_lesson ( lesson )
00026     {
00027     }
00028 
00029     Lesson::Lesson ( KEduVocContainer * container )
00030     {
00031         m_lesson = static_cast<KEduVocLesson*> ( container );
00032         m_container = m_lesson;
00033     }
00034 
00035     Lesson::Lesson ( const QString& name )
00036     {
00037         m_lesson = new KEduVocLesson ( name );
00038         m_container = m_lesson;
00039     }
00040 
00041 
00042     Lesson::~Lesson()
00043     {
00044     }
00045 
00046     QList<KEduVocLesson*>  flattenLessons ( KEduVocLesson * rootLesson )
00047     {
00048         QList<KEduVocLesson*> lessonsList;
00049         foreach ( KEduVocContainer * child, rootLesson->childContainers() )
00050         {
00051             lessonsList << static_cast<KEduVocLesson*> ( child );
00052             lessonsList += flattenLessons ( static_cast<KEduVocLesson*> ( child ) );
00053         }
00054         return lessonsList;
00055     }
00056 
00057 
00058     QVariantList Lesson::childLessons ( bool recursive )
00059     {
00060         if ( recursive )
00061             return toVariantList<KEduVocLesson,Lesson> ( flattenLessons ( m_lesson ) );
00062         return toVariantList<KEduVocContainer,Lesson> ( m_lesson->childContainers() );
00063     }
00064 
00065     QVariantList Lesson::entries ( bool recursive ) const
00066     {
00067         return toVariantList<KEduVocExpression,Expression> ( m_lesson->entries ( boolToEnum ( recursive ) ) );
00068     }
00069 
00070     void Lesson::setEntries ( QVariantList entries )
00071     {
00072         clearEntries();
00073 
00074         foreach ( const QVariant &ventry, entries )
00075         {
00076             QObject * obj = qvariant_cast<QObject*> ( ventry );
00077             Expression * entry = dynamic_cast<Expression*> ( obj );
00078             if ( entry )
00079                 m_lesson->appendEntry ( entry->kEduVocExpression() );
00080 //                 kDebug() << entry->translationTexts();
00081         }
00082     }
00083 
00084     QObject * Lesson::entry ( int row, bool recursive )
00085     {
00086         return new Expression ( m_lesson->entry ( row, boolToEnum ( recursive ) ) );
00087     }
00088 
00089     int Lesson::entryCount ( bool recursive )
00090     {
00091         return m_lesson->entryCount ( boolToEnum ( recursive ) );
00092     }
00093 
00094     void Lesson::appendEntry ( Expression * entry )
00095     {
00096         m_lesson->appendEntry ( entry->kEduVocExpression() );
00097     }
00098 
00099     void Lesson::insertEntry ( int index, Expression * entry )
00100     {
00101         m_lesson->insertEntry ( index,entry->kEduVocExpression() );
00102     }
00103 
00104     void Lesson::removeEntry ( QObject * entry )
00105     {
00107         Expression * e = dynamic_cast<Expression*> ( entry );
00108         if ( e )
00109         {
00110             m_lesson->removeEntry ( e->kEduVocExpression() );
00111         }
00112         else
00113         {
00114             kDebug() << "The entry given does not exist";
00115         }
00116     }
00117 
00118     void Lesson::clearEntries()
00119     {
00120         int N = m_lesson->entryCount ( KEduVocLesson::NotRecursive );
00121         for ( int i = 0; i < N; i++ )
00122             m_lesson->removeEntry( m_lesson->entry ( 0,KEduVocLesson::NotRecursive ) );
00123     }
00124 
00125 
00126     QObject* Lesson::newEntry()
00127     {
00128         return new Expression();
00129     }
00130 
00131 //     QObject* Lesson::newEntry ( const QString & expression )
00132 //     {
00133 //         return new Expression ( expression );
00134 //     }
00135 
00136     QObject* Lesson::newEntry ( QStringList translations )
00137     {
00138         return new Expression ( translations );
00139     }
00140 
00141     void Lesson::appendNewEntry ( QStringList translations )
00142     {
00143         KEduVocExpression * expr = new KEduVocExpression ( translations );
00144         m_lesson->appendEntry ( expr );
00145     }
00146 
00147     QObject * Lesson::findChildLesson ( const QString& name )
00148     {
00149         KEduVocContainer * container = findContainer ( name );
00150         if ( container )
00151             return new Lesson ( container );
00152         kDebug() << "not found";
00153         return 0;
00154     }
00155 
00156 }

parley

Skip menu "parley"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdeedu

Skip menu "kdeedu"
  •     lib
  • kalzium
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  • marble
  • parley
  •   stepcore
Generated for kdeedu by doxygen 1.5.9-20090814
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal