Read/write empty layout file.

This commit is contained in:
Roman Telezhynskyi 2021-05-22 20:29:33 +03:00
parent 224aa23527
commit 5467e213a2
19 changed files with 358 additions and 341 deletions

View File

@ -189,10 +189,8 @@ auto VPMainWindow::LoadFile(QString path) -> bool
VPLayoutFileReader fileReader;
if(m_layout == nullptr)
{
m_layout = new VPLayout();
}
delete m_layout;
m_layout = new VPLayout();
fileReader.ReadFile(m_layout, &file);
@ -209,6 +207,10 @@ auto VPMainWindow::LoadFile(QString path) -> bool
return false;
}
SetCurrentFile(path);
m_layout->SetFocusedSheet();
// updates the properties with the loaded data
SetPropertiesData();

View File

@ -14,7 +14,7 @@
<string>Puzzle</string>
</property>
<property name="windowIcon">
<iconset>
<iconset resource="share/resources/puzzleicon.qrc">
<normaloff>:/puzzleicon/64x64/logo.png</normaloff>:/puzzleicon/64x64/logo.png</iconset>
</property>
<property name="layoutDirection">
@ -194,7 +194,7 @@
<enum>QTabWidget::Rounded</enum>
</property>
<property name="currentIndex">
<number>0</number>
<number>1</number>
</property>
<property name="iconSize">
<size>
@ -207,7 +207,7 @@
<string notr="true"/>
</property>
<attribute name="icon">
<iconset>
<iconset resource="share/resources/puzzleicon.qrc">
<normaloff>:/puzzleicon/64x64/iconCurrentPiece.png</normaloff>:/puzzleicon/64x64/iconCurrentPiece.png</iconset>
</attribute>
<attribute name="title">
@ -408,7 +408,7 @@
<string/>
</property>
<property name="icon">
<iconset>
<iconset resource="share/resources/puzzleicon.qrc">
<normaloff>:/puzzleicon/64x64/iconRotate90Clockwise.png</normaloff>:/puzzleicon/64x64/iconRotate90Clockwise.png</iconset>
</property>
<property name="iconSize">
@ -428,7 +428,7 @@
<string/>
</property>
<property name="icon">
<iconset>
<iconset resource="share/resources/puzzleicon.qrc">
<normaloff>:/puzzleicon/64x64/iconRotate90Anticlockwise.png</normaloff>:/puzzleicon/64x64/iconRotate90Anticlockwise.png</iconset>
</property>
<property name="iconSize">
@ -448,7 +448,7 @@
<string/>
</property>
<property name="icon">
<iconset>
<iconset resource="share/resources/puzzleicon.qrc">
<normaloff>:/puzzleicon/64x64/iconRotateGrainlineVertical.png</normaloff>:/puzzleicon/64x64/iconRotateGrainlineVertical.png</iconset>
</property>
<property name="iconSize">
@ -468,7 +468,7 @@
<string/>
</property>
<property name="icon">
<iconset>
<iconset resource="share/resources/puzzleicon.qrc">
<normaloff>:/puzzleicon/64x64/iconRotateGrainlineHorizontal.png</normaloff>:/puzzleicon/64x64/iconRotateGrainlineHorizontal.png</iconset>
</property>
<property name="iconSize">
@ -628,7 +628,7 @@
</widget>
<widget class="QWidget" name="tabSheetProperty">
<attribute name="icon">
<iconset>
<iconset resource="share/resources/puzzleicon.qrc">
<normaloff>:/puzzleicon/64x64/iconLayout.png</normaloff>:/puzzleicon/64x64/iconLayout.png</iconset>
</attribute>
<attribute name="title">
@ -668,7 +668,7 @@
<property name="geometry">
<rect>
<x>0</x>
<y>-153</y>
<y>-170</y>
<width>342</width>
<height>870</height>
</rect>
@ -780,7 +780,7 @@
<string notr="true"/>
</property>
<property name="icon">
<iconset>
<iconset resource="share/resources/puzzleicon.qrc">
<normaloff>:/puzzleicon/64x64/iconPortrait.png</normaloff>:/puzzleicon/64x64/iconPortrait.png</iconset>
</property>
<property name="iconSize">
@ -803,7 +803,7 @@
<string notr="true"/>
</property>
<property name="icon">
<iconset>
<iconset resource="share/resources/puzzleicon.qrc">
<normaloff>:/puzzleicon/64x64/iconLandscape.png</normaloff>:/puzzleicon/64x64/iconLandscape.png</iconset>
</property>
<property name="iconSize">
@ -995,7 +995,7 @@
<string notr="true"/>
</property>
<property name="icon">
<iconset>
<iconset resource="share/resources/puzzleicon.qrc">
<normaloff>:/puzzleicon/64x64/iconGrainlineVertical.png</normaloff>:/puzzleicon/64x64/iconGrainlineVertical.png</iconset>
</property>
<property name="iconSize">
@ -1015,7 +1015,7 @@
<string notr="true"/>
</property>
<property name="icon">
<iconset>
<iconset resource="share/resources/puzzleicon.qrc">
<normaloff>:/puzzleicon/64x64/iconGrainlineHorizontal.png</normaloff>:/puzzleicon/64x64/iconGrainlineHorizontal.png</iconset>
</property>
<property name="iconSize">
@ -1101,7 +1101,7 @@
</widget>
<widget class="QWidget" name="tabTilesProperty">
<attribute name="icon">
<iconset>
<iconset resource="share/resources/puzzleicon.qrc">
<normaloff>:/puzzleicon/64x64/iconTiles.png</normaloff>:/puzzleicon/64x64/iconTiles.png</iconset>
</attribute>
<attribute name="title">
@ -1211,7 +1211,7 @@
<string/>
</property>
<property name="icon">
<iconset>
<iconset resource="share/resources/puzzleicon.qrc">
<normaloff>:/puzzleicon/64x64/iconPortrait.png</normaloff>:/puzzleicon/64x64/iconPortrait.png</iconset>
</property>
<property name="iconSize">
@ -1231,7 +1231,7 @@
<string/>
</property>
<property name="icon">
<iconset>
<iconset resource="share/resources/puzzleicon.qrc">
<normaloff>:/puzzleicon/64x64/iconLandscape.png</normaloff>:/puzzleicon/64x64/iconLandscape.png</iconset>
</property>
<property name="iconSize">
@ -1389,7 +1389,7 @@
</widget>
<widget class="QWidget" name="tabLayoutProperty">
<attribute name="icon">
<iconset>
<iconset resource="share/resources/puzzleicon.qrc">
<normaloff>:/puzzleicon/64x64/iconProperties.png</normaloff>:/puzzleicon/64x64/iconProperties.png</iconset>
</attribute>
<attribute name="title">
@ -1810,6 +1810,8 @@
<tabstop>checkBoxLayoutWarningPiecesSuperposition</tabstop>
<tabstop>checkBoxLayoutWarningPiecesOutOfBound</tabstop>
</tabstops>
<resources/>
<resources>
<include location="share/resources/puzzleicon.qrc"/>
</resources>
<connections/>
</ui>

View File

@ -44,7 +44,7 @@ VPPieceList::VPPieceList(VPLayout *layout, VPSheet *sheet):
//---------------------------------------------------------------------------------------------------------------------
VPPieceList::~VPPieceList()
{
qDeleteAll(m_pieces);
}
//---------------------------------------------------------------------------------------------------------------------
@ -69,7 +69,7 @@ QList<VPPiece *> VPPieceList::GetPieces()
//---------------------------------------------------------------------------------------------------------------------
void VPPieceList::ClearSelection()
{
for (auto piece: m_pieces)
for (auto *piece: m_pieces)
{
piece->SetIsSelected(false);
}

View File

@ -33,14 +33,29 @@
#include "../ifc/exception/vexception.h"
#include "../ifc/exception/vexceptionconversionerror.h"
QT_WARNING_PUSH
QT_WARNING_DISABLE_CLANG("-Wmissing-prototypes")
QT_WARNING_DISABLE_INTEL(1418)
Q_LOGGING_CATEGORY(MLReader, "mlReader")
QT_WARNING_POP
//---------------------------------------------------------------------------------------------------------------------
bool VPLayoutFileReader::ReadFile(VPLayout *layout, QFile *file)
auto VPLayoutFileReader::ReadFile(VPLayout *layout, QFile *file) -> bool
{
setDevice(file);
if (readNextStartElement())
try
{
ReadLayout(layout);
if (readNextStartElement())
{
ReadLayout(layout);
}
}
catch(const VException &e)
{
raiseError(e.ErrorMessage());
}
return hasError();
@ -49,25 +64,27 @@ bool VPLayoutFileReader::ReadFile(VPLayout *layout, QFile *file)
//---------------------------------------------------------------------------------------------------------------------
void VPLayoutFileReader::ReadLayout(VPLayout *layout)
{
SCASSERT(isStartElement() && name() == ML::TagLayout);
AssertRootTag(ML::TagLayout);
const QStringList tags({ML::TagProperties, ML::TagUnplacedPieces, ML::TagSheets});
while (readNextStartElement())
{
if (name() == ML::TagProperties)
switch (tags.indexOf(name().toString()))
{
ReadProperties(layout);
}
else if (name() == ML::TagPieceLists)
{
ReadSheets(layout);
}
else if (name() == ML::TagUnplacedPieceList)
{
ReadUnplacedPieces(layout);
}
else
{
// TODO error handling, we encountered a tag that isn't defined in the specification
case 0: // ML::TagProperties
ReadProperties(layout);
break;
case 1: // ML::TagUnplacedPieces
ReadUnplacedPieces(layout);
break;
case 2: // ML::TagSheets
ReadSheets(layout);
break;
default:
qCDebug(MLReader, "Ignoring tag %s", qUtf8Printable(name().toString()));
skipCurrentElement();
break;
}
}
}
@ -75,101 +92,110 @@ void VPLayoutFileReader::ReadLayout(VPLayout *layout)
//---------------------------------------------------------------------------------------------------------------------
void VPLayoutFileReader::ReadProperties(VPLayout *layout)
{
SCASSERT(isStartElement() && name() == ML::TagProperties);
AssertRootTag(ML::TagProperties);
const QStringList tags
{
ML::TagUnit, // 0
ML::TagTitle, // 1
ML::TagDescription, // 2
ML::TagControl, // 3
ML::TagTiles // 4
};
while (readNextStartElement())
{
qDebug() << name().toString();
const QStringList tags = QStringList(
{
ML::TagUnit,
ML::TagDescription,
ML::TagControl,
ML::TagTiles
});
switch (tags.indexOf(name().toString()))
{
case 0:// unit
qDebug("read unit");
layout->SetUnit(StrToUnits(readElementText()));
break;
case 1:// description
{
qDebug("read description");
QString description = readElementText();
// TODO read the description info
break;
}
case 2:// control
{
qDebug("read control");
QXmlStreamAttributes attribs = attributes();
layout->SetWarningSuperpositionOfPieces(ReadAttributeBool(attribs, ML::AttrWarningSuperposition, trueStr));
layout->SetWarningPiecesOutOfBound(ReadAttributeBool(attribs, ML::AttrWarningOutOfBound, trueStr));
readElementText();
break;
}
case 3:// tiles
qDebug("read tiles");
ReadTiles(layout);
readElementText();
break;
default:
// TODO error handling, we encountered a tag that isn't defined in the specification
skipCurrentElement();
break;
case 0:// unit
qDebug("read unit");
layout->SetUnit(StrToUnits(readElementText()));
break;
case 1:// title
qDebug("read title");
layout->SetTitle(readElementText());
break;
case 2:// description
qDebug("read description");
layout->SetDescription(readElementText());
break;
case 3:// control
qDebug("read control");
ReadControl(layout);
break;
case 4:// tiles
qDebug("read tiles");
ReadTiles(layout);
break;
default:
qCDebug(MLReader, "Ignoring tag %s", qUtf8Printable(name().toString()));
skipCurrentElement();
break;
}
}
}
//---------------------------------------------------------------------------------------------------------------------
void VPLayoutFileReader::ReadControl(VPLayout *layout)
{
AssertRootTag(ML::TagControl);
QXmlStreamAttributes attribs = attributes();
layout->SetWarningSuperpositionOfPieces(ReadAttributeBool(attribs, ML::AttrWarningSuperposition, trueStr));
layout->SetWarningPiecesOutOfBound(ReadAttributeBool(attribs, ML::AttrWarningOutOfBound, trueStr));
readElementText();
}
//---------------------------------------------------------------------------------------------------------------------
void VPLayoutFileReader::ReadUnplacedPieces(VPLayout *layout)
{
AssertRootTag(ML::TagUnplacedPieces);
ReadPieceList(layout->GetUnplacedPieceList());
}
//---------------------------------------------------------------------------------------------------------------------
void VPLayoutFileReader::ReadTiles(VPLayout *layout)
{
Q_UNUSED(layout); // to be removed when used
AssertRootTag(ML::TagTiles);
SCASSERT(isStartElement() && name() == ML::TagTiles);
QXmlStreamAttributes attribs = attributes();
layout->SetShowTiles(ReadAttributeBool(attribs, ML::AttrVisible, falseStr));
// attribs.value(ML::AttrMatchingMarks); // TODO
// QXmlStreamAttributes attribs = attributes();
// attribs.value(ML::AttrVisible); // TODO
// attribs.value(ML::AttrMatchingMarks); // TODO
const QStringList tags
{
ML::TagSize, // 0
ML::TagMargin // 1
};
while (readNextStartElement())
{
if (name() == ML::TagSize)
switch (tags.indexOf(name().toString()))
{
QSizeF size = ReadSize();
// TODO set layout tiled size
Q_UNUSED(size);
readElementText();
}
else if (name() == ML::TagMargin)
{
QMarginsF margins = ReadMargins();
// TODO set layout tiled margins
Q_UNUSED(margins);
readElementText();
}
else
{
// TODO error handling, we encountered a tag that isn't defined in the specification
skipCurrentElement();
case 0: // size
layout->SetTilesSize(ReadSize());
break;
case 1: // margin
layout->SetTilesMargins(ReadMargins());
break;
default:
qCDebug(MLReader, "Ignoring tag %s", qUtf8Printable(name().toString()));
skipCurrentElement();
break;
}
}
readElementText();
}
//---------------------------------------------------------------------------------------------------------------------
void VPLayoutFileReader::ReadSheets(VPLayout *layout)
{
SCASSERT(isStartElement() && name() == ML::TagSheets);
AssertRootTag(ML::TagSheets);
while (readNextStartElement())
{
@ -179,25 +205,67 @@ void VPLayoutFileReader::ReadSheets(VPLayout *layout)
}
else
{
// TODO error handling, we encountered a tag that isn't defined in the specification
qCDebug(MLReader, "Ignoring tag %s", qUtf8Printable(name().toString()));
skipCurrentElement();
}
}
}
//---------------------------------------------------------------------------------------------------------------------
void VPLayoutFileReader::ReadSheetPieces(VPSheet *sheet)
{
AssertRootTag(ML::TagPieces);
ReadPieceList(sheet->GetPieceList());
}
//---------------------------------------------------------------------------------------------------------------------
void VPLayoutFileReader::ReadSheet(VPLayout *layout)
{
Q_UNUSED(layout);
// TODO
AssertRootTag(ML::TagSheet);
const QStringList tags
{
ML::TagName, // 0
ML::TagSize, // 1
ML::TagMargin, // 2
ML::TagPieces // 3
};
QScopedPointer<VPSheet> sheet (new VPSheet(layout));
while (readNextStartElement())
{
switch (tags.indexOf(name().toString()))
{
case 0: // name
sheet->SetName(readElementText());
break;
case 1: // size
sheet->SetSheetSize(ReadSize());
break;
case 2: // margin
sheet->SetSheetMargins(ReadMargins());
break;
case 3: // pieces
ReadSheetPieces(sheet.get());
break;
default:
qCDebug(MLReader, "Ignoring tag %s", qUtf8Printable(name().toString()));
skipCurrentElement();
break;
}
}
readElementText();
layout->AddSheet(sheet.take());
}
//---------------------------------------------------------------------------------------------------------------------
void VPLayoutFileReader::ReadPieceList(VPPieceList *pieceList)
{
SCASSERT(isStartElement() && (name() == ML::TagPieceList || name() == ML::TagUnplacedPieceList));
QXmlStreamAttributes attribs = attributes();
pieceList->SetName(ReadAttributeString(attribs, ML::AttrName, tr("Piece List")));
pieceList->SetIsVisible(ReadAttributeBool(attribs, ML::AttrVisible, trueStr));
@ -206,13 +274,13 @@ void VPLayoutFileReader::ReadPieceList(VPPieceList *pieceList)
{
if (name() == ML::TagPiece)
{
VPPiece *piece = new VPPiece();
ReadPiece(piece);
pieceList->AddPiece(piece);
QScopedPointer<VPPiece>piece(new VPPiece());
ReadPiece(piece.data());
pieceList->AddPiece(piece.take());
}
else
{
// TODO error handling, we encountered a tag that isn't defined in the specification
qCDebug(MLReader, "Ignoring tag %s", qUtf8Printable(name().toString()));
skipCurrentElement();
}
}
@ -221,13 +289,12 @@ void VPLayoutFileReader::ReadPieceList(VPPieceList *pieceList)
//---------------------------------------------------------------------------------------------------------------------
void VPLayoutFileReader::ReadPiece(VPPiece *piece)
{
Q_UNUSED(piece);
SCASSERT(isStartElement() && name() == ML::TagPiece);
AssertRootTag(ML::TagPiece);
QXmlStreamAttributes attribs = attributes();
piece->SetName(ReadAttributeString(attribs, ML::AttrName, tr("Piece")));
QString uuidStr = ReadAttributeString(attribs, ML::AttrID, QUuid().toString());// FIXME: is that correct to have a default value here?
QString uuidStr = ReadAttributeString(attribs, ML::AttrID, QUuid::createUuid().toString());
piece->SetUUID(QUuid(uuidStr));
bool showSeamline = ReadAttributeBool(attribs, ML::AttrShowSeamline, trueStr);
@ -251,7 +318,6 @@ void VPLayoutFileReader::ReadPiece(VPPiece *piece)
skipCurrentElement();
}
}
}
//---------------------------------------------------------------------------------------------------------------------
@ -265,24 +331,37 @@ QMarginsF VPLayoutFileReader::ReadMargins()
margins.setRight(ReadAttributeDouble(attribs, ML::AttrRight, QChar('0')));
margins.setBottom(ReadAttributeDouble(attribs, ML::AttrBottom, QChar('0')));
readElementText();
return margins;
}
//---------------------------------------------------------------------------------------------------------------------
QSizeF VPLayoutFileReader::ReadSize()
{
QSizeF size = QSize();
QSizeF size;
QXmlStreamAttributes attribs = attributes();
size.setWidth(ReadAttributeDouble(attribs, ML::AttrWidth, QChar('0')));
size.setHeight(ReadAttributeDouble(attribs, ML::AttrLength, QChar('0')));
readElementText();
return size;
}
//---------------------------------------------------------------------------------------------------------------------
void VPLayoutFileReader::AssertRootTag(const QString &tag) const
{
if (not (isStartElement() && name() == tag))
{
throw VException(tr("Unexpected tag %1 in line %2").arg(name()).arg(lineNumber()));
}
}
//---------------------------------------------------------------------------------------------------------------------
QString VPLayoutFileReader::ReadAttributeString(const QXmlStreamAttributes &attribs, const QString &name,
const QString &defValue)
const QString &defValue)
{
const QString parameter = attribs.value(name).toString();
if (parameter.isEmpty())
@ -291,10 +370,7 @@ QString VPLayoutFileReader::ReadAttributeString(const QXmlStreamAttributes &attr
{
throw VException(tr("Got empty attribute '%1'").arg(name));
}
else
{
return defValue;
}
return defValue;
}
return parameter;
}
@ -344,7 +420,7 @@ bool VPLayoutFileReader::ReadAttributeBool(const QXmlStreamAttributes &attribs,
//---------------------------------------------------------------------------------------------------------------------
qreal VPLayoutFileReader::ReadAttributeDouble(const QXmlStreamAttributes &attribs, const QString &name,
const QString &defValue)
const QString &defValue)
{
bool ok = false;
qreal param = 0;
@ -354,7 +430,7 @@ qreal VPLayoutFileReader::ReadAttributeDouble(const QXmlStreamAttributes &attrib
{
QString parametr = ReadAttributeString(attribs, name, defValue);
param = parametr.replace(QChar(','), QChar('.')).toDouble(&ok);
if (ok == false)
if (not ok)
{
throw VExceptionConversionError(message, name);
}

View File

@ -35,6 +35,10 @@
#include "vppiecelist.h"
#include "vppiece.h"
#include <QLoggingCategory>
Q_DECLARE_LOGGING_CATEGORY(MLReader)
class VPLayoutFileReader : public QXmlStreamReader
{
Q_DECLARE_TR_FUNCTIONS(VPLayoutFileReader)
@ -49,9 +53,11 @@ private:
void ReadLayout(VPLayout *layout);
void ReadProperties(VPLayout *layout);
void ReadControl(VPLayout *layout);
void ReadTiles(VPLayout *layout);
void ReadUnplacedPieces(VPLayout *layout);
void ReadSheets(VPLayout *layout);
void ReadSheetPieces(VPSheet *sheet);
void ReadSheet(VPLayout *layout);
void ReadPieceList(VPPieceList *pieceList);
void ReadPiece(VPPiece *piece);
@ -59,6 +65,8 @@ private:
QMarginsF ReadMargins();
QSizeF ReadSize();
void AssertRootTag(const QString &tag) const;
static QString ReadAttributeString(const QXmlStreamAttributes &attribs, const QString &name,
const QString &defValue);
static QString ReadAttributeEmptyString(const QXmlStreamAttributes &attribs, const QString &name);

View File

@ -33,6 +33,7 @@
#include "vppiece.h"
#include "vplayoutliterals.h"
#include "../ifc/xml/vlayoutconverter.h"
#include "../vmisc/projectversion.h"
//---------------------------------------------------------------------------------------------------------------------
void VPLayoutFileWriter::WriteFile(VPLayout *layout, QFile *file)
@ -52,9 +53,12 @@ void VPLayoutFileWriter::WriteLayout(VPLayout *layout)
{
writeStartElement(ML::TagLayout);
SetAttribute(ML::AttrVersion, VLayoutConverter::LayoutMaxVerStr);
writeComment(QStringLiteral("Layout created with Valentina v%1 (https://valentinaproject.bitbucket.io/).")
.arg(APP_VERSION_STR));
WriteProperties(layout);
WriteUnplacePiecesList(layout);
WritePieceList(layout->GetUnplacedPieceList(), ML::TagUnplacedPieces);
WriteSheets(layout);
writeEndElement(); //layout
}
@ -65,71 +69,62 @@ void VPLayoutFileWriter::WriteProperties(VPLayout *layout)
writeStartElement(ML::TagProperties);
writeTextElement(ML::TagUnit, UnitsToStr(layout->GetUnit()));
writeTextElement(ML::TagDescription, QString()); // TODO : define the value in layout
writeTextElement(ML::TagTitle, layout->GetTitle());
writeTextElement(ML::TagDescription, layout->GetDescription());
writeStartElement(ML::TagControl);
SetAttribute(ML::AttrWarningSuperposition, layout->GetWarningSuperpositionOfPieces());
SetAttribute(ML::AttrWarningOutOfBound, layout->GetWarningPiecesOutOfBound());
writeEndElement(); // control
// WriteTiles(layout); TODO: when tile functionality implemented, then uncomment this line
WriteTiles(layout);
writeEndElement(); // properties
}
//---------------------------------------------------------------------------------------------------------------------
void VPLayoutFileWriter::WriteUnplacePiecesList(VPLayout *layout)
{
Q_UNUSED(layout);
// TODO
}
//---------------------------------------------------------------------------------------------------------------------
void VPLayoutFileWriter::WriteSheets(VPLayout *layout)
{
Q_UNUSED(layout);
// TODO
writeStartElement(ML::TagSheets);
QList<VPSheet *> sheets = layout->GetSheets();
for (auto *sheet : sheets)
{
WriteSheet(sheet);
}
writeEndElement(); // sheets
}
//---------------------------------------------------------------------------------------------------------------------
void VPLayoutFileWriter::WriteSheet(VPSheet* sheet)
{
Q_UNUSED(sheet);
// TODO
writeStartElement(ML::TagSheet);
// WritePieceList(pieceList);
writeTextElement(ML::TagName, sheet->GetName());
WriteSize(sheet->GetSheetSize());
WriteMargins(sheet->GetSheetMargins());
WritePieceList(sheet->GetPieceList(), ML::TagPieces);
writeEndElement(); // sheet
}
//---------------------------------------------------------------------------------------------------------------------
void VPLayoutFileWriter::WriteTiles(VPLayout *layout)
{
Q_UNUSED(layout); // to be removed
writeStartElement(ML::TagTiles);
SetAttribute(ML::AttrVisible, false); // TODO / Fixme get the right value
SetAttribute(ML::AttrVisible, layout->GetShowTiles());
SetAttribute(ML::AttrMatchingMarks, "standard"); // TODO / Fixme get the right value
QSizeF size = QSizeF(); // TODO get the right size
WriteSize(size);
QMarginsF margins = QMarginsF(); // TODO get the right margins
WriteMargins(margins);
WriteSize(layout->GetTilesSize());
WriteMargins(layout->GetTilesMargins());
writeEndElement(); // tiles
}
//---------------------------------------------------------------------------------------------------------------------
void VPLayoutFileWriter::WritePieceList(VPPieceList *pieceList)
{
WritePieceList(pieceList, ML::TagPieceList);
}
//---------------------------------------------------------------------------------------------------------------------
void VPLayoutFileWriter::WritePieceList(VPPieceList *pieceList, const QString &tagName)
{
@ -139,9 +134,8 @@ void VPLayoutFileWriter::WritePieceList(VPPieceList *pieceList, const QString &t
// TODO selected info. Not sure how it's saved yet
//SetAttribute("selected", pieceList->GetIsSelected());
QList<VPPiece*> pieces = pieceList->GetPieces();
for (auto piece : pieces)
for (auto *piece : pieces)
{
WritePiece(piece);
}
@ -152,13 +146,11 @@ void VPLayoutFileWriter::WritePieceList(VPPieceList *pieceList, const QString &t
//---------------------------------------------------------------------------------------------------------------------
void VPLayoutFileWriter::WritePiece(VPPiece *piece)
{
Q_UNUSED(piece);
writeStartElement(ML::TagPiece);
SetAttribute(ML::AttrID, piece->GetUUID().toString());
SetAttribute(ML::AttrName, piece->GetName());
SetAttribute(ML::AttrMirrored, piece->GetPieceMirrored()); // TODO / Fixme get the right value
SetAttribute(ML::AttrShowSeamline, piece->GetShowSeamLine()); // TODO / Fixme get the right value
SetAttribute(ML::AttrMirrored, piece->GetPieceMirrored());
SetAttribute(ML::AttrShowSeamline, piece->GetShowSeamLine());
SetAttribute(ML::AttrTransform, "string representation of the transformation"); // TODO / Fixme get the right value
// TODO cuttingLine

View File

@ -54,11 +54,9 @@ public:
private:
void WriteLayout(VPLayout *layout);
void WriteProperties(VPLayout *layout);
void WriteUnplacePiecesList(VPLayout *layout);
void WriteSheets(VPLayout *layout);
void WriteSheet(VPSheet* sheet);
void WriteTiles(VPLayout *layout);
void WritePieceList(VPPieceList *pieceList);
void WritePieceList(VPPieceList *pieceList, const QString &tagName);
void WritePiece(VPPiece *piece);

View File

@ -27,22 +27,23 @@
*************************************************************************/
#include "vplayoutliterals.h"
namespace ML
namespace ML // Manual layout
{
const QString TagLayout = QStringLiteral("layout");
const QString TagProperties = QStringLiteral("properties");
const QString TagPieceLists = QStringLiteral("pieceLists");
const QString TagUnit = QStringLiteral("unit");
const QString TagTitle = QStringLiteral("title");
const QString TagDescription = QStringLiteral("description");
const QString TagSize = QStringLiteral("size");
const QString TagMargin = QStringLiteral("margin");
const QString TagControl = QStringLiteral("control");
const QString TagTiles = QStringLiteral("tiles");
const QString TagUnplacedPieceList = QStringLiteral("unplacedPieceList");
const QString TagPieceList = QStringLiteral("pieceList");
const QString TagUnplacedPieces = QStringLiteral("unplacedPieces");
const QString TagPieces = QStringLiteral("pieces");
const QString TagPiece = QStringLiteral("piece");
const QString TagSheets = QStringLiteral("sheets");
const QString TagSheet = QStringLiteral("sheet");
const QString TagName = QStringLiteral("name");
const QString AttrVersion = QStringLiteral("version");
const QString AttrWarningSuperposition = QStringLiteral("warningSuperposition");
@ -63,4 +64,4 @@ const QString AttrID = QStringLiteral("id");
const QString AttrMirrored = QStringLiteral("mirrored");
const QString AttrTransform = QStringLiteral("transform");
const QString AttrShowSeamline = QStringLiteral("showSeamline");
}
} // namespace ML

View File

@ -36,18 +36,19 @@ namespace ML
{
extern const QString TagLayout;
extern const QString TagProperties;
extern const QString TagPieceLists;
extern const QString TagUnit;
extern const QString TagTitle;
extern const QString TagDescription;
extern const QString TagSize;
extern const QString TagMargin;
extern const QString TagControl;
extern const QString TagTiles;
extern const QString TagUnplacedPieceList;
extern const QString TagPieceList;
extern const QString TagUnplacedPieces;
extern const QString TagPieces;
extern const QString TagPiece;
extern const QString TagSheets;
extern const QString TagSheet;
extern const QString TagName;
extern const QString AttrVersion;
extern const QString AttrWarningSuperposition;

View File

@ -5,41 +5,16 @@
<xs:element name="properties">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="unit"/>
<xs:element type="units" name="unit"/>
<xs:element type="xs:string" name="title"/>
<xs:element type="xs:string" name="description"/>
<xs:element name="size">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute type="xs:float" name="width"/>
<xs:attribute type="xs:short" name="length"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:element name="margin">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute type="xs:float" name="top"/>
<xs:attribute type="xs:float" name="right"/>
<xs:attribute type="xs:float" name="bottom"/>
<xs:attribute type="xs:float" name="left"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:element name="control">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute type="xs:string" name="followGrainLine"/>
<xs:attribute type="xs:string" name="warningSuperposition"/>
<xs:attribute type="xs:string" name="warningOutOfBound"/>
<xs:attribute type="xs:string" name="stickyEdges"/>
<xs:attribute type="xs:float" name="piecesGap"/>
</xs:extension>
</xs:simpleContent>
<xs:attribute type="xs:boolean" name="followGrainLine"/>
<xs:attribute type="xs:boolean" name="warningSuperposition"/>
<xs:attribute type="xs:boolean" name="warningOutOfBound"/>
<xs:attribute type="xs:boolean" name="stickyEdges"/>
<xs:attribute type="xs:float" name="piecesGap"/>
</xs:complexType>
</xs:element>
<xs:element name="tiles">
@ -47,165 +22,88 @@
<xs:sequence>
<xs:element name="size">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute type="xs:float" name="width"/>
<xs:attribute type="xs:float" name="length"/>
</xs:extension>
</xs:simpleContent>
<xs:attribute type="xs:float" name="width"/>
<xs:attribute type="xs:float" name="length"/>
</xs:complexType>
</xs:element>
<xs:element name="margin">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute type="xs:float" name="top"/>
<xs:attribute type="xs:float" name="right"/>
<xs:attribute type="xs:float" name="bottom"/>
<xs:attribute type="xs:float" name="left"/>
</xs:extension>
</xs:simpleContent>
<xs:attribute type="xs:float" name="top"/>
<xs:attribute type="xs:float" name="right"/>
<xs:attribute type="xs:float" name="bottom"/>
<xs:attribute type="xs:float" name="left"/>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute type="xs:string" name="visible"/>
<xs:attribute type="xs:boolean" name="visible"/>
<xs:attribute type="xs:string" name="matchingMarks"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="layers">
<xs:element name="unplacedPieces">
<xs:complexType>
<xs:sequence>
<xs:element name="unplacedPiecesLayer">
<xs:element name="piece" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
</xs:sequence>
<xs:attribute name="id" type="uuid"/>
<xs:attribute type="xs:string" name="name"/>
<xs:attribute type="xs:boolean" name="mirrored"/>
<xs:attribute type="xs:boolean" name="showSeamline"/>
<xs:attribute type="xs:string" name="transform"/>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute type="xs:string" name="name"/>
<xs:attribute type="xs:boolean" name="visible"/>
</xs:complexType>
</xs:element>
<xs:element name="sheets">
<xs:complexType>
<xs:sequence>
<xs:element name="sheet" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="name"/>
<xs:element name="size">
<xs:complexType>
<xs:attribute type="xs:float" name="width" use="required"/>
<xs:attribute type="xs:float" name="length" use="required"/>
</xs:complexType>
</xs:element>
<xs:element name="margin">
<xs:complexType>
<xs:attribute type="xs:float" name="top"/>
<xs:attribute type="xs:float" name="right"/>
<xs:attribute type="xs:float" name="bottom"/>
<xs:attribute type="xs:float" name="left"/>
</xs:complexType>
</xs:element>
<xs:element name="pieces">
<xs:complexType>
<xs:sequence>
<xs:element name="piece" maxOccurs="unbounded" minOccurs="0">
<xs:complexType mixed="true">
<xs:element name="piece" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="cuttingLine" minOccurs="0">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute type="xs:string" name="style"/>
<xs:attribute type="xs:string" name="color"/>
<xs:attribute type="xs:string" name="p"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:element name="seamLine" minOccurs="0">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute type="xs:string" name="style"/>
<xs:attribute type="xs:string" name="color"/>
<xs:attribute type="xs:string" name="visible"/>
<xs:attribute type="xs:string" name="p"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:element name="grainline" minOccurs="0">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute type="xs:float" name="angle"/>
<xs:attribute type="xs:string" name="p"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:element name="passMark" minOccurs="0">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute type="xs:string" name="p"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:element name="internalPath" minOccurs="0">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute type="xs:string" name="p"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:element name="placeLabel" minOccurs="0">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute type="xs:string" name="p"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:element name="labels" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element name="label">
<xs:complexType>
<xs:choice maxOccurs="unbounded" minOccurs="0">
<xs:element name="text">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute type="xs:string" name="align" use="optional"/>
<xs:attribute type="xs:string" name="decoration" use="optional"/>
<xs:attribute type="xs:byte" name="fsize" use="optional"/>
<xs:attribute type="xs:byte" name="size" use="optional"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:choice>
<xs:attribute type="xs:byte" name="width"/>
<xs:attribute type="xs:byte" name="height"/>
<xs:attribute type="xs:string" name="transform"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute type="xs:string" name="id" use="optional"/>
<xs:attribute type="xs:string" name="name" use="optional"/>
<xs:attribute type="xs:string" name="mirrored" use="optional"/>
<xs:attribute type="xs:string" name="transform" use="optional"/>
<xs:attribute name="id" type="uuid"/>
<xs:attribute type="xs:string" name="name"/>
<xs:attribute type="xs:boolean" name="mirrored"/>
<xs:attribute type="xs:boolean" name="showSeamline"/>
<xs:attribute type="xs:string" name="transform"/>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute type="xs:string" name="name"/>
<xs:attribute type="xs:boolean" name="visible"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="layer">
<xs:complexType>
<xs:sequence>
<xs:element name="piece">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute type="xs:string" name="id"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute type="xs:byte" name="id"/>
<xs:attribute type="xs:string" name="name"/>
<xs:attribute type="xs:string" name="selected"/>
<xs:attribute type="xs:string" name="visible"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
@ -213,9 +111,22 @@
<xs:attribute type="formatVersion" name="version"/>
</xs:complexType>
</xs:element>
<!--Types-->
<xs:simpleType name="formatVersion">
<xs:restriction base="xs:string">
<xs:pattern value="[0-9]{1,}\.[0-9]{1,}\.[0-9]{1,}"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="units">
<xs:restriction base="xs:string">
<xs:enumeration value="mm"/>
<xs:enumeration value="cm"/>
<xs:enumeration value="inch"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="uuid">
<xs:restriction base="xs:string">
<xs:pattern value="|\{[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}\}"/>
</xs:restriction>
</xs:simpleType>
</xs:schema>

View File

@ -112,14 +112,11 @@ void MessageHandler::handleMessage(QtMsgType type, const QString &description, c
//---------------------------------------------------------------------------------------------------------------------
VAbstractConverter::VAbstractConverter(const QString &fileName)
: VDomDocument(),
m_ver(0x0),
: m_ver(0x0),
m_originalFileName(fileName),
m_convertedFileName(fileName),
m_tmpFile()
m_convertedFileName(fileName)
{
setXMLContent(m_convertedFileName);// Throw an exception on error
m_ver = GetFormatVersion(GetFormatVersionStr());
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -81,7 +81,7 @@ protected:
private:
Q_DISABLE_COPY(VAbstractConverter)
QTemporaryFile m_tmpFile;
QTemporaryFile m_tmpFile{};
void ReserveFile() const;
};

View File

@ -39,6 +39,7 @@
VAbstractMConverter::VAbstractMConverter(const QString &fileName)
:VAbstractConverter(fileName)
{
m_ver = GetFormatVersion(GetFormatVersionStr());
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -127,7 +127,7 @@ public:
QString Major() const;
QString Minor() const;
QString Patch() const;
QString GetFormatVersionStr() const;
virtual QString GetFormatVersionStr() const;
static int GetFormatVersion(const QString &version);
static void RemoveAllChildren(QDomElement &domElement);

View File

@ -47,6 +47,7 @@ const QString VLabelTemplateConverter::CurrentSchema = QStringLiteral("
VLabelTemplateConverter::VLabelTemplateConverter(const QString &fileName)
: VAbstractConverter(fileName)
{
m_ver = GetFormatVersion(GetFormatVersionStr());
ValidateInputFile(CurrentSchema);
}

View File

@ -42,13 +42,36 @@ const QString VLayoutConverter::CurrentSchema = QStringLiteral("://schema/layo
//VLayoutConverter::LayoutMinVer; // <== DON'T FORGET TO UPDATE TOO!!!!
//VLayoutConverter::LayoutMaxVer; // <== DON'T FORGET TO UPDATE TOO!!!!
namespace
{
// The list of all string we use for conversion
// Better to use global variables because repeating QStringLiteral blows up code size
Q_GLOBAL_STATIC_WITH_ARGS(const QString, strVersion, (QLatin1String("version")))
}
//---------------------------------------------------------------------------------------------------------------------
VLayoutConverter::VLayoutConverter(const QString &fileName)
: VAbstractConverter(fileName)
{
m_ver = GetFormatVersion(GetFormatVersionStr());
ValidateInputFile(CurrentSchema);
}
//---------------------------------------------------------------------------------------------------------------------
auto VLayoutConverter::GetFormatVersionStr() const -> QString
{
QDomNode root = documentElement();
if (not root.isNull() && root.isElement())
{
const QDomElement layoutElement = root.toElement();
if (not layoutElement.isNull())
{
return GetParametrString(layoutElement, *strVersion, QStringLiteral("0.0.0"));
}
}
return QStringLiteral("0.0.0");
}
//---------------------------------------------------------------------------------------------------------------------
QString VLayoutConverter::XSDSchema(int ver) const
{

View File

@ -40,6 +40,8 @@ public:
explicit VLayoutConverter(const QString &fileName);
virtual ~VLayoutConverter() Q_DECL_EQ_DEFAULT;
virtual QString GetFormatVersionStr() const override;
static const QString LayoutMaxVerStr;
static const QString CurrentSchema;
static Q_DECL_CONSTEXPR const int LayoutMinVer = FORMAT_VERSION(0, 1, 0);

View File

@ -173,6 +173,7 @@ Q_GLOBAL_STATIC_WITH_ARGS(const QString, strQuantity, (QLatin1String("quantity")
VPatternConverter::VPatternConverter(const QString &fileName)
: VAbstractConverter(fileName)
{
m_ver = GetFormatVersion(GetFormatVersionStr());
ValidateInputFile(CurrentSchema);
}

View File

@ -46,6 +46,7 @@ const QString VWatermarkConverter::CurrentSchema = QStringLiteral("://s
VWatermarkConverter::VWatermarkConverter(const QString &fileName)
: VAbstractConverter(fileName)
{
m_ver = GetFormatVersion(GetFormatVersionStr());
ValidateInputFile(CurrentSchema);
}