Merge with feature

--HG--
branch : develop
This commit is contained in:
dismine 2014-12-11 22:59:44 +02:00
commit 7738b974fc
55 changed files with 862 additions and 203 deletions

View File

@ -10,11 +10,13 @@ TEMPLATE = app
DEPENDPATH += \ DEPENDPATH += \
../src/app \ ../src/app \
../src/libs/qmuparser \ ../src/libs/qmuparser \
../src/libs/vpropertyexplorer ../src/libs/vpropertyexplorer \
../src/libs/ifc
include(../src/app/app.pri) include(../src/app/app.pri)
include(../src/libs/qmuparser/qmuparser.pri) include(../src/libs/qmuparser/qmuparser.pri)
include(../src/libs/vpropertyexplorer/vpropertyexplorer.pri) include(../src/libs/vpropertyexplorer/vpropertyexplorer.pri)
include(../src/libs/ifc/ifc.pri)
# Add here path to new translation file with name "valentina_*_*.ts" if you want to add new language. # Add here path to new translation file with name "valentina_*_*.ts" if you want to add new language.
# Same paths in variable INSTALL_TRANSLATIONS (app.pro). # Same paths in variable INSTALL_TRANSLATIONS (app.pro).

View File

@ -1,7 +1,6 @@
# Suport subdirectories. Just better project code tree. # Suport subdirectories. Just better project code tree.
include(container/container.pri) include(container/container.pri)
include(dialogs/dialogs.pri) include(dialogs/dialogs.pri)
include(exception/exception.pri)
include(geometry/geometry.pri) include(geometry/geometry.pri)
include(tools/tools.pri) include(tools/tools.pri)
include(widgets/widgets.pri) include(widgets/widgets.pri)

View File

@ -51,7 +51,6 @@ RESOURCES += \
share/resources/icon.qrc \ # All other icons except cursors and Windows theme. share/resources/icon.qrc \ # All other icons except cursors and Windows theme.
share/resources/cursor.qrc \ # Tools cursor icons. share/resources/cursor.qrc \ # Tools cursor icons.
share/resources/theme.qrc \ # Windows theme icons. share/resources/theme.qrc \ # Windows theme icons.
share/resources/schema.qrc \ # Schemas for validation xml files.
share/resources/measurements.qrc \ # For measurements files that we save as resource. share/resources/measurements.qrc \ # For measurements files that we save as resource.
share/resources/flags.qrc share/resources/flags.qrc
@ -346,6 +345,14 @@ else:unix: LIBS += -L$${OUT_PWD}/../libs/vpropertyexplorer/$${DESTDIR} -lvproper
INCLUDEPATH += $${PWD}/../libs/vpropertyexplorer INCLUDEPATH += $${PWD}/../libs/vpropertyexplorer
DEPENDPATH += $${PWD}/../libs/vpropertyexplorer DEPENDPATH += $${PWD}/../libs/vpropertyexplorer
# IFC static library
unix|win32: LIBS += -L$$OUT_PWD/../libs/ifc/$${DESTDIR}/ -lifc
INCLUDEPATH += $$PWD/../libs/ifc
DEPENDPATH += $$PWD/../libs/ifc
win32:!win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../libs/ifc/$${DESTDIR}/ifc.lib
else:unix|win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../libs/ifc/$${DESTDIR}/libifc.a
# Strip after you link all libaries. # Strip after you link all libaries.
CONFIG(release, debug|release){ CONFIG(release, debug|release){

View File

@ -32,7 +32,7 @@
#include "variables.h" #include "variables.h"
#include "../geometry/vdetail.h" #include "../geometry/vdetail.h"
#include "../geometry/vgobject.h" #include "../geometry/vgobject.h"
#include "../exception/vexceptionbadid.h" #include "../libs/ifc/exception/vexceptionbadid.h"
#include "../geometry/vabstractcurve.h" #include "../geometry/vabstractcurve.h"
#include <QCoreApplication> #include <QCoreApplication>

View File

@ -27,11 +27,11 @@
*************************************************************************/ *************************************************************************/
#include "vapplication.h" #include "vapplication.h"
#include "../exception/vexceptionobjecterror.h" #include "../libs/ifc/exception/vexceptionobjecterror.h"
#include "../exception/vexceptionbadid.h" #include "../libs/ifc/exception/vexceptionbadid.h"
#include "../exception/vexceptionconversionerror.h" #include "../libs/ifc/exception/vexceptionconversionerror.h"
#include "../exception/vexceptionemptyparameter.h" #include "../libs/ifc/exception/vexceptionemptyparameter.h"
#include "../exception/vexceptionwrongid.h" #include "../libs/ifc/exception/vexceptionwrongid.h"
#include "vmaingraphicsview.h" #include "vmaingraphicsview.h"
#include "../container/calculator.h" #include "../container/calculator.h"
#include "../version.h" #include "../version.h"
@ -2039,53 +2039,6 @@ QString VApplication::STDescription(const QString &id) const
return QString(); 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() void VApplication::StartLogging()
{ {

View File

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

View File

@ -64,7 +64,7 @@ DialogIncrements::DialogIncrements(VContainer *data, VPattern *doc, QWidget *par
{ {
VDomDocument::ValidateXML("://schema/individual_measurements.xsd", filePath); VDomDocument::ValidateXML("://schema/individual_measurements.xsd", filePath);
m = new VIndividualMeasurements(data); m = new VIndividualMeasurements(data);
m->setContent(filePath); m->setXMLContent(filePath);
} }
catch (VException &e) catch (VException &e)
{ {
@ -527,7 +527,7 @@ void DialogIncrements::OpenTable()
VDomDocument::ValidateXML("://schema/individual_measurements.xsd", filePath); VDomDocument::ValidateXML("://schema/individual_measurements.xsd", filePath);
m1 = new VIndividualMeasurements(data); m1 = new VIndividualMeasurements(data);
m1->setContent(filePath); m1->setXMLContent(filePath);
} }
catch (VException &e) catch (VException &e)
{ {
@ -567,7 +567,7 @@ void DialogIncrements::OpenTable()
VDomDocument::ValidateXML("://schema/standard_measurements.xsd", filePath); VDomDocument::ValidateXML("://schema/standard_measurements.xsd", filePath);
m1 = new VStandardMeasurements(data); m1 = new VStandardMeasurements(data);
m1->setContent(filePath); m1->setXMLContent(filePath);
Unit mUnit = m1->MUnit(); Unit mUnit = m1->MUnit();
if (qApp->patternUnit() != mUnit) if (qApp->patternUnit() != mUnit)
{ {

View File

@ -111,7 +111,7 @@ void DialogIndividualMeasurements::DialogAccepted()
{ {
VDomDocument::ValidateXML("://schema/individual_measurements.xsd", _tablePath); VDomDocument::ValidateXML("://schema/individual_measurements.xsd", _tablePath);
VIndividualMeasurements m(data); VIndividualMeasurements m(data);
m.setContent(_tablePath); m.setXMLContent(_tablePath);
const qint32 index = ui->comboBoxUnits->currentIndex(); const qint32 index = ui->comboBoxUnits->currentIndex();
Unit unit = VDomDocument::StrToUnits(ui->comboBoxUnits->itemData(index).toString()); Unit unit = VDomDocument::StrToUnits(ui->comboBoxUnits->itemData(index).toString());
m.setUnit(unit); m.setUnit(unit);
@ -215,7 +215,7 @@ void DialogIndividualMeasurements::OpenTable()
fileName.clear(); fileName.clear();
} }
VIndividualMeasurements m(data); VIndividualMeasurements m(data);
m.setContent(fileName); m.setXMLContent(fileName);
ui->labelGivenName->setText(m.GivenName()); ui->labelGivenName->setText(m.GivenName());
ui->labelFamilyName->setText(m.FamilyName()); ui->labelFamilyName->setText(m.FamilyName());
ui->lineEditPathExistM->setText(fileName); ui->lineEditPathExistM->setText(fileName);

View File

@ -99,7 +99,7 @@ void DialogStandardMeasurements::DialogAccepted()
{ {
VDomDocument::ValidateXML("://schema/standard_measurements.xsd", _tablePath); VDomDocument::ValidateXML("://schema/standard_measurements.xsd", _tablePath);
VStandardMeasurements m(data); VStandardMeasurements m(data);
m.setContent(_tablePath); m.setXMLContent(_tablePath);
qApp->setPatternUnit(m.MUnit()); qApp->setPatternUnit(m.MUnit());
} }
catch (VException &e) catch (VException &e)
@ -170,7 +170,7 @@ void DialogStandardMeasurements::LoadStandardTables()
{ {
VDomDocument::ValidateXML("://schema/standard_measurements.xsd", fi.absoluteFilePath()); VDomDocument::ValidateXML("://schema/standard_measurements.xsd", fi.absoluteFilePath());
VStandardMeasurements m(data); VStandardMeasurements m(data);
m.setContent(fi.absoluteFilePath()); m.setXMLContent(fi.absoluteFilePath());
if (m.MUnit() == Unit::Inch) if (m.MUnit() == Unit::Inch)
{ {
qCWarning(vStMeasur)<<"We do not support inches for standard table. Ignore table" qCWarning(vStMeasur)<<"We do not support inches for standard table. Ignore table"

View File

@ -29,7 +29,7 @@
#include "dialogundo.h" #include "dialogundo.h"
#include "ui_dialogundo.h" #include "ui_dialogundo.h"
#include "../../core/vapplication.h" #include "../../core/vapplication.h"
#include "../../exception/vexceptionundo.h" #include "../../libs/ifc/exception/vexceptionundo.h"
#include <QCloseEvent> #include <QCloseEvent>
#include <QUndoStack> #include <QUndoStack>

View File

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

View File

@ -34,7 +34,7 @@
#include "../../geometry/vpointf.h" #include "../../geometry/vpointf.h"
#include "../../geometry/vsplinepath.h" #include "../../geometry/vsplinepath.h"
#include "../../container/vcontainer.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 "../../../libs/qmuparser/qmuparsererror.h"
#include "../../core/vapplication.h" #include "../../core/vapplication.h"
#include "../../core/vsettings.h" #include "../../core/vsettings.h"
#include "../../xml/vdomdocument.h" #include "../../libs/ifc/xml/vdomdocument.h"
#include <QTimer> #include <QTimer>
#include <QCloseEvent> #include <QCloseEvent>
#include <QShowEvent> #include <QShowEvent>

View File

@ -28,7 +28,7 @@
#include "vsplinepath.h" #include "vsplinepath.h"
#include "vsplinepath_p.h" #include "vsplinepath_p.h"
#include "../exception/vexception.h" #include "../libs/ifc/exception/vexception.h"
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VSplinePath::VSplinePath(qreal kCurve, quint32 idObject, Draw mode) VSplinePath::VSplinePath(qreal kCurve, quint32 idObject, Draw mode)

View File

@ -44,6 +44,7 @@
#include "undocommands/renamepp.h" #include "undocommands/renamepp.h"
#include "vtooloptionspropertybrowser.h" #include "vtooloptionspropertybrowser.h"
#include "options.h" #include "options.h"
#include "../libs/ifc/xml/vpatternconverter.h"
#include <QInputDialog> #include <QInputDialog>
#include <QDebug> #include <QDebug>
@ -166,7 +167,7 @@ void MainWindow::ActionNewPP()
path = stMeasurements.tablePath(); path = stMeasurements.tablePath();
qCDebug(vMainWindow)<<"Table path:"<<path; qCDebug(vMainWindow)<<"Table path:"<<path;
VStandardMeasurements m(pattern); VStandardMeasurements m(pattern);
m.setContent(path); m.setXMLContent(path);
m.SetSize(); m.SetSize();
m.SetHeight(); m.SetHeight();
m.Measurements(); m.Measurements();
@ -200,7 +201,7 @@ void MainWindow::ActionNewPP()
path = indMeasurements.tablePath(); path = indMeasurements.tablePath();
qCDebug(vMainWindow)<<"Table path:"<<path; qCDebug(vMainWindow)<<"Table path:"<<path;
VIndividualMeasurements m(pattern); VIndividualMeasurements m(pattern);
m.setContent(path); m.setXMLContent(path);
m.Measurements(); m.Measurements();
} }
else else
@ -2350,8 +2351,11 @@ void MainWindow::LoadPattern(const QString &fileName)
qApp->setOpeningPattern();//Begin opening file qApp->setOpeningPattern();//Begin opening file
try try
{ {
VDomDocument::ValidateXML("://schema/pattern.xsd", fileName); VPatternConverter converter(fileName);
doc->setContent(fileName); converter.Convert();
VDomDocument::ValidateXML(VPatternConverter::CurrentSchema, fileName);
doc->setXMLContent(fileName);
qApp->setPatternUnit(doc->MUnit()); qApp->setPatternUnit(doc->MUnit());
qApp->setPatternType(doc->MType()); qApp->setPatternType(doc->MType());
@ -2368,7 +2372,7 @@ void MainWindow::LoadPattern(const QString &fileName)
{ {
VStandardMeasurements m(pattern); VStandardMeasurements m(pattern);
VDomDocument::ValidateXML("://schema/standard_measurements.xsd", path); VDomDocument::ValidateXML("://schema/standard_measurements.xsd", path);
m.setContent(path); m.setXMLContent(path);
if (m.MUnit() == Unit::Inch) if (m.MUnit() == Unit::Inch)
{ {
QMessageBox::critical(this, tr("Wrong units."), QMessageBox::critical(this, tr("Wrong units."),
@ -2483,7 +2487,7 @@ void MainWindow::ReopenFilesAfterCrash(QStringList &args)
for (int i = 0; i < restoreFiles.size(); ++i) for (int i = 0; i < restoreFiles.size(); ++i)
{ {
QString error; 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"); QFile autoFile(restoreFiles.at(i) +".autosave");
autoFile.remove(); autoFile.remove();

View File

@ -29,8 +29,8 @@
#ifndef OPTIONS_H #ifndef OPTIONS_H
#define OPTIONS_H #define OPTIONS_H
#include <csignal>
#include <QtGlobal> #include <QtGlobal>
#include "../libs/ifc/ifcdef.h"
#ifdef Q_OS_WIN32 #ifdef Q_OS_WIN32
# if defined( Q_CC_MSVC ) // MSVC USED # if defined( Q_CC_MSVC ) // MSVC USED
@ -46,12 +46,8 @@ extern Q_CORE_EXPORT int qt_ntfs_permission_lookup;
class QString; class QString;
class QStringList; class QStringList;
static const quint32 null_id = 0;
#define SceneSize 50000 #define SceneSize 50000
#define DefPointRadius 2.0//mm #define DefPointRadius 2.0//mm
#define NULL_ID null_id//use this value for initialization variables that keeps id values. 0 mean uknown id value.
#define NULL_ID_STR "0"
extern const QString nameRegExp; extern const QString nameRegExp;
extern const QString degreeSymbol; extern const QString degreeSymbol;
@ -122,8 +118,6 @@ enum class Vis : unsigned char
enum class Source : char { FromGui, FromFile, FromTool }; enum class Source : char { FromGui, FromFile, FromTool };
enum class Draw : char { Calculation, Modeling }; 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 NodeDetail : char { Contour, Modeling };
enum class Contour : char { OpenContour, CloseContour }; enum class Contour : char { OpenContour, CloseContour };
enum class EquidistantType : char { OpenEquidistant, CloseEquidistant }; enum class EquidistantType : char { OpenEquidistant, CloseEquidistant };
@ -324,76 +318,4 @@ extern const QString cm_Oprt;
extern const QString mm_Oprt; extern const QString mm_Oprt;
extern const QString in_Oprt; extern const QString in_Oprt;
/*
* This macros SCASSERT (for Stop and Continue Assert) will break into the debugger on the line of the assert and allow
* you to continue afterwards should you choose to.
* idea: Q_ASSERT no longer pauses debugger - http://qt-project.org/forums/viewthread/13148
* Usefull links:
* 1. What's the difference between __PRETTY_FUNCTION__, __FUNCTION__, __func__? -
* https://stackoverflow.com/questions/4384765/whats-the-difference-between-pretty-function-function-func
*
* 2. Windows Predefined Macros - http://msdn.microsoft.com/library/b0084kay.aspx
*
* 3. Windows DebugBreak function - http://msdn.microsoft.com/en-us/library/ms679297%28VS.85%29.aspx
*
* 4. Continue to debug after failed assertion on Linux? [C/C++] -
* https://stackoverflow.com/questions/1721543/continue-to-debug-after-failed-assertion-on-linux-c-c
*/
#ifndef QT_NO_DEBUG
#ifdef Q_OS_WIN32
#ifdef Q_CC_MSVC
#define SCASSERT(cond) \
{ \
if (!(cond)) \
{ \
qDebug("ASSERT: %s in %s (%s:%u)", \
#cond, __FUNCSIG__, __FILE__, __LINE__); \
DebugBreak(); \
} \
} \
#else
#define SCASSERT(cond) \
{ \
if (!(cond)) \
{ \
qDebug("ASSERT: %s in %s (%s:%u)", \
#cond, __PRETTY_FUNCTION__, __FILE__, __LINE__);\
DebugBreak(); \
} \
} \
#endif /*Q_CC_MSVC*/
#else
#define SCASSERT(cond) \
{ \
if (!(cond)) \
{ \
qDebug("ASSERT: %s in %s (%s:%u)", \
#cond, __PRETTY_FUNCTION__, __FILE__, __LINE__);\
std::raise(SIGTRAP); \
} \
} \
#endif /* Q_OS_WIN32 */
#else // define but disable this function if debugging is not set
#define SCASSERT(cond) qt_noop();
#endif /* QT_NO_DEBUG */
// Detect whether the compiler supports C++11 noexcept exception specifications.
# if defined(__clang__)
# if __has_feature(cxx_noexcept)
# define V_NOEXCEPT_EXPR(x) noexcept(x) // Clang 3.0 and above have noexcept
# endif
# elif defined(__GNUC__)
# if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && defined(__GXX_EXPERIMENTAL_CXX0X__)
# define V_NOEXCEPT_EXPR(x) noexcept(x) // GCC 4.7 and following have noexcept
# endif
# elif defined(_MSC_FULL_VER) && _MSC_FULL_VER >= 180021114
# define QMUP_NOEXCEPT_EXPR(x) noexcept(x)
# else
# define V_NOEXCEPT_EXPR(x)
# endif
#endif // OPTIONS_H #endif // OPTIONS_H

View File

@ -34,7 +34,7 @@
#include "../container/calculator.h" #include "../container/calculator.h"
#include "../../undocommands/addtocalc.h" #include "../../undocommands/addtocalc.h"
#include "../../undocommands/savetooloptions.h" #include "../../undocommands/savetooloptions.h"
#include "../../exception/vexceptionundo.h" #include "../../libs/ifc/exception/vexceptionundo.h"
qreal VDrawTool::factor = 1; qreal VDrawTool::factor = 1;

View File

@ -30,7 +30,7 @@
#include "../../container/calculator.h" #include "../../container/calculator.h"
#include "../../dialogs/tools/dialogalongline.h" #include "../../dialogs/tools/dialogalongline.h"
#include "../../geometry/vpointf.h" #include "../../geometry/vpointf.h"
#include "../../exception/vexceptionobjecterror.h" #include "../../libs/ifc/exception/vexceptionobjecterror.h"
#include "../../visualization/vistoolalongline.h" #include "../../visualization/vistoolalongline.h"
const QString VToolAlongLine::ToolType = QStringLiteral("alongLine"); const QString VToolAlongLine::ToolType = QStringLiteral("alongLine");

View File

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

View File

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

View File

@ -32,11 +32,12 @@
#include "../tools/vtooluniondetails.h" #include "../tools/vtooluniondetails.h"
#include "../tools/drawTools/drawtools.h" #include "../tools/drawTools/drawtools.h"
#include "../tools/nodeDetails/nodedetails.h" #include "../tools/nodeDetails/nodedetails.h"
#include "../exception/vexceptionobjecterror.h" #include "../libs/ifc/exception/vexceptionobjecterror.h"
#include "../exception/vexceptionwrongid.h" #include "../libs/ifc/exception/vexceptionwrongid.h"
#include "../exception/vexceptionconversionerror.h" #include "../libs/ifc/exception/vexceptionconversionerror.h"
#include "../exception/vexceptionemptyparameter.h" #include "../libs/ifc/exception/vexceptionemptyparameter.h"
#include "../exception/vexceptionundo.h" #include "../libs/ifc/exception/vexceptionundo.h"
#include "../libs/ifc/xml/vpatternconverter.h"
#include "../core/undoevent.h" #include "../core/undoevent.h"
#include "../core/vsettings.h" #include "../core/vsettings.h"
#include "vstandardmeasurements.h" #include "vstandardmeasurements.h"
@ -121,7 +122,7 @@ const QString VPattern::IncrementDescription = QStringLiteral("description");
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VPattern::VPattern(VContainer *data, Draw *mode, VMainGraphicsScene *sceneDraw, VPattern::VPattern(VContainer *data, Draw *mode, VMainGraphicsScene *sceneDraw,
VMainGraphicsScene *sceneDetail, QObject *parent) 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), history(QVector<VToolRecord>()), cursor(0), patternPieces(QStringList()), mode(mode), sceneDraw(sceneDraw),
sceneDetail(sceneDetail) sceneDetail(sceneDetail)
{ {
@ -146,7 +147,7 @@ void VPattern::CreateEmptyFile(const QString &tablePath)
patternElement.appendChild(createComment("Valentina pattern format.")); patternElement.appendChild(createComment("Valentina pattern format."));
QDomElement version = createElement(TagVersion); QDomElement version = createElement(TagVersion);
QDomText newNodeText = createTextNode(VAL_STR_VERSION); QDomText newNodeText = createTextNode(VPatternConverter::PatternMaxVerStr);
version.appendChild(newNodeText); version.appendChild(newNodeText);
patternElement.appendChild(version); patternElement.appendChild(version);
@ -2431,13 +2432,13 @@ void VPattern::SetNotes(const QString &text)
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QString VPattern::GetVersion() const QString VPattern::GetVersion() const
{ {
return UniqueTagText(TagVersion, VAL_STR_VERSION); return UniqueTagText(TagVersion, VPatternConverter::PatternMaxVerStr);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPattern::SetVersion() void VPattern::SetVersion()
{ {
setTagText(TagVersion, VAL_STR_VERSION); setTagText(TagVersion, VPatternConverter::PatternMaxVerStr);
emit patternChanged(false); emit patternChanged(false);
} }
@ -2572,14 +2573,14 @@ void VPattern::UpdateMeasurements()
{ {
VStandardMeasurements m(data); VStandardMeasurements m(data);
ValidateXML("://schema/standard_measurements.xsd", path); ValidateXML("://schema/standard_measurements.xsd", path);
m.setContent(path); m.setXMLContent(path);
m.Measurements(); m.Measurements();
} }
else else
{ {
VIndividualMeasurements m(data); VIndividualMeasurements m(data);
ValidateXML("://schema/individual_measurements.xsd", path); ValidateXML("://schema/individual_measurements.xsd", path);
m.setContent(path); m.setXMLContent(path);
m.Measurements(); m.Measurements();
} }
} }

View File

@ -29,8 +29,9 @@
#ifndef VPATTERN_H #ifndef VPATTERN_H
#define VPATTERN_H #define VPATTERN_H
#include "vdomdocument.h" #include "../libs/ifc/xml/vdomdocument.h"
#include "vtoolrecord.h" #include "vtoolrecord.h"
#include "../container/vcontainer.h"
class VDataTool; class VDataTool;
class VMainGraphicsScene; class VMainGraphicsScene;
@ -38,16 +39,6 @@ class VMainGraphicsScene;
enum class Document : char { LiteParse, LitePPParse, FullParse }; enum class Document : char { LiteParse, LitePPParse, FullParse };
enum class LabelType : char {NewPatternPiece, NewLabel}; enum class LabelType : char {NewPatternPiece, NewLabel};
/*
VAL_VERSION is (major << 16) + (minor << 8) + patch.
*/
// version without patch part
#define VAL_MIN_VERSION 0x000100
// max support version of format
#define VAL_VERSION 0x000101
#define VAL_STR_VERSION "0.1.1"
/** /**
* @brief The VPattern class working with pattern file. * @brief The VPattern class working with pattern file.
*/ */
@ -233,6 +224,9 @@ protected:
private: private:
Q_DISABLE_COPY(VPattern) Q_DISABLE_COPY(VPattern)
/** @brief data container with data. */
VContainer *data;
/** @brief nameActivDraw name current pattern peace. */ /** @brief nameActivDraw name current pattern peace. */
QString nameActivPP; QString nameActivPP;

View File

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

View File

@ -31,7 +31,6 @@
#include <QMessageBox> #include <QMessageBox>
#include <QSpacerItem> #include <QSpacerItem>
#include <QApplication> #include <QApplication>
#include "../options.h"
#include <QLoggingCategory> #include <QLoggingCategory>
Q_LOGGING_CATEGORY(vExcep, "v.excep") Q_LOGGING_CATEGORY(vExcep, "v.excep")

View File

@ -31,8 +31,7 @@
#include <QException> #include <QException>
#include <QString> #include <QString>
#include <QCoreApplication> #include "ifcdef.h"
#include "../options.h"
class QWidget; class QWidget;

View File

@ -27,7 +27,6 @@
*************************************************************************/ *************************************************************************/
#include "vexceptionbadid.h" #include "vexceptionbadid.h"
#include "../options.h"
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/** /**

13
src/libs/ifc/ifc.pri Normal file
View File

@ -0,0 +1,13 @@
# Suport subdirectories. Just better project code tree.
include(exception/exception.pri)
include(xml/xml.pri)
# ADD TO EACH PATH $$PWD VARIABLE!!!!!!
# This need for corect working file translations.pro
HEADERS += \
$$PWD/stable.h \
$$PWD/ifcdef.h
SOURCES += \
$$PWD/stable.cpp

88
src/libs/ifc/ifc.pro Normal file
View File

@ -0,0 +1,88 @@
#-------------------------------------------------
#
# Project created by QtCreator 2014-12-10T17:53:37
#
#-------------------------------------------------
# File with common stuff for whole project
include(../../../Valentina.pri)
# Library work with xml.
QT += xml xmlpatterns printsupport
# We don't need gui library.
QT -= gui
# Name of library
TARGET = ifc # Internal Format Converter
# We want create library
TEMPLATE = lib
CONFIG += \
staticlib \# Making static library
c++11 # We use C++11 standard
# Use out-of-source builds (shadow builds)
CONFIG -= debug_and_release debug_and_release_target
include(ifc.pri)
# This is static library so no need in "make install"
# directory for executable file
DESTDIR = bin
# files created moc
MOC_DIR = moc
# objecs files
OBJECTS_DIR = obj
# Resource files. This files will be included in binary.
RESOURCES += \
schema.qrc # Schemas for validation xml files.
# Set using ccache. Function enable_ccache() defined in Valentina.pri.
$$enable_ccache()
# Set precompiled headers. Function set_PCH() defined in Valentina.pri.
$$set_PCH()
CONFIG(debug, debug|release){
# Debug mode
unix {
#Turn on compilers warnings.
*-g++{
QMAKE_CXXFLAGS += \
# Key -isystem disable checking errors in system headers.
-isystem "$${OUT_PWD}/$${MOC_DIR}" \
$$GCC_DEBUG_CXXFLAGS # See Valentina.pri for more details.
}
clang*{
QMAKE_CXXFLAGS += \
# Key -isystem disable checking errors in system headers.
-isystem "$${OUT_PWD}/$${MOC_DIR}" \
$$CLANG_DEBUG_CXXFLAGS # See Valentina.pri for more details.
}
} else {
*-g++{
QMAKE_CXXFLAGS += $$GCC_DEBUG_CXXFLAGS # See Valentina.pri for more details.
}
}
}else{
# Release mode
!unix:*-g++{
QMAKE_CXXFLAGS += -fno-omit-frame-pointer # Need for exchndl.dll
}
!macx:!win32-msvc*{
# Turn on debug symbols in release mode on Unix systems.
# On Mac OS X temporarily disabled. TODO: find way how to strip binary file.
QMAKE_CXXFLAGS_RELEASE += -g -gdwarf-3
QMAKE_CFLAGS_RELEASE += -g -gdwarf-3
QMAKE_LFLAGS_RELEASE =
}
}

114
src/libs/ifc/ifcdef.h Normal file
View File

@ -0,0 +1,114 @@
/************************************************************************
**
** @file ifcdef.h
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 10 12, 2014
**
** @brief
** @copyright
** This source code is part of the Valentine project, a pattern making
** program, whose allow create and modeling patterns of clothing.
** Copyright (C) 2014 Valentina project
** <https://bitbucket.org/dismine/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 IFCDEF_H
#define IFCDEF_H
#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.
#define NULL_ID_STR "0"
/*
* This macros SCASSERT (for Stop and Continue Assert) will break into the debugger on the line of the assert and allow
* you to continue afterwards should you choose to.
* idea: Q_ASSERT no longer pauses debugger - http://qt-project.org/forums/viewthread/13148
* Usefull links:
* 1. What's the difference between __PRETTY_FUNCTION__, __FUNCTION__, __func__? -
* https://stackoverflow.com/questions/4384765/whats-the-difference-between-pretty-function-function-func
*
* 2. Windows Predefined Macros - http://msdn.microsoft.com/library/b0084kay.aspx
*
* 3. Windows DebugBreak function - http://msdn.microsoft.com/en-us/library/ms679297%28VS.85%29.aspx
*
* 4. Continue to debug after failed assertion on Linux? [C/C++] -
* https://stackoverflow.com/questions/1721543/continue-to-debug-after-failed-assertion-on-linux-c-c
*/
#ifndef QT_NO_DEBUG
#ifdef Q_OS_WIN32
#ifdef Q_CC_MSVC
#define SCASSERT(cond) \
{ \
if (!(cond)) \
{ \
qDebug("ASSERT: %s in %s (%s:%u)", \
#cond, __FUNCSIG__, __FILE__, __LINE__); \
DebugBreak(); \
} \
} \
#else
#define SCASSERT(cond) \
{ \
if (!(cond)) \
{ \
qDebug("ASSERT: %s in %s (%s:%u)", \
#cond, __PRETTY_FUNCTION__, __FILE__, __LINE__);\
DebugBreak(); \
} \
} \
#endif /*Q_CC_MSVC*/
#else
#define SCASSERT(cond) \
{ \
if (!(cond)) \
{ \
qDebug("ASSERT: %s in %s (%s:%u)", \
#cond, __PRETTY_FUNCTION__, __FILE__, __LINE__);\
std::raise(SIGTRAP); \
} \
} \
#endif /* Q_OS_WIN32 */
#else // define but disable this function if debugging is not set
#define SCASSERT(cond) qt_noop();
#endif /* QT_NO_DEBUG */
// Detect whether the compiler supports C++11 noexcept exception specifications.
# if defined(__clang__)
# if __has_feature(cxx_noexcept)
# define V_NOEXCEPT_EXPR(x) noexcept(x) // Clang 3.0 and above have noexcept
# endif
# elif defined(__GNUC__)
# if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && defined(__GXX_EXPERIMENTAL_CXX0X__)
# define V_NOEXCEPT_EXPR(x) noexcept(x) // GCC 4.7 and following have noexcept
# endif
# elif defined(_MSC_FULL_VER) && _MSC_FULL_VER >= 180021114
# define QMUP_NOEXCEPT_EXPR(x) noexcept(x)
# else
# define V_NOEXCEPT_EXPR(x)
# endif
#endif // IFCDEF_H

View File

@ -1,7 +1,7 @@
<RCC> <RCC>
<qresource prefix="/"> <qresource prefix="/">
<file>schema/pattern.xsd</file>
<file>schema/individual_measurements.xsd</file> <file>schema/individual_measurements.xsd</file>
<file>schema/standard_measurements.xsd</file> <file>schema/standard_measurements.xsd</file>
<file>schema/pattern/v0.1.1.xsd</file>
</qresource> </qresource>
</RCC> </RCC>

30
src/libs/ifc/stable.cpp Normal file
View File

@ -0,0 +1,30 @@
/************************************************************************
**
** @file stable.cpp
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 10 12, 2014
**
** @brief
** @copyright
** This source code is part of the Valentine project, a pattern making
** program, whose allow create and modeling patterns of clothing.
** Copyright (C) 2013 Valentina project
** <https://bitbucket.org/dismine/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/>.
**
*************************************************************************/
// Build the precompiled headers.
#include "stable.h"

67
src/libs/ifc/stable.h Normal file
View File

@ -0,0 +1,67 @@
/************************************************************************
**
** @file stable.h
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 10 12, 2014
**
** @brief
** @copyright
** This source code is part of the Valentine project, a pattern making
** program, whose allow create and modeling patterns of clothing.
** Copyright (C) 2013 Valentina project
** <https://bitbucket.org/dismine/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 STABLE_H
#define STABLE_H
/* I like to include this pragma too, so the build log indicates if pre-compiled headers were in use. */
#ifndef __clang__
#pragma message("Compiling precompiled headers for IFC library.\n")
#endif
/* Add C includes here */
#if defined __cplusplus
/* Add C++ includes here */
#ifdef QT_CORE_LIB
#include <QtCore>
#endif
#ifdef QT_XML_LIB
# include <QtXml>
#endif
//In Windows you can't use those headers in all modes.
#if !defined(Q_OS_WIN)
# ifdef QT_PRINTSUPPORT_LIB
# include <QtPrintSupport>
# endif
# ifdef QT_XMLPATTERNS_LIB
# include <QtXmlPatterns>
# endif
# ifdef QT_NETWORK_LIB
# include <QtNetwork>
# endif
#endif/*Q_OS_WIN*/
#endif/*__cplusplus*/
#endif // STABLE_H

View File

@ -0,0 +1,160 @@
/************************************************************************
**
** @file vabstractconverter.cpp
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 10 12, 2014
**
** @brief
** @copyright
** This source code is part of the Valentine project, a pattern making
** program, whose allow create and modeling patterns of clothing.
** Copyright (C) 2014 Valentina project
** <https://bitbucket.org/dismine/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 "vabstractconverter.h"
#include "exception/vexception.h"
#include <QFile>
//---------------------------------------------------------------------------------------------------------------------
VAbstractConverter::VAbstractConverter(const QString &fileName)
:VDomDocument(), ver(0x0), fileName(fileName)
{
this->setXMLContent(fileName);
const QString version = GetVersionStr();
ver = GetVersion(version);
}
//---------------------------------------------------------------------------------------------------------------------
VAbstractConverter::~VAbstractConverter()
{}
//---------------------------------------------------------------------------------------------------------------------
void VAbstractConverter::Convert() const
{
if (ver == MaxVer())
{
return;
}
QString error;
const QString backupFileName = fileName +".backup";
if (SafeCopy(fileName, backupFileName, error) == false)
{
const QString errorMsg(tr("Error creation backup file: %1.").arg(error));
throw VException(errorMsg);
}
ApplyPatches();
QFile file(backupFileName);
file.remove();
}
//---------------------------------------------------------------------------------------------------------------------
QString VAbstractConverter::GetVersionStr() const
{
const QDomNodeList nodeList = this->elementsByTagName(TagVersion);
if (nodeList.isEmpty())
{
const QString errorMsg(tr("Couldn't get version information."));
throw VException(errorMsg);
}
if (nodeList.count() > 1)
{
const QString errorMsg(tr("Too many tags <%1> in file.").arg(TagVersion));
throw VException(errorMsg);
}
const QDomNode domNode = nodeList.at(0);
if (domNode.isNull() == false && domNode.isElement())
{
const QDomElement domElement = domNode.toElement();
if (domElement.isNull() == false)
{
return domElement.text();
}
}
return QString(QStringLiteral("0.0.0"));
}
//---------------------------------------------------------------------------------------------------------------------
int VAbstractConverter::GetVersion(const QString &version) const
{
ValidateVersion(version);
QStringList ver = version.split(".");
bool ok = false;
int major = ver.at(0).toInt(&ok);
if (ok == false)
{
return 0x0;
}
ok = false;
int minor = ver.at(1).toInt(&ok);
if (ok == false)
{
return 0x0;
}
ok = false;
int patch = ver.at(2).toInt(&ok);
if (ok == false)
{
return 0x0;
}
return (major<<16)|(minor<<8)|(patch);
}
//---------------------------------------------------------------------------------------------------------------------
void VAbstractConverter::ValidateVersion(const QString &version) const
{
QRegExp rx(QStringLiteral("^(0|([1-9][0-9]*)).(0|([1-9][0-9]*)).(0|([1-9][0-9]*))$"));
if (rx.exactMatch(version) == false)
{
const QString errorMsg(tr("Version \"%1\" invalid.").arg(version));
throw VException(errorMsg);
}
if (version == QLatin1String("0.0.0"))
{
const QString errorMsg(tr("Version \"0.0.0\" invalid."));
throw VException(errorMsg);
}
}
//---------------------------------------------------------------------------------------------------------------------
void VAbstractConverter::CheckVersion(int ver) const
{
if (ver < MinVer())
{
const QString errorMsg(tr("Invalid version. Minimum supported version is %1").arg(MinVerStr()));
throw VException(errorMsg);
}
if (ver > MaxVer())
{
const QString errorMsg(tr("Invalid version. Maximum supported version is %1").arg(MaxVerStr()));
throw VException(errorMsg);
}
}

View File

@ -0,0 +1,67 @@
/************************************************************************
**
** @file vabstractconverter.h
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 10 12, 2014
**
** @brief
** @copyright
** This source code is part of the Valentine project, a pattern making
** program, whose allow create and modeling patterns of clothing.
** Copyright (C) 2014 Valentina project
** <https://bitbucket.org/dismine/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 VABSTRACTCONVERTER_H
#define VABSTRACTCONVERTER_H
#include "vdomdocument.h"
class VAbstractConverter :public VDomDocument
{
public:
VAbstractConverter(const QString &fileName);
virtual ~VAbstractConverter();
void Convert() const;
protected:
int ver;
QString fileName;
int GetVersion(const QString &version) const;
void CheckVersion(int ver) const;
virtual int MinVer() const =0;
virtual int MaxVer() const =0;
virtual QString MinVerStr() const =0;
virtual QString MaxVerStr() const =0;
virtual QString XSDSchema(int ver) const =0;
virtual void ApplyPatches() const =0;
private:
Q_DISABLE_COPY(VAbstractConverter)
QString GetVersionStr() const;
void ValidateVersion(const QString &version) const;
};
#endif // VABSTRACTCONVERTER_H

View File

@ -27,11 +27,9 @@
*************************************************************************/ *************************************************************************/
#include "vdomdocument.h" #include "vdomdocument.h"
#include "../exception/vexceptionconversionerror.h" #include "exception/vexceptionconversionerror.h"
#include "../exception/vexceptionemptyparameter.h" #include "exception/vexceptionemptyparameter.h"
#include "../exception/vexceptionbadid.h" #include "exception/vexceptionbadid.h"
#include "../options.h"
#include "../core/vapplication.h"
#include <QAbstractMessageHandler> #include <QAbstractMessageHandler>
#include <QXmlSchema> #include <QXmlSchema>
@ -100,8 +98,8 @@ const QString VDomDocument::UnitINCH = QStringLiteral("inch");
const QString VDomDocument::TagVersion = QStringLiteral("version"); const QString VDomDocument::TagVersion = QStringLiteral("version");
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VDomDocument::VDomDocument(VContainer *data) VDomDocument::VDomDocument()
: QDomDocument(), data(data), map(QHash<QString, QDomElement>()) : QDomDocument(), map(QHash<QString, QDomElement>())
{} {}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -412,7 +410,7 @@ void VDomDocument::ValidateXML(const QString &schema, const QString &fileName)
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VDomDocument::setContent(const QString &fileName) void VDomDocument::setXMLContent(const QString &fileName)
{ {
QFile file(fileName); QFile file(fileName);
if (file.open(QIODevice::ReadOnly) == false) if (file.open(QIODevice::ReadOnly) == false)
@ -536,7 +534,7 @@ bool VDomDocument::SaveDocument(const QString &fileName, QString &error)
tempFile.close(); tempFile.close();
} }
//Copy document to file //Copy document to file
bool result = VApplication::SafeCopy(temp, fileName, error); bool result = VDomDocument::SafeCopy(temp, fileName, error);
tempFile.remove();//Clear temp file tempFile.remove();//Clear temp file
return result; return result;
@ -635,3 +633,50 @@ QDomElement VDomDocument::NodeById(const quint32 &nodeId)
} }
return domElement; 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 <QDomDocument>
#include <QDebug> #include <QDebug>
#include "../container/vcontainer.h"
#include <QLoggingCategory> #include <QLoggingCategory>
#include <QCoreApplication>
#include "ifcdef.h"
Q_DECLARE_LOGGING_CATEGORY(vXML) Q_DECLARE_LOGGING_CATEGORY(vXML)
@ -80,7 +82,7 @@ public:
/** /**
* @param data container with variables * @param data container with variables
*/ */
VDomDocument(VContainer *data); VDomDocument();
virtual ~VDomDocument(); virtual ~VDomDocument();
QDomElement elementById(const QString& id); QDomElement elementById(const QString& id);
void removeAllChilds(QDomElement &element); void removeAllChilds(QDomElement &element);
@ -104,7 +106,7 @@ public:
qreal GetParametrDouble(const QDomElement& domElement, const QString &name, const QString &defValue) const; qreal GetParametrDouble(const QDomElement& domElement, const QString &name, const QString &defValue) const;
static void ValidateXML(const QString &schema, const QString &fileName); static void ValidateXML(const QString &schema, const QString &fileName);
void setContent(const QString &fileName); void setXMLContent(const QString &fileName);
static Unit StrToUnits(const QString &unit); static Unit StrToUnits(const QString &unit);
static QString UnitsToStr(const Unit &unit, const bool translate = false); static QString UnitsToStr(const Unit &unit, const bool translate = false);
virtual bool SaveDocument(const QString &fileName, QString &error); virtual bool SaveDocument(const QString &fileName, QString &error);
@ -116,12 +118,12 @@ public:
QDomNode ParentNodeById(const quint32 &nodeId); QDomNode ParentNodeById(const quint32 &nodeId);
QDomElement CloneNodeById(const quint32 &nodeId); QDomElement CloneNodeById(const quint32 &nodeId);
QDomElement NodeById(const quint32 &nodeId); QDomElement NodeById(const quint32 &nodeId);
protected: static bool SafeCopy(const QString &source, const QString &destination, QString &error);
/** @brief data container with data. */
VContainer *data;
protected:
void setTagText(const QString &tag, const QString &text); void setTagText(const QString &tag, const QString &text);
QString UniqueTagText(const QString &tagName, const QString &defVal = QString()) const; QString UniqueTagText(const QString &tagName, const QString &defVal = QString()) const;
private: private:
Q_DISABLE_COPY(VDomDocument) Q_DISABLE_COPY(VDomDocument)
/** @brief Map used for finding element by id. */ /** @brief Map used for finding element by id. */

View File

@ -0,0 +1,122 @@
/************************************************************************
**
** @file vpatternconverter.cpp
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 11 12, 2014
**
** @brief
** @copyright
** This source code is part of the Valentine project, a pattern making
** program, whose allow create and modeling patterns of clothing.
** Copyright (C) 2014 Valentina project
** <https://bitbucket.org/dismine/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 "vpatternconverter.h"
#include "exception/vexception.h"
#include <QFile>
const QString VPatternConverter::PatternMinVerStr = QStringLiteral("0.1.1");
const QString VPatternConverter::PatternMaxVerStr = QStringLiteral("0.1.1");
const QString VPatternConverter::CurrentSchema = QStringLiteral("://schema/pattern/v0.1.1.xsd");
//---------------------------------------------------------------------------------------------------------------------
VPatternConverter::VPatternConverter(const QString &fileName)
:VAbstractConverter(fileName)
{
const QString schema = XSDSchema(ver);
ValidateXML(schema, fileName);
}
//---------------------------------------------------------------------------------------------------------------------
VPatternConverter::~VPatternConverter()
{}
//---------------------------------------------------------------------------------------------------------------------
int VPatternConverter::MinVer() const
{
return GetVersion(PatternMinVerStr);
}
//---------------------------------------------------------------------------------------------------------------------
int VPatternConverter::MaxVer() const
{
return GetVersion(PatternMaxVerStr);
}
//---------------------------------------------------------------------------------------------------------------------
QString VPatternConverter::MinVerStr() const
{
return PatternMinVerStr;
}
//---------------------------------------------------------------------------------------------------------------------
QString VPatternConverter::MaxVerStr() const
{
return PatternMaxVerStr;
}
//---------------------------------------------------------------------------------------------------------------------
QString VPatternConverter::XSDSchema(int ver) const
{
CheckVersion(ver);
switch(ver)
{
case (0x000101):
return CurrentSchema;
default:
{
const QString errorMsg(tr("Unexpected version \"%1\".").arg(ver, 0, 16));
throw VException(errorMsg);
break;
}
}
}
//---------------------------------------------------------------------------------------------------------------------
void VPatternConverter::ApplyPatches() const
{
try
{
switch(ver)
{
case (0x000101):
break;
default:
break;
}
}
catch (VException &e)
{
QString error;
const QString backupFileName = fileName +".backup";
if (SafeCopy(backupFileName, fileName, error) == false)
{
const QString errorMsg(tr("Error restoring backup file: %1.").arg(error));
VException excep(errorMsg);
excep.AddMoreInformation(e.ErrorMessage());
throw excep;
}
QFile file(backupFileName);
file.remove();
throw e;
}
}

View File

@ -0,0 +1,58 @@
/************************************************************************
**
** @file vpatternconverter.h
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 11 12, 2014
**
** @brief
** @copyright
** This source code is part of the Valentine project, a pattern making
** program, whose allow create and modeling patterns of clothing.
** Copyright (C) 2014 Valentina project
** <https://bitbucket.org/dismine/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 VPATTERNCONVERTER_H
#define VPATTERNCONVERTER_H
#include "vabstractconverter.h"
class VPatternConverter : public VAbstractConverter
{
public:
VPatternConverter(const QString &fileName);
virtual ~VPatternConverter();
static const QString PatternMaxVerStr;
static const QString CurrentSchema;
protected:
virtual int MinVer() const;
virtual int MaxVer() const;
virtual QString MinVerStr() const;
virtual QString MaxVerStr() const;
QString XSDSchema(int ver) const;
virtual void ApplyPatches() const;
private:
Q_DISABLE_COPY(VPatternConverter)
static const QString PatternMinVerStr;
};
#endif // VPATTERNCONVERTER_H

12
src/libs/ifc/xml/xml.pri Normal file
View File

@ -0,0 +1,12 @@
# ADD TO EACH PATH $$PWD VARIABLE!!!!!!
# This need for corect working file translations.pro
HEADERS += \
$$PWD/vabstractconverter.h \
$$PWD/vdomdocument.h \
$$PWD/vpatternconverter.h
SOURCES += \
$$PWD/vabstractconverter.cpp \
$$PWD/vdomdocument.cpp \
$$PWD/vpatternconverter.cpp

View File

@ -1,4 +1,5 @@
TEMPLATE = subdirs TEMPLATE = subdirs
CONFIG += ordered CONFIG += ordered
SUBDIRS = qmuparser \ SUBDIRS = qmuparser \
vpropertyexplorer vpropertyexplorer \
ifc