From 8b15f4aed65aa385043d1a4c19a105b779dc306d Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sat, 23 Jan 2021 21:37:36 +0200 Subject: [PATCH] Final measurement printout on pattern piece. Closes #85 --- ChangeLog.txt | 1 + .../dialogs/dialogfinalmeasurements.h | 2 +- src/app/valentina/mainwindow.cpp | 1 + src/libs/vlayout/vtextmanager.cpp | 38 ++++++++++++++--- src/libs/vmisc/def.cpp | 1 + src/libs/vmisc/def.h | 1 + .../dialogs/support/dialogeditlabel.cpp | 41 +++++++++++++++---- 7 files changed, 71 insertions(+), 14 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index e7efbc488..b52c4069d 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -12,6 +12,7 @@ - New warning. Grainline is not valid. - [smart-pattern/valentina#87] Add support for TIFF format. - [smart-pattern/valentina#88] Allow insertion of multiple nodes by setting their number. +- [smart-pattern/valentina#85] Final measurement printout on pattern piece. # Version 0.7.41 Dec 4, 2020 - Bug fixes. diff --git a/src/app/valentina/dialogs/dialogfinalmeasurements.h b/src/app/valentina/dialogs/dialogfinalmeasurements.h index cd0d222d5..f143d0256 100644 --- a/src/app/valentina/dialogs/dialogfinalmeasurements.h +++ b/src/app/valentina/dialogs/dialogfinalmeasurements.h @@ -45,7 +45,7 @@ class DialogFinalMeasurements : public QDialog Q_OBJECT public: - DialogFinalMeasurements(VPattern *doc, QWidget *parent = nullptr); + explicit DialogFinalMeasurements(VPattern *doc, QWidget *parent = nullptr); virtual ~DialogFinalMeasurements(); QVector FinalMeasurements() const; diff --git a/src/app/valentina/mainwindow.cpp b/src/app/valentina/mainwindow.cpp index d93ee939e..9b84c3c87 100644 --- a/src/app/valentina/mainwindow.cpp +++ b/src/app/valentina/mainwindow.cpp @@ -4820,6 +4820,7 @@ void MainWindow::CreateActions() if (result == QDialog::Accepted) { doc->SetFinalMeasurements(dialogFMeasurements->FinalMeasurements()); + emit doc->UpdatePatternLabel(); } dialogFMeasurements->close(); }); diff --git a/src/libs/vlayout/vtextmanager.cpp b/src/libs/vlayout/vtextmanager.cpp index 28e9f36c7..ddabcc98c 100644 --- a/src/libs/vlayout/vtextmanager.cpp +++ b/src/libs/vlayout/vtextmanager.cpp @@ -43,6 +43,7 @@ # include "../vmisc/vdatastreamenum.h" #endif #include "../vpatterndb/vcontainer.h" +#include "../vpatterndb/calculator.h" #include "vtextmanager.h" const quint32 TextLine::streamHeader = 0xA3881E49; // CRC-32Q string "TextLine" @@ -234,13 +235,38 @@ QMap PreparePlaceholders(const VAbstractPattern *doc, const VC placeholders.insert(pl_userMaterial + number, value); } - const QMap > measurements = data->DataMeasurements(); - auto i = measurements.constBegin(); - while (i != measurements.constEnd()) { - QString description = i.value()->GetGuiText().isEmpty() ? i.key() : i.value()->GetGuiText(); - placeholders.insert(pl_measurement + i.key(), QString::number(*i.value()->GetValue())); - ++i; + const QMap > measurements = data->DataMeasurements(); + auto i = measurements.constBegin(); + while (i != measurements.constEnd()) + { + QString description = i.value()->GetGuiText().isEmpty() ? i.key() : i.value()->GetGuiText(); + placeholders.insert(pl_measurement + i.key(), QString::number(*i.value()->GetValue())); + ++i; + } + } + + { + const QVector measurements = doc->GetFinalMeasurements(); + const VContainer completeData = doc->GetCompleteData(); + + for (int i=0; i < measurements.size(); ++i) + { + const VFinalMeasurement &m = measurements.at(i); + + try + { + QScopedPointer cal(new Calculator()); + const qreal result = cal->EvalFormula(completeData.DataVariables(), m.formula); + + placeholders.insert(pl_finalMeasurement + m.name, QString::number(result)); + } + catch (qmu::QmuParserError &e) + { + qCritical("%s\n\n%s", qUtf8Printable(QObject::tr("Failed to prepare final measurement placeholder.")), + qUtf8Printable(QObject::tr("Parser error at line %1: %2.").arg(i+1).arg(e.GetMsg()))); + } + } } // Piece tags diff --git a/src/libs/vmisc/def.cpp b/src/libs/vmisc/def.cpp index ae80816f6..365850573 100644 --- a/src/libs/vmisc/def.cpp +++ b/src/libs/vmisc/def.cpp @@ -169,6 +169,7 @@ const QString pl_mInterlining = QStringLiteral("mInterlining"); const QString pl_wCut = QStringLiteral("wCut"); const QString pl_wOnFold = QStringLiteral("wOnFold"); const QString pl_measurement = QStringLiteral("measurement_"); +const QString pl_finalMeasurement = QStringLiteral("finalMeasurement_"); const QString cursorArrowOpenHand = QStringLiteral("://cursor/cursor-arrow-openhand.png"); const QString cursorArrowCloseHand = QStringLiteral("://cursor/cursor-arrow-closehand.png"); diff --git a/src/libs/vmisc/def.h b/src/libs/vmisc/def.h index 6df4b410b..664d3f2c1 100644 --- a/src/libs/vmisc/def.h +++ b/src/libs/vmisc/def.h @@ -437,6 +437,7 @@ extern const QString pl_mInterlining; extern const QString pl_wCut; extern const QString pl_wOnFold; extern const QString pl_measurement; +extern const QString pl_finalMeasurement; // Don't forget to syncronize with XSD schema. const int userMaterialPlaceholdersQuantity = 20; diff --git a/src/libs/vtools/dialogs/support/dialogeditlabel.cpp b/src/libs/vtools/dialogs/support/dialogeditlabel.cpp index 54da3386c..ab65cf3c2 100644 --- a/src/libs/vtools/dialogs/support/dialogeditlabel.cpp +++ b/src/libs/vtools/dialogs/support/dialogeditlabel.cpp @@ -36,6 +36,7 @@ #include "../vpatterndb/vcontainer.h" #include "../vpatterndb/vpiece.h" #include "../vpatterndb/floatItemData/vpiecelabeldata.h" +#include "../vpatterndb/calculator.h" #include "../tools/dialogtool.h" #include @@ -549,14 +550,40 @@ void DialogEditLabel::InitPlaceholders() m_placeholders.insert(pl_userMaterial + number, qMakePair(materialDescription + number, value)); } - const QMap > measurements = m_data->DataMeasurements(); - auto i = measurements.constBegin(); - while (i != measurements.constEnd()) { - QString description = i.value()->GetGuiText().isEmpty() ? i.key() : i.value()->GetGuiText(); - m_placeholders.insert(pl_measurement + i.key(), qMakePair(tr("Measurement: %1").arg(description), - QString::number(*i.value()->GetValue()))); - ++i; + const QMap > measurements = m_data->DataMeasurements(); + auto i = measurements.constBegin(); + while (i != measurements.constEnd()) + { + QString description = i.value()->GetGuiText().isEmpty() ? i.key() : i.value()->GetGuiText(); + m_placeholders.insert(pl_measurement + i.key(), qMakePair(tr("Measurement: %1").arg(description), + QString::number(*i.value()->GetValue()))); + ++i; + } + } + + { + const QVector measurements = m_doc->GetFinalMeasurements(); + const VContainer completeData = m_doc->GetCompleteData(); + + for (int i=0; i < measurements.size(); ++i) + { + const VFinalMeasurement &m = measurements.at(i); + + try + { + QScopedPointer cal(new Calculator()); + const qreal result = cal->EvalFormula(completeData.DataVariables(), m.formula); + + m_placeholders.insert(pl_finalMeasurement + m.name, qMakePair(tr("Final measurement: %1").arg(m.name), + QString::number(result))); + } + catch (qmu::QmuParserError &e) + { + qCritical("%s\n\n%s", qUtf8Printable(QObject::tr("Failed to prepare final measurement placeholder.")), + qUtf8Printable(QObject::tr("Parser error at line %1: %2.").arg(i+1).arg(e.GetMsg()))); + } + } } // Piece tags