Work on VPuzzleLayoutFileWriter

This commit is contained in:
Ronan Le Tiec 2020-04-18 16:32:54 +02:00
parent 13d42bfa62
commit 596707d5b1
8 changed files with 373 additions and 10 deletions

View File

@ -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 \

View File

@ -26,20 +26,30 @@
**
*************************************************************************/
#include "puzzlemainwindow.h"
#include <QFileDialog>
#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);
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -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();

View File

@ -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);
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -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
** <https://gitlab.com/smart-pattern/valentina> 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 <http://www.gnu.org/licenses/>.
**
** *************************************************************************/
#include "vpuzzlelayoutfilereader.h"
VPuzzleLayoutFileReader::VPuzzleLayoutFileReader()
{
}

View File

@ -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
** <https://gitlab.com/smart-pattern/valentina> 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 <http://www.gnu.org/licenses/>.
**
** *************************************************************************/
#ifndef VPUZZLELAYOUTFILEREADER_H
#define VPUZZLELAYOUTFILEREADER_H
#include <QXmlStreamReader>
class VPuzzleLayoutFileReader : public QXmlStreamReader
{
public:
VPuzzleLayoutFileReader();
};
#endif // VPUZZLELAYOUTFILEREADER_H

View File

@ -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
** <https://gitlab.com/smart-pattern/valentina> 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 <http://www.gnu.org/licenses/>.
**
*************************************************************************/
#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<VPuzzleLayer*> 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<VPuzzlePiece*> 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
}

View File

@ -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
** <https://gitlab.com/smart-pattern/valentina> 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 <http://www.gnu.org/licenses/>.
**
** *************************************************************************/
#ifndef VPUZZLELAYOUTFILEWRITER_H
#define VPUZZLELAYOUTFILEWRITER_H
#include <QXmlStreamWriter>
#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