From c9ff24dd79814f8d39b143ccedd21d2a1dfe34c3 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Tue, 13 Oct 2015 11:13:43 +0300 Subject: [PATCH] Resolved issue #378. Change 'sex' field name to 'gender'. --HG-- branch : develop --- src/app/tape/tmainwindow.cpp | 32 ++++----- src/app/tape/tmainwindow.h | 2 +- src/app/tape/tmainwindow.ui | 16 +++-- src/libs/ifc/schema.qrc | 1 + .../schema/individual_measurements/v0.3.1.xsd | 66 +++++++++++++++++++ src/libs/ifc/xml/vvitconverter.cpp | 34 +++++++++- src/libs/ifc/xml/vvitconverter.h | 2 + src/libs/vformat/vmeasurements.cpp | 53 ++++++++------- src/libs/vformat/vmeasurements.h | 18 ++--- 9 files changed, 163 insertions(+), 61 deletions(-) create mode 100644 src/libs/ifc/schema/individual_measurements/v0.3.1.xsd diff --git a/src/app/tape/tmainwindow.cpp b/src/app/tape/tmainwindow.cpp index 31ae81326..d5ce76834 100644 --- a/src/app/tape/tmainwindow.cpp +++ b/src/app/tape/tmainwindow.cpp @@ -623,12 +623,12 @@ void TMainWindow::SaveEmail() } //--------------------------------------------------------------------------------------------------------------------- -void TMainWindow::SaveSex(int index) +void TMainWindow::SaveGender(int index) { - const SexType type = static_cast(ui->comboBoxSex->itemData(index).toInt()); - if (m->Sex() != type) + const GenderType type = static_cast(ui->comboBoxGender->itemData(index).toInt()); + if (m->Gender() != type) { - m->SetSex(type); + m->SetGender(type); MeasurementsWasSaved(false); } } @@ -1619,7 +1619,7 @@ void TMainWindow::InitWindow() // Tab Information delete ui->lineEditGivenName; delete ui->lineEditFamilyName; - delete ui->comboBoxSex; + delete ui->comboBoxGender; delete ui->lineEditEmail; delete ui->labelGivenName; @@ -1634,8 +1634,8 @@ void TMainWindow::InitWindow() delete ui->dateEditBirthDate; ui->dateEditBirthDate = new QDateEdit(this); - delete ui->labelSex; - ui->labelSex = new QLabel(this); + delete ui->labelGender; + ui->labelGender = new QLabel(this); delete ui->labelEmail; ui->labelEmail = new QLabel(this); @@ -1672,7 +1672,7 @@ void TMainWindow::InitWindow() ui->lineEditGivenName->setEnabled(true); ui->lineEditFamilyName->setEnabled(true); ui->dateEditBirthDate->setEnabled(true); - ui->comboBoxSex->setEnabled(true); + ui->comboBoxGender->setEnabled(true); ui->lineEditEmail->setEnabled(true); // Tab Measurements @@ -1705,11 +1705,11 @@ void TMainWindow::InitWindow() ui->lineEditGivenName->setText(m->GivenName()); ui->lineEditFamilyName->setText(m->FamilyName()); - ui->comboBoxSex->addItem(tr("unknown", "gender"), QVariant(static_cast(SexType::Unknown))); - ui->comboBoxSex->addItem(tr("male", "gender"), QVariant(static_cast(SexType::Male))); - ui->comboBoxSex->addItem(tr("female", "gender"), QVariant(static_cast(SexType::Female))); - const qint32 index = ui->comboBoxSex->findData(static_cast(m->Sex())); - ui->comboBoxSex->setCurrentIndex(index); + ui->comboBoxGender->addItem(tr("unknown", "gender"), QVariant(static_cast(GenderType::Unknown))); + ui->comboBoxGender->addItem(tr("male", "gender"), QVariant(static_cast(GenderType::Male))); + ui->comboBoxGender->addItem(tr("female", "gender"), QVariant(static_cast(GenderType::Female))); + const qint32 index = ui->comboBoxGender->findData(static_cast(m->Gender())); + ui->comboBoxGender->setCurrentIndex(index); ui->dateEditBirthDate->setDate(m->BirthDate()); ui->lineEditEmail->setText(m->Email()); @@ -1717,8 +1717,8 @@ void TMainWindow::InitWindow() connect(ui->lineEditGivenName, &QLineEdit::editingFinished, this, &TMainWindow::SaveGivenName); connect(ui->lineEditFamilyName, &QLineEdit::editingFinished, this, &TMainWindow::SaveFamilyName); connect(ui->lineEditEmail, &QLineEdit::editingFinished, this, &TMainWindow::SaveEmail); - connect(ui->comboBoxSex, static_cast(&QComboBox::currentIndexChanged), this, - &TMainWindow::SaveSex); + connect(ui->comboBoxGender, static_cast(&QComboBox::currentIndexChanged), this, + &TMainWindow::SaveGender); connect(ui->dateEditBirthDate, &QDateEdit::dateChanged, this, &TMainWindow::SaveBirthDate); connect(ui->pushButtonGrow, &QPushButton::clicked, this, &TMainWindow::DeployFormula); @@ -2225,7 +2225,7 @@ void TMainWindow::GUIReadOnly(bool ro) ui->lineEditGivenName->setReadOnly(ro); ui->lineEditFamilyName->setReadOnly(ro); ui->dateEditBirthDate->setReadOnly(ro); - ui->comboBoxSex->setDisabled(ro); + ui->comboBoxGender->setDisabled(ro); ui->lineEditEmail->setReadOnly(ro); } diff --git a/src/app/tape/tmainwindow.h b/src/app/tape/tmainwindow.h index 3e717399f..59a03904e 100644 --- a/src/app/tape/tmainwindow.h +++ b/src/app/tape/tmainwindow.h @@ -83,7 +83,7 @@ private slots: void SaveGivenName(); void SaveFamilyName(); void SaveEmail(); - void SaveSex(int index); + void SaveGender(int index); void SaveBirthDate(const QDate & date); void SaveNotes(); void ReadOnly(bool ro); diff --git a/src/app/tape/tmainwindow.ui b/src/app/tape/tmainwindow.ui index cb83fa2bc..80c7465fe 100644 --- a/src/app/tape/tmainwindow.ui +++ b/src/app/tape/tmainwindow.ui @@ -32,7 +32,7 @@ - 0 + 1 @@ -344,7 +344,9 @@ ... - + + + @@ -396,7 +398,9 @@ ... - + + + @@ -636,14 +640,14 @@ - + - Sex: + Gender: - + false diff --git a/src/libs/ifc/schema.qrc b/src/libs/ifc/schema.qrc index 9e30ee05b..b28677382 100644 --- a/src/libs/ifc/schema.qrc +++ b/src/libs/ifc/schema.qrc @@ -10,5 +10,6 @@ schema/standard_measurements/v0.4.0.xsd schema/individual_measurements/v0.2.0.xsd schema/individual_measurements/v0.3.0.xsd + schema/individual_measurements/v0.3.1.xsd diff --git a/src/libs/ifc/schema/individual_measurements/v0.3.1.xsd b/src/libs/ifc/schema/individual_measurements/v0.3.1.xsd new file mode 100644 index 000000000..1a51f5a62 --- /dev/null +++ b/src/libs/ifc/schema/individual_measurements/v0.3.1.xsd @@ -0,0 +1,66 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/libs/ifc/xml/vvitconverter.cpp b/src/libs/ifc/xml/vvitconverter.cpp index 8bd754b78..a847146ca 100644 --- a/src/libs/ifc/xml/vvitconverter.cpp +++ b/src/libs/ifc/xml/vvitconverter.cpp @@ -40,8 +40,8 @@ */ const QString VVITConverter::MeasurementMinVerStr = QStringLiteral("0.2.0"); -const QString VVITConverter::MeasurementMaxVerStr = QStringLiteral("0.3.0"); -const QString VVITConverter::CurrentSchema = QStringLiteral("://schema/individual_measurements/v0.3.0.xsd"); +const QString VVITConverter::MeasurementMaxVerStr = QStringLiteral("0.3.1"); +const QString VVITConverter::CurrentSchema = QStringLiteral("://schema/individual_measurements/v0.3.1.xsd"); //--------------------------------------------------------------------------------------------------------------------- VVITConverter::VVITConverter(const QString &fileName) @@ -89,6 +89,8 @@ QString VVITConverter::XSDSchema(int ver) const case (0x000200): return QStringLiteral("://schema/individual_measurements/v0.2.0.xsd"); case (0x000300): + return QStringLiteral("://schema/individual_measurements/v0.3.0.xsd"); + case (0x000301): return CurrentSchema; default: { @@ -113,6 +115,13 @@ void VVITConverter::ApplyPatches() V_FALLTHROUGH } case (0x000300): + { + ToV0_3_1(); + const QString schema = XSDSchema(0x000301); + ValidateXML(schema, fileName); + V_FALLTHROUGH + } + case (0x000301): break; default: break; @@ -213,6 +222,19 @@ QDomElement VVITConverter::AddMV0_3_0(const QString &name, qreal value) return element; } +//--------------------------------------------------------------------------------------------------------------------- +void VVITConverter::GenderV0_3_1() +{ + const QDomNodeList nodeList = this->elementsByTagName(QStringLiteral("sex")); + QDomElement sex = nodeList.at(0).toElement(); + + QDomElement gender = createElement(QStringLiteral("gender")); + gender.appendChild(createTextNode(sex.text())); + + QDomElement parent = sex.parentNode().toElement(); + parent.replaceChild(gender, sex); +} + //--------------------------------------------------------------------------------------------------------------------- void VVITConverter::ToV0_3_0() { @@ -222,3 +244,11 @@ void VVITConverter::ToV0_3_0() ConvertMeasurementsToV0_3_0(); Save(); } + +//--------------------------------------------------------------------------------------------------------------------- +void VVITConverter::ToV0_3_1() +{ + SetVersion(QStringLiteral("0.3.1")); + GenderV0_3_1(); + Save(); +} diff --git a/src/libs/ifc/xml/vvitconverter.h b/src/libs/ifc/xml/vvitconverter.h index 83a22a92f..dc9d5d07b 100644 --- a/src/libs/ifc/xml/vvitconverter.h +++ b/src/libs/ifc/xml/vvitconverter.h @@ -59,8 +59,10 @@ private: QString MUnitV0_2_0(); void ConvertMeasurementsToV0_3_0(); QDomElement AddMV0_3_0(const QString &name, qreal value); + void GenderV0_3_1(); void ToV0_3_0(); + void ToV0_3_1(); }; #endif // VVITCONVERTER_H diff --git a/src/libs/vformat/vmeasurements.cpp b/src/libs/vformat/vmeasurements.cpp index c19d5b542..f07e8c22a 100644 --- a/src/libs/vformat/vmeasurements.cpp +++ b/src/libs/vformat/vmeasurements.cpp @@ -43,7 +43,7 @@ const QString VMeasurements::TagPersonal = QStringLiteral("personal"); const QString VMeasurements::TagFamilyName = QStringLiteral("family-name"); const QString VMeasurements::TagGivenName = QStringLiteral("given-name"); const QString VMeasurements::TagBirthDate = QStringLiteral("birth-date"); -const QString VMeasurements::TagSex = QStringLiteral("sex"); +const QString VMeasurements::TagGender = QStringLiteral("gender"); const QString VMeasurements::TagEmail = QStringLiteral("email"); const QString VMeasurements::TagReadOnly = QStringLiteral("read-only"); const QString VMeasurements::TagMeasurement = QStringLiteral("m"); @@ -56,9 +56,9 @@ const QString VMeasurements::AttrDescription = QStringLiteral("description"); const QString VMeasurements::AttrName = QStringLiteral("name"); const QString VMeasurements::AttrFullName = QStringLiteral("full_name"); -const QString VMeasurements::SexMale = QStringLiteral("male"); -const QString VMeasurements::SexFemale = QStringLiteral("female"); -const QString VMeasurements::SexUnknown = QStringLiteral("unknown"); +const QString VMeasurements::GenderMale = QStringLiteral("male"); +const QString VMeasurements::GenderFemale = QStringLiteral("female"); +const QString VMeasurements::GenderUnknown = QStringLiteral("unknown"); //--------------------------------------------------------------------------------------------------------------------- VMeasurements::VMeasurements(VContainer *data) @@ -379,17 +379,17 @@ void VMeasurements::SetBirthDate(const QDate &date) } //--------------------------------------------------------------------------------------------------------------------- -SexType VMeasurements::Sex() const +GenderType VMeasurements::Gender() const { - return StrToGender(UniqueTagText(TagSex, SexUnknown)); + return StrToGender(UniqueTagText(TagGender, GenderUnknown)); } //--------------------------------------------------------------------------------------------------------------------- -void VMeasurements::SetSex(const SexType &sex) +void VMeasurements::SetGender(const GenderType &gender) { if (not ReadOnly()) { - setTagText(TagSex, GenderToStr(sex)); + setTagText(TagGender, GenderToStr(gender)); } } @@ -533,33 +533,33 @@ void VMeasurements::SetMFullName(const QString &name, const QString &text) } //--------------------------------------------------------------------------------------------------------------------- -QString VMeasurements::GenderToStr(const SexType &sex) +QString VMeasurements::GenderToStr(const GenderType &sex) { switch (sex) { - case SexType::Male: - return SexMale; - case SexType::Female: - return SexFemale; - case SexType::Unknown: + case GenderType::Male: + return GenderMale; + case GenderType::Female: + return GenderFemale; + case GenderType::Unknown: default: - return SexUnknown; + return GenderUnknown; } } //--------------------------------------------------------------------------------------------------------------------- -SexType VMeasurements::StrToGender(const QString &sex) +GenderType VMeasurements::StrToGender(const QString &sex) { - const QStringList genders = QStringList() << SexMale << SexFemale << SexUnknown; + const QStringList genders = QStringList() << GenderMale << GenderFemale << GenderUnknown; switch (genders.indexOf(sex)) { - case 0: // SexMale - return SexType::Male; - case 1: // SexFemale - return SexType::Female; - case 2: // SexUnknown + case 0: // GenderMale + return GenderType::Male; + case 1: // GenderFemale + return GenderType::Female; + case 2: // GenderUnknown default: - return SexType::Unknown; + return GenderType::Unknown; } } @@ -705,10 +705,9 @@ void VMeasurements::CreateEmptyIndividualFile(Unit unit) date.appendChild(newDate); personal.appendChild(date); - QDomElement sex = createElement(TagSex); - const QDomText newSex = createTextNode(GenderToStr(SexType::Unknown)); - sex.appendChild(newSex); - personal.appendChild(sex); + QDomElement gender = createElement(TagGender); + gender.appendChild(createTextNode(GenderToStr(GenderType::Unknown))); + personal.appendChild(gender); personal.appendChild(createElement(TagEmail)); mElement.appendChild(personal); diff --git a/src/libs/vformat/vmeasurements.h b/src/libs/vformat/vmeasurements.h index 39efb7e95..c4205e400 100644 --- a/src/libs/vformat/vmeasurements.h +++ b/src/libs/vformat/vmeasurements.h @@ -32,7 +32,7 @@ #include "../ifc/xml/vdomdocument.h" #include "../vpatterndb/vcontainer.h" -enum class SexType : char { Male, Female, Unknown }; +enum class GenderType : char { Male, Female, Unknown }; class VMeasurements : public VDomDocument { @@ -72,8 +72,8 @@ public: QDate BirthDate() const; void SetBirthDate(const QDate &date); - SexType Sex() const; - void SetSex(const SexType &sex); + GenderType Gender() const; + void SetGender(const GenderType &gender); QString Email() const; void SetEmail(const QString &text); @@ -100,7 +100,7 @@ public: static const QString TagFamilyName; static const QString TagGivenName; static const QString TagBirthDate; - static const QString TagSex; + static const QString TagGender; static const QString TagEmail; static const QString TagReadOnly; static const QString TagMeasurement; @@ -113,12 +113,12 @@ public: static const QString AttrName; static const QString AttrFullName; - static const QString SexMale; - static const QString SexFemale; - static const QString SexUnknown; + static const QString GenderMale; + static const QString GenderFemale; + static const QString GenderUnknown; - static QString GenderToStr(const SexType &sex); - static SexType StrToGender(const QString &sex); + static QString GenderToStr(const GenderType &sex); + static GenderType StrToGender(const QString &sex); QStringList ListAll() const; QStringList ListKnown() const;