From 329b8a98db5729f2fb6957c82a24e333a451006a Mon Sep 17 00:00:00 2001 From: Pino Toscano Date: Sat, 3 Mar 2007 21:57:58 +0000 Subject: [PATCH] API work on KEduVocExpression: - move all the private stuff into a Private class - add the copy constructor, operator= and operator== so the class can work as value class svn path=/trunk/KDE/kdeedu/libkdeedu/; revision=638963 --- kdeeducore/keduvocexpression.cpp | 558 +++++++++++++++++++------------ kdeeducore/keduvocexpression.h | 52 +-- 2 files changed, 360 insertions(+), 250 deletions(-) diff --git a/kdeeducore/keduvocexpression.cpp b/kdeeducore/keduvocexpression.cpp index e9be6ae..74ed49f 100644 --- a/kdeeducore/keduvocexpression.cpp +++ b/kdeeducore/keduvocexpression.cpp @@ -18,7 +18,57 @@ #include "keduvocexpression.h" -void KEduVocExpression::Init() + +class KEduVocExpression::Private +{ +public: + Private(KEduVocExpression* qq) + : q(qq) + { + init(); + } + + void init(); + + bool operator==(const Private &p) const; + + KEduVocExpression* q; + + QString m_original; + + // all these vectors must be deleted in removeTranslation() + QStringList m_expressionTypes; + QStringList m_translations; + QStringList m_remarks; + QStringList m_usageLabels; + QStringList m_paraphrases; + QStringList m_fauxAmi; + QStringList m_reverseFauxAmi; + QStringList m_synonym; + QStringList m_example; + QStringList m_antonym; + QStringList m_pronunciations; + QList m_grades; + QList m_reverseGrades; + QList m_queryCounts; + QList m_reverseQueryCounts; + QList m_badCounts; + QList m_reverseBadCounts; + QList m_queryDates; + QList m_reverseQueryDates; + QList m_conjugations; + QList m_comparisons; + QList m_multipleChoices; + + QString m_leitnerBox; + int m_sortIndex; + int m_lesson; + bool m_inQuery; + bool m_active; +}; + + +void KEduVocExpression::Private::init() { m_grades.append(KV_NORM_GRADE); m_reverseGrades.append(KV_NORM_GRADE); @@ -35,24 +85,58 @@ void KEduVocExpression::Init() m_sortIndex = 0; } + +bool KEduVocExpression::Private::operator==(const KEduVocExpression::Private &p) const +{ + return m_original == p.m_original && + m_expressionTypes == p.m_expressionTypes && + m_translations == p.m_translations && + m_remarks == p.m_remarks && + m_usageLabels == p.m_usageLabels && + m_paraphrases == p.m_paraphrases && + m_fauxAmi == p.m_fauxAmi && + m_reverseFauxAmi == p.m_reverseFauxAmi && + m_synonym == p.m_synonym && + m_example == p.m_example && + m_antonym == p.m_antonym && + m_pronunciations == p.m_pronunciations && + m_grades == p.m_grades && + m_reverseGrades == p.m_reverseGrades && + m_queryCounts == p.m_queryCounts && + m_reverseQueryCounts == p.m_reverseQueryCounts && + m_badCounts == p.m_badCounts && + m_reverseBadCounts == p.m_reverseBadCounts && + m_queryDates == p.m_queryDates && + m_reverseQueryDates == p.m_reverseQueryDates && + m_conjugations == p.m_conjugations && + m_comparisons == p.m_comparisons && + m_multipleChoices == p.m_multipleChoices && + m_leitnerBox == p.m_leitnerBox && + m_lesson == p.m_lesson && + m_sortIndex == p.m_sortIndex && + m_inQuery == p.m_inQuery && + m_active == p.m_active; +} + + KEduVocExpression::KEduVocExpression() + : d(new Private(this)) { - Init(); } KEduVocExpression::KEduVocExpression(const QString & expression, int lesson) + : d(new Private(this)) { - Init(); setOriginal(expression.simplified()); - m_lesson = lesson; + d->m_lesson = lesson; } KEduVocExpression::KEduVocExpression(const QString & expression, const QString & separator, int lesson) + : d(new Private(this)) { - Init(); QString se; QString expr = expression; - m_lesson = lesson; + d->m_lesson = lesson; if (separator.length()) { int pos = expr.indexOf(separator); @@ -76,19 +160,32 @@ KEduVocExpression::KEduVocExpression(const QString & expression, const QString & } } + +KEduVocExpression::KEduVocExpression(const KEduVocExpression &expression) + : d(new Private(*expression.d)) +{ +} + + +KEduVocExpression::~KEduVocExpression() +{ + delete d; +} + + int KEduVocExpression::translationCount() const { - return m_translations.count(); + return d->m_translations.count(); } QString KEduVocExpression::remark(int index) const { - if (index >= m_remarks.count() || index < 0) { + if (index >= d->m_remarks.count() || index < 0) { return ""; } else { - return m_remarks[index]; + return d->m_remarks[index]; } } @@ -99,11 +196,11 @@ void KEduVocExpression::setRemark(int index, const QString & expr) return; // extend remarks with empty strings if necessary - if (m_remarks.count() <= index) - for (int i = m_remarks.count(); i < index + 1; i++) - m_remarks.append(""); + if (d->m_remarks.count() <= index) + for (int i = d->m_remarks.count(); i < index + 1; i++) + d->m_remarks.append(""); - m_remarks[index] = expr.simplified(); + d->m_remarks[index] = expr.simplified(); } @@ -114,19 +211,19 @@ void KEduVocExpression::setFauxAmi(int index, const QString & expr, bool rev_ami if (rev_ami) { // extend friend with empty strings if necessary - if (m_reverseFauxAmi.count() <= index) - for (int i = m_reverseFauxAmi.count(); i < index + 1; i++) - m_reverseFauxAmi.append(""); + if (d->m_reverseFauxAmi.count() <= index) + for (int i = d->m_reverseFauxAmi.count(); i < index + 1; i++) + d->m_reverseFauxAmi.append(""); - m_reverseFauxAmi[index] = expr.simplified(); + d->m_reverseFauxAmi[index] = expr.simplified(); } else { // extend friend with empty strings if necessary - if (m_fauxAmi.count() <= index) - for (int i = m_fauxAmi.count(); i < index + 1; i++) - m_fauxAmi.append(""); + if (d->m_fauxAmi.count() <= index) + for (int i = d->m_fauxAmi.count(); i < index + 1; i++) + d->m_fauxAmi.append(""); - m_fauxAmi[index] = expr.simplified(); + d->m_fauxAmi[index] = expr.simplified(); } } @@ -134,18 +231,18 @@ void KEduVocExpression::setFauxAmi(int index, const QString & expr, bool rev_ami QString KEduVocExpression::fauxAmi(int index, bool rev_ami) const { if (rev_ami) { - if (index >= m_reverseFauxAmi.count() || index < 1) { + if (index >= d->m_reverseFauxAmi.count() || index < 1) { return ""; } - return m_reverseFauxAmi[index]; + return d->m_reverseFauxAmi[index]; } - if (index >= m_fauxAmi.count() || index < 1) { + if (index >= d->m_fauxAmi.count() || index < 1) { return ""; } - return m_fauxAmi[index]; + return d->m_fauxAmi[index]; } @@ -155,21 +252,21 @@ void KEduVocExpression::setSynonym(int index, const QString & expr) return; // extend synonym with empty strings if necessary - if (m_synonym.count() <= index) - for (int i = m_synonym.count(); i < index + 1; i++) - m_synonym.append("-"); + if (d->m_synonym.count() <= index) + for (int i = d->m_synonym.count(); i < index + 1; i++) + d->m_synonym.append("-"); - m_synonym[index] = expr.simplified(); + d->m_synonym[index] = expr.simplified(); } QString KEduVocExpression::synonym(int index) const { - if (index >= m_synonym.count() || index < 0) { + if (index >= d->m_synonym.count() || index < 0) { return ""; } else { - return m_synonym[index]; + return d->m_synonym[index]; } } @@ -180,21 +277,21 @@ void KEduVocExpression::setExample(int index, const QString & expr) return; // extend exampls with empty strings if necessary - if (m_example.count() <= index) - for (int i = m_example.count(); i < index + 1; i++) - m_example.append(""); + if (d->m_example.count() <= index) + for (int i = d->m_example.count(); i < index + 1; i++) + d->m_example.append(""); - m_example[index] = expr.simplified(); + d->m_example[index] = expr.simplified(); } QString KEduVocExpression::example(int index) const { - if (index >= m_example.count() || index < 0) { + if (index >= d->m_example.count() || index < 0) { return ""; } else { - return m_example[index]; + return d->m_example[index]; } } @@ -205,21 +302,21 @@ void KEduVocExpression::setUsageLabel(int index, const QString & expr) return; // extend labels with empty strings if necessary - if (m_usageLabels.count() <= index) - for (int i = m_usageLabels.count(); i < index + 1; i++) - m_usageLabels.append(""); + if (d->m_usageLabels.count() <= index) + for (int i = d->m_usageLabels.count(); i < index + 1; i++) + d->m_usageLabels.append(""); - m_usageLabels[index] = expr.simplified(); + d->m_usageLabels[index] = expr.simplified(); } QString KEduVocExpression::usageLabel(int index) const { - if (index >= m_usageLabels.count() || index < 0) { + if (index >= d->m_usageLabels.count() || index < 0) { return ""; } else { - return m_usageLabels[index]; + return d->m_usageLabels[index]; } } @@ -230,21 +327,21 @@ void KEduVocExpression::setParaphrase(int index, const QString & expr) return; // extend phrase with empty strings if necessary - if (m_paraphrases.count() <= index) - for (int i = m_paraphrases.count(); i < index + 1; i++) - m_paraphrases.append(""); + if (d->m_paraphrases.count() <= index) + for (int i = d->m_paraphrases.count(); i < index + 1; i++) + d->m_paraphrases.append(""); - m_paraphrases[index] = expr.simplified(); + d->m_paraphrases[index] = expr.simplified(); } QString KEduVocExpression::paraphrase(int index) const { - if (index >= m_paraphrases.count() || index < 0) { + if (index >= d->m_paraphrases.count() || index < 0) { return ""; } else { - return m_paraphrases[index]; + return d->m_paraphrases[index]; } } @@ -255,21 +352,21 @@ void KEduVocExpression::setAntonym(int index, const QString & expr) return; // extend antonym with empty strings if necessary - if (m_antonym.count() <= index) - for (int i = m_antonym.count(); i < index + 1; i++) - m_antonym.append(""); + if (d->m_antonym.count() <= index) + for (int i = d->m_antonym.count(); i < index + 1; i++) + d->m_antonym.append(""); - m_antonym[index] = expr.simplified(); + d->m_antonym[index] = expr.simplified(); } QString KEduVocExpression::antonym(int index) const { - if (index >= m_antonym.count() || index < 0) { + if (index >= d->m_antonym.count() || index < 0) { return ""; } else { - return m_antonym[index]; + return d->m_antonym[index]; } } @@ -280,21 +377,21 @@ void KEduVocExpression::setConjugation(int index, const KEduVocConjugation &con) return; // extend conjugation with empty elements - if (m_conjugations.count() <= index) - for (int i = m_conjugations.count(); i < index + 1; i++) - m_conjugations.append(KEduVocConjugation()); + if (d->m_conjugations.count() <= index) + for (int i = d->m_conjugations.count(); i < index + 1; i++) + d->m_conjugations.append(KEduVocConjugation()); - m_conjugations[index] = con; + d->m_conjugations[index] = con; } KEduVocConjugation KEduVocExpression::conjugation(int index) const { - if (index >= m_conjugations.count() || index < 0) { + if (index >= d->m_conjugations.count() || index < 0) { return KEduVocConjugation(); } else { - return m_conjugations[index]; + return d->m_conjugations[index]; } } @@ -305,21 +402,21 @@ void KEduVocExpression::setComparison(int index, const KEduVocComparison &con) return; // extend comparison with empty elements - if (m_comparisons.count() <= index) - for (int i = m_comparisons.count(); i < index + 1; i++) - m_comparisons.append(KEduVocComparison()); + if (d->m_comparisons.count() <= index) + for (int i = d->m_comparisons.count(); i < index + 1; i++) + d->m_comparisons.append(KEduVocComparison()); - m_comparisons[index] = con; + d->m_comparisons[index] = con; } KEduVocComparison KEduVocExpression::comparison (int index) const { - if (index >= m_comparisons.count() || index < 0) { + if (index >= d->m_comparisons.count() || index < 0) { return KEduVocComparison(); } else { - return m_comparisons[index]; + return d->m_comparisons[index]; } } @@ -330,32 +427,32 @@ void KEduVocExpression::setMultipleChoice(int index, const KEduVocMultipleChoice return; // extend comparison with empty elements - if (m_multipleChoices.count() <= index) - for (int i = m_multipleChoices.count(); i < index + 1; i++) - m_multipleChoices.append(KEduVocMultipleChoice()); + if (d->m_multipleChoices.count() <= index) + for (int i = d->m_multipleChoices.count(); i < index + 1; i++) + d->m_multipleChoices.append(KEduVocMultipleChoice()); - m_multipleChoices[index] = mc; + d->m_multipleChoices[index] = mc; } KEduVocMultipleChoice KEduVocExpression::multipleChoice(int index) const { - if (index >= m_multipleChoices.count() || index < 0) { + if (index >= d->m_multipleChoices.count() || index < 0) { return KEduVocMultipleChoice(); } else { - return m_multipleChoices[index]; + return d->m_multipleChoices[index]; } } QString KEduVocExpression::pronunciation(int index) const { - if (index >= m_pronunciations.count() || index < 0) { + if (index >= d->m_pronunciations.count() || index < 0) { return ""; } else { - return m_pronunciations[index]; + return d->m_pronunciations[index]; } } @@ -365,11 +462,11 @@ void KEduVocExpression::setPronunciation(int index, const QString & expr) if (index < 0) return; // extend with empty strings if necessary - if (m_pronunciations.count() <= index) - for (int i = m_pronunciations.count(); i < index + 1; i++) - m_pronunciations.append(""); + if (d->m_pronunciations.count() <= index) + for (int i = d->m_pronunciations.count(); i < index + 1; i++) + d->m_pronunciations.append(""); - m_pronunciations[index] = expr.simplified(); + d->m_pronunciations[index] = expr.simplified(); } @@ -381,18 +478,18 @@ void KEduVocExpression::addTranslation(const QString & expr, grade_t grade, grad if (rev_grade > KV_MAX_GRADE) rev_grade = KV_MAX_GRADE; - m_grades.append(grade); - m_reverseGrades.append(rev_grade); - m_translations.append(expr.simplified()); + d->m_grades.append(grade); + d->m_reverseGrades.append(rev_grade); + d->m_translations.append(expr.simplified()); } QString KEduVocExpression::translation(int index) const { - if (index > m_translations.count() || index < 1) + if (index > d->m_translations.count() || index < 1) return ""; else - return m_translations[index-1]; + return d->m_translations[index-1]; } @@ -402,67 +499,67 @@ void KEduVocExpression::removeTranslation(int index) return; if (index <= translationCount()) - m_translations.removeAt(index - 1); + d->m_translations.removeAt(index - 1); - if (index < m_remarks.count()) - m_remarks.removeAt(index - 1); + if (index < d->m_remarks.count()) + d->m_remarks.removeAt(index - 1); - if (index < m_conjugations.count()) - m_conjugations.removeAt(index -1); + if (index < d->m_conjugations.count()) + d->m_conjugations.removeAt(index -1); - if (index < m_comparisons.count()) - m_comparisons.removeAt(index - 1); + if (index < d->m_comparisons.count()) + d->m_comparisons.removeAt(index - 1); - if (index < m_fauxAmi.count()) - m_fauxAmi.removeAt(index - 1); + if (index < d->m_fauxAmi.count()) + d->m_fauxAmi.removeAt(index - 1); - if (index < m_reverseFauxAmi.count()) - m_reverseFauxAmi.removeAt(index - 1); + if (index < d->m_reverseFauxAmi.count()) + d->m_reverseFauxAmi.removeAt(index - 1); - if (index < m_synonym.count()) - m_synonym.removeAt(index - 1); + if (index < d->m_synonym.count()) + d->m_synonym.removeAt(index - 1); - if (index < m_example.count()) - m_example.removeAt(index - 1); + if (index < d->m_example.count()) + d->m_example.removeAt(index - 1); - if (index < m_usageLabels.count()) - m_usageLabels.removeAt(index - 1); + if (index < d->m_usageLabels.count()) + d->m_usageLabels.removeAt(index - 1); - if (index < m_paraphrases.count()) - m_paraphrases.removeAt(index - 1); + if (index < d->m_paraphrases.count()) + d->m_paraphrases.removeAt(index - 1); - if (index < m_antonym.count()) - m_antonym.removeAt(index - 1); + if (index < d->m_antonym.count()) + d->m_antonym.removeAt(index - 1); - if (index < m_expressionTypes.count()) - m_expressionTypes.removeAt(index - 1); + if (index < d->m_expressionTypes.count()) + d->m_expressionTypes.removeAt(index - 1); - if (index < m_pronunciations.count()) - m_pronunciations.removeAt(index - 1); + if (index < d->m_pronunciations.count()) + d->m_pronunciations.removeAt(index - 1); - if (index < m_grades.count()) - m_grades.removeAt(index - 1); + if (index < d->m_grades.count()) + d->m_grades.removeAt(index - 1); - if (index < m_reverseGrades.count()) - m_reverseGrades.removeAt(index - 1); + if (index < d->m_reverseGrades.count()) + d->m_reverseGrades.removeAt(index - 1); - if (index < m_queryCounts.count()) - m_queryCounts.removeAt(index - 1); + if (index < d->m_queryCounts.count()) + d->m_queryCounts.removeAt(index - 1); - if (index < m_reverseQueryCounts.count()) - m_reverseQueryCounts.removeAt(index - 1); + if (index < d->m_reverseQueryCounts.count()) + d->m_reverseQueryCounts.removeAt(index - 1); - if (index < m_badCounts.count()) - m_badCounts.removeAt(index - 1); + if (index < d->m_badCounts.count()) + d->m_badCounts.removeAt(index - 1); - if (index < m_reverseBadCounts.count()) - m_reverseBadCounts.removeAt(index - 1); + if (index < d->m_reverseBadCounts.count()) + d->m_reverseBadCounts.removeAt(index - 1); - if (index < m_queryDates.count()) - m_queryDates.removeAt(index - 1); + if (index < d->m_queryDates.count()) + d->m_queryDates.removeAt(index - 1); - if (index < m_reverseQueryDates.count()) - m_reverseQueryDates.removeAt(index - 1); + if (index < d->m_reverseQueryDates.count()) + d->m_reverseQueryDates.removeAt(index - 1); } @@ -472,37 +569,37 @@ void KEduVocExpression::setTranslation(int index, const QString & expr) return; // extend translations with empty strings if necessary - if (m_translations.count() < index) - for (int i = m_translations.count(); i < index; i++) - m_translations.append(""); + if (d->m_translations.count() < index) + for (int i = d->m_translations.count(); i < index; i++) + d->m_translations.append(""); // if (index <= translations.count()) - m_translations[index-1] = expr.simplified(); + d->m_translations[index-1] = expr.simplified(); } grade_t KEduVocExpression::grade(int index, bool rev_grade) const { if (rev_grade) { - if (index >= m_reverseGrades.count() || index < 1) { + if (index >= d->m_reverseGrades.count() || index < 1) { return KV_NORM_GRADE; } - else if (m_reverseGrades[index] > KV_MAX_GRADE) { + else if (d->m_reverseGrades[index] > KV_MAX_GRADE) { return KV_MAX_GRADE; } - return m_reverseGrades[index]; + return d->m_reverseGrades[index]; } else { - if (index >= m_grades.count() || index < 1) { + if (index >= d->m_grades.count() || index < 1) { return KV_NORM_GRADE; } - else if (m_grades[index] > KV_MAX_GRADE) { + else if (d->m_grades[index] > KV_MAX_GRADE) { return KV_MAX_GRADE; } - return m_grades[index]; + return d->m_grades[index]; } } @@ -519,19 +616,19 @@ void KEduVocExpression::setGrade(int index, grade_t grade, bool rev_grade) if (rev_grade) { // extend rev grades with standard grade if necessary - if (m_reverseGrades.count() <= index) - for (int i = m_reverseGrades.count(); i <= index; i++) { - m_reverseGrades.append(KV_NORM_GRADE); + if (d->m_reverseGrades.count() <= index) + for (int i = d->m_reverseGrades.count(); i <= index; i++) { + d->m_reverseGrades.append(KV_NORM_GRADE); } - m_reverseGrades[index] = grade; + d->m_reverseGrades[index] = grade; } else { // extend grades with standard grade if necessary - if (m_grades.count() <= index) - for (int i = m_grades.count(); i <= index; i++) { - m_grades.append(KV_NORM_GRADE); + if (d->m_grades.count() <= index) + for (int i = d->m_grades.count(); i <= index; i++) { + d->m_grades.append(KV_NORM_GRADE); } - m_grades[index] = grade; + d->m_grades[index] = grade; } } @@ -543,21 +640,21 @@ void KEduVocExpression::incGrade(int index, bool rev_grade) if (rev_grade) { // extend rev grades with standard grade if necessary - if (m_reverseGrades.count() <= index) - for (int i = m_reverseGrades.count(); i <= index; i++) { - m_reverseGrades.append(KV_NORM_GRADE); + if (d->m_reverseGrades.count() <= index) + for (int i = d->m_reverseGrades.count(); i <= index; i++) { + d->m_reverseGrades.append(KV_NORM_GRADE); } - if (m_reverseGrades[index] < KV_MAX_GRADE) - m_reverseGrades[index]++; + if (d->m_reverseGrades[index] < KV_MAX_GRADE) + d->m_reverseGrades[index]++; } else { // extend grades with standard grade if necessary - if (m_grades.count() <= index) - for (int i = m_grades.count(); i <= index; i++) { - m_grades.append(KV_NORM_GRADE); + if (d->m_grades.count() <= index) + for (int i = d->m_grades.count(); i <= index; i++) { + d->m_grades.append(KV_NORM_GRADE); } - if (m_grades[index] < KV_MAX_GRADE) - m_grades[index]++; + if (d->m_grades[index] < KV_MAX_GRADE) + d->m_grades[index]++; } } @@ -569,21 +666,21 @@ void KEduVocExpression::decGrade(int index, bool rev_grade) if (rev_grade) { // extend rev grades with standard grade if necessary - if (m_reverseGrades.count() <= index) - for (int i = m_reverseGrades.count(); i <= index; i++) { - m_reverseGrades.append(KV_NORM_GRADE); + if (d->m_reverseGrades.count() <= index) + for (int i = d->m_reverseGrades.count(); i <= index; i++) { + d->m_reverseGrades.append(KV_NORM_GRADE); } - if (m_reverseGrades[index] > KV_MIN_GRADE) - m_reverseGrades[index]--; + if (d->m_reverseGrades[index] > KV_MIN_GRADE) + d->m_reverseGrades[index]--; } else { // extend grades with standard grade if necessary - if (m_grades.count() <= index) - for (int i = m_grades.count(); i <= index; i++) { - m_grades.append(KV_NORM_GRADE); + if (d->m_grades.count() <= index) + for (int i = d->m_grades.count(); i <= index; i++) { + d->m_grades.append(KV_NORM_GRADE); } - if (m_grades[index] > KV_MIN_GRADE) - m_grades[index]--; + if (d->m_grades[index] > KV_MIN_GRADE) + d->m_grades[index]--; } } @@ -591,18 +688,18 @@ void KEduVocExpression::decGrade(int index, bool rev_grade) count_t KEduVocExpression::queryCount(int index, bool rev_count) const { if (rev_count) { - if (index >= m_reverseQueryCounts.count() || index < 1) { + if (index >= d->m_reverseQueryCounts.count() || index < 1) { return 0; } - return m_reverseQueryCounts[index]; + return d->m_reverseQueryCounts[index]; } - if (index >= m_queryCounts.count() || index < 1) { + if (index >= d->m_queryCounts.count() || index < 1) { return 0; } - return m_queryCounts[index]; + return d->m_queryCounts[index]; } @@ -613,21 +710,21 @@ void KEduVocExpression::setQueryCount(int index, count_t count, bool rev_count) if (rev_count) { // extend rev counts with 0 if necessary - if (m_reverseQueryCounts.count() <= index) - for (int i = m_reverseQueryCounts.count(); i <= index; i++) { - m_reverseQueryCounts.append(0); + if (d->m_reverseQueryCounts.count() <= index) + for (int i = d->m_reverseQueryCounts.count(); i <= index; i++) { + d->m_reverseQueryCounts.append(0); } - m_reverseQueryCounts[index] = count; + d->m_reverseQueryCounts[index] = count; } else { // extend counts with 0 if necessary - if (m_queryCounts.count() <= index) - for (int i = m_queryCounts.count(); i <= index; i++) { - m_queryCounts.append(0); + if (d->m_queryCounts.count() <= index) + for (int i = d->m_queryCounts.count(); i <= index; i++) { + d->m_queryCounts.append(0); } - m_queryCounts[index] = count; + d->m_queryCounts[index] = count; } } @@ -635,18 +732,18 @@ void KEduVocExpression::setQueryCount(int index, count_t count, bool rev_count) count_t KEduVocExpression::badCount(int index, bool rev_count) const { if (rev_count) { - if (index >= m_reverseBadCounts.count() || index < 1) { + if (index >= d->m_reverseBadCounts.count() || index < 1) { return 0; } - return m_reverseBadCounts[index]; + return d->m_reverseBadCounts[index]; } - if (index >= m_badCounts.count() || index < 1) { + if (index >= d->m_badCounts.count() || index < 1) { return 0; } - return m_badCounts[index]; + return d->m_badCounts[index]; } @@ -657,21 +754,21 @@ void KEduVocExpression::setBadCount(int index, count_t count, bool rev_count) if (rev_count) { // extend rev counts with 0 if necessary - if (m_reverseBadCounts.count() <= index) - for (int i = m_reverseBadCounts.count(); i <= index; i++) { - m_reverseBadCounts.append(0); + if (d->m_reverseBadCounts.count() <= index) + for (int i = d->m_reverseBadCounts.count(); i <= index; i++) { + d->m_reverseBadCounts.append(0); } - m_reverseBadCounts[index] = count; + d->m_reverseBadCounts[index] = count; } else { // extend counts with 0 if necessary - if (m_badCounts.count() <= index) - for (int i = m_badCounts.count(); i <= index; i++) { - m_badCounts.append(0); + if (d->m_badCounts.count() <= index) + for (int i = d->m_badCounts.count(); i <= index; i++) { + d->m_badCounts.append(0); } - m_badCounts[index] = count; + d->m_badCounts[index] = count; } } @@ -679,24 +776,24 @@ void KEduVocExpression::setBadCount(int index, count_t count, bool rev_count) QDateTime KEduVocExpression::queryDate(int index, bool rev_date) const { if (rev_date) { - if (index >= m_reverseQueryDates.count() || index < 1) + if (index >= d->m_reverseQueryDates.count() || index < 1) { QDateTime dt; dt.setTime_t(0); return dt; } - return m_reverseQueryDates[index]; + return d->m_reverseQueryDates[index]; } - if (index >= m_queryDates.count() || index < 1) + if (index >= d->m_queryDates.count() || index < 1) { QDateTime dt; dt.setTime_t(0); return dt; } - return m_queryDates[index]; + return d->m_queryDates[index]; } @@ -707,27 +804,27 @@ void KEduVocExpression::setQueryDate(int index, const QDateTime & date, bool rev if (rev_date) { // extend rev dates with 0 if necessary - if (m_reverseQueryDates.count() <= index) - for (int i = m_reverseQueryDates.count(); i <= index; i++) + if (d->m_reverseQueryDates.count() <= index) + for (int i = d->m_reverseQueryDates.count(); i <= index; i++) { QDateTime dt; dt.setTime_t(0); - m_reverseQueryDates.append(dt); + d->m_reverseQueryDates.append(dt); } - m_reverseQueryDates[index] = date; + d->m_reverseQueryDates[index] = date; } else { // extend dates with 0 if necessary - if (m_queryDates.count() <= index) - for (int i = m_queryDates.count(); i <= index; i++) + if (d->m_queryDates.count() <= index) + for (int i = d->m_queryDates.count(); i <= index; i++) { QDateTime dt; dt.setTime_t(0); - m_queryDates.append(dt); + d->m_queryDates.append(dt); } - m_queryDates[index] = date; + d->m_queryDates[index] = date; } } @@ -745,11 +842,11 @@ bool KEduVocExpression::uniqueType() const QString KEduVocExpression::type(int index) const { - if (index >= m_expressionTypes.count() || index < 0) { + if (index >= d->m_expressionTypes.count() || index < 0) { return ""; } else { - return m_expressionTypes[index]; + return d->m_expressionTypes[index]; } } @@ -760,23 +857,23 @@ void KEduVocExpression::setType(int index, const QString &type) return; // extend types with empty strings if necessary - if (m_expressionTypes.count() <= index) - for (int i = m_expressionTypes.count(); i < index + 1; i++) - m_expressionTypes.append(""); + if (d->m_expressionTypes.count() <= index) + for (int i = d->m_expressionTypes.count(); i < index + 1; i++) + d->m_expressionTypes.append(""); - m_expressionTypes[index] = type.simplified(); + d->m_expressionTypes[index] = type.simplified(); } int KEduVocExpression::lesson() const { - return m_lesson; + return d->m_lesson; } void KEduVocExpression::setLesson(int l) { - m_lesson = l; + d->m_lesson = l; } @@ -794,24 +891,61 @@ void KEduVocExpression::incBadCount(int index, bool rev_count) QString KEduVocExpression::original() const { - return m_original; + return d->m_original; } void KEduVocExpression::setOriginal(const QString & expr) { - m_original = expr; + d->m_original = expr; } -QString& KEduVocExpression::leitnerBox() +QString KEduVocExpression::leitnerBox() { - return m_leitnerBox; + return d->m_leitnerBox; } void KEduVocExpression::setLeitnerBox(const QString& box) { - m_leitnerBox = box; + d->m_leitnerBox = box; +} + + +bool KEduVocExpression::isInQuery() const +{ + return d->m_inQuery; +} + + +void KEduVocExpression::setInQuery(bool flag) +{ + d->m_inQuery = flag; +} + + +bool KEduVocExpression::isActive() const +{ + return d->m_active; +} + + +void KEduVocExpression::setActive(bool flag) +{ + d->m_active = flag; +} + + +KEduVocExpression& KEduVocExpression::operator=(const KEduVocExpression &expression) +{ + *d = *expression.d; + return *this; +} + + +bool KEduVocExpression::operator==(const KEduVocExpression &expression) const +{ + return (*d == *expression.d); } diff --git a/kdeeducore/keduvocexpression.h b/kdeeducore/keduvocexpression.h index 43e9370..38e0cd9 100644 --- a/kdeeducore/keduvocexpression.h +++ b/kdeeducore/keduvocexpression.h @@ -87,6 +87,10 @@ public: */ KEduVocExpression(const QString & expression, const QString & separator, int lesson = 0); + KEduVocExpression(const KEduVocExpression &expression); + + ~KEduVocExpression(); + /** adds a new translation of this entry * @param expression translation * @param grade grade of knowledge of this translation @@ -122,19 +126,19 @@ public: /** returns flag if entry is "selected" for queries */ - bool isInQuery() const { return m_inQuery; } + bool isInQuery() const; /** set entry "selected" */ - void setInQuery(bool flag = true) { m_inQuery = flag; } + void setInQuery(bool flag = true); /** returns flag if entry is activated for queries */ - bool isActive() const {return m_active; } + bool isActive() const; /** set entry active (enabled for queries) */ - void setActive(bool flag = true) { m_active = flag; } + void setActive(bool flag = true); /** returns translation of this expression * @@ -421,43 +425,15 @@ public: * * @return the box's name */ - QString& leitnerBox(); + QString leitnerBox(); + + KEduVocExpression& operator=(const KEduVocExpression &expression); -protected: - void Init(); + bool operator==(const KEduVocExpression &expression) const; private: - QString m_original; - - // all these vectors must be deleted in removeTranslation() - QStringList m_expressionTypes; - QStringList m_translations; - QStringList m_remarks; - QStringList m_usageLabels; - QStringList m_paraphrases; - QStringList m_fauxAmi; - QStringList m_reverseFauxAmi; - QStringList m_synonym; - QStringList m_example; - QStringList m_antonym; - QStringList m_pronunciations; - QList m_grades; - QList m_reverseGrades; - QList m_queryCounts; - QList m_reverseQueryCounts; - QList m_badCounts; - QList m_reverseBadCounts; - QList m_queryDates; - QList m_reverseQueryDates; - QList m_conjugations; - QList m_comparisons; - QList m_multipleChoices; - - QString m_leitnerBox; - int m_sortIndex; - int m_lesson; - bool m_inQuery; - bool m_active; + class Private; + Private* const d; }; #endif // KEduVocExpression_H -- 2.47.3