diff --git a/src/app/core/vapplication.cpp b/src/app/core/vapplication.cpp index f42e18c3a..74bb563de 100644 --- a/src/app/core/vapplication.cpp +++ b/src/app/core/vapplication.cpp @@ -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() { diff --git a/src/app/core/vapplication.h b/src/app/core/vapplication.h index 3b18c6e17..7122d424d 100644 --- a/src/app/core/vapplication.h +++ b/src/app/core/vapplication.h @@ -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(); diff --git a/src/app/dialogs/tools/dialogarc.cpp b/src/app/dialogs/tools/dialogarc.cpp index 7349aedbb..00eef7b31 100644 --- a/src/app/dialogs/tools/dialogarc.cpp +++ b/src/app/dialogs/tools/dialogarc.cpp @@ -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" //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/dialogs/tools/dialogdetail.cpp b/src/app/dialogs/tools/dialogdetail.cpp index 92943718f..b4bded7e0 100644 --- a/src/app/dialogs/tools/dialogdetail.cpp +++ b/src/app/dialogs/tools/dialogdetail.cpp @@ -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" //--------------------------------------------------------------------------------------------------------------------- /** diff --git a/src/app/dialogs/tools/dialogtool.cpp b/src/app/dialogs/tools/dialogtool.cpp index beb8b405a..f2f40b050 100644 --- a/src/app/dialogs/tools/dialogtool.cpp +++ b/src/app/dialogs/tools/dialogtool.cpp @@ -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 #include #include diff --git a/src/app/mainwindow.cpp b/src/app/mainwindow.cpp index f32764cfe..372900df2 100644 --- a/src/app/mainwindow.cpp +++ b/src/app/mainwindow.cpp @@ -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(); diff --git a/src/app/options.h b/src/app/options.h index beaf82dbf..5d1c9e37b 100644 --- a/src/app/options.h +++ b/src/app/options.h @@ -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 }; diff --git a/src/app/xml/vabstractmeasurements.cpp b/src/app/xml/vabstractmeasurements.cpp index 81c6a7f0c..fbf3339b7 100644 --- a/src/app/xml/vabstractmeasurements.cpp +++ b/src/app/xml/vabstractmeasurements.cpp @@ -33,7 +33,7 @@ const QString VAbstractMeasurements::AttrValue = QStringLiteral("value"); //--------------------------------------------------------------------------------------------------------------------- VAbstractMeasurements::VAbstractMeasurements(VContainer *data) - :VDomDocument(data) + :VDomDocument(), data(data) { SCASSERT(data != nullptr) } diff --git a/src/app/xml/vabstractmeasurements.h b/src/app/xml/vabstractmeasurements.h index 5de17cc73..ac64c9828 100644 --- a/src/app/xml/vabstractmeasurements.h +++ b/src/app/xml/vabstractmeasurements.h @@ -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: diff --git a/src/app/xml/vpattern.cpp b/src/app/xml/vpattern.cpp index 38b329be0..fc22c61d9 100644 --- a/src/app/xml/vpattern.cpp +++ b/src/app/xml/vpattern.cpp @@ -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()), + : QObject(parent), VDomDocument(), data(data), nameActivPP(QString()), tools(QHash()), history(QVector()), cursor(0), patternPieces(QStringList()), mode(mode), sceneDraw(sceneDraw), sceneDetail(sceneDetail) { diff --git a/src/app/xml/vpattern.h b/src/app/xml/vpattern.h index 50eb05f00..ee2c8e469 100644 --- a/src/app/xml/vpattern.h +++ b/src/app/xml/vpattern.h @@ -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; diff --git a/src/app/xml/xml.pri b/src/app/xml/xml.pri index b1de7e167..a26d7d4aa 100644 --- a/src/app/xml/xml.pri +++ b/src/app/xml/xml.pri @@ -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 \ diff --git a/src/libs/ifc/ifcdef.h b/src/libs/ifc/ifcdef.h index 6b8915473..79d0c2179 100644 --- a/src/libs/ifc/ifcdef.h +++ b/src/libs/ifc/ifcdef.h @@ -31,6 +31,9 @@ #include +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. diff --git a/src/app/xml/vdomdocument.cpp b/src/libs/ifc/xml/vdomdocument.cpp similarity index 92% rename from src/app/xml/vdomdocument.cpp rename to src/libs/ifc/xml/vdomdocument.cpp index 1d5ac15a0..1dd514e85 100644 --- a/src/app/xml/vdomdocument.cpp +++ b/src/libs/ifc/xml/vdomdocument.cpp @@ -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 #include @@ -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()) +VDomDocument::VDomDocument() + : QDomDocument(), map(QHash()) {} //--------------------------------------------------------------------------------------------------------------------- @@ -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; +} diff --git a/src/app/xml/vdomdocument.h b/src/libs/ifc/xml/vdomdocument.h similarity index 97% rename from src/app/xml/vdomdocument.h rename to src/libs/ifc/xml/vdomdocument.h index 132bc8e35..a8e29ebb3 100644 --- a/src/app/xml/vdomdocument.h +++ b/src/libs/ifc/xml/vdomdocument.h @@ -31,8 +31,10 @@ #include #include -#include "../container/vcontainer.h" #include +#include + +#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. */ diff --git a/src/libs/ifc/xml/xml.pri b/src/libs/ifc/xml/xml.pri index 9c8d74470..3a23b3a95 100644 --- a/src/libs/ifc/xml/xml.pri +++ b/src/libs/ifc/xml/xml.pri @@ -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