From 5c84c800395553fe0b7c27b002b813b19a167769 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Mon, 22 Jul 2019 17:06:30 +0300 Subject: [PATCH] Refactoring. Reduce modules dependency. --HG-- branch : develop --- src/app/valentina/core/vcmdexport.h | 1 + .../valentina/dialogs/dialoglayoutsettings.h | 3 +- .../valentina/dialogs/vabstractlayoutdialog.h | 4 +- src/app/valentina/mainwindowsnogui.cpp | 4 +- src/libs/vdxf/vdxfengine.cpp | 1 + src/libs/vlayout/vabstractpiece.cpp | 38 ++++++++++++++++ src/libs/vlayout/vabstractpiece.h | 43 +------------------ src/libs/vlayout/vbank.cpp | 2 + src/libs/vlayout/vbank.h | 3 ++ src/libs/vlayout/vcontour.cpp | 2 + src/libs/vlayout/vlayoutpiece.cpp | 1 + src/libs/vlayout/vlayoutpiece.h | 12 +++--- src/libs/vlayout/vposition.cpp | 2 + src/libs/vmisc/vcommonsettings.h | 2 - src/libs/vmisc/vsettings.cpp | 27 +++++++++++- src/libs/vmisc/vsettings.h | 29 ++----------- src/libs/vtools/tools/vtoolseamallowance.cpp | 1 + 17 files changed, 94 insertions(+), 81 deletions(-) diff --git a/src/app/valentina/core/vcmdexport.h b/src/app/valentina/core/vcmdexport.h index fb8ccae89..420ac1a79 100644 --- a/src/app/valentina/core/vcmdexport.h +++ b/src/app/valentina/core/vcmdexport.h @@ -41,6 +41,7 @@ class VCommandLine; using VCommandLinePtr = std::shared_ptr; using VLayoutGeneratorPtr = std::shared_ptr; +enum class PageOrientation : bool; //@brief: class used to install export command line options and parse their values //QCommandLineParser* object must exists until this object alive diff --git a/src/app/valentina/dialogs/dialoglayoutsettings.h b/src/app/valentina/dialogs/dialoglayoutsettings.h index d0a109234..2a4ac3bb8 100644 --- a/src/app/valentina/dialogs/dialoglayoutsettings.h +++ b/src/app/valentina/dialogs/dialoglayoutsettings.h @@ -33,8 +33,6 @@ #include #include "vabstractlayoutdialog.h" -#include "../vlayout/vbank.h" -#include "../ifc/ifcdef.h" namespace Ui { @@ -42,6 +40,7 @@ namespace Ui } class VLayoutGenerator; +enum class Cases : char; class DialogLayoutSettings : public VAbstractLayoutDialog { diff --git a/src/app/valentina/dialogs/vabstractlayoutdialog.h b/src/app/valentina/dialogs/vabstractlayoutdialog.h index ff2948d59..289c3ef76 100644 --- a/src/app/valentina/dialogs/vabstractlayoutdialog.h +++ b/src/app/valentina/dialogs/vabstractlayoutdialog.h @@ -29,11 +29,11 @@ #ifndef VABSTRACTLAYOUTDIALOG_H #define VABSTRACTLAYOUTDIALOG_H -#include "../ifc/ifcdef.h" - #include #include +enum class Unit : char; + class VAbstractLayoutDialog : public QDialog { public: diff --git a/src/app/valentina/mainwindowsnogui.cpp b/src/app/valentina/mainwindowsnogui.cpp index 6844da28a..9e43ad147 100644 --- a/src/app/valentina/mainwindowsnogui.cpp +++ b/src/app/valentina/mainwindowsnogui.cpp @@ -323,8 +323,8 @@ bool MainWindowsNoGUI::GenerateLayout(VLayoutGenerator& lGenerator) isLayoutPortrait = lGenerator.IsPortrait(); scenes = CreateScenes(papers, shadows, details); //Uncomment to debug, shows global contour - // gcontours = lGenerator.GetGlobalContours(); // uncomment for debugging - // InsertGlobalContours(scenes, gcontours); // uncomment for debugging + gcontours = lGenerator.GetGlobalContours(); // uncomment for debugging + InsertGlobalContours(scenes, gcontours); // uncomment for debugging if (VApplication::IsGUIMode()) { PrepareSceneList(PreviewQuatilty::Fast); diff --git a/src/libs/vdxf/vdxfengine.cpp b/src/libs/vdxf/vdxfengine.cpp index 7771e66ea..03a90fdec 100644 --- a/src/libs/vdxf/vdxfengine.cpp +++ b/src/libs/vdxf/vdxfengine.cpp @@ -51,6 +51,7 @@ #include "../vmisc/vmath.h" #include "dxiface.h" #include "../vlayout/vlayoutpiece.h" +#include "../vgeometry/vgeometrydef.h" static const qreal AAMATextHeight = 2.5; diff --git a/src/libs/vlayout/vabstractpiece.cpp b/src/libs/vlayout/vabstractpiece.cpp index 6bbf6a0a3..7be188472 100644 --- a/src/libs/vlayout/vabstractpiece.cpp +++ b/src/libs/vlayout/vabstractpiece.cpp @@ -768,6 +768,44 @@ QT_WARNING_POP } } #endif + +//--------------------------------------------------------------------------------------------------------------------- +template +QVector CorrectPathDistortion(QVector path) +{ + if (path.size() < 3) + { + return path; + } + + int prev = -1; + for (qint32 i = 0; i < path.size(); ++i) + { + if (prev == -1) + { + i == 0 ? prev = path.size() - 1 : prev = i-1; + } + + int next = i+1; + if (i == path.size() - 1) + { + next = 0; + } + + const QPointF &iPoint = path.at(i); + const QPointF &prevPoint = path.at(prev); + const QPointF &nextPoint = path.at(next); + + if (VGObject::IsPointOnLineSegment(iPoint, prevPoint, nextPoint)) + { + const QPointF p = VGObject::CorrectDistortion(iPoint, prevPoint, nextPoint); + path[i].setX(p.x()); + path[i].setY(p.y()); + } + } + + return path; +} } // Friend functions diff --git a/src/libs/vlayout/vabstractpiece.h b/src/libs/vlayout/vabstractpiece.h index 7ef859e5f..356cc8e02 100644 --- a/src/libs/vlayout/vabstractpiece.h +++ b/src/libs/vlayout/vabstractpiece.h @@ -44,6 +44,8 @@ class VAbstractPieceData; class QPainterPath; class VGrainlineData; class VContainer; +enum class LayoutGravity : qint8; +enum class CuttingTime : unsigned char; QT_WARNING_PUSH QT_WARNING_DISABLE_GCC("-Weffc++") @@ -223,9 +225,6 @@ public: static QLineF ParallelLine(const VSAPoint &p1, const VSAPoint &p2, qreal width); static bool IsAllowanceValid(const QVector &base, const QVector &allowance); - template - static QVector CorrectPathDistortion(QVector path); - template static QVector CorrectEquidistantPoints(const QVector &points, bool removeFirstAndLast = true); @@ -254,44 +253,6 @@ private: Q_DECLARE_TYPEINFO(VAbstractPiece, Q_MOVABLE_TYPE); -//--------------------------------------------------------------------------------------------------------------------- -template -QVector VAbstractPiece::CorrectPathDistortion(QVector path) -{ - if (path.size() < 3) - { - return path; - } - - int prev = -1; - for (qint32 i = 0; i < path.size(); ++i) - { - if (prev == -1) - { - i == 0 ? prev = path.size() - 1 : prev = i-1; - } - - int next = i+1; - if (i == path.size() - 1) - { - next = 0; - } - - const QPointF &iPoint = path.at(i); - const QPointF &prevPoint = path.at(prev); - const QPointF &nextPoint = path.at(next); - - if (VGObject::IsPointOnLineSegment(iPoint, prevPoint, nextPoint)) - { - const QPointF p = VGObject::CorrectDistortion(iPoint, prevPoint, nextPoint); - path[i].setX(p.x()); - path[i].setY(p.y()); - } - } - - return path; -} - //--------------------------------------------------------------------------------------------------------------------- /** * @brief CorrectEquidistantPoints clear equivalent points and remove point on line from equdistant. diff --git a/src/libs/vlayout/vbank.cpp b/src/libs/vlayout/vbank.cpp index df9ef89f0..aeef4f4cd 100644 --- a/src/libs/vlayout/vbank.cpp +++ b/src/libs/vlayout/vbank.cpp @@ -34,6 +34,8 @@ #include "../vmisc/vabstractapplication.h" #include "vlayoutpiece.h" #include "vlayoutdef.h" +#include "../ifc/exception/vexception.h" +#include "../vpatterndb/floatItemData/floatitemdef.h" QT_WARNING_PUSH QT_WARNING_DISABLE_CLANG("-Wmissing-prototypes") diff --git a/src/libs/vlayout/vbank.h b/src/libs/vlayout/vbank.h index cef34eb67..a47281151 100644 --- a/src/libs/vlayout/vbank.h +++ b/src/libs/vlayout/vbank.h @@ -34,6 +34,7 @@ #include #include #include +#include #include "../vmisc/typedef.h" @@ -45,6 +46,8 @@ #undef small #endif +Q_DECLARE_LOGGING_CATEGORY(lBank) + class VLayoutPiece; enum class Cases : char { CaseThreeGroup = 0, CaseTwoGroup, CaseDesc, UnknownCase}; diff --git a/src/libs/vlayout/vcontour.cpp b/src/libs/vlayout/vcontour.cpp index acb485904..eeaa9ce50 100644 --- a/src/libs/vlayout/vcontour.cpp +++ b/src/libs/vlayout/vcontour.cpp @@ -39,6 +39,8 @@ #include "vcontour_p.h" #include "vlayoutpiece.h" #include "../vmisc/vmath.h" +#include "../vgeometry/vgeometrydef.h" +#include "../vgeometry/vgobject.h" namespace { diff --git a/src/libs/vlayout/vlayoutpiece.cpp b/src/libs/vlayout/vlayoutpiece.cpp index d31b815ba..01b4e2075 100644 --- a/src/libs/vlayout/vlayoutpiece.cpp +++ b/src/libs/vlayout/vlayoutpiece.cpp @@ -49,6 +49,7 @@ #include "../vpatterndb/floatItemData/vpiecelabeldata.h" #include "../vmisc/vmath.h" #include "../vmisc/vabstractapplication.h" +#include "../vpatterndb/vcontainer.h" #include "../vpatterndb/calculator.h" #include "../vpatterndb/vpassmark.h" #include "../vpatterndb/vpiecenode.h" diff --git a/src/libs/vlayout/vlayoutpiece.h b/src/libs/vlayout/vlayoutpiece.h index 63047275e..6dbc74f44 100644 --- a/src/libs/vlayout/vlayoutpiece.h +++ b/src/libs/vlayout/vlayoutpiece.h @@ -40,19 +40,21 @@ #include #include #include +#include -#include "../ifc/xml/vabstractpattern.h" -#include "../vpatterndb/floatItemData/vpatternlabeldata.h" -#include "../vpatterndb/floatItemData/vpiecelabeldata.h" -#include "../vpatterndb/vcontainer.h" #include "vabstractpiece.h" -#include "../vgeometry/vgeometrydef.h" +#include "../vmisc/typedef.h" class VLayoutPieceData; class VLayoutPiecePath; class QGraphicsItem; class QGraphicsPathItem; class VTextManager; +class VPiece; +class VPieceLabelData; +class VAbstractPattern; +class VPatternLabelData; +enum class ArrowType : char; class VLayoutPiece :public VAbstractPiece { diff --git a/src/libs/vlayout/vposition.cpp b/src/libs/vlayout/vposition.cpp index a75afa327..053a6a4fb 100644 --- a/src/libs/vlayout/vposition.cpp +++ b/src/libs/vlayout/vposition.cpp @@ -49,6 +49,8 @@ #include "../vmisc/def.h" #include "../vmisc/vmath.h" +#include "../ifc/exception/vexception.h" +#include "../vpatterndb/floatItemData/floatitemdef.h" #if QT_VERSION < QT_VERSION_CHECK(5, 12, 0) #include "../vmisc/backport/qscopeguard.h" diff --git a/src/libs/vmisc/vcommonsettings.h b/src/libs/vmisc/vcommonsettings.h index f39abff44..0cea45cf2 100644 --- a/src/libs/vmisc/vcommonsettings.h +++ b/src/libs/vmisc/vcommonsettings.h @@ -38,8 +38,6 @@ #include #include -#include "../vlayout/vbank.h" - class VCommonSettings : public QSettings { Q_OBJECT diff --git a/src/libs/vmisc/vsettings.cpp b/src/libs/vmisc/vsettings.cpp index 23b2294c5..bad24291a 100644 --- a/src/libs/vmisc/vsettings.cpp +++ b/src/libs/vmisc/vsettings.cpp @@ -43,6 +43,7 @@ #include "../vmisc/def.h" #include "../vmisc/vmath.h" +#include "../vlayout/vbank.h" Q_DECLARE_METATYPE(QMarginsF) @@ -123,6 +124,30 @@ VSettings::VSettings(Format format, Scope scope, const QString &organization, co qRegisterMetaTypeStreamOperators("QMarginsF"); } +//--------------------------------------------------------------------------------------------------------------------- +template +inline T VSettings::ValueOrDef(const QString &setting, const T &defValue) const +{ + const QVariant val = value(setting, QVariant::fromValue(defValue)); + return val.canConvert() ? val.value() : defValue; +} + +//--------------------------------------------------------------------------------------------------------------------- +template <> +inline Cases VSettings::ValueOrDef(const QString &setting, const Cases &defValue) const +{ + const QVariant val = value(setting, QVariant::fromValue(static_cast(defValue))); + const int g = val.canConvert() ? val.value() : static_cast(defValue); + if (g < static_cast(Cases::CaseThreeGroup) || g >= static_cast(Cases::UnknownCase)) + { + return defValue; + } + else + { + return static_cast(g); + } +} + //--------------------------------------------------------------------------------------------------------------------- QString VSettings::GetLabelLanguage() const { @@ -138,7 +163,7 @@ void VSettings::SetLabelLanguage(const QString &value) //--------------------------------------------------------------------------------------------------------------------- QString VSettings::GetDefPathLayout() { - return QDir::homePath() + QLatin1String("/valentina/") + tr("layouts"); + return QDir::homePath() + QStringLiteral("/valentina/") + tr("layouts"); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vmisc/vsettings.h b/src/libs/vmisc/vsettings.h index 1d92ecbc7..85a4e22f6 100644 --- a/src/libs/vmisc/vsettings.h +++ b/src/libs/vmisc/vsettings.h @@ -36,11 +36,12 @@ #include #include -#include "../vmisc/def.h" -#include "../vlayout/vbank.h" #include "vcommonsettings.h" template class QSharedPointer; +enum class Cases : char; +enum class Unit : char; +enum class PageOrientation : bool; class VSettings : public VCommonSettings { @@ -187,28 +188,4 @@ private: T ValueOrDef(const QString &setting, const T &defValue) const; }; -//--------------------------------------------------------------------------------------------------------------------- -template -inline T VSettings::ValueOrDef(const QString &setting, const T &defValue) const -{ - const QVariant val = value(setting, QVariant::fromValue(defValue)); - return val.canConvert() ? val.value() : defValue; -} - -//--------------------------------------------------------------------------------------------------------------------- -template <> -inline Cases VSettings::ValueOrDef(const QString &setting, const Cases &defValue) const -{ - const QVariant val = value(setting, QVariant::fromValue(static_cast(defValue))); - const int g = val.canConvert() ? val.value() : static_cast(defValue); - if (g < static_cast(Cases::CaseThreeGroup) || g >= static_cast(Cases::UnknownCase)) - { - return defValue; - } - else - { - return static_cast(g); - } -} - #endif // VSETTINGS_H diff --git a/src/libs/vtools/tools/vtoolseamallowance.cpp b/src/libs/vtools/tools/vtoolseamallowance.cpp index 1f4fa1c9e..79d4d620e 100644 --- a/src/libs/vtools/tools/vtoolseamallowance.cpp +++ b/src/libs/vtools/tools/vtoolseamallowance.cpp @@ -54,6 +54,7 @@ #include "../vwidgets/vnobrushscalepathitem.h" #include "../vwidgets/vabstractmainwindow.h" #include "../qmuparser/qmutokenparser.h" +#include "../vlayout/vlayoutdef.h" #include #include