Converter inherits class VDomDocument.

--HG--
branch : feature
This commit is contained in:
dismine 2014-12-10 20:33:20 +02:00
parent 394d54e9c1
commit 21d1a781fd
16 changed files with 83 additions and 75 deletions

View File

@ -2039,53 +2039,6 @@ QString VApplication::STDescription(const QString &id) const
return QString();
}
//---------------------------------------------------------------------------------------------------------------------
bool VApplication::SafeCopy(const QString &source, const QString &destination, QString &error)
{
bool result = false;
#ifdef Q_OS_WIN32
qt_ntfs_permission_lookup++; // turn checking on
#endif /*Q_OS_WIN32*/
QFile patternFile(destination);
patternFile.setPermissions(QFile::ReadOwner | QFile::WriteOwner);
// We need here temporary file because we want restore document after error of copying temp file.
QTemporaryFile tempOfPattern;
if (tempOfPattern.open())
{
if (patternFile.exists())
{
patternFile.copy(tempOfPattern.fileName());
}
}
if ( patternFile.exists() == false || patternFile.remove() )
{
QFile sourceFile(source);
if ( sourceFile.copy(patternFile.fileName()) == false )
{
error = tr("Could not copy temp file to document file");
tempOfPattern.copy(destination);
result = false;
}
else
{
result = true;
}
}
else
{
error = tr("Could not remove document file");
result = false;
}
#ifdef Q_OS_WIN32
qt_ntfs_permission_lookup--; // turn off check permission again
#endif /*Q_OS_WIN32*/
return result;
}
//---------------------------------------------------------------------------------------------------------------------
void VApplication::StartLogging()
{

View File

@ -106,7 +106,6 @@ public:
static QStringList LabelLanguages();
QString STDescription(const QString &id)const;
static bool SafeCopy(const QString &source, const QString &destination, QString &error);
void StartLogging();
QTextStream *LogFile();

View File

@ -34,7 +34,7 @@
#include "../../geometry/vpointf.h"
#include "../../container/vcontainer.h"
#include "../../xml/vdomdocument.h"
#include "../../libs/ifc/xml/vdomdocument.h"
#include "../../visualization/vistoolarc.h"
//---------------------------------------------------------------------------------------------------------------------

View File

@ -34,7 +34,7 @@
#include "../../geometry/vpointf.h"
#include "../../geometry/vsplinepath.h"
#include "../../container/vcontainer.h"
#include "../../xml/vdomdocument.h"
#include "../../libs/ifc/xml/vdomdocument.h"
//---------------------------------------------------------------------------------------------------------------------
/**

View File

@ -36,7 +36,7 @@
#include "../../../libs/qmuparser/qmuparsererror.h"
#include "../../core/vapplication.h"
#include "../../core/vsettings.h"
#include "../../xml/vdomdocument.h"
#include "../../libs/ifc/xml/vdomdocument.h"
#include <QTimer>
#include <QCloseEvent>
#include <QShowEvent>

View File

@ -2483,7 +2483,7 @@ void MainWindow::ReopenFilesAfterCrash(QStringList &args)
for (int i = 0; i < restoreFiles.size(); ++i)
{
QString error;
if (VApplication::SafeCopy(restoreFiles.at(i) +".autosave", restoreFiles.at(i), error))
if (VDomDocument::SafeCopy(restoreFiles.at(i) +".autosave", restoreFiles.at(i), error))
{
QFile autoFile(restoreFiles.at(i) +".autosave");
autoFile.remove();

View File

@ -118,8 +118,6 @@ enum class Vis : unsigned char
enum class Source : char { FromGui, FromFile, FromTool };
enum class Draw : char { Calculation, Modeling };
enum class Unit : char { Mm, Cm, Inch };
enum class MeasurementsType : char { Standard, Individual };
enum class NodeDetail : char { Contour, Modeling };
enum class Contour : char { OpenContour, CloseContour };
enum class EquidistantType : char { OpenEquidistant, CloseEquidistant };

View File

@ -33,7 +33,7 @@ const QString VAbstractMeasurements::AttrValue = QStringLiteral("value");
//---------------------------------------------------------------------------------------------------------------------
VAbstractMeasurements::VAbstractMeasurements(VContainer *data)
:VDomDocument(data)
:VDomDocument(), data(data)
{
SCASSERT(data != nullptr)
}

View File

@ -29,7 +29,8 @@
#ifndef VABSTRACTMEASUREMENTS_H
#define VABSTRACTMEASUREMENTS_H
#include "vdomdocument.h"
#include "../libs/ifc/xml/vdomdocument.h"
#include "../container/vcontainer.h"
class VAbstractMeasurements : public VDomDocument
{
@ -42,6 +43,9 @@ public:
static const QString AttrValue;
static qreal UnitConvertor(qreal value, const Unit &from, const Unit &to);
protected:
/** @brief data container with data. */
VContainer *data;
void Measurement(const QString &tag);
virtual void ReadMeasurement(const QDomElement &domElement, const QString &tag) = 0;
private:

View File

@ -121,7 +121,7 @@ const QString VPattern::IncrementDescription = QStringLiteral("description");
//---------------------------------------------------------------------------------------------------------------------
VPattern::VPattern(VContainer *data, Draw *mode, VMainGraphicsScene *sceneDraw,
VMainGraphicsScene *sceneDetail, QObject *parent)
: QObject(parent), VDomDocument(data), nameActivPP(QString()), tools(QHash<quint32, VDataTool*>()),
: QObject(parent), VDomDocument(), data(data), nameActivPP(QString()), tools(QHash<quint32, VDataTool*>()),
history(QVector<VToolRecord>()), cursor(0), patternPieces(QStringList()), mode(mode), sceneDraw(sceneDraw),
sceneDetail(sceneDetail)
{

View File

@ -29,8 +29,9 @@
#ifndef VPATTERN_H
#define VPATTERN_H
#include "vdomdocument.h"
#include "../libs/ifc/xml/vdomdocument.h"
#include "vtoolrecord.h"
#include "../container/vcontainer.h"
class VDataTool;
class VMainGraphicsScene;
@ -233,6 +234,9 @@ protected:
private:
Q_DISABLE_COPY(VPattern)
/** @brief data container with data. */
VContainer *data;
/** @brief nameActivDraw name current pattern peace. */
QString nameActivPP;

View File

@ -3,7 +3,6 @@
HEADERS += \
$$PWD/vtoolrecord.h \
$$PWD/vdomdocument.h \
$$PWD/vpattern.h \
$$PWD/vstandardmeasurements.h \
$$PWD/vindividualmeasurements.h \
@ -11,7 +10,6 @@ HEADERS += \
SOURCES += \
$$PWD/vtoolrecord.cpp \
$$PWD/vdomdocument.cpp \
$$PWD/vpattern.cpp \
$$PWD/vstandardmeasurements.cpp \
$$PWD/vindividualmeasurements.cpp \

View File

@ -31,6 +31,9 @@
#include <csignal>
enum class Unit : char { Mm, Cm, Inch };
enum class MeasurementsType : char { Standard, Individual };
static const quint32 null_id = 0;
#define NULL_ID null_id//use this value for initialization variables that keeps id values. 0 mean uknown id value.

View File

@ -27,11 +27,9 @@
*************************************************************************/
#include "vdomdocument.h"
#include "../libs/ifc/exception/vexceptionconversionerror.h"
#include "../libs/ifc/exception/vexceptionemptyparameter.h"
#include "../libs/ifc/exception/vexceptionbadid.h"
#include "../options.h"
#include "../core/vapplication.h"
#include "exception/vexceptionconversionerror.h"
#include "exception/vexceptionemptyparameter.h"
#include "exception/vexceptionbadid.h"
#include <QAbstractMessageHandler>
#include <QXmlSchema>
@ -100,8 +98,8 @@ const QString VDomDocument::UnitINCH = QStringLiteral("inch");
const QString VDomDocument::TagVersion = QStringLiteral("version");
//---------------------------------------------------------------------------------------------------------------------
VDomDocument::VDomDocument(VContainer *data)
: QDomDocument(), data(data), map(QHash<QString, QDomElement>())
VDomDocument::VDomDocument()
: QDomDocument(), map(QHash<QString, QDomElement>())
{}
//---------------------------------------------------------------------------------------------------------------------
@ -536,7 +534,7 @@ bool VDomDocument::SaveDocument(const QString &fileName, QString &error)
tempFile.close();
}
//Copy document to file
bool result = VApplication::SafeCopy(temp, fileName, error);
bool result = VDomDocument::SafeCopy(temp, fileName, error);
tempFile.remove();//Clear temp file
return result;
@ -635,3 +633,50 @@ QDomElement VDomDocument::NodeById(const quint32 &nodeId)
}
return domElement;
}
//---------------------------------------------------------------------------------------------------------------------
bool VDomDocument::SafeCopy(const QString &source, const QString &destination, QString &error)
{
bool result = false;
#ifdef Q_OS_WIN32
qt_ntfs_permission_lookup++; // turn checking on
#endif /*Q_OS_WIN32*/
QFile patternFile(destination);
patternFile.setPermissions(QFile::ReadOwner | QFile::WriteOwner);
// We need here temporary file because we want restore document after error of copying temp file.
QTemporaryFile tempOfPattern;
if (tempOfPattern.open())
{
if (patternFile.exists())
{
patternFile.copy(tempOfPattern.fileName());
}
}
if ( patternFile.exists() == false || patternFile.remove() )
{
QFile sourceFile(source);
if ( sourceFile.copy(patternFile.fileName()) == false )
{
error = tr("Could not copy temp file to document file");
tempOfPattern.copy(destination);
result = false;
}
else
{
result = true;
}
}
else
{
error = tr("Could not remove document file");
result = false;
}
#ifdef Q_OS_WIN32
qt_ntfs_permission_lookup--; // turn off check permission again
#endif /*Q_OS_WIN32*/
return result;
}

View File

@ -31,8 +31,10 @@
#include <QDomDocument>
#include <QDebug>
#include "../container/vcontainer.h"
#include <QLoggingCategory>
#include <QCoreApplication>
#include "ifcdef.h"
Q_DECLARE_LOGGING_CATEGORY(vXML)
@ -80,7 +82,7 @@ public:
/**
* @param data container with variables
*/
VDomDocument(VContainer *data);
VDomDocument();
virtual ~VDomDocument();
QDomElement elementById(const QString& id);
void removeAllChilds(QDomElement &element);
@ -116,12 +118,12 @@ public:
QDomNode ParentNodeById(const quint32 &nodeId);
QDomElement CloneNodeById(const quint32 &nodeId);
QDomElement NodeById(const quint32 &nodeId);
protected:
/** @brief data container with data. */
VContainer *data;
static bool SafeCopy(const QString &source, const QString &destination, QString &error);
protected:
void setTagText(const QString &tag, const QString &text);
QString UniqueTagText(const QString &tagName, const QString &defVal = QString()) const;
private:
Q_DISABLE_COPY(VDomDocument)
/** @brief Map used for finding element by id. */

View File

@ -2,7 +2,9 @@
# This need for corect working file translations.pro
HEADERS += \
$$PWD/vabstractconverter.h
$$PWD/vabstractconverter.h \
$$PWD/vdomdocument.h
SOURCES += \
$$PWD/vabstractconverter.cpp
$$PWD/vabstractconverter.cpp \
$$PWD/vdomdocument.cpp