Fix crashing after a piece remove while rendering label.

This commit is contained in:
Roman Telezhynskyi 2024-06-10 07:46:59 +03:00
parent fea9e5ed07
commit 28e70e73c6
5 changed files with 25 additions and 12 deletions

View File

@ -4512,6 +4512,9 @@ void VPattern::PrepareForParse(const Document &parse)
{ {
SCASSERT(sceneDraw != nullptr) SCASSERT(sceneDraw != nullptr)
SCASSERT(sceneDetail != nullptr) SCASSERT(sceneDetail != nullptr)
emit CancelLabelRendering();
if (parse == Document::FullParse) if (parse == Document::FullParse)
{ {
RefreshElementIdCache(); RefreshElementIdCache();

View File

@ -30,8 +30,8 @@
#define VPATTERN_H #define VPATTERN_H
#include "../ifc/xml/vabstractpattern.h" #include "../ifc/xml/vabstractpattern.h"
#include "../vpatterndb/vcontainer.h"
#include "../ifc/xml/vpatternconverter.h" #include "../ifc/xml/vpatternconverter.h"
#include "../vpatterndb/vcontainer.h"
class VMainGraphicsScene; class VMainGraphicsScene;
class VNodeDetail; class VNodeDetail;
@ -45,6 +45,7 @@ class VToolSeamAllowance;
class VPattern : public VAbstractPattern class VPattern : public VAbstractPattern
{ {
Q_OBJECT // NOLINT Q_OBJECT // NOLINT
public: public:
VPattern(VContainer *data, VMainGraphicsScene *sceneDraw, VMainGraphicsScene *sceneDetail, VPattern(VContainer *data, VMainGraphicsScene *sceneDraw, VMainGraphicsScene *sceneDetail,
QObject *parent = nullptr); QObject *parent = nullptr);
@ -130,7 +131,7 @@ private:
Q_DISABLE_COPY_MOVE(VPattern) // NOLINT Q_DISABLE_COPY_MOVE(VPattern) // NOLINT
/** @brief data container with data. */ /** @brief data container with data. */
VContainer *data; VContainer *data;
VMainGraphicsScene *sceneDraw; VMainGraphicsScene *sceneDraw;
VMainGraphicsScene *sceneDetail; VMainGraphicsScene *sceneDetail;
@ -144,8 +145,8 @@ private:
static auto ParseDetailNode(const QDomElement &domElement) -> VNodeDetail; static auto ParseDetailNode(const QDomElement &domElement) -> VNodeDetail;
void ParseRootElement(const Document &parse, const QDomNode &node); void ParseRootElement(const Document &parse, const QDomNode &node);
void ParseDrawElement(const QDomNode& node, const Document &parse); void ParseDrawElement(const QDomNode &node, const Document &parse);
void ParseDrawMode(const QDomNode& node, const Document &parse, const Draw &mode); void ParseDrawMode(const QDomNode &node, const Document &parse, const Draw &mode);
void ParseDrawModeElement(QDomElement &domElement, const Document &parse, const Draw &mode); void ParseDrawModeElement(QDomElement &domElement, const Document &parse, const Draw &mode);
void ParseDetailElement(QDomElement &domElement, const Document &parse); void ParseDetailElement(QDomElement &domElement, const Document &parse);
void ParseDetailInternals(const QDomElement &domElement, VPiece &detail) const; void ParseDetailInternals(const QDomElement &domElement, VPiece &detail) const;
@ -205,23 +206,20 @@ private:
const Document &parse); const Document &parse);
void ParseToolPointOfIntersectionCircles(VMainGraphicsScene *scene, QDomElement &domElement, const Document &parse); void ParseToolPointOfIntersectionCircles(VMainGraphicsScene *scene, QDomElement &domElement, const Document &parse);
void ParseToolPointOfIntersectionCurves(VMainGraphicsScene *scene, QDomElement &domElement, const Document &parse); void ParseToolPointOfIntersectionCurves(VMainGraphicsScene *scene, QDomElement &domElement, const Document &parse);
void ParseToolPointFromCircleAndTangent(VMainGraphicsScene *scene, QDomElement &domElement, void ParseToolPointFromCircleAndTangent(VMainGraphicsScene *scene, QDomElement &domElement, const Document &parse);
const Document &parse);
void ParseToolPointFromArcAndTangent(VMainGraphicsScene *scene, const QDomElement &domElement, void ParseToolPointFromArcAndTangent(VMainGraphicsScene *scene, const QDomElement &domElement,
const Document &parse); const Document &parse);
void ParseToolTrueDarts(VMainGraphicsScene *scene, const QDomElement &domElement, const Document &parse); void ParseToolTrueDarts(VMainGraphicsScene *scene, const QDomElement &domElement, const Document &parse);
// TODO. Delete if minimal supported version is 0.2.7 // TODO. Delete if minimal supported version is 0.2.7
Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < FormatVersion(0, 2, 7), Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < FormatVersion(0, 2, 7), "Time to refactor the code.");
"Time to refactor the code.");
void ParseOldToolSpline(VMainGraphicsScene *scene, QDomElement &domElement, const Document &parse); void ParseOldToolSpline(VMainGraphicsScene *scene, QDomElement &domElement, const Document &parse);
void ParseToolSpline(VMainGraphicsScene *scene, QDomElement &domElement, const Document &parse); void ParseToolSpline(VMainGraphicsScene *scene, QDomElement &domElement, const Document &parse);
void ParseToolCubicBezier(VMainGraphicsScene *scene, const QDomElement &domElement, const Document &parse); void ParseToolCubicBezier(VMainGraphicsScene *scene, const QDomElement &domElement, const Document &parse);
// TODO. Delete if minimal supported version is 0.2.7 // TODO. Delete if minimal supported version is 0.2.7
Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < FormatVersion(0, 2, 7), Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < FormatVersion(0, 2, 7), "Time to refactor the code.");
"Time to refactor the code.");
void ParseOldToolSplinePath(VMainGraphicsScene *scene, QDomElement &domElement, const Document &parse); void ParseOldToolSplinePath(VMainGraphicsScene *scene, QDomElement &domElement, const Document &parse);
void ParseToolSplinePath(VMainGraphicsScene *scene, const QDomElement &domElement, const Document &parse); void ParseToolSplinePath(VMainGraphicsScene *scene, const QDomElement &domElement, const Document &parse);

View File

@ -473,6 +473,8 @@ signals:
void BackgroundImagePositionChanged(const QUuid &id); void BackgroundImagePositionChanged(const QUuid &id);
void BackgroundImageOpacityChanged(const QUuid &id); void BackgroundImageOpacityChanged(const QUuid &id);
void CancelLabelRendering();
public slots: public slots:
virtual void LiteParseTree(const Document &parse) = 0; virtual void LiteParseTree(const Document &parse) = 0;
void haveLiteChange(); void haveLiteChange();

View File

@ -395,6 +395,12 @@ auto RenderFoldLine(const VPiece &detail, const VContainer *data) -> VFoldLine
} }
} // namespace } // namespace
//---------------------------------------------------------------------------------------------------------------------
VToolSeamAllowance::~VToolSeamAllowance()
{
CancelLabelRendering();
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
auto VToolSeamAllowance::Create(const QPointer<DialogTool> &dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, auto VToolSeamAllowance::Create(const QPointer<DialogTool> &dialog, VMainGraphicsScene *scene, VAbstractPattern *doc,
VContainer *data) -> VToolSeamAllowance * VContainer *data) -> VToolSeamAllowance *
@ -1734,6 +1740,7 @@ VToolSeamAllowance::VToolSeamAllowance(const VToolSeamAllowanceInitData &initDat
connect(m_sceneDetails, &VMainGraphicsScene::EnableToolMove, this, &VToolSeamAllowance::EnableToolMove); connect(m_sceneDetails, &VMainGraphicsScene::EnableToolMove, this, &VToolSeamAllowance::EnableToolMove);
connect(m_sceneDetails, &VMainGraphicsScene::ItemSelection, this, &VToolSeamAllowance::ToolSelectionType); connect(m_sceneDetails, &VMainGraphicsScene::ItemSelection, this, &VToolSeamAllowance::ToolSelectionType);
connect(m_sceneDetails, &VMainGraphicsScene::UpdatePassmarks, this, &VToolSeamAllowance::UpdatePassmarks); connect(m_sceneDetails, &VMainGraphicsScene::UpdatePassmarks, this, &VToolSeamAllowance::UpdatePassmarks);
connect(doc, &VAbstractPattern::CancelLabelRendering, this, &VToolSeamAllowance::CancelLabelRendering);
ConnectOutsideSignals(); ConnectOutsideSignals();
@ -1973,6 +1980,8 @@ void VToolSeamAllowance::SaveDialogChange(const QString &undoText)
const VPiece newDet = dialogTool->GetPiece(); const VPiece newDet = dialogTool->GetPiece();
const VPiece oldDet = VAbstractTool::data.GetPiece(m_id); const VPiece oldDet = VAbstractTool::data.GetPiece(m_id);
CancelLabelRendering();
QVector<QPointer<VUndoCommand>> &undocommands = dialogTool->UndoStack(); QVector<QPointer<VUndoCommand>> &undocommands = dialogTool->UndoStack();
const bool groupChange = not undocommands.isEmpty(); const bool groupChange = not undocommands.isEmpty();

View File

@ -55,7 +55,7 @@ class VToolSeamAllowance final : public VInteractiveTool, public QGraphicsPathIt
Q_OBJECT // NOLINT Q_OBJECT // NOLINT
public: public:
~VToolSeamAllowance() override = default; ~VToolSeamAllowance() override;
static auto Create(const QPointer<DialogTool> &dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, static auto Create(const QPointer<DialogTool> &dialog, VMainGraphicsScene *scene, VAbstractPattern *doc,
VContainer *data) -> VToolSeamAllowance *; VContainer *data) -> VToolSeamAllowance *;
@ -122,7 +122,6 @@ public:
auto boundingRect() const -> QRectF override; auto boundingRect() const -> QRectF override;
auto shape() const -> QPainterPath override; auto shape() const -> QPainterPath override;
void CancelLabelRendering();
public slots: public slots:
void FullUpdateFromGuiApply() override; void FullUpdateFromGuiApply() override;
void FullUpdateFromFile() override; void FullUpdateFromFile() override;
@ -138,6 +137,8 @@ public slots:
void UpdatePassmarks(); void UpdatePassmarks();
void ShowOptions(); void ShowOptions();
void DeleteFromMenu(); void DeleteFromMenu();
void CancelLabelRendering();
protected slots: protected slots:
void UpdateGrainline(); void UpdateGrainline();
void SaveMoveDetail(const QPointF &ptPos); void SaveMoveDetail(const QPointF &ptPos);