File indexing completed on 2022-10-04 13:56:35

0001 /*
0002  * SPDX-FileCopyrightText: 2007 Jeremy Whiting <jpwhiting@kde.org>
0003  * SPDX-FileCopyrightText: 2007 Frederik Gladhorn <frederik.gladhorn@kdemail.net>
0004  * SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "keduvoclesson.h"
0008 
0009 #include "keduvocexpression.h"
0010 
0011 #include <QList>
0012 
0013 /** private class to store information about a lesson */
0014 class KEduVocLesson::Private
0015 {
0016 public:
0017     // entries
0018     QList<KEduVocExpression*> m_entries;
0019 };
0020 
0021 
0022 KEduVocLesson::KEduVocLesson(const QString& name, KEduVocContainer *parent)
0023         : KEduVocContainer(name, Lesson, parent), d( new Private )
0024 {
0025 }
0026 
0027 // Private constructor only used by KEduVocDocument when creating the top level lesson.
0028 KEduVocLesson::KEduVocLesson(const QString& name, KEduVocDocument *document)
0029    : KEduVocContainer(name, Lesson, document)
0030    , d(new Private)
0031 {
0032 }
0033 
0034 
0035 KEduVocLesson::KEduVocLesson( const KEduVocLesson &other )
0036         : KEduVocContainer(other), d( new Private )
0037 {
0038     d->m_entries = other.d->m_entries;
0039 }
0040 
0041 
0042 KEduVocLesson::~KEduVocLesson()
0043 {
0044     qDeleteAll(d->m_entries);
0045     delete d;
0046 }
0047 
0048 
0049 
0050 QList<KEduVocExpression*> KEduVocLesson::entries(EnumEntriesRecursive recursive)
0051 {
0052     if (recursive == Recursive) {
0053         return entriesRecursive();
0054     }
0055     return d->m_entries;
0056 }
0057 
0058 int KEduVocLesson::entryCount(EnumEntriesRecursive recursive)
0059 {
0060     if (recursive == Recursive) {
0061         return entriesRecursive().count();
0062     }
0063     return d->m_entries.count();
0064 }
0065 
0066 void KEduVocLesson::appendEntry(KEduVocExpression* entry)
0067 {
0068     insertEntry(d->m_entries.size(), entry);
0069 }
0070 
0071 void KEduVocLesson::insertEntry(int index, KEduVocExpression * entry)
0072 {
0073     Q_ASSERT(entry);
0074     d->m_entries.insert( index, entry );
0075     entry->setLesson(this);
0076     invalidateChildLessonEntries();
0077 }
0078 
0079 void KEduVocLesson::removeEntry(KEduVocExpression* entry)
0080 {
0081     Q_ASSERT(entry);
0082     if (d->m_entries.indexOf(entry) == -1) {
0083         //attempting to remove entry from lesson that does not contain it!
0084         return;
0085     }
0086     d->m_entries.removeAt( d->m_entries.indexOf(entry) );
0087     invalidateChildLessonEntries();
0088 }
0089 
0090 KEduVocExpression * KEduVocLesson::entry(int row, EnumEntriesRecursive recursive)
0091 {
0092     if (recursive == Recursive) {
0093         return entriesRecursive().value(row);
0094     }
0095     return d->m_entries.value(row);
0096 }
0097 
0098