Vocabulary is now copied including grades, conjugations etc.
Not copied are synonym, antonym and false friend.
Some cleanup of the copy constructors of expression/translation to get copies right.
Fix deletion of entries.
Testing appreciated :)
CCMAIL: parley-devel@kde.org
svn path=/trunk/KDE/kdeedu/libkdeedu/; revision=808703
QMap <int, KEduVocTranslation*> m_translations;
};
-
KEduVocExpression::KEduVocExpressionPrivate::~KEduVocExpressionPrivate()
{
qDeleteAll(m_translations);
}
-
KEduVocExpression::KEduVocExpressionPrivate::KEduVocExpressionPrivate(const KEduVocExpressionPrivate & other)
{
m_active = other.m_active;
-
- foreach (int key, other.m_translations.keys()) {
- m_translations[key] = new KEduVocTranslation(*other.m_translations.value(key));
- }
+ m_lesson = 0;
}
KEduVocExpression::KEduVocExpressionPrivate & KEduVocExpression::KEduVocExpressionPrivate::operator =(const KEduVocExpressionPrivate & other)
{
m_active = other.m_active;
+ m_lesson = 0;
- foreach (int key, other.m_translations.keys()) {
- m_translations[key] = new KEduVocTranslation(*other.m_translations.value(key));
- }
return *this;
}
KEduVocExpression::KEduVocExpression(const KEduVocExpression & other)
: d(new KEduVocExpressionPrivate(*other.d))
{
- d->m_lesson = 0;
- if (other.lesson()) {
- other.lesson()->appendEntry(this);
+ kDebug() << "Expression copy constructor";
+ foreach (int key, other.d->m_translations.keys()) {
+ d->m_translations[key] = new KEduVocTranslation(*other.d->m_translations.value(key));
+ kDebug() << "copy translation: " << other.d->m_translations.value(key)->text();
+ d->m_translations[key]->setEntry(this);
}
}
+KEduVocExpression& KEduVocExpression::operator= ( const KEduVocExpression &other )
+{
+ *d = *other.d;
+ foreach (int key, other.d->m_translations.keys()) {
+ d->m_translations[key] = new KEduVocTranslation(*other.d->m_translations.value(key));
+ kDebug() << "copy translation: " << other.d->m_translations.value(key)->text();
+ d->m_translations[key]->setEntry(this);
+ }
+ return *this;
+}
KEduVocExpression::~KEduVocExpression()
{
- if (d->m_lesson) {
- d->m_lesson->removeEntry(this);
- }
+ setLesson(0);
delete d;
}
}
}
-
-KEduVocExpression& KEduVocExpression::operator= ( const KEduVocExpression &expression )
-{
- *d = *expression.d;
- return *this;
-}
-
-
bool KEduVocExpression::operator== ( const KEduVocExpression &expression ) const
{
return ( *d == *expression.d );
return d->m_translations[index];
}
+KEduVocTranslation * KEduVocExpression::translation(int index) const
+{
+ if(d->m_translations.contains(index)) {
+ return 0;
+ }
+ return d->m_translations[index];
+}
+
QList< int > KEduVocExpression::translationIndices() const
{
return d->m_translations.keys();
* @return the translation
*/
KEduVocTranslation* translation( int index );
+ KEduVocTranslation* translation( int index ) const;
QList<int> translationIndices() const;
#include "keduvocexpression.h"
#include <KRandomSequence>
+#include <KDebug>
#include <QList>
/** private class to store information about a lesson */
void KEduVocLesson::removeEntry(KEduVocExpression* entry)
{
Q_ASSERT(entry);
+ if (d->m_entries.indexOf(entry) == -1) {
+ kDebug() << "attempting to remove entry from lesson that does not contain it!";
+ return;
+ }
d->m_entries.removeAt( d->m_entries.indexOf(entry) );
invalidateChildLessonEntries();
}
KEduVocTranslation::KEduVocTranslation( const KEduVocTranslation &other )
: KEduVocText(other),
- d( new KEduVocTranslationPrivate(other.d->m_entry) )
+ // set the entry to 0, the translation will be put into a copied entry by the expression copy constructor
+ d( new KEduVocTranslationPrivate(0) )
{
- d->m_wordType = other.d->m_wordType;
+ // beter no word type copy as this is pointer copying
+ // will not work as this is not added to the word type container!
+// d->m_wordType = other.d->m_wordType;
d->m_comment = other.d->m_comment;
d->m_paraphrase = other.d->m_paraphrase;
d->m_example = other.d->m_example;
d->m_multipleChoice = other.d->m_multipleChoice;
d->m_imageUrl = other.d->m_imageUrl;
d->m_soundUrl = other.d->m_soundUrl;
- d->m_synonyms = other.d->m_synonyms;
- d->m_antonyms = other.d->m_antonyms;
- d->m_falseFriends = other.d->m_falseFriends;
+// no copies of the following for now. we don't know enough to also add this as synonym/etc
+// d->m_synonyms = other.d->m_synonyms;
+// d->m_antonyms = other.d->m_antonyms;
+// d->m_falseFriends = other.d->m_falseFriends;
if (other.d->m_declension) {
d->m_declension = new KEduVocDeclension(*other.d->m_declension);
}
///@todo false friends
}
+void KEduVocTranslation::setEntry(KEduVocExpression * entry)
+{
+ d->m_entry = entry;
+}
+
*/
KEduVocTranslation(KEduVocExpression* entry, const QString &translation );
- /** copy constructor for d-pointer safet */
+ /** copy constructor for d-pointer safety */
KEduVocTranslation( const KEduVocTranslation &other );
/**
private:
class KEduVocTranslationPrivate;
KEduVocTranslationPrivate* const d;
+
+ // for the copy constructor
+ void setEntry(KEduVocExpression* entry);
+ friend class KEduVocExpression;
};
#endif