New option. Default piece label template for new pieces.

(cherry picked from commit 664bbe9afe)
This commit is contained in:
Roman Telezhynskyi 2023-01-16 16:40:50 +02:00
parent 4bed35052b
commit 525dac06de
11 changed files with 194 additions and 12 deletions

View File

@ -12,6 +12,7 @@
- New option Interactive tools.
- Improve error messages while import CSV data.
- [smart-pattern/valentina#189] Fix regression in dialog Known measurements.
- New option. Default piece label template for new pieces.
# Valentina 0.7.52 September 12, 2022
- Fix crash when default locale is ru.

View File

@ -166,6 +166,11 @@ DialogPatternProperties::DialogPatternProperties(VPattern *doc, VContainer *pat
//Initialization change value. Set to default value after initialization
m_defaultChanged = false;
m_securityChanged = false;
connect(ui->pushButtonBrowsePieceLabelPath, &QPushButton::clicked, this,
&DialogPatternProperties::BrowseLabelPath);
ui->lineEditPieceLabelPath->setText(m_doc->GetDefaultPieceLabelPath());
connect(ui->lineEditPieceLabelPath, &QLineEdit::textChanged, this, &DialogPatternProperties::LabelPathChanged);
}
//---------------------------------------------------------------------------------------------------------------------
@ -235,6 +240,7 @@ void DialogPatternProperties::SaveDescription()
m_doc->SetDescription(ui->plainTextEditDescription->document()->toPlainText());
m_doc->SetLabelPrefix(qvariant_cast<QString>(ui->comboBoxLabelLanguage->currentData()));
m_doc->SetPassmarkLengthVariable(ui->lineEditPassmarkLength->text());
m_doc->SetDefaultPieceLabelPath(ui->lineEditPieceLabelPath->text());
if (m_oldPassmarkLength != ui->lineEditPassmarkLength->text())
{
@ -421,3 +427,31 @@ void DialogPatternProperties::ShowImage()
qCritical() << tr("Unable to open temp file");
}
}
//---------------------------------------------------------------------------------------------------------------------
void DialogPatternProperties::BrowseLabelPath()
{
QString path = ui->lineEditPieceLabelPath->text();
if (path.isEmpty())
{
path = VCommonSettings::PrepareLabelTemplates(
VAbstractApplication::VApp()->Settings()->GetPathLabelTemplate());
}
QString filters(tr("Label template") + QLatin1String("(*.xml)"));
const QString filePath = QFileDialog::getOpenFileName(this, tr("Label template"), path, filters, nullptr,
VAbstractApplication::VApp()->NativeFileDialog());
ui->lineEditPieceLabelPath->setText(filePath);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogPatternProperties::LabelPathChanged(const QString &text)
{
QPalette palette = ui->lineEditPieceLabelPath->palette();
palette.setColor(ui->lineEditPieceLabelPath->foregroundRole(),
text.isEmpty() || QFileInfo::exists(text) ? Qt::black : Qt::red);
ui->lineEditPieceLabelPath->setPalette(palette);
m_descriptionChanged = true;
}

View File

@ -63,6 +63,8 @@ private slots:
void ChangeImage();
void SaveImage();
void ShowImage();
void BrowseLabelPath();
void LabelPathChanged(const QString &text);
private:
// cppcheck-suppress unknownMacro
Q_DISABLE_COPY_MOVE(DialogPatternProperties) // NOLINT

View File

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>493</width>
<height>582</height>
<width>552</width>
<height>667</height>
</rect>
</property>
<property name="windowTitle">
@ -124,6 +124,54 @@
</item>
</layout>
</item>
<item>
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>Default piece label template</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label_5">
<property name="text">
<string>Path:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEditPieceLabelPath">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="placeholderText">
<string>Path to default label template</string>
</property>
<property name="clearButtonEnabled">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButtonBrowsePieceLabelPath">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Select path to label template</string>
</property>
<property name="text">
<string>Browse…</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_7">
<property name="spacing">

View File

@ -33,6 +33,7 @@
<xs:attribute name="timeFormat" type="xs:string"/>
</xs:complexType>
</xs:element>
<xs:element name="pieceLabel" type="xs:string" minOccurs="0" maxOccurs="1"/>
<xs:element name="watermark" type="xs:string" minOccurs="0" maxOccurs="1"/>
<xs:element name="patternMaterials" minOccurs="0" maxOccurs="1">
<xs:complexType>
@ -81,7 +82,7 @@
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:element>
<xs:element name="measurements">
<xs:complexType>
<xs:attribute name="path" type="xs:string"/>

View File

@ -106,6 +106,7 @@ const QString VAbstractPattern::TagNodes = QStringLiteral("nodes");
const QString VAbstractPattern::TagNode = QStringLiteral("node");
const QString VAbstractPattern::TagBackgroundImages = QStringLiteral("backgroudImages");
const QString VAbstractPattern::TagBackgroundImage = QStringLiteral("backgroudImage");
const QString VAbstractPattern::TagPieceLabel = QStringLiteral("pieceLabel");
const QString VAbstractPattern::AttrName = QStringLiteral("name");
const QString VAbstractPattern::AttrVisible = QStringLiteral("visible");
@ -1273,6 +1274,21 @@ void VAbstractPattern::SetFinalMeasurements(const QVector<VFinalMeasurement> &me
emit patternChanged(false);
}
//---------------------------------------------------------------------------------------------------------------------
QString VAbstractPattern::GetDefaultPieceLabelPath() const
{
return UniqueTagText(TagPieceLabel);
}
//---------------------------------------------------------------------------------------------------------------------
void VAbstractPattern::SetDefaultPieceLabelPath(const QString &path)
{
CheckTagExists(TagPieceLabel);
setTagText(TagPieceLabel, path);
modified = true;
emit patternChanged(false);
}
//---------------------------------------------------------------------------------------------------------------------
void VAbstractPattern::SetPatternWasChanged(bool changed)
{
@ -1577,10 +1593,11 @@ auto VAbstractPattern::CheckTagExists(const QString &tag) -> QDomElement
TagCustomerBirthDate, // 8
TagCustomerEmail, // 9
TagPatternLabel, // 10
TagWatermark, // 11
TagPatternMaterials, // 12
TagFinalMeasurements, // 13
TagBackgroundImages // 14
TagPieceLabel, // 11
TagWatermark, // 12
TagPatternMaterials, // 13
TagFinalMeasurements, // 14
TagBackgroundImages // 15
};
switch (tags.indexOf(tag))
@ -1615,16 +1632,19 @@ auto VAbstractPattern::CheckTagExists(const QString &tag) -> QDomElement
case 10: // TagPatternLabel
element = createElement(TagPatternLabel);
break;
case 11: // TagWatermark
case 11: // TagPieceLabel
element = createElement(TagPieceLabel);
break;
case 12: // TagWatermark
element = createElement(TagWatermark);
break;
case 12: // TagPatternMaterials
case 13: // TagPatternMaterials
element = createElement(TagPatternMaterials);
break;
case 13: // TagFinalMeasurements
case 14: // TagFinalMeasurements
element = createElement(TagFinalMeasurements);
break;
case 14: // TagBackgroundImages
case 15: // TagBackgroundImages
element = createElement(TagBackgroundImages);
break;
case 0: //TagUnit (Mandatory tag)

View File

@ -196,6 +196,9 @@ public:
QVector<VFinalMeasurement> GetFinalMeasurements() const;
void SetFinalMeasurements(const QVector<VFinalMeasurement> &measurements);
QString GetDefaultPieceLabelPath() const;
void SetDefaultPieceLabelPath(const QString &path);
void SetPatternWasChanged(bool changed);
bool GetPatternWasChanged() const;
@ -300,6 +303,7 @@ public:
static const QString TagNode;
static const QString TagBackgroundImages;
static const QString TagBackgroundImage;
static const QString TagPieceLabel;
static const QString AttrName;
static const QString AttrVisible;

View File

@ -99,6 +99,7 @@ enum class ContextMenuOption : int
InLayout,
ForbidFlipping,
ForceFlipping,
ResetLabelTemplate,
Remove,
TurnPoint,
LAST_ONE_DO_NOT_USE
@ -351,6 +352,10 @@ QHash<int, QAction *> VNodePoint::InitContextMenu(QMenu *menu, vidtype pieceId,
forceFlippingOption->setChecked(detail.IsForceFlipping());
contextMenu.insert(static_cast<int>(ContextMenuOption::ForceFlipping), forceFlippingOption);
QAction *reseteLabelTemplateOption = menu->addAction(tr("Reset piece label template"));
reseteLabelTemplateOption->setEnabled(not doc->GetDefaultPieceLabelPath().isEmpty());
contextMenu.insert(static_cast<int>(ContextMenuOption::ResetLabelTemplate), reseteLabelTemplateOption);
QAction *actionRemove = menu->addAction(QIcon::fromTheme(QStringLiteral("edit-delete")), tr("Delete"));
referens > 1 ? actionRemove->setEnabled(false) : actionRemove->setEnabled(true);
contextMenu.insert(static_cast<int>(ContextMenuOption::Remove), actionRemove);
@ -580,7 +585,7 @@ void VNodePoint::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
ContextMenuOption selectedOption = static_cast<ContextMenuOption>(
contextMenu.key(selectedAction, static_cast<int>(ContextMenuOption::NoSelection)));
Q_STATIC_ASSERT_X(static_cast<int>(ContextMenuOption::LAST_ONE_DO_NOT_USE) == 32,
Q_STATIC_ASSERT_X(static_cast<int>(ContextMenuOption::LAST_ONE_DO_NOT_USE) == 33,
"Not all options were handled.");
QT_WARNING_PUSH
@ -603,6 +608,9 @@ QT_WARNING_DISABLE_GCC("-Wswitch-default")
case ContextMenuOption::ForceFlipping:
emit ToggleForceFlipping(selectedAction->isChecked());
break;
case ContextMenuOption::ResetLabelTemplate:
emit ResetPieceLabelTemplate();
break;
case ContextMenuOption::Remove:
try
{

View File

@ -70,6 +70,7 @@ signals:
void TogglePassmark(quint32 id, bool toggle);
void TogglePassmarkAngleType(quint32 id, PassmarkAngleType type);
void TogglePassmarkLineType(quint32 id, PassmarkLineType type);
void ResetPieceLabelTemplate();
public slots:
virtual void FullUpdateFromFile() override;
void NameChangePosition(const QPointF &pos);

View File

@ -41,6 +41,7 @@
#include "../vgeometry/vellipticalarc.h"
#include "../ifc/xml/vpatternconverter.h"
#include "../ifc/exception/vexceptionwrongid.h"
#include "../ifc/xml/vlabeltemplateconverter.h"
#include "../undocommands/addpiece.h"
#include "../undocommands/deletepiece.h"
#include "../undocommands/movepiece.h"
@ -63,6 +64,7 @@
#include "nodeDetails/vnodespline.h"
#include "nodeDetails/vnodesplinepath.h"
#include "nodeDetails/vtoolplacelabel.h"
#include "../vformat/vlabeltemplate.h"
#include <QFuture>
#include <QtConcurrent/QtConcurrentRun>
@ -176,6 +178,29 @@ VToolSeamAllowance *VToolSeamAllowance::Create(const QPointer<DialogTool> &dialo
initData.parse = Document::FullParse;
initData.typeCreation = Source::FromGui;
auto LoadLabelTemplate = [&initData](const QString &path)
{
if (not path.isEmpty())
{
try
{
VLabelTemplate ltemplate;
ltemplate.setXMLContent(VLabelTemplateConverter(path).Convert());
return ltemplate.ReadLines();
}
catch (VException &e)
{
const QString errorMsg = QObject::tr("Piece '%1'. Unable to load default piece label template.\n%2\n%3")
.arg(initData.detail.GetName(), e.ErrorMessage(), e.DetailedInformation());
VAbstractApplication::VApp()->IsPedantic() ? throw VException(errorMsg) :
qWarning() << VAbstractValApplication::warningMessageSignature + errorMsg;
}
}
return QVector<VLabelTemplateLine>();
};
initData.detail.GetPieceLabelData().SetLabelTemplate(LoadLabelTemplate(doc->GetDefaultPieceLabelPath()));
initData.detail.GetPath().SetNodes(PrepareNodes(initData.detail.GetPath(), scene, doc, data));
VToolSeamAllowance *piece = Create(initData);
@ -1225,6 +1250,9 @@ void VToolSeamAllowance::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
forceFlippingOption->setCheckable(true);
forceFlippingOption->setChecked(detail.IsForceFlipping());
QAction *reseteLabelTemplateOption = menu.addAction(tr("Reset piece label template"));
reseteLabelTemplateOption->setEnabled(not doc->GetDefaultPieceLabelPath().isEmpty());
QAction *actionRemove = menu.addAction(QIcon::fromTheme(QStringLiteral("edit-delete")), tr("Delete"));
actionRemove->setDisabled(_referens > 0);
@ -1245,6 +1273,10 @@ void VToolSeamAllowance::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
{
ToggleForceFlipping(selectedAction->isChecked());
}
else if (selectedAction == reseteLabelTemplateOption)
{
ResetPieceLabelTemplate();
}
else if (selectedAction == actionRemove)
{
try
@ -1690,6 +1722,34 @@ void VToolSeamAllowance::TogglePassmarkLineType(quint32 id, PassmarkLineType typ
}
}
//---------------------------------------------------------------------------------------------------------------------
void VToolSeamAllowance::ResetPieceLabelTemplate()
{
const VPiece oldDet = VAbstractTool::data.GetPiece(m_id);
VPiece newDet = oldDet;
const QString path = doc->GetDefaultPieceLabelPath();
if (not path.isEmpty())
{
QVector<VLabelTemplateLine> lines;
try
{
VLabelTemplate ltemplate;
ltemplate.setXMLContent(VLabelTemplateConverter(path).Convert());
lines = ltemplate.ReadLines();
newDet.GetPieceLabelData().SetLabelTemplate(lines);
VAbstractApplication::VApp()->getUndoStack()->push(new SavePieceOptions(oldDet, newDet, doc, m_id));
}
catch (VException &e)
{
const QString errorMsg = QObject::tr("Piece '%1'. Unable to load default piece label template.\n%2\n%3")
.arg(newDet.GetName(), e.ErrorMessage(), e.DetailedInformation());
VAbstractApplication::VApp()->IsPedantic() ? throw VException(errorMsg) :
qWarning() << VAbstractValApplication::warningMessageSignature + errorMsg;
}
}
}
//---------------------------------------------------------------------------------------------------------------------
VPieceItem::MoveTypes VToolSeamAllowance::FindLabelGeometry(const VPatternLabelData& labelData,
const QVector<quint32> &pins, qreal &rotationAngle,
@ -1928,6 +1988,8 @@ void VToolSeamAllowance::InitNode(const VPieceNode &node, VMainGraphicsScene *sc
&VToolSeamAllowance::TogglePassmarkAngleType, Qt::UniqueConnection);
connect(tool, &VNodePoint::TogglePassmarkLineType, parent,
&VToolSeamAllowance::TogglePassmarkLineType, Qt::UniqueConnection);
connect(tool, &VNodePoint::ResetPieceLabelTemplate, parent,
&VToolSeamAllowance::ResetPieceLabelTemplate, Qt::UniqueConnection);
tool->setParentItem(parent);
tool->SetParentType(ParentType::Item);
tool->SetExluded(node.IsExcluded());

View File

@ -173,6 +173,7 @@ private slots:
void ToggleNodePointPassmark(quint32 id, bool toggle);
void TogglePassmarkAngleType(quint32 id, PassmarkAngleType type);
void TogglePassmarkLineType(quint32 id, PassmarkLineType type);
void ResetPieceLabelTemplate();
private:
Q_DISABLE_COPY_MOVE(VToolSeamAllowance) // NOLINT