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
This commit is contained in:
Roman Telezhynskyi 2017-10-27 09:13:51 +03:00
parent 6dfe04e2bc
commit 4af32961b0
13 changed files with 41 additions and 43 deletions

View File

@ -295,7 +295,7 @@ void MainWindow::AddPP(const QString &PPName)
comboBoxDraws->blockSignals(false); comboBoxDraws->blockSignals(false);
// Show best for new PP // Show best for new PP
VMainGraphicsView::NewSceneRect(ui->view->scene(), ui->view); VMainGraphicsView::NewSceneRect(ui->view->scene(), ui->view, spoint);
//ZoomFitBestCurrent(); //ZoomFitBestCurrent();
QApplication::postEvent(this, new FitBestCurrentEvent()); QApplication::postEvent(this, new FitBestCurrentEvent());

View File

@ -184,9 +184,9 @@ inline void VAbstractSpline::ShowToolVisualization(bool show)
ShowHandles(show); ShowHandles(show);
} }
if (scene()) if (QGraphicsScene *sc = scene())
{ // Showing/hiding control points require recalculation scene size. { // Showing/hiding control points require recalculation scene size.
VMainGraphicsView::NewSceneRect(scene(), qApp->getSceneView()); VMainGraphicsView::NewSceneRect(sc, qApp->getSceneView(), this);
} }
} }

View File

@ -287,7 +287,7 @@ void VToolSpline::ControlPointChangePosition(const qint32 &indexSpline, const Sp
if (QGraphicsScene *sc = scene()) 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()) if (QGraphicsScene *sc = scene())
{ {
VMainGraphicsView::NewSceneRect(sc, qApp->getSceneView()); VMainGraphicsView::NewSceneRect(sc, qApp->getSceneView(), this);
} }
} }

View File

@ -283,7 +283,7 @@ void VToolSplinePath::ControlPointChangePosition(const qint32 &indexSpline, cons
if (QGraphicsScene *sc = scene()) 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()) if (QGraphicsScene *sc = scene())
{ {
VMainGraphicsView::NewSceneRect(sc, qApp->getSceneView()); VMainGraphicsView::NewSceneRect(sc, qApp->getSceneView(), this);
} }
} }

View File

@ -492,7 +492,7 @@ void VToolSeamAllowance::Update(const VPiece &piece)
setFlag(QGraphicsItem::ItemSendsGeometryChanges, false); setFlag(QGraphicsItem::ItemSendsGeometryChanges, false);
VAbstractTool::data.UpdatePiece(m_id, piece); VAbstractTool::data.UpdatePiece(m_id, piece);
RefreshGeometry(); RefreshGeometry();
VMainGraphicsView::NewSceneRect(m_sceneDetails, qApp->getSceneView()); VMainGraphicsView::NewSceneRect(m_sceneDetails, qApp->getSceneView(), this);
setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
} }

View File

@ -89,8 +89,6 @@ void AddPiece::undo()
DecrementReferences(m_detail.GetCustomSARecords()); DecrementReferences(m_detail.GetCustomSARecords());
DecrementReferences(m_detail.GetInternalPaths()); DecrementReferences(m_detail.GetInternalPaths());
DecrementReferences(m_detail.GetPins()); DecrementReferences(m_detail.GetPins());
VMainGraphicsView::NewSceneRect(m_scene, qApp->getSceneView());
} }
else else
{ {
@ -127,10 +125,14 @@ void AddPiece::redo()
m_scene->addItem(m_tool); m_scene->addItem(m_tool);
m_tool->ConnectOutsideSignals(); m_tool->ConnectOutsideSignals();
m_tool->show(); m_tool->show();
VMainGraphicsView::NewSceneRect(m_scene, qApp->getSceneView(), m_tool);
m_tool.clear(); m_tool.clear();
} }
else
VMainGraphicsView::NewSceneRect(m_scene, qApp->getSceneView()); {
VMainGraphicsView::NewSceneRect(m_scene, qApp->getSceneView(),
qobject_cast<VToolSeamAllowance*>(VAbstractPattern::getTool(nodeId)));
}
} }
else else
{ {

View File

@ -103,9 +103,8 @@ void DeletePiece::undo()
m_scene->addItem(m_tool); m_scene->addItem(m_tool);
m_tool->ConnectOutsideSignals(); m_tool->ConnectOutsideSignals();
m_tool->show(); m_tool->show();
VMainGraphicsView::NewSceneRect(m_scene, qApp->getSceneView(), m_tool);
m_tool.clear(); m_tool.clear();
VMainGraphicsView::NewSceneRect(m_scene, qApp->getSceneView());
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -133,8 +132,6 @@ void DeletePiece::redo()
DecrementReferences(m_detail.GetCustomSARecords()); DecrementReferences(m_detail.GetCustomSARecords());
DecrementReferences(m_detail.GetInternalPaths()); DecrementReferences(m_detail.GetInternalPaths());
DecrementReferences(m_detail.GetPins()); DecrementReferences(m_detail.GetPins());
VMainGraphicsView::NewSceneRect(m_scene, qApp->getSceneView());
} }
else else
{ {

View File

@ -74,11 +74,12 @@ void MovePiece::undo()
if (domElement.isElement()) if (domElement.isElement())
{ {
SaveCoordinates(domElement, m_oldX, m_oldY); SaveCoordinates(domElement, m_oldX, m_oldY);
if (VToolSeamAllowance *tool = qobject_cast<VToolSeamAllowance *>(VAbstractPattern::getTool(nodeId))) VToolSeamAllowance *tool = qobject_cast<VToolSeamAllowance *>(VAbstractPattern::getTool(nodeId));
if (tool)
{ {
tool->Move(m_oldX, m_oldY); tool->Move(m_oldX, m_oldY);
} }
VMainGraphicsView::NewSceneRect(m_scene, qApp->getSceneView()); VMainGraphicsView::NewSceneRect(m_scene, qApp->getSceneView(), tool);
} }
else else
{ {
@ -96,14 +97,12 @@ void MovePiece::redo()
{ {
SaveCoordinates(domElement, m_newX, m_newY); SaveCoordinates(domElement, m_newX, m_newY);
if (redoFlag) VToolSeamAllowance *tool = qobject_cast<VToolSeamAllowance *>(VAbstractPattern::getTool(nodeId));
if (redoFlag && tool)
{ {
if (VToolSeamAllowance *tool = qobject_cast<VToolSeamAllowance *>(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; redoFlag = true;
} }
else else

View File

@ -64,7 +64,6 @@ void MoveSpline::undo()
qCDebug(vUndo, "Undo."); qCDebug(vUndo, "Undo.");
Do(oldSpline); Do(oldSpline);
VMainGraphicsView::NewSceneRect(scene, qApp->getSceneView());
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -73,7 +72,6 @@ void MoveSpline::redo()
qCDebug(vUndo, "Redo."); qCDebug(vUndo, "Redo.");
Do(newSpline); Do(newSpline);
VMainGraphicsView::NewSceneRect(scene, qApp->getSceneView());
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -63,7 +63,6 @@ void MoveSplinePath::undo()
qCDebug(vUndo, "Undo."); qCDebug(vUndo, "Undo.");
Do(oldSplinePath); Do(oldSplinePath);
VMainGraphicsView::NewSceneRect(scene, qApp->getSceneView());
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -72,7 +71,6 @@ void MoveSplinePath::redo()
qCDebug(vUndo, "Redo."); qCDebug(vUndo, "Redo.");
Do(newSplinePath); Do(newSplinePath);
VMainGraphicsView::NewSceneRect(scene, qApp->getSceneView());
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -116,12 +116,9 @@ void VGraphicsSimpleTextItem::paint(QPainter *painter, const QStyleOptionGraphic
m_oldScale = 1; 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, this);
{
VMainGraphicsView::NewSceneRect(scene, view);
}
} }
QGraphicsSimpleTextItem::paint(painter, option, widget); QGraphicsSimpleTextItem::paint(painter, option, widget);
} }

View File

@ -578,21 +578,28 @@ void VMainGraphicsView::AllowRubberBand(bool value)
* @param sc scene. * @param sc scene.
* @param view view. * @param view view.
*/ */
void VMainGraphicsView::NewSceneRect(QGraphicsScene *sc, QGraphicsView *view) void VMainGraphicsView::NewSceneRect(QGraphicsScene *sc, QGraphicsView *view, QGraphicsItem *item)
{ {
SCASSERT(sc != nullptr) SCASSERT(sc != nullptr)
SCASSERT(view != nullptr) SCASSERT(view != nullptr)
//Calculate view rect if (item == nullptr)
const QRectF viewRect = SceneVisibleArea(view); {
//Calculate view rect
const QRectF viewRect = SceneVisibleArea(view);
//Calculate scene rect //Calculate scene rect
VMainGraphicsScene *currentScene = qobject_cast<VMainGraphicsScene *>(sc); VMainGraphicsScene *currentScene = qobject_cast<VMainGraphicsScene *>(sc);
SCASSERT(currentScene) SCASSERT(currentScene)
const QRectF itemsRect = currentScene->VisibleItemsBoundingRect(); const QRectF itemsRect = currentScene->VisibleItemsBoundingRect();
//Unite two rects //Unite two rects
sc->setSceneRect(itemsRect.united(viewRect)); sc->setSceneRect(itemsRect.united(viewRect));
}
else if (not sc->sceneRect().contains(item->sceneBoundingRect()))
{
sc->setSceneRect(sc->sceneRect().united(item->sceneBoundingRect()));
}
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -118,7 +118,7 @@ public:
void setShowToolOptions(bool value); void setShowToolOptions(bool value);
void AllowRubberBand(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 QRectF SceneVisibleArea(QGraphicsView *view);
static qreal MinScale(); static qreal MinScale();