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

parley

document.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 "document.h"
00016 #include <keduvocwordtype.h>
00017 
00018 #include "translation.h"
00019 
00020 #include <KDebug>
00021 
00022 namespace Scripting
00023 {
00024 
00025     Document::Document ( QObject* parent )
00026     {
00027         m_doc = new KEduVocDocument ( parent );
00028     }
00029 
00030     Document::Document ( KEduVocDocument * doc )
00031             : QObject(), m_doc ( doc )
00032     {
00033     }
00034 
00035     Document::~Document()
00036     {
00037     }
00038 
00039     QVariantList Document::allLessons()
00040     {
00041         Lesson * l = new Lesson ( m_doc->lesson() );
00042         return QVariantList() << qVariantFromValue ( static_cast<QObject*> ( l ) ) <<  l->childLessons ( true );
00043     }
00044 
00045     KEduVocWordType * Document::wordTypeFromString ( const QString & name )
00046     {
00047         QList<KEduVocContainer*> list = Container::flattenContainer ( m_doc->wordTypeContainer() );
00048         list.removeFirst();
00049 
00050 //         foreach ( KEduVocContainer * child, list )
00051 //             kDebug() << static_cast<KEduVocWordType*>(child)->name();
00052 
00053         foreach ( KEduVocContainer * child, list )
00054         {
00055             KEduVocWordType * wt = static_cast<KEduVocWordType*> ( child );
00056             if ( name == wt->name() )
00057                 return wt;
00058         }
00059         return 0;
00060     }
00061 
00062     void Document::setWordType ( QObject * translation, const QString & wordtype )
00063     {
00064         Translation * tr = dynamic_cast<Translation*> ( translation );
00065         if ( !tr )
00066         {
00067             kDebug() << "Invalid lesson entry";
00068             return;
00069         }
00070         KEduVocWordType * wt = wordTypeFromString ( wordtype );
00071         if ( wt )
00072             tr->setWordType ( wt );
00073         else
00074             kDebug() << "Invalid given wordtype: " << wordtype;
00075     }
00076 
00077     QStringList Document::wordTypes()
00078     {
00079         QList<KEduVocContainer*> list = Container::flattenContainer ( m_doc->wordTypeContainer() );
00080         list.removeFirst();
00081         QStringList strList;
00082         foreach ( KEduVocContainer * child, list )
00083         {
00084             strList << child->name();
00085         }
00086         return strList;
00087     }
00088 
00089     QVariantList Document::identifiers()
00090     {
00091         QVariantList list;
00092         for ( int i = 0; i < m_doc->identifierCount(); i++ )
00093         {
00094             QObject * obj = new Identifier ( m_doc->identifier ( i ) );
00095             list << qVariantFromValue ( obj );
00096         }
00097         return list;
00098     }
00099 
00100     void Document::appendNewIdentifier ( const QString& name, const QString& locale )
00101     {
00102         KEduVocIdentifier ident;
00103         ident.setName ( name );
00104         ident.setLocale ( locale );
00105         m_doc->appendIdentifier ( ident );
00106     }
00107 
00108     void Document::appendLesson( QObject * lesson ) { 
00109         Lesson * l = dynamic_cast<Lesson*>(lesson);
00110         if (l)
00111             m_doc->lesson()->appendChildContainer(l->kEduVocContainer());
00112     }
00113 
00114     QObject * Document::appendNewLesson ( const QString & name )
00115     {
00116         KEduVocLesson * lesson = new KEduVocLesson(name,m_doc->lesson());
00117         m_doc->lesson()->appendChildContainer(lesson);
00118         return new Lesson(lesson);
00119     }
00120 
00121     QObject * Document::appendNewLesson ( const QString & name, Lesson * parent )
00122     {
00123         KEduVocLesson * lesson = new KEduVocLesson(name,parent->kEduVocContainer());
00124         parent->kEduVocContainer()->appendChildContainer(lesson);
00125         return new Lesson(lesson);
00126     }
00127 
00128     QObject * Document::findLesson(const QString& name) {
00129         Lesson tmpLesson(m_doc->lesson());
00130         return tmpLesson.findChildLesson(name);
00131     }
00132 
00133 }

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