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) 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 "vpsheet.h"
#include "vplayout.h" #include "vplayout.h"
#include "../vlayout/vtextmanager.h" #include "../vlayout/vtextmanager.h"
#include "../vlayout/vlayoutpiecepath.h"
#include <QIcon> #include <QIcon>
#include <QLoggingCategory> #include <QLoggingCategory>
@ -127,6 +128,45 @@ VPPiece::VPPiece(const VLayoutPiece &layoutPiece)
ClearTransformations(); 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() void VPPiece::ClearTransformations()
{ {
@ -454,3 +494,15 @@ auto VPPiece::IsValid() const -> bool
return true; 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: public:
VPPiece() = default; VPPiece() = default;
explicit VPPiece(const VLayoutPiece &layoutPiece); explicit VPPiece(const VLayoutPiece &layoutPiece);
virtual ~VPPiece() = default; virtual ~VPPiece() = default;
void Update(const VPPiecePtr &piece);
virtual auto GetUniqueID() const -> QString override;
void ClearTransformations(); void ClearTransformations();
/** /**
@ -118,6 +122,9 @@ public:
auto IsValid() const -> bool; auto IsValid() const -> bool;
auto CopyNumber() const -> quint16;
void SetCopyNumber(quint16 newCopyNumber);
private: private:
Q_DISABLE_COPY(VPPiece) Q_DISABLE_COPY(VPPiece)
@ -128,6 +135,8 @@ private:
bool m_isSelected{false}; bool m_isSelected{false};
bool m_outOfBound{false}; bool m_outOfBound{false};
bool m_hasSuperpositionWithPieces{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) for (const auto& rawPiece : data.pieces)
{ {
// TODO for feature "Update piece" : CreateOrUpdate() function indstead of CreatePiece() for (quint16 i = 1; i <= rawPiece.GetQuantity(); ++i)
VPPiecePtr piece(new VPPiece(rawPiece));
if (not piece->IsValid())
{ {
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); qCCritical(pWindow) << qPrintable(tr("Piece %1 invalid.").arg(piece->GetName()));
return;
}
}
piece->SetSheet(nullptr); // just in case if (m_cmd != nullptr && not m_cmd->IsGuiEnabled())
VPLayout::AddPiece(m_layout, piece); {
QGuiApplication::exit(V_EX_DATAERR);
return;
}
}
piece->SetSheet(nullptr); // just in case
VPLayout::AddPiece(m_layout, piece);
}
} }
m_carrousel->Refresh(); m_carrousel->Refresh();

View File

@ -438,6 +438,9 @@ void VPLayoutFileReader::ReadPiece(const VPPiecePtr &piece)
QString uuidStr = ReadAttributeString(attribs, ML::AttrID, QUuid::createUuid().toString()); QString uuidStr = ReadAttributeString(attribs, ML::AttrID, QUuid::createUuid().toString());
piece->SetUUID(QUuid(uuidStr)); 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); // bool showSeamline = ReadAttributeBool(attribs, ML::AttrShowSeamline, trueStr);
// piece->SetShowSeamLine(showSeamline); // piece->SetShowSeamLine(showSeamline);

View File

@ -248,6 +248,9 @@ void VPLayoutFileWriter::WritePiece(const VPPiecePtr &piece)
SetAttribute(ML::AttrName, piece->GetName()); SetAttribute(ML::AttrName, piece->GetName());
SetAttributeOrRemoveIf<bool>(ML::AttrMirrored, piece->IsMirror(), [](bool mirrored){return not mirrored;}); SetAttributeOrRemoveIf<bool>(ML::AttrMirrored, piece->IsMirror(), [](bool mirrored){return not mirrored;});
SetAttribute(ML::AttrTransform, TransformToString(piece->GetMatrix())); 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); writeStartElement(ML::TagSeamLine);
writeCharacters(PathToString(piece->GetContourPoints())); writeCharacters(PathToString(piece->GetContourPoints()));

View File

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

View File

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

View File

@ -183,7 +183,9 @@
<xs:attribute name="id" type="uuid" use="required"/> <xs:attribute name="id" type="uuid" use="required"/>
<xs:attribute type="xs:string" name="name"/> <xs:attribute type="xs:string" name="name"/>
<xs:attribute type="xs:boolean" name="mirrored"/> <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:complexType>
</xs:element> </xs:element>
</xs:sequence> </xs:sequence>