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

parley

  • sources
  • kde-4.12
  • kdeedu
  • parley
  • src
  • scripts
  • scripting
document.cpp
Go to the documentation of this file.
1 /***************************************************************************
2 
3  Copyright 2008 Avgoustinos Kadis <avgoustinos.kadis@kdemail.net>
4 
5  ***************************************************************************/
6 
7 /***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 #include "document.h"
16 #include <keduvocwordtype.h>
17 
18 #include "translation.h"
19 
20 #include <KDebug>
21 
22 namespace Scripting
23 {
24 
25  Document::Document ( QObject* parent )
26  {
27  m_doc = new KEduVocDocument ( parent );
28  }
29 
30  Document::Document ( KEduVocDocument * doc )
31  : QObject(), m_doc ( doc )
32  {
33  }
34 
35  Document::~Document()
36  {
37  }
38 
39  QVariantList Document::allLessons()
40  {
41  Lesson * l = new Lesson ( m_doc->lesson() );
42  return QVariantList() << qVariantFromValue ( static_cast<QObject*> ( l ) ) << l->childLessons ( true );
43  }
44 
45  KEduVocWordType * Document::wordTypeFromString ( const QString & name )
46  {
47  QList<KEduVocContainer*> list = Container::flattenContainer ( m_doc->wordTypeContainer() );
48  list.removeFirst();
49 
50 // foreach ( KEduVocContainer * child, list )
51 // kDebug() << static_cast<KEduVocWordType*>(child)->name();
52 
53  foreach ( KEduVocContainer * child, list )
54  {
55  KEduVocWordType * wt = static_cast<KEduVocWordType*> ( child );
56  if ( name == wt->name() )
57  return wt;
58  }
59  return 0;
60  }
61 
62  void Document::setWordType ( QObject * translation, const QString & wordtype )
63  {
64  Translation * tr = dynamic_cast<Translation*> ( translation );
65  if ( !tr )
66  {
67  kDebug() << "Invalid lesson entry";
68  return;
69  }
70  KEduVocWordType * wt = wordTypeFromString ( wordtype );
71  if ( wt )
72  tr->setWordType ( wt );
73  else
74  kDebug() << "Invalid given wordtype: " << wordtype;
75  }
76 
77  QStringList Document::wordTypes()
78  {
79  QList<KEduVocContainer*> list = Container::flattenContainer ( m_doc->wordTypeContainer() );
80  list.removeFirst();
81  QStringList strList;
82  foreach ( KEduVocContainer * child, list )
83  {
84  strList << child->name();
85  }
86  return strList;
87  }
88 
89  QVariantList Document::identifiers()
90  {
91  QVariantList list;
92  for ( int i = 0; i < m_doc->identifierCount(); i++ )
93  {
94  QObject * obj = new Identifier ( m_doc->identifier ( i ) );
95  list << qVariantFromValue ( obj );
96  }
97  return list;
98  }
99 
100  void Document::appendNewIdentifier ( const QString& name, const QString& locale )
101  {
102  KEduVocIdentifier ident;
103  ident.setName ( name );
104  ident.setLocale ( locale );
105  m_doc->appendIdentifier ( ident );
106  }
107 
108  void Document::appendLesson( QObject * lesson ) {
109  Lesson * l = dynamic_cast<Lesson*>(lesson);
110  if (l)
111  m_doc->lesson()->appendChildContainer(l->kEduVocContainer());
112  }
113 
114  QObject * Document::appendNewLesson ( const QString & name )
115  {
116  KEduVocLesson * lesson = new KEduVocLesson(name,m_doc->lesson());
117  m_doc->lesson()->appendChildContainer(lesson);
118  return new Lesson(lesson);
119  }
120 
121  QObject * Document::appendNewLesson ( const QString & name, Lesson * parent )
122  {
123  KEduVocLesson * lesson = new KEduVocLesson(name,parent->kEduVocContainer());
124  parent->kEduVocContainer()->appendChildContainer(lesson);
125  return new Lesson(lesson);
126  }
127 
128  QObject * Document::findLesson(const QString& name) {
129  Lesson tmpLesson(m_doc->lesson());
130  return tmpLesson.findChildLesson(name);
131  }
132 
133 }
Scripting::Lesson::findChildLesson
QObject * findChildLesson(const QString &name)
Searches through all the child lessons (recursively) and returns the first lesson the specified name...
Definition: lesson.cpp:147
Scripting::Lesson::childLessons
QVariantList childLessons(bool recursive=false)
Returns a list of all the child lessons.
Definition: lesson.cpp:58
Scripting::Translation::setWordType
void setWordType(KEduVocWordType *wordType)
Definition: translation.h:139
Scripting::Lesson
KEduVocLesson wrapping class for Kross scripts.
Definition: lesson.h:47
Scripting::Translation
KEduVocTranslation wrapper class for scripting with Kross.
Definition: translation.h:36
QObject
Scripting::Document::appendLesson
void appendLesson(QObject *lesson)
Appends a lesson to the document.
Definition: document.cpp:108
Scripting::Document::~Document
~Document()
Definition: document.cpp:35
document.h
translation.h
Scripting::Document::Document
Document(QObject *parent=0)
Definition: document.cpp:25
Scripting::Document::findLesson
QObject * findLesson(const QString &name)
Searches through all the lessons (recursively) and returns the first lesson the specified name...
Definition: document.cpp:128
Scripting::Document::appendNewLesson
QObject * appendNewLesson(const QString &name)
Creates a new lesson and appends it to the root lesson.
Definition: document.cpp:114
Scripting::Document::wordTypes
QStringList wordTypes()
Returns a string list with all the available word type's names.
Definition: document.cpp:77
Scripting::Identifier
Identifier class can be accessed from Document class and is used for specifying the document language...
Definition: identifier.h:54
Scripting::Container::flattenContainer
static QList< KEduVocContainer * > flattenContainer(KEduVocContainer *root)
Definition: container.cpp:62
Scripting::Document::setWordType
void setWordType(QObject *tr, const QString &wordtype)
Sets the word type (wordtype) of the given tr translation object.
Definition: document.cpp:62
Scripting::Document::appendNewIdentifier
void appendNewIdentifier(const QString &name, const QString &locale)
Append a new identifier by giving the name and locale.
Definition: document.cpp:100
Scripting::Document::identifiers
QVariantList identifiers()
Returns a list of all the identifiers of this document.
Definition: document.cpp:89
Scripting::Document::wordTypeFromString
KEduVocWordType * wordTypeFromString(const QString &name)
Definition: document.cpp:45
Scripting::Document::allLessons
QVariantList allLessons()
Returns all the lessons in the document (including sublessons)
Definition: document.cpp:39
Scripting::Container::kEduVocContainer
KEduVocContainer * kEduVocContainer()
Definition: container.h:69
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:42:05 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

parley

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

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal