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 "keduvoclesson.h"
8
9 #include "keduvocexpression.h"
10
11 #include <QList>
12
13 /** private class to store information about a lesson */
14 class KEduVocLesson::Private
15 {
16 public:
17 // entries
18 QList<KEduVocExpression*> m_entries;
19 };
20
21
KEduVocLesson(const QString & name,KEduVocContainer * parent)22 KEduVocLesson::KEduVocLesson(const QString& name, KEduVocContainer *parent)
23 : KEduVocContainer(name, Lesson, parent), d( new Private )
24 {
25 }
26
27 // Private constructor only used by KEduVocDocument when creating the top level lesson.
KEduVocLesson(const QString & name,KEduVocDocument * document)28 KEduVocLesson::KEduVocLesson(const QString& name, KEduVocDocument *document)
29 : KEduVocContainer(name, Lesson, document)
30 , d(new Private)
31 {
32 }
33
34
KEduVocLesson(const KEduVocLesson & other)35 KEduVocLesson::KEduVocLesson( const KEduVocLesson &other )
36 : KEduVocContainer(other), d( new Private )
37 {
38 d->m_entries = other.d->m_entries;
39 }
40
41
~KEduVocLesson()42 KEduVocLesson::~KEduVocLesson()
43 {
44 qDeleteAll(d->m_entries);
45 delete d;
46 }
47
48
49
entries(EnumEntriesRecursive recursive)50 QList<KEduVocExpression*> KEduVocLesson::entries(EnumEntriesRecursive recursive)
51 {
52 if (recursive == Recursive) {
53 return entriesRecursive();
54 }
55 return d->m_entries;
56 }
57
entryCount(EnumEntriesRecursive recursive)58 int KEduVocLesson::entryCount(EnumEntriesRecursive recursive)
59 {
60 if (recursive == Recursive) {
61 return entriesRecursive().count();
62 }
63 return d->m_entries.count();
64 }
65
appendEntry(KEduVocExpression * entry)66 void KEduVocLesson::appendEntry(KEduVocExpression* entry)
67 {
68 insertEntry(d->m_entries.size(), entry);
69 }
70
insertEntry(int index,KEduVocExpression * entry)71 void KEduVocLesson::insertEntry(int index, KEduVocExpression * entry)
72 {
73 Q_ASSERT(entry);
74 d->m_entries.insert( index, entry );
75 entry->setLesson(this);
76 invalidateChildLessonEntries();
77 }
78
removeEntry(KEduVocExpression * entry)79 void KEduVocLesson::removeEntry(KEduVocExpression* entry)
80 {
81 Q_ASSERT(entry);
82 if (d->m_entries.indexOf(entry) == -1) {
83 //attempting to remove entry from lesson that does not contain it!
84 return;
85 }
86 d->m_entries.removeAt( d->m_entries.indexOf(entry) );
87 invalidateChildLessonEntries();
88 }
89
entry(int row,EnumEntriesRecursive recursive)90 KEduVocExpression * KEduVocLesson::entry(int row, EnumEntriesRecursive recursive)
91 {
92 if (recursive == Recursive) {
93 return entriesRecursive().value(row);
94 }
95 return d->m_entries.value(row);
96 }
97
98
99