]> Git trees. - libqmvoc.git/commitdiff
Make KEduVocGrade a proper class.
authorFrederik Gladhorn <gladhorn@kde.org>
Mon, 18 Jun 2007 10:59:26 +0000 (10:59 +0000)
committerFrederik Gladhorn <gladhorn@kde.org>
Mon, 18 Jun 2007 10:59:26 +0000 (10:59 +0000)
svn path=/trunk/KDE/kdeedu/libkdeedu/; revision=677032

kdeeducore/keduvocgrade.cpp
kdeeducore/keduvocgrade.h
kdeeducore/keduvockvtmlwriter.cpp
kdeeducore/keduvoctranslation.cpp
kdeeducore/keduvoctranslation.h
kdeeducore/keduvocvokabelnreader.cpp

index c0ecfa1dae597d65f22d70c681e29eebb9c2316b..3682988bce23adf68297922b23de62cd0b3ff23a 100644 (file)
 #include "keduvocgrade.h"
 
 KEduVocGrade::KEduVocGrade()
+{
+    resetGrades();
+}
+
+
+void KEduVocGrade::resetGrades()
 {
     m_grade = KV_NORM_GRADE;
     m_queryCount = 0;
@@ -27,8 +33,77 @@ KEduVocGrade::KEduVocGrade()
 }
 
 
-void KEduVocGrade::resetGrades()
+grade_t KEduVocGrade::grade () const
+{
+    return m_grade;
+}
+
+
+void KEduVocGrade::setGrade ( grade_t grade )
+{
+    if ( grade > KV_MAX_GRADE )
+        grade = KV_MAX_GRADE;
+    if ( grade < KV_MIN_GRADE )
+        grade = KV_MIN_GRADE;
+    m_grade = grade;
+}
+
+
+void KEduVocGrade::incGrade ()
+{
+    setGrade ( grade() + 1 );
+}
+
+
+void KEduVocGrade::decGrade ()
+{
+    setGrade ( grade() - 1 );
+}
+
+
+count_t KEduVocGrade::queryCount ( )  const
+{
+    return m_queryCount;
+}
+
+
+void KEduVocGrade::incQueryCount ( )
+{
+    setQueryCount ( queryCount() + 1 );
+}
+
+
+void KEduVocGrade::incBadCount ( )
+{
+    setBadCount ( badCount() + 1 );
+}
+
+
+void KEduVocGrade::setQueryCount ( count_t count )
+{
+    m_queryCount = count;
+}
+
+
+count_t KEduVocGrade::badCount ( ) const
+{
+    return m_badCount;
+}
+
+
+void KEduVocGrade::setBadCount ( count_t count )
 {
+    m_badCount = count;
+}
+
 
+QDateTime KEduVocGrade::queryDate () const
+{
+    return m_queryDate;
 }
 
+
+void KEduVocGrade::setQueryDate ( const QDateTime & date )
+{
+    m_queryDate = date;
+}
index 797be5cc65de13ed1dfa168a7305117593201155..dee337136585b574ddec18671a3c5d68b08deee7 100644 (file)
@@ -60,10 +60,110 @@ class KDEEDUCORE_EXPORT KEduVocGrade
 {
 public:
     KEduVocGrade();
+
+      /** returns query count of given translation as int
+   *
+   * @param index            index of translation
+   * @param index       the identifier displayed to the user
+
+   */
+  count_t queryCount(   ) const;
+
+  /** set query count of given translation as int
+   *
+   * @param index            index of translation
+   * @param index       the identifier displayed to the user
+   * @param count            the new count
+
+   */
+  void setQueryCount( count_t count );
+
+  /** returns bad query count of given translation as int
+   *
+   * @param index            index of translation
+   * @param index       the identifier displayed to the user
+   * @param reverse          dito, in opposite direction
+   */
+  count_t badCount( ) const;
+
+  /** set bad query count of given translation as int
+   *
+   * @param index            index of translation
+   * @param index       the identifier displayed to the user
+   * @param count            the new count
+   */
+  void setBadCount( count_t count );
+
+  /** increment bad query count of given translation by 1
+   *
+   * @param index            index of translation
+   * @param index       the identifier displayed to the user
+   */
+  void incBadCount( );
+
+  /** increment query count of given translation by 1
+   *
+   * @param index            index of translation
+   * @param index       the identifier displayed to the user
+
+   */
+  void incQueryCount( );
+
+
+    /**
+     * Clears grading and date information.
+     */
     void resetGrades();
 
-/// @todo make these private and write the according functions like updateQueryDate, increaseGrade, decreaseGrade etc.
-public:
+  /** sets grade of given translation
+   *
+   * @param index            index of translation
+   * @param index       the identifier displayed to the user
+   * @param grade            number of knowlegde: 0=known, x=numbers not knows
+   */
+  void setGrade( grade_t grade );
+
+  /** returns grade of given translation as int
+   *
+   * @param index            index of translation
+   * @param index         the identifier displayed to the user
+   * @return                 number of knowlegde: 0=known, x=numbers not knows
+   */
+  grade_t grade() const;
+
+  /** increments grade of given translation
+   *
+   * @param index            index of translation
+   * @param index       the identifier displayed to the user
+
+   */
+  void incGrade(  );
+
+  /** decrements grade of given translation
+   *
+   * @param index            index of translation
+   * @param index       the identifier displayed to the user
+
+   */
+  void decGrade(  );
+
+  /** returns last query date of given translation as int
+   *
+   * @param index            index of translation
+   * @param index       the identifier displayed to the user
+
+   */
+  QDateTime queryDate(  ) const;
+
+
+   /**
+   * Set last query date
+   * @param index            index of translation
+   * @param date             the new date
+   */
+    void setQueryDate ( const QDateTime & date );
+
+private:
     grade_t m_grade;
     count_t m_queryCount;
     count_t m_badCount;
index 637be687086da694f184d7ff80b6a3da1a830915..8ec658112512cb301f3b5c55e8cea7dbf7c04b0f 100644 (file)
@@ -211,17 +211,17 @@ bool KEduVocKvtmlWriter::writeDoc(KEduVocDocument *doc, const QString &generator
           domElementTranslation.setAttribute(KV_QUERY, (QString) KV_T);
       }
 
-      if (entry->translation(trans).grade(0) != 0 || entry->translation(0).grade(trans) != 0)
-        domElementTranslation.setAttribute(KV_GRADE, QString::number(entry->translation(trans).grade(0)) + ';' + QString::number(entry->translation(0).grade(trans)));
+      if (entry->translation(trans).gradeFrom(0).grade() != 0 || entry->translation(0).gradeFrom(trans).grade() != 0)
+        domElementTranslation.setAttribute(KV_GRADE, QString::number(entry->translation(trans).gradeFrom(0).grade()) + ';' + QString::number(entry->translation(0).gradeFrom(trans).grade()));
 
-      if (entry->translation(trans).queryCount(0) != 0 || entry->translation(0).queryCount(trans) != 0)
-        domElementTranslation.setAttribute(KV_COUNT, QString::number(entry->translation(trans).queryCount(0)) + ';' + QString::number(entry->translation(0).queryCount(trans)));
+      if (entry->translation(trans).gradeFrom(0).queryCount() != 0 || entry->translation(0).gradeFrom(trans).queryCount() != 0)
+        domElementTranslation.setAttribute(KV_COUNT, QString::number(entry->translation(trans).gradeFrom(0).queryCount()) + ';' + QString::number(entry->translation(0).gradeFrom(trans).queryCount()));
 
-      if (entry->translation(trans).badCount(0) != 0 || entry->translation(0).badCount(trans) != 0)
-        domElementTranslation.setAttribute(KV_BAD, QString::number(entry->translation(trans).badCount(0)) + ';' + QString::number(entry->translation(0).badCount(trans)));
+      if (entry->translation(trans).gradeFrom(0).badCount() != 0 || entry->translation(0).gradeFrom(trans).badCount() != 0)
+        domElementTranslation.setAttribute(KV_BAD, QString::number(entry->translation(trans).gradeFrom(0).badCount()) + ';' + QString::number(entry->translation(0).gradeFrom(trans).badCount()));
 
-      if (entry->translation(trans).queryDate(0).toTime_t() != 0 || entry->translation(0).queryDate(trans).toTime_t() != 0)
-        domElementTranslation.setAttribute(KV_DATE, QString::number(entry->translation(trans).queryDate(0).toTime_t()) + ';' + QString::number(entry->translation(0).queryDate(trans).toTime_t()));
+      if (entry->translation(trans).gradeFrom(0).queryDate().toTime_t() != 0 || entry->translation(0).gradeFrom(trans).queryDate().toTime_t() != 0)
+        domElementTranslation.setAttribute(KV_DATE, QString::number(entry->translation(trans).gradeFrom(0).queryDate().toTime_t()) + ';' + QString::number(entry->translation(0).gradeFrom(trans).queryDate().toTime_t()));
 
       if (!entry->translation(trans).comment().isEmpty() )
         domElementTranslation.setAttribute(KV_REMARK, entry->translation(trans).comment());
index a80763c018576c4c094ce1ec41a07a4d011fd7db..0cbb9d50f8ae4d48084b700e9bd04be9b445a42d 100644 (file)
@@ -256,73 +256,6 @@ void KEduVocTranslation::setPronunciation (  const QString & expr )
 }
 
 
-grade_t KEduVocTranslation::grade (  int indexFrom ) const
-{
-    if (m_grades.contains(indexFrom)) {
-        return m_grades.value(indexFrom).m_grade;
-    }
-    return KV_NORM_GRADE;
-}
-
-
-void KEduVocTranslation::setGrade (  int indexFrom, grade_t grade )
-{
-    if ( grade > KV_MAX_GRADE )
-        grade = KV_MAX_GRADE;
-    if ( grade < KV_MIN_GRADE )
-        grade = KV_MIN_GRADE;
-    m_grades[indexFrom].m_grade = grade;
-}
-
-
-void KEduVocTranslation::incGrade (  int indexFrom )
-{
-    setGrade ( indexFrom, grade( indexFrom) + 1 );
-}
-
-
-void KEduVocTranslation::decGrade (  int indexFrom )
-{
-    setGrade ( indexFrom, grade( indexFrom) - 1 );
-}
-
-
-count_t KEduVocTranslation::queryCount (  int indexFrom )  const
-{
-    return m_grades.value(indexFrom).m_queryCount;
-}
-
-
-void KEduVocTranslation::setQueryCount (  int indexFrom, count_t count )
-{
-    m_grades[indexFrom].m_queryCount = count;
-}
-
-
-count_t KEduVocTranslation::badCount (  int indexFrom ) const
-{
-    return m_grades.value(indexFrom).m_badCount;
-}
-
-
-void KEduVocTranslation::setBadCount (  int indexFrom, count_t count )
-{
-    m_grades[indexFrom].m_badCount = count;
-}
-
-
-QDateTime KEduVocTranslation::queryDate (  int indexFrom ) const
-{
-    return m_grades.value(indexFrom).m_queryDate;
-}
-
-
-void KEduVocTranslation::setQueryDate (  int indexFrom, const QDateTime & date )
-{
-    m_grades[indexFrom].m_queryDate = date;
-}
-
-
 QString KEduVocTranslation::type() const
 {
     return m_types;
@@ -335,18 +268,6 @@ void KEduVocTranslation::setType (  const QString &type )
 }
 
 
-void KEduVocTranslation::incQueryCount (  int indexFrom )
-{
-    setQueryCount ( indexFrom, queryCount ( indexFrom ) + 1 );
-}
-
-
-void KEduVocTranslation::incBadCount (  int indexFrom )
-{
-    setBadCount ( indexFrom, badCount ( indexFrom ) + 1 );
-}
-
-
 void KEduVocTranslation::resetGrades(){
     m_grades.clear();
 }
@@ -396,3 +317,8 @@ KEduVocTranslation & KEduVocTranslation::operator =(const KEduVocTranslation & t
     return *this;
 }
 
+KEduVocGrade & KEduVocTranslation::gradeFrom(int indexFrom)
+{
+    return m_grades[indexFrom];
+}
+
index 957180f967a0364f57eb55ae12f31fca0b42106b..66a755a5dcfd9ca25b0ace70db1d615fe38a3f6a 100644 (file)
@@ -63,12 +63,6 @@ public:
     void setTranslation ( const QString & expr );
 
 
-    /**
-     * Clears grading and date information.
-     */
-    void resetGrades();
-
-
   /** sets the pronunciation of this expression
    *
    * @param index            index of expression
@@ -196,54 +190,10 @@ public:
    */
   void setType( const QString &type);
 
-  /** sets grade of given translation
-   *
-   * @param index            index of translation
-   * @param indexint indexFrom        the identifier displayed to the user
-   * @param grade            number of knowlegde: 0=known, x=numbers not knows
-   */
-  void setGrade( int indexFrom, grade_t grade );
-
-  /** returns grade of given translation as int
-   *
-   * @param index            index of translation
-   * @param indexint indexFrom          the identifier displayed to the user
-   * @return                 number of knowlegde: 0=known, x=numbers not knows
-   */
-  grade_t grade( int indexFrom ) const;
-
-  /** increments grade of given translation
-   *
-   * @param index            index of translation
-   * @param indexint indexFrom        the identifier displayed to the user
-
-   */
-  void incGrade(  int indexFrom );
-
-  /** decrements grade of given translation
-   *
-   * @param index            index of translation
-   * @param indexint indexFrom        the identifier displayed to the user
-
-   */
-  void decGrade(  int indexFrom );
-
-  /** returns last query date of given translation as int
-   *
-   * @param index            index of translation
-   * @param indexint indexFrom        the identifier displayed to the user
+  void resetGrades();
 
-   */
-  QDateTime queryDate(  int indexFrom ) const;
-
-  /** set last query date of given translation as int
-   *
-   * @param index            index of translation
-   * @param indexint indexFrom        the identifier displayed to the user
-   * @param date             the new date
+  KEduVocGrade & gradeFrom( int indexFrom );
 
-   */
-  void setQueryDate(  int indexFrom, const QDateTime & date );
 
   /** returns conjugations if available
    *
@@ -285,54 +235,6 @@ public:
   void setMultipleChoice( const KEduVocMultipleChoice &mc);
 
 
-  /** returns query count of given translation as int
-   *
-   * @param index            index of translation
-   * @param indexint indexFrom        the identifier displayed to the user
-
-   */
-  count_t queryCount(  int indexFrom  ) const;
-
-  /** set query count of given translation as int
-   *
-   * @param index            index of translation
-   * @param indexint indexFrom        the identifier displayed to the user
-   * @param count            the new count
-
-   */
-  void setQueryCount( int indexFrom, count_t count );
-
-  /** returns bad query count of given translation as int
-   *
-   * @param index            index of translation
-   * @param indexint indexFrom        the identifier displayed to the user
-   * @param reverse          dito, in opposite direction
-   */
-  count_t badCount( int indexFrom ) const;
-
-  /** set bad query count of given translation as int
-   *
-   * @param index            index of translation
-   * @param indexint indexFrom        the identifier displayed to the user
-   * @param count            the new count
-   */
-  void setBadCount( int indexFrom, count_t count );
-
-  /** increment bad query count of given translation by 1
-   *
-   * @param index            index of translation
-   * @param indexint indexFrom        the identifier displayed to the user
-   */
-  void incBadCount( int indexFrom );
-
-  /** increment query count of given translation by 1
-   *
-   * @param index            index of translation
-   * @param indexint indexFrom        the identifier displayed to the user
-
-   */
-  void incQueryCount( int indexFrom );
-
     /**
      * Equal operator to assing a translation to another one.
      * @param translation translation to be copied
index ad522a2420b0b3a1624aaf211323eec92558efb8..df169f8eddeb66fb33f763a803fafb36ccba8f16 100644 (file)
@@ -123,8 +123,8 @@ bool KEduVocVokabelnReader::readDoc(KEduVocDocument *doc)
     KEduVocExpression kve;
     kve.setTranslation(0, original);
     kve.setTranslation(1, translation);
-    kve.translation(1).setGrade(0, 0);
-    kve.translation(0).setGrade(1, 0);
+    kve.translation(1).gradeFrom(0).setGrade(0);
+    kve.translation(0).gradeFrom(1).setGrade(0);
     kve.setLesson(lesson);
 
     m_doc->appendEntry(&kve);