From bfe327ee132e480b510eb90eddd662d04a2ff387 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Tue, 19 Sep 2017 16:07:48 +0300 Subject: [PATCH] If pattern linked to individual measurements it should get customer name from it. --HG-- branch : develop --- src/app/tape/tmainwindow.cpp | 34 +++------ src/app/tape/tmainwindow.h | 3 +- src/app/tape/tmainwindow.ui | 45 +++--------- .../dialogs/dialogpatternproperties.cpp | 17 ++++- src/app/valentina/mainwindow.cpp | 8 +++ src/libs/ifc/schema.qrc | 1 + .../schema/individual_measurements/v0.4.0.xsd | 71 +++++++++++++++++++ src/libs/ifc/xml/vvitconverter.cpp | 67 ++++++++++++++++- src/libs/ifc/xml/vvitconverter.h | 10 +-- src/libs/vformat/vmeasurements.cpp | 29 ++------ src/libs/vformat/vmeasurements.h | 10 +-- src/libs/vlayout/vtextmanager.cpp | 11 ++- src/libs/vmisc/vabstractapplication.cpp | 1 + src/libs/vmisc/vabstractapplication.h | 16 +++++ .../dialogs/support/dialogeditlabel.cpp | 14 +++- 15 files changed, 230 insertions(+), 107 deletions(-) create mode 100644 src/libs/ifc/schema/individual_measurements/v0.4.0.xsd diff --git a/src/app/tape/tmainwindow.cpp b/src/app/tape/tmainwindow.cpp index 294e7c523..eaee4feee 100644 --- a/src/app/tape/tmainwindow.cpp +++ b/src/app/tape/tmainwindow.cpp @@ -110,8 +110,7 @@ TMainWindow::TMainWindow(QWidget *parent) ui->lineEditFind->setClearButtonEnabled(true); ui->lineEditName->setClearButtonEnabled(true); ui->lineEditFullName->setClearButtonEnabled(true); - ui->lineEditGivenName->setClearButtonEnabled(true); - ui->lineEditFamilyName->setClearButtonEnabled(true); + ui->lineEditCustomerName->setClearButtonEnabled(true); ui->lineEditEmail->setClearButtonEnabled(true); ui->lineEditFind->installEventFilter(this); @@ -990,21 +989,11 @@ void TMainWindow::OpenAt(QAction *where) #endif //defined(Q_OS_MAC) //--------------------------------------------------------------------------------------------------------------------- -void TMainWindow::SaveGivenName() +void TMainWindow::SaveCustomerName() { - if (m->GivenName() != ui->lineEditGivenName->text()) + if (m->Customer() != ui->lineEditCustomerName->text()) { - m->SetGivenName(ui->lineEditGivenName->text()); - MeasurementsWasSaved(false); - } -} - -//--------------------------------------------------------------------------------------------------------------------- -void TMainWindow::SaveFamilyName() -{ - if (m->FamilyName() != ui->lineEditFamilyName->text()) - { - m->SetFamilyName(ui->lineEditFamilyName->text()); + m->SetCustomer(ui->lineEditCustomerName->text()); MeasurementsWasSaved(false); } } @@ -2019,12 +2008,10 @@ void TMainWindow::InitWindow() HackWidget(&ui->pushButtonGrow); // Tab Information - HackWidget(&ui->lineEditGivenName); - HackWidget(&ui->lineEditFamilyName); + HackWidget(&ui->lineEditCustomerName); HackWidget(&ui->comboBoxGender); HackWidget(&ui->lineEditEmail); - HackWidget(&ui->labelGivenName); - HackWidget(&ui->labelFamilyName); + HackWidget(&ui->labelCustomerName); HackWidget(&ui->labelBirthDate); HackWidget(&ui->dateEditBirthDate); HackWidget(&ui->labelGender); @@ -2061,8 +2048,7 @@ void TMainWindow::InitWindow() { ui->labelMType->setText(tr("Individual measurements")); - ui->lineEditGivenName->setEnabled(true); - ui->lineEditFamilyName->setEnabled(true); + ui->lineEditCustomerName->setEnabled(true); ui->dateEditBirthDate->setEnabled(true); ui->comboBoxGender->setEnabled(true); ui->lineEditEmail->setEnabled(true); @@ -2081,8 +2067,7 @@ void TMainWindow::InitWindow() HackWidget(&ui->labelBaseHeight); HackWidget(&ui->labelBaseHeightValue); - ui->lineEditGivenName->setText(m->GivenName()); - ui->lineEditFamilyName->setText(m->FamilyName()); + ui->lineEditCustomerName->setText(m->Customer()); ui->comboBoxGender->clear(); InitGender(ui->comboBoxGender); @@ -2098,8 +2083,7 @@ void TMainWindow::InitWindow() ui->lineEditEmail->setText(m->Email()); - connect(ui->lineEditGivenName, &QLineEdit::editingFinished, this, &TMainWindow::SaveGivenName); - connect(ui->lineEditFamilyName, &QLineEdit::editingFinished, this, &TMainWindow::SaveFamilyName); + connect(ui->lineEditCustomerName, &QLineEdit::editingFinished, this, &TMainWindow::SaveCustomerName); connect(ui->lineEditEmail, &QLineEdit::editingFinished, this, &TMainWindow::SaveEmail); connect(ui->comboBoxGender, static_cast(&QComboBox::currentIndexChanged), this, &TMainWindow::SaveGender); diff --git a/src/app/tape/tmainwindow.h b/src/app/tape/tmainwindow.h index fa580db88..9a3163b88 100644 --- a/src/app/tape/tmainwindow.h +++ b/src/app/tape/tmainwindow.h @@ -91,8 +91,7 @@ private slots: void OpenAt(QAction *where); #endif //defined(Q_OS_MAC) - void SaveGivenName(); - void SaveFamilyName(); + void SaveCustomerName(); void SaveEmail(); void SaveGender(int index); void SaveBirthDate(const QDate & date); diff --git a/src/app/tape/tmainwindow.ui b/src/app/tape/tmainwindow.ui index 88d0ab33c..d7717b0bd 100644 --- a/src/app/tape/tmainwindow.ui +++ b/src/app/tape/tmainwindow.ui @@ -682,14 +682,14 @@ - + - Given name: + Customer name: - + false @@ -705,36 +705,13 @@ - - - Family name: - - - - - - - false - - - - 0 - 0 - - - - Customer's family name - - - - Birth date: - + false @@ -769,14 +746,14 @@ - + Gender: - + false @@ -795,14 +772,14 @@ - + Email: - + false @@ -818,14 +795,14 @@ - + Notes: - + false @@ -850,7 +827,7 @@ 0 0 835 - 19 + 25 diff --git a/src/app/valentina/dialogs/dialogpatternproperties.cpp b/src/app/valentina/dialogs/dialogpatternproperties.cpp index f9c0680f8..a8f2b6819 100644 --- a/src/app/valentina/dialogs/dialogpatternproperties.cpp +++ b/src/app/valentina/dialogs/dialogpatternproperties.cpp @@ -180,7 +180,17 @@ DialogPatternProperties::DialogPatternProperties(VPattern *doc, VContainer *pat ui->lineEditPatternName->setText(doc->GetPatternName()); ui->lineEditPatternNumber->setText(doc->GetPatternNumber()); ui->lineEditCompanyName->setText(doc->GetCompanyName()); - ui->lineEditCustomerName->setText(doc->GetCustomerName()); + + if (qApp->patternType() == MeasurementsType::Individual) + { + ui->lineEditCustomerName->setText(qApp->GetCustomerName()); + ui->lineEditCustomerName->setReadOnly(true); + ui->lineEditCustomerName->setToolTip(tr("The customer name from individual measurements")); + } + else + { + ui->lineEditCustomerName->setText(doc->GetCustomerName()); + } connect(ui->lineEditPatternName, &QLineEdit::editingFinished, this, &DialogPatternProperties::LabelDataChanged); connect(ui->lineEditPatternNumber, &QLineEdit::editingFinished, this, &DialogPatternProperties::LabelDataChanged); @@ -601,7 +611,10 @@ void DialogPatternProperties::SaveLabelData() doc->SetPatternName(ui->lineEditPatternName->text()); doc->SetPatternNumber(ui->lineEditPatternNumber->text()); doc->SetCompanyName(ui->lineEditCompanyName->text()); - doc->SetCustomerName(ui->lineEditCustomerName->text()); + if (qApp->patternType() != MeasurementsType::Individual) + { + doc->SetCustomerName(ui->lineEditCustomerName->text()); + } doc->SetLabelDateFormat(ui->comboBoxDateFormat->currentText()); doc->SetLabelTimeFormat(ui->comboBoxTimeFormat->currentText()); diff --git a/src/app/valentina/mainwindow.cpp b/src/app/valentina/mainwindow.cpp index d1576778f..23e4f8acc 100644 --- a/src/app/valentina/mainwindow.cpp +++ b/src/app/valentina/mainwindow.cpp @@ -455,6 +455,10 @@ bool MainWindow::LoadMeasurements(const QString &path) try { qApp->setPatternType(m->Type()); + if (m->Type() == MeasurementsType::Individual) + { + qApp->SetCustomerName(m->Customer()); + } ToolBarOption(); pattern->ClearVariables(VarType::Measurement); m->ReadMeasurements(); @@ -510,6 +514,10 @@ bool MainWindow::UpdateMeasurements(const QString &path, int size, int height) { pattern->ClearVariables(VarType::Measurement); m->ReadMeasurements(); + if (m->Type() == MeasurementsType::Individual) + { + qApp->SetCustomerName(m->Customer()); + } } catch (VExceptionEmptyParameter &e) { diff --git a/src/libs/ifc/schema.qrc b/src/libs/ifc/schema.qrc index 9b12757fb..4a41e341d 100644 --- a/src/libs/ifc/schema.qrc +++ b/src/libs/ifc/schema.qrc @@ -48,6 +48,7 @@ schema/individual_measurements/v0.3.1.xsd schema/individual_measurements/v0.3.2.xsd schema/individual_measurements/v0.3.3.xsd + schema/individual_measurements/v0.4.0.xsd schema/label_template/v1.0.0.xsd diff --git a/src/libs/ifc/schema/individual_measurements/v0.4.0.xsd b/src/libs/ifc/schema/individual_measurements/v0.4.0.xsd new file mode 100644 index 000000000..0ea4852a6 --- /dev/null +++ b/src/libs/ifc/schema/individual_measurements/v0.4.0.xsd @@ -0,0 +1,71 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/libs/ifc/xml/vvitconverter.cpp b/src/libs/ifc/xml/vvitconverter.cpp index 8b32b688a..00b3d91a0 100644 --- a/src/libs/ifc/xml/vvitconverter.cpp +++ b/src/libs/ifc/xml/vvitconverter.cpp @@ -53,13 +53,19 @@ */ const QString VVITConverter::MeasurementMinVerStr = QStringLiteral("0.2.0"); -const QString VVITConverter::MeasurementMaxVerStr = QStringLiteral("0.3.3"); -const QString VVITConverter::CurrentSchema = QStringLiteral("://schema/individual_measurements/v0.3.3.xsd"); +const QString VVITConverter::MeasurementMaxVerStr = QStringLiteral("0.4.0"); +const QString VVITConverter::CurrentSchema = QStringLiteral("://schema/individual_measurements/v0.4.0.xsd"); //VVITConverter::MeasurementMinVer; // <== DON'T FORGET TO UPDATE TOO!!!! //VVITConverter::MeasurementMaxVer; // <== DON'T FORGET TO UPDATE TOO!!!! +// The list of all string we use for conversion +// Better to use global variables because repeating QStringLiteral blows up code size static const QString strTagRead_Only = QStringLiteral("read-only"); +static const QString strGivenName = QStringLiteral("given-name"); +static const QString strFamilyName = QStringLiteral("family-name"); +static const QString strCustomer = QStringLiteral("customer"); +static const QString strPersonal = QStringLiteral("personal"); //--------------------------------------------------------------------------------------------------------------------- VVITConverter::VVITConverter(const QString &fileName) @@ -82,6 +88,8 @@ QString VVITConverter::XSDSchema(int ver) const case (0x000302): return QStringLiteral("://schema/individual_measurements/v0.3.2.xsd"); case (0x000303): + return QStringLiteral("://schema/individual_measurements/v0.3.3.xsd"); + case (0x000400): return CurrentSchema; default: InvalidVersion(ver); @@ -112,6 +120,10 @@ void VVITConverter::ApplyPatches() ValidateXML(XSDSchema(0x000303), m_convertedFileName); V_FALLTHROUGH case (0x000303): + ToV0_4_0(); + ValidateXML(XSDSchema(0x000400), m_convertedFileName); + V_FALLTHROUGH + case (0x000400): break; default: InvalidVersion(m_ver); @@ -130,7 +142,7 @@ void VVITConverter::DowngradeToCurrentMaxVersion() bool VVITConverter::IsReadOnly() const { // Check if attribute read-only was not changed in file format - Q_STATIC_ASSERT_X(VVITConverter::MeasurementMaxVer == CONVERTER_VERSION_CHECK(0, 3, 3), + Q_STATIC_ASSERT_X(VVITConverter::MeasurementMaxVer == CONVERTER_VERSION_CHECK(0, 4, 0), "Check attribute read-only."); // Possibly in future attribute read-only will change position etc. @@ -299,6 +311,43 @@ void VVITConverter::ConvertMeasurementsToV0_3_3() } } +//--------------------------------------------------------------------------------------------------------------------- +void VVITConverter::ConverCustomerNameToV0_4_0() +{ + // Find root tag + const QDomNodeList personalList = this->elementsByTagName(strPersonal); + if (personalList.isEmpty()) + { + return; + } + + QDomNode personal = personalList.at(0); + + // Given name + QString givenName; + const QDomNodeList givenNameList = this->elementsByTagName(strGivenName); + if (not givenNameList.isEmpty()) + { + QDomNode givenNameNode = givenNameList.at(0); + givenName = givenNameNode.toElement().text(); + personal.removeChild(givenNameNode); + } + + // Family name + QString familyName; + const QDomNodeList familyNameList = this->elementsByTagName(strFamilyName); + if (not familyNameList.isEmpty()) + { + QDomNode familyNameNode = familyNameList.at(0); + familyName = familyNameNode.toElement().text(); + personal.removeChild(familyNameNode); + } + + QDomElement customer = createElement(strCustomer); + customer.appendChild(createTextNode(givenName + QLatin1Char(' ') + familyName)); + personal.insertBefore(customer, personal.firstChild()); +} + //--------------------------------------------------------------------------------------------------------------------- void VVITConverter::ToV0_3_0() { @@ -348,3 +397,15 @@ void VVITConverter::ToV0_3_3() ConvertMeasurementsToV0_3_3(); Save(); } + +//--------------------------------------------------------------------------------------------------------------------- +void VVITConverter::ToV0_4_0() +{ + // TODO. Delete if minimal supported version is 0.4.0 + Q_STATIC_ASSERT_X(VVITConverter::MeasurementMinVer < CONVERTER_VERSION_CHECK(0, 4, 0), + "Time to refactor the code."); + + SetVersion(QStringLiteral("0.4.0")); + ConverCustomerNameToV0_4_0(); + Save(); +} diff --git a/src/libs/ifc/xml/vvitconverter.h b/src/libs/ifc/xml/vvitconverter.h index 6df49c884..70640a997 100644 --- a/src/libs/ifc/xml/vvitconverter.h +++ b/src/libs/ifc/xml/vvitconverter.h @@ -48,14 +48,8 @@ public: static const QString MeasurementMaxVerStr; static const QString CurrentSchema; -// GCC 4.6 doesn't allow constexpr and const together -#if !defined(__INTEL_COMPILER) && !defined(__clang__) && defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__) <= 406 - static Q_DECL_CONSTEXPR int MeasurementMinVer = CONVERTER_VERSION_CHECK(0, 2, 0); - static Q_DECL_CONSTEXPR int MeasurementMaxVer = CONVERTER_VERSION_CHECK(0, 3, 3); -#else static Q_DECL_CONSTEXPR const int MeasurementMinVer = CONVERTER_VERSION_CHECK(0, 2, 0); - static Q_DECL_CONSTEXPR const int MeasurementMaxVer = CONVERTER_VERSION_CHECK(0, 3, 3); -#endif + static Q_DECL_CONSTEXPR const int MeasurementMaxVer = CONVERTER_VERSION_CHECK(0, 4, 0); protected: virtual int MinVer() const Q_DECL_OVERRIDE; @@ -80,11 +74,13 @@ private: void GenderV0_3_1(); void PM_SystemV0_3_2(); void ConvertMeasurementsToV0_3_3(); + void ConverCustomerNameToV0_4_0(); void ToV0_3_0(); void ToV0_3_1(); void ToV0_3_2(); void ToV0_3_3(); + void ToV0_4_0(); }; //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vformat/vmeasurements.cpp b/src/libs/vformat/vmeasurements.cpp index f108723f5..14bdce4ef 100644 --- a/src/libs/vformat/vmeasurements.cpp +++ b/src/libs/vformat/vmeasurements.cpp @@ -62,8 +62,7 @@ const QString VMeasurements::TagNotes = QStringLiteral("notes"); const QString VMeasurements::TagSize = QStringLiteral("size"); const QString VMeasurements::TagHeight = QStringLiteral("height"); const QString VMeasurements::TagPersonal = QStringLiteral("personal"); -const QString VMeasurements::TagFamilyName = QStringLiteral("family-name"); -const QString VMeasurements::TagGivenName = QStringLiteral("given-name"); +const QString VMeasurements::TagCustomer = QStringLiteral("customer"); const QString VMeasurements::TagBirthDate = QStringLiteral("birth-date"); const QString VMeasurements::TagGender = QStringLiteral("gender"); const QString VMeasurements::TagPMSystem = QStringLiteral("pm_system"); @@ -402,32 +401,17 @@ void VMeasurements::SetNotes(const QString &text) } //--------------------------------------------------------------------------------------------------------------------- -QString VMeasurements::FamilyName() const +QString VMeasurements::Customer() const { - return UniqueTagText(TagFamilyName, ""); + return UniqueTagText(TagCustomer, ""); } //--------------------------------------------------------------------------------------------------------------------- -void VMeasurements::SetFamilyName(const QString &text) +void VMeasurements::SetCustomer(const QString &text) { if (not IsReadOnly()) { - setTagText(TagFamilyName, text); - } -} - -//--------------------------------------------------------------------------------------------------------------------- -QString VMeasurements::GivenName() const -{ - return UniqueTagText(TagGivenName, ""); -} - -//--------------------------------------------------------------------------------------------------------------------- -void VMeasurements::SetGivenName(const QString &text) -{ - if (not IsReadOnly()) - { - setTagText(TagGivenName, text); + setTagText(TagCustomer, text); } } @@ -786,8 +770,7 @@ void VMeasurements::CreateEmptyIndividualFile(Unit unit) mElement.appendChild(system); QDomElement personal = createElement(TagPersonal); - personal.appendChild(createElement(TagFamilyName)); - personal.appendChild(createElement(TagGivenName)); + personal.appendChild(createElement(TagCustomer)); QDomElement date = createElement(TagBirthDate); date.appendChild(createTextNode(defBirthDate)); diff --git a/src/libs/vformat/vmeasurements.h b/src/libs/vformat/vmeasurements.h index f451e1f0a..3ad10c81e 100644 --- a/src/libs/vformat/vmeasurements.h +++ b/src/libs/vformat/vmeasurements.h @@ -72,11 +72,8 @@ public: QString Notes() const; void SetNotes(const QString &text); - QString FamilyName() const; - void SetFamilyName(const QString &text); - - QString GivenName() const; - void SetGivenName(const QString &text); + QString Customer() const; + void SetCustomer(const QString &text); QDate BirthDate() const; void SetBirthDate(const QDate &date); @@ -111,8 +108,7 @@ public: static const QString TagSize; static const QString TagHeight; static const QString TagPersonal; - static const QString TagFamilyName; - static const QString TagGivenName; + static const QString TagCustomer; static const QString TagBirthDate; static const QString TagGender; static const QString TagPMSystem; diff --git a/src/libs/vlayout/vtextmanager.cpp b/src/libs/vlayout/vtextmanager.cpp index afb02cd9e..8f46d55ca 100644 --- a/src/libs/vlayout/vtextmanager.cpp +++ b/src/libs/vlayout/vtextmanager.cpp @@ -77,7 +77,16 @@ QMap PreparePlaceholders(const VAbstractPattern *doc) placeholders.insert(pl_patternName, doc->GetPatternName()); placeholders.insert(pl_patternNumber, doc->GetPatternNumber()); placeholders.insert(pl_author, doc->GetCompanyName()); - placeholders.insert(pl_customer, doc->GetCustomerName()); + + if (qApp->patternType() == MeasurementsType::Individual) + { + placeholders.insert(pl_customer, qApp->GetCustomerName()); + } + else + { + placeholders.insert(pl_customer, doc->GetCustomerName()); + } + placeholders.insert(pl_pExt, QString("val")); placeholders.insert(pl_pFileName, QFileInfo(qApp->GetPPath()).baseName()); placeholders.insert(pl_mFileName, QFileInfo(doc->MPath()).baseName()); diff --git a/src/libs/vmisc/vabstractapplication.cpp b/src/libs/vmisc/vabstractapplication.cpp index 0321cf8fd..fca1ec123 100644 --- a/src/libs/vmisc/vabstractapplication.cpp +++ b/src/libs/vmisc/vabstractapplication.cpp @@ -58,6 +58,7 @@ VAbstractApplication::VAbstractApplication(int &argc, char **argv) currentScene(nullptr), sceneView(nullptr), doc(nullptr), + m_customerName(), openingPattern(false) { QString rules; diff --git a/src/libs/vmisc/vabstractapplication.h b/src/libs/vmisc/vabstractapplication.h index 3e4a38b3e..06dcd4f3d 100644 --- a/src/libs/vmisc/vabstractapplication.h +++ b/src/libs/vmisc/vabstractapplication.h @@ -77,6 +77,9 @@ public: MeasurementsType patternType() const; void setPatternType(const MeasurementsType &patternType); + QString GetCustomerName() const; + void SetCustomerName(const QString &name); + virtual void OpenSettings()=0; VCommonSettings *Settings(); @@ -140,6 +143,7 @@ private: VMainGraphicsView *sceneView; VAbstractPattern *doc; + QString m_customerName; /** * @brief openingPattern true when we opening pattern. If something will be wrong in formula this help understand if @@ -150,6 +154,18 @@ private: void ClearTranslation(); }; +//--------------------------------------------------------------------------------------------------------------------- +inline QString VAbstractApplication::GetCustomerName() const +{ + return m_customerName; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline void VAbstractApplication::SetCustomerName(const QString &name) +{ + m_customerName = name; +} + //--------------------------------------------------------------------------------------------------------------------- inline QString VAbstractApplication::GetPPath() const { diff --git a/src/libs/vtools/dialogs/support/dialogeditlabel.cpp b/src/libs/vtools/dialogs/support/dialogeditlabel.cpp index 16925302e..daf03a9cf 100644 --- a/src/libs/vtools/dialogs/support/dialogeditlabel.cpp +++ b/src/libs/vtools/dialogs/support/dialogeditlabel.cpp @@ -457,9 +457,17 @@ void DialogEditLabel::InitPlaceholders() m_placeholders.insert(pl_patternName, qMakePair(tr("Pattern name"), m_doc->GetPatternName())); m_placeholders.insert(pl_patternNumber, qMakePair(tr("Pattern number"), m_doc->GetPatternNumber())); - m_placeholders.insert(pl_author, qMakePair(tr("Company name or designer name"), - m_doc->GetCompanyName())); - m_placeholders.insert(pl_customer, qMakePair(tr("Customer name"), m_doc->GetCustomerName())); + m_placeholders.insert(pl_author, qMakePair(tr("Company name or designer name"), m_doc->GetCompanyName())); + + if (qApp->patternType() == MeasurementsType::Individual) + { + m_placeholders.insert(pl_customer, qMakePair(tr("Customer name"), qApp->GetCustomerName())); + } + else + { + m_placeholders.insert(pl_customer, qMakePair(tr("Customer name"), m_doc->GetCustomerName())); + } + m_placeholders.insert(pl_pExt, qMakePair(tr("Pattern extension"), QString("val"))); const QString patternFilePath = QFileInfo(qApp->GetPPath()).baseName();