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

parley

  • sources
  • kde-4.14
  • 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  KEduVocWordType * wt = static_cast<KEduVocWordType*>(child);
55  if (name == wt->name())
56  return wt;
57  }
58  return 0;
59 }
60 
61 void Document::setWordType(QObject * translation, const QString & wordtype)
62 {
63  Translation * tr = dynamic_cast<Translation*>(translation);
64  if (!tr) {
65  kDebug() << "Invalid lesson entry";
66  return;
67  }
68  KEduVocWordType * wt = wordTypeFromString(wordtype);
69  if (wt)
70  tr->setWordType(wt);
71  else
72  kDebug() << "Invalid given wordtype: " << wordtype;
73 }
74 
75 QStringList Document::wordTypes()
76 {
77  QList<KEduVocContainer*> list = Container::flattenContainer(m_doc->wordTypeContainer());
78  list.removeFirst();
79  QStringList strList;
80  foreach(KEduVocContainer * child, list) {
81  strList << child->name();
82  }
83  return strList;
84 }
85 
86 QVariantList Document::identifiers()
87 {
88  QVariantList list;
89  for (int i = 0; i < m_doc->identifierCount(); i++) {
90  QObject * obj = new Identifier(m_doc->identifier(i));
91  list << qVariantFromValue(obj);
92  }
93  return list;
94 }
95 
96 void Document::appendNewIdentifier(const QString& name, const QString& locale)
97 {
98  KEduVocIdentifier ident;
99  ident.setName(name);
100  ident.setLocale(locale);
101  m_doc->appendIdentifier(ident);
102 }
103 
104 void Document::appendLesson(QObject * lesson)
105 {
106  Lesson * l = dynamic_cast<Lesson*>(lesson);
107  if (l)
108  m_doc->lesson()->appendChildContainer(l->kEduVocContainer());
109 }
110 
111 QObject * Document::appendNewLesson(const QString & name)
112 {
113  KEduVocLesson * lesson = new KEduVocLesson(name, m_doc->lesson());
114  m_doc->lesson()->appendChildContainer(lesson);
115  return new Lesson(lesson);
116 }
117 
118 QObject * Document::appendNewLesson(const QString & name, Lesson * parent)
119 {
120  KEduVocLesson * lesson = new KEduVocLesson(name, parent->kEduVocContainer());
121  parent->kEduVocContainer()->appendChildContainer(lesson);
122  return new Lesson(lesson);
123 }
124 
125 QObject * Document::findLesson(const QString& name)
126 {
127  Lesson tmpLesson(m_doc->lesson());
128  return tmpLesson.findChildLesson(name);
129 }
130 
131 }
QObject::child
QObject * child(const char *objName, const char *inheritsClass, bool recursiveSearch) const
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:142
Scripting::Lesson::childLessons
QVariantList childLessons(bool recursive=false)
Returns a list of all the child lessons.
Definition: lesson.cpp:57
Scripting::Translation::setWordType
void setWordType(KEduVocWordType *wordType)
Definition: translation.h:157
QList::removeFirst
void removeFirst()
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::tr
QString tr(const char *sourceText, const char *disambiguation, int n)
Scripting::Document::appendLesson
void appendLesson(QObject *lesson)
Appends a lesson to the document.
Definition: document.cpp:104
QObject
Scripting::Document::~Document
~Document()
Definition: document.cpp:35
document.h
QString
QList< KEduVocContainer * >
translation.h
QStringList
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:125
Scripting::Document::appendNewLesson
QObject * appendNewLesson(const QString &name)
Creates a new lesson and appends it to the root lesson.
Definition: document.cpp:111
Scripting::Document::wordTypes
QStringList wordTypes()
Returns a string list with all the available word type's names.
Definition: document.cpp:75
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:61
Scripting::Document::appendNewIdentifier
void appendNewIdentifier(const QString &name, const QString &locale)
Append a new identifier by giving the name and locale.
Definition: document.cpp:96
Scripting::Document::identifiers
QVariantList identifiers()
Returns a list of all the identifiers of this document.
Definition: document.cpp:86
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-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:15:56 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
  • 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