From 36704cd02ed263f131ebf08dabbc9fe1d6374c3b Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Wed, 25 Nov 2015 15:45:38 +0200 Subject: [PATCH] Invisible "VSimpleCurve" causes exponential growth scene size, and it causes the program crash. Because we don't need anymore this calss i just have removed it. --HG-- branch : develop --- .../core/vtooloptionspropertybrowser.cpp | 4 - src/libs/vgeometry/vgobject.cpp | 2 +- src/libs/vmisc/def.h | 1 - .../toolsinglepoint/toolcut/vtoolcut.cpp | 31 +---- .../toolsinglepoint/toolcut/vtoolcut.h | 11 -- .../toolsinglepoint/toolcut/vtoolcutarc.cpp | 38 ------ .../toolsinglepoint/toolcut/vtoolcutarc.h | 4 - .../toolcut/vtoolcutspline.cpp | 38 ------ .../toolsinglepoint/toolcut/vtoolcutspline.h | 4 - .../toolcut/vtoolcutsplinepath.cpp | 40 ------ .../toolcut/vtoolcutsplinepath.h | 4 - .../toolsinglepoint/vtoolbasepoint.cpp | 18 ++- src/libs/vtools/undocommands/movedetail.cpp | 6 - .../vtools/undocommands/movedoublelabel.cpp | 3 - src/libs/vtools/undocommands/movelabel.cpp | 3 - src/libs/vtools/undocommands/movespline.cpp | 3 - .../vtools/undocommands/movesplinepath.cpp | 3 - src/libs/vtools/undocommands/movespoint.cpp | 3 - .../vtools/undocommands/savedetailoptions.cpp | 6 - src/libs/vtools/visualization/visline.cpp | 10 ++ .../vtools/visualization/visualization.cpp | 1 + src/libs/vwidgets/vcontrolpointspline.cpp | 14 +- src/libs/vwidgets/vgraphicssimpletextitem.cpp | 12 +- src/libs/vwidgets/vmaingraphicsview.cpp | 37 +++-- src/libs/vwidgets/vsimplecurve.cpp | 128 ------------------ src/libs/vwidgets/vsimplecurve.h | 78 ----------- src/libs/vwidgets/vwidgets.pri | 2 - 27 files changed, 64 insertions(+), 440 deletions(-) delete mode 100644 src/libs/vwidgets/vsimplecurve.cpp delete mode 100644 src/libs/vwidgets/vsimplecurve.h diff --git a/src/app/valentina/core/vtooloptionspropertybrowser.cpp b/src/app/valentina/core/vtooloptionspropertybrowser.cpp index 835145765..4d55e4cbf 100644 --- a/src/app/valentina/core/vtooloptionspropertybrowser.cpp +++ b/src/app/valentina/core/vtooloptionspropertybrowser.cpp @@ -146,10 +146,6 @@ void VToolOptionsPropertyBrowser::ShowItemOptions(QGraphicsItem *item) currentItem = item->parentItem(); ShowItemOptions(currentItem); break; - case VSimpleCurve::Type: - currentItem = item->parentItem(); - ShowItemOptions(currentItem); - break; case VToolLineIntersectAxis::Type: ShowOptionsToolLineIntersectAxis(item); break; diff --git a/src/libs/vgeometry/vgobject.cpp b/src/libs/vgeometry/vgobject.cpp index 69dd3574c..9d035d96d 100644 --- a/src/libs/vgeometry/vgobject.cpp +++ b/src/libs/vgeometry/vgobject.cpp @@ -185,7 +185,7 @@ QLineF VGObject::BuildLine(const QPointF &p1, const qreal &length, const qreal & { QLineF line = QLineF(); line.setP1(p1); - line.setAngle(angle);// First set angle than length. Length can have negative value. + line.setAngle(angle);// First set angle then length. Length can have negative value. line.setLength(length); return line; } diff --git a/src/libs/vmisc/def.h b/src/libs/vmisc/def.h index a8096f8d4..16fd1e99d 100644 --- a/src/libs/vmisc/def.h +++ b/src/libs/vmisc/def.h @@ -103,7 +103,6 @@ enum class Vis : ToolVisHolderType { ControlPointSpline = static_cast(Tool::LAST_ONE_DO_NOT_USE), GraphicsSimpleTextItem, - SimpleSplinePath, SimplePoint, Line, Path, diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcut.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcut.cpp index e5a4ee6a6..96e04acb5 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcut.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcut.cpp @@ -34,7 +34,7 @@ VToolCut::VToolCut(VAbstractPattern *doc, VContainer *data, const quint32 &id, const QString &formula, const quint32 &curveCutId, const quint32 &curve1id, const quint32 &curve2id, const QString &color, QGraphicsItem *parent) - :VToolSinglePoint(doc, data, id, parent), formula(formula), firstCurve(nullptr), secondCurve(nullptr), + :VToolSinglePoint(doc, data, id, parent), formula(formula), curveCutId(curveCutId), curve1id(curve1id), curve2id(curve2id), detailsMode(false) { Q_ASSERT_X(curveCutId != 0, Q_FUNC_INFO, "curveCutId == 0"); //-V654 //-V712 @@ -42,39 +42,12 @@ VToolCut::VToolCut(VAbstractPattern *doc, VContainer *data, const quint32 &id, c Q_ASSERT_X(curve2id != 0, Q_FUNC_INFO, "curve2id == 0"); //-V654 //-V712 lineColor = color; - - firstCurve = new VSimpleCurve(curve1id, QColor(lineColor), SimpleCurvePoint::ForthPoint, *data->GetPatternUnit(), - &factor); - firstCurve->setParentItem(this); - connect(firstCurve, &VSimpleCurve::Choosed, this, &VToolCut::CurveChoosed); - connect(firstCurve, &VSimpleCurve::HoverPath, this, &VToolCut::HoverPath); - // TODO: Now we only hide simple curves, but in future need totally delete them all. - firstCurve->setVisible(false); - - secondCurve = new VSimpleCurve(curve2id, QColor(lineColor), SimpleCurvePoint::FirstPoint, *data->GetPatternUnit(), - &factor); - secondCurve->setParentItem(this); - connect(secondCurve, &VSimpleCurve::Choosed, this, &VToolCut::CurveChoosed); - connect(secondCurve, &VSimpleCurve::HoverPath, this, &VToolCut::HoverPath); - secondCurve->setVisible(false); -} - -//--------------------------------------------------------------------------------------------------------------------- -void VToolCut::HoverPath(quint32 id, SimpleCurvePoint curvePosition, PathDirection direction) -{ - VSimpleCurve* simpleCurve = qobject_cast(sender()); - if (simpleCurve) - { - RefreshCurve(simpleCurve, id, curvePosition, direction); - } } //--------------------------------------------------------------------------------------------------------------------- void VToolCut::Disable(bool disable, const QString &namePP) { VToolSinglePoint::Disable(disable, namePP); - firstCurve->ChangedActivDraw(enabled); - secondCurve->ChangedActivDraw(enabled); } //--------------------------------------------------------------------------------------------------------------------- @@ -141,8 +114,6 @@ void VToolCut::SetFormula(const VFormula &value) */ void VToolCut::RefreshGeometry() { - RefreshCurve(firstCurve, curve1id, SimpleCurvePoint::ForthPoint); - RefreshCurve(secondCurve, curve2id, SimpleCurvePoint::FirstPoint); VToolSinglePoint::RefreshPointGeometry(*VDrawTool::data.GeometricObject(id)); } diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcut.h b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcut.h index 42a882e23..b221d232d 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcut.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcut.h @@ -30,7 +30,6 @@ #define VTOOLCUT_H #include "../vtoolsinglepoint.h" -#include "../vwidgets/vsimplecurve.h" #include "../../../toolcurve/vabstractspline.h" class VFormula; @@ -52,8 +51,6 @@ public: void setCurveCutId(const quint32 &value); public slots: - virtual void CurveChoosed(quint32 id)=0; - void HoverPath(quint32 id, SimpleCurvePoint curvePosition, PathDirection direction); virtual void Disable(bool disable, const QString &namePP) Q_DECL_OVERRIDE; void DetailsMode(bool mode); virtual void FullUpdateFromFile() Q_DECL_OVERRIDE; @@ -61,20 +58,12 @@ protected: /** @brief formula keep formula of length */ QString formula; - /** @brief firstCurve first curve after cutting. */ - VSimpleCurve *firstCurve; - - /** @brief secondCurve second curve after cutting. */ - VSimpleCurve *secondCurve; - quint32 curveCutId; quint32 curve1id; quint32 curve2id; bool detailsMode; - virtual void RefreshCurve(VSimpleCurve *curve, quint32 curveId, SimpleCurvePoint curvePosition, - PathDirection direction = PathDirection::Hide)=0; void RefreshGeometry(); virtual void RemoveReferens() Q_DECL_OVERRIDE; void FullUpdateCurveFromFile(const QString &attrCurve); diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutarc.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutarc.cpp index 5ec0fba65..fda07b74b 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutarc.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutarc.cpp @@ -54,9 +54,6 @@ VToolCutArc::VToolCutArc(VAbstractPattern *doc, VContainer *data, const quint32 const Source &typeCreation, QGraphicsItem * parent) :VToolCut(doc, data, id, formula, arcId, arc1id, arc2id, color, parent) { - RefreshCurve(firstCurve, curve1id, SimpleCurvePoint::ForthPoint); - RefreshCurve(secondCurve, curve2id, SimpleCurvePoint::FirstPoint); - ToolCreation(typeCreation); } @@ -185,16 +182,6 @@ void VToolCutArc::ShowVisualization(bool show) ShowToolVisualization(show); } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief CurveChoosed send signal about selection from cutted arc. - * @param id object id in container. - */ -void VToolCutArc::CurveChoosed(quint32 id) -{ - emit ChoosedTool(id, SceneObject::Arc); -} - //--------------------------------------------------------------------------------------------------------------------- /** * @brief contextMenuEvent handle context menu events. @@ -228,31 +215,6 @@ void VToolCutArc::SaveDialog(QDomElement &domElement) doc->SetAttribute(domElement, AttrColor, dialogTool->GetColor()); } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief RefreshCurve refresh curve on scene. - * @param curve curve. - * @param curveId curve id. - */ -void VToolCutArc::RefreshCurve(VSimpleCurve *curve, quint32 curveId, SimpleCurvePoint curvePosition, - PathDirection direction) -{ - const QSharedPointer arc = VAbstractTool::data.GeometricObject(curveId); - QPainterPath path; - path.addPath(arc->GetPath(direction)); - path.setFillRule( Qt::WindingFill ); - if (curvePosition == SimpleCurvePoint::FirstPoint) - { - path.translate(-arc->GetP1().x(), -arc->GetP1().y()); - } - else - { - path.translate(-arc->GetP2().x(), -arc->GetP2().y()); - } - curve->SetCurrentColor(QColor(lineColor)); - curve->setPath(path); -} - //--------------------------------------------------------------------------------------------------------------------- void VToolCutArc::SaveOptions(QDomElement &tag, QSharedPointer &obj) { diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutarc.h b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutarc.h index 7178a313e..3900fe74f 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutarc.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutarc.h @@ -52,13 +52,9 @@ public: virtual int type() const Q_DECL_OVERRIDE {return Type;} enum { Type = UserType + static_cast(Tool::CutArc)}; virtual void ShowVisualization(bool show) Q_DECL_OVERRIDE; -public slots: - virtual void CurveChoosed(quint32 id) Q_DECL_OVERRIDE; protected: virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ) Q_DECL_OVERRIDE; virtual void SaveDialog(QDomElement &domElement) Q_DECL_OVERRIDE; - virtual void RefreshCurve(VSimpleCurve *curve, quint32 curveId, SimpleCurvePoint curvePosition, - PathDirection direction = PathDirection::Hide) Q_DECL_OVERRIDE; virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj) Q_DECL_OVERRIDE; virtual void ReadToolAttributes(const QDomElement &domElement) Q_DECL_OVERRIDE; virtual void SetVisualization() Q_DECL_OVERRIDE; diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutspline.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutspline.cpp index c1ffb392b..fcded45df 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutspline.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutspline.cpp @@ -53,9 +53,6 @@ VToolCutSpline::VToolCutSpline(VAbstractPattern *doc, VContainer *data, const qu const QString &color, const Source &typeCreation, QGraphicsItem *parent) :VToolCut(doc, data, id, formula, splineId, spl1id, spl2id, color, parent) { - RefreshCurve(firstCurve, curve1id, SimpleCurvePoint::ForthPoint); - RefreshCurve(secondCurve, curve2id, SimpleCurvePoint::FirstPoint); - ToolCreation(typeCreation); } @@ -193,16 +190,6 @@ void VToolCutSpline::ShowVisualization(bool show) ShowToolVisualization(show); } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief CurveChoosed send signal about selection from spline. - * @param id object id in container. - */ -void VToolCutSpline::CurveChoosed(quint32 id) -{ - emit ChoosedTool(id, SceneObject::Spline); -} - //--------------------------------------------------------------------------------------------------------------------- /** * @brief contextMenuEvent handle context menu events. @@ -236,31 +223,6 @@ void VToolCutSpline::SaveDialog(QDomElement &domElement) doc->SetAttribute(domElement, AttrColor, dialogTool->GetColor()); } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief RefreshCurve refresh curve on scene. - * @param curve curve. - * @param curveId curve id. - */ -void VToolCutSpline::RefreshCurve(VSimpleCurve *curve, quint32 curveId, SimpleCurvePoint curvePosition, - PathDirection direction) -{ - const QSharedPointer spl = VAbstractTool::data.GeometricObject(curveId); - QPainterPath path; - path.addPath(spl->GetPath(direction)); - path.setFillRule( Qt::WindingFill ); - if (curvePosition == SimpleCurvePoint::FirstPoint) - { - path.translate(-spl->GetP1().toQPointF().x(), -spl->GetP1().toQPointF().y()); - } - else - { - path.translate(-spl->GetP4().toQPointF().x(), -spl->GetP4().toQPointF().y()); - } - curve->SetCurrentColor(QColor(lineColor)); - curve->setPath(path); -} - //--------------------------------------------------------------------------------------------------------------------- void VToolCutSpline::SaveOptions(QDomElement &tag, QSharedPointer &obj) { diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutspline.h b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutspline.h index c3924192b..f29a1f4f2 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutspline.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutspline.h @@ -55,13 +55,9 @@ public: virtual int type() const Q_DECL_OVERRIDE {return Type;} enum { Type = UserType + static_cast(Tool::CutSpline)}; virtual void ShowVisualization(bool show) Q_DECL_OVERRIDE; -public slots: - virtual void CurveChoosed(quint32 id) Q_DECL_OVERRIDE; protected: virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ) Q_DECL_OVERRIDE; virtual void SaveDialog(QDomElement &domElement) Q_DECL_OVERRIDE; - virtual void RefreshCurve(VSimpleCurve *curve, quint32 curveId, SimpleCurvePoint curvePosition, - PathDirection direction = PathDirection::Hide) Q_DECL_OVERRIDE; virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj) Q_DECL_OVERRIDE; virtual void ReadToolAttributes(const QDomElement &domElement) Q_DECL_OVERRIDE; virtual void SetVisualization() Q_DECL_OVERRIDE; diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutsplinepath.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutsplinepath.cpp index 3f611b0a2..3b659e0c4 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutsplinepath.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutsplinepath.cpp @@ -56,9 +56,6 @@ VToolCutSplinePath::VToolCutSplinePath(VAbstractPattern *doc, VContainer *data, const Source &typeCreation, QGraphicsItem *parent) :VToolCut(doc, data, id, formula, splinePathId, splPath1id, splPath2id, color, parent) { - RefreshCurve(firstCurve, curve1id, SimpleCurvePoint::ForthPoint); - RefreshCurve(secondCurve, curve2id, SimpleCurvePoint::FirstPoint); - ToolCreation(typeCreation); } @@ -237,16 +234,6 @@ void VToolCutSplinePath::ShowVisualization(bool show) ShowToolVisualization(show); } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief CurveChoosed send signal about selection splinePath. - * @param id object id in container. - */ -void VToolCutSplinePath::CurveChoosed(quint32 id) -{ - emit ChoosedTool(id, SceneObject::SplinePath); -} - //--------------------------------------------------------------------------------------------------------------------- /** * @brief contextMenuEvent handle context menu events. @@ -280,33 +267,6 @@ void VToolCutSplinePath::SaveDialog(QDomElement &domElement) doc->SetAttribute(domElement, AttrColor, dialogTool->GetColor()); } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief RefreshCurve refresh curve on scene. - * @param curve curve. - * @param curveId curve id. - */ -void VToolCutSplinePath::RefreshCurve(VSimpleCurve *curve, quint32 curveId, SimpleCurvePoint curvePosition, - PathDirection direction) -{ - const QSharedPointer splPath = VAbstractTool::data.GeometricObject(curveId); - QPainterPath path; - path.addPath(splPath->GetPath(direction)); - path.setFillRule( Qt::WindingFill ); - if (curvePosition == SimpleCurvePoint::FirstPoint) - { - VSpline spl = splPath->GetSpline(1); - path.translate(-spl.GetP1().toQPointF().x(), -spl.GetP1().toQPointF().y()); - } - else - { - VSpline spl = splPath->GetSpline(splPath->Count()); - path.translate(-spl.GetP4().toQPointF().x(), -spl.GetP4().toQPointF().y()); - } - curve->SetCurrentColor(QColor(lineColor)); - curve->setPath(path); -} - //--------------------------------------------------------------------------------------------------------------------- void VToolCutSplinePath::SaveOptions(QDomElement &tag, QSharedPointer &obj) { diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutsplinepath.h b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutsplinepath.h index b44935fbf..040c271a4 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutsplinepath.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutsplinepath.h @@ -56,13 +56,9 @@ public: virtual int type() const Q_DECL_OVERRIDE {return Type;} enum { Type = UserType + static_cast(Tool::CutSplinePath)}; virtual void ShowVisualization(bool show) Q_DECL_OVERRIDE; -public slots: - virtual void CurveChoosed(quint32 id) Q_DECL_OVERRIDE; protected: virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ) Q_DECL_OVERRIDE; virtual void SaveDialog(QDomElement &domElement) Q_DECL_OVERRIDE; - virtual void RefreshCurve(VSimpleCurve *curve, quint32 curveId, SimpleCurvePoint curvePosition, - PathDirection direction = PathDirection::Hide) Q_DECL_OVERRIDE; virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj) Q_DECL_OVERRIDE; virtual void ReadToolAttributes(const QDomElement &domElement) Q_DECL_OVERRIDE; virtual void SetVisualization() Q_DECL_OVERRIDE; diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolbasepoint.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolbasepoint.cpp index d9f376e55..6446f41ce 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolbasepoint.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolbasepoint.cpp @@ -141,12 +141,20 @@ QVariant VToolBasePoint::itemChange(QGraphicsItem::GraphicsItemChange change, co } if (change == ItemPositionHasChanged && scene()) { - // value - this is new position. - QPointF newPos = value.toPointF(); + // Each time we move something we call recalculation scene rect. In some cases this can cause moving + // objects positions. And this cause infinite redrawing. That's why we wait the finish of saving the last move. + static bool changeFinished = true; + if (changeFinished) + { + changeFinished = false; + // value - this is new position. + QPointF newPos = value.toPointF(); - MoveSPoint *moveSP = new MoveSPoint(doc, newPos.x(), newPos.y(), id, this->scene()); - connect(moveSP, &MoveSPoint::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree); - qApp->getUndoStack()->push(moveSP); + MoveSPoint *moveSP = new MoveSPoint(doc, newPos.x(), newPos.y(), id, this->scene()); + connect(moveSP, &MoveSPoint::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree); + qApp->getUndoStack()->push(moveSP); + changeFinished = true; + } } return QGraphicsItem::itemChange(change, value); } diff --git a/src/libs/vtools/undocommands/movedetail.cpp b/src/libs/vtools/undocommands/movedetail.cpp index 814a1b16b..87e15a4f1 100644 --- a/src/libs/vtools/undocommands/movedetail.cpp +++ b/src/libs/vtools/undocommands/movedetail.cpp @@ -70,9 +70,6 @@ void MoveDetail::undo() SaveCoordinates(domElement, oldX, oldY); emit NeedLiteParsing(Document::LiteParse); - - QList list = scene->views(); - VMainGraphicsView::NewSceneRect(scene, list[0]); } else { @@ -96,9 +93,6 @@ void MoveDetail::redo() emit NeedLiteParsing(Document::LiteParse); } redoFlag = true; - - QList list = scene->views(); - VMainGraphicsView::NewSceneRect(scene, list[0]); } else { diff --git a/src/libs/vtools/undocommands/movedoublelabel.cpp b/src/libs/vtools/undocommands/movedoublelabel.cpp index 67f8c5f2e..c6ae63de9 100644 --- a/src/libs/vtools/undocommands/movedoublelabel.cpp +++ b/src/libs/vtools/undocommands/movedoublelabel.cpp @@ -178,9 +178,6 @@ void MoveDoubleLabel::Do(double mx, double my) } emit NeedLiteParsing(Document::LitePPParse); - - QList list = scene->views(); - VMainGraphicsView::NewSceneRect(scene, list[0]); } else { diff --git a/src/libs/vtools/undocommands/movelabel.cpp b/src/libs/vtools/undocommands/movelabel.cpp index a26090288..e841c858f 100644 --- a/src/libs/vtools/undocommands/movelabel.cpp +++ b/src/libs/vtools/undocommands/movelabel.cpp @@ -121,9 +121,6 @@ void MoveLabel::Do(double mx, double my) doc->SetAttribute(domElement, AttrMy, QString().setNum(qApp->fromPixel(my))); emit NeedLiteParsing(Document::LitePPParse); - - QList list = scene->views(); - VMainGraphicsView::NewSceneRect(scene, list[0]); } else { diff --git a/src/libs/vtools/undocommands/movespline.cpp b/src/libs/vtools/undocommands/movespline.cpp index 85b69438b..f19650e0e 100644 --- a/src/libs/vtools/undocommands/movespline.cpp +++ b/src/libs/vtools/undocommands/movespline.cpp @@ -99,9 +99,6 @@ void MoveSpline::Do(const VSpline &spl) doc->SetAttribute(domElement, AttrKCurve, QString().setNum(spl.GetKcurve())); emit NeedLiteParsing(Document::LiteParse); - - QList list = scene->views(); - VMainGraphicsView::NewSceneRect(scene, list[0]); } else { diff --git a/src/libs/vtools/undocommands/movesplinepath.cpp b/src/libs/vtools/undocommands/movesplinepath.cpp index 142e871e3..398ed9605 100644 --- a/src/libs/vtools/undocommands/movesplinepath.cpp +++ b/src/libs/vtools/undocommands/movesplinepath.cpp @@ -93,9 +93,6 @@ void MoveSplinePath::Do(const VSplinePath &splPath) VToolSplinePath::UpdatePathPoint(doc, domElement, splPath); emit NeedLiteParsing(Document::LiteParse); - - QList list = scene->views(); - VMainGraphicsView::NewSceneRect(scene, list[0]); } else { diff --git a/src/libs/vtools/undocommands/movespoint.cpp b/src/libs/vtools/undocommands/movespoint.cpp index fb34714b6..881e33b94 100644 --- a/src/libs/vtools/undocommands/movespoint.cpp +++ b/src/libs/vtools/undocommands/movespoint.cpp @@ -123,9 +123,6 @@ void MoveSPoint::Do(double x, double y) doc->SetAttribute(domElement, AttrY, QString().setNum(qApp->fromPixel(y))); emit NeedLiteParsing(Document::LitePPParse); - - QList list = scene->views(); - VMainGraphicsView::NewSceneRect(scene, list[0]); } else { diff --git a/src/libs/vtools/undocommands/savedetailoptions.cpp b/src/libs/vtools/undocommands/savedetailoptions.cpp index 9c6c7da53..7c77c99d9 100644 --- a/src/libs/vtools/undocommands/savedetailoptions.cpp +++ b/src/libs/vtools/undocommands/savedetailoptions.cpp @@ -71,9 +71,6 @@ void SaveDetailOptions::undo() } } emit NeedLiteParsing(Document::LiteParse); - - QList list = scene->views(); - VMainGraphicsView::NewSceneRect(scene, list[0]); } else { @@ -108,9 +105,6 @@ void SaveDetailOptions::redo() } } emit NeedLiteParsing(Document::LiteParse); - - QList listV = scene->views(); - VMainGraphicsView::NewSceneRect(scene, listV[0]); } else { diff --git a/src/libs/vtools/visualization/visline.cpp b/src/libs/vtools/visualization/visline.cpp index 1c20b5165..86bd79cd2 100644 --- a/src/libs/vtools/visualization/visline.cpp +++ b/src/libs/vtools/visualization/visline.cpp @@ -85,6 +85,16 @@ QPointF VisLine::Ray(const QPointF &firstPoint, const qreal &angle) const } QRectF scRect = this->scene()->sceneRect(); + + //Limit size of the scene rect. Axis that has same size as scene rect cause scene size growth. + QLineF line1 = QLineF(scRect.topLeft(), scRect.bottomRight()); + line1.setLength(20); + + QLineF line2 = QLineF(scRect.bottomRight(), scRect.topLeft()); + line2.setLength(20); + + scRect = QRectF(line1.p2(), line2.p2()); + if (QGuiApplication::keyboardModifiers() == Qt::ShiftModifier) { return VGObject::BuildRay(firstPoint, CorrectAngle(angle), scRect); diff --git a/src/libs/vtools/visualization/visualization.cpp b/src/libs/vtools/visualization/visualization.cpp index 1c11267ad..18203df56 100644 --- a/src/libs/vtools/visualization/visualization.cpp +++ b/src/libs/vtools/visualization/visualization.cpp @@ -112,6 +112,7 @@ QGraphicsEllipseItem *Visualization::InitPoint(const QColor &color, QGraphicsIte point->setBrush(QBrush(Qt::NoBrush)); point->setPen(QPen(color, qApp->toPixel(WidthMainLine(*Visualization::data->GetPatternUnit()))/factor)); point->setRect(PointRect(ToPixel(DefPointRadius/*mm*/, Unit::Mm))); + point->setPos(QPointF()); point->setFlags(QGraphicsItem::ItemStacksBehindParent); point->setVisible(false); return point; diff --git a/src/libs/vwidgets/vcontrolpointspline.cpp b/src/libs/vwidgets/vcontrolpointspline.cpp index 49f504573..d4ac1c088 100644 --- a/src/libs/vwidgets/vcontrolpointspline.cpp +++ b/src/libs/vwidgets/vcontrolpointspline.cpp @@ -120,9 +120,17 @@ QVariant VControlPointSpline::itemChange(QGraphicsItem::GraphicsItemChange chang { if (change == ItemPositionChange && scene()) { - // value - new position. - QPointF newPos = value.toPointF(); - emit ControlPointChangePosition(indexSpline, position, newPos); + // Each time we move something we call recalculation scene rect. In some cases this can cause moving + // objects positions. And this cause infinite redrawing. That's why we wait the finish of saving the last move. + static bool changeFinished = true; + if (changeFinished) + { + changeFinished = false; + // value - new position. + QPointF newPos = value.toPointF(); + emit ControlPointChangePosition(indexSpline, position, newPos); + changeFinished = false; + } } return QGraphicsItem::itemChange(change, value); } diff --git a/src/libs/vwidgets/vgraphicssimpletextitem.cpp b/src/libs/vwidgets/vgraphicssimpletextitem.cpp index a87aa40cd..963197bc4 100644 --- a/src/libs/vwidgets/vgraphicssimpletextitem.cpp +++ b/src/libs/vwidgets/vgraphicssimpletextitem.cpp @@ -115,8 +115,16 @@ QVariant VGraphicsSimpleTextItem::itemChange(GraphicsItemChange change, const QV { if (change == ItemPositionChange && scene()) { - QPointF newPos = value.toPointF() + this->parentItem()->pos(); - emit NameChangePosition(newPos); + // Each time we move something we call recalculation scene rect. In some cases this can cause moving + // objects positions. And this cause infinite redrawing. That's why we wait the finish of saving the last move. + static bool changeFinished = true; + if (changeFinished) + { + changeFinished = false; + QPointF newPos = value.toPointF() + this->parentItem()->pos(); + emit NameChangePosition(newPos); + changeFinished = true; + } } return QGraphicsItem::itemChange(change, value); } diff --git a/src/libs/vwidgets/vmaingraphicsview.cpp b/src/libs/vwidgets/vmaingraphicsview.cpp index 7c87b8516..db782fd14 100644 --- a/src/libs/vwidgets/vmaingraphicsview.cpp +++ b/src/libs/vwidgets/vmaingraphicsview.cpp @@ -32,7 +32,7 @@ #include #include #include -#include "vsimplecurve.h" +#include "vsimplepoint.h" #include #include @@ -211,6 +211,7 @@ void VMainGraphicsView::ZoomOriginal() trans.setMatrix(1.0, trans.m12(), trans.m13(), trans.m21(), 1.0, trans.m23(), trans.m31(), trans.m32(), trans.m33()); this->setTransform(trans); + VMainGraphicsView::NewSceneRect(this->scene(), this); emit NewFactor(1.0); } @@ -225,6 +226,7 @@ void VMainGraphicsView::ZoomFitBest() } this->fitInView(rect, Qt::KeepAspectRatio); + VMainGraphicsView::NewSceneRect(this->scene(), this); emit NewFactor(this->transform().m11()); } @@ -255,7 +257,7 @@ void VMainGraphicsView::mousePressEvent(QMouseEvent *mousePress) { if (this->scene()->items().contains(list.at(i))) { - if (list.at(i)->type() <= VSimpleCurve::Type && + if (list.at(i)->type() <= VSimplePoint::Type && list.at(i)->type() > QGraphicsItem::UserType) { emit itemClicked(list.at(i)); @@ -308,25 +310,20 @@ void VMainGraphicsView::NewSceneRect(QGraphicsScene *sc, QGraphicsView *view) SCASSERT(sc != nullptr); SCASSERT(view != nullptr); - const QRectF rect = sc->itemsBoundingRect(); - const QRect rec0 = QRect(0, 0, view->rect().width()-2, view->rect().height()-2); - const QTransform t = view->transform(); + //Calculate view rect + //to receive the currently visible area, map the widgets bounds to the scene + const QPointF a = view->mapToScene(0, 0 ); + const QPointF b = view->mapToScene(view->viewport()->width(), view->viewport()->height()); + const QRectF viewRect = QRectF( a, b ); - QRectF rec1; - if (t.m11() < 1) - { - const qreal width = rec0.width()/t.m11(); - const qreal height = rec0.height()/t.m22(); - rec1 = QRect(0, 0, static_cast(width), static_cast(height)); + //Calculate scene rect + const QRectF itemsRect = sc->itemsBoundingRect(); - rec1.translate(rec0.center().x()-rec1.center().x(), rec0.center().y()-rec1.center().y()); - const QPolygonF polygone = view->mapToScene(rec1.toRect()); - rec1 = polygone.boundingRect(); + //Unite two rects + const QRectF newRect = itemsRect.united(viewRect); + + if (newRect != itemsRect) + {//Update if only need + sc->setSceneRect(newRect); } - else - { - rec1 = rec0; - } - rec1 = rec1.united(rect.toRect()); - sc->setSceneRect(rec1); } diff --git a/src/libs/vwidgets/vsimplecurve.cpp b/src/libs/vwidgets/vsimplecurve.cpp deleted file mode 100644 index e63ce5ce7..000000000 --- a/src/libs/vwidgets/vsimplecurve.cpp +++ /dev/null @@ -1,128 +0,0 @@ -/************************************************************************ - ** - ** @file vsimplecurve.cpp - ** @author Roman Telezhynskyi - ** @date 17 12, 2013 - ** - ** @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-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 "vsimplecurve.h" -#include -#include -#include - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief VSimpleSpline constructor. - * @param id spline id. - * @param factor scene scale factor. - * @param currentColor current color. - * @param parent parent object. - */ -VSimpleCurve::VSimpleCurve(quint32 id, const QColor ¤tColor, SimpleCurvePoint pointPosition, Unit patternUnit, - qreal *factor, QObject *parent) - :VAbstractSimple(id, currentColor, patternUnit, factor, parent), QGraphicsPathItem(), curvePosition(pointPosition) -{ - SetPen(this, currentColor, WidthHairLine(patternUnit)); - setFlag(QGraphicsItem::ItemIsSelectable, true); - setAcceptHoverEvents(true); -} - -//--------------------------------------------------------------------------------------------------------------------- -void VSimpleCurve::ChangedActivDraw(const bool &flag) -{ - enabled = flag; - setEnabled(enabled); - SetPen(this, currentColor, WidthHairLine(patternUnit)); -} - -//--------------------------------------------------------------------------------------------------------------------- -void VSimpleCurve::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) -{ - /* From question on StackOverflow - * https://stackoverflow.com/questions/10985028/how-to-remove-border-around-qgraphicsitem-when-selected - * - * There's no interface to disable the drawing of the selection border for the build-in QGraphicsItems. The only way - * I can think of is derive your own items from the build-in ones and override the paint() function:*/ - QStyleOptionGraphicsItem myOption(*option); - myOption.state &= ~QStyle::State_Selected; - QGraphicsPathItem::paint(painter, &myOption, widget); -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief mouseReleaseEvent handle mouse release events. - * @param event mouse release event. - */ -void VSimpleCurve::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) -{ - if (event->button() == Qt::LeftButton) - { - emit Choosed(id); - } - QGraphicsPathItem::mouseReleaseEvent(event); -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief hoverEnterEvent handle hover enter events. - * @param event hover move event. - */ -void VSimpleCurve::hoverEnterEvent(QGraphicsSceneHoverEvent *event) -{ - Q_UNUSED(event); - SetPen(this, currentColor, WidthMainLine(patternUnit)); - emit HoverPath(id, curvePosition, PathDirection::Show); -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief hoverLeaveEvent handle hover leave events. - * @param event hover leave event. - */ -void VSimpleCurve::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) -{ - Q_UNUSED(event); - SetPen(this, currentColor, WidthHairLine(patternUnit)); - emit HoverPath(id, curvePosition, PathDirection::Hide); -} - -//--------------------------------------------------------------------------------------------------------------------- -void VSimpleCurve::mousePressEvent(QGraphicsSceneMouseEvent *event) -{ - event->ignore(); -} - -//--------------------------------------------------------------------------------------------------------------------- -// cppcheck-suppress unusedFunction -QColor VSimpleCurve::GetCurrentColor() const -{ - return currentColor; -} - -//--------------------------------------------------------------------------------------------------------------------- -void VSimpleCurve::SetCurrentColor(const QColor &value) -{ - currentColor = value; - SetPen(this, CorrectColor(currentColor), pen().widthF()); -} diff --git a/src/libs/vwidgets/vsimplecurve.h b/src/libs/vwidgets/vsimplecurve.h deleted file mode 100644 index 4803936a2..000000000 --- a/src/libs/vwidgets/vsimplecurve.h +++ /dev/null @@ -1,78 +0,0 @@ -/************************************************************************ - ** - ** @file vsimplecurve.h - ** @author Roman Telezhynskyi - ** @date 17 12, 2013 - ** - ** @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-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 VSIMPLECURVE_H -#define VSIMPLECURVE_H - -#include -#include "../vgeometry/vabstractcurve.h" -#include "vabstractsimple.h" - -enum class SimpleCurvePoint : char { FirstPoint, ForthPoint }; - -/** - * @brief The VSimpleSpline class for simple spline. This object used when we cut spline and want show peaces. - */ -class VSimpleCurve : public VAbstractSimple, public QGraphicsPathItem -{ - Q_OBJECT -public: - VSimpleCurve(quint32 id, const QColor ¤tColor, SimpleCurvePoint curvePosition, Unit patternUnit, - qreal *factor = nullptr, QObject *parent = 0); - virtual void ChangedActivDraw(const bool &flag) Q_DECL_OVERRIDE; - virtual void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, - QWidget * widget = 0) Q_DECL_OVERRIDE; - - virtual int type() const Q_DECL_OVERRIDE {return Type;} - enum { Type = UserType + static_cast(Vis::SimpleSplinePath)}; - - QColor GetCurrentColor() const; - void SetCurrentColor(const QColor &value); - -signals: - /** - * @brief Choosed send id when clicked. - * @param id spline id. - */ - void Choosed(quint32 id); - void HoverPath(quint32 id, SimpleCurvePoint curvePosition, PathDirection direction); -protected: - virtual void mousePressEvent(QGraphicsSceneMouseEvent * event) Q_DECL_OVERRIDE; - virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ) Q_DECL_OVERRIDE; - virtual void hoverEnterEvent ( QGraphicsSceneHoverEvent * event ) Q_DECL_OVERRIDE; - virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ) Q_DECL_OVERRIDE; -private: - Q_DISABLE_COPY(VSimpleCurve) - - - SimpleCurvePoint curvePosition; - - -}; - -#endif // VSIMPLECURVE_H diff --git a/src/libs/vwidgets/vwidgets.pri b/src/libs/vwidgets/vwidgets.pri index 8610902ad..f8798a032 100644 --- a/src/libs/vwidgets/vwidgets.pri +++ b/src/libs/vwidgets/vwidgets.pri @@ -4,7 +4,6 @@ SOURCES += \ $$PWD/vmaingraphicsscene.cpp \ $$PWD/vmaingraphicsview.cpp \ - $$PWD/vsimplecurve.cpp \ $$PWD/vwidgetpopup.cpp \ $$PWD/vcontrolpointspline.cpp \ $$PWD/vgraphicssimpletextitem.cpp \ @@ -17,7 +16,6 @@ HEADERS += \ $$PWD/stable.h \ $$PWD/vmaingraphicsscene.h \ $$PWD/vmaingraphicsview.h \ - $$PWD/vsimplecurve.h \ $$PWD/vwidgetpopup.h \ $$PWD/vcontrolpointspline.h \ $$PWD/vgraphicssimpletextitem.h \