From a312e763c09f281d242b1bc890f7a2958891d99c Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Thu, 18 Jun 2015 11:45:38 +0300 Subject: [PATCH] Move VFormula to library VPatternDB. New class VAbstractPattern. --HG-- branch : feature --- src/app/core/core.pri | 2 - src/app/core/vapplication.cpp | 27 +----- src/app/core/vapplication.h | 40 +------- src/app/core/vformulaproperty.cpp | 2 +- src/app/core/vformulapropertyeditor.h | 2 +- src/app/core/vtooloptionspropertybrowser.cpp | 2 +- src/app/tools/drawTools/vtoolarc.cpp | 2 +- .../tools/drawTools/vtoolarcwithlength.cpp | 2 +- src/app/tools/drawTools/vtoolcut.cpp | 2 +- src/app/tools/drawTools/vtoollinepoint.h | 2 +- .../vtoolpointfromcircleandtangent.cpp | 2 +- .../tools/drawTools/vtoolpointofcontact.cpp | 2 +- .../vtoolpointofintersectioncircles.cpp | 2 +- src/libs/ifc/ifcdef.h | 1 - src/libs/ifc/xml/vdomdocument.h | 1 + src/libs/vmisc/def.h | 1 + src/libs/vmisc/vabstractapplication.cpp | 61 ++++++++++++ src/libs/vmisc/vabstractapplication.h | 92 +++++++++++++++++++ src/libs/vmisc/vmisc.pri | 6 +- src/libs/vpatterndb/calculator.h | 2 +- .../core => libs/vpatterndb}/vformula.cpp | 9 +- src/{app/core => libs/vpatterndb}/vformula.h | 0 src/libs/vpatterndb/vpatterndb.pri | 6 +- 23 files changed, 186 insertions(+), 82 deletions(-) create mode 100644 src/libs/vmisc/vabstractapplication.cpp create mode 100644 src/libs/vmisc/vabstractapplication.h rename src/{app/core => libs/vpatterndb}/vformula.cpp (98%) rename src/{app/core => libs/vpatterndb}/vformula.h (100%) diff --git a/src/app/core/core.pri b/src/app/core/core.pri index 401024d03..7627b9046 100644 --- a/src/app/core/core.pri +++ b/src/app/core/core.pri @@ -3,14 +3,12 @@ HEADERS += \ $$PWD/vapplication.h \ - $$PWD/vformula.h \ $$PWD/vformulaproperty.h \ $$PWD/vformulapropertyeditor.h \ $$PWD/vtooloptionspropertybrowser.h SOURCES += \ $$PWD/vapplication.cpp \ - $$PWD/vformula.cpp \ $$PWD/vformulaproperty.cpp \ $$PWD/vformulapropertyeditor.cpp \ $$PWD/vtooloptionspropertybrowser.cpp diff --git a/src/app/core/vapplication.cpp b/src/app/core/vapplication.cpp index e461fc1da..cd70f6d5f 100644 --- a/src/app/core/vapplication.cpp +++ b/src/app/core/vapplication.cpp @@ -156,9 +156,9 @@ const QString VApplication::GistFileName = QStringLiteral("gist.json"); * @param argv command line. */ VApplication::VApplication(int &argc, char **argv) - : QApplication(argc, argv), _patternUnit(Unit::Cm), _patternType(MeasurementsType::Individual), + : VAbstractApplication(argc, argv), _patternUnit(Unit::Cm), trVars(nullptr), undoStack(nullptr), sceneView(nullptr), currentScene(nullptr), autoSaveTimer(nullptr), - mainWindow(nullptr), openingPattern(false), settings(nullptr), doc(nullptr), log(nullptr), + mainWindow(nullptr), openingPattern(false), doc(nullptr), log(nullptr), #if QT_VERSION >= QT_VERSION_CHECK(5, 1, 0) out(nullptr), logLock(nullptr) #else @@ -572,29 +572,6 @@ void VApplication::setOpeningPattern() openingPattern = !openingPattern; } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief VApplication::OpenSettings get acsses to application settings. - * - * Because we can create object in constructor we open file separately. - */ -void VApplication::OpenSettings() -{ - settings = new VSettings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(), - QApplication::applicationName(), this); -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief VApplication::getSettings hide settings constructor. - * @return pointer to class for acssesing to settings in ini file. - */ -VSettings *VApplication::getSettings() -{ - SCASSERT(settings != nullptr); - return settings; -} - //--------------------------------------------------------------------------------------------------------------------- QGraphicsScene *VApplication::getCurrentScene() const { diff --git a/src/app/core/vapplication.h b/src/app/core/vapplication.h index 1427e57f8..d480f4dba 100644 --- a/src/app/core/vapplication.h +++ b/src/app/core/vapplication.h @@ -29,13 +29,13 @@ #ifndef VAPPLICATION_H #define VAPPLICATION_H -#include +#include "../libs/vmisc/vabstractapplication.h" #include "../options.h" #include "../libs/vwidgets/vmaingraphicsview.h" #include "../libs/vpatterndb/vtranslatevars.h" #include "vsettings.h" -class VApplication;// used in define +class VApplication;// use in define class QUndoStack; class VMainGraphicsView; class VPattern; @@ -47,12 +47,12 @@ class QLockFile; #if defined(qApp) #undef qApp #endif -#define qApp (static_cast(QCoreApplication::instance())) +#define qApp (static_cast(VAbstractApplication::instance())) /** * @brief The VApplication class reimplamentation QApplication class. */ -class VApplication : public QApplication +class VApplication : public VAbstractApplication { Q_OBJECT public: @@ -64,8 +64,6 @@ public: Unit patternUnit() const; const Unit *patternUnitP() const; void setPatternUnit(const Unit &patternUnit); - MeasurementsType patternType() const; - void setPatternType(const MeasurementsType &patternType); void InitOptions(); @@ -78,14 +76,6 @@ public: QString translationsPath() const; - template - QString LocaleToString(const T &value) - { - QLocale loc; - qApp->getSettings()->GetOsSeparator() ? loc = QLocale::system() : loc = QLocale(QLocale::C); - return loc.toString(value); - } - QUndoStack *getUndoStack() const; VMainGraphicsView *getSceneView() const; void setSceneView(VMainGraphicsView *value); @@ -96,9 +86,6 @@ public: bool getOpeningPattern() const; void setOpeningPattern(); - void OpenSettings(); - VSettings *getSettings(); - QGraphicsScene *getCurrentScene() const; void setCurrentScene(QGraphicsScene *value); @@ -110,7 +97,7 @@ public: void StartLogging(); QTextStream *LogFile(); - const VTranslateVars *TrVars(); + virtual const VTranslateVars *TrVars(); void InitTrVars(); @@ -127,7 +114,6 @@ private slots: private: Q_DISABLE_COPY(VApplication) Unit _patternUnit; - MeasurementsType _patternType; VTranslateVars *trVars; QUndoStack *undoStack; VMainGraphicsView *sceneView; @@ -143,10 +129,6 @@ private: * we can allow user use Undo option. */ bool openingPattern; - /** - * @brief settings pointer to settings. Help hide constructor creation settings. Make make code more readable. - */ - VSettings *settings; VPattern *doc; QFile *log; @@ -185,18 +167,6 @@ inline const Unit *VApplication::patternUnitP() const return &_patternUnit; } -//--------------------------------------------------------------------------------------------------------------------- -inline MeasurementsType VApplication::patternType() const -{ - return _patternType; -} - -//--------------------------------------------------------------------------------------------------------------------- -inline void VApplication::setPatternType(const MeasurementsType &patternType) -{ - _patternType = patternType; -} - //--------------------------------------------------------------------------------------------------------------------- inline QUndoStack *VApplication::getUndoStack() const { diff --git a/src/app/core/vformulaproperty.cpp b/src/app/core/vformulaproperty.cpp index e42887c09..6be529d65 100644 --- a/src/app/core/vformulaproperty.cpp +++ b/src/app/core/vformulaproperty.cpp @@ -32,7 +32,7 @@ #include "../../libs/vpropertyexplorer/vproperty_p.h" #include "vformulapropertyeditor.h" #include "../../libs/vpropertyexplorer/vproperties.h" -#include "../core/vformula.h" +#include "../../libs/vpatterndb/vformula.h" enum class ChildType : char {Invalid = 0, Value = 1, Formula = 2}; diff --git a/src/app/core/vformulapropertyeditor.h b/src/app/core/vformulapropertyeditor.h index 3d3c529aa..e57910837 100644 --- a/src/app/core/vformulapropertyeditor.h +++ b/src/app/core/vformulapropertyeditor.h @@ -35,7 +35,7 @@ #include #include -#include "../core/vformula.h" +#include "../../libs/vpatterndb/vformula.h" class VFormulaPropertyEditor : public QWidget { diff --git a/src/app/core/vtooloptionspropertybrowser.cpp b/src/app/core/vtooloptionspropertybrowser.cpp index 7e47f60cf..61fbea81c 100644 --- a/src/app/core/vtooloptionspropertybrowser.cpp +++ b/src/app/core/vtooloptionspropertybrowser.cpp @@ -34,7 +34,7 @@ #include "../../libs/vwidgets/vcontrolpointspline.h" #include "../../libs/vpropertyexplorer/vproperties.h" #include "vformulaproperty.h" -#include "../core/vformula.h" +#include "../../libs/vpatterndb/vformula.h" #include #include diff --git a/src/app/tools/drawTools/vtoolarc.cpp b/src/app/tools/drawTools/vtoolarc.cpp index 5c98e36ef..a520dd08d 100644 --- a/src/app/tools/drawTools/vtoolarc.cpp +++ b/src/app/tools/drawTools/vtoolarc.cpp @@ -30,7 +30,7 @@ #include "../../libs/vpatterndb/calculator.h" #include "../../dialogs/tools/dialogarc.h" #include "../../libs/vgeometry/varc.h" -#include "../../core/vformula.h" +#include "../../libs/vpatterndb/vformula.h" #include "../../visualization/vistoolarc.h" #include diff --git a/src/app/tools/drawTools/vtoolarcwithlength.cpp b/src/app/tools/drawTools/vtoolarcwithlength.cpp index ae65670b5..bbcde358b 100644 --- a/src/app/tools/drawTools/vtoolarcwithlength.cpp +++ b/src/app/tools/drawTools/vtoolarcwithlength.cpp @@ -30,7 +30,7 @@ #include "../../libs/vpatterndb/calculator.h" #include "../../dialogs/tools/dialogarcwithlength.h" #include "../../libs/vgeometry/varc.h" -#include "../../core/vformula.h" +#include "../../libs/vpatterndb/vformula.h" #include "../../visualization/vistoolarcwithlength.h" #include diff --git a/src/app/tools/drawTools/vtoolcut.cpp b/src/app/tools/drawTools/vtoolcut.cpp index e6a2fce65..2fbf78129 100644 --- a/src/app/tools/drawTools/vtoolcut.cpp +++ b/src/app/tools/drawTools/vtoolcut.cpp @@ -28,7 +28,7 @@ #include "vtoolcut.h" #include "../../libs/vgeometry/vpointf.h" -#include "../../core/vformula.h" +#include "../../libs/vpatterndb/vformula.h" //--------------------------------------------------------------------------------------------------------------------- VToolCut::VToolCut(VPattern *doc, VContainer *data, const quint32 &id, const QString &formula, diff --git a/src/app/tools/drawTools/vtoollinepoint.h b/src/app/tools/drawTools/vtoollinepoint.h index 93d020c68..b8646de6e 100644 --- a/src/app/tools/drawTools/vtoollinepoint.h +++ b/src/app/tools/drawTools/vtoollinepoint.h @@ -30,7 +30,7 @@ #define VTOOLLINEPOINT_H #include "vtoolpoint.h" -#include "../../core/vformula.h" +#include "../../../libs/vpatterndb/vformula.h" /** * @brief The VToolLinePoint class parent for all tools what create point with line. diff --git a/src/app/tools/drawTools/vtoolpointfromcircleandtangent.cpp b/src/app/tools/drawTools/vtoolpointfromcircleandtangent.cpp index 6156d55a5..350285d11 100644 --- a/src/app/tools/drawTools/vtoolpointfromcircleandtangent.cpp +++ b/src/app/tools/drawTools/vtoolpointfromcircleandtangent.cpp @@ -31,7 +31,7 @@ #include "../../libs/vgeometry/vpointf.h" #include "../../libs/vgeometry/varc.h" #include "../../visualization/vistoolpointfromcircleandtangent.h" -#include "../../core/vformula.h" +#include "../../libs/vpatterndb/vformula.h" const QString VToolPointFromCircleAndTangent::ToolType = QStringLiteral("pointFromCircleAndTangent"); diff --git a/src/app/tools/drawTools/vtoolpointofcontact.cpp b/src/app/tools/drawTools/vtoolpointofcontact.cpp index 026529f95..42ac9f46f 100644 --- a/src/app/tools/drawTools/vtoolpointofcontact.cpp +++ b/src/app/tools/drawTools/vtoolpointofcontact.cpp @@ -30,7 +30,7 @@ #include "../../libs/vpatterndb/calculator.h" #include "../../dialogs/tools/dialogpointofcontact.h" #include "../../libs/vgeometry/vpointf.h" -#include "../../core/vformula.h" +#include "../../libs/vpatterndb/vformula.h" #include "../../visualization/vistoolpointofcontact.h" #include diff --git a/src/app/tools/drawTools/vtoolpointofintersectioncircles.cpp b/src/app/tools/drawTools/vtoolpointofintersectioncircles.cpp index b5f7e5823..5eb6833bf 100644 --- a/src/app/tools/drawTools/vtoolpointofintersectioncircles.cpp +++ b/src/app/tools/drawTools/vtoolpointofintersectioncircles.cpp @@ -31,7 +31,7 @@ #include "../../libs/vgeometry/vpointf.h" #include "../../libs/vgeometry/varc.h" #include "../../visualization/vistoolpointofintersectioncircles.h" -#include "../../core/vformula.h" +#include "../../libs/vpatterndb/vformula.h" const QString VToolPointOfIntersectionCircles::ToolType = QStringLiteral("pointOfIntersectionCircles"); diff --git a/src/libs/ifc/ifcdef.h b/src/libs/ifc/ifcdef.h index e61a27a06..af4eb50ca 100644 --- a/src/libs/ifc/ifcdef.h +++ b/src/libs/ifc/ifcdef.h @@ -37,7 +37,6 @@ #endif /*Q_OS_WIN32*/ enum class Unit : char { Mm, Cm, Inch, Px }; -enum class MeasurementsType : char { Standard, Individual }; static const quint32 null_id = 0; diff --git a/src/libs/ifc/xml/vdomdocument.h b/src/libs/ifc/xml/vdomdocument.h index 20d78c8eb..ab86e8bb9 100644 --- a/src/libs/ifc/xml/vdomdocument.h +++ b/src/libs/ifc/xml/vdomdocument.h @@ -34,6 +34,7 @@ #include #include "ifcdef.h" +#include "../vmisc/def.h" #include "../vmisc/logging.h" Q_DECLARE_LOGGING_CATEGORY(vXML) diff --git a/src/libs/vmisc/def.h b/src/libs/vmisc/def.h index 0bab8864f..d1693a929 100644 --- a/src/libs/vmisc/def.h +++ b/src/libs/vmisc/def.h @@ -35,6 +35,7 @@ enum class NodeDetail : char { Contour, Modeling }; enum class SceneObject : char { Point, Line, Spline, Arc, SplinePath, Detail, Unknown }; +enum class MeasurementsType : char { Standard, Individual }; enum class Tool : unsigned char { diff --git a/src/libs/vmisc/vabstractapplication.cpp b/src/libs/vmisc/vabstractapplication.cpp new file mode 100644 index 000000000..7a31758cb --- /dev/null +++ b/src/libs/vmisc/vabstractapplication.cpp @@ -0,0 +1,61 @@ +/************************************************************************ + ** + ** @file vabstractapplication.cpp + ** @author Roman Telezhynskyi + ** @date 18 6, 2015 + ** + ** @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) 2015 Valentina project + ** 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 . + ** + *************************************************************************/ + +#include "vabstractapplication.h" + +//--------------------------------------------------------------------------------------------------------------------- +VAbstractApplication::VAbstractApplication(int &argc, char **argv) + :QApplication(argc, argv), _patternType(MeasurementsType::Individual), settings(nullptr) +{} + +//--------------------------------------------------------------------------------------------------------------------- +VAbstractApplication::~VAbstractApplication() +{} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief OpenSettings get acsses to application settings. + * + * Because we can create object in constructor we open file separately. + */ +void VAbstractApplication::OpenSettings() +{ + settings = new VSettings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(), + QApplication::applicationName(), this); +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief getSettings hide settings constructor. + * @return pointer to class for acssesing to settings in ini file. + */ +VSettings *VAbstractApplication::getSettings() +{ + SCASSERT(settings != nullptr); + return settings; +} diff --git a/src/libs/vmisc/vabstractapplication.h b/src/libs/vmisc/vabstractapplication.h new file mode 100644 index 000000000..f420c4edc --- /dev/null +++ b/src/libs/vmisc/vabstractapplication.h @@ -0,0 +1,92 @@ +/************************************************************************ + ** + ** @file vabstractapplication.h + ** @author Roman Telezhynskyi + ** @date 18 6, 2015 + ** + ** @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) 2015 Valentina project + ** 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 . + ** + *************************************************************************/ + +#ifndef VABSTRACTAPPLICATION_H +#define VABSTRACTAPPLICATION_H + +#include +#include "def.h" +#include "vsettings.h" + +class VAbstractApplication;// use in define +class VTranslateVars; + +#if defined(qApp) +#undef qApp +#endif +#define qApp (static_cast(QCoreApplication::instance())) + +class VAbstractApplication : public QApplication +{ +public: + VAbstractApplication(int &argc, char ** argv); + virtual ~VAbstractApplication(); + + virtual const VTranslateVars *TrVars()=0; + + MeasurementsType patternType() const; + void setPatternType(const MeasurementsType &patternType); + + void OpenSettings(); + VSettings *getSettings(); + + template + QString LocaleToString(const T &value); + + +private: + Q_DISABLE_COPY(VAbstractApplication) + MeasurementsType _patternType; + /** + * @brief settings pointer to settings. Help hide constructor creation settings. Make make code more readable. + */ + VSettings *settings; +}; + +//--------------------------------------------------------------------------------------------------------------------- +inline MeasurementsType VAbstractApplication::patternType() const +{ + return _patternType; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline void VAbstractApplication::setPatternType(const MeasurementsType &patternType) +{ + _patternType = patternType; +} + +//--------------------------------------------------------------------------------------------------------------------- +template +QString VAbstractApplication::LocaleToString(const T &value) +{ + QLocale loc; + qApp->getSettings()->GetOsSeparator() ? loc = QLocale::system() : loc = QLocale(QLocale::C); + return loc.toString(value); +} + +#endif // VABSTRACTAPPLICATION_H diff --git a/src/libs/vmisc/vmisc.pri b/src/libs/vmisc/vmisc.pri index 658e0d301..e33858f0a 100644 --- a/src/libs/vmisc/vmisc.pri +++ b/src/libs/vmisc/vmisc.pri @@ -7,7 +7,8 @@ SOURCES += \ $$PWD/undoevent.cpp \ $$PWD/backport/qcommandlineoption.cpp \ $$PWD/backport/qcommandlineparser.cpp \ - $$PWD/vsettings.cpp + $$PWD/vsettings.cpp \ + $$PWD/vabstractapplication.cpp HEADERS += \ $$PWD/stable.h \ @@ -17,4 +18,5 @@ HEADERS += \ $$PWD/undoevent.h \ $$PWD/backport/qcommandlineoption.h \ $$PWD/backport/qcommandlineparser.h \ - $$PWD/vsettings.h + $$PWD/vsettings.h \ + $$PWD/vabstractapplication.h diff --git a/src/libs/vpatterndb/calculator.h b/src/libs/vpatterndb/calculator.h index db9dba192..9cb2b5a3f 100644 --- a/src/libs/vpatterndb/calculator.h +++ b/src/libs/vpatterndb/calculator.h @@ -30,7 +30,7 @@ #define CALCULATOR_H #include "../qmuparser/qmuparser.h" -#include "../ifc/ifcdef.h" +#include "../vmisc/def.h" class VContainer; diff --git a/src/app/core/vformula.cpp b/src/libs/vpatterndb/vformula.cpp similarity index 98% rename from src/app/core/vformula.cpp rename to src/libs/vpatterndb/vformula.cpp index 3cdca81f7..1de34fa53 100644 --- a/src/app/core/vformula.cpp +++ b/src/libs/vpatterndb/vformula.cpp @@ -27,10 +27,11 @@ *************************************************************************/ #include "vformula.h" -#include "../libs/vpatterndb/calculator.h" -#include "../libs/vpatterndb/vcontainer.h" -#include "../core/vapplication.h" -#include "../libs/vmisc/vsettings.h" +#include "calculator.h" +#include "vcontainer.h" +#include "../vmisc/vabstractapplication.h" +#include "../vmisc/vsettings.h" +#include "vtranslatevars.h" #include //VFormula diff --git a/src/app/core/vformula.h b/src/libs/vpatterndb/vformula.h similarity index 100% rename from src/app/core/vformula.h rename to src/libs/vpatterndb/vformula.h diff --git a/src/libs/vpatterndb/vpatterndb.pri b/src/libs/vpatterndb/vpatterndb.pri index 5cf261312..97e7281c6 100644 --- a/src/libs/vpatterndb/vpatterndb.pri +++ b/src/libs/vpatterndb/vpatterndb.pri @@ -21,7 +21,8 @@ SOURCES += \ $$PWD/variables/vmeasurement.cpp \ $$PWD/variables/vsplineangle.cpp \ $$PWD/variables/vsplinelength.cpp \ - $$PWD/variables/vvariable.cpp + $$PWD/variables/vvariable.cpp \ + $$PWD/vformula.cpp HEADERS += \ $$PWD/vcontainer.h \ @@ -54,4 +55,5 @@ HEADERS += \ $$PWD/variables/vsplineangle.h \ $$PWD/variables/vsplinelength.h \ $$PWD/variables/vvariable.h \ - $$PWD/variables/vvariable_p.h + $$PWD/variables/vvariable_p.h \ + $$PWD/vformula.h