Import with update.

This commit is contained in:
Roman Telezhynskyi 2021-08-31 13:08:59 +03:00
parent 29325add49
commit b14ad59010
9 changed files with 103 additions and 16 deletions

View file

@ -96,9 +96,20 @@ void VPLayout::AddPiece(const VPLayoutPtr &layout, const VPPiecePtr &piece)
//---------------------------------------------------------------------------------------------------------------------
void VPLayout::AddPiece(const VPPiecePtr &piece)
{
if ((piece != nullptr) && not m_pieces.contains(piece->GetUniqueID()))
if (not piece.isNull())
{
m_pieces.insert(piece->GetUniqueID(), piece);
if (not m_pieces.contains(piece->GetUniqueID()))
{
m_pieces.insert(piece->GetUniqueID(), piece);
}
else
{
VPPiecePtr oldPiece = m_pieces.value(piece->GetUniqueID());
if (not oldPiece.isNull())
{
oldPiece->Update(piece);
}
}
}
}

View file

@ -33,6 +33,7 @@
#include "vpsheet.h"
#include "vplayout.h"
#include "../vlayout/vtextmanager.h"
#include "../vlayout/vlayoutpiecepath.h"
#include <QIcon>
#include <QLoggingCategory>
@ -127,6 +128,45 @@ VPPiece::VPPiece(const VLayoutPiece &layoutPiece)
ClearTransformations();
}
//---------------------------------------------------------------------------------------------------------------------
void VPPiece::Update(const VPPiecePtr &piece)
{
if (piece.isNull())
{
return;
}
SetName(piece->GetName());
SetCountourPoints(piece->GetContourPoints(), IsHideMainPath());
SetSeamAllowancePoints(GetSeamAllowancePoints(), piece->IsSeamAllowance(), piece->IsSeamAllowanceBuiltIn());
SetInternalPaths(GetInternalPaths());
SetPassmarks(GetPassmarks());
SetPlaceLabels(GetPlaceLabels());
SetGrainlineEnabled(piece->IsGrainlineEnabled());
SetGrainlineAngle(piece->GrainlineAngle());
SetGrainlineArrowType(piece->GrainlineArrowType());
SetGrainlinePoints(piece->GetGrainline());
SetPieceLabelRect(piece->GetPieceLabelRect());
SetPieceLabelData(piece->GetPieceLabelData());
SetPatternLabelRect(piece->GetPatternLabelRect());
SetPatternLabelData(piece->GetPatternLabelData());
}
//---------------------------------------------------------------------------------------------------------------------
QString VPPiece::GetUniqueID() const
{
QString id = VLayoutPiece::GetUniqueID();
if (m_copyNumber > 1)
{
id = id + '_' + QString::number(m_copyNumber);
}
return id;
}
//---------------------------------------------------------------------------------------------------------------------
void VPPiece::ClearTransformations()
{
@ -454,3 +494,15 @@ auto VPPiece::IsValid() const -> bool
return true;
}
//---------------------------------------------------------------------------------------------------------------------
quint16 VPPiece::CopyNumber() const
{
return m_copyNumber;
}
//---------------------------------------------------------------------------------------------------------------------
void VPPiece::SetCopyNumber(quint16 newCopyNumber)
{
m_copyNumber = qMax(static_cast<quint16>(1), newCopyNumber);
}

View file

@ -44,9 +44,13 @@ class VPPiece : public VLayoutPiece
public:
VPPiece() = default;
explicit VPPiece(const VLayoutPiece &layoutPiece);
virtual ~VPPiece() = default;
void Update(const VPPiecePtr &piece);
virtual auto GetUniqueID() const -> QString override;
void ClearTransformations();
/**
@ -118,6 +122,9 @@ public:
auto IsValid() const -> bool;
auto CopyNumber() const -> quint16;
void SetCopyNumber(quint16 newCopyNumber);
private:
Q_DISABLE_COPY(VPPiece)
@ -128,6 +135,8 @@ private:
bool m_isSelected{false};
bool m_outOfBound{false};
bool m_hasSuperpositionWithPieces{false};
quint16 m_copyNumber{1};
};
//---------------------------------------------------------------------------------------------------------------------

View file

@ -371,22 +371,25 @@ void VPMainWindow::ImportRawLayouts(const QStringList &rawLayouts)
{
for (const auto& rawPiece : data.pieces)
{
// TODO for feature "Update piece" : CreateOrUpdate() function indstead of CreatePiece()
VPPiecePtr piece(new VPPiece(rawPiece));
if (not piece->IsValid())
for (quint16 i = 1; i <= rawPiece.GetQuantity(); ++i)
{
qCCritical(pWindow) << qPrintable(tr("Piece %1 invalid.").arg(piece->GetName()));
VPPiecePtr piece(new VPPiece(rawPiece));
piece->SetCopyNumber(i);
if (m_cmd != nullptr && not m_cmd->IsGuiEnabled())
if (not piece->IsValid())
{
QGuiApplication::exit(V_EX_DATAERR);
return;
}
}
qCCritical(pWindow) << qPrintable(tr("Piece %1 invalid.").arg(piece->GetName()));
piece->SetSheet(nullptr); // just in case
VPLayout::AddPiece(m_layout, piece);
if (m_cmd != nullptr && not m_cmd->IsGuiEnabled())
{
QGuiApplication::exit(V_EX_DATAERR);
return;
}
}
piece->SetSheet(nullptr); // just in case
VPLayout::AddPiece(m_layout, piece);
}
}
m_carrousel->Refresh();

View file

@ -438,6 +438,9 @@ void VPLayoutFileReader::ReadPiece(const VPPiecePtr &piece)
QString uuidStr = ReadAttributeString(attribs, ML::AttrID, QUuid::createUuid().toString());
piece->SetUUID(QUuid(uuidStr));
piece->SetName(ReadAttributeEmptyString(attribs, ML::AttrGradationLabel));
piece->SetCopyNumber(static_cast<quint16>(ReadAttributeUInt(attribs, ML::AttrCopyNumber, QChar('1'))));
// bool showSeamline = ReadAttributeBool(attribs, ML::AttrShowSeamline, trueStr);
// piece->SetShowSeamLine(showSeamline);

View file

@ -248,6 +248,9 @@ void VPLayoutFileWriter::WritePiece(const VPPiecePtr &piece)
SetAttribute(ML::AttrName, piece->GetName());
SetAttributeOrRemoveIf<bool>(ML::AttrMirrored, piece->IsMirror(), [](bool mirrored){return not mirrored;});
SetAttribute(ML::AttrTransform, TransformToString(piece->GetMatrix()));
SetAttributeOrRemoveIf<QString>(ML::AttrGradationLabel, piece->GetGradationId(),
[](const QString &label){return label.isEmpty();});
SetAttribute(ML::AttrCopyNumber, piece->CopyNumber());
writeStartElement(ML::TagSeamLine);
writeCharacters(PathToString(piece->GetContourPoints()));

View file

@ -95,6 +95,8 @@ const QString AttrFontSize = QStringLiteral("fontSize");
const QString AttrBold = QStringLiteral("bold");
const QString AttrItalic = QStringLiteral("italic");
const QString AttrAlignment = QStringLiteral("alignment");
const QString AttrGradationLabel = QStringLiteral("gradationLabel");
const QString AttrCopyNumber = QStringLiteral("copyNumber");
const QString atFrontStr = QStringLiteral("atFront");
const QString atRearStr = QStringLiteral("atRear");

View file

@ -100,6 +100,8 @@ extern const QString AttrFontSize;
extern const QString AttrBold;
extern const QString AttrItalic;
extern const QString AttrAlignment;
extern const QString AttrGradationLabel;
extern const QString AttrCopyNumber;
extern const QString atFrontStr;
extern const QString atRearStr;

View file

@ -183,7 +183,9 @@
<xs:attribute name="id" type="uuid" use="required"/>
<xs:attribute type="xs:string" name="name"/>
<xs:attribute type="xs:boolean" name="mirrored"/>
<xs:attribute type="Transformation" name="transform"/>
<xs:attribute type="Transformation" name="transform"/>
<xs:attribute type="xs:string" name="gradationLabel"/>
<xs:attribute type="xs:unsignedInt" name="copyNumber"/>
</xs:complexType>
</xs:element>
</xs:sequence>