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

libkdeedu/keduvocdocument

  • sources
  • kde-4.12
  • kdeedu
  • libkdeedu
  • keduvocdocument
keduvocleitnerbox.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  Copyright 2008 Frederik Gladhorn <frederik.gladhorn@kdemail.net>
3  ***************************************************************************/
4 
5 /***************************************************************************
6  * *
7  * This program is free software; you can redistribute it and/or modify *
8  * it under the terms of the GNU General Public License as published by *
9  * the Free Software Foundation; either version 2 of the License, or *
10  * (at your option) any later version. *
11  * *
12  ***************************************************************************/
13 
14 #include "keduvocleitnerbox.h"
15 
16 #include "keduvocexpression.h"
17 
18 #include <QtCore/QSet>
19 
20 class KEduVocLeitnerBox::Private
21 {
22 public:
23  // cache the entries
24  QList<KEduVocExpression*> m_expressions;
25  // list of translations
26  QList<KEduVocTranslation*> m_translations;
27 };
28 
29 KEduVocLeitnerBox::KEduVocLeitnerBox(const QString& name, KEduVocLeitnerBox *parent)
30  : KEduVocContainer(name, Leitner, parent), d( new Private )
31 {
32  // only one top level and children, this is only a list
33  Q_ASSERT(!parent || !parent->parent());
34 }
35 
36 KEduVocLeitnerBox::~KEduVocLeitnerBox()
37 {
38  foreach(KEduVocTranslation* translation, d->m_translations) {
39  translation->setLeitnerBox(0);
40  }
41  delete d;
42 }
43 
44 QList<KEduVocExpression*> KEduVocLeitnerBox::entries(EnumEntriesRecursive recursive)
45 {
46  Q_UNUSED(recursive)
47  return d->m_expressions;
48 }
49 
50 int KEduVocLeitnerBox::entryCount(EnumEntriesRecursive recursive)
51 {
52  Q_UNUSED(recursive)
53  return d->m_expressions.count();
54 }
55 
56 void KEduVocLeitnerBox::addTranslation(KEduVocTranslation* translation)
57 {
58  // add to expression - if not already there because another translation of the same word is there.
59  bool found = false;
60  foreach(int i, translation->entry()->translationIndices()) {
61  if (translation->entry()->translation(i)->leitnerBox() == this) {
62  found = true;
63  break;
64  }
65  }
66  if (!found) {
67  d->m_expressions.append(translation->entry());
68  }
69  d->m_translations.append( translation );
70  invalidateChildLessonEntries();
71 }
72 
73 void KEduVocLeitnerBox::removeTranslation(KEduVocTranslation* translation)
74 {
75  int index = d->m_translations.indexOf(translation);
76  d->m_translations.removeAt(index);
77 
78  // no lesson found - this entry is being deleted. remove all its siblings.
79  if (!translation->entry()->lesson()) {
80  int index = d->m_expressions.indexOf(translation->entry());
81  if (index != -1) {
82  d->m_expressions.removeAt(index);
83  }
84  }
85 
86  // remove from cache
87  bool found = false;
88  foreach(int i, translation->entry()->translationIndices()) {
89  if (translation->entry()->translation(i)->leitnerBox() == this) {
90  found = true;
91  break;
92  }
93  }
94  if (!found) {
95  d->m_expressions.removeAt(d->m_expressions.indexOf(translation->entry()));
96  }
97 
98  invalidateChildLessonEntries();
99 }
100 
101 KEduVocTranslation * KEduVocLeitnerBox::translation(int row)
102 {
103  return d->m_translations.value(row);
104 }
105 
106 KEduVocExpression * KEduVocLeitnerBox::entry(int row, EnumEntriesRecursive recursive)
107 {
108  Q_UNUSED(recursive)
109  return entries().value(row);
110 }
111 
keduvocexpression.h
KEduVocContainer
class to store information about a container - that can be a lesson or word types ...
Definition: keduvoccontainer.h:30
KEduVocTranslation::entry
KEduVocExpression * entry()
Definition: keduvoctranslation.cpp:391
KEduVocLeitnerBox::entryCount
int entryCount(EnumEntriesRecursive recursive=NotRecursive)
get the number of entries in the lesson
Definition: keduvocleitnerbox.cpp:50
KEduVocLeitnerBox::translation
KEduVocTranslation * translation(int row)
The leitner box class keeps track of individual translations, because for one entry, the translations can have different grades.
Definition: keduvocleitnerbox.cpp:101
KEduVocTranslation::setLeitnerBox
void setLeitnerBox(KEduVocLeitnerBox *leitnerBox)
Sets the leitner box of this translation.
Definition: keduvoctranslation.cpp:380
KEduVocLeitnerBox
Leitner Boxes are an alternative grading system.
Definition: keduvocleitnerbox.h:31
KEduVocContainer::invalidateChildLessonEntries
void invalidateChildLessonEntries()
Set the child entry cache to invalid.
Definition: keduvoccontainer.cpp:241
KEduVocContainer::EnumEntriesRecursive
EnumEntriesRecursive
Definition: keduvoccontainer.h:42
KEduVocContainer::parent
virtual KEduVocContainer * parent()
Definition: keduvoccontainer.cpp:195
KEduVocExpression::lesson
KEduVocLesson * lesson() const
return the lesson
Definition: keduvocexpression.cpp:144
KEduVocTranslation
Definition: keduvoctranslation.h:35
KEduVocLeitnerBox::entries
QList< KEduVocExpression * > entries(EnumEntriesRecursive recursive=NotRecursive)
get a list of all entries in the box
Definition: keduvocleitnerbox.cpp:44
KEduVocExpression
This class contains one vocabulary expression as an original with one or more translations.
Definition: keduvocexpression.h:37
KEduVocExpression::translation
KEduVocTranslation * translation(int index)
Get a pointer to the translation.
Definition: keduvocexpression.cpp:182
KEduVocExpression::translationIndices
QList< int > translationIndices() const
Definition: keduvocexpression.cpp:199
keduvocleitnerbox.h
KEduVocTranslation::leitnerBox
KEduVocLeitnerBox * leitnerBox() const
Returns the leitner box of this translation.
Definition: keduvoctranslation.cpp:375
KEduVocLeitnerBox::KEduVocLeitnerBox
KEduVocLeitnerBox(const QString &name, KEduVocLeitnerBox *parent=0)
default constructor
Definition: keduvocleitnerbox.cpp:29
KEduVocLeitnerBox::~KEduVocLeitnerBox
~KEduVocLeitnerBox()
destructor
Definition: keduvocleitnerbox.cpp:36
KEduVocLeitnerBox::entry
KEduVocExpression * entry(int row, EnumEntriesRecursive recursive=NotRecursive)
Definition: keduvocleitnerbox.cpp:106
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:37:21 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

libkdeedu/keduvocdocument

Skip menu "libkdeedu/keduvocdocument"
  • 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