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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -5,41 +5,16 @@
<xs:element name="properties"> <xs:element name="properties">
<xs:complexType> <xs:complexType>
<xs:sequence> <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 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:element name="control">
<xs:complexType> <xs:complexType>
<xs:simpleContent> <xs:attribute type="xs:boolean" name="followGrainLine"/>
<xs:extension base="xs:string"> <xs:attribute type="xs:boolean" name="warningSuperposition"/>
<xs:attribute type="xs:string" name="followGrainLine"/> <xs:attribute type="xs:boolean" name="warningOutOfBound"/>
<xs:attribute type="xs:string" name="warningSuperposition"/> <xs:attribute type="xs:boolean" name="stickyEdges"/>
<xs:attribute type="xs:string" name="warningOutOfBound"/> <xs:attribute type="xs:float" name="piecesGap"/>
<xs:attribute type="xs:string" name="stickyEdges"/>
<xs:attribute type="xs:float" name="piecesGap"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType> </xs:complexType>
</xs:element> </xs:element>
<xs:element name="tiles"> <xs:element name="tiles">
@ -47,165 +22,88 @@
<xs:sequence> <xs:sequence>
<xs:element name="size"> <xs:element name="size">
<xs:complexType> <xs:complexType>
<xs:simpleContent> <xs:attribute type="xs:float" name="width"/>
<xs:extension base="xs:string"> <xs:attribute type="xs:float" name="length"/>
<xs:attribute type="xs:float" name="width"/>
<xs:attribute type="xs:float" name="length"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType> </xs:complexType>
</xs:element> </xs:element>
<xs:element name="margin"> <xs:element name="margin">
<xs:complexType> <xs:complexType>
<xs:simpleContent> <xs:attribute type="xs:float" name="top"/>
<xs:extension base="xs:string"> <xs:attribute type="xs:float" name="right"/>
<xs:attribute type="xs:float" name="top"/> <xs:attribute type="xs:float" name="bottom"/>
<xs:attribute type="xs:float" name="right"/> <xs:attribute type="xs:float" name="left"/>
<xs:attribute type="xs:float" name="bottom"/>
<xs:attribute type="xs:float" name="left"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType> </xs:complexType>
</xs:element> </xs:element>
</xs:sequence> </xs:sequence>
<xs:attribute type="xs:string" name="visible"/> <xs:attribute type="xs:boolean" name="visible"/>
<xs:attribute type="xs:string" name="matchingMarks"/> <xs:attribute type="xs:string" name="matchingMarks"/>
</xs:complexType> </xs:complexType>
</xs:element> </xs:element>
</xs:sequence> </xs:sequence>
</xs:complexType> </xs:complexType>
</xs:element> </xs:element>
<xs:element name="layers"> <xs:element name="unplacedPieces">
<xs:complexType> <xs:complexType>
<xs:sequence> <xs:sequence>
<xs:element name="unplacedPiecesLayer"> <xs:element name="piece" minOccurs="0" maxOccurs="unbounded">
<xs:complexType> <xs:complexType>
<xs:sequence> <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:element name="pieces">
<xs:complexType> <xs:complexType>
<xs:sequence> <xs:sequence>
<xs:element name="piece" maxOccurs="unbounded" minOccurs="0"> <xs:element name="piece" minOccurs="0" maxOccurs="unbounded">
<xs:complexType mixed="true"> <xs:complexType>
<xs:sequence> <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:sequence>
<xs:attribute type="xs:string" name="id" use="optional"/> <xs:attribute name="id" type="uuid"/>
<xs:attribute type="xs:string" name="name" use="optional"/> <xs:attribute type="xs:string" name="name"/>
<xs:attribute type="xs:string" name="mirrored" use="optional"/> <xs:attribute type="xs:boolean" name="mirrored"/>
<xs:attribute type="xs:string" name="transform" use="optional"/> <xs:attribute type="xs:boolean" name="showSeamline"/>
<xs:attribute type="xs:string" name="transform"/>
</xs:complexType> </xs:complexType>
</xs:element> </xs:element>
</xs:sequence> </xs:sequence>
<xs:attribute type="xs:string" name="name"/>
<xs:attribute type="xs:boolean" name="visible"/>
</xs:complexType> </xs:complexType>
</xs:element> </xs:element>
</xs:sequence> </xs:sequence>
</xs:complexType> </xs:complexType>
</xs:element> </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:sequence>
</xs:complexType> </xs:complexType>
</xs:element> </xs:element>
@ -213,9 +111,22 @@
<xs:attribute type="formatVersion" name="version"/> <xs:attribute type="formatVersion" name="version"/>
</xs:complexType> </xs:complexType>
</xs:element> </xs:element>
<!--Types-->
<xs:simpleType name="formatVersion"> <xs:simpleType name="formatVersion">
<xs:restriction base="xs:string"> <xs:restriction base="xs:string">
<xs:pattern value="[0-9]{1,}\.[0-9]{1,}\.[0-9]{1,}"/> <xs:pattern value="[0-9]{1,}\.[0-9]{1,}\.[0-9]{1,}"/>
</xs:restriction> </xs:restriction>
</xs:simpleType> </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> </xs:schema>

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -42,13 +42,36 @@ const QString VLayoutConverter::CurrentSchema = QStringLiteral("://schema/layo
//VLayoutConverter::LayoutMinVer; // <== DON'T FORGET TO UPDATE TOO!!!! //VLayoutConverter::LayoutMinVer; // <== DON'T FORGET TO UPDATE TOO!!!!
//VLayoutConverter::LayoutMaxVer; // <== 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) VLayoutConverter::VLayoutConverter(const QString &fileName)
: VAbstractConverter(fileName) : VAbstractConverter(fileName)
{ {
m_ver = GetFormatVersion(GetFormatVersionStr());
ValidateInputFile(CurrentSchema); 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 QString VLayoutConverter::XSDSchema(int ver) const
{ {

View file

@ -40,6 +40,8 @@ public:
explicit VLayoutConverter(const QString &fileName); explicit VLayoutConverter(const QString &fileName);
virtual ~VLayoutConverter() Q_DECL_EQ_DEFAULT; virtual ~VLayoutConverter() Q_DECL_EQ_DEFAULT;
virtual QString GetFormatVersionStr() const override;
static const QString LayoutMaxVerStr; static const QString LayoutMaxVerStr;
static const QString CurrentSchema; static const QString CurrentSchema;
static Q_DECL_CONSTEXPR const int LayoutMinVer = FORMAT_VERSION(0, 1, 0); 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) VPatternConverter::VPatternConverter(const QString &fileName)
: VAbstractConverter(fileName) : VAbstractConverter(fileName)
{ {
m_ver = GetFormatVersion(GetFormatVersionStr());
ValidateInputFile(CurrentSchema); ValidateInputFile(CurrentSchema);
} }

View file

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