diff --git a/src/app/puzzle/layout/vppiece.cpp b/src/app/puzzle/layout/vppiece.cpp index f5e197c58..57362e67d 100644 --- a/src/app/puzzle/layout/vppiece.cpp +++ b/src/app/puzzle/layout/vppiece.cpp @@ -31,6 +31,7 @@ #include "../vmisc/def.h" #include "vpsheet.h" +#include "../vlayout/vtextmanager.h" #include #include @@ -169,3 +170,75 @@ void VPPiece::SetLayout(VPLayout *layout) SCASSERT(layout != nullptr) m_layout = layout; } + +//--------------------------------------------------------------------------------------------------------------------- +void VPPiece::SetGrainlineEnabled(bool enabled) +{ + VLayoutPiece::SetGrainlineEnabled(enabled); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPPiece::SetGrainlineAngle(qreal angle) +{ + VLayoutPiece::SetGrainlineAngle(angle); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPPiece::SetGrainlineArrowType(GrainlineArrowDirection type) +{ + VLayoutPiece::SetGrainlineArrowType(type); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPPiece::SetGrainlinePoints(const QVector &points) +{ + VLayoutPiece::SetGrainlinePoints(points); +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VPPiece::GetPieceLabelRect() const -> QVector +{ + return VLayoutPiece::GetPieceLabelRect(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPPiece::SetPieceLabelRect(const QVector &rect) +{ + VLayoutPiece::SetPieceLabelRect(rect); +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VPPiece::GetPieceLabelData() const -> VTextManager +{ + return VLayoutPiece::GetPieceLabelData(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPPiece::SetPieceLabelData(const VTextManager &data) +{ + VLayoutPiece::SetPieceLabelData(data); +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VPPiece::GetPatternLabelRect() const -> QVector +{ + return VLayoutPiece::GetPatternLabelRect(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPPiece::SetPatternLabelRect(const QVector &rect) +{ + VLayoutPiece::SetPatternLabelRect(rect); +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VPPiece::GetPatternLabelData() const -> VTextManager +{ + return VLayoutPiece::GetPatternLabelData(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPPiece::SetPatternLabelData(const VTextManager &data) +{ + VLayoutPiece::SetPatternLabelData(data); +} diff --git a/src/app/puzzle/layout/vppiece.h b/src/app/puzzle/layout/vppiece.h index a21bea9ad..9cef09f26 100644 --- a/src/app/puzzle/layout/vppiece.h +++ b/src/app/puzzle/layout/vppiece.h @@ -83,6 +83,23 @@ public: auto Layout() const -> VPLayout *; void SetLayout(VPLayout *layout); + void SetGrainlineEnabled(bool enabled); + void SetGrainlineAngle(qreal angle); + void SetGrainlineArrowType(GrainlineArrowDirection type); + void SetGrainlinePoints(const QVector &points); + + auto GetPieceLabelRect() const -> QVector; + void SetPieceLabelRect(const QVector &rect); + + auto GetPieceLabelData() const ->VTextManager; + void SetPieceLabelData(const VTextManager &data); + + auto GetPatternLabelRect() const -> QVector; + void SetPatternLabelRect(const QVector &rect); + + auto GetPatternLabelData() const ->VTextManager; + void SetPatternLabelData(const VTextManager &data); + private: Q_DISABLE_COPY(VPPiece) diff --git a/src/app/puzzle/scene/vpgraphicssheet.cpp b/src/app/puzzle/scene/vpgraphicssheet.cpp index 2206366f1..2839cacff 100644 --- a/src/app/puzzle/scene/vpgraphicssheet.cpp +++ b/src/app/puzzle/scene/vpgraphicssheet.cpp @@ -33,19 +33,11 @@ #include //--------------------------------------------------------------------------------------------------------------------- -VPGraphicsSheet::VPGraphicsSheet(VPSheet *sheet, QGraphicsItem *parent): +VPGraphicsSheet::VPGraphicsSheet(VPLayout *layout, QGraphicsItem *parent): QGraphicsItem(parent), - m_sheet(sheet), + m_layout(layout), m_boundingRect(GetSheetRect()) -{ - -} - -//--------------------------------------------------------------------------------------------------------------------- -VPGraphicsSheet::~VPGraphicsSheet() -{ - -} +{} //--------------------------------------------------------------------------------------------------------------------- void VPGraphicsSheet::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) @@ -74,12 +66,12 @@ void VPGraphicsSheet::paint(QPainter *painter, const QStyleOptionGraphicsItem *o painter->drawRect(sheetRect); } - if(m_sheet->GetLayout()->LayoutSettings().GetShowGrid()) + if(m_layout->LayoutSettings().GetShowGrid()) { pen.setColor(QColor(204,204,204)); painter->setPen(pen); - qreal colWidth = m_sheet->GetLayout()->LayoutSettings().GetGridColWidth(); + qreal colWidth = m_layout->LayoutSettings().GetGridColWidth(); if(colWidth > 0) { qreal colX = colWidth; @@ -91,7 +83,7 @@ void VPGraphicsSheet::paint(QPainter *painter, const QStyleOptionGraphicsItem *o } } - qreal rowHeight = m_sheet->GetLayout()->LayoutSettings().GetGridRowHeight(); + qreal rowHeight = m_layout->LayoutSettings().GetGridRowHeight(); if(rowHeight > 0) { qreal rowY = rowHeight; @@ -112,8 +104,8 @@ void VPGraphicsSheet::paint(QPainter *painter, const QStyleOptionGraphicsItem *o QRectF VPGraphicsSheet::GetSheetRect() const { QPoint topLeft = QPoint(0,0); - QSizeF size = m_sheet->GetLayout()->LayoutSettings().GetSheetSize(); - if(m_sheet->GetLayout()->LayoutSettings().GetOrientation() == PageOrientation::Landscape) + QSizeF size = m_layout->LayoutSettings().GetSheetSize(); + if(m_layout->LayoutSettings().GetOrientation() == PageOrientation::Landscape) { size.transpose(); } @@ -124,10 +116,10 @@ QRectF VPGraphicsSheet::GetSheetRect() const //--------------------------------------------------------------------------------------------------------------------- QRectF VPGraphicsSheet::GetMarginsRect() const { - QMarginsF margins = m_sheet->GetLayout()->LayoutSettings().GetSheetMargins(); - QSizeF size = m_sheet->GetLayout()->LayoutSettings().GetSheetSize(); + QMarginsF margins = m_layout->LayoutSettings().GetSheetMargins(); + QSizeF size = m_layout->LayoutSettings().GetSheetSize(); - if(m_sheet->GetLayout()->LayoutSettings().GetOrientation() == PageOrientation::Landscape) + if(m_layout->LayoutSettings().GetOrientation() == PageOrientation::Landscape) { size.transpose(); } diff --git a/src/app/puzzle/scene/vpgraphicssheet.h b/src/app/puzzle/scene/vpgraphicssheet.h index d76170953..ffdd09a07 100644 --- a/src/app/puzzle/scene/vpgraphicssheet.h +++ b/src/app/puzzle/scene/vpgraphicssheet.h @@ -32,18 +32,17 @@ #include #include -class VPSheet; +class VPLayout; class VPGraphicsSheet : public QGraphicsItem { public: - explicit VPGraphicsSheet(VPSheet *sheet, QGraphicsItem *parent = nullptr); - ~VPGraphicsSheet(); + explicit VPGraphicsSheet(VPLayout *sheet, QGraphicsItem *parent = nullptr); + ~VPGraphicsSheet()=default; QRectF boundingRect() const override; void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override; - QRectF GetSheetRect() const; QRectF GetMarginsRect() const; @@ -62,7 +61,7 @@ public: private: Q_DISABLE_COPY(VPGraphicsSheet) - VPSheet *m_sheet{nullptr}; + VPLayout *m_layout{nullptr}; QRectF m_boundingRect; bool m_showMargin{true}; diff --git a/src/app/puzzle/scene/vpmaingraphicsview.cpp b/src/app/puzzle/scene/vpmaingraphicsview.cpp index bb4ef2fba..e63f08a25 100644 --- a/src/app/puzzle/scene/vpmaingraphicsview.cpp +++ b/src/app/puzzle/scene/vpmaingraphicsview.cpp @@ -64,7 +64,7 @@ VPMainGraphicsView::VPMainGraphicsView(VPLayout *layout, VPTileFactory *tileFact SCASSERT(m_layout != nullptr) setScene(m_scene); - m_graphicsSheet = new VPGraphicsSheet(m_layout->GetFocusedSheet()); + m_graphicsSheet = new VPGraphicsSheet(m_layout); m_graphicsSheet->setPos(0, 0); m_scene->addItem(m_graphicsSheet); diff --git a/src/app/puzzle/vpmainwindow.cpp b/src/app/puzzle/vpmainwindow.cpp index bc50c6b80..3878952a8 100644 --- a/src/app/puzzle/vpmainwindow.cpp +++ b/src/app/puzzle/vpmainwindow.cpp @@ -207,7 +207,9 @@ auto VPMainWindow::LoadFile(QString path) -> bool // updates the properties with the loaded data SetPropertiesData(); - // TODO : update the Carrousel and the QGraphicView + m_carrousel->Refresh(); + m_graphicsView->RefreshLayout(); + m_graphicsView->RefreshPieces(); return true; } diff --git a/src/app/puzzle/xml/vplayoutfilereader.cpp b/src/app/puzzle/xml/vplayoutfilereader.cpp index 6fbbfc3b7..496cdc521 100644 --- a/src/app/puzzle/xml/vplayoutfilereader.cpp +++ b/src/app/puzzle/xml/vplayoutfilereader.cpp @@ -26,11 +26,15 @@ ** ** *************************************************************************/ +#include +#include #include #include "vplayoutfilereader.h" #include "vplayoutfilewriter.h" #include "vplayoutliterals.h" #include "../layout/vpsheet.h" +#include "../vlayout/vlayoutpiecepath.h" +#include "../vlayout/vtextmanager.h" #include "../ifc/exception/vexception.h" #include "../ifc/exception/vexceptionconversionerror.h" @@ -42,6 +46,138 @@ Q_LOGGING_CATEGORY(MLReader, "mlReader") QT_WARNING_POP +namespace +{ + +//--------------------------------------------------------------------------------------------------------------------- +auto StringToTransfrom(const QString &matrix) -> QTransform +{ + QStringList elements = matrix.split(ML::groupSep); + if (elements.count() == 9) + { + qreal m11 = elements.at(0).toDouble(); + qreal m12 = elements.at(1).toDouble(); + qreal m13 = elements.at(2).toDouble(); + qreal m21 = elements.at(3).toDouble(); + qreal m22 = elements.at(4).toDouble(); + qreal m23 = elements.at(5).toDouble(); + qreal m31 = elements.at(6).toDouble(); + qreal m32 = elements.at(7).toDouble(); + qreal m33 = elements.at(8).toDouble(); + return {m11, m12, m13, m21, m22, m23, m31, m32, m33}; + } + + return {}; +} + +//--------------------------------------------------------------------------------------------------------------------- +auto StringToPoint(const QString &point) -> QPointF +{ + QStringList coordinates = point.split(ML::coordintatesSep); + if (coordinates.count() == 2) + { + return {coordinates.at(0).toDouble(), coordinates.at(1).toDouble()}; + } + + return {}; +} + +//--------------------------------------------------------------------------------------------------------------------- +auto StringToPath(const QString &path) -> QVector +{ + QVector p; + QStringList points = path.split(ML::pointsSep); + for (const auto& point : points) + { + p.append(StringToPoint(point)); + } + + return p; +} + +//--------------------------------------------------------------------------------------------------------------------- +auto StringToGrainlineArrowDirrection(const QString &dirrection) -> GrainlineArrowDirection +{ + const QStringList arrows + { + ML::atFrontStr, // 0 + ML::atRearStr, // 1 + ML::atBothStr // 2 + }; + + GrainlineArrowDirection arrowDirection = GrainlineArrowDirection::atBoth; + switch (arrows.indexOf(dirrection)) + { + case 0:// at front + arrowDirection = GrainlineArrowDirection::atFront; + break; + case 1:// at rear + arrowDirection = GrainlineArrowDirection::atRear; + break; + case 2:// at both + default: + arrowDirection = GrainlineArrowDirection::atBoth; + break; + } + return arrowDirection; +} + +//--------------------------------------------------------------------------------------------------------------------- +auto StringToLine(const QString &string) -> QLineF +{ + QStringList points = string.split(ML::groupSep); + if (points.count() == 2) + { + return {StringToPoint(points.at(0)), StringToPoint(points.at(1))}; + } + + return {}; +} + +//--------------------------------------------------------------------------------------------------------------------- +auto StringToLines(const QString &string) -> QVector +{ + QStringList lines = string.split(ML::itemsSep); + QVector path; + + for (const auto& line : lines) + { + QLineF l = StringToLine(line); + if (not l.isNull()) + { + path.append(StringToLine(line)); + } + } + + return path; +} + +//--------------------------------------------------------------------------------------------------------------------- +auto StringToRect(const QString &string) -> QRectF +{ + QStringList points = string.split(ML::groupSep); + if (points.count() == 4) + { + return {points.at(0).toDouble(), points.at(1).toDouble(), points.at(2).toDouble(), points.at(3).toDouble()}; + } + + return {}; +} + +//--------------------------------------------------------------------------------------------------------------------- +auto StringToMarkerShape(const QString &string) -> PlaceLabelImg +{ + PlaceLabelImg shape; + QStringList paths = string.split(ML::itemsSep); + for (const auto& path : paths) + { + shape.append(StringToPath(path)); + } + + return shape; +} +} // namespace + //--------------------------------------------------------------------------------------------------------------------- auto VPLayoutFileReader::ReadFile(VPLayout *layout, QFile *file) -> bool { @@ -71,9 +207,7 @@ void VPLayoutFileReader::ReadLayout(VPLayout *layout) { ML::TagProperties, // 0 ML::TagUnplacedPieces, // 1 - ML::TagSheets, // 2 - ML::TagSize, // 3 - ML::TagMargin // 4 + ML::TagSheets // 2 }; while (readNextStartElement()) @@ -89,12 +223,6 @@ void VPLayoutFileReader::ReadLayout(VPLayout *layout) case 2: // ML::TagSheets ReadSheets(layout); break; - case 3: // size - layout->LayoutSettings().SetSheetSize(ReadSize()); - break; - case 4: // margin - layout->LayoutSettings().SetSheetMargins(ReadMargins()); - break; default: qCDebug(MLReader, "Ignoring tag %s", qUtf8Printable(name().toString())); skipCurrentElement(); @@ -113,8 +241,10 @@ void VPLayoutFileReader::ReadProperties(VPLayout *layout) ML::TagUnit, // 0 ML::TagTitle, // 1 ML::TagDescription, // 2 - ML::TagControl, // 3 - ML::TagTiles // 4 + ML::TagSize, // 3 + ML::TagMargin, // 4 + ML::TagControl, // 5 + ML::TagTiles // 6 }; while (readNextStartElement()) @@ -135,11 +265,17 @@ void VPLayoutFileReader::ReadProperties(VPLayout *layout) qDebug("read description"); layout->LayoutSettings().SetDescription(readElementText()); break; - case 3:// control + case 3: // size + layout->LayoutSettings().SetSheetSize(ReadSize()); + break; + case 4: // margin + layout->LayoutSettings().SetSheetMargins(ReadMargins()); + break; + case 5: // control qDebug("read control"); ReadControl(layout); break; - case 4:// tiles + case 6: // tiles qDebug("read tiles"); ReadTiles(layout); break; @@ -160,6 +296,9 @@ void VPLayoutFileReader::ReadControl(VPLayout *layout) layout->LayoutSettings().SetWarningSuperpositionOfPieces( ReadAttributeBool(attribs, ML::AttrWarningSuperposition, trueStr)); layout->LayoutSettings().SetWarningPiecesOutOfBound(ReadAttributeBool(attribs, ML::AttrWarningOutOfBound, trueStr)); + layout->LayoutSettings().SetStickyEdges(ReadAttributeBool(attribs, ML::AttrStickyEdges, trueStr)); + layout->LayoutSettings().SetPiecesGap(ReadAttributeDouble(attribs, ML::AttrPiecesGap, QChar('0'))); +// layout->LayoutSettings().SetFollowGrainline(ReadAttributeBool(attribs, ML::AttrFollowGrainLine, trueStr)); readElementText(); } @@ -302,26 +441,303 @@ void VPLayoutFileReader::ReadPiece(VPPiece *piece) bool pieceMirrored = ReadAttributeBool(attribs, ML::AttrMirrored, falseStr); piece->SetMirror(pieceMirrored); - // TODO read the further attributes + QString matrix = ReadAttributeEmptyString(attribs, ML::AttrTransform); + piece->SetMatrix(StringToTransfrom(matrix)); + + const QStringList tags + { + ML::TagSeamLine, // 0 + ML::TagSeamAllowance, // 1 + ML::TagGrainline, // 2 + ML::TagNotches, // 3 + ML::TagInternalPaths, // 4 + ML::TagMarkers, // 5 + ML::TagLabels // 6 + }; while (readNextStartElement()) { - if (name() == QString("...")) + switch (tags.indexOf(name().toString())) { - // TODO - readElementText(); + case 0: // seam line + piece->SetCountourPoints(StringToPath(readElementText())); + break; + case 1: // seam allowance + ReadSeamAllowance(piece); + break; + case 2: // grainline + ReadGrainline(piece); + break; + case 3: // notches + ReadNotches(piece); + break; + case 4: // internal paths + ReadInternalPaths(piece); + break; + case 5: // markers + ReadMarkers(piece); + break; + case 6: // labels + ReadLabels(piece); + break; + default: + qCDebug(MLReader, "Ignoring tag %s", qUtf8Printable(name().toString())); + skipCurrentElement(); + break; + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPLayoutFileReader::ReadSeamAllowance(VPPiece *piece) +{ + AssertRootTag(ML::TagSeamAllowance); + + QXmlStreamAttributes attribs = attributes(); + bool enabled = ReadAttributeBool(attribs, ML::AttrEnabled, falseStr); + piece->SetSeamAllowance(enabled); + + bool builtIn = ReadAttributeBool(attribs, ML::AttrBuiltIn, falseStr); + QVector path = StringToPath(readElementText()); + + if (enabled) + { + if (not builtIn) + { + // TODO add check if not empty + piece->SetSeamAllowancePoints(path); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPLayoutFileReader::ReadGrainline(VPPiece *piece) +{ + AssertRootTag(ML::TagGrainline); + + QXmlStreamAttributes attribs = attributes(); + bool enabled = ReadAttributeBool(attribs, ML::AttrEnabled, falseStr); + piece->SetGrainlineEnabled(enabled); + QVector path = StringToPath(readElementText()); + + if (enabled) + { + piece->SetGrainlineAngle(ReadAttributeDouble(attribs, ML::AttrAngle, QChar('0'))); + QString arrowDirection = ReadAttributeEmptyString(attribs, ML::AttrArrowDirection); + piece->SetGrainlineArrowType(StringToGrainlineArrowDirrection(arrowDirection)); + + // TODO add check if not empty + piece->SetGrainlinePoints(path); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPLayoutFileReader::ReadNotches(VPPiece *piece) +{ + AssertRootTag(ML::TagNotches); + + QVector passmarks; + + while (readNextStartElement()) + { + if (name() == ML::TagNotch) + { + passmarks.append(ReadNotch()); } else { - // TODO error handling, we encountered a tag that isn't defined in the specification + qCDebug(MLReader, "Ignoring tag %s", qUtf8Printable(name().toString())); + skipCurrentElement(); + } + } + + piece->SetPassmarks(passmarks); +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VPLayoutFileReader::ReadNotch() -> VLayoutPassmark +{ + AssertRootTag(ML::TagNotch); + + QXmlStreamAttributes attribs = attributes(); + + VLayoutPassmark passmark; + passmark.isBuiltIn = ReadAttributeBool(attribs, ML::AttrBuiltIn, falseStr); + passmark.baseLine = StringToLine(ReadAttributeEmptyString(attribs, ML::AttrBaseLine)); + passmark.lines = StringToLines(ReadAttributeEmptyString(attribs, ML::AttrPath)); + + QString defaultType = QString::number(static_cast(PassmarkLineType::OneLine)); + passmark.type = static_cast(ReadAttributeUInt(attribs, ML::AttrType, defaultType)); + + readElementText(); + + return passmark; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPLayoutFileReader::ReadInternalPaths(VPPiece *piece) +{ + AssertRootTag(ML::TagInternalPaths); + + QVector internalPaths; + + while (readNextStartElement()) + { + if (name() == ML::TagInternalPath) + { + internalPaths.append(ReadInternalPath()); + } + else + { + qCDebug(MLReader, "Ignoring tag %s", qUtf8Printable(name().toString())); + skipCurrentElement(); + } + } + + piece->SetInternalPaths(internalPaths); +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VPLayoutFileReader::ReadInternalPath() -> VLayoutPiecePath +{ + AssertRootTag(ML::TagInternalPath); + + VLayoutPiecePath path; + + QXmlStreamAttributes attribs = attributes(); + path.SetCutPath(ReadAttributeBool(attribs, ML::AttrCut, falseStr)); + path.SetPenStyle(LineStyleToPenStyle(ReadAttributeString(attribs, ML::AttrPenStyle, TypeLineLine))); + // TODO check if not empty + path.SetPoints(StringToPath(readElementText())); + + return path; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPLayoutFileReader::ReadMarkers(VPPiece *piece) +{ + AssertRootTag(ML::TagMarkers); + + QVector markers; + + while (readNextStartElement()) + { + if (name() == ML::TagMarker) + { + markers.append(ReadMarker()); + } + else + { + qCDebug(MLReader, "Ignoring tag %s", qUtf8Printable(name().toString())); + skipCurrentElement(); + } + } + + piece->SetPlaceLabels(markers); +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VPLayoutFileReader::ReadMarker() -> VLayoutPlaceLabel +{ + AssertRootTag(ML::TagMarker); + + VLayoutPlaceLabel marker; + + QXmlStreamAttributes attribs = attributes(); + + QString matrix = ReadAttributeEmptyString(attribs, ML::AttrTransform); + marker.rotationMatrix = StringToTransfrom(matrix); + + marker.type = static_cast(ReadAttributeUInt(attribs, ML::AttrType, QChar('0'))); + marker.center = StringToPoint(ReadAttributeEmptyString(attribs, ML::AttrCenter)); + marker.box = StringToRect(ReadAttributeEmptyString(attribs, ML::AttrBox)); + marker.shape = StringToMarkerShape(readElementText()); + + return marker; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPLayoutFileReader::ReadLabels(VPPiece *piece) +{ + AssertRootTag(ML::TagLabels); + + while (readNextStartElement()) + { + if (name() == ML::TagPieceLabel) + { + QXmlStreamAttributes attribs = attributes(); + piece->SetPieceLabelRect(StringToPath(ReadAttributeEmptyString(attribs, ML::AttrShape))); + + piece->SetPieceLabelData(ReadLabelLines()); + } + else if (name() == ML::TagPatternLabel) + { + QXmlStreamAttributes attribs = attributes(); + piece->SetPatternLabelRect(StringToPath(ReadAttributeEmptyString(attribs, ML::AttrShape))); + + piece->SetPatternLabelData(ReadLabelLines()); + } + else + { + qCDebug(MLReader, "Ignoring tag %s", qUtf8Printable(name().toString())); skipCurrentElement(); } } } //--------------------------------------------------------------------------------------------------------------------- -QMarginsF VPLayoutFileReader::ReadMargins() +auto VPLayoutFileReader::ReadLabelLines() -> VTextManager +{ + AssertRootTag(ML::TagLabels); + + VTextManager text; + QVector lines; + + QXmlStreamAttributes attribs = attributes(); + QFont f; + f.fromString(ReadAttributeEmptyString(attribs, ML::AttrFont)); + text.SetFont(f); + + while (readNextStartElement()) + { + if (name() == ML::TagLine) + { + lines.append(ReadLabelLine()); + } + else + { + qCDebug(MLReader, "Ignoring tag %s", qUtf8Printable(name().toString())); + skipCurrentElement(); + } + } + + text.SetAllSourceLines(lines); + + return text; +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VPLayoutFileReader::ReadLabelLine() -> TextLine +{ + AssertRootTag(ML::TagLine); + + TextLine line; + + QXmlStreamAttributes attribs = attributes(); + + line.m_iFontSize = ReadAttributeInt(attribs, ML::AttrFontSize, QString::number(MIN_FONT_SIZE)); + line.m_bold = ReadAttributeBool(attribs, ML::AttrBold, falseStr); + line.m_italic = ReadAttributeBool(attribs, ML::AttrItalic, falseStr); + int alignment = ReadAttributeInt(attribs, ML::AttrAlignment, QString::number(static_cast(Qt::AlignCenter))); + line.m_eAlign = static_cast(alignment); + line.m_qsText = readElementText(); + + return line; +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VPLayoutFileReader::ReadMargins() -> QMarginsF { QMarginsF margins = QMarginsF(); @@ -337,7 +753,7 @@ QMarginsF VPLayoutFileReader::ReadMargins() } //--------------------------------------------------------------------------------------------------------------------- -QSizeF VPLayoutFileReader::ReadSize() +auto VPLayoutFileReader::ReadSize() -> QSizeF { QSizeF size; @@ -360,8 +776,8 @@ void VPLayoutFileReader::AssertRootTag(const QString &tag) const } //--------------------------------------------------------------------------------------------------------------------- -QString VPLayoutFileReader::ReadAttributeString(const QXmlStreamAttributes &attribs, const QString &name, - const QString &defValue) +auto VPLayoutFileReader::ReadAttributeString(const QXmlStreamAttributes &attribs, const QString &name, + const QString &defValue) -> QString { const QString parameter = attribs.value(name).toString(); if (parameter.isEmpty()) @@ -376,14 +792,14 @@ QString VPLayoutFileReader::ReadAttributeString(const QXmlStreamAttributes &attr } //--------------------------------------------------------------------------------------------------------------------- -QString VPLayoutFileReader::ReadAttributeEmptyString(const QXmlStreamAttributes &attribs, const QString &name) +auto VPLayoutFileReader::ReadAttributeEmptyString(const QXmlStreamAttributes &attribs, const QString &name) -> QString { return attribs.value(name).toString(); } //--------------------------------------------------------------------------------------------------------------------- -bool VPLayoutFileReader::ReadAttributeBool(const QXmlStreamAttributes &attribs, const QString &name, - const QString &defValue) +auto VPLayoutFileReader::ReadAttributeBool(const QXmlStreamAttributes &attribs, const QString &name, + const QString &defValue) -> bool { QString parametr; bool val = true; @@ -419,8 +835,8 @@ bool VPLayoutFileReader::ReadAttributeBool(const QXmlStreamAttributes &attribs, } //--------------------------------------------------------------------------------------------------------------------- -qreal VPLayoutFileReader::ReadAttributeDouble(const QXmlStreamAttributes &attribs, const QString &name, - const QString &defValue) +auto VPLayoutFileReader::ReadAttributeDouble(const QXmlStreamAttributes &attribs, const QString &name, + const QString &defValue) -> qreal { bool ok = false; qreal param = 0; @@ -443,3 +859,55 @@ qreal VPLayoutFileReader::ReadAttributeDouble(const QXmlStreamAttributes &attrib } return param; } + +//--------------------------------------------------------------------------------------------------------------------- +auto VPLayoutFileReader::ReadAttributeUInt(const QXmlStreamAttributes &attribs, const QString &name, + const QString &defValue) -> quint32 +{ + bool ok = false; + quint32 param = 0; + + const QString message = QObject::tr("Can't convert toUInt parameter"); + try + { + QString parametr = ReadAttributeString(attribs, name, defValue); + param = parametr.replace(QChar(','), QChar('.')).toUInt(&ok); + if (not ok) + { + throw VExceptionConversionError(message, name); + } + } + catch (const VException &e) + { + VExceptionConversionError excep(message, name); + excep.AddMoreInformation(e.ErrorMessage()); + throw excep; + } + return param; +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VPLayoutFileReader::ReadAttributeInt(const QXmlStreamAttributes &attribs, const QString &name, + const QString &defValue) -> int +{ + bool ok = false; + int param = 0; + + const QString message = QObject::tr("Can't convert toInt parameter"); + try + { + QString parametr = ReadAttributeString(attribs, name, defValue); + param = parametr.replace(QChar(','), QChar('.')).toInt(&ok); + if (not ok) + { + throw VExceptionConversionError(message, name); + } + } + catch (const VException &e) + { + VExceptionConversionError excep(message, name); + excep.AddMoreInformation(e.ErrorMessage()); + throw excep; + } + return param; +} diff --git a/src/app/puzzle/xml/vplayoutfilereader.h b/src/app/puzzle/xml/vplayoutfilereader.h index 92886d741..3261ca267 100644 --- a/src/app/puzzle/xml/vplayoutfilereader.h +++ b/src/app/puzzle/xml/vplayoutfilereader.h @@ -38,6 +38,8 @@ Q_DECLARE_LOGGING_CATEGORY(MLReader) +struct TextLine; + class VPLayoutFileReader : public QXmlStreamReader { Q_DECLARE_TR_FUNCTIONS(VPLayoutFileReader) @@ -45,7 +47,7 @@ public: VPLayoutFileReader()=default; ~VPLayoutFileReader()=default; - bool ReadFile(VPLayout *layout, QFile *file); + auto ReadFile(VPLayout *layout, QFile *file) -> bool; private: Q_DISABLE_COPY(VPLayoutFileReader) @@ -59,18 +61,34 @@ private: void ReadSheet(VPLayout *layout); void ReadPieces(VPLayout *layout, VPSheet *sheet=nullptr); void ReadPiece(VPPiece *piece); + void ReadSeamAllowance(VPPiece *piece); + void ReadGrainline(VPPiece *piece); + void ReadNotches(VPPiece *piece); + auto ReadNotch() -> VLayoutPassmark; + void ReadInternalPaths(VPPiece *piece); + auto ReadInternalPath() -> VLayoutPiecePath; + void ReadMarkers(VPPiece *piece); + auto ReadMarker() -> VLayoutPlaceLabel; + void ReadLabels(VPPiece *piece); + auto ReadLabelLines() -> VTextManager; + auto ReadLabelLine() -> TextLine; - QMarginsF ReadMargins(); - QSizeF ReadSize(); + auto ReadMargins() -> QMarginsF; + auto ReadSize() -> QSizeF; 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); - static bool ReadAttributeBool(const QXmlStreamAttributes &attribs, const QString &name, const QString &defValue); - static qreal ReadAttributeDouble(const QXmlStreamAttributes &attribs, const QString &name, - const QString &defValue); + static auto ReadAttributeString(const QXmlStreamAttributes &attribs, const QString &name, + const QString &defValue) -> QString; + static auto ReadAttributeEmptyString(const QXmlStreamAttributes &attribs, const QString &name) -> QString; + static auto ReadAttributeBool(const QXmlStreamAttributes &attribs, const QString &name, + const QString &defValue) -> bool; + static auto ReadAttributeDouble(const QXmlStreamAttributes &attribs, const QString &name, + const QString &defValue) -> qreal; + static auto ReadAttributeUInt(const QXmlStreamAttributes &attribs, const QString &name, + const QString &defValue) -> quint32; + static auto ReadAttributeInt(const QXmlStreamAttributes &attribs, const QString &name, + const QString &defValue) -> int; }; #endif // VPLAYOUTFILEREADER_H diff --git a/src/app/puzzle/xml/vplayoutfilewriter.cpp b/src/app/puzzle/xml/vplayoutfilewriter.cpp index 7bd0aeb34..8f3791fc8 100644 --- a/src/app/puzzle/xml/vplayoutfilewriter.cpp +++ b/src/app/puzzle/xml/vplayoutfilewriter.cpp @@ -33,6 +33,108 @@ #include "vplayoutliterals.h" #include "../ifc/xml/vlayoutconverter.h" #include "../vmisc/projectversion.h" +#include "../vlayout/vlayoutpiecepath.h" +#include "../vlayout/vtextmanager.h" + +namespace +{ +//--------------------------------------------------------------------------------------------------------------------- +template +auto NumberToString(T number) -> QString +{ + const QLocale locale = QLocale::c(); + return locale.toString(number, 'g', 12).remove(locale.groupSeparator()); +} + +//--------------------------------------------------------------------------------------------------------------------- +auto TransformToString(const QTransform &m) -> QString +{ + QStringList matrix + { + NumberToString(m.m11()), + NumberToString(m.m12()), + NumberToString(m.m13()), + NumberToString(m.m21()), + NumberToString(m.m22()), + NumberToString(m.m23()), + NumberToString(m.m31()), + NumberToString(m.m32()), + NumberToString(m.m33()) + }; + return matrix.join(ML::groupSep); +} + +//--------------------------------------------------------------------------------------------------------------------- +auto PointToString(const QPointF &p) -> QString +{ + return NumberToString(p.x()) + ML::coordintatesSep + NumberToString(p.y()); +} + +//--------------------------------------------------------------------------------------------------------------------- +auto PathToString(const QVector &pathPoints) -> QString +{ + QStringList path; + + for (auto point : pathPoints) + { + path.append(PointToString(point)); + } + + return path.join(ML::pointsSep); +} + +//--------------------------------------------------------------------------------------------------------------------- +auto RectToString(const QRectF &r) -> QString +{ + return NumberToString(r.x()) + ML::groupSep + + NumberToString(r.y()) + ML::groupSep + + NumberToString(r.width()) + ML::groupSep + + NumberToString(r.height()); +} + +//--------------------------------------------------------------------------------------------------------------------- +auto MarkerShapeToString(const PlaceLabelImg &shape) -> QString +{ + QStringList s; + for (const auto& path : shape) + { + s.append(PathToString(path)); + } + return s.join(ML::itemsSep); +} + +//--------------------------------------------------------------------------------------------------------------------- +auto LineToString(const QLineF &line) -> QString +{ + return PointToString(line.p1()) + ML::groupSep + PointToString(line.p2()); +} + +//--------------------------------------------------------------------------------------------------------------------- +auto LinesToString(const QVector &lines) -> QString +{ + QStringList l; + for (auto line : lines) + { + l.append(LineToString(line)); + } + return l.join(ML::itemsSep); +} + +//--------------------------------------------------------------------------------------------------------------------- +auto GrainlineArrowDirrectionToString(GrainlineArrowDirection type) -> QString +{ + switch(type) + { + case GrainlineArrowDirection::atFront: + return ML::atFrontStr; + case GrainlineArrowDirection::atRear: + return ML::atRearStr; + case GrainlineArrowDirection::atBoth: + default: + return ML::atBothStr; + } +} +} // namespace //--------------------------------------------------------------------------------------------------------------------- void VPLayoutFileWriter::WriteFile(VPLayout *layout, QFile *file) @@ -41,6 +143,8 @@ void VPLayoutFileWriter::WriteFile(VPLayout *layout, QFile *file) setAutoFormatting(true); writeStartDocument(); + writeComment(QStringLiteral("Layout created with Valentina v%1 (https://smart-pattern.com.ua/).") + .arg(APP_VERSION_STR)); WriteLayout(layout); writeEndDocument(); @@ -52,13 +156,9 @@ void VPLayoutFileWriter::WriteLayout(VPLayout *layout) { writeStartElement(ML::TagLayout); SetAttribute(ML::AttrVersion, VLayoutConverter::LayoutMaxVerStr); - writeComment(QStringLiteral("Layout created with Valentina v%1 (https://smart-pattern.com.ua/).") - .arg(APP_VERSION_STR)); - WriteProperties(layout); WritePieceList(layout->GetUnplacedPieces(), ML::TagUnplacedPieces); WriteSheets(layout); - writeEndElement(); //layout } @@ -76,6 +176,9 @@ void VPLayoutFileWriter::WriteProperties(VPLayout *layout) writeStartElement(ML::TagControl); SetAttribute(ML::AttrWarningSuperposition, layout->LayoutSettings().GetWarningSuperpositionOfPieces()); SetAttribute(ML::AttrWarningOutOfBound, layout->LayoutSettings().GetWarningPiecesOutOfBound()); + SetAttribute(ML::AttrStickyEdges, layout->LayoutSettings().GetStickyEdges()); + SetAttribute(ML::AttrPiecesGap, layout->LayoutSettings().GetPiecesGap()); +// SetAttribute(ML::AttrFollowGrainLine, layout->LayoutSettings().GetFollowGrainline()); writeEndElement(); // control WriteTiles(layout); @@ -142,19 +245,110 @@ void VPLayoutFileWriter::WritePiece(VPPiece *piece) writeStartElement(ML::TagPiece); SetAttribute(ML::AttrID, piece->GetUUID().toString()); SetAttribute(ML::AttrName, piece->GetName()); - SetAttribute(ML::AttrMirrored, piece->IsMirror()); -// SetAttribute(ML::AttrShowSeamline, piece->GetShowSeamLine()); - SetAttribute(ML::AttrTransform, "string representation of the transformation"); // TODO / Fixme get the right value + SetAttributeOrRemoveIf(ML::AttrMirrored, piece->IsMirror(), [](bool mirrored){return not mirrored;}); + SetAttribute(ML::AttrTransform, TransformToString(piece->GetMatrix())); - // TODO cuttingLine - // TODO seamLine - // TODO grainline - // TODO passmarks - // TODO internal paths - // TODO placeLabels (buttonholes etc.) + writeStartElement(ML::TagSeamLine); + writeCharacters(PathToString(piece->GetContourPoints())); + writeEndElement(); - // TODO labels + writeStartElement(ML::TagSeamAllowance); + SetAttributeOrRemoveIf(ML::AttrEnabled, piece->IsSeamAllowance(), [](bool enabled){return not enabled;}); + SetAttributeOrRemoveIf(ML::AttrBuiltIn, piece->IsSeamAllowanceBuiltIn(), + [](bool builtin){return not builtin;}); + if (piece->IsSeamAllowance() && not piece->IsSeamAllowanceBuiltIn()) + { + writeCharacters(PathToString(piece->GetSeamAllowancePoints())); + } + writeEndElement(); + writeStartElement(ML::TagGrainline); + SetAttributeOrRemoveIf(ML::AttrEnabled, piece->IsGrainlineEnabled(), [](bool enabled){return not enabled;}); + if (piece->IsGrainlineEnabled()) + { + SetAttribute(ML::AttrAngle, piece->GrainlineAngle()); + SetAttribute(ML::AttrArrowDirection, GrainlineArrowDirrectionToString(piece->GrainlineArrowType())); + writeCharacters(PathToString(piece->GetGrainline())); + } + writeEndElement(); + + writeStartElement(ML::TagNotches); + QVector passmarks = piece->GetPassmarks(); + for (const auto& passmark : passmarks) + { + writeStartElement(ML::TagNotch); + SetAttribute(ML::AttrBuiltIn, passmark.isBuiltIn); + SetAttribute(ML::AttrType, static_cast(passmark.type)); + SetAttribute(ML::AttrBaseLine, LineToString(passmark.baseLine)); + SetAttribute(ML::AttrPath, LinesToString(passmark.lines)); + writeEndElement(); + } + writeEndElement(); + + writeStartElement(ML::TagInternalPaths); + QVector internalPaths = piece->GetInternalPaths(); + for (const auto& path : internalPaths) + { + writeStartElement(ML::TagInternalPath); + SetAttribute(ML::AttrCut, path.IsCutPath()); + SetAttribute(ML::AttrPenStyle, PenStyleToLineStyle(path.PenStyle())); + writeCharacters(PathToString(path.Points())); + writeEndElement(); + } + writeEndElement(); + + writeStartElement(ML::TagMarkers); + QVector placelabels = piece->GetPlaceLabels(); + for (const auto& label : placelabels) + { + writeStartElement(ML::TagMarker); + SetAttribute(ML::AttrTransform, TransformToString(label.rotationMatrix)); + SetAttribute(ML::AttrType, static_cast(label.type)); + SetAttribute(ML::AttrCenter, PointToString(label.center)); + SetAttribute(ML::AttrBox, RectToString(label.box)); + writeCharacters(MarkerShapeToString(label.shape)); + + writeEndElement(); + } + writeEndElement(); + + writeStartElement(ML::TagLabels); + WriteLabel(piece->GetPieceLabelRect(), piece->GetPieceLabelData(), ML::TagPieceLabel); + WriteLabel(piece->GetPatternLabelRect(), piece->GetPatternLabelData(), ML::TagPatternLabel); + writeEndElement(); + + writeEndElement(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPLayoutFileWriter::WriteLabel(const QVector &labelShape, const VTextManager &tm, const QString &tagName) +{ + if (labelShape.size() > 2 && tm.GetSourceLinesCount() > 0) + { + writeStartElement(tagName); + SetAttribute(ML::AttrShape, PathToString(labelShape)); + WriteLabelLines(tm); + writeEndElement(); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPLayoutFileWriter::WriteLabelLines(const VTextManager &tm) +{ + writeStartElement(ML::TagLines); + SetAttribute(ML::AttrFont, tm.GetFont().toString()); + + for (int i = 0; i < tm.GetSourceLinesCount(); ++i) + { + writeStartElement(ML::TagLine); + const TextLine& tl = tm.GetSourceLine(i); + SetAttribute(ML::AttrFontSize, tl.m_iFontSize); + SetAttribute(ML::AttrBold, tl.m_bold); + SetAttribute(ML::AttrItalic, tl.m_italic); + SetAttribute(ML::AttrAlignment, static_cast(tl.m_eAlign)); + writeCharacters(tl.m_qsText); + writeEndElement(); + } writeEndElement(); } diff --git a/src/app/puzzle/xml/vplayoutfilewriter.h b/src/app/puzzle/xml/vplayoutfilewriter.h index 769b277dd..dda791333 100644 --- a/src/app/puzzle/xml/vplayoutfilewriter.h +++ b/src/app/puzzle/xml/vplayoutfilewriter.h @@ -42,6 +42,7 @@ class VPPieceList; class VPPiece; class QFile; class QMarginsF; +class VTextManager; class VPLayoutFileWriter : public QXmlStreamWriter { @@ -60,6 +61,8 @@ private: void WriteTiles(VPLayout *layout); void WritePieceList(const QList &list, const QString &tagName); void WritePiece(VPPiece *piece); + void WriteLabel(const QVector &labelShape, const VTextManager &tm, const QString &tagName); + void WriteLabelLines(const VTextManager &tm); void WriteMargins(const QMarginsF &margins); void WriteSize(QSizeF size); diff --git a/src/app/puzzle/xml/vplayoutliterals.cpp b/src/app/puzzle/xml/vplayoutliterals.cpp index 91bb2f3d8..2be7cdcc4 100644 --- a/src/app/puzzle/xml/vplayoutliterals.cpp +++ b/src/app/puzzle/xml/vplayoutliterals.cpp @@ -44,6 +44,20 @@ const QString TagPiece = QStringLiteral("piece"); const QString TagSheets = QStringLiteral("sheets"); const QString TagSheet = QStringLiteral("sheet"); const QString TagName = QStringLiteral("name"); +const QString TagSeamLine = QStringLiteral("seamLine"); +const QString TagSeamAllowance = QStringLiteral("seamAllowance"); +const QString TagGrainline = QStringLiteral("grainline"); +const QString TagNotches = QStringLiteral("notches"); +const QString TagNotch = QStringLiteral("notch"); +const QString TagInternalPaths = QStringLiteral("internalPaths"); +const QString TagInternalPath = QStringLiteral("internalPath"); +const QString TagMarkers = QStringLiteral("markers"); +const QString TagMarker = QStringLiteral("marker"); +const QString TagLabels = QStringLiteral("labels"); +const QString TagPieceLabel = QStringLiteral("pieceLabel"); +const QString TagPatternLabel = QStringLiteral("patternLabel"); +const QString TagLines = QStringLiteral("lines"); +const QString TagLine = QStringLiteral("line"); const QString AttrVersion = QStringLiteral("version"); const QString AttrWarningSuperposition = QStringLiteral("warningSuperposition"); @@ -64,4 +78,30 @@ const QString AttrID = QStringLiteral("id"); const QString AttrMirrored = QStringLiteral("mirrored"); const QString AttrTransform = QStringLiteral("transform"); const QString AttrShowSeamline = QStringLiteral("showSeamline"); +const QString AttrEnabled = QStringLiteral("enabled"); +const QString AttrBuiltIn = QStringLiteral("builtIn"); +const QString AttrAngle = QStringLiteral("angle"); +const QString AttrArrowDirection = QStringLiteral("arrowDirection"); +const QString AttrType = QStringLiteral("type"); +const QString AttrBaseLine = QStringLiteral("baseLine"); +const QString AttrPath = QStringLiteral("path"); +const QString AttrCut = QStringLiteral("cut"); +const QString AttrPenStyle = QStringLiteral("penStyle"); +const QString AttrCenter = QStringLiteral("center"); +const QString AttrBox = QStringLiteral("box"); +const QString AttrShape = QStringLiteral("shape"); +const QString AttrFont = QStringLiteral("font"); +const QString AttrFontSize = QStringLiteral("fontSize"); +const QString AttrBold = QStringLiteral("bold"); +const QString AttrItalic = QStringLiteral("italic"); +const QString AttrAlignment = QStringLiteral("alignment"); + +const QString atFrontStr = QStringLiteral("atFront"); +const QString atRearStr = QStringLiteral("atRear"); +const QString atBothStr = QStringLiteral("atBoth"); + +const QChar groupSep = QLatin1Char(';'); +const QChar coordintatesSep = QLatin1Char(','); +const QChar pointsSep = QLatin1Char(' '); +const QChar itemsSep = QLatin1Char('*'); } // namespace ML diff --git a/src/app/puzzle/xml/vplayoutliterals.h b/src/app/puzzle/xml/vplayoutliterals.h index 27439a7da..3aba6adc6 100644 --- a/src/app/puzzle/xml/vplayoutliterals.h +++ b/src/app/puzzle/xml/vplayoutliterals.h @@ -49,6 +49,20 @@ extern const QString TagPiece; extern const QString TagSheets; extern const QString TagSheet; extern const QString TagName; +extern const QString TagSeamLine; +extern const QString TagSeamAllowance; +extern const QString TagGrainline; +extern const QString TagNotches; +extern const QString TagNotch; +extern const QString TagInternalPaths; +extern const QString TagInternalPath; +extern const QString TagMarkers; +extern const QString TagMarker; +extern const QString TagLabels; +extern const QString TagPieceLabel; +extern const QString TagPatternLabel; +extern const QString TagLines; +extern const QString TagLine; extern const QString AttrVersion; extern const QString AttrWarningSuperposition; @@ -69,6 +83,32 @@ extern const QString AttrID; extern const QString AttrMirrored; extern const QString AttrTransform; extern const QString AttrShowSeamline; +extern const QString AttrEnabled; +extern const QString AttrBuiltIn; +extern const QString AttrAngle; +extern const QString AttrArrowDirection; +extern const QString AttrType; +extern const QString AttrBaseLine; +extern const QString AttrPath; +extern const QString AttrCut; +extern const QString AttrPenStyle; +extern const QString AttrCenter; +extern const QString AttrBox; +extern const QString AttrShape; +extern const QString AttrFont; +extern const QString AttrFontSize; +extern const QString AttrBold; +extern const QString AttrItalic; +extern const QString AttrAlignment; + +extern const QString atFrontStr; +extern const QString atRearStr; +extern const QString atBothStr; + +extern const QChar groupSep; +extern const QChar coordintatesSep; +extern const QChar pointsSep; +extern const QChar itemsSep; } diff --git a/src/libs/ifc/schema/layout/v0.1.0.xsd b/src/libs/ifc/schema/layout/v0.1.0.xsd index 233ef55dc..a2f24cd77 100644 --- a/src/libs/ifc/schema/layout/v0.1.0.xsd +++ b/src/libs/ifc/schema/layout/v0.1.0.xsd @@ -8,9 +8,22 @@ + + + + + + + + + + + + + + - @@ -48,17 +61,131 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - - + - - @@ -68,39 +195,139 @@ - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - - + - - - + @@ -129,4 +356,102 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/libs/vlayout/vlayoutpiece.cpp b/src/libs/vlayout/vlayoutpiece.cpp index d6a49e749..78f4f5dec 100644 --- a/src/libs/vlayout/vlayoutpiece.cpp +++ b/src/libs/vlayout/vlayoutpiece.cpp @@ -719,6 +719,30 @@ void VLayoutPiece::SetPieceText(const QString& qsName, const VPieceLabelData& da d->m_tmDetail.FitFontSize(labelWidth, labelHeight); } +//--------------------------------------------------------------------------------------------------------------------- +auto VLayoutPiece::GetPieceLabelRect() const -> QVector +{ + return d->detailLabel; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VLayoutPiece::SetPieceLabelRect(const QVector &rect) +{ + d->detailLabel = rect; +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VLayoutPiece::GetPieceLabelData() const -> VTextManager +{ + return d->m_tmDetail; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VLayoutPiece::SetPieceLabelData(const VTextManager &data) +{ + d->m_tmDetail = data; +} + //--------------------------------------------------------------------------------------------------------------------- QPointF VLayoutPiece::GetPatternTextPosition() const { @@ -777,6 +801,30 @@ void VLayoutPiece::SetPatternInfo(VAbstractPattern* pDoc, const VPatternLabelDat d->m_tmPattern.FitFontSize(labelWidth, labelHeight); } +//--------------------------------------------------------------------------------------------------------------------- +auto VLayoutPiece::GetPatternLabelRect() const -> QVector +{ + return d->patternInfo; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VLayoutPiece::SetPatternLabelRect(const QVector &rect) +{ + d->patternInfo = rect; +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VLayoutPiece::GetPatternLabelData() const -> VTextManager +{ + return d->m_tmPattern; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VLayoutPiece::SetPatternLabelData(const VTextManager &data) +{ + d->m_tmPattern = data; +} + //--------------------------------------------------------------------------------------------------------------------- void VLayoutPiece::SetGrainline(const VGrainlineData& geom, const VContainer* pattern) { @@ -814,6 +862,30 @@ bool VLayoutPiece::IsGrainlineEnabled() const return d->grainlineEnabled; } +//--------------------------------------------------------------------------------------------------------------------- +void VLayoutPiece::SetGrainlineEnabled(bool enabled) +{ + d->grainlineEnabled = enabled; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VLayoutPiece::SetGrainlineAngle(qreal angle) +{ + d->grainlineAngle = angle; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VLayoutPiece::SetGrainlineArrowType(GrainlineArrowDirection type) +{ + d->grainlineArrowType = type; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VLayoutPiece::SetGrainlinePoints(const QVector &points) +{ + d->grainlinePoints = points; +} + //--------------------------------------------------------------------------------------------------------------------- qreal VLayoutPiece::GrainlineAngle() const { @@ -1105,7 +1177,7 @@ QVector > VLayoutPiece::MappedInternalPathsForCut(bool cut) con { QVector > paths; - for (auto &path : d->m_internalPaths) + for (const auto &path : d->m_internalPaths) { if (path.IsCutPath() == cut) { diff --git a/src/libs/vlayout/vlayoutpiece.h b/src/libs/vlayout/vlayoutpiece.h index c1d1e1f26..ce70f8f7d 100644 --- a/src/libs/vlayout/vlayoutpiece.h +++ b/src/libs/vlayout/vlayoutpiece.h @@ -167,6 +167,24 @@ public: friend QDataStream& operator<< (QDataStream& dataStream, const VLayoutPiece& piece); friend QDataStream& operator>> (QDataStream& dataStream, VLayoutPiece& piece); +protected: + void SetGrainlineEnabled(bool enabled); + void SetGrainlineAngle(qreal angle); + void SetGrainlineArrowType(GrainlineArrowDirection type); + void SetGrainlinePoints(const QVector &points); + + auto GetPieceLabelRect() const -> QVector; + void SetPieceLabelRect(const QVector &rect); + + auto GetPieceLabelData() const ->VTextManager; + void SetPieceLabelData(const VTextManager &data); + + auto GetPatternLabelRect() const -> QVector; + void SetPatternLabelRect(const QVector &rect); + + auto GetPatternLabelData() const ->VTextManager; + void SetPatternLabelData(const VTextManager &data); + private: QSharedDataPointer d; diff --git a/src/libs/vlayout/vtextmanager.cpp b/src/libs/vlayout/vtextmanager.cpp index 9c8890bf3..b32df25f6 100644 --- a/src/libs/vlayout/vtextmanager.cpp +++ b/src/libs/vlayout/vtextmanager.cpp @@ -51,7 +51,7 @@ const quint16 TextLine::classVersion = 1; // Friend functions //--------------------------------------------------------------------------------------------------------------------- -QDataStream& operator<<(QDataStream &dataStream, const TextLine &data) +auto operator<<(QDataStream &dataStream, const TextLine &data) -> QDataStream& { dataStream << TextLine::streamHeader << TextLine::classVersion; @@ -68,7 +68,7 @@ QDataStream& operator<<(QDataStream &dataStream, const TextLine &data) } //--------------------------------------------------------------------------------------------------------------------- -QDataStream& operator>>(QDataStream &dataStream, TextLine &data) +auto operator>>(QDataStream &dataStream, TextLine &data) -> QDataStream& { quint32 actualStreamHeader = 0; dataStream >> actualStreamHeader; @@ -113,7 +113,7 @@ const quint16 VTextManager::classVersion = 1; // Friend functions //--------------------------------------------------------------------------------------------------------------------- -QDataStream& operator<<(QDataStream &dataStream, const VTextManager &data) +auto operator<<(QDataStream &dataStream, const VTextManager &data) -> QDataStream& { dataStream << VTextManager::streamHeader << VTextManager::classVersion; @@ -127,7 +127,7 @@ QDataStream& operator<<(QDataStream &dataStream, const VTextManager &data) } //--------------------------------------------------------------------------------------------------------------------- -QDataStream& operator>>(QDataStream &dataStream, VTextManager &data) +auto operator>>(QDataStream &dataStream, VTextManager &data) -> QDataStream& { quint32 actualStreamHeader = 0; dataStream >> actualStreamHeader; @@ -167,7 +167,7 @@ namespace { //--------------------------------------------------------------------------------------------------------------------- -QMap PreparePlaceholders(const VAbstractPattern *doc, const VContainer *data) +auto PreparePlaceholders(const VAbstractPattern *doc, const VContainer *data) -> QMap { SCASSERT(doc != nullptr) SCASSERT(data != nullptr) @@ -331,7 +331,7 @@ void InitPiecePlaceholders(QMap &placeholders, const QString & } //--------------------------------------------------------------------------------------------------------------------- -QString ReplacePlaceholders(const QMap &placeholders, QString line) +auto ReplacePlaceholders(const QMap &placeholders, QString line) -> QString { QChar per('%'); @@ -359,7 +359,7 @@ QString ReplacePlaceholders(const QMap &placeholders, QString } //--------------------------------------------------------------------------------------------------------------------- -QVector PrepareLines(const QVector &lines) +auto PrepareLines(const QVector &lines) -> QVector { QVector textLines; @@ -412,7 +412,7 @@ VTextManager &VTextManager::operator=(const VTextManager &text) * @brief GetSpacing returns the vertical spacing between the lines * @return spacing */ -int VTextManager::GetSpacing() const +auto VTextManager::GetSpacing() const -> int { return 0; } @@ -432,7 +432,7 @@ void VTextManager::SetFont(const QFont& font) * @brief GetFont returns the text base font * @return text base font */ -const QFont& VTextManager::GetFont() const +auto VTextManager::GetFont() const -> const QFont& { return m_font; } @@ -448,17 +448,23 @@ void VTextManager::SetFontSize(int iFS) } //--------------------------------------------------------------------------------------------------------------------- -QVector VTextManager::GetAllSourceLines() const +auto VTextManager::GetAllSourceLines() const -> QVector { return m_liLines; } +//--------------------------------------------------------------------------------------------------------------------- +void VTextManager::SetAllSourceLines(const QVector &lines) +{ + m_liLines = lines; +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief VTextManager::GetSourceLinesCount returns the number of input text lines * @return number of text lines that were added to the list by calling AddLine */ -int VTextManager::GetSourceLinesCount() const +auto VTextManager::GetSourceLinesCount() const -> int { return m_liLines.count(); } @@ -469,7 +475,7 @@ int VTextManager::GetSourceLinesCount() const * @param i index of the requested line * @return reference to the requested TextLine object */ -const TextLine& VTextManager::GetSourceLine(int i) const +auto VTextManager::GetSourceLine(int i) const -> const TextLine& { Q_ASSERT(i >= 0); Q_ASSERT(i < m_liLines.count()); diff --git a/src/libs/vlayout/vtextmanager.h b/src/libs/vlayout/vtextmanager.h index 9728d9e15..5968b9aea 100644 --- a/src/libs/vlayout/vtextmanager.h +++ b/src/libs/vlayout/vtextmanager.h @@ -57,8 +57,8 @@ struct TextLine bool m_italic{false}; Qt::Alignment m_eAlign{Qt::AlignCenter}; - friend QDataStream& operator<<(QDataStream& dataStream, const TextLine& data); - friend QDataStream& operator>>(QDataStream& dataStream, TextLine& data); + friend auto operator<<(QDataStream& dataStream, const TextLine& data) -> QDataStream&; + friend auto operator>>(QDataStream& dataStream, TextLine& data) -> QDataStream&; private: static const quint32 streamHeader; static const quint16 classVersion; @@ -78,22 +78,23 @@ public: VTextManager(const VTextManager &text); VTextManager &operator=(const VTextManager &text); - virtual int GetSpacing() const; + virtual auto GetSpacing() const -> int; - void SetFont(const QFont& font); - const QFont& GetFont() const; - void SetFontSize(int iFS); - void FitFontSize(qreal fW, qreal fH); + void SetFont(const QFont& font); + auto GetFont() const -> const QFont&; + void SetFontSize(int iFS); + void FitFontSize(qreal fW, qreal fH); - QVector GetAllSourceLines() const; - int GetSourceLinesCount() const; - const TextLine& GetSourceLine(int i) const; + auto GetAllSourceLines() const -> QVector; + void SetAllSourceLines(const QVector &lines); + auto GetSourceLinesCount() const -> int; + auto GetSourceLine(int i) const -> const TextLine&; void Update(const QString& qsName, const VPieceLabelData& data, const VContainer *pattern); void Update(VAbstractPattern* pDoc, const VContainer *pattern); - friend QDataStream& operator<<(QDataStream& dataStream, const VTextManager& data); - friend QDataStream& operator>>(QDataStream& dataStream, VTextManager& data); + friend auto operator<<(QDataStream& dataStream, const VTextManager& data) -> QDataStream&; + friend auto operator>>(QDataStream& dataStream, VTextManager& data) -> QDataStream&; private: QFont m_font;