libkdeedu/keduvocdocument
keduvocexpression.cpp
Go to the documentation of this file.00001 /*************************************************************************** 00002 Vocabulary Expression for KDE Edu 00003 ----------------------------------------------------------------------- 00004 copyright : (C) 1999-2001 Ewald Arnold <kvoctrain@ewald-arnold.de> 00005 00006 (C) 2005-2007 Peter Hedlund <peter.hedlund@kdemail.net> 00007 Copyright 2008 Frederik Gladhorn <frederik.gladhorn@kdemail.net> 00008 ***************************************************************************/ 00009 00010 /*************************************************************************** 00011 * * 00012 * This program is free software; you can redistribute it and/or modify * 00013 * it under the terms of the GNU General Public License as published by * 00014 * the Free Software Foundation; either version 2 of the License, or * 00015 * (at your option) any later version. * 00016 * * 00017 ***************************************************************************/ 00018 00019 00020 #include "keduvocexpression.h" 00021 00022 #include <KDebug> 00023 00024 00025 class KEduVocExpression::KEduVocExpressionPrivate 00026 { 00027 public: 00028 KEduVocExpressionPrivate() 00029 { 00030 m_active = true; 00031 m_lesson = 0; 00032 } 00033 ~KEduVocExpressionPrivate(); 00034 00035 KEduVocExpressionPrivate(const KEduVocExpressionPrivate &other); 00036 KEduVocExpressionPrivate& operator= (const KEduVocExpressionPrivate &other); 00037 00038 bool operator== ( const KEduVocExpressionPrivate &p ) const; 00039 00040 KEduVocLesson* m_lesson; 00041 bool m_active; 00042 00043 QMap <int, KEduVocTranslation*> m_translations; 00044 }; 00045 00046 KEduVocExpression::KEduVocExpressionPrivate::~KEduVocExpressionPrivate() 00047 { 00048 qDeleteAll(m_translations); 00049 } 00050 00051 KEduVocExpression::KEduVocExpressionPrivate::KEduVocExpressionPrivate(const KEduVocExpressionPrivate & other) 00052 { 00053 m_active = other.m_active; 00054 m_lesson = 0; 00055 } 00056 00057 KEduVocExpression::KEduVocExpressionPrivate & KEduVocExpression::KEduVocExpressionPrivate::operator =(const KEduVocExpressionPrivate & other) 00058 { 00059 m_active = other.m_active; 00060 m_lesson = 0; 00061 00062 return *this; 00063 } 00064 00065 bool KEduVocExpression::KEduVocExpressionPrivate::operator== ( const KEduVocExpression::KEduVocExpressionPrivate &p ) const 00066 { 00067 return 00068 m_translations == p.m_translations && 00069 m_lesson == p.m_lesson && 00070 m_active == p.m_active; 00071 } 00072 00073 00074 KEduVocExpression::KEduVocExpression() 00075 : d( new KEduVocExpressionPrivate ) 00076 {} 00077 00078 KEduVocExpression::KEduVocExpression( const QString & expression ) 00079 : d( new KEduVocExpressionPrivate ) 00080 { 00081 setTranslation( 0, expression.simplified() ); 00082 } 00083 00084 KEduVocExpression::KEduVocExpression( const QStringList & translations) 00085 : d( new KEduVocExpressionPrivate ) 00086 { 00087 foreach ( const QString &translation, translations ) { 00088 setTranslation(d->m_translations.count(), translation); 00089 } 00090 } 00091 00092 00093 KEduVocExpression::KEduVocExpression(const KEduVocExpression & other) 00094 : d(new KEduVocExpressionPrivate(*other.d)) 00095 { 00096 foreach (int key, other.d->m_translations.keys()) { 00097 d->m_translations[key] = new KEduVocTranslation(*other.d->m_translations.value(key)); 00098 d->m_translations[key]->setEntry(this); 00099 } 00100 } 00101 00102 KEduVocExpression& KEduVocExpression::operator= ( const KEduVocExpression &other ) 00103 { 00104 *d = *other.d; 00105 foreach (int key, other.d->m_translations.keys()) { 00106 d->m_translations[key] = new KEduVocTranslation(*other.d->m_translations.value(key)); 00107 d->m_translations[key]->setEntry(this); 00108 } 00109 return *this; 00110 } 00111 00112 KEduVocExpression::~KEduVocExpression() 00113 { 00114 setLesson(0); 00115 delete d; 00116 } 00117 00118 void KEduVocExpression::removeTranslation( int index ) 00119 { 00120 int count = d->m_translations.count(); 00121 00122 // remove the index we delete 00123 delete d->m_translations.take(index); 00124 00125 // shift all other indexes, +1 for the deleted 00126 for (int j = index; j < count-1; j++) { 00127 d->m_translations[j] = d->m_translations.take(j+1); 00128 } 00129 } 00130 00131 00132 void KEduVocExpression::setTranslation( int index, const QString & expr ) 00133 { 00134 if ( index < 0 ) { 00135 return; 00136 } 00137 00138 if (!d->m_translations.contains(index)) { 00139 d->m_translations[index] = new KEduVocTranslation(this); 00140 } 00141 d->m_translations[index]->setText(expr.simplified()); 00142 } 00143 00144 00145 KEduVocLesson* KEduVocExpression::lesson() const 00146 { 00147 return d->m_lesson; 00148 } 00149 00150 00151 bool KEduVocExpression::isActive() const 00152 { 00153 return d->m_active; 00154 } 00155 00156 00157 void KEduVocExpression::setActive( bool flag ) 00158 { 00159 d->m_active = flag; 00160 } 00161 00162 00163 void KEduVocExpression::resetGrades( int index ) 00164 { 00165 if ( index == -1 ) { // clear grades for all languages 00166 foreach( KEduVocTranslation* trans, d->m_translations ) { 00167 trans->resetGrades(); 00168 } 00169 return; 00170 } 00171 00172 // only language index 00173 if ( d->m_translations.contains( index ) ) { 00174 d->m_translations[index]->resetGrades(); 00175 } 00176 } 00177 00178 bool KEduVocExpression::operator== ( const KEduVocExpression &expression ) const 00179 { 00180 return ( *d == *expression.d ); 00181 } 00182 00183 KEduVocTranslation* KEduVocExpression::translation( int index ) 00184 { 00185 if(translationIndices().contains(index)) { 00186 return d->m_translations[index]; 00187 } 00188 d->m_translations[index] = new KEduVocTranslation(this); 00189 return d->m_translations[index]; 00190 } 00191 00192 KEduVocTranslation * KEduVocExpression::translation(int index) const 00193 { 00194 if(d->m_translations.contains(index)) { 00195 return 0; 00196 } 00197 return d->m_translations[index]; 00198 } 00199 00200 QList< int > KEduVocExpression::translationIndices() const 00201 { 00202 return d->m_translations.keys(); 00203 } 00204 00205 void KEduVocExpression::setLesson(KEduVocLesson * l) 00206 { 00207 if (d->m_lesson) { 00208 d->m_lesson->removeEntry(this); 00209 } 00210 d->m_lesson = l; 00211 } 00212 00213
KDE 4.2 API Reference