diff --git a/src/app/puzzle/puzzle.pri b/src/app/puzzle/puzzle.pri index 6ca67a366..40cfdef6f 100644 --- a/src/app/puzzle/puzzle.pri +++ b/src/app/puzzle/puzzle.pri @@ -11,7 +11,9 @@ SOURCES += \ $$PWD/vpiececarrousel.cpp \ $$PWD/vpuzzlelayout.cpp \ $$PWD/vpuzzlelayer.cpp \ - $$PWD/vpuzzlepiece.cpp + $$PWD/vpuzzlepiece.cpp \ + $$PWD/xml/vpuzzlelayoutfilewriter.cpp \ + $$PWD/xml/vpuzzlelayoutfilereader.cpp *msvc*:SOURCES += $$PWD/stable.cpp @@ -25,7 +27,9 @@ HEADERS += \ $$PWD/vpiececarrousel.h \ $$PWD/vpuzzlelayout.h \ $$PWD/vpuzzlelayer.h \ - $$PWD/vpuzzlepiece.h + $$PWD/vpuzzlepiece.h \ + $$PWD/xml/vpuzzlelayoutfilewriter.h \ + $$PWD/xml/vpuzzlelayoutfilereader.h FORMS += \ $$PWD/puzzlemainwindow.ui \ diff --git a/src/app/puzzle/puzzlemainwindow.cpp b/src/app/puzzle/puzzlemainwindow.cpp index c663a6858..ae062dd68 100644 --- a/src/app/puzzle/puzzlemainwindow.cpp +++ b/src/app/puzzle/puzzlemainwindow.cpp @@ -26,20 +26,30 @@ ** *************************************************************************/ #include "puzzlemainwindow.h" + +#include + #include "ui_puzzlemainwindow.h" #include "dialogs/dialogaboutpuzzle.h" +#include "xml/vpuzzlelayoutfilewriter.h" //--------------------------------------------------------------------------------------------------------------------- PuzzleMainWindow::PuzzleMainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::PuzzleMainWindow), - pieceCarrousel(new VPieceCarrousel) + pieceCarrousel(new VPieceCarrousel), + m_layout (new VPuzzleLayout) { ui->setupUi(this); InitMenuBar(); InitProperties(); InitPieceCarrousel(); + + + // for test purposes, to be removed when we can edit the size / margins through the UI: + m_layout->SetLayoutMargins(1.5, 2.00, 4.21, 0.25); + m_layout->SetLayoutSize(21.0, 29.7); } //--------------------------------------------------------------------------------------------------------------------- @@ -269,14 +279,24 @@ void PuzzleMainWindow::Save() //--------------------------------------------------------------------------------------------------------------------- void PuzzleMainWindow::SaveAs() { - // just for test purpuses, to be removed: - QMessageBox msgBox; - msgBox.setText("TODO PuzzleMainWindow::SaveAs"); - int ret = msgBox.exec(); + // TODO / FIXME : See valentina how the save is done over there. we need to add the extension .vlt, check for empty file names etc. - Q_UNUSED(ret); - // TODO + QString filters(tr("Pattern files") + QLatin1String("(*.val)")); + QString fileName = QFileDialog::getSaveFileName(this, tr("Save as"), + /*dir +*/ QLatin1String("/") + tr("Layout") + QLatin1String(".vlt"), + filters, nullptr +#ifdef Q_OS_LINUX + , QFileDialog::DontUseNativeDialog +#endif + ); + + + QFile file(fileName); + file.open(QIODevice::WriteOnly); + + VPuzzleLayoutFileWriter *fileWriter = new VPuzzleLayoutFileWriter(); + fileWriter->WriteFile(m_layout, &file); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/puzzle/puzzlemainwindow.h b/src/app/puzzle/puzzlemainwindow.h index 86f786f2c..ae99ecd94 100644 --- a/src/app/puzzle/puzzlemainwindow.h +++ b/src/app/puzzle/puzzlemainwindow.h @@ -33,6 +33,7 @@ #include "../vmisc/def.h" #include "vpiececarrousel.h" +#include "vpuzzlelayout.h" namespace Ui { @@ -59,6 +60,9 @@ private: Ui::PuzzleMainWindow *ui; VPieceCarrousel *pieceCarrousel; + VPuzzleLayout *m_layout; + + void InitMenuBar(); void InitProperties(); void InitPropertyTabCurrentPiece(); diff --git a/src/app/puzzle/vpuzzlelayout.cpp b/src/app/puzzle/vpuzzlelayout.cpp index 3e14dd36e..31bd4dca6 100644 --- a/src/app/puzzle/vpuzzlelayout.cpp +++ b/src/app/puzzle/vpuzzlelayout.cpp @@ -113,7 +113,7 @@ void VPuzzleLayout::SetLayoutMargins(qreal left, qreal top, qreal right, qreal b m_margins.setLeft(left); m_margins.setTop(top); m_margins.setRight(right); - m_margins.setRight(bottom); + m_margins.setBottom(bottom); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/puzzle/xml/vpuzzlelayoutfilereader.cpp b/src/app/puzzle/xml/vpuzzlelayoutfilereader.cpp new file mode 100644 index 000000000..014fdc66a --- /dev/null +++ b/src/app/puzzle/xml/vpuzzlelayoutfilereader.cpp @@ -0,0 +1,34 @@ +/************************************************************************ + ** + ** @file vpuzzlelayoutfilereader.cpp + ** @author Ronan Le Tiec + ** @date 18 4, 2020 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentina project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2020 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + ** *************************************************************************/ + +#include "vpuzzlelayoutfilereader.h" + +VPuzzleLayoutFileReader::VPuzzleLayoutFileReader() +{ + +} diff --git a/src/app/puzzle/xml/vpuzzlelayoutfilereader.h b/src/app/puzzle/xml/vpuzzlelayoutfilereader.h new file mode 100644 index 000000000..9db832014 --- /dev/null +++ b/src/app/puzzle/xml/vpuzzlelayoutfilereader.h @@ -0,0 +1,40 @@ +/************************************************************************ + ** + ** @file vpuzzlelayoutfilereader.h + ** @author Ronan Le Tiec + ** @date 18 4, 2020 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentina project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2020 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + ** *************************************************************************/ + +#ifndef VPUZZLELAYOUTFILEREADER_H +#define VPUZZLELAYOUTFILEREADER_H + +#include + +class VPuzzleLayoutFileReader : public QXmlStreamReader +{ +public: + VPuzzleLayoutFileReader(); +}; + +#endif // VPUZZLELAYOUTFILEREADER_H diff --git a/src/app/puzzle/xml/vpuzzlelayoutfilewriter.cpp b/src/app/puzzle/xml/vpuzzlelayoutfilewriter.cpp new file mode 100644 index 000000000..044d597f1 --- /dev/null +++ b/src/app/puzzle/xml/vpuzzlelayoutfilewriter.cpp @@ -0,0 +1,201 @@ +/************************************************************************ + ** + ** @file vpuzzlelayoutfilewriter.cpp + ** @author Ronan Le Tiec + ** @date 18 4, 2020 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentina project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2020 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#include "vpuzzlelayoutfilewriter.h" + +//--------------------------------------------------------------------------------------------------------------------- +VPuzzleLayoutFileWriter::VPuzzleLayoutFileWriter() +{ + +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPuzzleLayoutFileWriter::WriteFile(VPuzzleLayout *layout, QFile *file) +{ + Q_UNUSED(layout); + + setDevice(file); + setAutoFormatting(true); + + writeStartDocument(); + WriteLayout(layout); + writeEndDocument(); + + file->close(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPuzzleLayoutFileWriter::WriteLayout(VPuzzleLayout *layout) +{ + writeStartElement("layout"); + writeAttribute("version", "1.0.0"); // TODO / FIXME : get the version properly + + WriteProperties(layout); + WriteLayers(layout); + + writeEndElement(); //layout +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPuzzleLayoutFileWriter::WriteProperties(VPuzzleLayout *layout) +{ + writeStartElement("properties"); + + writeTextElement("unit", UnitsToStr(layout->getUnit())); + + writeTextElement("description", ""); // TODO : define the value in layout + + WriteSize(layout->GetLayoutSize()); + + WriteMargins(layout->GetLayoutMargins()); + + writeStartElement("control"); + writeAttribute("followGrainLine", "no"); // TODO / Fixme get the right value + writeAttribute("warningSuperposition", QString(layout->GetWarningSuperpositionOfPieces() ? "true" : "false")); + writeAttribute("warningOutOfBound", QString(layout->GetWarningPiecesOutOfBound() ? "true" : "false")); + writeAttribute("stickyEdges", QString(layout->GetStickyEdges() ? "true" : "false")); + writeAttribute("piecesGap", QString::number(layout->GetPiecesGap())); + writeEndElement(); // control + + // WriteTiles(layout); TODO: when tile functionality implemented, then uncomment this line + + writeEndElement(); // properties +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPuzzleLayoutFileWriter::WriteTiles(VPuzzleLayout *layout) +{ + Q_UNUSED(layout); // to be removed + + writeStartElement("tiles"); + writeAttribute("visible", QString(false ? "true" : "false")); // TODO / Fixme get the right value + writeAttribute("matchingMarks", "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); + + writeEndElement(); // tiles +} + + +//--------------------------------------------------------------------------------------------------------------------- +void VPuzzleLayoutFileWriter::WriteLayers(VPuzzleLayout *layout) +{ + writeStartElement("layers"); + + WriteLayer(layout->GetUnplacedPiecesLayer(), "unplacedPieces"); + + QList layers = layout->GetLayers(); + for (auto layer : layers) + { + WriteLayer(layer); + } + + writeEndElement(); // layers +} + + +//--------------------------------------------------------------------------------------------------------------------- +void VPuzzleLayoutFileWriter::WriteLayer(VPuzzleLayer *layer) +{ + WriteLayer(layer, "layer"); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPuzzleLayoutFileWriter::WriteLayer(VPuzzleLayer *layer, const QString &tagName) +{ + writeStartElement(tagName); // layer + writeAttribute("name", layer->GetName()); + writeAttribute("visible", QString(layer->GetIsVisible()? "true" : "false")); + // TODO selected info. Not sure how it's saved yet + //writeAttribute("selected", QString(layer->GetIsSelected()? "true" : "false")); + + + QList pieces = layer->GetPieces(); + for (auto piece : pieces) + { + WritePiece(piece); + } + + writeEndElement(); // layer +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPuzzleLayoutFileWriter::WritePiece(VPuzzlePiece *piece) +{ + writeStartElement("piece"); + writeAttribute("id", "uuid1"); // TODO / Fixme get the right value + writeAttribute("name", "Piece name"); // TODO / Fixme get the right value + writeAttribute("mirrored", "false"); // TODO / Fixme get the right value + writeAttribute("transform", "string representation of the transformation"); // TODO / Fixme get the right value + + // TODO cuttingLine + // TODO seamLine + // TODO grainline + // TODO passmarks + // TODO internal paths + // TODO placeLabels (buttonholes etc.) + + // TODO labels + + writeEndElement(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPuzzleLayoutFileWriter::WriteMargins(QMarginsF margins) +{ + writeStartElement("margin"); + writeAttribute("left", QString::number(margins.left())); + writeAttribute("top", QString::number(margins.top())); + writeAttribute("right", QString::number(margins.right())); + writeAttribute("bottom", QString::number(margins.bottom())); + writeEndElement(); // margin +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPuzzleLayoutFileWriter::WriteSize(QSizeF size) +{ + // maybe not necessary to test this, the writer should "stupidly write", the application should take care of these tests + qreal width = size.width(); + if(width < 0) { + width = 0; + } + + qreal length = size.height(); + if(length < 0) { + length = 0; + } + + writeStartElement("size"); + writeAttribute("width", QString::number(width)); + writeAttribute("length", QString::number(length)); + writeEndElement(); // size +} diff --git a/src/app/puzzle/xml/vpuzzlelayoutfilewriter.h b/src/app/puzzle/xml/vpuzzlelayoutfilewriter.h new file mode 100644 index 000000000..5c22fdb5c --- /dev/null +++ b/src/app/puzzle/xml/vpuzzlelayoutfilewriter.h @@ -0,0 +1,60 @@ +/************************************************************************ + ** + ** @file vpuzzlelayoutfilewriter.h + ** @author Ronan Le Tiec + ** @date 18 4, 2020 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentina project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2020 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + ** *************************************************************************/ + +#ifndef VPUZZLELAYOUTFILEWRITER_H +#define VPUZZLELAYOUTFILEWRITER_H + +#include +#include "vpuzzlelayout.h" +#include "vpuzzlelayer.h" +#include "vpuzzlepiece.h" + +class VPuzzleLayoutFileWriter : public QXmlStreamWriter +{ +public: + VPuzzleLayoutFileWriter(); + + void WriteFile(VPuzzleLayout *layout, QFile *file); + +private: + + void WriteLayout(VPuzzleLayout *layout); + void WriteProperties(VPuzzleLayout *layout); + void WriteTiles(VPuzzleLayout *layout); + void WriteLayers(VPuzzleLayout *layout); + void WriteLayer(VPuzzleLayer *layer); + void WriteLayer(VPuzzleLayer *layer, const QString &tagName); + void WritePiece(VPuzzlePiece *piece); + + void WriteMargins(QMarginsF margins); + void WriteSize(QSizeF size); + + +}; + +#endif // VPUZZLELAYOUTFILEWRITER_H