• 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
lesson.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 "lesson.h"
16 #include "expression.h"
17 
18 #include <keduvocexpression.h>
19 
20 #include <KDebug>
21 
22 namespace Scripting
23 {
24 Lesson::Lesson(KEduVocLesson * lesson)
25  : Container(lesson), m_lesson(lesson)
26 {
27 }
28 
29 Lesson::Lesson(KEduVocContainer * container)
30 {
31  m_lesson = static_cast<KEduVocLesson*>(container);
32  m_container = m_lesson;
33 }
34 
35 Lesson::Lesson(const QString& name)
36 {
37  m_lesson = new KEduVocLesson(name);
38  m_container = m_lesson;
39 }
40 
41 
42 Lesson::~Lesson()
43 {
44 }
45 
46 QList<KEduVocLesson*> flattenLessons(KEduVocLesson * rootLesson)
47 {
48  QList<KEduVocLesson*> lessonsList;
49  foreach(KEduVocContainer * child, rootLesson->childContainers()) {
50  lessonsList << static_cast<KEduVocLesson*>(child);
51  lessonsList += flattenLessons(static_cast<KEduVocLesson*>(child));
52  }
53  return lessonsList;
54 }
55 
56 
57 QVariantList Lesson::childLessons(bool recursive)
58 {
59  if (recursive)
60  return toVariantList<KEduVocLesson, Lesson> (flattenLessons(m_lesson));
61  return toVariantList<KEduVocContainer, Lesson> (m_lesson->childContainers());
62 }
63 
64 QVariantList Lesson::entries(bool recursive) const
65 {
66  return toVariantList<KEduVocExpression, Expression> (m_lesson->entries(boolToEnum(recursive)));
67 }
68 
69 void Lesson::setEntries(QVariantList entries)
70 {
71  clearEntries();
72 
73  foreach(const QVariant & ventry, entries) {
74  QObject * obj = qvariant_cast<QObject*> (ventry);
75  Expression * entry = dynamic_cast<Expression*>(obj);
76  if (entry)
77  m_lesson->appendEntry(entry->kEduVocExpression());
78 // kDebug() << entry->translationTexts();
79  }
80 }
81 
82 QObject * Lesson::entry(int row, bool recursive)
83 {
84  return new Expression(m_lesson->entry(row, boolToEnum(recursive)));
85 }
86 
87 int Lesson::entryCount(bool recursive)
88 {
89  return m_lesson->entryCount(boolToEnum(recursive));
90 }
91 
92 void Lesson::appendEntry(Expression * entry)
93 {
94  m_lesson->appendEntry(entry->kEduVocExpression());
95 }
96 
97 void Lesson::insertEntry(int index, Expression * entry)
98 {
99  m_lesson->insertEntry(index, entry->kEduVocExpression());
100 }
101 
102 void Lesson::removeEntry(QObject * entry)
103 {
105  Expression * e = dynamic_cast<Expression*>(entry);
106  if (e) {
107  m_lesson->removeEntry(e->kEduVocExpression());
108  } else {
109  kDebug() << "The entry given does not exist";
110  }
111 }
112 
113 void Lesson::clearEntries()
114 {
115  int N = m_lesson->entryCount(KEduVocLesson::NotRecursive);
116  for (int i = 0; i < N; i++)
117  m_lesson->removeEntry(m_lesson->entry(0, KEduVocLesson::NotRecursive));
118 }
119 
120 
121 QObject* Lesson::newEntry()
122 {
123  return new Expression();
124 }
125 
126 // QObject* Lesson::newEntry ( const QString & expression )
127 // {
128 // return new Expression ( expression );
129 // }
130 
131 QObject* Lesson::newEntry(QStringList translations)
132 {
133  return new Expression(translations);
134 }
135 
136 void Lesson::appendNewEntry(QStringList translations)
137 {
138  KEduVocExpression * expr = new KEduVocExpression(translations);
139  m_lesson->appendEntry(expr);
140 }
141 
142 QObject * Lesson::findChildLesson(const QString& name)
143 {
144  KEduVocContainer * container = findContainer(name);
145  if (container)
146  return new Lesson(container);
147  kDebug() << "not found";
148  return 0;
149 }
150 
151 }
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::Container::boolToEnum
static KEduVocContainer::EnumEntriesRecursive boolToEnum(bool recursive)
Definition: container.cpp:50
Scripting::Lesson::childLessons
QVariantList childLessons(bool recursive=false)
Returns a list of all the child lessons.
Definition: lesson.cpp:57
N
static const int N
Definition: dashboard.h:23
Scripting::Container
KEduVocContainer wrapping class for Kross scripts (inherited by Lesson)
Definition: container.h:33
Scripting::Lesson::removeEntry
void removeEntry(QObject *entry)
Removes an entry from this lesson.
Definition: lesson.cpp:102
Scripting::Lesson::Lesson
Lesson(KEduVocLesson *lesson)
Definition: lesson.cpp:24
Scripting::Lesson::appendEntry
void appendEntry(Expression *entry)
Appends an entry at the end of the lesson.
Definition: lesson.cpp:92
Scripting::Lesson::entries
QVariantList entries(bool recursive=false) const
Returns a list of all the entries of a lesson.
Definition: lesson.cpp:64
Scripting::Lesson::entry
QObject * entry(int row, bool recursive=false)
Returns the entry of the given row.
Definition: lesson.cpp:82
QObject
expression.h
Scripting::Container::findContainer
KEduVocContainer * findContainer(const QString &name)
Definition: container.cpp:73
Scripting::Lesson::newEntry
QObject * newEntry()
Creates and returns a new Expression Object.
Definition: lesson.cpp:121
QString
QList
QStringList
Scripting::Lesson::entryCount
int entryCount(bool recursive=false)
Returns how many entries are in this lesson (or with sublessons if recursive is true) ...
Definition: lesson.cpp:87
Scripting::Container::m_container
KEduVocContainer * m_container
Definition: container.h:204
Scripting::Lesson::insertEntry
void insertEntry(int index, Expression *entry)
Insert an entry on a specific index.
Definition: lesson.cpp:97
Scripting::Lesson::~Lesson
~Lesson()
Definition: lesson.cpp:42
Scripting::Lesson::appendNewEntry
void appendNewEntry(QStringList translations)
Creates and appends a new entry with the given translations.
Definition: lesson.cpp:136
lesson.h
Scripting::Lesson::setEntries
void setEntries(QVariantList entries)
Definition: lesson.cpp:69
Scripting::Lesson::clearEntries
void clearEntries()
Removes all the lesson entries (not recursively)
Definition: lesson.cpp:113
Scripting::Expression::kEduVocExpression
KEduVocExpression * kEduVocExpression() const
Definition: expression.h:70
Scripting::Expression
This class represents.
Definition: expression.h:35
QVariant
Scripting::flattenLessons
QList< KEduVocLesson * > flattenLessons(KEduVocLesson *rootLesson)
Definition: lesson.cpp:46
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