Extend placeholders list with list of measurements.

This commit is contained in:
Roman Telezhynskyi 2020-10-16 13:43:54 +03:00
parent 92c3f75e02
commit d10f20f399
14 changed files with 93 additions and 49 deletions

View File

@ -495,7 +495,7 @@ void DialogPatternProperties::EditLabel()
} }
} }
DialogEditLabel editor(doc); DialogEditLabel editor(doc, pattern);
templateDataChanged ? editor.SetTemplate(templateLines) : editor.SetTemplate(doc->GetPatternLabelTemplate()); templateDataChanged ? editor.SetTemplate(templateLines) : editor.SetTemplate(doc->GetPatternLabelTemplate());

View File

@ -4947,7 +4947,7 @@ void MainWindow::CreateActions()
connect(ui->actionLabelTemplateEditor, &QAction::triggered, this, [this]() connect(ui->actionLabelTemplateEditor, &QAction::triggered, this, [this]()
{ {
DialogEditLabel editor(doc); DialogEditLabel editor(doc, pattern);
editor.exec(); editor.exec();
}); });

View File

@ -697,7 +697,7 @@ void VLayoutPiece::SetPieceText(const QString& qsName, const VPieceLabelData& da
// generate text // generate text
d->m_tmDetail.SetFont(font); d->m_tmDetail.SetFont(font);
d->m_tmDetail.SetFontSize(data.GetFontSize()); d->m_tmDetail.SetFontSize(data.GetFontSize());
d->m_tmDetail.Update(qsName, data); d->m_tmDetail.Update(qsName, data, pattern);
// this will generate the lines of text // this will generate the lines of text
d->m_tmDetail.SetFontSize(data.GetFontSize()); d->m_tmDetail.SetFontSize(data.GetFontSize());
d->m_tmDetail.FitFontSize(labelWidth, labelHeight); d->m_tmDetail.FitFontSize(labelWidth, labelHeight);
@ -754,7 +754,7 @@ void VLayoutPiece::SetPatternInfo(VAbstractPattern* pDoc, const VPatternLabelDat
d->m_tmPattern.SetFont(font); d->m_tmPattern.SetFont(font);
d->m_tmPattern.SetFontSize(geom.GetFontSize()); d->m_tmPattern.SetFontSize(geom.GetFontSize());
d->m_tmPattern.Update(pDoc); d->m_tmPattern.Update(pDoc, pattern);
// generate lines of text // generate lines of text
d->m_tmPattern.SetFontSize(geom.GetFontSize()); d->m_tmPattern.SetFontSize(geom.GetFontSize());

View File

@ -166,9 +166,10 @@ namespace
{ {
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QMap<QString, QString> PreparePlaceholders(const VAbstractPattern *doc) QMap<QString, QString> PreparePlaceholders(const VAbstractPattern *doc, const VContainer *data)
{ {
SCASSERT(doc != nullptr) SCASSERT(doc != nullptr)
SCASSERT(data != nullptr)
QMap<QString, QString> placeholders; QMap<QString, QString> placeholders;
@ -233,6 +234,15 @@ QMap<QString, QString> PreparePlaceholders(const VAbstractPattern *doc)
placeholders.insert(pl_userMaterial + number, value); 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;
}
// Piece tags // Piece tags
placeholders.insert(pl_pLetter, QString()); placeholders.insert(pl_pLetter, QString());
placeholders.insert(pl_pAnnotation, QString()); placeholders.insert(pl_pAnnotation, QString());
@ -474,11 +484,11 @@ void VTextManager::FitFontSize(qreal fW, qreal fH)
* @param qsName detail name * @param qsName detail name
* @param data reference to the detail data * @param data reference to the detail data
*/ */
void VTextManager::Update(const QString& qsName, const VPieceLabelData& data) void VTextManager::Update(const QString& qsName, const VPieceLabelData& data, const VContainer *pattern)
{ {
m_liLines.clear(); m_liLines.clear();
QMap<QString, QString> placeholders = PreparePlaceholders(qApp->getCurrentDocument()); QMap<QString, QString> placeholders = PreparePlaceholders(qApp->getCurrentDocument(), pattern);
InitPiecePlaceholders(placeholders, qsName, data); InitPiecePlaceholders(placeholders, qsName, data);
QVector<VLabelTemplateLine> lines = data.GetLabelTemplate(); QVector<VLabelTemplateLine> lines = data.GetLabelTemplate();
@ -496,7 +506,7 @@ void VTextManager::Update(const QString& qsName, const VPieceLabelData& data)
* @brief VTextManager::Update updates the text lines with pattern info * @brief VTextManager::Update updates the text lines with pattern info
* @param pDoc pointer to the abstract pattern object * @param pDoc pointer to the abstract pattern object
*/ */
void VTextManager::Update(VAbstractPattern *pDoc) void VTextManager::Update(VAbstractPattern *pDoc, const VContainer *pattern)
{ {
m_liLines.clear(); m_liLines.clear();
@ -508,7 +518,7 @@ void VTextManager::Update(VAbstractPattern *pDoc)
return; // Nothing to parse return; // Nothing to parse
} }
const QMap<QString, QString> placeholders = PreparePlaceholders(pDoc); const QMap<QString, QString> placeholders = PreparePlaceholders(pDoc, pattern);
for (int i=0; i<lines.size(); ++i) for (int i=0; i<lines.size(); ++i)
{ {

View File

@ -41,6 +41,7 @@
class VPieceLabelData; class VPieceLabelData;
class VAbstractPattern; class VAbstractPattern;
class VContainer;
#define MIN_FONT_SIZE 5 #define MIN_FONT_SIZE 5
#define MAX_FONT_SIZE 128 #define MAX_FONT_SIZE 128
@ -88,8 +89,8 @@ public:
int GetSourceLinesCount() const; int GetSourceLinesCount() const;
const TextLine& GetSourceLine(int i) const; const TextLine& GetSourceLine(int i) const;
void Update(const QString& qsName, const VPieceLabelData& data); void Update(const QString& qsName, const VPieceLabelData& data, const VContainer *pattern);
void Update(VAbstractPattern* pDoc); void Update(VAbstractPattern* pDoc, const VContainer *pattern);
friend QDataStream& operator<<(QDataStream& dataStream, const VTextManager& data); friend QDataStream& operator<<(QDataStream& dataStream, const VTextManager& data);
friend QDataStream& operator>>(QDataStream& dataStream, VTextManager& data); friend QDataStream& operator>>(QDataStream& dataStream, VTextManager& data);

View File

@ -181,34 +181,45 @@ const QString pl_mInterfacing = QStringLiteral("mInterfacing");
const QString pl_mInterlining = QStringLiteral("mInterlining"); const QString pl_mInterlining = QStringLiteral("mInterlining");
const QString pl_wCut = QStringLiteral("wCut"); const QString pl_wCut = QStringLiteral("wCut");
const QString pl_wOnFold = QStringLiteral("wOnFold"); const QString pl_wOnFold = QStringLiteral("wOnFold");
const QString pl_measurement = QStringLiteral("measurement_");
const QStringList labelTemplatePlaceholders = QStringList() << pl_size const QStringList labelTemplatePlaceholders = {
<< pl_height pl_size,
<< pl_date pl_height,
<< pl_time pl_hip,
<< pl_patternName pl_waist,
<< pl_patternNumber pl_date,
<< pl_author pl_time,
<< pl_customer pl_birthDate,
<< pl_userMaterial pl_patternName,
<< pl_pExt pl_patternNumber,
<< pl_pFileName pl_author,
<< pl_mFileName pl_customer,
<< pl_mExt pl_email,
<< pl_pLetter pl_userMaterial,
<< pl_pAnnotation pl_pExt,
<< pl_pOrientation pl_pUnits,
<< pl_pRotation pl_pFileName,
<< pl_pTilt pl_mFileName,
<< pl_pFoldPosition pl_mExt,
<< pl_pName pl_mUnits,
<< pl_pQuantity pl_mSizeUnits,
<< pl_mFabric pl_pLetter,
<< pl_mLining pl_pAnnotation,
<< pl_mInterfacing pl_pOrientation,
<< pl_mInterlining pl_pRotation,
<< pl_wCut pl_pTilt,
<< pl_wOnFold; pl_pFoldPosition,
pl_pName,
pl_pQuantity,
pl_mFabric,
pl_mLining,
pl_mInterfacing,
pl_mInterlining,
pl_wCut,
pl_wOnFold,
pl_measurement
};
const QString cursorArrowOpenHand = QStringLiteral("://cursor/cursor-arrow-openhand.png"); const QString cursorArrowOpenHand = QStringLiteral("://cursor/cursor-arrow-openhand.png");
const QString cursorArrowCloseHand = QStringLiteral("://cursor/cursor-arrow-closehand.png"); const QString cursorArrowCloseHand = QStringLiteral("://cursor/cursor-arrow-closehand.png");

View File

@ -435,6 +435,7 @@ extern const QString pl_mInterfacing;
extern const QString pl_mInterlining; extern const QString pl_mInterlining;
extern const QString pl_wCut; extern const QString pl_wCut;
extern const QString pl_wOnFold; extern const QString pl_wOnFold;
extern const QString pl_measurement;
// Don't forget to syncronize with XSD schema. // Don't forget to syncronize with XSD schema.
const int userMaterialPlaceholdersQuantity = 20; const int userMaterialPlaceholdersQuantity = 20;

View File

@ -541,17 +541,24 @@ void VTranslateVars::InitPlaceholder()
{ {
placeholders.insert(pl_size, translate("VTranslateVars", "size", "placeholder")); placeholders.insert(pl_size, translate("VTranslateVars", "size", "placeholder"));
placeholders.insert(pl_height, translate("VTranslateVars", "height", "placeholder")); placeholders.insert(pl_height, translate("VTranslateVars", "height", "placeholder"));
placeholders.insert(pl_hip, translate("VTranslateVars", "hip", "placeholder"));
placeholders.insert(pl_waist, translate("VTranslateVars", "waist", "placeholder"));
placeholders.insert(pl_date, translate("VTranslateVars", "date", "placeholder")); placeholders.insert(pl_date, translate("VTranslateVars", "date", "placeholder"));
placeholders.insert(pl_time, translate("VTranslateVars", "time", "placeholder")); placeholders.insert(pl_time, translate("VTranslateVars", "time", "placeholder"));
placeholders.insert(pl_birthDate, translate("VTranslateVars", "birthDate", "placeholder"));
placeholders.insert(pl_patternName, translate("VTranslateVars", "patternName", "placeholder")); placeholders.insert(pl_patternName, translate("VTranslateVars", "patternName", "placeholder"));
placeholders.insert(pl_patternNumber, translate("VTranslateVars", "patternNumber", "placeholder")); placeholders.insert(pl_patternNumber, translate("VTranslateVars", "patternNumber", "placeholder"));
placeholders.insert(pl_author, translate("VTranslateVars", "author", "placeholder")); placeholders.insert(pl_author, translate("VTranslateVars", "author", "placeholder"));
placeholders.insert(pl_customer, translate("VTranslateVars", "customer", "placeholder")); placeholders.insert(pl_customer, translate("VTranslateVars", "customer", "placeholder"));
placeholders.insert(pl_email, translate("VTranslateVars", "email", "placeholder"));
placeholders.insert(pl_userMaterial, translate("VTranslateVars", "userMaterial", "placeholder")); placeholders.insert(pl_userMaterial, translate("VTranslateVars", "userMaterial", "placeholder"));
placeholders.insert(pl_pExt, translate("VTranslateVars", "pExt", "placeholder")); placeholders.insert(pl_pExt, translate("VTranslateVars", "pExt", "placeholder"));
placeholders.insert(pl_pUnits, translate("VTranslateVars", "pUnits", "placeholder"));
placeholders.insert(pl_pFileName, translate("VTranslateVars", "pFileName", "placeholder")); placeholders.insert(pl_pFileName, translate("VTranslateVars", "pFileName", "placeholder"));
placeholders.insert(pl_mFileName, translate("VTranslateVars", "mFileName", "placeholder")); placeholders.insert(pl_mFileName, translate("VTranslateVars", "mFileName", "placeholder"));
placeholders.insert(pl_mExt, translate("VTranslateVars", "mExt", "placeholder")); placeholders.insert(pl_mExt, translate("VTranslateVars", "mExt", "placeholder"));
placeholders.insert(pl_mUnits, translate("VTranslateVars", "mUnits", "placeholder"));
placeholders.insert(pl_mSizeUnits, translate("VTranslateVars", "mSizeUnits", "placeholder"));
placeholders.insert(pl_pLetter, translate("VTranslateVars", "pLetter", "placeholder")); placeholders.insert(pl_pLetter, translate("VTranslateVars", "pLetter", "placeholder"));
placeholders.insert(pl_pAnnotation, translate("VTranslateVars", "pAnnotation", "placeholder")); placeholders.insert(pl_pAnnotation, translate("VTranslateVars", "pAnnotation", "placeholder"));
placeholders.insert(pl_pOrientation, translate("VTranslateVars", "pOrientation", "placeholder")); placeholders.insert(pl_pOrientation, translate("VTranslateVars", "pOrientation", "placeholder"));
@ -566,6 +573,7 @@ void VTranslateVars::InitPlaceholder()
placeholders.insert(pl_mInterlining, translate("VTranslateVars", "mInterlining", "placeholder")); placeholders.insert(pl_mInterlining, translate("VTranslateVars", "mInterlining", "placeholder"));
placeholders.insert(pl_wCut, translate("VTranslateVars", "wCut", "placeholder")); placeholders.insert(pl_wCut, translate("VTranslateVars", "wCut", "placeholder"));
placeholders.insert(pl_wOnFold, translate("VTranslateVars", "wOnFold", "placeholder")); placeholders.insert(pl_wOnFold, translate("VTranslateVars", "wOnFold", "placeholder"));
placeholders.insert(pl_measurement, translate("VTranslateVars", "measurement", "placeholder"));
} }
#undef translate #undef translate

View File

@ -45,11 +45,12 @@
#include <QDate> #include <QDate>
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
DialogEditLabel::DialogEditLabel(VAbstractPattern *doc, QWidget *parent) DialogEditLabel::DialogEditLabel(VAbstractPattern *doc, const VContainer *data, QWidget *parent)
: QDialog(parent), : QDialog(parent),
ui(new Ui::DialogEditLabel), ui(new Ui::DialogEditLabel),
m_placeholdersMenu(new QMenu(this)), m_placeholdersMenu(new QMenu(this)),
m_doc(doc), m_doc(doc),
m_data(data),
m_placeholders() m_placeholders()
{ {
ui->setupUi(this); ui->setupUi(this);
@ -555,6 +556,16 @@ void DialogEditLabel::InitPlaceholders()
m_placeholders.insert(pl_userMaterial + number, qMakePair(materialDescription + number, value)); 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;
}
// Piece tags // Piece tags
m_placeholders.insert(pl_pLetter, qMakePair(tr("Piece letter"), QString())); m_placeholders.insert(pl_pLetter, qMakePair(tr("Piece letter"), QString()));
m_placeholders.insert(pl_pAnnotation, qMakePair(tr("Piece annotation"), QString())); m_placeholders.insert(pl_pAnnotation, qMakePair(tr("Piece annotation"), QString()));

View File

@ -42,13 +42,14 @@ struct VLabelTemplateLine;
class QMenu; class QMenu;
class VAbstractPattern; class VAbstractPattern;
class VPiece; class VPiece;
class VContainer;
class DialogEditLabel : public QDialog class DialogEditLabel : public QDialog
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit DialogEditLabel(VAbstractPattern *doc, QWidget *parent = nullptr); explicit DialogEditLabel(VAbstractPattern *doc, const VContainer *data, QWidget *parent = nullptr);
virtual ~DialogEditLabel(); virtual ~DialogEditLabel();
QVector<VLabelTemplateLine> GetTemplate() const; QVector<VLabelTemplateLine> GetTemplate() const;
@ -75,6 +76,7 @@ private:
Ui::DialogEditLabel *ui; Ui::DialogEditLabel *ui;
QMenu *m_placeholdersMenu; QMenu *m_placeholdersMenu;
VAbstractPattern *m_doc; VAbstractPattern *m_doc;
const VContainer *m_data;
QMap<QString, QPair<QString, QString>> m_placeholders; QMap<QString, QPair<QString, QString>> m_placeholders;

View File

@ -2428,7 +2428,7 @@ void DialogSeamAllowance::PatternPinPointChanged()
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void DialogSeamAllowance::EditLabel() void DialogSeamAllowance::EditLabel()
{ {
DialogEditLabel editor(qApp->getCurrentDocument()); DialogEditLabel editor(qApp->getCurrentDocument(), data);
editor.SetTemplate(m_templateLines); editor.SetTemplate(m_templateLines);
editor.SetPiece(GetPiece()); editor.SetPiece(GetPiece());

View File

@ -614,7 +614,7 @@ void VToolSeamAllowance::UpdateDetailLabel()
if (PrepareLabelData(labelData, pins, m_dataLabel, pos, labelAngle)) if (PrepareLabelData(labelData, pins, m_dataLabel, pos, labelAngle))
{ {
m_dataLabel->UpdateData(detail.GetName(), labelData); m_dataLabel->UpdateData(detail.GetName(), labelData, getData());
UpdateLabelItem(m_dataLabel, pos, labelAngle); UpdateLabelItem(m_dataLabel, pos, labelAngle);
} }
} }
@ -641,7 +641,7 @@ void VToolSeamAllowance::UpdatePatternInfo()
if (PrepareLabelData(geom, pins, m_patternInfo, pos, labelAngle)) if (PrepareLabelData(geom, pins, m_patternInfo, pos, labelAngle))
{ {
m_patternInfo->UpdateData(doc); m_patternInfo->UpdateData(doc, getData());
UpdateLabelItem(m_patternInfo, pos, labelAngle); UpdateLabelItem(m_patternInfo, pos, labelAngle);
} }
} }

View File

@ -317,9 +317,9 @@ bool VTextGraphicsItem::IsContained(QRectF rectBB, qreal dRot, qreal &dX, qreal
* @param qsName name of detail * @param qsName name of detail
* @param data reference to VPatternPieceData * @param data reference to VPatternPieceData
*/ */
void VTextGraphicsItem::UpdateData(const QString &qsName, const VPieceLabelData &data) void VTextGraphicsItem::UpdateData(const QString &qsName, const VPieceLabelData &data, const VContainer *pattern)
{ {
m_tm.Update(qsName, data); m_tm.Update(qsName, data, pattern);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -327,9 +327,9 @@ void VTextGraphicsItem::UpdateData(const QString &qsName, const VPieceLabelData
* @brief VTextGraphicsItem::UpdateData Updates the pattern label * @brief VTextGraphicsItem::UpdateData Updates the pattern label
* @param pDoc pointer to the pattern object * @param pDoc pointer to the pattern object
*/ */
void VTextGraphicsItem::UpdateData(VAbstractPattern* pDoc) void VTextGraphicsItem::UpdateData(VAbstractPattern* pDoc, const VContainer *pattern)
{ {
m_tm.Update(pDoc); m_tm.Update(pDoc, pattern);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -65,8 +65,8 @@ public:
int GetFontSize() const; int GetFontSize() const;
void SetSize(qreal fW, qreal fH); void SetSize(qreal fW, qreal fH);
bool IsContained(QRectF rectBB, qreal dRot, qreal& dX, qreal& dY) const; bool IsContained(QRectF rectBB, qreal dRot, qreal& dX, qreal& dY) const;
void UpdateData(const QString& qsName, const VPieceLabelData& data); void UpdateData(const QString& qsName, const VPieceLabelData& data, const VContainer *pattern);
void UpdateData(VAbstractPattern* pDoc); void UpdateData(VAbstractPattern* pDoc, const VContainer *pattern);
int GetTextLines() const; int GetTextLines() const;
protected: protected: