• 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
keduvockvtmlcompability.cpp
Go to the documentation of this file.
1 /***************************************************************************
2 
3  C++ Implementation: keduvockvtml1compability_p
4 
5  -----------------------------------------------------------------------
6 
7  begin : Di Aug 28 2007
8 
9  copyright : (C) 2007 Frederik Gladhorn <frederik.gladhorn@kdemail.net>
10 
11  -----------------------------------------------------------------------
12 
13  ***************************************************************************/
14 
15 /***************************************************************************
16  * *
17  * This program is free software; you can redistribute it and/or modify *
18  * it under the terms of the GNU General Public License as published by *
19  * the Free Software Foundation; either version 2 of the License, or *
20  * (at your option) any later version. *
21  * *
22  ***************************************************************************/
23 
24 #include "keduvockvtmlcompability.h"
25 #include "keduvocwordtype.h"
26 
27 #include <KLocale>
28 #include <KDebug>
29 
30 const QString KEduVocKvtmlCompability::KVTML_1_USER_DEFINED = QString( "#" );
31 const QString KEduVocKvtmlCompability::KVTML_1_SEPERATOR = QString( ":" );
32 
33 
34 KEduVocKvtmlCompability::KEduVocKvtmlCompability()
35 {
36  m_userdefinedTenseCounter = 0;
37  m_userdefinedTypeCounter = 0;
38 
39  initOldTypeLists();
40  initOldTenses();
41 }
42 
43 
45 void KEduVocKvtmlCompability::initOldTypeLists()
46 {
47  m_oldMainTypeNames.clear();
48  m_oldMainTypeNames.insert( "v", i18nc( "@item:inlistbox The grammatical type of a word", "Verb" ) );
49  m_oldMainTypeNames.insert( "n", i18nc( "@item:inlistbox The grammatical type of a word", "Noun" ) );
50  m_oldMainTypeNames.insert( "nm", i18nc( "@item:inlistbox The grammatical type of a word", "Name" ) );
51  m_oldMainTypeNames.insert( "ar", i18nc( "@item:inlistbox The grammatical type of a word", "Article" ) );
52  m_oldMainTypeNames.insert( "aj", i18nc( "@item:inlistbox The grammatical type of a word", "Adjective" ) );
53  m_oldMainTypeNames.insert( "av", i18nc( "@item:inlistbox The grammatical type of a word", "Adverb" ) );
54  m_oldMainTypeNames.insert( "pr", i18nc( "@item:inlistbox The grammatical type of a word", "Pronoun" ) );
55  m_oldMainTypeNames.insert( "ph", i18nc( "@item:inlistbox The grammatical type of an entry", "Phrase" ) );
56  m_oldMainTypeNames.insert( "num", i18nc( "@item:inlistbox The grammatical type of a word", "Numeral" ) );
57  m_oldMainTypeNames.insert( "con", i18nc( "@item:inlistbox The grammatical type of a word", "Conjunction" ) );
58  m_oldMainTypeNames.insert( "pre", i18nc( "@item:inlistbox The grammatical type of a word", "Preposition" ) );
59  m_oldMainTypeNames.insert( "qu", i18nc( "@item:inlistbox The grammatical type of an entry", "Question" ) );
60 
61 
62  m_oldSubTypeNames.clear();
63  m_oldSubTypeNames.insert( "ord", i18nc( "@item:inlistbox A subtype of the grammatical word type: Numeral Ordinal (first, second, third, ...)","Ordinal" ) );
64  m_oldSubTypeNames.insert( "crd", i18nc( "@item:inlistbox A subtype of the grammatical word type: Numeral Cardinal (one, two, three, ...)","Cardinal" ) );
65  m_oldSubTypeNames.insert( "def", i18nc( "@item:inlistbox A subtype of the grammatical word type: Article (the)","Definite" ) );
66  m_oldSubTypeNames.insert( "ind", i18nc( "@item:inlistbox A subtype of the grammatical word type: Article (a)","Indefinite" ) );
67  m_oldSubTypeNames.insert( "re", i18nc( "@item:inlistbox A subtype of the grammatical word type: Verb with regular conjugation","Regular" ) );
68  m_oldSubTypeNames.insert( "ir", i18nc( "@item:inlistbox A subtype of the grammatical word type: Verb with irregular conjugation","Irregular" ) );
69  m_oldSubTypeNames.insert( "pos", i18nc( "@item:inlistbox A subtype of the grammatical word type: Pronoun (my, your, his, her...)", "Possessive" ) );
70  m_oldSubTypeNames.insert( "per", i18nc( "@item:inlistbox A subtype of the grammatical word type: Pronoun (I, you, he...)", "Personal" ) );
71  m_oldSubTypeNames.insert( "m", i18nc( "@item:inlistbox A subtype of the grammatical word type: Noun", "Male" ) );
72  m_oldSubTypeNames.insert( "f", i18nc( "@item:inlistbox A subtype of the grammatical word type: Noun", "Female" ) );
73  m_oldSubTypeNames.insert( "s", i18nc( "@item:inlistbox A subtype of the grammatical word type: Noun", "Neutral" ) );
74 }
75 
76 
77 KEduVocWordType* KEduVocKvtmlCompability::typeFromOldFormat(KEduVocWordType* parent, const QString & typeSubtypeString ) const
78 {
79  // check if it's user defined
80  if ( typeSubtypeString.length() >= 2 && typeSubtypeString.left( 1 ) == QM_USER_TYPE ) {
81  // they started counting at 1, we need to know which index we are dealing with:
82  int selfDefinedTypeIndex = typeSubtypeString.right( typeSubtypeString.count()-1 ).toInt() -1;
83  return static_cast<KEduVocWordType*>(parent->childContainer(selfDefinedTypeIndex));
84  }
85 
86  // assume the parent is set up to contain the old types correctly
87  QString mainType;
88  QString subType;
89  int i;
90 
91  if (( i = typeSubtypeString.indexOf( KVTML_1_SEPERATOR ) ) >= 0 ) {
92  mainType = typeSubtypeString.left( i );
93  subType = typeSubtypeString.right( i+1 );
94  } else {
95  mainType = typeSubtypeString;
96  }
97 
98  // convert from pre-0.5 versions (I guess we can just leave that in here.
99  // I seriously doubt that any such documents exist...
100  if ( mainType == "1" ) {
101  mainType = QM_VERB;
102  } else if ( mainType == "2" ) {
103  mainType = QM_NOUN;
104  } else if ( mainType == "3" ) {
105  mainType = QM_NAME;
106  }
107 
108  QString typeName = m_oldMainTypeNames.value( mainType );
109  if ( typeName.isEmpty() ) {
110  kDebug() << "Unknown old maintype: " << typeSubtypeString;
111  return 0;
112  }
113 
114  QString subTypeName = m_oldSubTypeNames.value( subType );
115 
116  foreach (KEduVocContainer* wordType, parent->childContainers()) {
117  if (wordType->name() == typeName) {
118  if (subType.isEmpty()) {
119  return static_cast<KEduVocWordType*>(wordType);
120  } else {
121  foreach (KEduVocContainer* subWordType, wordType->childContainers()) {
122  if (subWordType->name() == subTypeName) {
123  return static_cast<KEduVocWordType*>(subWordType);
124  }
125  }
126  }
127  }
128  }
129 
130  return 0;
131 }
132 
133 
134 
135 
136 
137 
138 /*
139 if ( type.length() >= 2 && type.left( 1 ) == QM_USER_TYPE ) {
140  // they started counting at 1, we need to know which index we are dealing with:
141  int selfDefinedTypeIndex = type.right( type.count()-1 ).toInt() -1;
142 
143  // append invented types (do we not trust our own writer?)
144  if ( selfDefinedTypeIndex >= m_oldSelfDefinedTypes.count() ) {
145  while ( selfDefinedTypeIndex >= m_oldSelfDefinedTypes.count() ) {
146  m_oldSelfDefinedTypes.append( i18n( "User defined word type %1", m_oldSelfDefinedTypes.count() - 1 ) );
147  }
148  }
149  type = m_oldSelfDefinedTypes.value( selfDefinedTypeIndex );
150  } else {
151  type = m_compability.mainTypeFromOldFormat( oldType );
152  subType = m_compability.subTypeFromOldFormat( oldType );
153  } // not user defined - preset types
154 
155 
156 if ( oldType.length() >= 2 && type.left( 1 ) == QM_USER_TYPE ) {
157  // they started counting at 1
158  int selfDefinedTypeIndex = oldType.right( type.count()-1 ).toInt() -1;
159  // append invented types (do we not trust our own writer?)
160  if ( selfDefinedTypeIndex >= m_oldSelfDefinedTypes.count() ) {
161  while ( selfDefinedTypeIndex >= m_oldSelfDefinedTypes.count() ) {
162  m_oldSelfDefinedTypes.append( i18n( "User defined word type %1", m_oldSelfDefinedTypes.count() - 1 ) );
163  }
164  }
165  type = m_oldSelfDefinedTypes.value( selfDefinedTypeIndex );
166  } else {
167  type = m_compability.mainTypeFromOldFormat( oldType );
168  subType = m_compability.subTypeFromOldFormat( oldType );
169  } // not user defined - preset types
170  }
171 */
172 
173 
174 
175 void KEduVocKvtmlCompability::initOldTenses()
176 {
177  m_oldTenses["PrSi"] = i18n( "Simple Present" );
178  m_oldTenses["PrPr"] = i18n( "Present Progressive" );
179  m_oldTenses["PrPe"] = i18n( "Present Perfect" );
180  m_oldTenses["PaSi"] = i18n( "Simple Past" );
181  m_oldTenses["PaPr"] = i18n( "Past Progressive" );
182  m_oldTenses["PaPa"] = i18n( "Past Participle" );
183  m_oldTenses["FuSi"] = i18n( "Future" );
184 }
185 
186 
187 void KEduVocKvtmlCompability::addUserdefinedTense(const QString & tense)
188 {
189  m_userdefinedTenseCounter++;
190  m_oldTenses[KVTML_1_USER_DEFINED + QString::number( m_userdefinedTenseCounter )] = tense;
191  m_tenses.insert(tense);
192 
193  kDebug() << " Add tense: " << KVTML_1_USER_DEFINED + QString::number( m_userdefinedTenseCounter ) << " - " << tense;
194 }
195 
196 
197 QString KEduVocKvtmlCompability::tenseFromKvtml1(const QString & oldTense)
198 {
199  // in case the document got chaged, at least make up something as tense
200  if (!m_oldTenses.keys().contains(oldTense)) {
201  m_oldTenses[oldTense] = oldTense;
202  kDebug() << "Warning, tense " << oldTense << " not found in document!";
203  }
204  m_tenses.insert(m_oldTenses.value(oldTense));
205  return m_oldTenses.value(oldTense);
206 }
207 
208 
209 QStringList KEduVocKvtmlCompability::documentTenses() const
210 {
211  return m_tenses.values();
212 }
213 
214 
215 QString KEduVocKvtmlCompability::oldTense(const QString & tense)
216 {
218  if ( !m_oldTenses.values().contains(tense) ) {
219  m_userdefinedTenseCounter++;
220  m_oldTenses[KVTML_1_USER_DEFINED + QString::number( m_userdefinedTenseCounter )] = tense;
221  }
222  return m_oldTenses.key(tense);
223 }
224 
225 void KEduVocKvtmlCompability::setupWordTypes(KEduVocWordType * parent)
226 {
227  QStringList wordTypeNames;
228  wordTypeNames
229  << i18nc( "The grammatical type of a word", "Verb" ) // 0
230  << i18nc( "The grammatical type of a word", "Noun" ) // 1
231  << i18nc( "The grammatical type of a word", "Name" )
232  << i18nc( "The grammatical type of a word", "Article" ) // 3
233  << i18nc( "The grammatical type of a word", "Adjective" ) // 4
234  << i18nc( "The grammatical type of a word", "Adverb" ) // 5
235  << i18nc( "The grammatical type of a word", "Pronoun" ) // 6
236  << i18nc( "The grammatical type of an entry", "Phrase" )
237  << i18nc( "The grammatical type of a word", "Numeral" ) // 8
238  << i18nc( "The grammatical type of a word", "Conjunction" )
239  << i18nc( "The grammatical type of a word", "Preposition" )
240  << i18nc( "The grammatical type of an entry", "Question" );
241 
242  foreach (const QString &typeName, wordTypeNames) {
243  KEduVocWordType* wordType = new KEduVocWordType(typeName, parent);
244  parent->appendChildContainer(wordType);
245  m_userdefinedTypeCounter++;
246  }
247  static_cast<KEduVocWordType*>(parent->childContainer(4))->setWordType(KEduVocWordFlag::Adjective);
248  static_cast<KEduVocWordType*>(parent->childContainer(5))->setWordType(KEduVocWordFlag::Adverb);
249 
250  KEduVocWordType* numeral = static_cast<KEduVocWordType*>(parent->childContainer(8));
251  KEduVocWordType* wordType = new KEduVocWordType(
252  i18nc( "@item:inlistbox A subtype of the grammatical word type: Numeral Ordinal (first, second, third, ...)","Ordinal" ), numeral);
253  wordType->setWordType(KEduVocWordFlag::Adjective);
254  numeral->appendChildContainer(wordType);
255  wordType = new KEduVocWordType(
256  i18nc( "@item:inlistbox A subtype of the grammatical word type: Numeral Cardinal (one, two, three, ...)","Cardinal" ), numeral);
257 
258  wordType->setWordType(KEduVocWordFlag::Adjective);
259  numeral->appendChildContainer(wordType);
260 
261  KEduVocWordType* article = static_cast<KEduVocWordType*>(parent->childContainer(3));
262  wordType = new KEduVocWordType(i18nc( "@item:inlistbox A subtype of the grammatical word type: Article (the)","Definite" ), article);
263  wordType->setWordType(KEduVocWordFlag::Article | KEduVocWordFlag::Definite);
264  article->appendChildContainer(wordType);
265  wordType = new KEduVocWordType(i18nc( "@item:inlistbox A subtype of the grammatical word type: Article (a)","Indefinite" ), article);
266  wordType->setWordType(KEduVocWordFlag::Article | KEduVocWordFlag::Indefinite);
267  article->appendChildContainer(wordType);
268 
269  KEduVocWordType* verb = static_cast<KEduVocWordType*>(parent->childContainer(0));
270  verb->setWordType(KEduVocWordFlag::Verb);
271  wordType = new KEduVocWordType(i18nc( "@item:inlistbox A subtype of the grammatical word type: Verb with regular conjugation","Regular" ), verb);
272  wordType->setWordType(KEduVocWordFlag::Verb | KEduVocWordFlag::Regular);
273  verb->appendChildContainer(wordType);
274  wordType = new KEduVocWordType(i18nc( "@item:inlistbox A subtype of the grammatical word type: Verb with irregular conjugation","Irregular" ), verb);
275  verb->appendChildContainer(wordType);
276  wordType->setWordType(KEduVocWordFlag::Verb | KEduVocWordFlag::Irregular);
277 
278  KEduVocWordType* noun = static_cast<KEduVocWordType*>(parent->childContainer(1));
279  noun->setWordType(KEduVocWordFlag::Noun);
280  wordType = new KEduVocWordType(i18nc( "@item:inlistbox A subtype of the grammatical word type: Noun", "Male" ), noun);
281  noun->appendChildContainer(wordType);
282  wordType->setWordType(KEduVocWordFlag::Noun | KEduVocWordFlag::Masculine);
283  wordType = new KEduVocWordType(i18nc( "@item:inlistbox A subtype of the grammatical word type: Noun", "Female" ), noun);
284  noun->appendChildContainer(wordType);
285  wordType->setWordType(KEduVocWordFlag::Noun | KEduVocWordFlag::Feminine);
286  wordType = new KEduVocWordType(i18nc( "@item:inlistbox A subtype of the grammatical word type: Noun", "Neutral" ), noun);
287  noun->appendChildContainer(wordType);
288  wordType->setWordType(KEduVocWordFlag::Noun | KEduVocWordFlag::Neuter);
289 
290 
291  KEduVocWordType* pronoun = static_cast<KEduVocWordType*>(parent->childContainer(6));
292  wordType = new KEduVocWordType(i18nc( "@item:inlistbox A subtype of the grammatical word type: Pronoun (my, your, his, her...)", "Possessive" ), pronoun);
293  wordType->setWordType(KEduVocWordFlag::Pronoun);
294  pronoun->appendChildContainer(wordType);
295  wordType = new KEduVocWordType(i18nc( "@item:inlistbox A subtype of the grammatical word type: Pronoun (I, you, he...)", "Personal" ), pronoun);
296  wordType->setWordType(KEduVocWordFlag::Pronoun);
297  pronoun->appendChildContainer(wordType);
298 }
299 
KEduVocContainer::childContainers
QList< KEduVocContainer * > childContainers()
Definition: keduvoccontainer.cpp:190
KEduVocWordFlag::Adjective
Definition: keduvocwordflags.h:41
KEduVocContainer
class to store information about a container - that can be a lesson or word types ...
Definition: keduvoccontainer.h:30
KEduVocWordFlag::Verb
Definition: keduvocwordflags.h:38
KEduVocWordFlag::Pronoun
Definition: keduvocwordflags.h:40
QM_VERB
#define QM_VERB
Definition: keduvockvtmlcompability.h:34
KEduVocKvtmlCompability::typeFromOldFormat
KEduVocWordType * typeFromOldFormat(KEduVocWordType *parent, const QString &typeSubtypeString) const
Get the type from an old type definition.
Definition: keduvockvtmlcompability.cpp:77
KEduVocWordFlag::Article
Definition: keduvocwordflags.h:43
KEduVocWordFlag::Masculine
Definition: keduvocwordflags.h:28
keduvocwordtype.h
KEduVocKvtmlCompability::documentTenses
QStringList documentTenses() const
Definition: keduvockvtmlcompability.cpp:209
KEduVocContainer::childContainer
KEduVocContainer * childContainer(int row)
Definition: keduvoccontainer.cpp:85
KEduVocKvtmlCompability::KEduVocKvtmlCompability
KEduVocKvtmlCompability()
Constructor, initialize the map.
Definition: keduvockvtmlcompability.cpp:34
QM_NAME
#define QM_NAME
Definition: keduvockvtmlcompability.h:41
QM_NOUN
#define QM_NOUN
Definition: keduvockvtmlcompability.h:37
KEduVocWordType
class to store translation word types
Definition: keduvocwordtype.h:33
KEduVocKvtmlCompability::setupWordTypes
void setupWordTypes(KEduVocWordType *parent)
Definition: keduvockvtmlcompability.cpp:225
QM_USER_TYPE
#define QM_USER_TYPE
Definition: keduvockvtmlcompability.h:62
KEduVocWordFlag::Irregular
Definition: keduvocwordflags.h:64
KEduVocWordFlag::Noun
Definition: keduvocwordflags.h:39
KEduVocWordFlag::Indefinite
Definition: keduvocwordflags.h:62
KEduVocContainer::name
QString name()
get the container name
Definition: keduvoccontainer.cpp:156
KEduVocWordFlag::Regular
Definition: keduvocwordflags.h:63
KEduVocKvtmlCompability::addUserdefinedTense
void addUserdefinedTense(const QString &tense)
Definition: keduvockvtmlcompability.cpp:187
KEduVocWordFlag::Adverb
Definition: keduvocwordflags.h:42
KEduVocContainer::appendChildContainer
void appendChildContainer(KEduVocContainer *child)
Definition: keduvoccontainer.cpp:77
KEduVocKvtmlCompability::oldTense
QString oldTense(const QString &tense)
Definition: keduvockvtmlcompability.cpp:215
KEduVocKvtmlCompability::tenseFromKvtml1
QString tenseFromKvtml1(const QString &oldTense)
Definition: keduvockvtmlcompability.cpp:197
KEduVocWordFlag::Neuter
Definition: keduvocwordflags.h:30
KEduVocWordType::setWordType
void setWordType(KEduVocWordFlags flags)
assignment operator
Definition: keduvocwordtype.cpp:126
keduvockvtmlcompability.h
KEduVocWordFlag::Feminine
Definition: keduvocwordflags.h:29
KEduVocWordFlag::Definite
Definition: keduvocwordflags.h:61
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