From: Peter Hedlund Date: Sun, 17 Jul 2005 22:26:57 +0000 (+0000) Subject: Mainly modifications to the KEduVocExpression class. Use of Qt list classes and date... X-Git-Tag: v3.80.2~237^2~23 X-Git-Url: https://git.rmz.fi/?a=commitdiff_plain;h=da10a3949a5ba1a36928f78cd4ff34e007e7c629;p=libqmvoc.git Mainly modifications to the KEduVocExpression class. Use of Qt list classes and date class. KVocTrain example file loaded and saved without data loss. svn path=/branches/work/kwordquiz/src/keduvocexpression.h; revision=435712 --- diff --git a/kwordquiz/keduvocdocument.cpp b/kwordquiz/keduvocdocument.cpp index f533194..f4ef4b7 100644 --- a/kwordquiz/keduvocdocument.cpp +++ b/kwordquiz/keduvocdocument.cpp @@ -767,8 +767,10 @@ public: x.setQueryCount (i, 0, false); x.setBadCount (i, 0, true); x.setBadCount (i, 0, false); - x.setQueryDate (i, 0, true); - x.setQueryDate (i, 0, false); + QDateTime dt; + dt.setTime_t(0); + x.setQueryDate (i, dt, true); + x.setQueryDate (i, dt, false); } } } @@ -795,8 +797,10 @@ public: x.setQueryCount (index, 0, false); x.setBadCount (index, 0, true); x.setBadCount (index, 0, false); - x.setQueryDate (index, 0, true); - x.setQueryDate (index, 0, false); + QDateTime dt; + dt.setTime_t(0); + x.setQueryDate (index, dt, true); + x.setQueryDate (index, dt, false); } } diff --git a/kwordquiz/keduvocexpression.cpp b/kwordquiz/keduvocexpression.cpp index 384b636..e42496d 100644 --- a/kwordquiz/keduvocexpression.cpp +++ b/kwordquiz/keduvocexpression.cpp @@ -28,8 +28,9 @@ void KEduVocExpression::Init() rev_qcounts.push_back(0); bcounts.push_back(0); rev_bcounts.push_back(0); - qdates.push_back(0); - rev_qdates.push_back(0); + QDateTime dt; + qdates.push_back(dt); + rev_qdates.push_back(dt); m_lesson = 0; } @@ -402,67 +403,67 @@ void KEduVocExpression::removeTranslation (int idx) return; if (idx <= numTranslations()) - translations.remove(translations.at(idx-1)); + translations.remove(translations.at(idx - 1)); if (idx < (int)remarks.size() ) - remarks.erase (remarks.begin() + idx); + remarks.remove(remarks.at(idx - 1)); if (idx < (int)conjugations.size() ) - conjugations.erase (conjugations.begin() + idx); + conjugations.remove(conjugations.at(idx -1)); if (idx < (int)comparisons.size() ) - comparisons.erase (comparisons.begin() + idx); + comparisons.remove(comparisons.at(idx - 1)); if (idx < (int)m_fauxAmi.size() ) - m_fauxAmi.erase (m_fauxAmi.begin() + idx); + m_fauxAmi.remove(m_fauxAmi.at(idx - 1)); if (idx < (int)rev_fauxAmi.size() ) - rev_fauxAmi.erase (rev_fauxAmi.begin() + idx); + rev_fauxAmi.remove(rev_fauxAmi.at(idx - 1)); if (idx < (int)m_synonym.size() ) - m_synonym.erase (m_synonym.begin() + idx); + m_synonym.remove(m_synonym.at(idx - 1)); if (idx < (int)m_example.size() ) - m_example.erase (m_example.begin() + idx); + m_example.remove(m_example.at(idx - 1)); if (idx < (int)usageLabels.size() ) - usageLabels.erase (usageLabels.begin() + idx); + usageLabels.remove(usageLabels.at(idx - 1)); if (idx < (int)paraphrases.size() ) - paraphrases.erase (paraphrases.begin() + idx); + paraphrases.remove(paraphrases.at(idx - 1)); if (idx < (int)m_antonym.size() ) - m_antonym.erase (m_antonym.begin() + idx); + m_antonym.remove(m_antonym.at(idx - 1)); if (idx < (int)exprtypes.size() ) - exprtypes.erase (exprtypes.begin() + idx); + exprtypes.remove(exprtypes.at(idx - 1)); if (idx < (int)pronunces.size() ) - pronunces.erase (pronunces.begin() + idx); + pronunces.remove(pronunces.at(idx - 1)); if (idx < (int)grades.size() ) - grades.erase (grades.begin() + idx); + grades.remove(grades.at(idx - 1)); if (idx < (int)rev_grades.size() ) - rev_grades.erase (rev_grades.begin() + idx); + rev_grades.remove(rev_grades.at(idx - 1)); if (idx < (int)qcounts.size() ) - qcounts.erase (qcounts.begin() + idx); + qcounts.remove(qcounts.at(idx - 1)); if (idx < (int)rev_qcounts.size() ) - rev_qcounts.erase (rev_qcounts.begin() + idx); + rev_qcounts.remove(rev_qcounts.at(idx - 1)); if (idx < (int)bcounts.size() ) - bcounts.erase (bcounts.begin() + idx); + bcounts.remove(bcounts.at(idx - 1)); if (idx < (int)rev_bcounts.size() ) - rev_bcounts.erase (rev_bcounts.begin() + idx); + rev_bcounts.remove(rev_bcounts.at(idx - 1)); if (idx < (int)qdates.size() ) - qdates.erase (qdates.begin() + idx); + qdates.remove(qdates.at(idx - 1)); if (idx < (int)rev_qdates.size() ) - rev_qdates.erase (rev_qdates.begin() + idx); + rev_qdates.remove(rev_qdates.at(idx - 1)); } @@ -678,34 +679,43 @@ void KEduVocExpression::setBadCount (int idx, count_t count, bool rev_count) } -time_t KEduVocExpression::queryDate (int idx, bool rev_date) const +QDateTime KEduVocExpression::queryDate (int idx, bool rev_date) const { if (rev_date) { - if (idx >= (int)rev_qdates.size() || idx < 1 ) { - return 0; + if (idx >= (int)rev_qdates.size() || idx < 1 ) + { + QDateTime dt; + dt.setTime_t(0); + return dt; } return rev_qdates[idx]; } - if (idx >= (int)qdates.size() || idx < 1 ) { - return 0; + if (idx >= (int)qdates.size() || idx < 1 ) + { + QDateTime dt; + dt.setTime_t(0); + return dt; } return qdates[idx]; } -void KEduVocExpression::setQueryDate (int idx, time_t date, bool rev_date) +void KEduVocExpression::setQueryDate (int idx, const QDateTime & date, bool rev_date) { if (idx < 1) return; if (rev_date) { // extend rev dates with 0 if necessary if ((int)rev_qdates.size() <= idx ) - for (int i = rev_qdates.size(); i <= idx; i++) { - rev_qdates.push_back (0); - } + for (int i = rev_qdates.size(); i <= idx; i++) + { + QDateTime dt; + dt.setTime_t(0); + rev_qdates.append(dt); + } rev_qdates[idx] = date; @@ -713,8 +723,11 @@ void KEduVocExpression::setQueryDate (int idx, time_t date, bool rev_date) else { // extend dates with 0 if necessary if ((int)qdates.size() <= idx ) - for (int i = qdates.size(); i <= idx; i++) { - qdates.push_back (0); + for (int i = qdates.size(); i <= idx; i++) + { + QDateTime dt; + dt.setTime_t(0); + qdates.append(dt); } qdates[idx] = date; } @@ -734,7 +747,7 @@ bool KEduVocExpression::uniqueType () const QString KEduVocExpression::type (int idx) const { - if (idx >= (int)exprtypes.size() || idx < 0) { + if (idx >= (int)exprtypes.count() || idx < 0) { return ""; } else { @@ -783,9 +796,9 @@ void KEduVocExpression::setType (int idx, const QString &type) if ( idx < 0) return; // extend types with empty strings if necessary - if ((int)exprtypes.size() <= idx ) - for (int i = exprtypes.size(); i < idx+1; i++) - exprtypes.push_back (""); + if ((int)exprtypes.count() <= idx ) + for (int i = exprtypes.count(); i < idx + 1; i++) + exprtypes.append(""); exprtypes[idx] = type.stripWhiteSpace(); } diff --git a/kwordquiz/keduvocexpression.h b/kwordquiz/keduvocexpression.h index 89b1e76..56f9559 100644 --- a/kwordquiz/keduvocexpression.h +++ b/kwordquiz/keduvocexpression.h @@ -47,11 +47,9 @@ #define KV_LEV7_GRADE 7 #define KV_LEV7_TEXT I18N_NOOP("Level 7") +#include #include - -#include -#include -using namespace std; +#include #include "grammarmanager.h" #include "multiplechoice.h" @@ -59,10 +57,10 @@ using namespace std; typedef signed char grade_t; typedef unsigned short count_t; -/*************************************************************** - * This class contains one expression as original or in one - * translations - **************************************************************/ +/** + This class contains one expression either as an original or as a + translation + */ class KEduVocExpression { @@ -328,14 +326,14 @@ class KEduVocExpression * @param index index of translation * @param rev_date dito, in opposite direction */ - time_t queryDate (int index, bool rev_date = false) const; + QDateTime queryDate (int index, bool rev_date = false) const; /** set last query date of given translation as int * * @param index index of translation * @param rev_date dito, in opposite direction */ - void setQueryDate (int index, time_t date, bool rev_date = false); + void setQueryDate (int index, const QDateTime & date, bool rev_date = false); /** returns conjugations if available * @@ -435,31 +433,31 @@ class KEduVocExpression void Init(); private: - QString origin; + QString origin; // all these vectors must be deleted in removeTranslation() - vector exprtypes; - /*vector*/ QStringList translations; - vector remarks; - vector usageLabels; - vector paraphrases; - vector m_fauxAmi; - vector rev_fauxAmi; - vector m_synonym; - vector m_example; - vector m_antonym; - vector pronunces; - vector grades; - vector rev_grades; - vector qcounts; - vector rev_qcounts; - vector bcounts; - vector rev_bcounts; - vector qdates; - vector rev_qdates; - vector conjugations; - vector comparisons; - vector mcs; + QStringList exprtypes; + QStringList translations; + QStringList remarks; + QStringList usageLabels; + QStringList paraphrases; + QStringList m_fauxAmi; + QStringList rev_fauxAmi; + QStringList m_synonym; + QStringList m_example; + QStringList m_antonym; + QStringList pronunces; + QValueList grades; + QValueList rev_grades; + QValueList qcounts; + QValueList rev_qcounts; + QValueList bcounts; + QValueList rev_bcounts; + QValueList qdates; + QValueList rev_qdates; + QValueList conjugations; + QValueList comparisons; + QValueList mcs; QString m_leitnerBox; int m_lesson; diff --git a/kwordquiz/keduvockvtmlreader.cpp b/kwordquiz/keduvockvtmlreader.cpp index b8674cb..a5997dd 100644 --- a/kwordquiz/keduvockvtmlreader.cpp +++ b/kwordquiz/keduvockvtmlreader.cpp @@ -1004,7 +1004,9 @@ bool KEduVocKvtmlReader::readExpression(QDomElement &domElementParent) QDomAttr domAttrType = domElementParent.attributeNode(KV_EXPRTYPE); if (!domAttrType.isNull()) { - exprtype = !domAttrType.value().toInt(); + exprtype = domAttrType.value(); + //exprtype = !domAttrType.value().toInt(); PBH 2005-07-17 I don't know what this is supposed to achieve? + //The above works better if (exprtype == "1") exprtype = QM_VERB; else if (exprtype == "2") // convert from pre-0.5 versions @@ -1377,8 +1379,11 @@ bool KEduVocKvtmlReader::readExpression(QDomElement &domElementParent) expr.setQueryCount (count, r_qcount, true); expr.setBadCount (count, bcount, false); expr.setBadCount (count, r_bcount, true); - expr.setQueryDate (count, qdate, false); - expr.setQueryDate (count, r_qdate, true); + QDateTime dt; + dt.setTime_t(qdate); + expr.setQueryDate(count, dt, false); + dt.setTime_t(r_qdate); + expr.setQueryDate(count, dt, true); if (conjug.size() > 0) { diff --git a/kwordquiz/keduvockvtmlwriter.cpp b/kwordquiz/keduvockvtmlwriter.cpp index 52d58c2..724aed6 100644 --- a/kwordquiz/keduvockvtmlwriter.cpp +++ b/kwordquiz/keduvockvtmlwriter.cpp @@ -699,8 +699,9 @@ bool KEduVocKvtmlWriter::writeDoc(KEduVocDocument *doc, const QString &generator ent_no++; if (ent_percent != 0 && (ent_no % ent_percent) == 0 ) -//TODO emit progressChanged(this, ent_no / (int) f_ent_percent); - + { + //TODO emit progressChanged(this, ent_no / (int) f_ent_percent); + } if ((*first).lesson() != 0) { // entry belongs to lesson x @@ -856,11 +857,11 @@ bool KEduVocKvtmlWriter::writeDoc(KEduVocDocument *doc, const QString &generator domElementTranslation.setAttribute(KV_BAD, s1 +';' +s2); } - if ((*first).queryDate(trans, false) != 0 - ||(*first).queryDate(trans, true) != 0) + if ((*first).queryDate(trans, false).toTime_t() != 0 + ||(*first).queryDate(trans, true).toTime_t() != 0) { - s1.setNum((*first).queryDate(trans, false)); - s2.setNum((*first).queryDate(trans, true)); + s1.setNum((*first).queryDate(trans, false).toTime_t()); + s2.setNum((*first).queryDate(trans, true).toTime_t()); domElementTranslation.setAttribute(KV_DATE, s1 +';' +s2); }