diff --git a/src/app/valentina/mainwindow.cpp b/src/app/valentina/mainwindow.cpp index 6c0712a8a..007b84b7c 100644 --- a/src/app/valentina/mainwindow.cpp +++ b/src/app/valentina/mainwindow.cpp @@ -1790,6 +1790,7 @@ void MainWindow::ActionDraw(bool checked) leftGoToStage->setPixmap(QPixmap("://icon/24x24/fast_forward_left_to_right_arrow.png")); rightGoToStage->setPixmap(QPixmap("://icon/24x24/left_to_right_arrow.png")); + ui->actionDraw->setChecked(true); ui->actionDetails->setChecked(false); ui->actionLayout->setChecked(false); SaveCurrentScene(); @@ -1868,6 +1869,7 @@ void MainWindow::ActionDetails(bool checked) rightGoToStage->setPixmap(QPixmap("://icon/24x24/left_to_right_arrow.png")); ui->actionDraw->setChecked(false); + ui->actionDetails->setChecked(true); ui->actionLayout->setChecked(false); SaveCurrentScene(); @@ -1955,6 +1957,7 @@ void MainWindow::ActionLayout(bool checked) ui->actionDraw->setChecked(false); ui->actionDetails->setChecked(false); + ui->actionLayout->setChecked(true); SaveCurrentScene(); PrepareDetailsForLayout(details); @@ -2192,7 +2195,7 @@ void MainWindow::Clear() qCDebug(vMainWindow, "Reseting main window."); lock.reset(); qCDebug(vMainWindow, "Unlocked pattern file."); - ui->actionDraw->setChecked(true); + ActionDraw(true); qCDebug(vMainWindow, "Returned to Draw mode."); pattern->Clear(); qCDebug(vMainWindow, "Clearing pattern."); @@ -2489,9 +2492,7 @@ void MainWindow::Layout() else { listDetails.clear(); - ui->actionDetails->setChecked(false); - ui->actionLayout->setChecked(false); - ui->actionDraw->setChecked(true); + ActionDraw(true); SetLayoutModeActions(false); } } @@ -3543,7 +3544,7 @@ bool MainWindow::LoadPattern(const QString &fileName, const QString& customMeasu //Fit scene size to best size for first show ZoomFirstShow(); - ui->actionDraw->setChecked(true); + ActionDraw(true); } qApp->setOpeningPattern();// End opening file return true; diff --git a/src/app/valentina/xml/vpattern.cpp b/src/app/valentina/xml/vpattern.cpp index a09ec77c6..8db3a299a 100644 --- a/src/app/valentina/xml/vpattern.cpp +++ b/src/app/valentina/xml/vpattern.cpp @@ -91,6 +91,13 @@ void VPattern::CreateEmptyFile() insertBefore(createProcessingInstruction("xml", "version=\"1.0\" encoding=\"UTF-8\""), this->firstChild()); } +//--------------------------------------------------------------------------------------------------------------------- +void VPattern::setXMLContent(const QString &fileName) +{ + VDomDocument::setXMLContent(fileName); + GarbageCollector(); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief Parse parse file. @@ -1272,10 +1279,11 @@ void VPattern::ParseNodePoint(const QDomElement &domElement, const Document &par PointsCommonAttributes(domElement, id, mx, my); const quint32 idObject = GetParametrUInt(domElement, VAbstractNode::AttrIdObject, NULL_ID_STR); const quint32 idTool = GetParametrUInt(domElement, VAbstractNode::AttrIdTool, NULL_ID_STR); + const NodeUsage inUse = GetParametrUsage(domElement, VAbstractNode::AttrInUse); const QSharedPointer point = data->GeometricObject(idObject ); data->UpdateGObject(id, new VPointF(point->toQPointF(), point->name(), mx, my, idObject, Draw::Modeling)); - VNodePoint::Create(this, data, sceneDetail, id, idObject, parse, Source::FromFile, idTool); + VNodePoint::Create(this, data, sceneDetail, id, idObject, parse, Source::FromFile, inUse, idTool); } catch (const VExceptionBadId &e) { @@ -1892,11 +1900,12 @@ void VPattern::ParseNodeSpline(const QDomElement &domElement, const Document &pa quint32 idTool = 0; SplinesCommonAttributes(domElement, id, idObject, idTool); + const NodeUsage inUse = GetParametrUsage(domElement, VAbstractNode::AttrInUse); VSpline *spl = new VSpline(*data->GeometricObject(idObject)); spl->setIdObject(idObject); spl->setMode(Draw::Modeling); data->UpdateGObject(id, spl); - VNodeSpline::Create(this, data, id, idObject, parse, Source::FromFile, idTool); + VNodeSpline::Create(this, data, sceneDetail, id, idObject, parse, Source::FromFile, inUse, idTool); } catch (const VExceptionBadId &e) { @@ -1918,11 +1927,12 @@ void VPattern::ParseNodeSplinePath(const QDomElement &domElement, const Document quint32 idTool = 0; SplinesCommonAttributes(domElement, id, idObject, idTool); + const NodeUsage inUse = GetParametrUsage(domElement, VAbstractNode::AttrInUse); VSplinePath *path = new VSplinePath(*data->GeometricObject(idObject)); path->setIdObject(idObject); path->setMode(Draw::Modeling); data->UpdateGObject(id, path); - VNodeSplinePath::Create(this, data, id, idObject, parse, Source::FromFile, idTool); + VNodeSplinePath::Create(this, data, sceneDetail, id, idObject, parse, Source::FromFile, inUse, idTool); } catch (const VExceptionBadId &e) { @@ -1989,11 +1999,12 @@ void VPattern::ParseNodeArc(const QDomElement &domElement, const Document &parse ToolsCommonAttributes(domElement, id); const quint32 idObject = GetParametrUInt(domElement, VAbstractNode::AttrIdObject, NULL_ID_STR); const quint32 idTool = GetParametrUInt(domElement, VAbstractNode::AttrIdTool, NULL_ID_STR); + const NodeUsage inUse = GetParametrUsage(domElement, VAbstractNode::AttrInUse); VArc *arc = new VArc(*data->GeometricObject(idObject)); arc->setIdObject(idObject); arc->setMode(Draw::Modeling); data->UpdateGObject(id, arc); - VNodeArc::Create(this, data, id, idObject, parse, Source::FromFile, idTool); + VNodeArc::Create(this, data, sceneDetail, id, idObject, parse, Source::FromFile, inUse, idTool); } catch (const VExceptionBadId &e) { @@ -2111,6 +2122,44 @@ QDomElement VPattern::FindIncrement(const QString &name) const return QDomElement(); } +//--------------------------------------------------------------------------------------------------------------------- +void VPattern::GarbageCollector() +{ + QDomNodeList modelingList = elementsByTagName(TagModeling); + for (int i=0; i < modelingList.size(); ++i) + { + QDomElement modElement = modelingList.at(i).toElement(); + if (not modElement.isNull()) + { + QDomElement modNode = modElement.firstChild().toElement(); + while (not modNode.isNull()) + { + // First get next sibling because later will not have chance to get it + QDomElement nextSibling = modNode.nextSibling().toElement(); + if (modNode.hasAttribute(VAbstractNode::AttrInUse)) + { + const NodeUsage inUse = GetParametrUsage(modNode, VAbstractNode::AttrInUse); + if (inUse == NodeUsage::InUse) + { // It is dangerous to leave object with attribute 'inUse' + // Each parse should confirm this status. + modNode.removeAttribute(VAbstractNode::AttrInUse); + } + else + { // Parent was deleted. We do not need this object anymore + modElement.removeChild(modNode); + } + } + else + { // Last parse did not confirm use of an object + modElement.removeChild(modNode); // was not used + } + + modNode = nextSibling; + } + } + } +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief ParseSplineElement parse spline tag. diff --git a/src/app/valentina/xml/vpattern.h b/src/app/valentina/xml/vpattern.h index d4c08bba7..9072159d6 100644 --- a/src/app/valentina/xml/vpattern.h +++ b/src/app/valentina/xml/vpattern.h @@ -58,6 +58,7 @@ public: quint32 SPointActiveDraw(); + virtual void setXMLContent(const QString &fileName) Q_DECL_OVERRIDE; virtual bool SaveDocument(const QString &fileName, QString &error) const Q_DECL_OVERRIDE; QRectF ActiveDrawBoundingRect() const; @@ -174,6 +175,8 @@ private: QDomElement MakeEmptyIncrement(const QString &name); QDomElement FindIncrement(const QString &name) const; + + void GarbageCollector(); }; #endif // VPATTERN_H diff --git a/src/libs/ifc/schema.qrc b/src/libs/ifc/schema.qrc index e01d23aaf..a53d2a278 100644 --- a/src/libs/ifc/schema.qrc +++ b/src/libs/ifc/schema.qrc @@ -8,6 +8,7 @@ schema/pattern/v0.2.0.xsd schema/pattern/v0.2.1.xsd schema/pattern/v0.2.2.xsd + schema/pattern/v0.2.3.xsd schema/standard_measurements/v0.3.0.xsd schema/standard_measurements/v0.4.0.xsd schema/standard_measurements/v0.4.1.xsd diff --git a/src/libs/ifc/schema/pattern/v0.2.3.xsd b/src/libs/ifc/schema/pattern/v0.2.3.xsd new file mode 100644 index 000000000..b1905a2ab --- /dev/null +++ b/src/libs/ifc/schema/pattern/v0.2.3.xsd @@ -0,0 +1,415 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/libs/ifc/xml/vdomdocument.cpp b/src/libs/ifc/xml/vdomdocument.cpp index 535d4009a..6963b7853 100644 --- a/src/libs/ifc/xml/vdomdocument.cpp +++ b/src/libs/ifc/xml/vdomdocument.cpp @@ -274,6 +274,33 @@ bool VDomDocument::GetParametrBool(const QDomElement &domElement, const QString return val; } +//--------------------------------------------------------------------------------------------------------------------- +NodeUsage VDomDocument::GetParametrUsage(const QDomElement &domElement, const QString &name) const +{ + const bool value = GetParametrBool(domElement, name, QStringLiteral("true")); + if (value) + { + return NodeUsage::InUse; + } + else + { + return NodeUsage::NotInUse; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VDomDocument::SetParametrUsage(QDomElement &domElement, const QString &name, const NodeUsage &value) +{ + if (value == NodeUsage::InUse) + { + domElement.setAttribute(name, QStringLiteral("true")); + } + else + { + domElement.setAttribute(name, QStringLiteral("false")); + } +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief Returns the string value of the given attribute. RENAME: see above @@ -794,6 +821,7 @@ bool VDomDocument::SafeCopy(const QString &source, const QString &destination, Q if (result) { + QFile::remove(destination); if (not destFile.rename(destination)) { error = destFile.errorString(); diff --git a/src/libs/ifc/xml/vdomdocument.h b/src/libs/ifc/xml/vdomdocument.h index 00cfc33f5..faa1d1f45 100644 --- a/src/libs/ifc/xml/vdomdocument.h +++ b/src/libs/ifc/xml/vdomdocument.h @@ -87,13 +87,17 @@ public: quint32 GetParametrUInt(const QDomElement& domElement, const QString &name, const QString &defValue) const; bool GetParametrBool(const QDomElement& domElement, const QString &name, const QString &defValue) const; + + NodeUsage GetParametrUsage(const QDomElement& domElement, const QString &name) const; + void SetParametrUsage(QDomElement& domElement, const QString &name, const NodeUsage &value); + QString GetParametrString(const QDomElement& domElement, const QString &name, const QString &defValue = QString()) const; qreal GetParametrDouble(const QDomElement& domElement, const QString &name, const QString &defValue) const; quint32 GetParametrId(const QDomElement& domElement) const; static void ValidateXML(const QString &schema, const QString &fileName); - void setXMLContent(const QString &fileName); + virtual void setXMLContent(const QString &fileName); static Unit StrToUnits(const QString &unit); static QString UnitsToStr(const Unit &unit, const bool translate = false); static QString UnitsHelpString(); diff --git a/src/libs/ifc/xml/vpatternconverter.cpp b/src/libs/ifc/xml/vpatternconverter.cpp index 811f574d9..d9a127429 100644 --- a/src/libs/ifc/xml/vpatternconverter.cpp +++ b/src/libs/ifc/xml/vpatternconverter.cpp @@ -43,8 +43,8 @@ */ const QString VPatternConverter::PatternMinVerStr = QStringLiteral("0.1.0"); -const QString VPatternConverter::PatternMaxVerStr = QStringLiteral("0.2.2"); -const QString VPatternConverter::CurrentSchema = QStringLiteral("://schema/pattern/v0.2.2.xsd"); +const QString VPatternConverter::PatternMaxVerStr = QStringLiteral("0.2.3"); +const QString VPatternConverter::CurrentSchema = QStringLiteral("://schema/pattern/v0.2.3.xsd"); //--------------------------------------------------------------------------------------------------------------------- VPatternConverter::VPatternConverter(const QString &fileName) @@ -104,6 +104,8 @@ QString VPatternConverter::XSDSchema(int ver) const case (0x000201): return QStringLiteral("://schema/pattern/v0.2.1.xsd"); case (0x000202): + return QStringLiteral("://schema/pattern/v0.2.2.xsd"); + case (0x000203): return CurrentSchema; default: { @@ -170,6 +172,13 @@ void VPatternConverter::ApplyPatches() V_FALLTHROUGH } case (0x000202): + { + ToV0_2_3(); + const QString schema = XSDSchema(0x000203); + ValidateXML(schema, fileName); + V_FALLTHROUGH + } + case (0x000203): break; default: break; @@ -248,6 +257,13 @@ void VPatternConverter::ToV0_2_2() Save(); } +//--------------------------------------------------------------------------------------------------------------------- +void VPatternConverter::ToV0_2_3() +{ + SetVersion(QStringLiteral("0.2.3")); + Save(); +} + //--------------------------------------------------------------------------------------------------------------------- void VPatternConverter::TagUnitToV0_2_0() { diff --git a/src/libs/ifc/xml/vpatternconverter.h b/src/libs/ifc/xml/vpatternconverter.h index 7bdb2e9a7..f5f9e7ff2 100644 --- a/src/libs/ifc/xml/vpatternconverter.h +++ b/src/libs/ifc/xml/vpatternconverter.h @@ -62,6 +62,7 @@ private: void ToV0_2_0(); void ToV0_2_1(); void ToV0_2_2(); + void ToV0_2_3(); void TagUnitToV0_2_0(); void TagIncrementToV0_2_0(); diff --git a/src/libs/vmisc/def.h b/src/libs/vmisc/def.h index becdec863..d99a40f0b 100644 --- a/src/libs/vmisc/def.h +++ b/src/libs/vmisc/def.h @@ -54,6 +54,7 @@ enum class SceneObject : char { Point, Line, Spline, Arc, SplinePath, Detail, Un enum class MeasurementsType : char { Standard, Individual , Unknown}; enum class Unit : char { Mm = 0, Cm, Inch, Px, LAST_UNIT_DO_NOT_USE}; enum class Source : char { FromGui, FromFile, FromTool }; +enum class NodeUsage : bool {NotInUse = false, InUse = true}; typedef unsigned char ToolVisHolderType; enum class Tool : ToolVisHolderType diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolbasepoint.h b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolbasepoint.h index 7320ad877..5c1707934 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolbasepoint.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolbasepoint.h @@ -47,6 +47,7 @@ public: virtual int type() const Q_DECL_OVERRIDE {return Type;} enum { Type = UserType + static_cast(Tool::BasePoint)}; virtual void ShowVisualization(bool show) Q_DECL_OVERRIDE; + virtual void decrementReferens() Q_DECL_OVERRIDE; public slots: virtual void FullUpdateFromFile() Q_DECL_OVERRIDE; virtual void SetFactor(qreal factor) Q_DECL_OVERRIDE; @@ -60,7 +61,6 @@ protected: virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ) Q_DECL_OVERRIDE; virtual void AddToFile() Q_DECL_OVERRIDE; QVariant itemChange ( GraphicsItemChange change, const QVariant &value ); - virtual void decrementReferens() Q_DECL_OVERRIDE; virtual void DeleteTool(bool ask = true) Q_DECL_OVERRIDE; virtual void SaveDialog(QDomElement &domElement) Q_DECL_OVERRIDE; virtual void hoverEnterEvent ( QGraphicsSceneHoverEvent * event ) Q_DECL_OVERRIDE; diff --git a/src/libs/vtools/tools/nodeDetails/vabstractnode.cpp b/src/libs/vtools/tools/nodeDetails/vabstractnode.cpp index ec316c4e3..aaa754692 100644 --- a/src/libs/vtools/tools/nodeDetails/vabstractnode.cpp +++ b/src/libs/vtools/tools/nodeDetails/vabstractnode.cpp @@ -33,6 +33,7 @@ const QString VAbstractNode::AttrIdObject = QStringLiteral("idObject"); const QString VAbstractNode::AttrIdTool = QStringLiteral("idTool"); +const QString VAbstractNode::AttrInUse = QStringLiteral("inUse"); //--------------------------------------------------------------------------------------------------------------------- /** @@ -51,23 +52,6 @@ VAbstractNode::VAbstractNode(VAbstractPattern *doc, VContainer *data, const quin _referens = 0; } -//--------------------------------------------------------------------------------------------------------------------- -void VAbstractNode::DeleteNode() -{ - if (_referens <= 1) - { - RemoveReferens();//deincrement referens - } -} - -void VAbstractNode::RestoreNode() -{ - if (_referens <= 1) - { - RestoreReferens(); - } -} - //--------------------------------------------------------------------------------------------------------------------- void VAbstractNode::ShowVisualization(bool show) { @@ -75,14 +59,22 @@ void VAbstractNode::ShowVisualization(bool show) } //--------------------------------------------------------------------------------------------------------------------- -/** - * @brief AddToModeling add tag to modeling tag current pattern peace. - * @param domElement tag. - */ -void VAbstractNode::AddToModeling(const QDomElement &domElement) +void VAbstractNode::incrementReferens() { - AddDetNode *addNode = new AddDetNode(domElement, doc); - qApp->getUndoStack()->push(addNode); + if (_referens <= 0) + { + ++_referens; + } + if (_referens > 0) + { + idTool != NULL_ID ? doc->IncrementReferens(idTool) : doc->IncrementReferens(idNode); + ShowNode(); + QDomElement domElement = doc->elementById(id); + if (domElement.isElement()) + { + doc->SetParametrUsage(domElement, AttrInUse, NodeUsage::InUse); + } + } } //--------------------------------------------------------------------------------------------------------------------- @@ -97,41 +89,23 @@ void VAbstractNode::decrementReferens() } if (_referens <= 0) { - doc->DecrementReferens(idNode); + idTool != NULL_ID ? doc->DecrementReferens(idTool) : doc->DecrementReferens(idNode); + HideNode(); QDomElement domElement = doc->elementById(id); if (domElement.isElement()) { - QDomNode element = domElement.parentNode(); - if (element.isNull() == false) - { - element.removeChild(domElement); - } + doc->SetParametrUsage(domElement, AttrInUse, NodeUsage::NotInUse); } } } //--------------------------------------------------------------------------------------------------------------------- -void VAbstractNode::RemoveReferens() +/** + * @brief AddToModeling add tag to modeling tag current pattern peace. + * @param domElement tag. + */ +void VAbstractNode::AddToModeling(const QDomElement &domElement) { - if (idTool != 0) - { - doc->DecrementReferens(idTool); - } - else - { - doc->DecrementReferens(idNode); - } -} - -//--------------------------------------------------------------------------------------------------------------------- -void VAbstractNode::RestoreReferens() -{ - if (idTool != 0) - { - doc->IncrementReferens(idTool); - } - else - { - doc->IncrementReferens(idNode); - } + AddDetNode *addNode = new AddDetNode(domElement, doc); + qApp->getUndoStack()->push(addNode); } diff --git a/src/libs/vtools/tools/nodeDetails/vabstractnode.h b/src/libs/vtools/tools/nodeDetails/vabstractnode.h index 862dd1925..6c55136c0 100644 --- a/src/libs/vtools/tools/nodeDetails/vabstractnode.h +++ b/src/libs/vtools/tools/nodeDetails/vabstractnode.h @@ -45,9 +45,10 @@ public: virtual ~VAbstractNode() Q_DECL_OVERRIDE {} static const QString AttrIdObject; static const QString AttrIdTool; - virtual void DeleteNode(); - virtual void RestoreNode(); + static const QString AttrInUse; virtual void ShowVisualization(bool show) Q_DECL_OVERRIDE; + virtual void incrementReferens() Q_DECL_OVERRIDE; + virtual void decrementReferens() Q_DECL_OVERRIDE; protected: /** @brief idNodenode id. */ quint32 idNode; @@ -59,10 +60,10 @@ protected: QColor currentColor; void AddToModeling(const QDomElement &domElement); - virtual void decrementReferens() Q_DECL_OVERRIDE; - virtual void RemoveReferens() Q_DECL_OVERRIDE; - virtual void RestoreReferens(); virtual void SetVisualization() {} + + virtual void ShowNode()=0; + virtual void HideNode()=0; }; #endif // VABSTRACTNODE_H diff --git a/src/libs/vtools/tools/nodeDetails/vnodearc.cpp b/src/libs/vtools/tools/nodeDetails/vnodearc.cpp index 3bb868acb..4366d9d55 100644 --- a/src/libs/vtools/tools/nodeDetails/vnodearc.cpp +++ b/src/libs/vtools/tools/nodeDetails/vnodearc.cpp @@ -68,25 +68,37 @@ VNodeArc::VNodeArc(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 * @param idTool tool id. * @param parent QObject parent */ -void VNodeArc::Create(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 idArc, const Document &parse, - const Source &typeCreation, const quint32 &idTool, QObject *parent) +void VNodeArc::Create(VAbstractPattern *doc, VContainer *data, VMainGraphicsScene *scene, quint32 id, quint32 idArc, + const Document &parse, + const Source &typeCreation, const NodeUsage &inUse, const quint32 &idTool, QObject *parent) { VAbstractTool::AddRecord(id, Tool::NodeArc, doc); if (parse == Document::FullParse) { VNodeArc *arc = new VNodeArc(doc, data, id, idArc, typeCreation, idTool, parent); + + // Try to prevent memory leak + arc->hide();// If no one will use node, it will stay hidden + scene->addItem(arc);// First adopted by scene + doc->AddTool(id, arc); - if (idTool != 0) + if (idTool != NULL_ID) { - doc->IncrementReferens(idTool); + if (inUse == NodeUsage::InUse) + { + doc->IncrementReferens(idTool); + } //Some nodes we don't show on scene. Tool that create this nodes must free memory. VDataTool *tool = doc->getTool(idTool); SCASSERT(tool != nullptr); - arc->setParent(tool); + arc->setParent(tool);// Adopted by a tool } else { - doc->IncrementReferens(idArc); + if (inUse == NodeUsage::InUse) + { + doc->IncrementReferens(idArc); + } } } else @@ -95,26 +107,6 @@ void VNodeArc::Create(VAbstractPattern *doc, VContainer *data, quint32 id, quint } } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief DeleteNode delete node from detail. - */ -void VNodeArc::DeleteNode() -{ - VAbstractNode::DeleteNode(); - this->setVisible(false); -} - -//--------------------------------------------------------------------------------------------------------------------- -void VNodeArc::RestoreNode() -{ - if (this->isVisible() == false) - { - VAbstractNode::RestoreNode(); - this->setVisible(true); - } -} - //--------------------------------------------------------------------------------------------------------------------- QString VNodeArc::getTagName() const { @@ -203,6 +195,18 @@ void VNodeArc::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) this->setPen(QPen(currentColor, qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit())))); } +//--------------------------------------------------------------------------------------------------------------------- +void VNodeArc::ShowNode() +{ + show(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VNodeArc::HideNode() +{ + hide(); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief RefreshGeometry refresh item on scene. diff --git a/src/libs/vtools/tools/nodeDetails/vnodearc.h b/src/libs/vtools/tools/nodeDetails/vnodearc.h index a87822c74..a19208f13 100644 --- a/src/libs/vtools/tools/nodeDetails/vnodearc.h +++ b/src/libs/vtools/tools/nodeDetails/vnodearc.h @@ -42,12 +42,12 @@ public: VNodeArc(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 idArc, const Source &typeCreation, const quint32 &idTool = 0, QObject *qoParent = nullptr, QGraphicsItem * parent = nullptr); - static void Create(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 idArc, const Document &parse, - const Source &typeCreation, const quint32 &idTool = 0, QObject *parent = nullptr); + static void Create(VAbstractPattern *doc, VContainer *data, VMainGraphicsScene *scene, quint32 id, + quint32 idArc, const Document &parse, + const Source &typeCreation, const NodeUsage &inUse, const quint32 &idTool = 0, + QObject *parent = nullptr); static const QString TagName; static const QString ToolType; - virtual void DeleteNode() Q_DECL_OVERRIDE; - virtual void RestoreNode() Q_DECL_OVERRIDE; virtual int type() const Q_DECL_OVERRIDE {return Type;} enum { Type = UserType + static_cast(Tool::NodeArc)}; virtual QString getTagName() const Q_DECL_OVERRIDE; @@ -59,6 +59,8 @@ protected: virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ) Q_DECL_OVERRIDE; virtual void hoverMoveEvent ( QGraphicsSceneHoverEvent * event ) Q_DECL_OVERRIDE; virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ) Q_DECL_OVERRIDE; + virtual void ShowNode() Q_DECL_OVERRIDE; + virtual void HideNode() Q_DECL_OVERRIDE; private: void RefreshGeometry(); }; diff --git a/src/libs/vtools/tools/nodeDetails/vnodepoint.cpp b/src/libs/vtools/tools/nodeDetails/vnodepoint.cpp index dc25e90d0..c45ca6cad 100644 --- a/src/libs/vtools/tools/nodeDetails/vnodepoint.cpp +++ b/src/libs/vtools/tools/nodeDetails/vnodepoint.cpp @@ -81,7 +81,7 @@ VNodePoint::VNodePoint(VAbstractPattern *doc, VContainer *data, quint32 id, quin */ void VNodePoint::Create(VAbstractPattern *doc, VContainer *data, VMainGraphicsScene *scene, quint32 id, quint32 idPoint, const Document &parse, - const Source &typeCreation, const quint32 &idTool, QObject *parent) + const Source &typeCreation, const NodeUsage &inUse, const quint32 &idTool, QObject *parent) { VAbstractTool::AddRecord(id, Tool::NodePoint, doc); if (parse == Document::FullParse) @@ -89,19 +89,30 @@ void VNodePoint::Create(VAbstractPattern *doc, VContainer *data, VMainGraphicsSc //TODO Need create garbage collector and remove all nodes, what we don't use. //Better check garbage before each saving file. Check only modeling tags. VNodePoint *point = new VNodePoint(doc, data, id, idPoint, typeCreation, idTool, parent); + + // Try to prevent memory leak + point->hide();// If no one will use node, it will stay hidden + scene->addItem(point);// First adopted by scene + connect(scene, &VMainGraphicsScene::EnableToolMove, point, &VNodePoint::EnableToolMove); doc->AddTool(id, point); - if (idTool != 0) + if (idTool != NULL_ID) { - doc->IncrementReferens(idTool); + if (inUse == NodeUsage::InUse) + { + doc->IncrementReferens(idTool); + } //Some nodes we don't show on scene. Tool that create this nodes must free memory. VDataTool *tool = doc->getTool(idTool); SCASSERT(tool != nullptr); - point->setParent(tool); + point->setParent(tool);// Adopted by a tool } else { - doc->IncrementReferens(idPoint); + if (inUse == NodeUsage::InUse) + { + doc->IncrementReferens(idPoint); + } } } else @@ -110,26 +121,6 @@ void VNodePoint::Create(VAbstractPattern *doc, VContainer *data, VMainGraphicsSc } } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief DeleteNode delete node from detail. - */ -void VNodePoint::DeleteNode() -{ - VAbstractNode::DeleteNode(); - this->setVisible(false); -} - -//--------------------------------------------------------------------------------------------------------------------- -void VNodePoint::RestoreNode() -{ - if (this->isVisible() == false) - { - VAbstractNode::RestoreNode(); - this->setVisible(true); - } -} - //--------------------------------------------------------------------------------------------------------------------- QString VNodePoint::getTagName() const { @@ -291,6 +282,18 @@ void VNodePoint::RefreshLine() VAbstractTool::RefreshLine(this, namePoint, lineName, radius); } +//--------------------------------------------------------------------------------------------------------------------- +void VNodePoint::ShowNode() +{ + show(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VNodePoint::HideNode() +{ + hide(); +} + //--------------------------------------------------------------------------------------------------------------------- void VNodePoint::EnableToolMove(bool move) { diff --git a/src/libs/vtools/tools/nodeDetails/vnodepoint.h b/src/libs/vtools/tools/nodeDetails/vnodepoint.h index 112cd571e..93aa46dc0 100644 --- a/src/libs/vtools/tools/nodeDetails/vnodepoint.h +++ b/src/libs/vtools/tools/nodeDetails/vnodepoint.h @@ -50,11 +50,10 @@ public: static void Create(VAbstractPattern *doc, VContainer *data, VMainGraphicsScene *scene, quint32 id, quint32 idPoint, const Document &parse, - const Source &typeCreation, const quint32 &idTool = 0, QObject *parent = nullptr); + const Source &typeCreation, const NodeUsage &inUse, const quint32 &idTool = 0, + QObject *parent = nullptr); static const QString TagName; static const QString ToolType; - virtual void DeleteNode() Q_DECL_OVERRIDE; - virtual void RestoreNode() Q_DECL_OVERRIDE; virtual int type() const Q_DECL_OVERRIDE {return Type;} enum { Type = UserType + static_cast(Tool::NodePoint)}; virtual QString getTagName() const Q_DECL_OVERRIDE; @@ -81,6 +80,8 @@ protected: virtual void UpdateNamePosition(qreal mx, qreal my); virtual void RefreshPointGeometry(const VPointF &point); void RefreshLine(); + virtual void ShowNode() Q_DECL_OVERRIDE; + virtual void HideNode() Q_DECL_OVERRIDE; private: Q_DISABLE_COPY(VNodePoint) }; diff --git a/src/libs/vtools/tools/nodeDetails/vnodespline.cpp b/src/libs/vtools/tools/nodeDetails/vnodespline.cpp index 388e08a8d..bbf122f4c 100644 --- a/src/libs/vtools/tools/nodeDetails/vnodespline.cpp +++ b/src/libs/vtools/tools/nodeDetails/vnodespline.cpp @@ -69,27 +69,39 @@ VNodeSpline::VNodeSpline(VAbstractPattern *doc, VContainer *data, quint32 id, qu * @param idTool id node. * @return pointer to node. */ -VNodeSpline *VNodeSpline::Create(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 idSpline, - const Document &parse, - const Source &typeCreation, const quint32 &idTool, QObject *parent) +VNodeSpline *VNodeSpline::Create(VAbstractPattern *doc, VContainer *data, VMainGraphicsScene *scene, quint32 id, + quint32 idSpline, const Document &parse, + const Source &typeCreation, const NodeUsage &inUse, const quint32 &idTool, + QObject *parent) { VAbstractTool::AddRecord(id, Tool::NodeSpline, doc); VNodeSpline *spl = nullptr; if (parse == Document::FullParse) { spl = new VNodeSpline(doc, data, id, idSpline, typeCreation, idTool, parent); + + // Try to prevent memory leak + spl->hide();// If no one will use node, it will stay hidden + scene->addItem(spl);// First adopted by scene + doc->AddTool(id, spl); - if (idTool != 0) + if (idTool != NULL_ID) { - doc->IncrementReferens(idTool); + if (inUse == NodeUsage::InUse) + { + doc->IncrementReferens(idTool); + } //Some nodes we don't show on scene. Tool that create this nodes must free memory. VDataTool *tool = doc->getTool(idTool); SCASSERT(tool != nullptr); - spl->setParent(tool); + spl->setParent(tool);// Adopted by a tool } else { - doc->IncrementReferens(idSpline); + if (inUse == NodeUsage::InUse) + { + doc->IncrementReferens(idSpline); + } } } else @@ -99,26 +111,6 @@ VNodeSpline *VNodeSpline::Create(VAbstractPattern *doc, VContainer *data, quint3 return spl; } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief DeleteNode delete node from detail. - */ -void VNodeSpline::DeleteNode() -{ - VAbstractNode::DeleteNode(); - this->setVisible(false); -} - -//--------------------------------------------------------------------------------------------------------------------- -void VNodeSpline::RestoreNode() -{ - if (this->isVisible() == false) - { - VAbstractNode::RestoreNode(); - this->setVisible(true); - } -} - //--------------------------------------------------------------------------------------------------------------------- QString VNodeSpline::getTagName() const { @@ -206,6 +198,18 @@ void VNodeSpline::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) this->setPen(QPen(currentColor, qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit())))); } +//--------------------------------------------------------------------------------------------------------------------- +void VNodeSpline::ShowNode() +{ + show(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VNodeSpline::HideNode() +{ + hide(); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief RefreshGeometry refresh item on scene. diff --git a/src/libs/vtools/tools/nodeDetails/vnodespline.h b/src/libs/vtools/tools/nodeDetails/vnodespline.h index 531574637..69abfe3ec 100644 --- a/src/libs/vtools/tools/nodeDetails/vnodespline.h +++ b/src/libs/vtools/tools/nodeDetails/vnodespline.h @@ -42,13 +42,12 @@ public: VNodeSpline(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 idSpline, const Source &typeCreation, const quint32 &idTool = 0, QObject *qoParent = nullptr, QGraphicsItem * parent = nullptr); - static VNodeSpline *Create(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 idSpline, - const Document &parse, - const Source &typeCreation, const quint32 &idTool = 0, QObject *parent = nullptr); + static VNodeSpline *Create(VAbstractPattern *doc, VContainer *data, VMainGraphicsScene *scene, quint32 id, + quint32 idSpline, const Document &parse, + const Source &typeCreation, const NodeUsage &inUse, const quint32 &idTool = 0, + QObject *parent = nullptr); static const QString TagName; static const QString ToolType; - virtual void DeleteNode() Q_DECL_OVERRIDE; - virtual void RestoreNode() Q_DECL_OVERRIDE; virtual int type() const Q_DECL_OVERRIDE {return Type;} enum { Type = UserType + static_cast(Tool::NodeSpline)}; virtual QString getTagName() const Q_DECL_OVERRIDE; @@ -60,6 +59,8 @@ protected: virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ) Q_DECL_OVERRIDE; virtual void hoverMoveEvent ( QGraphicsSceneHoverEvent * event ) Q_DECL_OVERRIDE; virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ) Q_DECL_OVERRIDE; + virtual void ShowNode() Q_DECL_OVERRIDE; + virtual void HideNode() Q_DECL_OVERRIDE; private: void RefreshGeometry (); }; diff --git a/src/libs/vtools/tools/nodeDetails/vnodesplinepath.cpp b/src/libs/vtools/tools/nodeDetails/vnodesplinepath.cpp index 814a3da9e..0e1ce01c5 100644 --- a/src/libs/vtools/tools/nodeDetails/vnodesplinepath.cpp +++ b/src/libs/vtools/tools/nodeDetails/vnodesplinepath.cpp @@ -70,30 +70,41 @@ VNodeSplinePath::VNodeSplinePath(VAbstractPattern *doc, VContainer *data, quint3 * @param idTool tool id. * @param parent QObject parent. */ -void VNodeSplinePath::Create(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 idSpline, - const Document &parse, - const Source &typeCreation, const quint32 &idTool, QObject *parent) +void VNodeSplinePath::Create(VAbstractPattern *doc, VContainer *data, VMainGraphicsScene *scene, quint32 id, + quint32 idSpline, const Document &parse, + const Source &typeCreation, const NodeUsage &inUse, const quint32 &idTool, QObject *parent) { VAbstractTool::AddRecord(id, Tool::NodeSplinePath, doc); if (parse == Document::FullParse) { VNodeSplinePath *splPath = new VNodeSplinePath(doc, data, id, idSpline, typeCreation, idTool, parent); + + // Try to prevent memory leak + splPath->hide();// If no one will use node, it will stay hidden + scene->addItem(splPath);// First adopted by scene + doc->AddTool(id, splPath); const QSharedPointer path = data->GeometricObject(id); const QVector *points = path->GetPoint(); for (qint32 i = 0; isize(); ++i) { - if (idTool != 0) + if (idTool != NULL_ID) { - doc->IncrementReferens(idTool); + if (inUse == NodeUsage::InUse) + { + doc->IncrementReferens(idTool); + } //Some nodes we don't show on scene. Tool that create this nodes must free memory. VDataTool *tool = doc->getTool(idTool); SCASSERT(tool != nullptr); - splPath->setParent(tool); + splPath->setParent(tool);// Adopted by a tool } else { - doc->IncrementReferens(points->at(i).P().id()); + if (inUse == NodeUsage::InUse) + { + doc->IncrementReferens(points->at(i).P().id()); + } } } } @@ -103,26 +114,6 @@ void VNodeSplinePath::Create(VAbstractPattern *doc, VContainer *data, quint32 id } } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief DeleteNode delete node from detail. - */ -void VNodeSplinePath::DeleteNode() -{ - VAbstractNode::DeleteNode(); - this->setVisible(false); -} - -//--------------------------------------------------------------------------------------------------------------------- -void VNodeSplinePath::RestoreNode() -{ - if (this->isVisible() == false) - { - VAbstractNode::RestoreNode(); - this->setVisible(true); - } -} - //--------------------------------------------------------------------------------------------------------------------- QString VNodeSplinePath::getTagName() const { @@ -210,6 +201,18 @@ void VNodeSplinePath::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) this->setPen(QPen(currentColor, qApp->toPixel(WidthHairLine(*VAbstractTool::data.GetPatternUnit())))); } +//--------------------------------------------------------------------------------------------------------------------- +void VNodeSplinePath::ShowNode() +{ + show(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VNodeSplinePath::HideNode() +{ + hide(); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief RefreshGeometry refresh item on scene. diff --git a/src/libs/vtools/tools/nodeDetails/vnodesplinepath.h b/src/libs/vtools/tools/nodeDetails/vnodesplinepath.h index dcf9c7d21..d039db98c 100644 --- a/src/libs/vtools/tools/nodeDetails/vnodesplinepath.h +++ b/src/libs/vtools/tools/nodeDetails/vnodesplinepath.h @@ -41,12 +41,12 @@ class VNodeSplinePath : public VAbstractNode, public QGraphicsPathItem public: VNodeSplinePath(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 idSpline, const Source &typeCreation, const quint32 &idTool = 0, QObject *qoParent = nullptr, QGraphicsItem * parent = nullptr); - static void Create(VAbstractPattern *doc, VContainer *data, quint32 id, quint32 idSpline, const Document &parse, - const Source &typeCreation, const quint32 &idTool = 0, QObject *parent = 0); + static void Create(VAbstractPattern *doc, VContainer *data, VMainGraphicsScene *scene, quint32 id, + quint32 idSpline, const Document &parse, + const Source &typeCreation, const NodeUsage &inUse, const quint32 &idTool = 0, + QObject *parent = 0); static const QString TagName; static const QString ToolType; - virtual void DeleteNode() Q_DECL_OVERRIDE; - virtual void RestoreNode() Q_DECL_OVERRIDE; virtual int type() const Q_DECL_OVERRIDE {return Type;} enum { Type = UserType + static_cast(Tool::SplinePath)}; virtual QString getTagName() const Q_DECL_OVERRIDE; @@ -58,6 +58,8 @@ protected: virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ) Q_DECL_OVERRIDE; virtual void hoverMoveEvent ( QGraphicsSceneHoverEvent * event ) Q_DECL_OVERRIDE; virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ) Q_DECL_OVERRIDE; + virtual void ShowNode() Q_DECL_OVERRIDE; + virtual void HideNode() Q_DECL_OVERRIDE; private: void RefreshGeometry(); }; diff --git a/src/libs/vtools/tools/vtooldetail.cpp b/src/libs/vtools/tools/vtooldetail.cpp index 8f8f05247..262e419c2 100644 --- a/src/libs/vtools/tools/vtooldetail.cpp +++ b/src/libs/vtools/tools/vtooldetail.cpp @@ -162,25 +162,29 @@ void VToolDetail::Create(DialogTool *dialog, VMainGraphicsScene *scene, VAbstrac case (Tool::NodePoint): { id = CreateNode(data, nodeD.getId()); - VNodePoint::Create(doc, data, scene, id, nodeD.getId(), Document::FullParse, Source::FromGui); + VNodePoint::Create(doc, data, scene, id, nodeD.getId(), Document::FullParse, Source::FromGui, + NodeUsage::InUse); } break; case (Tool::NodeArc): { id = CreateNode(data, nodeD.getId()); - VNodeArc::Create(doc, data, id, nodeD.getId(), Document::FullParse, Source::FromGui); + VNodeArc::Create(doc, data, scene, id, nodeD.getId(), Document::FullParse, Source::FromGui, + NodeUsage::InUse); } break; case (Tool::NodeSpline): { id = CreateNode(data, nodeD.getId()); - VNodeSpline::Create(doc, data, id, nodeD.getId(), Document::FullParse, Source::FromGui); + VNodeSpline::Create(doc, data, scene, id, nodeD.getId(), Document::FullParse, Source::FromGui, + NodeUsage::InUse); } break; case (Tool::NodeSplinePath): { id = CreateNode(data, nodeD.getId()); - VNodeSplinePath::Create(doc, data, id, nodeD.getId(), Document::FullParse, Source::FromGui); + VNodeSplinePath::Create(doc, data, scene, id, nodeD.getId(), Document::FullParse, Source::FromGui, + NodeUsage::InUse); } break; default: @@ -306,7 +310,7 @@ void VToolDetail::AddToFile() AddNode(doc, domElement, detail.at(i)); } - AddDet *addDet = new AddDet(domElement, doc); + AddDet *addDet = new AddDet(domElement, doc, detail); connect(addDet, &AddDet::NeedFullParsing, doc, &VAbstractPattern::NeedFullParsing); qApp->getUndoStack()->push(addDet); } @@ -499,19 +503,6 @@ void VToolDetail::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) } } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief RemoveReferens decrement value of reference. - */ -void VToolDetail::RemoveReferens() -{ - VDetail detail = VAbstractTool::data.GetDetail(id); - for (int i = 0; i< detail.CountNode(); ++i) - { - doc->DecrementReferens(detail.at(i).getId()); - } -} - //--------------------------------------------------------------------------------------------------------------------- /** * @brief AddNode add node to the file. @@ -588,7 +579,7 @@ void VToolDetail::RefreshGeometry() //--------------------------------------------------------------------------------------------------------------------- void VToolDetail::DeleteTool(bool ask) { - DeleteDetail *delDet = new DeleteDetail(doc, id); + DeleteDetail *delDet = new DeleteDetail(doc, id, VAbstractTool::data.GetDetail(id)); if (ask) { if (ConfirmDeletion() == QMessageBox::No) diff --git a/src/libs/vtools/tools/vtooldetail.h b/src/libs/vtools/tools/vtooldetail.h index 91670dd09..f4be08e2c 100644 --- a/src/libs/vtools/tools/vtooldetail.h +++ b/src/libs/vtools/tools/vtooldetail.h @@ -100,7 +100,6 @@ protected: virtual void hoverEnterEvent ( QGraphicsSceneHoverEvent * event ) Q_DECL_OVERRIDE; virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ) Q_DECL_OVERRIDE; virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ) Q_DECL_OVERRIDE; - virtual void RemoveReferens() Q_DECL_OVERRIDE; virtual void keyReleaseEvent(QKeyEvent * event) Q_DECL_OVERRIDE; virtual void SetVisualization() Q_DECL_OVERRIDE {} private: diff --git a/src/libs/vtools/tools/vtooluniondetails.cpp b/src/libs/vtools/tools/vtooluniondetails.cpp index 4302c43cd..80e538758 100644 --- a/src/libs/vtools/tools/vtooluniondetails.cpp +++ b/src/libs/vtools/tools/vtooluniondetails.cpp @@ -105,7 +105,8 @@ void VToolUnionDetails::AddToNewDetail(QObject *tool, VMainGraphicsScene *scene, VPointF *point1 = new VPointF(*point); point1->setMode(Draw::Modeling); id = data->AddGObject(point1); - VNodePoint::Create(doc, data, scene, id, idObject, Document::FullParse, Source::FromGui, idTool, tool); + VNodePoint::Create(doc, data, scene, id, idObject, Document::FullParse, Source::FromGui, + NodeUsage::InUse, idTool, tool); } } break; @@ -117,7 +118,7 @@ void VToolUnionDetails::AddToNewDetail(QObject *tool, VMainGraphicsScene *scene, } else { - const QPointF p = data->GeometricObject(pRotate)->toQPointF(); + const QPointF p = data->GeometricObject(pRotate)->toQPointF(); const QSharedPointer arc = data->GeometricObject(det.at(i).getId()); VPointF p1 = VPointF(arc->GetP1(), "A", 0, 0); BiasRotatePoint(&p1, dx, dy, p, angle); @@ -141,7 +142,8 @@ void VToolUnionDetails::AddToNewDetail(QObject *tool, VMainGraphicsScene *scene, arc2->setMode(Draw::Modeling); id = data->AddGObject(arc2); - VNodeArc::Create(doc, data, id, idObject, Document::FullParse, Source::FromGui, idTool, tool); + VNodeArc::Create(doc, data, scene, id, idObject, Document::FullParse, Source::FromGui, NodeUsage::InUse, + idTool, tool); } } break; @@ -155,7 +157,7 @@ void VToolUnionDetails::AddToNewDetail(QObject *tool, VMainGraphicsScene *scene, { const QSharedPointer spline = data->GeometricObject(det.at(i).getId()); - const QPointF p = data->GeometricObject(pRotate)->toQPointF(); + const QPointF p = data->GeometricObject(pRotate)->toQPointF(); VPointF *p1 = new VPointF(spline->GetP1()); BiasRotatePoint(p1, dx, dy, p, angle); @@ -175,7 +177,8 @@ void VToolUnionDetails::AddToNewDetail(QObject *tool, VMainGraphicsScene *scene, VSpline *spl1 = new VSpline(*spl); spl1->setMode(Draw::Modeling); id = data->AddGObject(spl1); - VNodeSpline::Create(doc, data, id, idObject, Document::FullParse, Source::FromGui, idTool, tool); + VNodeSpline::Create(doc, data, scene, id, idObject, Document::FullParse, Source::FromGui, + NodeUsage::InUse, idTool, tool); delete p4; delete p1; @@ -195,13 +198,13 @@ void VToolUnionDetails::AddToNewDetail(QObject *tool, VMainGraphicsScene *scene, const QSharedPointer splinePath = data->GeometricObject(det.at(i).getId()); for (qint32 i = 1; i <= splinePath->Count(); ++i) { - const VSplinePoint &point1 = splinePath->at(i-1); - const VSplinePoint &point2 = splinePath->at(i); + const VSplinePoint &point1 = splinePath->at(i-1); + const VSplinePoint &point2 = splinePath->at(i); VSpline spline(point1.P(), point2.P(), point1.Angle2(), point2.Angle1(), point1.KAsm2(), point2.KAsm1(), splinePath->GetKCurve()); - const QPointF p = data->GeometricObject(pRotate)->toQPointF(); + const QPointF p = data->GeometricObject(pRotate)->toQPointF(); VPointF *p1 = new VPointF(spline.GetP1()); BiasRotatePoint(p1, dx, dy, p, angle); @@ -230,7 +233,8 @@ void VToolUnionDetails::AddToNewDetail(QObject *tool, VMainGraphicsScene *scene, VSplinePath *path1 = new VSplinePath(*path); path1->setMode(Draw::Modeling); id = data->AddGObject(path1); - VNodeSplinePath::Create(doc, data, id, idObject, Document::FullParse, Source::FromGui, idTool, tool); + VNodeSplinePath::Create(doc, data, scene, id, idObject, Document::FullParse, Source::FromGui, + NodeUsage::InUse, idTool, tool); } } break; @@ -278,7 +282,7 @@ void VToolUnionDetails::UpdatePoints(const quint32 &idDetail, VContainer *data, { if (qFuzzyCompare(dx+1, 1) == false || qFuzzyCompare(dy+1, 1) == false || pRotate != 0) { - const QPointF p = data->GeometricObject(pRotate)->toQPointF(); + const QPointF p = data->GeometricObject(pRotate)->toQPointF(); const QSharedPointer arc = data->GeometricObject(det.at(i).getId()); VPointF p1 = VPointF(arc->GetP1()); BiasRotatePoint(&p1, dx, dy, p, angle); @@ -309,7 +313,7 @@ void VToolUnionDetails::UpdatePoints(const quint32 &idDetail, VContainer *data, { const QSharedPointer spline = data->GeometricObject(det.at(i).getId()); - const QPointF p = data->GeometricObject(pRotate)->toQPointF(); + const QPointF p = data->GeometricObject(pRotate)->toQPointF(); VPointF *p1 = new VPointF(spline->GetP1()); BiasRotatePoint(p1, dx, dy, p, angle); @@ -344,13 +348,13 @@ void VToolUnionDetails::UpdatePoints(const quint32 &idDetail, VContainer *data, SCASSERT(splinePath != nullptr); for (qint32 i = 1; i <= splinePath->Count(); ++i) { - const VSplinePoint &point1 = splinePath->at(i-1); - const VSplinePoint &point2 = splinePath->at(i); + const VSplinePoint &point1 = splinePath->at(i-1); + const VSplinePoint &point2 = splinePath->at(i); VSpline spline(point1.P(), point2.P(), point1.Angle2(), point2.Angle1(), point1.KAsm2(), point2.KAsm1(), splinePath->GetKCurve()); - const QPointF p = data->GeometricObject(pRotate)->toQPointF(); + const QPointF p = data->GeometricObject(pRotate)->toQPointF(); VPointF *p1 = new VPointF(spline.GetP1()); BiasRotatePoint(p1, dx, dy, p, angle); @@ -438,8 +442,8 @@ VToolUnionDetails* VToolUnionDetails::Create(DialogTool *dialog, VMainGraphicsSc quint32 indexD1 = static_cast(dialogTool->getIndexD1()); quint32 indexD2 = static_cast(dialogTool->getIndexD2()); qApp->getUndoStack()->beginMacro("union details"); - VToolUnionDetails* tool = Create(0, d1, d2, dialogTool->getD1(), dialogTool->getD2(), indexD1, indexD2, scene, - doc, data, Document::FullParse, Source::FromGui); + VToolUnionDetails* tool = Create(0, d1, d2, dialogTool->getD1(), dialogTool->getD2(), indexD1, indexD2, scene, + doc, data, Document::FullParse, Source::FromGui); qApp->getUndoStack()->endMacro(); return tool; } diff --git a/src/libs/vtools/undocommands/adddet.cpp b/src/libs/vtools/undocommands/adddet.cpp index 7ecc54b3d..5fbd7a1e2 100644 --- a/src/libs/vtools/undocommands/adddet.cpp +++ b/src/libs/vtools/undocommands/adddet.cpp @@ -29,8 +29,8 @@ #include "adddet.h" //--------------------------------------------------------------------------------------------------------------------- -AddDet::AddDet(const QDomElement &xml, VAbstractPattern *doc, QUndoCommand *parent) - : VUndoCommand(xml, doc, parent) +AddDet::AddDet(const QDomElement &xml, VAbstractPattern *doc, const VDetail &detail, QUndoCommand *parent) + : VUndoCommand(xml, doc, parent), detail(detail) { setText(tr("add detail")); nodeId = doc->GetParametrId(xml); @@ -57,6 +57,15 @@ void AddDet::undo() qCDebug(vUndo, "Can't delete node"); return; } + + QVector nodes = detail.getNodes(); + if (nodes.size()>0) + { + for (qint32 i = 0; i < nodes.size(); ++i) + { + doc->DecrementReferens(nodes.at(i).getId()); + } + } } else { diff --git a/src/libs/vtools/undocommands/adddet.h b/src/libs/vtools/undocommands/adddet.h index a4cc094fe..0bbfa4f1d 100644 --- a/src/libs/vtools/undocommands/adddet.h +++ b/src/libs/vtools/undocommands/adddet.h @@ -30,12 +30,13 @@ #define ADDDET_H #include "vundocommand.h" +#include "../tools/vtooldetail.h" class AddDet : public VUndoCommand { Q_OBJECT public: - AddDet(const QDomElement &xml, VAbstractPattern *doc, QUndoCommand *parent = 0); + AddDet(const QDomElement &xml, VAbstractPattern *doc, const VDetail &detail, QUndoCommand *parent = 0); virtual ~AddDet() Q_DECL_OVERRIDE; // cppcheck-suppress unusedFunction virtual void undo() Q_DECL_OVERRIDE; @@ -43,6 +44,7 @@ public: virtual void redo() Q_DECL_OVERRIDE; private: Q_DISABLE_COPY(AddDet) + VDetail detail; }; #endif // ADDDET_H diff --git a/src/libs/vtools/undocommands/deletedetail.cpp b/src/libs/vtools/undocommands/deletedetail.cpp index c3c0de113..dd4be5d6c 100644 --- a/src/libs/vtools/undocommands/deletedetail.cpp +++ b/src/libs/vtools/undocommands/deletedetail.cpp @@ -30,8 +30,8 @@ #include "../tools/vtooldetail.h" //--------------------------------------------------------------------------------------------------------------------- -DeleteDetail::DeleteDetail(VAbstractPattern *doc, quint32 id, QUndoCommand *parent) - : VUndoCommand(QDomElement(), doc, parent), parentNode(QDomNode()), siblingId(NULL_ID) +DeleteDetail::DeleteDetail(VAbstractPattern *doc, quint32 id, const VDetail &detail, QUndoCommand *parent) + : VUndoCommand(QDomElement(), doc, parent), parentNode(QDomNode()), siblingId(NULL_ID), detail(detail) { setText(tr("delete tool")); nodeId = id; @@ -89,6 +89,15 @@ void DeleteDetail::redo() SCASSERT(toolDet != nullptr); toolDet->hide(); + QVector nodes = detail.getNodes(); + if (nodes.size()>0) + { + for (qint32 i = 0; i < nodes.size(); ++i) + { + doc->DecrementReferens(nodes.at(i).getId()); + } + } + emit NeedFullParsing(); // Doesn't work when UnionDetail delete detail. } else diff --git a/src/libs/vtools/undocommands/deletedetail.h b/src/libs/vtools/undocommands/deletedetail.h index dc2654053..780d10f75 100644 --- a/src/libs/vtools/undocommands/deletedetail.h +++ b/src/libs/vtools/undocommands/deletedetail.h @@ -30,13 +30,15 @@ #define DELETEDETAIL_H #include "vundocommand.h" +#include "../tools/vtooldetail.h" + class QGraphicsItem; class DeleteDetail : public VUndoCommand { Q_OBJECT public: - DeleteDetail(VAbstractPattern *doc, quint32 id, QUndoCommand *parent = 0); + DeleteDetail(VAbstractPattern *doc, quint32 id, const VDetail &detail, QUndoCommand *parent = 0); virtual ~DeleteDetail() Q_DECL_OVERRIDE; virtual void undo() Q_DECL_OVERRIDE; virtual void redo() Q_DECL_OVERRIDE; @@ -44,6 +46,7 @@ private: Q_DISABLE_COPY(DeleteDetail) QDomNode parentNode; quint32 siblingId; + VDetail detail; }; #endif // DELETEDETAIL_H diff --git a/src/libs/vtools/undocommands/savedetailoptions.cpp b/src/libs/vtools/undocommands/savedetailoptions.cpp index 7c77c99d9..fe5d270e5 100644 --- a/src/libs/vtools/undocommands/savedetailoptions.cpp +++ b/src/libs/vtools/undocommands/savedetailoptions.cpp @@ -60,13 +60,10 @@ void SaveDetailOptions::undo() VToolDetail::AddNode(doc, domElement, oldDet.at(i)); } QVector nodes = oldDet.getNodes(); - QHash* tools = doc->getTools(); if (nodes.size()>0) { for (qint32 i = 0; i < nodes.size(); ++i) { - VAbstractNode *node = qobject_cast(tools->value(nodes.at(i).getId())); - node->RestoreNode(); doc->IncrementReferens(nodes.at(i).getId()); } } @@ -94,13 +91,10 @@ void SaveDetailOptions::redo() VToolDetail::AddNode(doc, domElement, newDet.at(i)); } QList list = oldDet.Missing(newDet); - QHash* tools = doc->getTools(); if (list.size()>0) { for (qint32 i = 0; i < list.size(); ++i) { - VAbstractNode *node = qobject_cast(tools->value(list.at(i))); - node->DeleteNode(); doc->DecrementReferens(list.at(i)); } }