File indexing completed on 2022-10-04 13:56:36

0001 /*
0002  * SPDX-FileCopyrightText: 2007-2008 Frederik Gladhorn <frederik.gladhorn@kdemail.net>
0003  * SPDX-License-Identifier: GPL-2.0-or-later
0004 */
0005 
0006 #ifndef KEDUVOCTEXT_H
0007 #define KEDUVOCTEXT_H
0008 
0009 #include "keduvocdocument_export.h"
0010 #include <QDateTime>
0011 
0012 
0013 #define KV_MAX_GRADE       7
0014 #define KV_MIN_GRADE       0
0015 
0016 #define KV_NORM_GRADE      0       // not practiced yet
0017 #define KV_NORM_TEXT       I18N_NOOP("Not Practiced Yet")
0018 
0019 #define KV_LEV1_GRADE      1
0020 #define KV_LEV1_TEXT       I18N_NOOP("Level 1")
0021 
0022 #define KV_LEV2_GRADE      2
0023 #define KV_LEV2_TEXT       I18N_NOOP("Level 2")
0024 
0025 #define KV_LEV3_GRADE      3
0026 #define KV_LEV3_TEXT       I18N_NOOP("Level 3")
0027 
0028 #define KV_LEV4_GRADE      4
0029 #define KV_LEV4_TEXT       I18N_NOOP("Level 4")
0030 
0031 #define KV_LEV5_GRADE      5
0032 #define KV_LEV5_TEXT       I18N_NOOP("Level 5")
0033 
0034 #define KV_LEV6_GRADE      6
0035 #define KV_LEV6_TEXT       I18N_NOOP("Level 6")
0036 
0037 #define KV_LEV7_GRADE      7
0038 #define KV_LEV7_TEXT       I18N_NOOP("Level 7")
0039 
0040 
0041 typedef unsigned short grade_t;
0042 typedef unsigned short count_t;
0043 
0044 class QDomElement;
0045 
0046 /**
0047  * A text in vocabulary documents. Associated with it are grade and date information.
0048  * This should be used instead of strings for all things that can be tested and thus get a grade.
0049  @author Frederik Gladhorn <frederik.gladhorn@kdemail.net>
0050 */
0051 class KEDUVOCDOCUMENT_EXPORT KEduVocText
0052 {
0053 public:
0054     /** default constructor */
0055     KEduVocText(const QString& text = QString());
0056 
0057     /** copy constructor
0058      * provides safe copy of d pointer
0059      * @param other object to copy from
0060      */
0061     KEduVocText( const KEduVocText &other );
0062 
0063     /** default destructor */
0064     ~KEduVocText();
0065 
0066     /**
0067      * The translation as string (the word itself)
0068      * @return the translation
0069      */
0070     QString text() const;
0071 
0072     /**
0073      * Sets the translation
0074      * @param expr
0075      */
0076     void setText( const QString & expr );
0077 
0078     /**
0079      * Equal operator to copy grades.
0080      * @param other grades copied
0081      * @return reference to the new grades
0082      */
0083     KEduVocText &operator=(const KEduVocText &other);
0084     /**
0085      * Compare two sets of grades.
0086      * @param other
0087      * @return true if equal
0088      */
0089     bool operator==(const KEduVocText &other) const;
0090 
0091 
0092     /** returns how often this entry has been practiced as int
0093     * @returns total count
0094     */
0095     count_t practiceCount() const;
0096 
0097     /** set how often this entry has been practiced as int
0098     * @param count the new count
0099     */
0100     void setPracticeCount( count_t count );
0101 
0102     /** returns bad query count as int
0103     * @returns bad query count
0104     */
0105     count_t badCount() const;
0106 
0107     /** set bad query count as int
0108     * @param count the new count
0109     */
0110     void setBadCount( count_t count );
0111 
0112     /** increment bad query count of given translation by 1 */
0113     void incBadCount();
0114 
0115     /** increment query count of given translation by 1 */
0116     void incPracticeCount();
0117 
0118     /**
0119      * Clears grading and date information.
0120      */
0121     void resetGrades();
0122 
0123     /** sets the pregrade
0124     * @param grade number of knowledge: 0=known, x=numbers not knows
0125     */
0126     void setPreGrade( grade_t grade );
0127 
0128     /** returns pregrade
0129     */
0130     grade_t preGrade() const;
0131 
0132     /** sets the grade
0133     * @param grade number of knowledge: 0=known, x=numbers not knows
0134     */
0135     void setGrade( grade_t grade );
0136 
0137     /** returns grade as int
0138     * @returns number of knowledge: 0=known, x=numbers not knows
0139     */
0140     grade_t grade() const;
0141 
0142     /** increments grade */
0143     void incGrade();
0144 
0145     /** decrements grade */
0146     void decGrade();
0147 
0148     /** returns last practice date as int
0149     */
0150     QDateTime practiceDate() const;
0151 
0152     /** Set last query date
0153     * @param date             the new date
0154     */
0155     void setPracticeDate( const QDateTime & date );
0156 
0157     /** returns interval until next practice is due
0158     */
0159     quint32 interval() const;
0160 
0161     /** Set interval until next practice is due.
0162     * @param interval   the new interval
0163     */
0164     void setInterval( quint32 interval );
0165 
0166     /**
0167      * If the string inside is empty this returns true.
0168      * @return 
0169      */
0170     bool isEmpty();
0171 
0172     void fromKVTML2(QDomElement& parent);
0173     void toKVTML2(QDomElement& parent);
0174 
0175 private:
0176     class KEduVocTextPrivate;
0177     KEduVocTextPrivate * const d;
0178 };
0179 
0180 #endif