]> Git trees. - libqmvoc.git/commitdiff
Implement copy, cut and paste.
authorFrederik Gladhorn <gladhorn@kde.org>
Sat, 17 May 2008 11:43:46 +0000 (11:43 +0000)
committerFrederik Gladhorn <gladhorn@kde.org>
Sat, 17 May 2008 11:43:46 +0000 (11:43 +0000)
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

keduvocdocument/keduvocexpression.cpp
keduvocdocument/keduvocexpression.h
keduvocdocument/keduvoclesson.cpp
keduvocdocument/keduvoctranslation.cpp
keduvocdocument/keduvoctranslation.h

index 37f9f075eb1b28754f2738eb63bb731dae74484f..466c0b9711db304f765f404d239a275a0efafc36 100644 (file)
@@ -43,29 +43,22 @@ public:
     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;
 }
 
@@ -100,18 +93,28 @@ KEduVocExpression::KEduVocExpression( const QStringList & translations)
 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;
 }
 
@@ -173,14 +176,6 @@ void KEduVocExpression::resetGrades( int index )
     }
 }
 
-
-KEduVocExpression& KEduVocExpression::operator= ( const KEduVocExpression &expression )
-{
-    *d = *expression.d;
-    return *this;
-}
-
-
 bool KEduVocExpression::operator== ( const KEduVocExpression &expression ) const
 {
     return ( *d == *expression.d );
@@ -195,6 +190,14 @@ KEduVocTranslation* KEduVocExpression::translation( int index )
     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();
index 4369bb8bce5da65dedf9c48bf5acd15d3ff1aeb8..373033aaafa59e82b4a1cb391cc6471578cd316e 100644 (file)
@@ -102,6 +102,7 @@ public:
      * @return the translation
      */
     KEduVocTranslation* translation( int index );
+    KEduVocTranslation* translation( int index ) const;
 
     QList<int> translationIndices() const;
 
index 77e2ffeeccc15e9b5c2709e0d0d7b3714e96192a..2e525c14f3198746a837603f23cb8ba3efde28c3 100644 (file)
@@ -19,6 +19,7 @@
 #include "keduvocexpression.h"
 
 #include <KRandomSequence>
+#include <KDebug>
 #include <QList>
 
 /** private class to store information about a lesson */
@@ -81,6 +82,10 @@ void KEduVocLesson::insertEntry(int index, KEduVocExpression * entry)
 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();
 }
index 6cc4ff7eeb4847f911f50bc49bfc9920a9c376d3..f219a6e9162d46222485c2a04a1923bdd354d541 100644 (file)
@@ -97,9 +97,12 @@ KEduVocTranslation::KEduVocTranslation(KEduVocExpression* entry, const QString &
 
 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;
@@ -110,9 +113,10 @@ KEduVocTranslation::KEduVocTranslation( const KEduVocTranslation &other )
     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);
     }
@@ -439,3 +443,8 @@ void KEduVocTranslation::fromKVTML2(QDomElement & parent)
     ///@todo false friends
 }
 
+void KEduVocTranslation::setEntry(KEduVocExpression * entry)
+{
+    d->m_entry = entry;
+}
+
index ddaab1ed7880b9c25cf233187558fefe7c490d6b..f44c692835c3dc0979cf4d61e37ef8f4a775b4c6 100644 (file)
@@ -53,7 +53,7 @@ public:
         */
     KEduVocTranslation(KEduVocExpression* entry, const QString &translation );
 
-    /** copy constructor for d-pointer safet */
+    /** copy constructor for d-pointer safety */
     KEduVocTranslation( const KEduVocTranslation &other );
 
     /**
@@ -278,6 +278,10 @@ public:
 private:
     class KEduVocTranslationPrivate;
     KEduVocTranslationPrivate* const d;
+
+    // for the copy constructor
+    void setEntry(KEduVocExpression* entry);
+    friend class KEduVocExpression;
 };
 
 #endif