Final measurement printout on pattern piece. Closes #85

This commit is contained in:
Roman Telezhynskyi 2021-01-23 21:37:36 +02:00
parent c47664d86c
commit 8b15f4aed6
7 changed files with 71 additions and 14 deletions

View File

@ -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.

View File

@ -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<VFinalMeasurement> FinalMeasurements() const;

View File

@ -4820,6 +4820,7 @@ void MainWindow::CreateActions()
if (result == QDialog::Accepted)
{
doc->SetFinalMeasurements(dialogFMeasurements->FinalMeasurements());
emit doc->UpdatePatternLabel();
}
dialogFMeasurements->close();
});

View File

@ -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<QString, QString> PreparePlaceholders(const VAbstractPattern *doc, const VC
placeholders.insert(pl_userMaterial + number, value);
}
const QMap<QString, QSharedPointer<VMeasurement> > 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<QString, QSharedPointer<VMeasurement> > 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<VFinalMeasurement> measurements = doc->GetFinalMeasurements();
const VContainer completeData = doc->GetCompleteData();
for (int i=0; i < measurements.size(); ++i)
{
const VFinalMeasurement &m = measurements.at(i);
try
{
QScopedPointer<Calculator> 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

View File

@ -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");

View File

@ -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;

View File

@ -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 <QDir>
@ -549,14 +550,40 @@ void DialogEditLabel::InitPlaceholders()
m_placeholders.insert(pl_userMaterial + number, qMakePair(materialDescription + number, value));
}
const QMap<QString, QSharedPointer<VMeasurement> > 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<QString, QSharedPointer<VMeasurement> > 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<VFinalMeasurement> 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<Calculator> 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