• 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
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  {
51  lessonsList << static_cast<KEduVocLesson*> ( child );
52  lessonsList += flattenLessons ( static_cast<KEduVocLesson*> ( child ) );
53  }
54  return lessonsList;
55  }
56 
57 
58  QVariantList Lesson::childLessons ( bool recursive )
59  {
60  if ( recursive )
61  return toVariantList<KEduVocLesson,Lesson> ( flattenLessons ( m_lesson ) );
62  return toVariantList<KEduVocContainer,Lesson> ( m_lesson->childContainers() );
63  }
64 
65  QVariantList Lesson::entries ( bool recursive ) const
66  {
67  return toVariantList<KEduVocExpression,Expression> ( m_lesson->entries ( boolToEnum ( recursive ) ) );
68  }
69 
70  void Lesson::setEntries ( QVariantList entries )
71  {
72  clearEntries();
73 
74  foreach ( const QVariant &ventry, entries )
75  {
76  QObject * obj = qvariant_cast<QObject*> ( ventry );
77  Expression * entry = dynamic_cast<Expression*> ( obj );
78  if ( entry )
79  m_lesson->appendEntry ( entry->kEduVocExpression() );
80 // kDebug() << entry->translationTexts();
81  }
82  }
83 
84  QObject * Lesson::entry ( int row, bool recursive )
85  {
86  return new Expression ( m_lesson->entry ( row, boolToEnum ( recursive ) ) );
87  }
88 
89  int Lesson::entryCount ( bool recursive )
90  {
91  return m_lesson->entryCount ( boolToEnum ( recursive ) );
92  }
93 
94  void Lesson::appendEntry ( Expression * entry )
95  {
96  m_lesson->appendEntry ( entry->kEduVocExpression() );
97  }
98 
99  void Lesson::insertEntry ( int index, Expression * entry )
100  {
101  m_lesson->insertEntry ( index,entry->kEduVocExpression() );
102  }
103 
104  void Lesson::removeEntry ( QObject * entry )
105  {
107  Expression * e = dynamic_cast<Expression*> ( entry );
108  if ( e )
109  {
110  m_lesson->removeEntry ( e->kEduVocExpression() );
111  }
112  else
113  {
114  kDebug() << "The entry given does not exist";
115  }
116  }
117 
118  void Lesson::clearEntries()
119  {
120  int N = m_lesson->entryCount ( KEduVocLesson::NotRecursive );
121  for ( int i = 0; i < N; i++ )
122  m_lesson->removeEntry( m_lesson->entry ( 0,KEduVocLesson::NotRecursive ) );
123  }
124 
125 
126  QObject* Lesson::newEntry()
127  {
128  return new Expression();
129  }
130 
131 // QObject* Lesson::newEntry ( const QString & expression )
132 // {
133 // return new Expression ( expression );
134 // }
135 
136  QObject* Lesson::newEntry ( QStringList translations )
137  {
138  return new Expression ( translations );
139  }
140 
141  void Lesson::appendNewEntry ( QStringList translations )
142  {
143  KEduVocExpression * expr = new KEduVocExpression ( translations );
144  m_lesson->appendEntry ( expr );
145  }
146 
147  QObject * Lesson::findChildLesson ( const QString& name )
148  {
149  KEduVocContainer * container = findContainer ( name );
150  if ( container )
151  return new Lesson ( container );
152  kDebug() << "not found";
153  return 0;
154  }
155 
156 }
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::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:58
Scripting::Container
KEduVocContainer wrapping class for Kross scripts (inherited by Lesson)
Definition: container.h:33
QObject
Scripting::Lesson::removeEntry
void removeEntry(QObject *entry)
Removes an entry from this lesson.
Definition: lesson.cpp:104
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:94
Scripting::Lesson::entries
QVariantList entries(bool recursive=false) const
Returns a list of all the entries of a lesson.
Definition: lesson.cpp:65
Scripting::Lesson::entry
QObject * entry(int row, bool recursive=false)
Returns the entry of the given row.
Definition: lesson.cpp:84
expression.h
Scripting::Container::findContainer
KEduVocContainer * findContainer(const QString &name)
Definition: container.cpp:74
Scripting::Lesson::newEntry
QObject * newEntry()
Creates and returns a new Expression Object.
Definition: lesson.cpp:126
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:89
Scripting::Container::m_container
KEduVocContainer * m_container
Definition: container.h:168
Scripting::Lesson::insertEntry
void insertEntry(int index, Expression *entry)
Insert an entry on a specific index.
Definition: lesson.cpp:99
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:141
lesson.h
Scripting::Lesson::setEntries
void setEntries(QVariantList entries)
Definition: lesson.cpp:70
Scripting::Lesson::clearEntries
void clearEntries()
Removes all the lesson entries (not recursively)
Definition: lesson.cpp:118
Scripting::Expression::kEduVocExpression
KEduVocExpression * kEduVocExpression() const
Definition: expression.h:70
Scripting::Expression
This class represents.
Definition: expression.h:35
Scripting::flattenLessons
QList< KEduVocLesson * > flattenLessons(KEduVocLesson *rootLesson)
Definition: lesson.cpp:46
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:42:06 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