LibKEduVocDocument

keduvocconjugation.cpp
1/*
2 * C++ Implementation: keduvocconjugation
3 * SPDX-FileCopyrightText: 2007 Frederik Gladhorn <frederik.gladhorn@kdemail.net>
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
7#include "keduvocconjugation.h"
8#include "keduvoccommon_p.h"
9#include "kvtml2defs.h"
10
11#include <QDebug>
12#include <QDomDocument>
13#include <QMap>
14
15class KEduVocConjugation::Private
16{
17public:
19};
20
22 : d(new Private)
23{
24}
25
27 : d(new Private)
28{
29 d->m_conjugations = other.d->m_conjugations;
30}
31
32KEduVocConjugation::~KEduVocConjugation()
33{
34 delete d;
35}
36
37KEduVocConjugation &KEduVocConjugation::operator=(const KEduVocConjugation &other)
38{
39 d->m_conjugations = other.d->m_conjugations;
40 return *this;
41}
42
43bool KEduVocConjugation::operator==(const KEduVocConjugation &other) const
44{
45 return d->m_conjugations == other.d->m_conjugations;
46}
47
49{
50 return d->m_conjugations[flags & (KEduVocWordFlag::persons | KEduVocWordFlag::numbers | KEduVocWordFlag::genders)];
51}
52
54{
55 d->m_conjugations[flags & (KEduVocWordFlag::persons | KEduVocWordFlag::numbers | KEduVocWordFlag::genders)] = conjugation;
56}
57
58bool KEduVocConjugation::isEmpty()
59{
60 return d->m_conjugations.isEmpty();
61}
62
63QList<KEduVocWordFlags> KEduVocConjugation::keys()
64{
65 return d->m_conjugations.keys();
66}
67
69{
70 if (isEmpty()) {
71 return;
72 }
73
75 numbers[0] = KEduVocWordFlag::Singular;
76 numbers[1] = KEduVocWordFlag::Dual;
77 numbers[2] = KEduVocWordFlag::Plural;
79 persons[0] = KEduVocWordFlag::First;
80 persons[1] = KEduVocWordFlag::Second;
81 persons[2] = (KEduVocWordFlag::Flags)((int)KEduVocWordFlag::Third | (int)KEduVocWordFlag::Masculine);
82 persons[3] = (KEduVocWordFlag::Flags)((int)KEduVocWordFlag::Third | (int)KEduVocWordFlag::Feminine);
83 persons[4] = (KEduVocWordFlag::Flags)((int)KEduVocWordFlag::Third | (int)KEduVocWordFlag::Neuter);
84
85 QDomDocument domDoc = parent.ownerDocument();
86
87 // write the tense tag
88 if (!tense.isEmpty()) {
89 QDomElement tenseElement = domDoc.createElement(KVTML_TENSE);
90 tenseElement.appendChild(domDoc.createTextNode(tense));
91 parent.appendChild(tenseElement);
92 } else {
93 qDebug() << "Saving conjugation with empty tense";
94 }
95
96 for (int num = 0; num <= 2; ++num) {
97 QDomElement numberElement = domDoc.createElement(KVTML_GRAMMATICAL_NUMBER[num]);
98 for (int person = 0; person < 5; ++person) {
99 KEduVocWordFlags curFlags = numbers[num] | persons[person];
100
101 if (keys().contains(curFlags) && !conjugation(curFlags).isEmpty()) {
102 QDomElement personElement = domDoc.createElement(KVTML_GRAMMATICAL_PERSON[person]);
103 numberElement.appendChild(personElement);
104 conjugation(curFlags).toKVTML2(personElement);
105 }
106 }
107 if (numberElement.hasChildNodes()) {
108 parent.appendChild(numberElement);
109 }
110 }
111}
112
113/*
114
115 QString first = conjugation.conjugation(
116 KEduVocConjugation::First, num );
117 QString second = conjugation.conjugation(
118 KEduVocConjugation::Second, num );
119 QString third_male = conjugation.conjugation(
120 KEduVocConjugation::ThirdMale, num );
121 QString third_female = conjugation.conjugation(
122 KEduVocConjugation::ThirdFemale, num );
123 QString third_neutral = conjugation.conjugation(
124 KEduVocConjugation::ThirdNeutralCommon, num );
125
126 if ( !first.isEmpty() || !second.isEmpty() || !third_female.isEmpty() ||
127 !third_male.isEmpty() || !third_neutral.isEmpty() ) {
128 QDomElement number;
129 switch (num) {
130 case KEduVocConjugation::Singular:
131 number = m_domDoc.createElement( KVTML_SINGULAR );
132 break;
133 case KEduVocConjugation::Dual:
134 number = m_domDoc.createElement( KVTML_DUAL );
135 break;
136 case KEduVocConjugation::Plural:
137 number = m_domDoc.createElement( KVTML_PLURAL );
138 break;
139 }
140
141 number.appendChild( newTextElement( KVTML_1STPERSON, first ) );
142 number.appendChild( newTextElement( KVTML_2NDPERSON, second ) );
143 number.appendChild( newTextElement( KVTML_THIRD_MALE, third_male ) );
144 number.appendChild( newTextElement( KVTML_THIRD_FEMALE, third_female ) );
145 number.appendChild( newTextElement( KVTML_THIRD_NEUTRAL_COMMON, third_neutral ) );
146
147 conjugationElement.appendChild( number );
148 }
149 }*/
150
151/*
152for ( KEduVocWordFlag::DeclensionNumber num = KEduVocWordFlag::Singular; num <= KEduVocWordFlag::Plural; num = KEduVocWordFlag::DeclensionNumber(num +1) ) {
153 QDomElement numberElement = domDoc.createElement( KVTML_GRAMMATICAL_NUMBER[num] );
154 for ( KEduVocWordFlag::DeclensionCase dcase = KEduVocWordFlag::Nominative; dcase < KEduVocWordFlag::DeclensionCaseMAX; dcase =
155KEduVocWordFlag::DeclensionCase(dcase +1) ) { QDomElement caseElement = domDoc.createElement( KVTML_DECLENSION_CASE[dcase] ); declension(num,
156dcase).toKVTML2(caseElement);
157
158 if (caseElement.hasChildNodes()) {
159 numberElement.appendChild(caseElement);
160 }
161 }
162 if (numberElement.hasChildNodes()) {
163 declensionElement.appendChild(numberElement);
164 }
165}
166
167*/
168
170{
171 // sanity check
172 if (parent.isNull()) {
173 return nullptr;
174 }
175
177 numbers[0] = KEduVocWordFlag::Singular;
178 numbers[1] = KEduVocWordFlag::Dual;
179 numbers[2] = KEduVocWordFlag::Plural;
181 persons[0] = KEduVocWordFlag::First;
182 persons[1] = KEduVocWordFlag::Second;
183 persons[2] = (KEduVocWordFlag::Flags)((int)KEduVocWordFlag::Third | (int)KEduVocWordFlag::Masculine);
184 persons[3] = (KEduVocWordFlag::Flags)((int)KEduVocWordFlag::Third | (int)KEduVocWordFlag::Feminine);
185 persons[4] = (KEduVocWordFlag::Flags)((int)KEduVocWordFlag::Third | (int)KEduVocWordFlag::Neuter);
186
188
189 for (int num = 0; num <= 2; num++) {
190 QDomElement numberElement = parent.firstChildElement(KVTML_GRAMMATICAL_NUMBER[num]);
191
192 if (numberElement.hasChildNodes()) {
193 for (int person = 0; person < 5; person++) {
194 QDomElement personElement = numberElement.firstChildElement(KVTML_GRAMMATICAL_PERSON[person]);
195 if (!personElement.isNull()) {
196 KEduVocText text;
197 text.fromKVTML2(personElement);
198 if (text.text().isEmpty()) {
199 // compatibility for kde 4.0. There the text was directly below the person, not enabling grades per conjugation form.
200 text.setText(personElement.text());
201 }
202 conjugation->setConjugation(text, persons[person] | numbers[num]);
203 }
204 }
205 }
206 }
207 return conjugation;
208}
The conjugation of a verb.
KEduVocConjugation()
The constructor.
void setConjugation(const KEduVocText &conjugation, KEduVocWordFlags flags)
Updates or creates the conjugation object for the given word flags.
KEduVocText & conjugation(KEduVocWordFlags flags) const
Returns an existing conjugation object.
void toKVTML2(QDomElement &parent, const QString &tense)
Create xml for this declension.
static KEduVocConjugation * fromKVTML2(QDomElement &parent)
Reads a declension from xml, returns 0 if it is empty.
A text in vocabulary documents.
Definition keduvoctext.h:50
QString text() const
The translation as string (the word itself)
void setText(const QString &expr)
Sets the translation.
QDomElement createElement(const QString &tagName)
QDomText createTextNode(const QString &value)
QString text() const const
QDomNode appendChild(const QDomNode &newChild)
QDomElement firstChildElement(const QString &tagName, const QString &namespaceURI) const const
bool hasChildNodes() const const
bool isNull() const const
QDomDocument ownerDocument() const const
bool isEmpty() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:15:30 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.