KEduVocExpressionPrivate()
{
m_active = true;
+ m_lesson = 0;
}
~KEduVocExpressionPrivate();
bool operator== ( const KEduVocExpressionPrivate &p ) const;
- QList<KEduVocLesson*> m_lessons;
+ KEduVocLesson* m_lesson;
bool m_active;
QMap <int, KEduVocTranslation*> m_translations;
KEduVocExpression::KEduVocExpressionPrivate::KEduVocExpressionPrivate(const KEduVocExpressionPrivate & other)
{
m_active = other.m_active;
- m_lessons = other.m_lessons;
foreach (int key, other.m_translations.keys()) {
m_translations[key] = new KEduVocTranslation(*other.m_translations.value(key));
{
return
m_translations == p.m_translations &&
- m_lessons == p.m_lessons &&
+ m_lesson == p.m_lesson &&
m_active == p.m_active;
}
KEduVocExpression::KEduVocExpression(const KEduVocExpression & other)
: d(new KEduVocExpressionPrivate(*other.d))
-{}
+{
+ if (other.lesson()) {
+ other.lesson()->appendEntry(this);
+ }
+}
KEduVocExpression::~KEduVocExpression()
{
- foreach(KEduVocLesson * lesson, d->m_lessons) {
- lesson->removeEntry(this);
- }
+ d->m_lesson->removeEntry(this);
delete d;
}
}
-QList<KEduVocLesson*> KEduVocExpression::lessons() const
+KEduVocLesson* KEduVocExpression::lesson() const
{
- return d->m_lessons;
+ return d->m_lesson;
}
return d->m_translations.keys();
}
-void KEduVocExpression::addLesson(KEduVocLesson * l)
+void KEduVocExpression::setLesson(KEduVocLesson * l)
{
- d->m_lessons.append(l);
-}
-
-void KEduVocExpression::removeLesson(KEduVocLesson * l)
-{
- d->m_lessons.removeAt(d->m_lessons.indexOf(l));
+ if (d->m_lesson) {
+ d->m_lesson->removeEntry(this);
+ }
+ d->m_lesson = l;
}
-
-
~KEduVocExpression();
- /** returns index of lesson (-1 = none)
+ /** return the lesson
*/
- QList<KEduVocLesson *> lessons() const;
+ KEduVocLesson * lesson() const;
/** reset all grades of the entry
/** only called by lesson to add itself to the lesson list
*/
- void addLesson( KEduVocLesson * l );
- void removeLesson( KEduVocLesson * l );
+ void setLesson( KEduVocLesson * l );
friend class KEduVocLesson;
};
KEduVocLesson::~KEduVocLesson()
{
- foreach (KEduVocExpression* entry, d->m_entries) {
- entry->removeLesson(this);
- if (entry->lessons().count() == 0) {
- delete entry;
- }
- }
+ qDeleteAll(d->m_entries);
delete d;
}
{
Q_ASSERT(entry);
d->m_entries.append( entry );
- entry->addLesson(this);
+ entry->setLesson(this);
invalidateChildLessonEntries();
}
void KEduVocLesson::insertEntry(int index, KEduVocExpression * entry)
{
d->m_entries.insert( index, entry );
- entry->addLesson(this);
+ entry->setLesson(this);
invalidateChildLessonEntries();
}
{
if (entry) {
d->m_entries.removeAt( d->m_entries.indexOf(entry) );
- entry->removeLesson(this);
+ entry->setLesson(0);
invalidateChildLessonEntries();
}
}