LibKEduVocDocument

keduvocwordtype.cpp
1/*
2 * SPDX-FileCopyrightText: 2007 Jeremy Whiting <jpwhiting@kde.org>
3 * SPDX-FileCopyrightText: 2007 Frederik Gladhorn <frederik.gladhorn@kdemail.net>
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
7#include "keduvocwordtype.h"
8
9#include "keduvocexpression.h"
10
11#include <QSet>
12
13class KEduVocWordType::Private
14{
15public:
16 // bitvector of word type flags
17 KEduVocWordFlags m_flags;
18 QList<KEduVocExpression *> m_expressions;
19 // list of translations
20 QList<KEduVocTranslation *> m_translations;
21};
22
24 : KEduVocContainer(name, WordType, parent)
25 , d(new Private)
26{
27}
28
30{
31 foreach (KEduVocTranslation *translation, d->m_translations) {
32 translation->setWordType(nullptr);
33 }
34 delete d;
35}
36
38{
39 if (recursive == Recursive) {
40 return entriesRecursive();
41 }
42
43 return d->m_expressions;
44}
45
46int KEduVocWordType::entryCount(EnumEntriesRecursive recursive)
47{
48 if (recursive == Recursive) {
49 return entriesRecursive().count();
50 }
51 return d->m_expressions.count();
52}
53
54void KEduVocWordType::addTranslation(KEduVocTranslation *translation)
55{
56 // add to expression - if not already there because another translation of the same word is there.
57 bool found = false;
58 foreach (int i, translation->entry()->translationIndices()) {
59 if (translation->entry()->translation(i)->wordType() == this) {
60 found = true;
61 break;
62 }
63 }
64 if (!found) {
65 d->m_expressions.append(translation->entry());
66 }
67 d->m_translations.append(translation);
69}
70
71void KEduVocWordType::removeTranslation(KEduVocTranslation *translation)
72{
73 d->m_translations.removeAt(d->m_translations.indexOf(translation));
74
75 // no lesson found - this entry is being deleted. remove all its siblings.
76 if (!translation->entry()->lesson()) {
77 const int index = d->m_expressions.indexOf(translation->entry());
78 if (index != -1) {
79 d->m_expressions.removeAt(index);
80 }
81 }
82
83 // remove from cache if none of the translations use this word type (other than the one we are removing that should not be taken into account)
84 bool found = false;
85 foreach (int i, translation->entry()->translationIndices()) {
86 if (translation->entry()->translation(i)->wordType() && translation->entry()->translation(i)->wordType() == this
87 && translation->entry()->translation(i) != translation) {
88 found = true;
89 break;
90 }
91 }
92 if (!found) {
93 const int index = d->m_expressions.indexOf(translation->entry());
94 if (index >= 0) {
95 d->m_expressions.removeAt(index);
96 }
97 }
98
100}
101
103{
104 return d->m_translations.value(row);
105}
106
107KEduVocExpression *KEduVocWordType::entry(int row, EnumEntriesRecursive recursive)
108{
109 if (recursive == Recursive) {
110 return entriesRecursive().value(row);
111 }
112 return entries().value(row);
113}
114
116{
117 return d->m_flags;
118}
119
121{
122 d->m_flags = flags;
123}
124
126{
127 if (d->m_flags == flags) {
128 return this;
129 }
130 foreach (KEduVocContainer *child, childContainers()) {
131 KEduVocWordType *result = static_cast<KEduVocWordType *>(child)->childOfType(flags);
132 if (result) {
133 return result;
134 }
135 }
136 return nullptr;
137}
class to store information about a container - that can be a lesson or word types
void invalidateChildLessonEntries()
Set the child entry cache to invalid.
This class contains one vocabulary expression as an original with one or more translations.
KEduVocLesson * lesson() const
return the lesson
KEduVocTranslation * translation(int index)
Get a pointer to the translation.
void setWordType(KEduVocWordType *wordType)
Sets the word type of this expression.
KEduVocWordType * wordType() const
Returns the word type of this expression, you will get a 0 pointer if wordtype is not set for the tra...
class to store translation word types
int entryCount(EnumEntriesRecursive recursive=NotRecursive) override
get the number of entries in the lesson
KEduVocWordType(const QString &name, KEduVocWordType *parent=nullptr)
default constructor
QList< KEduVocExpression * > entries(EnumEntriesRecursive recursive=NotRecursive) override
get a list of all entries in the lesson
~KEduVocWordType() override
destructor
void setWordType(KEduVocWordFlags flags)
assignment operator
KEduVocTranslation * translation(int row)
The word type class does keep track of individual translations, because for one entry,...
KEduVocWordFlags wordType() const
Return the raw WordTypeFlags.
KEduVocWordType * childOfType(KEduVocWordFlags flags)
Return a child class (or this class) that is of the specified type.
void append(QList< T > &&value)
qsizetype count() const const
qsizetype indexOf(const AT &value, qsizetype from) const const
void removeAt(qsizetype i)
T value(qsizetype i) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 17 2024 11:55:29 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.