LibKEduVocDocument

keduvocleitnerbox.cpp
1/*
2 * SPDX-FileCopyrightText: 2008 Frederik Gladhorn <frederik.gladhorn@kdemail.net>
3 * SPDX-License-Identifier: GPL-2.0-or-later
4 */
5#include "keduvocleitnerbox.h"
6
7#include "keduvocexpression.h"
8
9#include <QSet>
10
11class KEduVocLeitnerBox::Private
12{
13public:
14 // cache the entries
15 QList<KEduVocExpression *> m_expressions;
16 // list of translations
17 QList<KEduVocTranslation *> m_translations;
18};
19
21 : KEduVocContainer(name, Leitner, parent)
22 , d(new Private)
23{
24 // only one top level and children, this is only a list
25 Q_ASSERT(!parent || !parent->parent());
26}
27
29{
30 foreach (KEduVocTranslation *translation, d->m_translations) {
31 translation->setLeitnerBox(nullptr);
32 }
33 delete d;
34}
35
37{
38 Q_UNUSED(recursive)
39 return d->m_expressions;
40}
41
42int KEduVocLeitnerBox::entryCount(EnumEntriesRecursive recursive)
43{
44 Q_UNUSED(recursive)
45 return d->m_expressions.count();
46}
47
48void KEduVocLeitnerBox::addTranslation(KEduVocTranslation *translation)
49{
50 // add to expression - if not already there because another translation of the same word is there.
51 bool found = false;
52 foreach (int i, translation->entry()->translationIndices()) {
53 if (translation->entry()->translation(i)->leitnerBox() == this) {
54 found = true;
55 break;
56 }
57 }
58 if (!found) {
59 d->m_expressions.append(translation->entry());
60 }
61 d->m_translations.append(translation);
63}
64
65void KEduVocLeitnerBox::removeTranslation(KEduVocTranslation *translation)
66{
67 int index = d->m_translations.indexOf(translation);
68 d->m_translations.removeAt(index);
69
70 // no lesson found - this entry is being deleted. remove all its siblings.
71 if (!translation->entry()->lesson()) {
72 int index = d->m_expressions.indexOf(translation->entry());
73 if (index != -1) {
74 d->m_expressions.removeAt(index);
75 }
76 }
77
78 // remove from cache
79 bool found = false;
80 foreach (int i, translation->entry()->translationIndices()) {
81 if (translation->entry()->translation(i)->leitnerBox() == this) {
82 found = true;
83 break;
84 }
85 }
86 if (!found) {
87 d->m_expressions.removeAt(d->m_expressions.indexOf(translation->entry()));
88 }
89
91}
92
94{
95 return d->m_translations.value(row);
96}
97
98KEduVocExpression *KEduVocLeitnerBox::entry(int row, EnumEntriesRecursive recursive)
99{
100 Q_UNUSED(recursive)
101 return entries().value(row);
102}
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.
Leitner Boxes are an alternative grading system.
QList< KEduVocExpression * > entries(EnumEntriesRecursive recursive=NotRecursive) override
get a list of all entries in the box
int entryCount(EnumEntriesRecursive recursive=NotRecursive) override
get the number of entries in the lesson
KEduVocTranslation * translation(int row)
The leitner box class keeps track of individual translations, because for one entry,...
KEduVocLeitnerBox(const QString &name, KEduVocLeitnerBox *parent=nullptr)
default constructor
~KEduVocLeitnerBox() override
destructor
void setLeitnerBox(KEduVocLeitnerBox *leitnerBox)
Sets the leitner box of this translation.
KEduVocLeitnerBox * leitnerBox() const
Returns the leitner box of this translation.
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 Dec 27 2024 11:48:25 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.