From 5467e213a2d24b201e9f081f075442b5c2ece916 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sat, 22 May 2021 20:29:33 +0300 Subject: [PATCH] Read/write empty layout file. --- src/app/puzzle/vpmainwindow.cpp | 10 +- src/app/puzzle/vpmainwindow.ui | 38 +-- src/app/puzzle/vppiecelist.cpp | 4 +- src/app/puzzle/xml/vplayoutfilereader.cpp | 278 ++++++++++++------- src/app/puzzle/xml/vplayoutfilereader.h | 8 + src/app/puzzle/xml/vplayoutfilewriter.cpp | 68 ++--- src/app/puzzle/xml/vplayoutfilewriter.h | 2 - src/app/puzzle/xml/vplayoutliterals.cpp | 11 +- src/app/puzzle/xml/vplayoutliterals.h | 7 +- src/libs/ifc/schema/layout/v0.1.0.xsd | 233 +++++----------- src/libs/ifc/xml/vabstractconverter.cpp | 7 +- src/libs/ifc/xml/vabstractconverter.h | 2 +- src/libs/ifc/xml/vabstractmconverter.cpp | 1 + src/libs/ifc/xml/vdomdocument.h | 2 +- src/libs/ifc/xml/vlabeltemplateconverter.cpp | 1 + src/libs/ifc/xml/vlayoutconverter.cpp | 23 ++ src/libs/ifc/xml/vlayoutconverter.h | 2 + src/libs/ifc/xml/vpatternconverter.cpp | 1 + src/libs/ifc/xml/vwatermarkconverter.cpp | 1 + 19 files changed, 358 insertions(+), 341 deletions(-) diff --git a/src/app/puzzle/vpmainwindow.cpp b/src/app/puzzle/vpmainwindow.cpp index e66656b9b..232c8a6b6 100644 --- a/src/app/puzzle/vpmainwindow.cpp +++ b/src/app/puzzle/vpmainwindow.cpp @@ -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(); diff --git a/src/app/puzzle/vpmainwindow.ui b/src/app/puzzle/vpmainwindow.ui index 8f7fdea5c..4ac7e21d7 100644 --- a/src/app/puzzle/vpmainwindow.ui +++ b/src/app/puzzle/vpmainwindow.ui @@ -14,7 +14,7 @@ Puzzle - + :/puzzleicon/64x64/logo.png:/puzzleicon/64x64/logo.png @@ -194,7 +194,7 @@ QTabWidget::Rounded - 0 + 1 @@ -207,7 +207,7 @@ - + :/puzzleicon/64x64/iconCurrentPiece.png:/puzzleicon/64x64/iconCurrentPiece.png @@ -408,7 +408,7 @@ - + :/puzzleicon/64x64/iconRotate90Clockwise.png:/puzzleicon/64x64/iconRotate90Clockwise.png @@ -428,7 +428,7 @@ - + :/puzzleicon/64x64/iconRotate90Anticlockwise.png:/puzzleicon/64x64/iconRotate90Anticlockwise.png @@ -448,7 +448,7 @@ - + :/puzzleicon/64x64/iconRotateGrainlineVertical.png:/puzzleicon/64x64/iconRotateGrainlineVertical.png @@ -468,7 +468,7 @@ - + :/puzzleicon/64x64/iconRotateGrainlineHorizontal.png:/puzzleicon/64x64/iconRotateGrainlineHorizontal.png @@ -628,7 +628,7 @@ - + :/puzzleicon/64x64/iconLayout.png:/puzzleicon/64x64/iconLayout.png @@ -668,7 +668,7 @@ 0 - -153 + -170 342 870 @@ -780,7 +780,7 @@ - + :/puzzleicon/64x64/iconPortrait.png:/puzzleicon/64x64/iconPortrait.png @@ -803,7 +803,7 @@ - + :/puzzleicon/64x64/iconLandscape.png:/puzzleicon/64x64/iconLandscape.png @@ -995,7 +995,7 @@ - + :/puzzleicon/64x64/iconGrainlineVertical.png:/puzzleicon/64x64/iconGrainlineVertical.png @@ -1015,7 +1015,7 @@ - + :/puzzleicon/64x64/iconGrainlineHorizontal.png:/puzzleicon/64x64/iconGrainlineHorizontal.png @@ -1101,7 +1101,7 @@ - + :/puzzleicon/64x64/iconTiles.png:/puzzleicon/64x64/iconTiles.png @@ -1211,7 +1211,7 @@ - + :/puzzleicon/64x64/iconPortrait.png:/puzzleicon/64x64/iconPortrait.png @@ -1231,7 +1231,7 @@ - + :/puzzleicon/64x64/iconLandscape.png:/puzzleicon/64x64/iconLandscape.png @@ -1389,7 +1389,7 @@ - + :/puzzleicon/64x64/iconProperties.png:/puzzleicon/64x64/iconProperties.png @@ -1810,6 +1810,8 @@ checkBoxLayoutWarningPiecesSuperposition checkBoxLayoutWarningPiecesOutOfBound - + + + diff --git a/src/app/puzzle/vppiecelist.cpp b/src/app/puzzle/vppiecelist.cpp index 65606f83c..c016c5f19 100644 --- a/src/app/puzzle/vppiecelist.cpp +++ b/src/app/puzzle/vppiecelist.cpp @@ -44,7 +44,7 @@ VPPieceList::VPPieceList(VPLayout *layout, VPSheet *sheet): //--------------------------------------------------------------------------------------------------------------------- VPPieceList::~VPPieceList() { - + qDeleteAll(m_pieces); } //--------------------------------------------------------------------------------------------------------------------- @@ -69,7 +69,7 @@ QList VPPieceList::GetPieces() //--------------------------------------------------------------------------------------------------------------------- void VPPieceList::ClearSelection() { - for (auto piece: m_pieces) + for (auto *piece: m_pieces) { piece->SetIsSelected(false); } diff --git a/src/app/puzzle/xml/vplayoutfilereader.cpp b/src/app/puzzle/xml/vplayoutfilereader.cpp index 4936a44ef..99aa0d455 100644 --- a/src/app/puzzle/xml/vplayoutfilereader.cpp +++ b/src/app/puzzle/xml/vplayoutfilereader.cpp @@ -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 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); + QScopedPointerpiece(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); } diff --git a/src/app/puzzle/xml/vplayoutfilereader.h b/src/app/puzzle/xml/vplayoutfilereader.h index f7b2b8d59..a7477ff4d 100644 --- a/src/app/puzzle/xml/vplayoutfilereader.h +++ b/src/app/puzzle/xml/vplayoutfilereader.h @@ -35,6 +35,10 @@ #include "vppiecelist.h" #include "vppiece.h" +#include + +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); diff --git a/src/app/puzzle/xml/vplayoutfilewriter.cpp b/src/app/puzzle/xml/vplayoutfilewriter.cpp index 3991483d5..a9c0ad140 100644 --- a/src/app/puzzle/xml/vplayoutfilewriter.cpp +++ b/src/app/puzzle/xml/vplayoutfilewriter.cpp @@ -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 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 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 diff --git a/src/app/puzzle/xml/vplayoutfilewriter.h b/src/app/puzzle/xml/vplayoutfilewriter.h index 2836c5186..287e6997e 100644 --- a/src/app/puzzle/xml/vplayoutfilewriter.h +++ b/src/app/puzzle/xml/vplayoutfilewriter.h @@ -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); diff --git a/src/app/puzzle/xml/vplayoutliterals.cpp b/src/app/puzzle/xml/vplayoutliterals.cpp index ada2d2f37..91bb2f3d8 100644 --- a/src/app/puzzle/xml/vplayoutliterals.cpp +++ b/src/app/puzzle/xml/vplayoutliterals.cpp @@ -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 diff --git a/src/app/puzzle/xml/vplayoutliterals.h b/src/app/puzzle/xml/vplayoutliterals.h index 0f1278b7d..27439a7da 100644 --- a/src/app/puzzle/xml/vplayoutliterals.h +++ b/src/app/puzzle/xml/vplayoutliterals.h @@ -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; diff --git a/src/libs/ifc/schema/layout/v0.1.0.xsd b/src/libs/ifc/schema/layout/v0.1.0.xsd index 0d6086b2e..2fac8a9ba 100644 --- a/src/libs/ifc/schema/layout/v0.1.0.xsd +++ b/src/libs/ifc/schema/layout/v0.1.0.xsd @@ -5,41 +5,16 @@ - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + @@ -47,165 +22,88 @@ - - - - - - + + - - - - - - - - + + + + - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + - - - - - - - - - - - - - - - - - - - @@ -213,9 +111,22 @@ + + + + + + + + + + + + + diff --git a/src/libs/ifc/xml/vabstractconverter.cpp b/src/libs/ifc/xml/vabstractconverter.cpp index 293b12bcb..990a98d14 100644 --- a/src/libs/ifc/xml/vabstractconverter.cpp +++ b/src/libs/ifc/xml/vabstractconverter.cpp @@ -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()); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/ifc/xml/vabstractconverter.h b/src/libs/ifc/xml/vabstractconverter.h index 708898531..4d103b65b 100644 --- a/src/libs/ifc/xml/vabstractconverter.h +++ b/src/libs/ifc/xml/vabstractconverter.h @@ -81,7 +81,7 @@ protected: private: Q_DISABLE_COPY(VAbstractConverter) - QTemporaryFile m_tmpFile; + QTemporaryFile m_tmpFile{}; void ReserveFile() const; }; diff --git a/src/libs/ifc/xml/vabstractmconverter.cpp b/src/libs/ifc/xml/vabstractmconverter.cpp index 1cfb68bc2..cd9ad0017 100644 --- a/src/libs/ifc/xml/vabstractmconverter.cpp +++ b/src/libs/ifc/xml/vabstractmconverter.cpp @@ -39,6 +39,7 @@ VAbstractMConverter::VAbstractMConverter(const QString &fileName) :VAbstractConverter(fileName) { + m_ver = GetFormatVersion(GetFormatVersionStr()); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/ifc/xml/vdomdocument.h b/src/libs/ifc/xml/vdomdocument.h index 97a5f0c57..c3b12d6d0 100644 --- a/src/libs/ifc/xml/vdomdocument.h +++ b/src/libs/ifc/xml/vdomdocument.h @@ -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); diff --git a/src/libs/ifc/xml/vlabeltemplateconverter.cpp b/src/libs/ifc/xml/vlabeltemplateconverter.cpp index 3fbd71777..b1f978344 100644 --- a/src/libs/ifc/xml/vlabeltemplateconverter.cpp +++ b/src/libs/ifc/xml/vlabeltemplateconverter.cpp @@ -47,6 +47,7 @@ const QString VLabelTemplateConverter::CurrentSchema = QStringLiteral(" VLabelTemplateConverter::VLabelTemplateConverter(const QString &fileName) : VAbstractConverter(fileName) { + m_ver = GetFormatVersion(GetFormatVersionStr()); ValidateInputFile(CurrentSchema); } diff --git a/src/libs/ifc/xml/vlayoutconverter.cpp b/src/libs/ifc/xml/vlayoutconverter.cpp index 8671199dc..beaed9420 100644 --- a/src/libs/ifc/xml/vlayoutconverter.cpp +++ b/src/libs/ifc/xml/vlayoutconverter.cpp @@ -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 { diff --git a/src/libs/ifc/xml/vlayoutconverter.h b/src/libs/ifc/xml/vlayoutconverter.h index 5e271b9bb..25874e9e5 100644 --- a/src/libs/ifc/xml/vlayoutconverter.h +++ b/src/libs/ifc/xml/vlayoutconverter.h @@ -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); diff --git a/src/libs/ifc/xml/vpatternconverter.cpp b/src/libs/ifc/xml/vpatternconverter.cpp index 024bc38a8..2a158b988 100644 --- a/src/libs/ifc/xml/vpatternconverter.cpp +++ b/src/libs/ifc/xml/vpatternconverter.cpp @@ -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); } diff --git a/src/libs/ifc/xml/vwatermarkconverter.cpp b/src/libs/ifc/xml/vwatermarkconverter.cpp index bb42aa389..1a9561224 100644 --- a/src/libs/ifc/xml/vwatermarkconverter.cpp +++ b/src/libs/ifc/xml/vwatermarkconverter.cpp @@ -46,6 +46,7 @@ const QString VWatermarkConverter::CurrentSchema = QStringLiteral("://s VWatermarkConverter::VWatermarkConverter(const QString &fileName) : VAbstractConverter(fileName) { + m_ver = GetFormatVersion(GetFormatVersionStr()); ValidateInputFile(CurrentSchema); }