From 4cfa4ce0fcf77c23b565971ef9e845a486b994ce Mon Sep 17 00:00:00 2001 From: Frederik Gladhorn Date: Tue, 28 Aug 2007 18:17:36 +0000 Subject: [PATCH] Move KEduVocConjugation into its own file. svn path=/trunk/KDE/kdeedu/libkdeedu/; revision=705851 --- keduvocdocument/CMakeLists.txt | 2 + keduvocdocument/keduvocconjugation.cpp | 508 ++++++++++++++++++++++++ keduvocdocument/keduvocconjugation.h | 143 +++++++ keduvocdocument/keduvocdocument.h | 1 + keduvocdocument/keduvocgrammar.cpp | 524 +------------------------ keduvocdocument/keduvocgrammar.h | 126 +----- keduvocdocument/keduvockvtmlwriter.h | 1 + keduvocdocument/keduvoctranslation.h | 3 +- 8 files changed, 690 insertions(+), 618 deletions(-) create mode 100644 keduvocdocument/keduvocconjugation.cpp create mode 100644 keduvocdocument/keduvocconjugation.h diff --git a/keduvocdocument/CMakeLists.txt b/keduvocdocument/CMakeLists.txt index 96a1af7..e7eb9ae 100644 --- a/keduvocdocument/CMakeLists.txt +++ b/keduvocdocument/CMakeLists.txt @@ -11,6 +11,7 @@ set(keduvocdocument_LIB_SRCS keduvoclesson.cpp keduvocgrade.cpp keduvocgrammar.cpp + keduvocconjugation.cpp keduvocwordtype.cpp keduvockvtmlreader.cpp keduvockvtml2reader.cpp @@ -49,6 +50,7 @@ install(FILES keduvocexpression.h keduvocgrade.h keduvocgrammar.h + keduvocconjugation.h keduvoclesson.h keduvocmultiplechoice.h keduvoctranslation.h diff --git a/keduvocdocument/keduvocconjugation.cpp b/keduvocdocument/keduvocconjugation.cpp new file mode 100644 index 0000000..0cc9a8c --- /dev/null +++ b/keduvocdocument/keduvocconjugation.cpp @@ -0,0 +1,508 @@ +/*************************************************************************** + + C++ Implementation: keduvocconjugation + + ----------------------------------------------------------------------- + + begin : Di Aug 28 2007 + + copyright : (C) 2007 Frederik Gladhorn + + ----------------------------------------------------------------------- + + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#include "keduvocconjugation.h" +#include "keduvoccommon_p.h" +#include + +class KEduVocConjugation::Private +{ +public: + Private() + { + } + + QString verbName; // added to have something to compare in operator ==, assumes that there is always only one + // KEduVocConjugation per verb + + struct conjug_name_t + { + const char *abbrev; + const char *name; + }; + + struct conjug_t + { + conjug_t() { + p3common = false; + s3common = false; + } + + QString type; + bool p3common; + bool s3common; + QString pers1_sing; + QString pers2_sing; + QString pers3_m_sing; + QString pers3_f_sing; + QString pers3_n_sing; + QString pers1_plur; + QString pers2_plur; + QString pers3_m_plur; + QString pers3_f_plur; + QString pers3_n_plur; + }; + + typedef QList conjug_tList; + conjug_tList conjugations; + + static conjug_name_t names[]; + static QStringList userTenses; +}; + + +KEduVocConjugation::Private::conjug_name_t + +KEduVocConjugation::Private::names [] = +{ + { CONJ_SIMPLE_PRESENT, I18N_NOOP("Simple Present") }, + { CONJ_PRESENT_PROGR, I18N_NOOP("Present Progressive") }, + { CONJ_PRESENT_PERFECT, I18N_NOOP("Present Perfect") }, + + { CONJ_SIMPLE_PAST, I18N_NOOP("Simple Past") }, + { CONJ_PAST_PROGR, I18N_NOOP("Past Progressive") }, + { CONJ_PAST_PARTICIPLE, I18N_NOOP("Past Participle") }, + + { CONJ_FUTURE, I18N_NOOP("Future") } +}; + + +QStringList KEduVocConjugation::Private::userTenses; + + + +KEduVocConjugation::KEduVocConjugation() + : d(new Private) +{ +} + + +KEduVocConjugation::KEduVocConjugation(const KEduVocConjugation& rhs) + : d(new Private(*rhs.d)) +{ +} + + +KEduVocConjugation::~KEduVocConjugation() +{ + delete d; +} + + +KEduVocConjugation& KEduVocConjugation::operator =(const KEduVocConjugation& a) +{ + *d = *a.d; + return *this; +} + + +bool KEduVocConjugation::operator ==(const KEduVocConjugation& a) const +{ + return d->verbName == a.getVerbName(); +} + + +QString KEduVocConjugation::getVerbName() const +{ + return d->verbName; +} + +int KEduVocConjugation::entryCount() const +{ + return d->conjugations.count(); +} + + +QList KEduVocConjugation::getRelation () +{ + QList vec; + + for (int i = 0; i < numInternalNames(); i++) { + vec.append(KEduVocTenseRelation(Private::names[i].abbrev, i18n(Private::names[i].name))); + } + + for (int i = 0; i < Private::userTenses.count(); i++) { + QString s; + s.setNum(i + 1); + s.prepend(UL_USER_TENSE); + vec.append(KEduVocTenseRelation(s, Private::userTenses[i])); + } + + return vec; +} + + +void KEduVocConjugation::setTenseNames(const QStringList& names) +{ + Private::userTenses = names; +} + + +QString KEduVocConjugation::getName(const QString &abbrev) +{ + if (abbrev.length() >= 2 && QString(abbrev[0]) == QString(UL_USER_TENSE)) { + QString s = abbrev; + s.remove(0, 1); + int i = s.toInt() - 1; + + if (i < Private::userTenses.count() ) + return Private::userTenses[i]; + else + return ""; + } + else { + for (int i = 0; i < numInternalNames(); i++) + if (Private::names[i].abbrev == abbrev) { + return i18n(Private::names[i].name); + } + } + + return ""; +} + + +QString KEduVocConjugation::getName(int idx) +{ + if (idx < numInternalNames()) + return i18n(Private::names[idx].name); + else if (idx < tenseCount()) + return Private::userTenses[idx-numInternalNames()]; + else + return ""; +} + + +QString KEduVocConjugation::getAbbrev(const QString &name) +{ + for (int i = 0; i < Private::userTenses.count(); i++) + if (Private::userTenses[i] == name) { + QString s; + s.setNum(i + 1); + s.prepend(UL_USER_TENSE); + return s; + } + + for (int i = 0; i < numInternalNames(); i++) + if (Private::names[i].name == name) + return Private::names[i].abbrev; + + return ""; +} + + +QString KEduVocConjugation::getAbbrev(int idx) +{ + if (idx < numInternalNames() ) + return Private::names[idx].abbrev; + + else if (idx < tenseCount()) { + QString s; + s.setNum(idx - numInternalNames() + 1); + s.prepend(UL_USER_TENSE); + return s; + } + + else + return ""; +} + + +int KEduVocConjugation::numInternalNames() +{ + return sizeof(Private::names) / sizeof(Private::names[0]); +} + + +int KEduVocConjugation::tenseCount() +{ + return numInternalNames() + Private::userTenses.size(); +} + + +QString KEduVocConjugation::getType(int idx) +{ + if (idx >= d->conjugations.count()) + return ""; + + return d->conjugations[idx].type; +} + + +void KEduVocConjugation::setType(int idx, const QString & type) +{ + if (idx >= d->conjugations.size()) + return; + + d->conjugations[idx].type = type; +} + + +void KEduVocConjugation::cleanUp() +{ + for (int i = d->conjugations.count() - 1; i >= 0; i--) { + const Private::conjug_t *ctp = &d->conjugations[i]; + if ( ctp->pers1_sing.simplified().isEmpty() + && ctp->pers2_sing.simplified().isEmpty() + && ctp->pers3_m_sing.simplified().isEmpty() + && ctp->pers3_f_sing.simplified().isEmpty() + && ctp->pers3_n_sing.simplified().isEmpty() + && ctp->pers1_plur.simplified().isEmpty() + && ctp->pers2_plur.simplified().isEmpty() + && ctp->pers3_m_plur.simplified().isEmpty() + && ctp->pers3_f_plur.simplified().isEmpty() + && ctp->pers3_n_plur.simplified().isEmpty() + ) + d->conjugations.removeAt(i); + } +} + + +bool KEduVocConjugation::isEmpty(int idx) +{ + if (idx < d->conjugations.count()) { + const Private::conjug_t *ctp = &d->conjugations[idx]; + return ctp->pers1_sing.simplified().isEmpty() + && ctp->pers2_sing.simplified().isEmpty() + && ctp->pers3_m_sing.simplified().isEmpty() + && ctp->pers3_f_sing.simplified().isEmpty() + && ctp->pers3_n_sing.simplified().isEmpty() + && ctp->pers1_plur.simplified().isEmpty() + && ctp->pers2_plur.simplified().isEmpty() + && ctp->pers3_m_plur.simplified().isEmpty() + && ctp->pers3_f_plur.simplified().isEmpty() + && ctp->pers3_n_plur.simplified().isEmpty(); + } + return true; +} + + +#define _GET_CON_(elem, type, default) \ + for (int i = 0; i < d->conjugations.size(); i++) \ + if (d->conjugations[i].type == type) \ + return d->conjugations[i].elem; \ + return default; + + +bool KEduVocConjugation::pers3SingularCommon(const QString &type) const +{ + _GET_CON_(s3common, type, false); +} + + +bool KEduVocConjugation::pers3PluralCommon(const QString &type) const +{ + _GET_CON_(p3common, type, false); +} + + +QString KEduVocConjugation::pers1Singular(const QString &type) const +{ + _GET_CON_(pers1_sing, type, ""); +} + + +QString KEduVocConjugation::pers2Singular(const QString &type) const +{ + _GET_CON_(pers2_sing, type, ""); +} + + +QString KEduVocConjugation::pers3FemaleSingular(const QString &type) const +{ + _GET_CON_(pers3_f_sing, type, ""); +} + + +QString KEduVocConjugation::pers3MaleSingular(const QString &type) const +{ + _GET_CON_(pers3_m_sing, type, ""); +} + + +QString KEduVocConjugation::pers3NaturalSingular(const QString &type) const +{ + _GET_CON_(pers3_n_sing, type, ""); +} + + +QString KEduVocConjugation::pers1Plural(const QString &type) const +{ + _GET_CON_(pers1_plur, type, ""); +} + + +QString KEduVocConjugation::pers2Plural(const QString &type) const +{ + _GET_CON_(pers2_plur, type, ""); +} + + +QString KEduVocConjugation::pers3FemalePlural(const QString &type) const +{ + _GET_CON_(pers3_f_plur, type, ""); +} + + +QString KEduVocConjugation::pers3MalePlural(const QString &type) const +{ + _GET_CON_(pers3_m_plur, type, ""); +} + + +QString KEduVocConjugation::pers3NaturalPlural(const QString &type) const +{ + _GET_CON_(pers3_n_plur, type, ""); +} + + +#undef _GET_CON_ + + +#define _SET_CON_(elem, type, str) \ + for (int i = 0; i < d->conjugations.size(); i++) \ + if (d->conjugations[i].type == type) { \ + d->conjugations[i].elem = str; \ + return; \ + } \ + Private::conjug_t ct; \ + ct.type = type; \ + ct.elem = str; \ + d->conjugations.append(ct); + + +void KEduVocConjugation::setPers3PluralCommon(const QString &type, bool f) +{ + _SET_CON_(p3common, type, f); +} + + +void KEduVocConjugation::setPers3SingularCommon(const QString &type, bool f) +{ + _SET_CON_(s3common, type, f); +} + + +void KEduVocConjugation::setPers1Singular(const QString &type, const QString &str) +{ + _SET_CON_(pers1_sing, type, str); +} + + +void KEduVocConjugation::setPers2Singular(const QString &type, const QString &str) +{ + _SET_CON_(pers2_sing, type, str); +} + + +void KEduVocConjugation::setPers3FemaleSingular(const QString &type, const QString &str) +{ + _SET_CON_(pers3_f_sing, type, str); +} + + +void KEduVocConjugation::setPers3MaleSingular(const QString &type, const QString &str) +{ + _SET_CON_(pers3_m_sing, type, str); +} + + +void KEduVocConjugation::setPers3NaturalSingular(const QString &type, const QString &str) +{ + _SET_CON_(pers3_n_sing, type, str); +} + + +void KEduVocConjugation::setPers1Plural(const QString &type, const QString &str) +{ + _SET_CON_(pers1_plur, type, str); +} + + +void KEduVocConjugation::setPers2Plural(const QString &type, const QString &str) +{ + _SET_CON_(pers2_plur, type, str); +} + + +void KEduVocConjugation::setPers3FemalePlural(const QString &type, const QString &str) +{ + _SET_CON_(pers3_f_plur, type, str); +} + + +void KEduVocConjugation::setPers3MalePlural(const QString &type, const QString &str) +{ + _SET_CON_(pers3_m_plur, type, str); +} + + +void KEduVocConjugation::setPers3NaturalPlural(const QString &type, const QString &str) +{ + _SET_CON_(pers3_n_plur, type, str); +} + +#undef _SET_CON_ + + +//============================================================== +class KEduVocTenseRelation::Private +{ + public: + QString shortId; + QString longId; +}; + +KEduVocTenseRelation::KEduVocTenseRelation() +: d(new Private) +{ +} + +KEduVocTenseRelation::KEduVocTenseRelation (const QString & _short, const QString & _long) +: d(new Private) +{ + d->shortId = _short; + d->longId = _long; +} + +KEduVocTenseRelation::~KEduVocTenseRelation() +{ + delete d; +} + +KEduVocTenseRelation &KEduVocTenseRelation::operator=(const KEduVocTenseRelation &other) +{ + d->shortId = other.shortStr(); + d->longId = other.longStr(); + return *this; +} + +QString KEduVocTenseRelation::shortStr() const +{ + return d->shortId; +} + +QString KEduVocTenseRelation::longStr() const +{ + return d->longId; +} + diff --git a/keduvocdocument/keduvocconjugation.h b/keduvocdocument/keduvocconjugation.h new file mode 100644 index 0000000..957f9f9 --- /dev/null +++ b/keduvocdocument/keduvocconjugation.h @@ -0,0 +1,143 @@ +/*************************************************************************** + + C++ Interface: keduvocconjugation + + ----------------------------------------------------------------------- + + begin : Di Aug 28 2007 + + copyright : (C) 2007 Frederik Gladhorn + + ----------------------------------------------------------------------- + + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + + +#ifndef KEDUVOCCONJUGATION_H +#define KEDUVOCCONJUGATION_H + +#include "libkeduvocdocument_export.h" + +#include + + +#define CONJ_PREFIX "--" // definition of prefixes (I, you, ..) + +#define UL_USER_TENSE "#" // designates number of user tense + + +class KEDUVOCDOCUMENT_EXPORT KEduVocTenseRelation +{ +public: + /** default constructor */ + KEduVocTenseRelation(); + KEduVocTenseRelation (const QString & _short, const QString & _long); + + /** default destructor, deletes the d-pointer */ + ~KEduVocTenseRelation(); + + QString shortStr() const; + QString longStr() const; + + KEduVocTenseRelation &operator=(const KEduVocTenseRelation &other); + +private: + class Private; + Private * const d; +}; + + +/** + * The conjugation of a verb + */ +class KEDUVOCDOCUMENT_EXPORT KEduVocConjugation +{ +public: + + /** + * The constructor + */ + explicit KEduVocConjugation(); + + KEduVocConjugation(const KEduVocConjugation& rhs); + + ~KEduVocConjugation(); + + /** + * @return + */ + int entryCount() const; + + /** + * @return + */ + static QList getRelation(); + + /** + * @param names + */ + static void setTenseNames(const QStringList& names); + + static QString getName(const QString &abbrev); + static QString getName(int index); + static QString getAbbrev(const QString &name); + static QString getAbbrev(int index); + static int numInternalNames(); + static int tenseCount(); + + QString getVerbName() const; + + QString getType(int index); + void setType(int index, const QString & type); + void cleanUp(); + bool isEmpty(int idx); + + QString pers1Singular(const QString &type) const; + QString pers2Singular(const QString &type) const; + bool pers3SingularCommon(const QString &type) const; + QString pers3FemaleSingular(const QString &type) const; + QString pers3MaleSingular(const QString &type) const; + QString pers3NaturalSingular(const QString &type) const; + + QString pers1Plural(const QString &type) const; + QString pers2Plural(const QString &type) const; + bool pers3PluralCommon(const QString &type) const; + QString pers3FemalePlural(const QString &type) const; + QString pers3MalePlural(const QString &type) const; + QString pers3NaturalPlural(const QString &type) const; + + void setPers1Singular(const QString &type, const QString &str); + void setPers2Singular(const QString &type, const QString &str); + void setPers3SingularCommon(const QString &type, bool f); + void setPers3FemaleSingular(const QString &type, const QString &str); + void setPers3MaleSingular(const QString &type, const QString &str); + void setPers3NaturalSingular(const QString &type, const QString &str); + + void setPers1Plural(const QString &type, const QString &str); + void setPers2Plural(const QString &type, const QString &str); + void setPers3PluralCommon(const QString &type, bool f); + void setPers3FemalePlural(const QString &type, const QString &str); + void setPers3MalePlural(const QString &type, const QString &str); + void setPers3NaturalPlural(const QString &type, const QString &str); + + KEduVocConjugation& operator = (const KEduVocConjugation& a); + bool operator == (const KEduVocConjugation& a) const; + +private: + class Private; + Private* const d; +}; + + + +#endif // KEDUVOCCONJUGATION_H + diff --git a/keduvocdocument/keduvocdocument.h b/keduvocdocument/keduvocdocument.h index f39b42d..8f83321 100644 --- a/keduvocdocument/keduvocdocument.h +++ b/keduvocdocument/keduvocdocument.h @@ -22,6 +22,7 @@ #include "libkeduvocdocument_export.h" #include "keduvocgrammar.h" +#include "keduvocconjugation.h" #include #include diff --git a/keduvocdocument/keduvocgrammar.cpp b/keduvocdocument/keduvocgrammar.cpp index d6077c2..df83a7c 100644 --- a/keduvocdocument/keduvocgrammar.cpp +++ b/keduvocdocument/keduvocgrammar.cpp @@ -9,6 +9,7 @@ copyright : (C) 1999-2001 Ewald Arnold (C) 2001 The KDE-EDU team (C) 2004, 2005, 2007 Peter Hedlund + (C) 2007 Frederik Gladhorn ----------------------------------------------------------------------- @@ -25,75 +26,6 @@ #include "keduvocgrammar.h" -#include "keduvoccommon_p.h" - -#include - -class KEduVocConjugation::Private -{ -public: - Private() - { - } - - QString verbName; // added to have something to compare in operator ==, assumes that there is always only one - // KEduVocConjugation per verb - - struct conjug_name_t - { - const char *abbrev; - const char *name; - }; - - struct conjug_t - { - conjug_t() { - p3common = false; - s3common = false; - } - - QString type; - bool p3common; - bool s3common; - QString pers1_sing; - QString pers2_sing; - QString pers3_m_sing; - QString pers3_f_sing; - QString pers3_n_sing; - QString pers1_plur; - QString pers2_plur; - QString pers3_m_plur; - QString pers3_f_plur; - QString pers3_n_plur; - }; - - typedef QList conjug_tList; - conjug_tList conjugations; - - static conjug_name_t names[]; - static QStringList userTenses; -}; - - -KEduVocConjugation::Private::conjug_name_t -KEduVocConjugation::Private::names [] = -{ - { CONJ_SIMPLE_PRESENT, I18N_NOOP("Simple Present") }, - { CONJ_PRESENT_PROGR, I18N_NOOP("Present Progressive") }, - { CONJ_PRESENT_PERFECT, I18N_NOOP("Present Perfect") }, - - { CONJ_SIMPLE_PAST, I18N_NOOP("Simple Past") }, - { CONJ_PAST_PROGR, I18N_NOOP("Past Progressive") }, - { CONJ_PAST_PARTICIPLE, I18N_NOOP("Past Participle") }, - - { CONJ_FUTURE, I18N_NOOP("Future") } -}; - - -QStringList KEduVocConjugation::Private::userTenses; - - -//================================================================ class KEduVocComparison::Private { @@ -134,7 +66,7 @@ KEduVocComparison &KEduVocComparison::operator=(const KEduVocComparison& other) setL1(other.l1()); setL2(other.l2()); setL3(other.l3()); - + return *this; } @@ -157,32 +89,32 @@ bool KEduVocComparison::operator ==(const KEduVocComparison& a) const } void KEduVocComparison::setL1(const QString &s) -{ - d->ls1 = s; +{ + d->ls1 = s; } -void KEduVocComparison::setL2(const QString &s) -{ - d->ls2 = s; +void KEduVocComparison::setL2(const QString &s) +{ + d->ls2 = s; } -void KEduVocComparison::setL3(const QString &s) -{ - d->ls3 = s; +void KEduVocComparison::setL3(const QString &s) +{ + d->ls3 = s; } -QString KEduVocComparison::l1() const -{ - return d->ls1; +QString KEduVocComparison::l1() const +{ + return d->ls1; } -QString KEduVocComparison::l2() const -{ - return d->ls2; +QString KEduVocComparison::l2() const +{ + return d->ls2; } -QString KEduVocComparison::l3() const -{ - return d->ls3; +QString KEduVocComparison::l3() const +{ + return d->ls3; } @@ -218,7 +150,7 @@ KEduVocArticle &KEduVocArticle::operator=(const KEduVocArticle& other) d->mal_indef = other.d->mal_indef; d->nat_def = other.d->nat_def; d->nat_indef = other.d->nat_indef; - + return *this; } @@ -282,420 +214,4 @@ void KEduVocArticle::getNatural(QString *def, QString *indef) const *indef = d->nat_indef; } -//============================================================== -class KEduVocTenseRelation::Private -{ - public: - QString shortId; - QString longId; -}; - -KEduVocTenseRelation::KEduVocTenseRelation() -: d(new Private) -{ -} - -KEduVocTenseRelation::KEduVocTenseRelation (const QString & _short, const QString & _long) -: d(new Private) -{ - d->shortId = _short; - d->longId = _long; -} - -KEduVocTenseRelation::~KEduVocTenseRelation() -{ - delete d; -} - -KEduVocTenseRelation &KEduVocTenseRelation::operator=(const KEduVocTenseRelation &other) -{ - d->shortId = other.shortStr(); - d->longId = other.longStr(); - return *this; -} - -QString KEduVocTenseRelation::shortStr() const -{ - return d->shortId; -} - -QString KEduVocTenseRelation::longStr() const -{ - return d->longId; -} - - -//============================================================== - - -KEduVocConjugation::KEduVocConjugation() - : d(new Private) -{ -} - - -KEduVocConjugation::KEduVocConjugation(const KEduVocConjugation& rhs) - : d(new Private(*rhs.d)) -{ -} - - -KEduVocConjugation::~KEduVocConjugation() -{ - delete d; -} - - -KEduVocConjugation& KEduVocConjugation::operator =(const KEduVocConjugation& a) -{ - *d = *a.d; - return *this; -} - - -bool KEduVocConjugation::operator ==(const KEduVocConjugation& a) const -{ - return d->verbName == a.getVerbName(); -} - - -QString KEduVocConjugation::getVerbName() const -{ - return d->verbName; -} - -int KEduVocConjugation::entryCount() const -{ - return d->conjugations.count(); -} - - -QList KEduVocConjugation::getRelation () -{ - QList vec; - - for (int i = 0; i < numInternalNames(); i++) { - vec.append(KEduVocTenseRelation(Private::names[i].abbrev, i18n(Private::names[i].name))); - } - - for (int i = 0; i < Private::userTenses.count(); i++) { - QString s; - s.setNum(i + 1); - s.prepend(UL_USER_TENSE); - vec.append(KEduVocTenseRelation(s, Private::userTenses[i])); - } - - return vec; -} - - -void KEduVocConjugation::setTenseNames(const QStringList& names) -{ - Private::userTenses = names; -} - - -QString KEduVocConjugation::getName(const QString &abbrev) -{ - if (abbrev.length() >= 2 && QString(abbrev[0]) == QString(UL_USER_TENSE)) { - QString s = abbrev; - s.remove(0, 1); - int i = s.toInt() - 1; - - if (i < Private::userTenses.count() ) - return Private::userTenses[i]; - else - return ""; - } - else { - for (int i = 0; i < numInternalNames(); i++) - if (Private::names[i].abbrev == abbrev) { - return i18n(Private::names[i].name); - } - } - - return ""; -} - - -QString KEduVocConjugation::getName(int idx) -{ - if (idx < numInternalNames()) - return i18n(Private::names[idx].name); - else if (idx < tenseCount()) - return Private::userTenses[idx-numInternalNames()]; - else - return ""; -} - - -QString KEduVocConjugation::getAbbrev(const QString &name) -{ - for (int i = 0; i < Private::userTenses.count(); i++) - if (Private::userTenses[i] == name) { - QString s; - s.setNum(i + 1); - s.prepend(UL_USER_TENSE); - return s; - } - - for (int i = 0; i < numInternalNames(); i++) - if (Private::names[i].name == name) - return Private::names[i].abbrev; - - return ""; -} - - -QString KEduVocConjugation::getAbbrev(int idx) -{ - if (idx < numInternalNames() ) - return Private::names[idx].abbrev; - - else if (idx < tenseCount()) { - QString s; - s.setNum(idx - numInternalNames() + 1); - s.prepend(UL_USER_TENSE); - return s; - } - - else - return ""; -} - - -int KEduVocConjugation::numInternalNames() -{ - return sizeof(Private::names) / sizeof(Private::names[0]); -} - - -int KEduVocConjugation::tenseCount() -{ - return numInternalNames() + Private::userTenses.size(); -} - - -QString KEduVocConjugation::getType(int idx) -{ - if (idx >= d->conjugations.count()) - return ""; - - return d->conjugations[idx].type; -} - - -void KEduVocConjugation::setType(int idx, const QString & type) -{ - if (idx >= d->conjugations.size()) - return; - - d->conjugations[idx].type = type; -} - - -void KEduVocConjugation::cleanUp() -{ - for (int i = d->conjugations.count() - 1; i >= 0; i--) { - const Private::conjug_t *ctp = &d->conjugations[i]; - if ( ctp->pers1_sing.simplified().isEmpty() - && ctp->pers2_sing.simplified().isEmpty() - && ctp->pers3_m_sing.simplified().isEmpty() - && ctp->pers3_f_sing.simplified().isEmpty() - && ctp->pers3_n_sing.simplified().isEmpty() - && ctp->pers1_plur.simplified().isEmpty() - && ctp->pers2_plur.simplified().isEmpty() - && ctp->pers3_m_plur.simplified().isEmpty() - && ctp->pers3_f_plur.simplified().isEmpty() - && ctp->pers3_n_plur.simplified().isEmpty() - ) - d->conjugations.removeAt(i); - } -} - - -bool KEduVocConjugation::isEmpty(int idx) -{ - if (idx < d->conjugations.count()) { - const Private::conjug_t *ctp = &d->conjugations[idx]; - return ctp->pers1_sing.simplified().isEmpty() - && ctp->pers2_sing.simplified().isEmpty() - && ctp->pers3_m_sing.simplified().isEmpty() - && ctp->pers3_f_sing.simplified().isEmpty() - && ctp->pers3_n_sing.simplified().isEmpty() - && ctp->pers1_plur.simplified().isEmpty() - && ctp->pers2_plur.simplified().isEmpty() - && ctp->pers3_m_plur.simplified().isEmpty() - && ctp->pers3_f_plur.simplified().isEmpty() - && ctp->pers3_n_plur.simplified().isEmpty(); - } - return true; -} - - -#define _GET_CON_(elem, type, default) \ - for (int i = 0; i < d->conjugations.size(); i++) \ - if (d->conjugations[i].type == type) \ - return d->conjugations[i].elem; \ - return default; - - -bool KEduVocConjugation::pers3SingularCommon(const QString &type) const -{ - _GET_CON_(s3common, type, false); -} - - -bool KEduVocConjugation::pers3PluralCommon(const QString &type) const -{ - _GET_CON_(p3common, type, false); -} - - -QString KEduVocConjugation::pers1Singular(const QString &type) const -{ - _GET_CON_(pers1_sing, type, ""); -} - - -QString KEduVocConjugation::pers2Singular(const QString &type) const -{ - _GET_CON_(pers2_sing, type, ""); -} - - -QString KEduVocConjugation::pers3FemaleSingular(const QString &type) const -{ - _GET_CON_(pers3_f_sing, type, ""); -} - - -QString KEduVocConjugation::pers3MaleSingular(const QString &type) const -{ - _GET_CON_(pers3_m_sing, type, ""); -} - - -QString KEduVocConjugation::pers3NaturalSingular(const QString &type) const -{ - _GET_CON_(pers3_n_sing, type, ""); -} - - -QString KEduVocConjugation::pers1Plural(const QString &type) const -{ - _GET_CON_(pers1_plur, type, ""); -} - - -QString KEduVocConjugation::pers2Plural(const QString &type) const -{ - _GET_CON_(pers2_plur, type, ""); -} - - -QString KEduVocConjugation::pers3FemalePlural(const QString &type) const -{ - _GET_CON_(pers3_f_plur, type, ""); -} - - -QString KEduVocConjugation::pers3MalePlural(const QString &type) const -{ - _GET_CON_(pers3_m_plur, type, ""); -} - - -QString KEduVocConjugation::pers3NaturalPlural(const QString &type) const -{ - _GET_CON_(pers3_n_plur, type, ""); -} - - -#undef _GET_CON_ - - -#define _SET_CON_(elem, type, str) \ - for (int i = 0; i < d->conjugations.size(); i++) \ - if (d->conjugations[i].type == type) { \ - d->conjugations[i].elem = str; \ - return; \ - } \ - Private::conjug_t ct; \ - ct.type = type; \ - ct.elem = str; \ - d->conjugations.append(ct); - - -void KEduVocConjugation::setPers3PluralCommon(const QString &type, bool f) -{ - _SET_CON_(p3common, type, f); -} - - -void KEduVocConjugation::setPers3SingularCommon(const QString &type, bool f) -{ - _SET_CON_(s3common, type, f); -} - - -void KEduVocConjugation::setPers1Singular(const QString &type, const QString &str) -{ - _SET_CON_(pers1_sing, type, str); -} - - -void KEduVocConjugation::setPers2Singular(const QString &type, const QString &str) -{ - _SET_CON_(pers2_sing, type, str); -} - - -void KEduVocConjugation::setPers3FemaleSingular(const QString &type, const QString &str) -{ - _SET_CON_(pers3_f_sing, type, str); -} - - -void KEduVocConjugation::setPers3MaleSingular(const QString &type, const QString &str) -{ - _SET_CON_(pers3_m_sing, type, str); -} - - -void KEduVocConjugation::setPers3NaturalSingular(const QString &type, const QString &str) -{ - _SET_CON_(pers3_n_sing, type, str); -} - - -void KEduVocConjugation::setPers1Plural(const QString &type, const QString &str) -{ - _SET_CON_(pers1_plur, type, str); -} - - -void KEduVocConjugation::setPers2Plural(const QString &type, const QString &str) -{ - _SET_CON_(pers2_plur, type, str); -} - - -void KEduVocConjugation::setPers3FemalePlural(const QString &type, const QString &str) -{ - _SET_CON_(pers3_f_plur, type, str); -} - - -void KEduVocConjugation::setPers3MalePlural(const QString &type, const QString &str) -{ - _SET_CON_(pers3_m_plur, type, str); -} - - -void KEduVocConjugation::setPers3NaturalPlural(const QString &type, const QString &str) -{ - _SET_CON_(pers3_n_plur, type, str); -} -#undef _SET_CON_ diff --git a/keduvocdocument/keduvocgrammar.h b/keduvocdocument/keduvocgrammar.h index bd9c440..64b8ccc 100644 --- a/keduvocdocument/keduvocgrammar.h +++ b/keduvocdocument/keduvocgrammar.h @@ -9,6 +9,7 @@ copyright : (C) 1999-2001 Ewald Arnold (C) 2001 The KDE-EDU team (C) 2005, 2007 Peter Hedlund + (C) 2007 Frederik Gladhorn ----------------------------------------------------------------------- @@ -30,9 +31,9 @@ #include -#define CONJ_PREFIX "--" // definition of prefixes (I, you, ..) - -#define UL_USER_TENSE "#" // designates number of user tense +// #define CONJ_PREFIX "--" // definition of prefixes (I, you, ..) +// +// #define UL_USER_TENSE "#" // designates number of user tense /** * Class representing the articles of a language @@ -47,8 +48,8 @@ public: * The constructor without arguments */ explicit KEduVocArticle(); - - /** copy constructor for d-pointer safety + + /** copy constructor for d-pointer safety * @param other article object to copy */ KEduVocArticle(const KEduVocArticle &other); @@ -68,7 +69,7 @@ public: * default destructor, deletes the d pointer */ ~KEduVocArticle(); - + /** * Sets the female articles * @param def const reference to a QString with the definite female article @@ -101,13 +102,13 @@ public: * @param indef pointer to the indefinite form */ void getMale (QString *def, QString *indef) const; - + /** get the neutral articles * @param def pointer to the definite form * @param indef pointer to the indefinite form */ void getNatural(QString *def, QString *indef) const; - + /** * assignment operator for d-pointer copying */ @@ -127,8 +128,8 @@ public: * The constructor without arguments */ explicit KEduVocComparison(); - - /** copy constructor + + /** copy constructor * @param other comparison object to copy */ KEduVocComparison(const KEduVocComparison &other); @@ -143,7 +144,7 @@ public: /** default destructor, deletes the d-pointer */ ~KEduVocComparison(); - + /** set the first comparison @param s value to set */ @@ -178,7 +179,7 @@ public: * @returns true if empty, false otherwise */ bool isEmpty() const; - + /** clear the comparison */ void clear(); @@ -200,105 +201,4 @@ private: }; -class KEDUVOCDOCUMENT_EXPORT KEduVocTenseRelation -{ -public: - /** default constructor */ - KEduVocTenseRelation(); - KEduVocTenseRelation (const QString & _short, const QString & _long); - - /** default destructor, deletes the d-pointer */ - ~KEduVocTenseRelation(); - - QString shortStr() const; - QString longStr() const; - - KEduVocTenseRelation &operator=(const KEduVocTenseRelation &other); - -private: - class Private; - Private * const d; -}; - -/** - * The conjugation of a verb - */ -class KEDUVOCDOCUMENT_EXPORT KEduVocConjugation -{ -public: - - /** - * The constructor - */ - explicit KEduVocConjugation(); - - KEduVocConjugation(const KEduVocConjugation& rhs); - - ~KEduVocConjugation(); - - /** - * @return - */ - int entryCount() const; - - /** - * @return - */ - static QList getRelation(); - - /** - * @param names - */ - static void setTenseNames(const QStringList& names); - - static QString getName(const QString &abbrev); - static QString getName(int index); - static QString getAbbrev(const QString &name); - static QString getAbbrev(int index); - static int numInternalNames(); - static int tenseCount(); - - QString getVerbName() const; - - QString getType(int index); - void setType(int index, const QString & type); - void cleanUp(); - bool isEmpty(int idx); - - QString pers1Singular(const QString &type) const; - QString pers2Singular(const QString &type) const; - bool pers3SingularCommon(const QString &type) const; - QString pers3FemaleSingular(const QString &type) const; - QString pers3MaleSingular(const QString &type) const; - QString pers3NaturalSingular(const QString &type) const; - - QString pers1Plural(const QString &type) const; - QString pers2Plural(const QString &type) const; - bool pers3PluralCommon(const QString &type) const; - QString pers3FemalePlural(const QString &type) const; - QString pers3MalePlural(const QString &type) const; - QString pers3NaturalPlural(const QString &type) const; - - void setPers1Singular(const QString &type, const QString &str); - void setPers2Singular(const QString &type, const QString &str); - void setPers3SingularCommon(const QString &type, bool f); - void setPers3FemaleSingular(const QString &type, const QString &str); - void setPers3MaleSingular(const QString &type, const QString &str); - void setPers3NaturalSingular(const QString &type, const QString &str); - - void setPers1Plural(const QString &type, const QString &str); - void setPers2Plural(const QString &type, const QString &str); - void setPers3PluralCommon(const QString &type, bool f); - void setPers3FemalePlural(const QString &type, const QString &str); - void setPers3MalePlural(const QString &type, const QString &str); - void setPers3NaturalPlural(const QString &type, const QString &str); - - KEduVocConjugation& operator = (const KEduVocConjugation& a); - bool operator == (const KEduVocConjugation& a) const; - -private: - class Private; - Private* const d; -}; - #endif // KEDUVOCGRAMMAR_H diff --git a/keduvocdocument/keduvockvtmlwriter.h b/keduvocdocument/keduvockvtmlwriter.h index 8304022..25a0ba9 100644 --- a/keduvocdocument/keduvockvtmlwriter.h +++ b/keduvocdocument/keduvockvtmlwriter.h @@ -25,6 +25,7 @@ #include #include "keduvocgrammar.h" +#include "keduvocconjugation.h" #include "keduvocmultiplechoice.h" #include "keduvockvtmlcompability.h" diff --git a/keduvocdocument/keduvoctranslation.h b/keduvocdocument/keduvoctranslation.h index 921ee7d..d4c6b40 100644 --- a/keduvocdocument/keduvoctranslation.h +++ b/keduvocdocument/keduvoctranslation.h @@ -22,6 +22,7 @@ #include #include "keduvocgrammar.h" +#include "keduvocconjugation.h" #include "keduvocmultiplechoice.h" class KEduVocGrade; @@ -56,7 +57,7 @@ public: * @return the translation */ QString text () const; - + /** * Sets the translation * @param expr -- 2.47.3