]> Git trees. - libqmvoc.git/commitdiff
MultipleChoice class has a d-pointer and doesn't crash!
authorJeremy Paul Whiting <jpwhiting@kde.org>
Sun, 22 Jul 2007 13:34:07 +0000 (13:34 +0000)
committerJeremy Paul Whiting <jpwhiting@kde.org>
Sun, 22 Jul 2007 13:34:07 +0000 (13:34 +0000)
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
kdeeducore/keduvocmultiplechoice.cpp
kdeeducore/keduvocmultiplechoice.h

index 419566f008027452d9b048f1999868e3dfe27f1d..def07aabb5b9ea9e8eedd1b0acb4f1482d32a602 100644 (file)
@@ -668,6 +668,8 @@ bool KEduVocKvtml2Reader::readArticle(QDomElement &articleElement, int identifie
 bool KEduVocKvtml2Reader::readConjugation(QDomElement &conjugElement, KEduVocConjugation &curr_conjug)
 /*
  <conjugation>
+  <tenseid>1</tenseid>
+  <type>regular</type>
   <singular>
     <first person></first person>
     <second person></second person>
@@ -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 &paraphrase)
-//{
-//  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"
index 75a79e41d0aff0fa8130bbbfede709ecc2c58fef..85d5fe24a856d59cb7b9ab92cdc180d3c797cad9 100644 (file)
 
 #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);
 }
index 8c0767585c579ada3cbf94564669bda17c201014..59377b3d0dce1d54409ec699dc3815d9014f216d 100644 (file)
 
 #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;
 };