LibKEduVocDocument

keduvocdeclension.cpp
1/*
2 * C++ Implementation: keduvocdeclension
3 * SPDX-FileCopyrightText: 2007 Frederik Gladhorn <frederik.gladhorn@kdemail.net>
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6#include "keduvocdeclension.h"
7
8#include "keduvockvtml2writer.h"
9#include "kvtml2defs.h"
10#include <QDomDocument>
11
12#include <QMap>
13
14class KEduVocDeclension::Private
15{
16public:
18};
19
21 : d(new Private)
22{
23}
24
26 : d(new Private)
27{
28 d->m_declensions = other.d->m_declensions;
29}
30
32{
33 d->m_declensions = other.d->m_declensions;
34 return *this;
35}
36
37KEduVocDeclension::~KEduVocDeclension()
38{
39 delete d;
40}
41
43{
44 return d->m_declensions[flags];
45}
46
48{
49 d->m_declensions[flags] = declension;
50}
51
52bool KEduVocDeclension::isEmpty()
53{
54 return d->m_declensions.isEmpty();
55}
56
58{
59 if (isEmpty()) {
60 return;
61 }
62 QDomDocument domDoc = parent.ownerDocument();
63 QDomElement declensionElement = domDoc.createElement(KVTML_DECLENSION);
64
66 genders[0] = KEduVocWordFlag::Masculine;
67 genders[1] = KEduVocWordFlag::Feminine;
68 genders[2] = KEduVocWordFlag::Neuter;
69
71 numbers[0] = KEduVocWordFlag::Singular;
72 numbers[1] = KEduVocWordFlag::Dual;
73 numbers[2] = KEduVocWordFlag::Plural;
74
76 cases[0] = KEduVocWordFlag::Nominative;
77 cases[1] = KEduVocWordFlag::Genitive;
78 cases[2] = KEduVocWordFlag::Dative;
79 cases[3] = KEduVocWordFlag::Accusative;
80 cases[4] = KEduVocWordFlag::Ablative;
81 cases[5] = KEduVocWordFlag::Locative;
82 cases[6] = KEduVocWordFlag::Vocative;
83
84 for (int gen = 0; gen <= 2; ++gen) {
85 QDomElement genderElement = domDoc.createElement(KVTML_GRAMMATICAL_GENDER[gen]);
86 for (int num = 0; num <= 2; ++num) {
87 QDomElement numberElement = domDoc.createElement(KVTML_GRAMMATICAL_NUMBER[num]);
88 for (int dcase = 0; dcase <= 6; ++dcase) {
89 QDomElement caseElement = domDoc.createElement(KVTML_DECLENSION_CASE[dcase]);
90 declension(genders[gen] | numbers[num] | cases[dcase]).toKVTML2(caseElement);
91
92 if (caseElement.hasChildNodes()) {
93 numberElement.appendChild(caseElement);
94 }
95 }
96 if (numberElement.hasChildNodes()) {
97 genderElement.appendChild(numberElement);
98 }
99 }
100 if (genderElement.hasChildNodes()) {
101 declensionElement.appendChild(genderElement);
102 }
103 }
104 if (declensionElement.hasChildNodes()) {
105 parent.appendChild(declensionElement);
106 }
107}
108
110{
111 QDomElement declensionElement = parent.firstChildElement(KVTML_DECLENSION);
112 // we don't create empty objects, if necessary, create later on demand.
113 if (declensionElement.isNull()) {
114 return nullptr;
115 }
116
118 genders[0] = KEduVocWordFlag::Masculine;
119 genders[1] = KEduVocWordFlag::Feminine;
120 genders[2] = KEduVocWordFlag::Neuter;
121
123 numbers[0] = KEduVocWordFlag::Singular;
124 numbers[1] = KEduVocWordFlag::Dual;
125 numbers[2] = KEduVocWordFlag::Plural;
126
128 cases[0] = KEduVocWordFlag::Nominative;
129 cases[1] = KEduVocWordFlag::Genitive;
130 cases[2] = KEduVocWordFlag::Dative;
131 cases[3] = KEduVocWordFlag::Accusative;
132 cases[4] = KEduVocWordFlag::Ablative;
133 cases[5] = KEduVocWordFlag::Locative;
134 cases[6] = KEduVocWordFlag::Vocative;
135
137
138 for (int gen = 0; gen <= 2; ++gen) {
139 QDomElement genderElement = declensionElement.firstChildElement(KVTML_GRAMMATICAL_GENDER[gen]);
140 if (!genderElement.isNull()) {
141 for (int num = 0; num <= 2; ++num) {
142 QDomElement numberElement = genderElement.firstChildElement(KVTML_GRAMMATICAL_NUMBER[num]);
143 if (!numberElement.isNull()) {
144 for (int dcase = 0; dcase <= 6; ++dcase) {
145 QDomElement caseElement = numberElement.firstChildElement(KVTML_DECLENSION_CASE[dcase]);
146 if (!caseElement.isNull()) {
147 KEduVocText text;
148 text.fromKVTML2(caseElement);
149 declension->setDeclension(text, genders[gen] | numbers[num] | cases[dcase]);
150 }
151 }
152 }
153 }
154 }
155 }
156 return declension;
157}
A declension contains all forms that a NOUN possibly can have.
void setDeclension(const KEduVocText &declension, KEduVocWordFlags flags)
Set a declension.
KEduVocText & declension(KEduVocWordFlags flags)
The grammatical number, there is singular and plural for english, some languages have dual for exactl...
KEduVocDeclension()
The constructor without arguments.
KEduVocDeclension & operator=(const KEduVocDeclension &other)
equality operator
static KEduVocDeclension * fromKVTML2(QDomElement &parent)
Reads a declension from xml, returns 0 if it is empty.
void toKVTML2(QDomElement &parent)
Create xml for this declension.
A text in vocabulary documents.
Definition keduvoctext.h:50
QDomElement createElement(const QString &tagName)
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
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.