From: Frederik Gladhorn Date: Wed, 23 Jan 2008 20:28:25 +0000 (+0000) Subject: Fix missing copy constructor which resulted in a pointer being copied X-Git-Tag: v4.0.71~77 X-Git-Url: https://git.rmz.fi/?a=commitdiff_plain;h=31ff98902e0e14465199310f98e214174b008029;p=libqmvoc.git Fix missing copy constructor which resulted in a pointer being copied for child translations instead of values. BUG: 155310 Sorry Peter, you were right, my bad :) svn path=/trunk/KDE/kdeedu/libkdeedu/; revision=765304 --- diff --git a/keduvocdocument/keduvocexpression.cpp b/keduvocdocument/keduvocexpression.cpp index e7b0c04..e21395e 100644 --- a/keduvocdocument/keduvocexpression.cpp +++ b/keduvocdocument/keduvocexpression.cpp @@ -4,6 +4,7 @@ copyright : (C) 1999-2001 Ewald Arnold (C) 2005-2007 Peter Hedlund + Copyright 2008 Frederik Gladhorn ***************************************************************************/ /*************************************************************************** @@ -24,16 +25,15 @@ class KEduVocExpression::KEduVocExpressionPrivate { public: - KEduVocExpressionPrivate( KEduVocExpression* qq ) - : q( qq ) + KEduVocExpressionPrivate() { m_active = true; } ~KEduVocExpressionPrivate(); - bool operator== ( const KEduVocExpressionPrivate &p ) const; + KEduVocExpressionPrivate(const KEduVocExpressionPrivate &other); - KEduVocExpression* q; + bool operator== ( const KEduVocExpressionPrivate &p ) const; QList m_lessons; bool m_active; @@ -42,12 +42,23 @@ public: }; -KEduVocExpression::KEduVocExpressionPrivate::~ KEduVocExpressionPrivate() +KEduVocExpression::KEduVocExpressionPrivate::~KEduVocExpressionPrivate() { qDeleteAll(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)); + } +} + + bool KEduVocExpression::KEduVocExpressionPrivate::operator== ( const KEduVocExpression::KEduVocExpressionPrivate &p ) const { return @@ -58,17 +69,17 @@ bool KEduVocExpression::KEduVocExpressionPrivate::operator== ( const KEduVocExpr KEduVocExpression::KEduVocExpression() - : d( new KEduVocExpressionPrivate( this ) ) + : d( new KEduVocExpressionPrivate ) {} KEduVocExpression::KEduVocExpression( const QString & expression ) - : d( new KEduVocExpressionPrivate( this ) ) + : d( new KEduVocExpressionPrivate ) { setTranslation( 0, expression.simplified() ); } KEduVocExpression::KEduVocExpression( const QStringList & translations) - : d( new KEduVocExpressionPrivate( this ) ) + : d( new KEduVocExpressionPrivate ) { foreach ( const QString &translation, translations ) { setTranslation(d->m_translations.count(), translation); @@ -76,12 +87,16 @@ KEduVocExpression::KEduVocExpression( const QStringList & translations) } +KEduVocExpression::KEduVocExpression(const KEduVocExpression & other) + : d(new KEduVocExpressionPrivate(*other.d)) +{} + + KEduVocExpression::~KEduVocExpression() { -///@todo probably infinite loop when a parent lesson decides to delete it :) -// foreach(KEduVocLesson * lesson, d->m_lessons) { -// lesson->removeEntry(this); -// } + foreach(KEduVocLesson * lesson, d->m_lessons) { + lesson->removeEntry(this); + } delete d; } @@ -178,3 +193,4 @@ void KEduVocExpression::removeLesson(KEduVocLesson * l) } + diff --git a/keduvocdocument/keduvocexpression.h b/keduvocdocument/keduvocexpression.h index 56762d3..13c0f4a 100644 --- a/keduvocdocument/keduvocexpression.h +++ b/keduvocdocument/keduvocexpression.h @@ -4,6 +4,7 @@ copyright : (C) 1999-2001 Ewald Arnold (C) 2005-2007 Peter Hedlund + Copyright 2008 Frederik Gladhorn ***************************************************************************/ /*************************************************************************** @@ -56,6 +57,8 @@ public: */ explicit KEduVocExpression( const QStringList & translations ); + KEduVocExpression(const KEduVocExpression& other); + ~KEduVocExpression(); /** returns index of lesson (-1 = none) diff --git a/keduvocdocument/keduvoctranslation.cpp b/keduvocdocument/keduvoctranslation.cpp index 7f11ecd..7c93bd2 100644 --- a/keduvocdocument/keduvoctranslation.cpp +++ b/keduvocdocument/keduvoctranslation.cpp @@ -1,7 +1,8 @@ /*************************************************************************** Vocabulary Expression Translation for KDE Edu ----------------------------------------------------------------------- - copyright :(C) 2007 Frederik Gladhorn + + Copyright 2007-2008 Frederik Gladhorn ***************************************************************************/ /*************************************************************************** @@ -29,6 +30,8 @@ class KEduVocTranslation::KEduVocTranslationPrivate public: KEduVocTranslationPrivate(KEduVocExpression* parent); + ~KEduVocTranslationPrivate(); + KEduVocExpression* m_entry; /// This is the word itself. The vocabulary. This is what it is all about. @@ -61,6 +64,7 @@ public: /// Conjugations of a word (I go, you go, he goes... boring in english) QMap m_conjugations; + /// The comparison forms of adjectives and adverbs: (fast), faster, fastest QString m_comparative; QString m_superlative; @@ -86,6 +90,12 @@ KEduVocTranslation::KEduVocTranslationPrivate::KEduVocTranslationPrivate(KEduVoc m_declination = 0; } + +KEduVocTranslation::KEduVocTranslationPrivate::~ KEduVocTranslationPrivate() +{ + delete m_declination; +} + KEduVocTranslation::KEduVocTranslation(KEduVocExpression* entry) : d( new KEduVocTranslationPrivate(entry) ) {} @@ -113,6 +123,7 @@ KEduVocTranslation::KEduVocTranslation( const KEduVocTranslation &other ) : d( n d->m_falseFriends = other.d->m_falseFriends; d->m_imageUrl = other.d->m_imageUrl; d->m_soundUrl = other.d->m_soundUrl; + /// @todo add declinations } KEduVocTranslation::~KEduVocTranslation() @@ -375,3 +386,4 @@ void KEduVocTranslation::setSuperlative(const QString & superlative) d->m_superlative = superlative; } + diff --git a/keduvocdocument/keduvoctranslation.h b/keduvocdocument/keduvoctranslation.h index b41e8a9..425c63a 100644 --- a/keduvocdocument/keduvoctranslation.h +++ b/keduvocdocument/keduvoctranslation.h @@ -1,7 +1,7 @@ /*************************************************************************** Vocabulary Expression Translation for KDE Edu ----------------------------------------------------------------------- - copyright :(C) 2007 Frederik Gladhorn + Copyright 2007-2008 Frederik Gladhorn ***************************************************************************/ /***************************************************************************