File indexing completed on 2024-09-08 03:33:29
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 KEduVocLesson::KEduVocLesson(const QString &name, KEduVocContainer *parent) 0022 : KEduVocContainer(name, Lesson, parent) 0023 , 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 KEduVocLesson::KEduVocLesson(const KEduVocLesson &other) 0035 : KEduVocContainer(other) 0036 , d(new Private) 0037 { 0038 d->m_entries = other.d->m_entries; 0039 } 0040 0041 KEduVocLesson::~KEduVocLesson() 0042 { 0043 qDeleteAll(d->m_entries); 0044 delete d; 0045 } 0046 0047 QList<KEduVocExpression *> KEduVocLesson::entries(EnumEntriesRecursive recursive) 0048 { 0049 if (recursive == Recursive) { 0050 return entriesRecursive(); 0051 } 0052 return d->m_entries; 0053 } 0054 0055 int KEduVocLesson::entryCount(EnumEntriesRecursive recursive) 0056 { 0057 if (recursive == Recursive) { 0058 return entriesRecursive().count(); 0059 } 0060 return d->m_entries.count(); 0061 } 0062 0063 void KEduVocLesson::appendEntry(KEduVocExpression *entry) 0064 { 0065 insertEntry(d->m_entries.size(), entry); 0066 } 0067 0068 void KEduVocLesson::insertEntry(int index, KEduVocExpression *entry) 0069 { 0070 Q_ASSERT(entry); 0071 d->m_entries.insert(index, entry); 0072 entry->setLesson(this); 0073 invalidateChildLessonEntries(); 0074 } 0075 0076 void KEduVocLesson::removeEntry(KEduVocExpression *entry) 0077 { 0078 Q_ASSERT(entry); 0079 if (d->m_entries.indexOf(entry) == -1) { 0080 // attempting to remove entry from lesson that does not contain it! 0081 return; 0082 } 0083 d->m_entries.removeAt(d->m_entries.indexOf(entry)); 0084 invalidateChildLessonEntries(); 0085 } 0086 0087 KEduVocExpression *KEduVocLesson::entry(int row, EnumEntriesRecursive recursive) 0088 { 0089 if (recursive == Recursive) { 0090 return entriesRecursive().value(row); 0091 } 0092 return d->m_entries.value(row); 0093 }