• 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
keduvocexpression.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  Vocabulary Expression for KDE Edu
3  -----------------------------------------------------------------------
4  copyright : (C) 1999-2001 Ewald Arnold <kvoctrain@ewald-arnold.de>
5 
6  (C) 2005-2007 Peter Hedlund <peter.hedlund@kdemail.net>
7  Copyright 2008 Frederik Gladhorn <frederik.gladhorn@kdemail.net>
8  ***************************************************************************/
9 
10 /***************************************************************************
11  * *
12  * This program is free software; you can redistribute it and/or modify *
13  * it under the terms of the GNU General Public License as published by *
14  * the Free Software Foundation; either version 2 of the License, or *
15  * (at your option) any later version. *
16  * *
17  ***************************************************************************/
18 
19 
20 #include "keduvocexpression.h"
21 
22 class KEduVocExpression::KEduVocExpressionPrivate
23 {
24 public:
25  KEduVocExpressionPrivate()
26  {
27  m_active = true;
28  m_lesson = 0;
29  }
30  ~KEduVocExpressionPrivate();
31 
32  KEduVocExpressionPrivate(const KEduVocExpressionPrivate &other);
33  KEduVocExpressionPrivate& operator= (const KEduVocExpressionPrivate &other);
34 
35  bool operator== ( const KEduVocExpressionPrivate &p ) const;
36 
37  KEduVocLesson* m_lesson;
38  bool m_active;
39 
40  QMap <int, KEduVocTranslation*> m_translations;
41 };
42 
43 KEduVocExpression::KEduVocExpressionPrivate::~KEduVocExpressionPrivate()
44 {
45  QMap <int, KEduVocTranslation*> translations = m_translations;
46  // empty the translations map, otherwise removal from word type will try to access them again when they don't exist any more
47  m_translations.clear();
48  qDeleteAll(translations);
49 }
50 
51 KEduVocExpression::KEduVocExpressionPrivate::KEduVocExpressionPrivate(const KEduVocExpressionPrivate & other)
52 {
53  m_active = other.m_active;
54  m_lesson = 0;
55 }
56 
57 KEduVocExpression::KEduVocExpressionPrivate & KEduVocExpression::KEduVocExpressionPrivate::operator =(const KEduVocExpressionPrivate & other)
58 {
59  m_active = other.m_active;
60  m_lesson = 0;
61 
62  return *this;
63 }
64 
65 bool KEduVocExpression::KEduVocExpressionPrivate::operator== ( const KEduVocExpression::KEduVocExpressionPrivate &p ) const
66 {
67  return
68  m_translations == p.m_translations &&
69  m_lesson == p.m_lesson &&
70  m_active == p.m_active;
71 }
72 
73 KEduVocExpression::KEduVocExpression()
74  : d( new KEduVocExpressionPrivate )
75 {}
76 
77 KEduVocExpression::KEduVocExpression( const QString & expression )
78  : d( new KEduVocExpressionPrivate )
79 {
80  setTranslation( 0, expression.simplified() );
81 }
82 
83 KEduVocExpression::KEduVocExpression( const QStringList & translations)
84  : d( new KEduVocExpressionPrivate )
85 {
86  foreach ( const QString &translation, translations ) {
87  setTranslation(d->m_translations.count(), translation);
88  }
89 }
90 
91 
92 KEduVocExpression::KEduVocExpression(const KEduVocExpression & other)
93  : d(new KEduVocExpressionPrivate(*other.d))
94 {
95  foreach (int key, other.d->m_translations.keys()) {
96  d->m_translations[key] = new KEduVocTranslation(*other.d->m_translations.value(key));
97  d->m_translations[key]->setEntry(this);
98  }
99 }
100 
101 KEduVocExpression& KEduVocExpression::operator= ( const KEduVocExpression &other )
102 {
103  *d = *other.d;
104  foreach (int key, other.d->m_translations.keys()) {
105  d->m_translations[key] = new KEduVocTranslation(*other.d->m_translations.value(key));
106  d->m_translations[key]->setEntry(this);
107  }
108  return *this;
109 }
110 
111 KEduVocExpression::~KEduVocExpression()
112 {
113  setLesson(0);
114  delete d;
115 }
116 
117 void KEduVocExpression::removeTranslation( int index )
118 {
119  int count = d->m_translations.count();
120 
121  // remove the index we delete
122  delete d->m_translations.take(index);
123 
124  // shift all other indexes, +1 for the deleted
125  for (int j = index; j < count-1; j++) {
126  d->m_translations[j] = d->m_translations.take(j+1);
127  }
128 }
129 
130 
131 void KEduVocExpression::setTranslation( int index, const QString & expr )
132 {
133  if ( index < 0 ) {
134  return;
135  }
136 
137  if (!d->m_translations.contains(index)) {
138  d->m_translations[index] = new KEduVocTranslation(this);
139  }
140  d->m_translations[index]->setText(expr.simplified());
141 }
142 
143 
144 KEduVocLesson* KEduVocExpression::lesson() const
145 {
146  return d->m_lesson;
147 }
148 
149 
150 bool KEduVocExpression::isActive() const
151 {
152  return d->m_active;
153 }
154 
155 
156 void KEduVocExpression::setActive( bool flag )
157 {
158  d->m_active = flag;
159 }
160 
161 
162 void KEduVocExpression::resetGrades( int index )
163 {
164  if ( index == -1 ) { // clear grades for all languages
165  foreach( KEduVocTranslation* trans, d->m_translations ) {
166  trans->resetGrades();
167  }
168  return;
169  }
170 
171  // only language index
172  if ( d->m_translations.contains( index ) ) {
173  d->m_translations[index]->resetGrades();
174  }
175 }
176 
177 bool KEduVocExpression::operator== ( const KEduVocExpression &expression ) const
178 {
179  return ( *d == *expression.d );
180 }
181 
182 KEduVocTranslation* KEduVocExpression::translation( int index )
183 {
184  if(translationIndices().contains(index)) {
185  return d->m_translations[index];
186  }
187  d->m_translations[index] = new KEduVocTranslation(this);
188  return d->m_translations[index];
189 }
190 
191 KEduVocTranslation * KEduVocExpression::translation(int index) const
192 {
193  if(d->m_translations.contains(index)) {
194  return 0;
195  }
196  return d->m_translations[index];
197 }
198 
199 QList< int > KEduVocExpression::translationIndices() const
200 {
201  return d->m_translations.keys();
202 }
203 
204 void KEduVocExpression::setLesson(KEduVocLesson * l)
205 {
206  if (d->m_lesson) {
207  d->m_lesson->removeEntry(this);
208  }
209  d->m_lesson = l;
210 }
211 
212 
keduvocexpression.h
KEduVocLesson
class to store information about a lesson
Definition: keduvoclesson.h:27
KEduVocExpression::operator==
bool operator==(const KEduVocExpression &expression) const
Definition: keduvocexpression.cpp:177
KEduVocExpression::removeTranslation
void removeTranslation(int index)
removes a translation
Definition: keduvocexpression.cpp:117
KEduVocExpression::isActive
bool isActive() const
returns flag if entry is activated for queries
Definition: keduvocexpression.cpp:150
KEduVocExpression::resetGrades
void resetGrades(int index)
reset all grades of the entry
Definition: keduvocexpression.cpp:162
KEduVocExpression::operator=
KEduVocExpression & operator=(const KEduVocExpression &expression)
Definition: keduvocexpression.cpp:101
KEduVocExpression::setTranslation
void setTranslation(int index, KEduVocTranslation *translation)
KEduVocExpression::KEduVocExpression
KEduVocExpression()
default constructor for an empty vocabulary expression
Definition: keduvocexpression.cpp:73
KEduVocExpression::setActive
void setActive(bool flag=true)
set entry active (enabled for queries)
Definition: keduvocexpression.cpp:156
KEduVocExpression::lesson
KEduVocLesson * lesson() const
return the lesson
Definition: keduvocexpression.cpp:144
KEduVocTranslation
Definition: keduvoctranslation.h:35
KEduVocText::resetGrades
void resetGrades()
Clears grading and date information.
Definition: keduvoctext.cpp:65
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
KEduVocExpression::~KEduVocExpression
~KEduVocExpression()
Definition: keduvocexpression.cpp:111
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