From 4af32961b009c30b038d71f454e0e2144a02b991 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Fri, 27 Oct 2017 09:13:51 +0300 Subject: [PATCH] Optimize adjusting new scene rect. If we know an object that cause adjustment no need to recalc bounding rect for all scene items. --HG-- branch : develop --- src/app/valentina/mainwindow.cpp | 2 +- .../drawTools/toolcurve/vabstractspline.h | 4 +-- .../tools/drawTools/toolcurve/vtoolspline.cpp | 4 +-- .../drawTools/toolcurve/vtoolsplinepath.cpp | 4 +-- src/libs/vtools/tools/vtoolseamallowance.cpp | 2 +- src/libs/vtools/undocommands/addpiece.cpp | 10 +++++--- src/libs/vtools/undocommands/deletepiece.cpp | 5 +--- src/libs/vtools/undocommands/movepiece.cpp | 15 ++++++----- src/libs/vtools/undocommands/movespline.cpp | 2 -- .../vtools/undocommands/movesplinepath.cpp | 2 -- src/libs/vwidgets/vgraphicssimpletextitem.cpp | 7 ++---- src/libs/vwidgets/vmaingraphicsview.cpp | 25 ++++++++++++------- src/libs/vwidgets/vmaingraphicsview.h | 2 +- 13 files changed, 41 insertions(+), 43 deletions(-) diff --git a/src/app/valentina/mainwindow.cpp b/src/app/valentina/mainwindow.cpp index cae1e9574..a20a68e4e 100644 --- a/src/app/valentina/mainwindow.cpp +++ b/src/app/valentina/mainwindow.cpp @@ -295,7 +295,7 @@ void MainWindow::AddPP(const QString &PPName) comboBoxDraws->blockSignals(false); // Show best for new PP - VMainGraphicsView::NewSceneRect(ui->view->scene(), ui->view); + VMainGraphicsView::NewSceneRect(ui->view->scene(), ui->view, spoint); //ZoomFitBestCurrent(); QApplication::postEvent(this, new FitBestCurrentEvent()); diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.h b/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.h index a30258c4a..43ccb5c95 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.h +++ b/src/libs/vtools/tools/drawTools/toolcurve/vabstractspline.h @@ -184,9 +184,9 @@ inline void VAbstractSpline::ShowToolVisualization(bool show) ShowHandles(show); } - if (scene()) + if (QGraphicsScene *sc = scene()) { // Showing/hiding control points require recalculation scene size. - VMainGraphicsView::NewSceneRect(scene(), qApp->getSceneView()); + VMainGraphicsView::NewSceneRect(sc, qApp->getSceneView(), this); } } diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vtoolspline.cpp b/src/libs/vtools/tools/drawTools/toolcurve/vtoolspline.cpp index c860a5470..641c2794c 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vtoolspline.cpp +++ b/src/libs/vtools/tools/drawTools/toolcurve/vtoolspline.cpp @@ -287,7 +287,7 @@ void VToolSpline::ControlPointChangePosition(const qint32 &indexSpline, const Sp if (QGraphicsScene *sc = scene()) { - VMainGraphicsView::NewSceneRect(sc, qApp->getSceneView()); + VMainGraphicsView::NewSceneRect(sc, qApp->getSceneView(), this); } } } @@ -454,7 +454,7 @@ void VToolSpline::mouseMoveEvent(QGraphicsSceneMouseEvent *event) if (QGraphicsScene *sc = scene()) { - VMainGraphicsView::NewSceneRect(sc, qApp->getSceneView()); + VMainGraphicsView::NewSceneRect(sc, qApp->getSceneView(), this); } } diff --git a/src/libs/vtools/tools/drawTools/toolcurve/vtoolsplinepath.cpp b/src/libs/vtools/tools/drawTools/toolcurve/vtoolsplinepath.cpp index d8009d57b..1cc7e5afc 100644 --- a/src/libs/vtools/tools/drawTools/toolcurve/vtoolsplinepath.cpp +++ b/src/libs/vtools/tools/drawTools/toolcurve/vtoolsplinepath.cpp @@ -283,7 +283,7 @@ void VToolSplinePath::ControlPointChangePosition(const qint32 &indexSpline, cons if (QGraphicsScene *sc = scene()) { - VMainGraphicsView::NewSceneRect(sc, qApp->getSceneView()); + VMainGraphicsView::NewSceneRect(sc, qApp->getSceneView(), this); } } } @@ -614,7 +614,7 @@ void VToolSplinePath::mouseMoveEvent(QGraphicsSceneMouseEvent *event) if (QGraphicsScene *sc = scene()) { - VMainGraphicsView::NewSceneRect(sc, qApp->getSceneView()); + VMainGraphicsView::NewSceneRect(sc, qApp->getSceneView(), this); } } diff --git a/src/libs/vtools/tools/vtoolseamallowance.cpp b/src/libs/vtools/tools/vtoolseamallowance.cpp index 7188f5a61..cadaaf430 100644 --- a/src/libs/vtools/tools/vtoolseamallowance.cpp +++ b/src/libs/vtools/tools/vtoolseamallowance.cpp @@ -492,7 +492,7 @@ void VToolSeamAllowance::Update(const VPiece &piece) setFlag(QGraphicsItem::ItemSendsGeometryChanges, false); VAbstractTool::data.UpdatePiece(m_id, piece); RefreshGeometry(); - VMainGraphicsView::NewSceneRect(m_sceneDetails, qApp->getSceneView()); + VMainGraphicsView::NewSceneRect(m_sceneDetails, qApp->getSceneView(), this); setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); } diff --git a/src/libs/vtools/undocommands/addpiece.cpp b/src/libs/vtools/undocommands/addpiece.cpp index b42fa0e86..89553abe8 100644 --- a/src/libs/vtools/undocommands/addpiece.cpp +++ b/src/libs/vtools/undocommands/addpiece.cpp @@ -89,8 +89,6 @@ void AddPiece::undo() DecrementReferences(m_detail.GetCustomSARecords()); DecrementReferences(m_detail.GetInternalPaths()); DecrementReferences(m_detail.GetPins()); - - VMainGraphicsView::NewSceneRect(m_scene, qApp->getSceneView()); } else { @@ -127,10 +125,14 @@ void AddPiece::redo() m_scene->addItem(m_tool); m_tool->ConnectOutsideSignals(); m_tool->show(); + VMainGraphicsView::NewSceneRect(m_scene, qApp->getSceneView(), m_tool); m_tool.clear(); } - - VMainGraphicsView::NewSceneRect(m_scene, qApp->getSceneView()); + else + { + VMainGraphicsView::NewSceneRect(m_scene, qApp->getSceneView(), + qobject_cast(VAbstractPattern::getTool(nodeId))); + } } else { diff --git a/src/libs/vtools/undocommands/deletepiece.cpp b/src/libs/vtools/undocommands/deletepiece.cpp index 0183ac43c..8a7a2d4d7 100644 --- a/src/libs/vtools/undocommands/deletepiece.cpp +++ b/src/libs/vtools/undocommands/deletepiece.cpp @@ -103,9 +103,8 @@ void DeletePiece::undo() m_scene->addItem(m_tool); m_tool->ConnectOutsideSignals(); m_tool->show(); + VMainGraphicsView::NewSceneRect(m_scene, qApp->getSceneView(), m_tool); m_tool.clear(); - - VMainGraphicsView::NewSceneRect(m_scene, qApp->getSceneView()); } //--------------------------------------------------------------------------------------------------------------------- @@ -133,8 +132,6 @@ void DeletePiece::redo() DecrementReferences(m_detail.GetCustomSARecords()); DecrementReferences(m_detail.GetInternalPaths()); DecrementReferences(m_detail.GetPins()); - - VMainGraphicsView::NewSceneRect(m_scene, qApp->getSceneView()); } else { diff --git a/src/libs/vtools/undocommands/movepiece.cpp b/src/libs/vtools/undocommands/movepiece.cpp index 5c4292ea5..e01836f5d 100644 --- a/src/libs/vtools/undocommands/movepiece.cpp +++ b/src/libs/vtools/undocommands/movepiece.cpp @@ -74,11 +74,12 @@ void MovePiece::undo() if (domElement.isElement()) { SaveCoordinates(domElement, m_oldX, m_oldY); - if (VToolSeamAllowance *tool = qobject_cast(VAbstractPattern::getTool(nodeId))) + VToolSeamAllowance *tool = qobject_cast(VAbstractPattern::getTool(nodeId)); + if (tool) { tool->Move(m_oldX, m_oldY); } - VMainGraphicsView::NewSceneRect(m_scene, qApp->getSceneView()); + VMainGraphicsView::NewSceneRect(m_scene, qApp->getSceneView(), tool); } else { @@ -96,14 +97,12 @@ void MovePiece::redo() { SaveCoordinates(domElement, m_newX, m_newY); - if (redoFlag) + VToolSeamAllowance *tool = qobject_cast(VAbstractPattern::getTool(nodeId)); + if (redoFlag && tool) { - if (VToolSeamAllowance *tool = qobject_cast(VAbstractPattern::getTool(nodeId))) - { - tool->Move(m_newX, m_newY); - } + tool->Move(m_newX, m_newY); } - VMainGraphicsView::NewSceneRect(m_scene, qApp->getSceneView()); + VMainGraphicsView::NewSceneRect(m_scene, qApp->getSceneView(), tool); redoFlag = true; } else diff --git a/src/libs/vtools/undocommands/movespline.cpp b/src/libs/vtools/undocommands/movespline.cpp index a46cb9da7..88270c336 100644 --- a/src/libs/vtools/undocommands/movespline.cpp +++ b/src/libs/vtools/undocommands/movespline.cpp @@ -64,7 +64,6 @@ void MoveSpline::undo() qCDebug(vUndo, "Undo."); Do(oldSpline); - VMainGraphicsView::NewSceneRect(scene, qApp->getSceneView()); } //--------------------------------------------------------------------------------------------------------------------- @@ -73,7 +72,6 @@ void MoveSpline::redo() qCDebug(vUndo, "Redo."); Do(newSpline); - VMainGraphicsView::NewSceneRect(scene, qApp->getSceneView()); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/undocommands/movesplinepath.cpp b/src/libs/vtools/undocommands/movesplinepath.cpp index 87fe93ea6..c60da8478 100644 --- a/src/libs/vtools/undocommands/movesplinepath.cpp +++ b/src/libs/vtools/undocommands/movesplinepath.cpp @@ -63,7 +63,6 @@ void MoveSplinePath::undo() qCDebug(vUndo, "Undo."); Do(oldSplinePath); - VMainGraphicsView::NewSceneRect(scene, qApp->getSceneView()); } //--------------------------------------------------------------------------------------------------------------------- @@ -72,7 +71,6 @@ void MoveSplinePath::redo() qCDebug(vUndo, "Redo."); Do(newSplinePath); - VMainGraphicsView::NewSceneRect(scene, qApp->getSceneView()); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vwidgets/vgraphicssimpletextitem.cpp b/src/libs/vwidgets/vgraphicssimpletextitem.cpp index bde8182d4..0fd7db601 100644 --- a/src/libs/vwidgets/vgraphicssimpletextitem.cpp +++ b/src/libs/vwidgets/vgraphicssimpletextitem.cpp @@ -116,12 +116,9 @@ void VGraphicsSimpleTextItem::paint(QPainter *painter, const QStyleOptionGraphic m_oldScale = 1; } - if (scene && not scene->sceneRect().contains(sceneBoundingRect())) + if (QGraphicsView *view = scene->views().at(0)) { - if (QGraphicsView *view = scene->views().at(0)) - { - VMainGraphicsView::NewSceneRect(scene, view); - } + VMainGraphicsView::NewSceneRect(scene, view, this); } QGraphicsSimpleTextItem::paint(painter, option, widget); } diff --git a/src/libs/vwidgets/vmaingraphicsview.cpp b/src/libs/vwidgets/vmaingraphicsview.cpp index d945f80a5..b5f29890b 100644 --- a/src/libs/vwidgets/vmaingraphicsview.cpp +++ b/src/libs/vwidgets/vmaingraphicsview.cpp @@ -578,21 +578,28 @@ void VMainGraphicsView::AllowRubberBand(bool value) * @param sc scene. * @param view view. */ -void VMainGraphicsView::NewSceneRect(QGraphicsScene *sc, QGraphicsView *view) +void VMainGraphicsView::NewSceneRect(QGraphicsScene *sc, QGraphicsView *view, QGraphicsItem *item) { SCASSERT(sc != nullptr) SCASSERT(view != nullptr) - //Calculate view rect - const QRectF viewRect = SceneVisibleArea(view); + if (item == nullptr) + { + //Calculate view rect + const QRectF viewRect = SceneVisibleArea(view); - //Calculate scene rect - VMainGraphicsScene *currentScene = qobject_cast(sc); - SCASSERT(currentScene) - const QRectF itemsRect = currentScene->VisibleItemsBoundingRect(); + //Calculate scene rect + VMainGraphicsScene *currentScene = qobject_cast(sc); + SCASSERT(currentScene) + const QRectF itemsRect = currentScene->VisibleItemsBoundingRect(); - //Unite two rects - sc->setSceneRect(itemsRect.united(viewRect)); + //Unite two rects + sc->setSceneRect(itemsRect.united(viewRect)); + } + else if (not sc->sceneRect().contains(item->sceneBoundingRect())) + { + sc->setSceneRect(sc->sceneRect().united(item->sceneBoundingRect())); + } } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vwidgets/vmaingraphicsview.h b/src/libs/vwidgets/vmaingraphicsview.h index 47824676a..c97e1d668 100644 --- a/src/libs/vwidgets/vmaingraphicsview.h +++ b/src/libs/vwidgets/vmaingraphicsview.h @@ -118,7 +118,7 @@ public: void setShowToolOptions(bool value); void AllowRubberBand(bool value); - static void NewSceneRect(QGraphicsScene *sc, QGraphicsView *view); + static void NewSceneRect(QGraphicsScene *sc, QGraphicsView *view, QGraphicsItem *item = nullptr); static QRectF SceneVisibleArea(QGraphicsView *view); static qreal MinScale();