Changes for vlt Format version
This commit is contained in:
parent
9e2c0e9cc5
commit
c83ac5e493
|
@ -28,6 +28,7 @@
|
||||||
|
|
||||||
#include <QXmlStreamAttributes>
|
#include <QXmlStreamAttributes>
|
||||||
#include "vpuzzlelayoutfilereader.h"
|
#include "vpuzzlelayoutfilereader.h"
|
||||||
|
#include "vpuzzlelayoutfilewriter.h"
|
||||||
|
|
||||||
VPuzzleLayoutFileReader::VPuzzleLayoutFileReader()
|
VPuzzleLayoutFileReader::VPuzzleLayoutFileReader()
|
||||||
{
|
{
|
||||||
|
@ -53,14 +54,25 @@ bool VPuzzleLayoutFileReader::ReadFile(VPuzzleLayout *layout, QFile *file)
|
||||||
// if it doesn't start with layout, error
|
// if it doesn't start with layout, error
|
||||||
// if it starts with version > than current version, error
|
// if it starts with version > than current version, error
|
||||||
|
|
||||||
if (name() == QString("layout")
|
if (name() == QString("layout"))
|
||||||
&& attributes().value(QString("version")) == QLatin1String("1.0.0"))
|
{
|
||||||
|
QString versionStr = attributes().value(QString("version")).toString();
|
||||||
|
QStringList versionStrParts = versionStr.split('.');
|
||||||
|
m_layoutFormatVersion = FORMAT_VERSION(versionStrParts.at(0).toInt(),versionStrParts.at(1).toInt(),versionStrParts.at(2).toInt());
|
||||||
|
|
||||||
|
if(VPuzzleLayoutFileWriter::LayoutFileFormatVersion >= m_layoutFormatVersion)
|
||||||
{
|
{
|
||||||
ReadLayout(layout);
|
ReadLayout(layout);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
raiseError(QObject::tr("The file is not a layout version 1.0.0 file."));
|
// TODO better error handling
|
||||||
|
raiseError(QObject::tr("You're trying to open a layout that was created with a newer version of puzzle"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
raiseError(QObject::tr("Wrong file structure"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -218,6 +230,7 @@ void VPuzzleLayoutFileReader::ReadLayer(VPuzzleLayer *layer)
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void VPuzzleLayoutFileReader::ReadPiece(VPuzzlePiece *piece)
|
void VPuzzleLayoutFileReader::ReadPiece(VPuzzlePiece *piece)
|
||||||
{
|
{
|
||||||
|
Q_UNUSED(piece);
|
||||||
Q_ASSERT(isStartElement() && name() == QString("piece"));
|
Q_ASSERT(isStartElement() && name() == QString("piece"));
|
||||||
|
|
||||||
// TODO read the attributes
|
// TODO read the attributes
|
||||||
|
|
|
@ -30,6 +30,7 @@
|
||||||
#define VPUZZLELAYOUTFILEREADER_H
|
#define VPUZZLELAYOUTFILEREADER_H
|
||||||
|
|
||||||
#include <QXmlStreamReader>
|
#include <QXmlStreamReader>
|
||||||
|
#include "../ifc/xml/vabstractconverter.h"
|
||||||
#include "vpuzzlelayout.h"
|
#include "vpuzzlelayout.h"
|
||||||
#include "vpuzzlelayer.h"
|
#include "vpuzzlelayer.h"
|
||||||
#include "vpuzzlepiece.h"
|
#include "vpuzzlepiece.h"
|
||||||
|
@ -43,6 +44,8 @@ public:
|
||||||
bool ReadFile(VPuzzleLayout *layout, QFile *file);
|
bool ReadFile(VPuzzleLayout *layout, QFile *file);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
int m_layoutFormatVersion;
|
||||||
|
|
||||||
void ReadLayout(VPuzzleLayout *layout);
|
void ReadLayout(VPuzzleLayout *layout);
|
||||||
void ReadProperties(VPuzzleLayout *layout);
|
void ReadProperties(VPuzzleLayout *layout);
|
||||||
void ReadTiles(VPuzzleLayout *layout);
|
void ReadTiles(VPuzzleLayout *layout);
|
||||||
|
|
|
@ -34,6 +34,12 @@ VPuzzleLayoutFileWriter::VPuzzleLayoutFileWriter()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
VPuzzleLayoutFileWriter::~VPuzzleLayoutFileWriter()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void VPuzzleLayoutFileWriter::WriteFile(VPuzzleLayout *layout, QFile *file)
|
void VPuzzleLayoutFileWriter::WriteFile(VPuzzleLayout *layout, QFile *file)
|
||||||
{
|
{
|
||||||
|
@ -51,7 +57,7 @@ void VPuzzleLayoutFileWriter::WriteFile(VPuzzleLayout *layout, QFile *file)
|
||||||
void VPuzzleLayoutFileWriter::WriteLayout(VPuzzleLayout *layout)
|
void VPuzzleLayoutFileWriter::WriteLayout(VPuzzleLayout *layout)
|
||||||
{
|
{
|
||||||
writeStartElement("layout");
|
writeStartElement("layout");
|
||||||
writeAttribute("version", "1.0.0"); // TODO / FIXME : get the version properly
|
writeAttribute("version", LayoutFileFormatVersionStr);
|
||||||
|
|
||||||
WriteProperties(layout);
|
WriteProperties(layout);
|
||||||
WriteLayers(layout);
|
WriteLayers(layout);
|
||||||
|
|
|
@ -30,6 +30,7 @@
|
||||||
#define VPUZZLELAYOUTFILEWRITER_H
|
#define VPUZZLELAYOUTFILEWRITER_H
|
||||||
|
|
||||||
#include <QXmlStreamWriter>
|
#include <QXmlStreamWriter>
|
||||||
|
#include "../ifc/xml/vabstractconverter.h"
|
||||||
#include "vpuzzlelayout.h"
|
#include "vpuzzlelayout.h"
|
||||||
#include "vpuzzlelayer.h"
|
#include "vpuzzlelayer.h"
|
||||||
#include "vpuzzlepiece.h"
|
#include "vpuzzlepiece.h"
|
||||||
|
@ -38,9 +39,24 @@ class VPuzzleLayoutFileWriter : public QXmlStreamWriter
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
VPuzzleLayoutFileWriter();
|
VPuzzleLayoutFileWriter();
|
||||||
|
~VPuzzleLayoutFileWriter();
|
||||||
|
|
||||||
void WriteFile(VPuzzleLayout *layout, QFile *file);
|
void WriteFile(VPuzzleLayout *layout, QFile *file);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Version rules:
|
||||||
|
* 1. Version have three parts "major.minor.patch";
|
||||||
|
* 2. major part only for stable releases;
|
||||||
|
* 3. minor - 10 or more patch changes, or one big change;
|
||||||
|
* 4. patch - little change.
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* @brief LayoutFileFormatVersion holds the version
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
static Q_DECL_CONSTEXPR const int LayoutFileFormatVersion = FORMAT_VERSION(1, 0, 0);
|
||||||
|
const QString LayoutFileFormatVersionStr = QStringLiteral("1.0.0");
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void WriteLayout(VPuzzleLayout *layout);
|
void WriteLayout(VPuzzleLayout *layout);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user