2016-08-12 12:11:12 +02:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @file vpatternpiecedata.cpp
|
|
|
|
** @author Bojan Kverh
|
|
|
|
** @date July 19, 2016
|
|
|
|
**
|
|
|
|
** @brief
|
|
|
|
** @copyright
|
2017-10-05 11:20:01 +02:00
|
|
|
** This source code is part of the Valentina project, a pattern making
|
2016-08-12 12:11:12 +02:00
|
|
|
** program, whose allow create and modeling patterns of clothing.
|
|
|
|
** Copyright (C) 2013-2015 Valentina project
|
|
|
|
** <https://bitbucket.org/dismine/valentina> All Rights Reserved.
|
|
|
|
**
|
|
|
|
** Valentina is free software: you can redistribute it and/or modify
|
|
|
|
** it under the terms of the GNU General Public License as published by
|
|
|
|
** the Free Software Foundation, either version 3 of the License, or
|
|
|
|
** (at your option) any later version.
|
|
|
|
**
|
|
|
|
** Valentina is distributed in the hope that it will be useful,
|
|
|
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
** GNU General Public License for more details.
|
|
|
|
**
|
|
|
|
** You should have received a copy of the GNU General Public License
|
|
|
|
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
**
|
|
|
|
*************************************************************************/
|
|
|
|
|
2016-08-08 13:44:49 +02:00
|
|
|
#include <QDate>
|
|
|
|
#include <QFileInfo>
|
2016-07-18 22:30:14 +02:00
|
|
|
#include <QFontMetrics>
|
2016-08-08 13:44:49 +02:00
|
|
|
#include <QLatin1String>
|
|
|
|
#include <QRegularExpression>
|
2016-08-11 22:44:53 +02:00
|
|
|
#include <QApplication>
|
2017-01-25 17:07:18 +01:00
|
|
|
#include <QDebug>
|
2016-07-18 22:30:14 +02:00
|
|
|
|
2016-08-08 13:44:49 +02:00
|
|
|
#include "../ifc/xml/vabstractpattern.h"
|
2017-02-23 10:37:19 +01:00
|
|
|
#include "../vpatterndb/floatItemData/vpiecelabeldata.h"
|
2016-08-23 13:02:09 +02:00
|
|
|
#include "../vmisc/vabstractapplication.h"
|
2016-12-14 10:59:21 +01:00
|
|
|
#include "../vmisc/vmath.h"
|
2017-08-15 14:22:33 +02:00
|
|
|
#include "../vpatterndb/vcontainer.h"
|
2016-07-18 22:30:14 +02:00
|
|
|
#include "vtextmanager.h"
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-07-23 15:26:15 +02:00
|
|
|
/**
|
|
|
|
* @brief TextLine::TextLine default constructor
|
|
|
|
*/
|
2016-07-18 22:30:14 +02:00
|
|
|
TextLine::TextLine()
|
2016-12-15 07:46:45 +01:00
|
|
|
: m_qsText(),
|
|
|
|
m_iFontSize(MIN_FONT_SIZE),
|
2017-08-15 14:22:33 +02:00
|
|
|
bold(false),
|
|
|
|
italic(false),
|
2016-12-15 07:46:45 +01:00
|
|
|
m_eAlign(Qt::AlignCenter)
|
2016-07-18 22:30:14 +02:00
|
|
|
{}
|
|
|
|
|
2017-08-15 14:22:33 +02:00
|
|
|
QList<TextLine> VTextManager::m_patternLabelLines = QList<TextLine>();
|
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QMap<QString, QString> PreparePlaceholders(const VAbstractPattern *doc)
|
|
|
|
{
|
|
|
|
SCASSERT(doc != nullptr)
|
|
|
|
|
|
|
|
QMap<QString, QString> placeholders;
|
|
|
|
|
2017-08-18 13:22:31 +02:00
|
|
|
// Pattern tags
|
2017-08-15 14:22:33 +02:00
|
|
|
QLocale locale(qApp->Settings()->GetLocale());
|
2017-08-19 18:37:14 +02:00
|
|
|
|
|
|
|
const QString date = locale.toString(QDate::currentDate(), doc->GetLabelDateFormat());
|
|
|
|
placeholders.insert(pl_date, date);
|
|
|
|
|
|
|
|
const QString time = locale.toString(QTime::currentTime(), doc->GetLabelTimeFormat());
|
|
|
|
placeholders.insert(pl_time, time);
|
|
|
|
|
2017-08-15 14:22:33 +02:00
|
|
|
placeholders.insert(pl_patternName, doc->GetPatternName());
|
|
|
|
placeholders.insert(pl_patternNumber, doc->GetPatternNumber());
|
|
|
|
placeholders.insert(pl_author, doc->GetCompanyName());
|
2017-09-19 15:07:48 +02:00
|
|
|
|
|
|
|
if (qApp->patternType() == MeasurementsType::Individual)
|
|
|
|
{
|
|
|
|
placeholders.insert(pl_customer, qApp->GetCustomerName());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
placeholders.insert(pl_customer, doc->GetCustomerName());
|
|
|
|
}
|
|
|
|
|
2017-08-15 14:22:33 +02:00
|
|
|
placeholders.insert(pl_pExt, QString("val"));
|
2017-08-17 15:04:52 +02:00
|
|
|
placeholders.insert(pl_pFileName, QFileInfo(qApp->GetPPath()).baseName());
|
|
|
|
placeholders.insert(pl_mFileName, QFileInfo(doc->MPath()).baseName());
|
2017-08-15 14:22:33 +02:00
|
|
|
|
|
|
|
QString curSize;
|
|
|
|
QString curHeight;
|
|
|
|
QString mExt;
|
|
|
|
if (qApp->patternType() == MeasurementsType::Multisize)
|
|
|
|
{
|
|
|
|
curSize = QString::number(VContainer::size());
|
|
|
|
curHeight = QString::number(VContainer::height());
|
|
|
|
mExt = "vst";
|
|
|
|
}
|
|
|
|
else if (qApp->patternType() == MeasurementsType::Individual)
|
|
|
|
{
|
2017-08-21 13:25:27 +02:00
|
|
|
curSize = QString::number(VContainer::size());
|
|
|
|
curHeight = QString::number(VContainer::height());
|
2017-08-15 14:22:33 +02:00
|
|
|
mExt = "vit";
|
|
|
|
}
|
|
|
|
|
|
|
|
placeholders.insert(pl_size, curSize);
|
|
|
|
placeholders.insert(pl_height, curHeight);
|
|
|
|
placeholders.insert(pl_mExt, mExt);
|
|
|
|
|
2017-08-30 08:32:39 +02:00
|
|
|
const QMap<int, QString> materials = doc->GetPatternMaterials();
|
|
|
|
for (int i = 0; i < userMaterialPlaceholdersQuantity; ++i)
|
|
|
|
{
|
|
|
|
const QString number = QString::number(i + 1);
|
|
|
|
|
|
|
|
QString value;
|
|
|
|
if (materials.contains(i + 1))
|
|
|
|
{
|
|
|
|
value = materials.value(i + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
placeholders.insert(pl_userMaterial + number, value);
|
|
|
|
}
|
|
|
|
|
2017-08-18 13:22:31 +02:00
|
|
|
// Piece tags
|
2018-03-14 15:01:24 +01:00
|
|
|
placeholders.insert(pl_pLetter, QString());
|
|
|
|
placeholders.insert(pl_pAnnotation, QString());
|
|
|
|
placeholders.insert(pl_pOrientation, QString());
|
|
|
|
placeholders.insert(pl_pRotation, QString());
|
|
|
|
placeholders.insert(pl_pTilt, QString());
|
|
|
|
placeholders.insert(pl_pFoldPosition, QString());
|
|
|
|
placeholders.insert(pl_pName, QString());
|
|
|
|
placeholders.insert(pl_pQuantity, QString());
|
|
|
|
placeholders.insert(pl_wOnFold, QString());
|
2017-08-18 13:22:31 +02:00
|
|
|
placeholders.insert(pl_mFabric, QObject::tr("Fabric"));
|
|
|
|
placeholders.insert(pl_mLining, QObject::tr("Lining"));
|
|
|
|
placeholders.insert(pl_mInterfacing, QObject::tr("Interfacing"));
|
|
|
|
placeholders.insert(pl_mInterlining, QObject::tr("Interlining"));
|
|
|
|
placeholders.insert(pl_wCut, QObject::tr("Cut"));
|
|
|
|
|
2017-08-15 14:22:33 +02:00
|
|
|
return placeholders;
|
|
|
|
}
|
|
|
|
|
2017-08-18 13:22:31 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void InitPiecePlaceholders(QMap<QString, QString> &placeholders, const QString &name, const VPieceLabelData& data)
|
|
|
|
{
|
|
|
|
placeholders[pl_pLetter] = data.GetLetter();
|
2017-08-21 12:16:43 +02:00
|
|
|
placeholders[pl_pAnnotation] = data.GetAnnotation();
|
|
|
|
placeholders[pl_pOrientation] = data.GetOrientation();
|
2017-08-21 16:10:55 +02:00
|
|
|
placeholders[pl_pRotation] = data.GetRotationWay();
|
2017-08-21 12:16:43 +02:00
|
|
|
placeholders[pl_pTilt] = data.GetTilt();
|
|
|
|
placeholders[pl_pFoldPosition] = data.GetFoldPosition();
|
2017-08-18 13:22:31 +02:00
|
|
|
placeholders[pl_pName] = name;
|
|
|
|
placeholders[pl_pQuantity] = QString::number(data.GetQuantity());
|
|
|
|
|
|
|
|
if (data.IsOnFold())
|
|
|
|
{
|
|
|
|
placeholders[pl_wOnFold] = QObject::tr("on fold");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-15 14:22:33 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QString ReplacePlaceholders(const QMap<QString, QString> &placeholders, QString line)
|
|
|
|
{
|
|
|
|
QChar per('%');
|
|
|
|
auto i = placeholders.constBegin();
|
|
|
|
while (i != placeholders.constEnd())
|
|
|
|
{
|
|
|
|
line.replace(per+i.key()+per, i.value());
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
return line;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QList<TextLine> PrepareLines(const QVector<VLabelTemplateLine> &lines)
|
|
|
|
{
|
|
|
|
QList<TextLine> textLines;
|
|
|
|
|
|
|
|
for (int i=0; i < lines.size(); ++i)
|
|
|
|
{
|
|
|
|
if (not lines.at(i).line.isEmpty())
|
|
|
|
{
|
|
|
|
TextLine tl;
|
|
|
|
tl.m_qsText = lines.at(i).line;
|
|
|
|
tl.m_eAlign = static_cast<Qt::Alignment>(lines.at(i).alignment);
|
2017-08-15 17:10:15 +02:00
|
|
|
tl.m_iFontSize = lines.at(i).fontSizeIncrement;
|
2017-08-15 14:22:33 +02:00
|
|
|
tl.bold = lines.at(i).bold;
|
|
|
|
tl.italic = lines.at(i).italic;
|
|
|
|
|
|
|
|
textLines << tl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return textLines;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-18 22:30:14 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-07-23 15:26:15 +02:00
|
|
|
/**
|
|
|
|
* @brief VTextManager::VTextManager constructor
|
|
|
|
*/
|
2016-07-18 22:30:14 +02:00
|
|
|
VTextManager::VTextManager()
|
2016-12-15 07:46:45 +01:00
|
|
|
: m_font(), m_liLines()
|
2016-07-18 22:30:14 +02:00
|
|
|
{}
|
|
|
|
|
2016-11-01 09:42:32 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VTextManager::VTextManager(const VTextManager &text)
|
2016-12-14 00:56:30 +01:00
|
|
|
: m_font(text.GetFont()), m_liLines(text.GetAllSourceLines())
|
2016-11-01 09:42:32 +01:00
|
|
|
{}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VTextManager &VTextManager::operator=(const VTextManager &text)
|
|
|
|
{
|
|
|
|
if ( &text == this )
|
|
|
|
{
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
m_font = text.GetFont();
|
|
|
|
m_liLines = text.GetAllSourceLines();
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2016-07-18 22:30:14 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-07-23 15:26:15 +02:00
|
|
|
/**
|
2016-11-01 09:42:32 +01:00
|
|
|
* @brief GetSpacing returns the vertical spacing between the lines
|
2016-11-01 10:46:51 +01:00
|
|
|
* @return spacing
|
2016-07-23 15:26:15 +02:00
|
|
|
*/
|
2016-07-18 22:30:14 +02:00
|
|
|
int VTextManager::GetSpacing() const
|
2016-07-19 02:26:50 +02:00
|
|
|
{
|
2016-12-14 00:56:30 +01:00
|
|
|
return 0;
|
2016-07-19 02:26:50 +02:00
|
|
|
}
|
2016-07-18 22:30:14 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-07-23 15:26:15 +02:00
|
|
|
/**
|
2016-11-01 09:42:32 +01:00
|
|
|
* @brief SetFont set the text base font
|
2016-07-23 15:26:15 +02:00
|
|
|
* @param font text base font
|
|
|
|
*/
|
2016-07-18 22:30:14 +02:00
|
|
|
void VTextManager::SetFont(const QFont& font)
|
2016-07-19 02:26:50 +02:00
|
|
|
{
|
|
|
|
m_font = font;
|
|
|
|
}
|
2016-07-18 22:30:14 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-07-23 15:26:15 +02:00
|
|
|
/**
|
2016-11-01 09:42:32 +01:00
|
|
|
* @brief GetFont returns the text base font
|
2016-07-23 15:26:15 +02:00
|
|
|
* @return text base font
|
|
|
|
*/
|
2016-07-18 22:30:14 +02:00
|
|
|
const QFont& VTextManager::GetFont() const
|
2016-07-19 02:26:50 +02:00
|
|
|
{
|
|
|
|
return m_font;
|
|
|
|
}
|
2016-07-18 22:30:14 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-07-23 15:26:15 +02:00
|
|
|
/**
|
2016-11-01 09:42:32 +01:00
|
|
|
* @brief SetFontSize sets the font size
|
2016-07-23 15:26:15 +02:00
|
|
|
* @param iFS font size in pixels
|
|
|
|
*/
|
2016-07-18 22:30:14 +02:00
|
|
|
void VTextManager::SetFontSize(int iFS)
|
2016-07-19 02:26:50 +02:00
|
|
|
{
|
2016-12-14 10:59:21 +01:00
|
|
|
iFS < MIN_FONT_SIZE ? m_font.setPixelSize(MIN_FONT_SIZE) : m_font.setPixelSize(iFS);
|
2016-07-19 02:26:50 +02:00
|
|
|
}
|
2016-07-18 22:30:14 +02:00
|
|
|
|
2016-11-01 09:42:32 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QList<TextLine> VTextManager::GetAllSourceLines() const
|
|
|
|
{
|
|
|
|
return m_liLines;
|
|
|
|
}
|
|
|
|
|
2016-07-19 02:26:50 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-07-23 15:26:15 +02:00
|
|
|
/**
|
2016-11-01 09:42:32 +01:00
|
|
|
* @brief VTextManager::GetSourceLinesCount returns the number of input text lines
|
2016-07-23 15:26:15 +02:00
|
|
|
* @return number of text lines that were added to the list by calling AddLine
|
|
|
|
*/
|
2016-11-01 09:42:32 +01:00
|
|
|
int VTextManager::GetSourceLinesCount() const
|
2016-07-19 02:26:50 +02:00
|
|
|
{
|
|
|
|
return m_liLines.count();
|
|
|
|
}
|
2016-07-18 22:30:14 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-07-23 15:26:15 +02:00
|
|
|
/**
|
2016-12-14 00:56:30 +01:00
|
|
|
* @brief VTextManager::GetSourceLine returns the reference to i-th text line
|
|
|
|
* @param i index of the requested line
|
|
|
|
* @return reference to the requested TextLine object
|
2016-07-23 15:26:15 +02:00
|
|
|
*/
|
2016-12-14 00:56:30 +01:00
|
|
|
const TextLine& VTextManager::GetSourceLine(int i) const
|
2016-07-19 02:26:50 +02:00
|
|
|
{
|
2016-12-14 00:56:30 +01:00
|
|
|
Q_ASSERT(i >= 0);
|
|
|
|
Q_ASSERT(i < m_liLines.count());
|
2016-12-14 10:59:21 +01:00
|
|
|
return m_liLines.at(i);
|
2016-07-19 02:26:50 +02:00
|
|
|
}
|
2016-07-18 22:30:14 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-07-23 15:26:15 +02:00
|
|
|
/**
|
2016-12-14 00:56:30 +01:00
|
|
|
* @brief VTextManager::FitFontSize sets the font size just big enough, so that the text fits into rectangle of
|
|
|
|
* size (fW, fH)
|
2016-07-23 15:26:15 +02:00
|
|
|
* @param fW rectangle width
|
|
|
|
* @param fH rectangle height
|
|
|
|
*/
|
2016-12-14 00:56:30 +01:00
|
|
|
void VTextManager::FitFontSize(qreal fW, qreal fH)
|
2016-07-18 22:30:14 +02:00
|
|
|
{
|
2017-01-05 12:11:18 +01:00
|
|
|
int iFS = 0;
|
|
|
|
if (GetSourceLinesCount() > 0)
|
|
|
|
{//division by zero
|
|
|
|
iFS = 3*qFloor(fH/GetSourceLinesCount())/4;
|
|
|
|
}
|
|
|
|
|
2016-12-14 00:56:30 +01:00
|
|
|
if (iFS < MIN_FONT_SIZE)
|
|
|
|
{
|
|
|
|
iFS = MIN_FONT_SIZE;
|
|
|
|
}
|
2016-09-29 01:39:50 +02:00
|
|
|
|
2016-12-14 00:56:30 +01:00
|
|
|
// get ratio between char width and height
|
|
|
|
|
|
|
|
int iMaxLen = 0;
|
2016-12-15 07:50:25 +01:00
|
|
|
TextLine maxLine;
|
2016-12-14 00:56:30 +01:00
|
|
|
QFont fnt;
|
|
|
|
for (int i = 0; i < GetSourceLinesCount(); ++i)
|
2016-07-18 22:30:14 +02:00
|
|
|
{
|
2016-12-14 00:56:30 +01:00
|
|
|
const TextLine& tl = GetSourceLine(i);
|
|
|
|
fnt = m_font;
|
|
|
|
fnt.setPixelSize(iFS + tl.m_iFontSize);
|
2017-08-15 14:22:33 +02:00
|
|
|
fnt.setBold(tl.bold);
|
|
|
|
fnt.setItalic(tl.italic);
|
2016-07-18 22:30:14 +02:00
|
|
|
QFontMetrics fm(fnt);
|
2016-12-15 07:50:25 +01:00
|
|
|
const int iTW = fm.width(tl.m_qsText);
|
2016-12-14 00:56:30 +01:00
|
|
|
if (iTW > iMaxLen)
|
2016-07-18 22:30:14 +02:00
|
|
|
{
|
2016-12-14 00:56:30 +01:00
|
|
|
iMaxLen = iTW;
|
2016-12-15 07:50:25 +01:00
|
|
|
maxLine = tl;
|
2016-07-18 22:30:14 +02:00
|
|
|
}
|
|
|
|
}
|
2016-12-14 00:56:30 +01:00
|
|
|
if (iMaxLen > fW)
|
2016-09-29 01:39:50 +02:00
|
|
|
{
|
2016-12-15 07:50:25 +01:00
|
|
|
QFont fnt = m_font;
|
2017-08-15 14:22:33 +02:00
|
|
|
fnt.setBold(maxLine.bold);
|
|
|
|
fnt.setItalic(maxLine.italic);
|
2016-12-15 07:50:25 +01:00
|
|
|
|
|
|
|
int lineLength = 0;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
--iFS;
|
|
|
|
fnt.setPixelSize(iFS + maxLine.m_iFontSize);
|
|
|
|
QFontMetrics fm(fnt);
|
|
|
|
lineLength = fm.width(maxLine.m_qsText);
|
|
|
|
}
|
|
|
|
while (lineLength > fW && iFS > MIN_FONT_SIZE);
|
2016-09-29 01:39:50 +02:00
|
|
|
}
|
2016-12-14 00:56:30 +01:00
|
|
|
SetFontSize(iFS);
|
2016-07-19 13:47:21 +02:00
|
|
|
}
|
|
|
|
|
2016-07-21 21:46:49 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-07-23 15:26:15 +02:00
|
|
|
/**
|
|
|
|
* @brief VTextManager::Update updates the text lines with detail data
|
|
|
|
* @param qsName detail name
|
|
|
|
* @param data reference to the detail data
|
|
|
|
*/
|
2017-02-23 10:19:27 +01:00
|
|
|
void VTextManager::Update(const QString& qsName, const VPieceLabelData& data)
|
2016-07-21 21:46:49 +02:00
|
|
|
{
|
2017-08-15 14:22:33 +02:00
|
|
|
m_liLines.clear();
|
|
|
|
|
2017-08-18 13:22:31 +02:00
|
|
|
QMap<QString, QString> placeholders = PreparePlaceholders(qApp->getCurrentDocument());
|
|
|
|
InitPiecePlaceholders(placeholders, qsName, data);
|
2016-07-21 21:46:49 +02:00
|
|
|
|
2017-08-18 13:22:31 +02:00
|
|
|
QVector<VLabelTemplateLine> lines = data.GetLabelTemplate();
|
|
|
|
|
|
|
|
for (int i=0; i<lines.size(); ++i)
|
2016-07-21 21:46:49 +02:00
|
|
|
{
|
2017-08-18 13:22:31 +02:00
|
|
|
lines[i].line = ReplacePlaceholders(placeholders, lines.at(i).line);
|
2016-07-21 21:46:49 +02:00
|
|
|
}
|
2017-08-18 13:22:31 +02:00
|
|
|
|
|
|
|
m_liLines = PrepareLines(lines);
|
2016-07-21 21:46:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-07-23 15:26:15 +02:00
|
|
|
/**
|
|
|
|
* @brief VTextManager::Update updates the text lines with pattern info
|
|
|
|
* @param pDoc pointer to the abstract pattern object
|
|
|
|
*/
|
2017-08-19 18:52:33 +02:00
|
|
|
void VTextManager::Update(VAbstractPattern *pDoc)
|
2016-07-21 21:46:49 +02:00
|
|
|
{
|
2017-08-15 14:22:33 +02:00
|
|
|
m_liLines.clear();
|
2016-07-21 21:46:49 +02:00
|
|
|
|
2017-08-15 14:22:33 +02:00
|
|
|
if (m_patternLabelLines.isEmpty() || pDoc->GetPatternWasChanged())
|
2016-07-21 21:46:49 +02:00
|
|
|
{
|
2017-08-15 14:22:33 +02:00
|
|
|
QVector<VLabelTemplateLine> lines = pDoc->GetPatternLabelTemplate();
|
|
|
|
if (lines.isEmpty() && m_patternLabelLines.isEmpty())
|
|
|
|
{
|
|
|
|
return; // Nothing to parse
|
|
|
|
}
|
|
|
|
|
|
|
|
const QMap<QString, QString> placeholders = PreparePlaceholders(pDoc);
|
|
|
|
|
|
|
|
for (int i=0; i<lines.size(); ++i)
|
|
|
|
{
|
|
|
|
lines[i].line = ReplacePlaceholders(placeholders, lines.at(i).line);
|
|
|
|
}
|
|
|
|
|
2017-08-19 18:52:33 +02:00
|
|
|
pDoc->SetPatternWasChanged(false);
|
2017-08-15 14:22:33 +02:00
|
|
|
m_patternLabelLines = PrepareLines(lines);
|
2016-07-21 21:46:49 +02:00
|
|
|
}
|
|
|
|
|
2017-08-15 14:22:33 +02:00
|
|
|
m_liLines = m_patternLabelLines;
|
|
|
|
}
|