Too bad, I didn't have the idea long ago.
Much simpler:
one grade for each word, no longer the fromTranslation.
So whenever the user gets abc right, abc gets it's grade increased.
Translation inherits from the new Text class.
The new class KEduVocText will be used instead of QString in many places
to for ex allow grades for individual conjugation forms etc.
Add initial unittests for translation class.
svn path=/trunk/KDE/kdeedu/libkdeedu/; revision=770972
class KEduVocConjugation::Private
{
public:
- KEduVocGrade m_grade;
QMap<int, QString> m_conjugations;
};
KEduVocConjugation::KEduVocConjugation( const KEduVocConjugation& other )
: d( new Private )
{
- d->m_grade = other.d->m_grade;
d->m_conjugations = other.d->m_conjugations;
}
KEduVocConjugation& KEduVocConjugation::operator = ( const KEduVocConjugation& other )
{
- d->m_grade = other.d->m_grade;
d->m_conjugations = other.d->m_conjugations;
return *this;
}
bool KEduVocConjugation::operator ==(const KEduVocConjugation& other) const
{
- return d->m_conjugations == other.d->m_conjugations &&
- d->m_grade == other.d->m_grade;
+ return d->m_conjugations == other.d->m_conjugations;
}
return d->m_conjugations.count() == 0;
}
-
-KEduVocGrade & KEduVocConjugation::grade()
-{
- return d->m_grade;
-}
-
QList< int > KEduVocConjugation::keys()
{
return d->m_conjugations.keys();
bool isEmpty();
- KEduVocGrade &grade();
-
static int indexOf(ConjugationPerson person, ConjugationNumber number);
private:
#include "keduvocgrade.h"
-class KEduVocGrade::KEduVocGradePrivate
+class KEduVocText::KEduVocTextPrivate
{
public:
+ /// This is the word itself. The vocabulary. This is what it is all about.
+ QString m_text;
+
grade_t m_grade;
count_t m_totalPracticeCount;
count_t m_badCount;
QDateTime m_practiceDate;
};
-KEduVocGrade::KEduVocGrade()
- :d( new KEduVocGradePrivate )
+KEduVocText::KEduVocText(const QString& text)
+ :d( new KEduVocTextPrivate )
{
+ d->m_text = text;
resetGrades();
}
-KEduVocGrade::KEduVocGrade( const KEduVocGrade &other )
- :d( new KEduVocGradePrivate )
+KEduVocText::KEduVocText( const KEduVocText &other )
+ :d( new KEduVocTextPrivate )
{
+ d->m_text = other.d->m_text;
setGrade( other.grade() );
setPracticeCount( other.practiceCount() );
setBadCount( other.badCount() );
setPracticeDate( other.practiceDate() );
}
-KEduVocGrade::~KEduVocGrade()
+KEduVocText::~KEduVocText()
{
delete d;
}
-void KEduVocGrade::resetGrades()
+QString KEduVocText::text() const
+{
+ return d->m_text;
+}
+
+void KEduVocText::setText( const QString & expr )
+{
+ d->m_text = expr.simplified();
+}
+
+void KEduVocText::resetGrades()
{
d->m_grade = KV_NORM_GRADE;
d->m_totalPracticeCount = 0;
}
-grade_t KEduVocGrade::grade() const
+grade_t KEduVocText::grade() const
{
return d->m_grade;
}
-void KEduVocGrade::setGrade( grade_t grade )
+void KEduVocText::setGrade( grade_t grade )
{
if ( grade > KV_MAX_GRADE ) {
grade = KV_MAX_GRADE;
}
-void KEduVocGrade::incGrade()
+void KEduVocText::incGrade()
{
setGrade( grade() + 1 );
}
-void KEduVocGrade::decGrade()
+void KEduVocText::decGrade()
{
if ( grade() == KV_MIN_GRADE ) {
return;
}
-count_t KEduVocGrade::practiceCount() const
+count_t KEduVocText::practiceCount() const
{
return d->m_totalPracticeCount;
}
-void KEduVocGrade::incPracticeCount()
+void KEduVocText::incPracticeCount()
{
setPracticeCount( practiceCount() + 1 );
}
-void KEduVocGrade::incBadCount()
+void KEduVocText::incBadCount()
{
setBadCount( badCount() + 1 );
}
-void KEduVocGrade::setPracticeCount( count_t count )
+void KEduVocText::setPracticeCount( count_t count )
{
d->m_totalPracticeCount = count;
}
-count_t KEduVocGrade::badCount() const
+count_t KEduVocText::badCount() const
{
return d->m_badCount;
}
-void KEduVocGrade::setBadCount( count_t count )
+void KEduVocText::setBadCount( count_t count )
{
d->m_badCount = count;
}
-QDateTime KEduVocGrade::practiceDate() const
+QDateTime KEduVocText::practiceDate() const
{
return d->m_practiceDate;
}
-void KEduVocGrade::setPracticeDate( const QDateTime & date )
+void KEduVocText::setPracticeDate( const QDateTime & date )
{
d->m_practiceDate = date;
}
-KEduVocGrade & KEduVocGrade::operator =(const KEduVocGrade & other)
+KEduVocText & KEduVocText::operator =(const KEduVocText & other)
{
d->m_grade = other.d->m_grade;
d->m_totalPracticeCount = other.d->m_totalPracticeCount;
return *this;
}
-bool KEduVocGrade::operator ==(const KEduVocGrade & other) const
+bool KEduVocText::operator ==(const KEduVocText & other) const
{
return d->m_grade == other.d->m_grade &&
d->m_totalPracticeCount == other.d->m_totalPracticeCount &&
/**
-Contains grading information (query date, bad count) for one language with respect to another.
-
+ * A text in vocabulary documents. Associated with it are grade and date information.
+ * This should be used instead of strings for all things that can be tested and thus get a grade.
@author Frederik Gladhorn <frederik.gladhorn@kdemail.net>
*/
-class KEDUVOCDOCUMENT_EXPORT KEduVocGrade
+class KEDUVOCDOCUMENT_EXPORT KEduVocText
{
public:
/** default constructor */
- KEduVocGrade();
+ KEduVocText(const QString& text = QString());
/** copy constructor
* provides safe copy of d pointer
* @param other object to copy from
*/
- KEduVocGrade( const KEduVocGrade &other );
+ KEduVocText( const KEduVocText &other );
/** default destructor */
- ~KEduVocGrade();
+ ~KEduVocText();
+
+ /**
+ * The translation as string (the word itself)
+ * @return the translation
+ */
+ QString text() const;
+
+ /**
+ * Sets the translation
+ * @param expr
+ */
+ void setText( const QString & expr );
/**
* Equal operator to copy grades.
* @param other grades copied
* @return reference to the new grades
*/
- KEduVocGrade& operator= ( const KEduVocGrade &other );
+ KEduVocText& operator= ( const KEduVocText &other );
/**
* Compare two sets of grades.
* @param other
* @return true if equal
*/
- bool operator== ( const KEduVocGrade &other ) const;
+ bool operator== ( const KEduVocText &other ) const;
/** returns how often this entry has been practiced as int
/** increment query count of given translation by 1 */
void incPracticeCount();
-
/**
* Clears grading and date information.
*/
void setPracticeDate( const QDateTime & date );
private:
- class KEduVocGradePrivate;
- KEduVocGradePrivate * const d;
+ class KEduVocTextPrivate;
+ KEduVocTextPrivate * const d;
};
#endif
bool KEduVocKvtml2Reader::readGrade( QDomElement &gradeElement, KEduVocExpression *expr, int index )
{
bool result = true;
- int id = gradeElement.attribute( KVTML_FROMID ).toInt( &result );
if ( !result ) {
m_errorMessage = i18n( "identifier missing id" );
return false;
QDomElement currentElement = gradeElement.firstChildElement( KVTML_CURRENTGRADE );
if ( !currentElement.isNull() ) {
int value = currentElement.text().toInt();
- expr->translation(index)->gradeFrom( id ).setGrade( value );
+ expr->translation(index)->setGrade( value );
}
currentElement = gradeElement.firstChildElement( KVTML_COUNT );
if ( !currentElement.isNull() ) {
int value = currentElement.text().toInt();
- expr->translation(index)->gradeFrom( id ).setPracticeCount( value );
+ expr->translation(index)->setPracticeCount( value );
}
currentElement = gradeElement.firstChildElement( KVTML_ERRORCOUNT );
if ( !currentElement.isNull() ) {
int value = currentElement.text().toInt();
- expr->translation(index)->gradeFrom( id ).setBadCount( value );
+ expr->translation(index)->setBadCount( value );
}
currentElement = gradeElement.firstChildElement( KVTML_DATE );
QString dateString = currentElement.text();
if ( !dateString.isEmpty() ) {
QDateTime value = QDateTime::fromString( dateString, Qt::ISODate );
- expr->translation(index)->gradeFrom( id ).setPracticeDate( value );
+ expr->translation(index)->setPracticeDate( value );
}
}
}
// grades
- for ( int i = 0; i < m_doc->identifierCount(); ++i ) {
- KEduVocGrade thisGrade = translation->gradeFrom( i );
- if ( thisGrade.practiceCount() > 0 ) {
- QDomElement gradeElement = m_domDoc.createElement( KVTML_GRADE );
- gradeElement.setAttribute( KVTML_FROMID, QString::number( i ) );
- //<currentgrade>2</currentgrade>
- gradeElement.appendChild( newTextElement( KVTML_CURRENTGRADE, QString::number( thisGrade.grade() ) ) );
+ if ( translation->practiceCount() > 0 ) {
+ QDomElement gradeElement = m_domDoc.createElement( KVTML_GRADE );
- //<count>6</count>
- gradeElement.appendChild( newTextElement( KVTML_COUNT, QString::number( thisGrade.practiceCount() ) ) );
+ //<currentgrade>2</currentgrade>
+ gradeElement.appendChild( newTextElement( KVTML_CURRENTGRADE, QString::number( translation->grade() ) ) );
- //<errorcount>1</errorcount>
- gradeElement.appendChild( newTextElement( KVTML_ERRORCOUNT, QString::number( thisGrade.badCount() ) ) );
+ //<count>6</count>
+ gradeElement.appendChild( newTextElement( KVTML_COUNT, QString::number( translation->practiceCount() ) ) );
- //<date>949757271</date>
- gradeElement.appendChild( newTextElement( KVTML_DATE, thisGrade.practiceDate().toString( Qt::ISODate ) ) );
+ //<errorcount>1</errorcount>
+ gradeElement.appendChild( newTextElement( KVTML_ERRORCOUNT, QString::number( translation->badCount() ) ) );
- translationElement.appendChild( gradeElement );
- }
+ //<date>949757271</date>
+ gradeElement.appendChild( newTextElement( KVTML_DATE, translation->practiceDate().toString( Qt::ISODate ) ) );
+
+ translationElement.appendChild( gradeElement );
}
// conjugation
entry->translation( i )->setAntonym( antonym );
if ( i != 0 ) {
- entry->translation( i )->gradeFrom( 0 ).setGrade( grade );
- entry->translation( 0 )->gradeFrom( i ).setGrade( r_grade );
- entry->translation( i )->gradeFrom( 0 ).setPracticeCount( qcount );
- entry->translation( 0 )->gradeFrom( i ).setPracticeCount( r_qcount );
- entry->translation( i )->gradeFrom( 0 ).setBadCount( bcount );
- entry->translation( 0 )->gradeFrom( i ).setBadCount( r_bcount );
- entry->translation( i )->gradeFrom( 0 ).setPracticeDate( qdate );
- entry->translation( 0 )->gradeFrom( i ).setPracticeDate( r_qdate );
+ entry->translation( i )->setGrade( grade );
+ entry->translation( 0 )->setGrade( r_grade );
+ entry->translation( i )->setPracticeCount( qcount );
+ entry->translation( 0 )->setPracticeCount( r_qcount );
+ entry->translation( i )->setBadCount( bcount );
+ entry->translation( 0 )->setBadCount( r_bcount );
+ entry->translation( i )->setPracticeDate( qdate );
+ entry->translation( 0 )->setPracticeDate( r_qdate );
}
// Next translation
KEduVocExpression* m_entry;
- /// This is the word itself. The vocabulary. This is what it is all about.
- QString m_translation;
-
/// Type of a word noun, verb, adjective etc
KEduVocWordType* m_wordType;
KEduVocDeclination* m_declination;
- // Here come all int indexFrom grades. (If you want, imagine the TO grades as int indexFrom of the other translation. That is where they belong. )
- // User is asked to give THIS here as answer, than the grades go here.
- // User answers, this is the source, grades go to the other translation.
- // Grades go to the translation the user has to type/choose/whatever.
- // not all have to be supplied
- QMap<int, KEduVocGrade> m_grades;
-
/// One false friend string per other language
QMap<int, QString> m_falseFriends;
};
KEduVocTranslation::KEduVocTranslation(KEduVocExpression* entry, const QString &translation ) : d( new KEduVocTranslationPrivate(entry) )
{
- d->m_translation = translation.simplified();
+ setText(translation.simplified());
}
-KEduVocTranslation::KEduVocTranslation( const KEduVocTranslation &other ) : d( new KEduVocTranslationPrivate(other.d->m_entry) )
+KEduVocTranslation::KEduVocTranslation( const KEduVocTranslation &other )
+ : d( new KEduVocTranslationPrivate(other.d->m_entry) ),
+ KEduVocText(other)
{
- d->m_translation = other.d->m_translation;
d->m_wordType = other.d->m_wordType;
d->m_comment = other.d->m_comment;
d->m_paraphrase = other.d->m_paraphrase;
d->m_comparative = other.d->m_comparative;
d->m_superlative = other.d->m_superlative;
d->m_multipleChoice = other.d->m_multipleChoice;
- d->m_grades = other.d->m_grades;
d->m_falseFriends = other.d->m_falseFriends;
d->m_imageUrl = other.d->m_imageUrl;
d->m_soundUrl = other.d->m_soundUrl;
delete d;
}
-
bool KEduVocTranslation::operator == ( const KEduVocTranslation & translation ) const
{
- return d->m_entry == translation.d->m_entry &&
- d->m_translation == translation.d->m_translation &&
- d->m_wordType == translation.d->m_wordType &&
+ return d->m_wordType == translation.d->m_wordType &&
d->m_comment == translation.d->m_comment &&
d->m_paraphrase == translation.d->m_paraphrase &&
d->m_synonym == translation.d->m_synonym &&
d->m_superlative == translation.d->m_superlative &&
d->m_multipleChoice == translation.d->m_multipleChoice &&
d->m_falseFriends == translation.d->m_falseFriends &&
- d->m_conjugations == translation.d->m_conjugations &&
- d->m_grades == translation.d->m_grades;
+ d->m_conjugations == translation.d->m_conjugations;
}
-
KEduVocTranslation & KEduVocTranslation::operator = ( const KEduVocTranslation & translation )
{
+ KEduVocText::operator=(translation);
d->m_entry = translation.d->m_entry;
- d->m_translation = translation.d->m_translation;
d->m_wordType = translation.d->m_wordType;
d->m_comment = translation.d->m_comment;
d->m_paraphrase = translation.d->m_paraphrase;
d->m_superlative = translation.d->m_superlative;
d->m_multipleChoice = translation.d->m_multipleChoice;
d->m_falseFriends = translation.d->m_falseFriends;
- d->m_grades == translation.d->m_grades;
d->m_conjugations = translation.d->m_conjugations;
return *this;
}
-QString KEduVocTranslation::text() const
-{
- return d->m_translation;
-}
-
-
-void KEduVocTranslation::setText( const QString & expr )
-{
- d->m_translation = expr.simplified();
-}
-
-
QString KEduVocTranslation::comment() const
{
return d->m_comment;
d->m_pronunciation = expr.simplified();
}
-void KEduVocTranslation::resetGrades()
-{
- d->m_grades.clear();
-}
-
-KEduVocGrade& KEduVocTranslation::gradeFrom( int indexFrom )
-{
- return d->m_grades[indexFrom];
-}
-
QStringList KEduVocTranslation::conjugationTenses() const
{
return d->m_conjugations.keys();
#include <QtCore/QString>
class KEduVocExpression;
-class KEduVocGrade;
+class KEduVocString;
class KEduVocWordType;
/**
@author Frederik Gladhorn <frederik.gladhorn@kdemail.net>
*/
class KEDUVOCDOCUMENT_EXPORT KEduVocTranslation
+ :public KEduVocText
{
public:
/**
KEduVocExpression* entry();
- /**
- * The translation as string (the word itself)
- * @return the translation
- */
- QString text() const;
-
- /**
- * Sets the translation
- * @param expr
- */
- void setText( const QString & expr );
-
/** sets the pronunciation of this expression
* @param expression pronunciation of this index
*/
void setWordType( KEduVocWordType* wordType );
-
- /** reset the grades for this translation */
- void resetGrades();
-
- /** get the gradeobject from given identifier
- * @param indexFrom which identifier to get the grade from
- * @returns the grade object
- */
- KEduVocGrade & gradeFrom( int indexFrom );
-
/** returns a conjugation if available
*/
KEduVocConjugation& conjugation( const QString& tense );
void testDocumentAboutInfo();
void testLessons();
void testWordTypes();
+ void testTranslations();
};
void KEduVocDocumentValidatorTest::testDocumentAboutInfo()
QCOMPARE(doc.wordTypeContainer()->childContainerCount(), 1);
}
+void KEduVocDocumentValidatorTest::testTranslations()
+{
+ KEduVocTranslation *trans1 = new KEduVocTranslation(0, QString("My word"));
+ QCOMPARE(trans1->text(), QString("My word"));
+
+ // copy ctor
+ KEduVocTranslation *trans2 = new KEduVocTranslation(*trans1);
+ QCOMPARE(trans2->text(), QString("My word"));
+
+ // operator =
+ KEduVocTranslation *trans3 = new KEduVocTranslation(0);
+ trans3 = trans1;
+ QCOMPARE(trans3->text(), QString("My word"));
+}
+
QTEST_KDEMAIN_CORE( KEduVocDocumentValidatorTest )
#include "keduvocdocumentvalidatortest.moc"