From a0643e5712b64c7bf2132aeb92b68babf93f1263 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Wed, 15 Nov 2017 13:23:19 +0200 Subject: [PATCH] Optimize tool piece visualization. --HG-- branch : develop --- .../visualization/path/vistoolpiece.cpp | 33 ++++++++++++++----- .../vtools/visualization/path/vistoolpiece.h | 5 +++ 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/src/libs/vtools/visualization/path/vistoolpiece.cpp b/src/libs/vtools/visualization/path/vistoolpiece.cpp index e597f9378..486e5afa3 100644 --- a/src/libs/vtools/visualization/path/vistoolpiece.cpp +++ b/src/libs/vtools/visualization/path/vistoolpiece.cpp @@ -37,7 +37,11 @@ VisToolPiece::VisToolPiece(const VContainer *data, QGraphicsItem *parent) m_points(), m_line1(nullptr), m_line2(nullptr), - m_piece() + m_piece(), + m_pieceCached(false), + m_cachedMainPath(), + m_cachedNodes(), + m_cachedMainPathPoints() { m_line1 = InitItem(supportColor, this); m_line2 = InitItem(supportColor, this); @@ -50,24 +54,34 @@ void VisToolPiece::RefreshGeometry() if (m_piece.GetPath().CountNodes() > 0) { - DrawPath(this, m_piece.MainPathPath(Visualization::data), mainColor, Qt::SolidLine, Qt::RoundCap); + if (not m_pieceCached) + { + m_cachedMainPath = m_piece.MainPathPath(Visualization::data); + m_cachedNodes = m_piece.MainPathNodePoints(Visualization::data); + if (mode == Mode::Creation) + { + m_cachedMainPathPoints = m_piece.MainPathPoints(Visualization::data); + } + m_pieceCached = true; + } - const QVector nodes = m_piece.MainPathNodePoints(Visualization::data); + DrawPath(this, m_cachedMainPath, mainColor, Qt::SolidLine, Qt::RoundCap); - for (int i = 0; i < nodes.size(); ++i) + for (int i = 0; i < m_cachedNodes.size(); ++i) { VScaledEllipse *point = GetPoint(static_cast(i), supportColor); - DrawPoint(point, nodes.at(i).toQPointF(), supportColor); + DrawPoint(point, m_cachedNodes.at(i).toQPointF(), supportColor); } if (mode == Mode::Creation) { - const QVector points = m_piece.MainPathPoints(Visualization::data); - DrawLine(m_line1, QLineF(points.first(), Visualization::scenePos), supportColor, Qt::DashLine); + DrawLine(m_line1, QLineF(m_cachedMainPathPoints.first(), Visualization::scenePos), supportColor, + Qt::DashLine); - if (points.size() > 1) + if (m_cachedMainPathPoints.size() > 1) { - DrawLine(m_line2, QLineF(points.last(), Visualization::scenePos), supportColor, Qt::DashLine); + DrawLine(m_line2, QLineF(m_cachedMainPathPoints.last(), Visualization::scenePos), supportColor, + Qt::DashLine); } } } @@ -77,6 +91,7 @@ void VisToolPiece::RefreshGeometry() void VisToolPiece::SetPiece(const VPiece &piece) { m_piece = piece; + m_pieceCached = false; } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/visualization/path/vistoolpiece.h b/src/libs/vtools/visualization/path/vistoolpiece.h index cd2e65790..dae2be9a3 100644 --- a/src/libs/vtools/visualization/path/vistoolpiece.h +++ b/src/libs/vtools/visualization/path/vistoolpiece.h @@ -34,6 +34,7 @@ #include "vispath.h" #include "../vpatterndb/vpiece.h" +#include "../vgeometry/vpointf.h" class VisToolPiece : public VisPath { @@ -53,6 +54,10 @@ private: VScaledLine *m_line1; VScaledLine *m_line2; VPiece m_piece; + bool m_pieceCached; + QPainterPath m_cachedMainPath; + QVector m_cachedNodes; + QVector m_cachedMainPathPoints; VScaledEllipse* GetPoint(quint32 i, const QColor &color);