From ebd2aeebb1477afe25e833d0412bea99f9dcbeb8 Mon Sep 17 00:00:00 2001 From: Jeremy Paul Whiting Date: Sun, 22 Jul 2007 13:34:07 +0000 Subject: [PATCH] MultipleChoice class has a d-pointer and doesn't crash! Frederik: mine crashed on the first attempt also, I think the copy constructor is the key. If we don't provide one, c++ just generates one that copies all member variables. Which causes d-pointer to be deleted when the first object is destructed :) svn path=/trunk/KDE/kdeedu/libkdeedu/; revision=690896 --- kdeeducore/keduvockvtml2reader.cpp | 87 ++-------------------------- kdeeducore/keduvocmultiplechoice.cpp | 52 ++++++++++++----- kdeeducore/keduvocmultiplechoice.h | 10 ++-- 3 files changed, 50 insertions(+), 99 deletions(-) diff --git a/kdeeducore/keduvockvtml2reader.cpp b/kdeeducore/keduvockvtml2reader.cpp index 419566f..def07aa 100644 --- a/kdeeducore/keduvockvtml2reader.cpp +++ b/kdeeducore/keduvockvtml2reader.cpp @@ -668,6 +668,8 @@ bool KEduVocKvtml2Reader::readArticle(QDomElement &articleElement, int identifie bool KEduVocKvtml2Reader::readConjugation(QDomElement &conjugElement, KEduVocConjugation &curr_conjug) /* + 1 + regular @@ -706,6 +708,8 @@ bool KEduVocKvtml2Reader::readConjugation(QDomElement &conjugElement, KEduVocCon { type = typeElement.text(); } + + // TODO: add something here to link and/or store tense information QDomElement currentGroup = conjugElement.firstChildElement(KVTML_SINGULAR); if (!currentGroup.isNull()) @@ -942,38 +946,8 @@ bool KEduVocKvtml2Reader::readMultipleChoice(QDomElement &multipleChoiceElement, } -//bool KEduVocKvtml2Reader::readExpressionChildAttributes( QDomElement &domElementExpressionChild, -// QString &lang, -// grade_t &grade, grade_t &rev_grade, -// int &count, int &rev_count, -// QDateTime &date, QDateTime &rev_date, -// QString &remark, -// int &bcount, int &rev_bcount, -// QString &query_id, -// QString &pronunciation, -// int &width, -// QString &type, -// QString &faux_ami_f, -// QString &faux_ami_t, -// QString &synonym, -// QString &example, -// QString &antonym, -// QString &usage, -// QString ¶phrase) -//{ -// int pos; -// QDomAttr attribute; - -// lang = ""; -// attribute = domElementExpressionChild.attributeNode(KV_LANG); -// if (!attribute.isNull()) -// lang = attribute.value(); - -// width = -1; -// attribute = domElementExpressionChild.attributeNode(KV_SIZEHINT); -// if (!attribute.isNull()) -// width = attribute.value().toInt(); +//**** old code from kvtmlreader // grade = KV_NORM_GRADE; // rev_grade = KV_NORM_GRADE; // attribute = domElementExpressionChild.attributeNode(KV_GRADE); @@ -1040,11 +1014,6 @@ bool KEduVocKvtml2Reader::readMultipleChoice(QDomElement &multipleChoiceElement, // //this format is deprecated and ignored. // } -// remark = ""; -// attribute = domElementExpressionChild.attributeNode(KV_REMARK); -// if (!attribute.isNull()) -// remark = attribute.value(); - // faux_ami_f = ""; // attribute = domElementExpressionChild.attributeNode(KV_FAUX_AMI_F); // if (!attribute.isNull()) @@ -1055,16 +1024,6 @@ bool KEduVocKvtml2Reader::readMultipleChoice(QDomElement &multipleChoiceElement, // if (!attribute.isNull()) // faux_ami_t = attribute.value(); -// synonym = ""; -// attribute = domElementExpressionChild.attributeNode(KV_SYNONYM); -// if (!attribute.isNull()) -// synonym = attribute.value(); - -// example = ""; -// attribute = domElementExpressionChild.attributeNode(KV_EXAMPLE); -// if (!attribute.isNull()) -// example = attribute.value(); - // usage = ""; // attribute = domElementExpressionChild.attributeNode(KV_USAGE); // if (!attribute.isNull()) @@ -1089,27 +1048,6 @@ bool KEduVocKvtml2Reader::readMultipleChoice(QDomElement &multipleChoiceElement, // } // } -// paraphrase = ""; -// attribute = domElementExpressionChild.attributeNode(KV_PARAPHRASE); -// if (!attribute.isNull()) -// paraphrase = attribute.value(); - -// antonym = ""; -// attribute = domElementExpressionChild.attributeNode(KV_ANTONYM); -// if (!attribute.isNull()) -// antonym = attribute.value(); - -// attribute = domElementExpressionChild.attributeNode(KV_EXPRTYPE); -// if (!attribute.isNull()) -// { -// type = attribute.value(); -// if (type == "1") -// type = QM_VERB; -// else if (type == "2") // convert from pre-0.5 versions -// type = QM_NOUN; -// else if (type == "3") -// type = QM_NAME; - // if (type.length() != 0 && type.left(1) == QM_USER_TYPE) // { // int num = qMin(type.mid (1, 40).toInt(), 1000); // paranoia check @@ -1129,19 +1067,4 @@ bool KEduVocKvtml2Reader::readMultipleChoice(QDomElement &multipleChoiceElement, // } // } -// pronunciation = ""; -// attribute = domElementExpressionChild.attributeNode(KV_PRONUNCE); -// if (!attribute.isNull()) -// pronunciation = attribute.value(); - -// query_id = ""; -// attribute = domElementExpressionChild.attributeNode(KV_QUERY); -// if (!attribute.isNull()) -// query_id = attribute.value(); - -// return true; -//} - - - #include "keduvockvtml2reader.moc" diff --git a/kdeeducore/keduvocmultiplechoice.cpp b/kdeeducore/keduvocmultiplechoice.cpp index 75a79e4..85d5fe2 100644 --- a/kdeeducore/keduvocmultiplechoice.cpp +++ b/kdeeducore/keduvocmultiplechoice.cpp @@ -25,55 +25,81 @@ #include "keduvocmultiplechoice.h" -KEduVocMultipleChoice::KEduVocMultipleChoice - (const QStringList &choices) - : m_choices(choices) +class KEduVocMultipleChoicePrivate +{ + public: + QStringList m_choices; +}; + +KEduVocMultipleChoice::KEduVocMultipleChoice() + : d(new KEduVocMultipleChoicePrivate) { } +KEduVocMultipleChoice::KEduVocMultipleChoice(const KEduVocMultipleChoice &other) + : d(new KEduVocMultipleChoicePrivate) +{ + d->m_choices = other.choices(); +} + +KEduVocMultipleChoice::KEduVocMultipleChoice(const QStringList &choices) + : d(new KEduVocMultipleChoicePrivate) +{ + setChoices(choices); +} + +void KEduVocMultipleChoice::setChoices (const QStringList &choices) +{ + d->m_choices = choices; +} + +QStringList KEduVocMultipleChoice::choices() const +{ + return d->m_choices; +} bool KEduVocMultipleChoice::isEmpty() const { - return m_choices.isEmpty(); + return d->m_choices.isEmpty(); } void KEduVocMultipleChoice::clear() { - m_choices.clear(); + d->m_choices.clear(); } QString KEduVocMultipleChoice::choice (int index) const { QString choice; - if (m_choices.size() >= index) + if (d->m_choices.size() >= index) { - choice = m_choices[index]; + choice = d->m_choices[index]; } return choice; } void KEduVocMultipleChoice::setChoice(int index, const QString &s) { - while (m_choices.size() < index) + while (d->m_choices.size() < index) { - m_choices.append(QString()); + d->m_choices.append(QString()); } - m_choices[index] = s; + d->m_choices[index] = s; } unsigned KEduVocMultipleChoice::size() { - return m_choices.size(); + return d->m_choices.size(); } bool KEduVocMultipleChoice::operator==(const KEduVocMultipleChoice &choice) const { - return m_choices == choice.m_choices; + return d->m_choices == choice.choices(); } void KEduVocMultipleChoice::appendChoice(const QString &s) { - m_choices.append(s); + d->m_choices.append(s); } diff --git a/kdeeducore/keduvocmultiplechoice.h b/kdeeducore/keduvocmultiplechoice.h index 8c07675..59377b3 100644 --- a/kdeeducore/keduvocmultiplechoice.h +++ b/kdeeducore/keduvocmultiplechoice.h @@ -34,13 +34,15 @@ #define MAX_MULTIPLE_CHOICE 5 // select one out of x +class KEduVocMultipleChoicePrivate; + class KDEEDUCORE_EXPORT KEduVocMultipleChoice { public: - KEduVocMultipleChoice() {} - + KEduVocMultipleChoice(); + KEduVocMultipleChoice(const KEduVocMultipleChoice &other); KEduVocMultipleChoice (const QStringList &choices); void setChoices (const QStringList &choices); @@ -57,9 +59,9 @@ public: bool operator==(const KEduVocMultipleChoice &choice) const; -protected: +private: - QStringList m_choices; + KEduVocMultipleChoicePrivate * d; }; -- 2.47.3