Refactoring VPuzzleLayoutFileWriter

This commit is contained in:
Ronan Le Tiec 2020-05-23 14:02:39 +02:00
parent d9e3a08eac
commit 13c060f2fc
5 changed files with 29 additions and 29 deletions

View File

@ -19,8 +19,8 @@ SOURCES += \
$$PWD/vpuzzlepiece.cpp \
$$PWD/vpuzzlesettings.cpp \
$$PWD/xml/vplayoutfilereader.cpp \
$$PWD/xml/vplayoutfilewriter.cpp \
$$PWD/xml/vplayoutliterals.cpp \
$$PWD/xml/vpuzzlelayoutfilewriter.cpp \
$$PWD/vpiececarrousellayer.cpp \
$$PWD/vpiececarrouselpiece.cpp
@ -44,8 +44,8 @@ HEADERS += \
$$PWD/vpuzzlepiece.h \
$$PWD/vpuzzlesettings.h \
$$PWD/xml/vplayoutfilereader.h \
$$PWD/xml/vplayoutfilewriter.h \
$$PWD/xml/vplayoutliterals.h \
$$PWD/xml/vpuzzlelayoutfilewriter.h \
$$PWD/vpiececarrousellayer.h \
$$PWD/vpiececarrouselpiece.h

View File

@ -32,7 +32,7 @@
#include "ui_puzzlemainwindow.h"
#include "dialogs/vpdialogabout.h"
#include "xml/vpuzzlelayoutfilewriter.h"
#include "xml/vplayoutfilewriter.h"
#include "xml/vplayoutfilereader.h"
#include "puzzleapplication.h"
#include "../vlayout/vrawlayout.h"
@ -126,7 +126,7 @@ bool PuzzleMainWindow::SaveFile(const QString &path)
QFile file(path);
file.open(QIODevice::WriteOnly);
VPuzzleLayoutFileWriter *fileWriter = new VPuzzleLayoutFileWriter();
VPLayoutFileWriter *fileWriter = new VPLayoutFileWriter();
fileWriter->WriteFile(m_layout, &file);
// TODO / FIXME : better return value and error handling

View File

@ -28,7 +28,7 @@
#include <QXmlStreamAttributes>
#include "vplayoutfilereader.h"
#include "vpuzzlelayoutfilewriter.h"
#include "vplayoutfilewriter.h"
#include "vplayoutliterals.h"
#include "../ifc/exception/vexception.h"
#include "../ifc/exception/vexceptionconversionerror.h"

View File

@ -26,7 +26,7 @@
**
*************************************************************************/
#include "vpuzzlelayoutfilewriter.h"
#include "vplayoutfilewriter.h"
#include "vpuzzlelayout.h"
#include "vpuzzlelayer.h"
#include "vpuzzlepiece.h"
@ -34,19 +34,19 @@
#include "../ifc/xml/vlayoutconverter.h"
//---------------------------------------------------------------------------------------------------------------------
VPuzzleLayoutFileWriter::VPuzzleLayoutFileWriter()
VPLayoutFileWriter::VPLayoutFileWriter()
{
}
//---------------------------------------------------------------------------------------------------------------------
VPuzzleLayoutFileWriter::~VPuzzleLayoutFileWriter()
VPLayoutFileWriter::~VPLayoutFileWriter()
{
}
//---------------------------------------------------------------------------------------------------------------------
void VPuzzleLayoutFileWriter::WriteFile(VPuzzleLayout *layout, QFile *file)
void VPLayoutFileWriter::WriteFile(VPuzzleLayout *layout, QFile *file)
{
setDevice(file);
setAutoFormatting(true);
@ -59,7 +59,7 @@ void VPuzzleLayoutFileWriter::WriteFile(VPuzzleLayout *layout, QFile *file)
}
//---------------------------------------------------------------------------------------------------------------------
void VPuzzleLayoutFileWriter::WriteLayout(VPuzzleLayout *layout)
void VPLayoutFileWriter::WriteLayout(VPuzzleLayout *layout)
{
writeStartElement(ML::TagLayout);
SetAttribute(ML::AttrVersion, VLayoutConverter::LayoutMaxVerStr);
@ -71,7 +71,7 @@ void VPuzzleLayoutFileWriter::WriteLayout(VPuzzleLayout *layout)
}
//---------------------------------------------------------------------------------------------------------------------
void VPuzzleLayoutFileWriter::WriteProperties(VPuzzleLayout *layout)
void VPLayoutFileWriter::WriteProperties(VPuzzleLayout *layout)
{
writeStartElement(ML::TagProperties);
@ -97,7 +97,7 @@ void VPuzzleLayoutFileWriter::WriteProperties(VPuzzleLayout *layout)
}
//---------------------------------------------------------------------------------------------------------------------
void VPuzzleLayoutFileWriter::WriteTiles(VPuzzleLayout *layout)
void VPLayoutFileWriter::WriteTiles(VPuzzleLayout *layout)
{
Q_UNUSED(layout); // to be removed
@ -116,7 +116,7 @@ void VPuzzleLayoutFileWriter::WriteTiles(VPuzzleLayout *layout)
//---------------------------------------------------------------------------------------------------------------------
void VPuzzleLayoutFileWriter::WriteLayers(VPuzzleLayout *layout)
void VPLayoutFileWriter::WriteLayers(VPuzzleLayout *layout)
{
writeStartElement(ML::TagLayers);
@ -133,13 +133,13 @@ void VPuzzleLayoutFileWriter::WriteLayers(VPuzzleLayout *layout)
//---------------------------------------------------------------------------------------------------------------------
void VPuzzleLayoutFileWriter::WriteLayer(VPuzzleLayer *layer)
void VPLayoutFileWriter::WriteLayer(VPuzzleLayer *layer)
{
WriteLayer(layer, ML::TagLayer);
}
//---------------------------------------------------------------------------------------------------------------------
void VPuzzleLayoutFileWriter::WriteLayer(VPuzzleLayer *layer, const QString &tagName)
void VPLayoutFileWriter::WriteLayer(VPuzzleLayer *layer, const QString &tagName)
{
writeStartElement(tagName); // layer
SetAttribute(ML::AttrName, layer->GetName());
@ -158,7 +158,7 @@ void VPuzzleLayoutFileWriter::WriteLayer(VPuzzleLayer *layer, const QString &tag
}
//---------------------------------------------------------------------------------------------------------------------
void VPuzzleLayoutFileWriter::WritePiece(VPuzzlePiece *piece)
void VPLayoutFileWriter::WritePiece(VPuzzlePiece *piece)
{
Q_UNUSED(piece);
@ -182,7 +182,7 @@ void VPuzzleLayoutFileWriter::WritePiece(VPuzzlePiece *piece)
}
//---------------------------------------------------------------------------------------------------------------------
void VPuzzleLayoutFileWriter::WriteMargins(const QMarginsF &margins)
void VPLayoutFileWriter::WriteMargins(const QMarginsF &margins)
{
writeStartElement(ML::TagMargin);
SetAttribute(ML::AttrLeft, margins.left());
@ -193,7 +193,7 @@ void VPuzzleLayoutFileWriter::WriteMargins(const QMarginsF &margins)
}
//---------------------------------------------------------------------------------------------------------------------
void VPuzzleLayoutFileWriter::WriteSize(QSizeF size)
void VPLayoutFileWriter::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();

View File

@ -26,8 +26,8 @@
**
** *************************************************************************/
#ifndef VPUZZLELAYOUTFILEWRITER_H
#define VPUZZLELAYOUTFILEWRITER_H
#ifndef VPLAYOUTFILEWRITER_H
#define VPLAYOUTFILEWRITER_H
#include <QLocale>
#include <QXmlStreamWriter>
@ -40,11 +40,11 @@ class VPuzzlePiece;
class QFile;
class QMarginsF;
class VPuzzleLayoutFileWriter : public QXmlStreamWriter
class VPLayoutFileWriter : public QXmlStreamWriter
{
public:
VPuzzleLayoutFileWriter();
~VPuzzleLayoutFileWriter();
VPLayoutFileWriter();
~VPLayoutFileWriter();
void WriteFile(VPuzzleLayout *layout, QFile *file);
@ -71,7 +71,7 @@ private:
//---------------------------------------------------------------------------------------------------------------------
template<typename T>
void VPuzzleLayoutFileWriter::SetAttribute(const QString &name, const T &value)
void VPLayoutFileWriter::SetAttribute(const QString &name, const T &value)
{
// See specification for xs:decimal
const QLocale locale = QLocale::c();
@ -80,30 +80,30 @@ void VPuzzleLayoutFileWriter::SetAttribute(const QString &name, const T &value)
//---------------------------------------------------------------------------------------------------------------------
template <>
inline void VPuzzleLayoutFileWriter::SetAttribute<QString>(const QString &name, const QString &value)
inline void VPLayoutFileWriter::SetAttribute<QString>(const QString &name, const QString &value)
{
writeAttribute(name, value);
}
//---------------------------------------------------------------------------------------------------------------------
template <>
inline void VPuzzleLayoutFileWriter::SetAttribute<QChar>(const QString &name, const QChar &value)
inline void VPLayoutFileWriter::SetAttribute<QChar>(const QString &name, const QChar &value)
{
writeAttribute(name, value);
}
//---------------------------------------------------------------------------------------------------------------------
template <>
inline void VPuzzleLayoutFileWriter::SetAttribute<bool>(const QString &name, const bool &value)
inline void VPLayoutFileWriter::SetAttribute<bool>(const QString &name, const bool &value)
{
writeAttribute(name, value ? trueStr : falseStr);
}
//---------------------------------------------------------------------------------------------------------------------
template <size_t N>
inline void VPuzzleLayoutFileWriter::SetAttribute(const QString &name, const char (&value)[N])
inline void VPLayoutFileWriter::SetAttribute(const QString &name, const char (&value)[N])
{
writeAttribute(name, QString(value));
}
#endif // VPUZZLELAYOUTFILEWRITER_H
#endif // VPLAYOUTFILEWRITER_H