From 3e363aea81daa56d0d6059d4404875ba91c9860b Mon Sep 17 00:00:00 2001 From: dismine Date: Mon, 16 Jun 2014 20:08:23 +0300 Subject: [PATCH] Cppcheck. Fix for garbage collector. --HG-- branch : develop --- src/app/container/vcontainer.cpp | 53 ---------------------- src/app/container/vcontainer.h | 1 - src/app/exception/vexception.cpp | 1 + src/app/exception/vexception.h | 1 + src/app/tools/vtooldetail.cpp | 1 + src/app/undocommands/adddet.cpp | 2 + src/app/undocommands/adddet.h | 2 + src/app/undocommands/deletedetail.cpp | 1 + src/app/undocommands/movedetail.cpp | 1 + src/app/undocommands/movedetail.h | 1 + src/app/undocommands/savedetailoptions.cpp | 2 + src/app/widgets/vapplication.cpp | 12 ----- src/app/widgets/vapplication.h | 2 - src/app/widgets/vcontrolpointspline.h | 2 +- src/app/widgets/vgraphicssimpletextitem.h | 2 +- src/app/xml/vdomdocument.cpp | 1 + src/app/xml/vpattern.cpp | 15 +++--- 17 files changed, 24 insertions(+), 76 deletions(-) diff --git a/src/app/container/vcontainer.cpp b/src/app/container/vcontainer.cpp index ad74f2ae2..1ff67ac16 100644 --- a/src/app/container/vcontainer.cpp +++ b/src/app/container/vcontainer.cpp @@ -463,59 +463,6 @@ void VContainer::ClearCalculationGObjects() } } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief FindVar return value of variable by name - * @param name name of variable - * @param ok false if can't find variable - * @return value of variable - */ -qreal VContainer::FindVar(const QString &name, bool *ok)const -{ - if (sizeName == name) - { - *ok = true; - return _size; - } - if (heightName == name) - { - *ok = true; - return _height; - } - if (measurements.contains(name)) - { - *ok = true; - return GetValueStandardTableRow(name); - } - if (increments.contains(name)) - { - *ok = true; - return GetValueIncrementTableRow(name); - } - if (lengthLines.contains(name)) - { - *ok = true; - return lengthLines.value(name); - } - if (lengthArcs.contains(name)) - { - *ok = true; - return lengthArcs.value(name); - } - if (lineAngles.contains(name)) - { - *ok = true; - return lineAngles.value(name); - } - if (lengthSplines.contains(name)) - { - *ok = true; - return lengthSplines.value(name); - } - *ok = false; - return 0; -} - //--------------------------------------------------------------------------------------------------------------------- /** * @brief AddLine add line to container diff --git a/src/app/container/vcontainer.h b/src/app/container/vcontainer.h index fd9652895..091ae9d68 100644 --- a/src/app/container/vcontainer.h +++ b/src/app/container/vcontainer.h @@ -127,7 +127,6 @@ public: QString SizeName()const; qreal height() const; QString HeightName()const; - qreal FindVar(const QString& name, bool *ok)const; bool IncrementTableContains(const QString& name); static quint32 getNextId(); void RemoveIncrementTableRow(const QString& name); diff --git a/src/app/exception/vexception.cpp b/src/app/exception/vexception.cpp index 5722e1f16..a0e06ebbc 100644 --- a/src/app/exception/vexception.cpp +++ b/src/app/exception/vexception.cpp @@ -133,6 +133,7 @@ QString VException::DetailedInformation() const * @brief clone clone exception * @return new exception */ +// cppcheck-suppress unusedFunction VException *VException::clone() const { return new VException(*this); diff --git a/src/app/exception/vexception.h b/src/app/exception/vexception.h index f524ee751..721e73132 100644 --- a/src/app/exception/vexception.h +++ b/src/app/exception/vexception.h @@ -47,6 +47,7 @@ public: virtual ~VException() noexcept (true){} virtual void raise() const; + // cppcheck-suppress unusedFunction virtual VException *clone() const; virtual QString ErrorMessage() const; virtual QString DetailedInformation() const; diff --git a/src/app/tools/vtooldetail.cpp b/src/app/tools/vtooldetail.cpp index e42edb6b7..1d09f48d4 100644 --- a/src/app/tools/vtooldetail.cpp +++ b/src/app/tools/vtooldetail.cpp @@ -586,4 +586,5 @@ void VToolDetail::InitTool(VMainGraphicsScene *scene, const VNodeDetail &node) SCASSERT(tool != nullptr); connect(tool, &Tool::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); tool->setParentItem(this); + doc->IncrementReferens(node.getId()); } diff --git a/src/app/undocommands/adddet.cpp b/src/app/undocommands/adddet.cpp index d927f3f47..2b001e695 100644 --- a/src/app/undocommands/adddet.cpp +++ b/src/app/undocommands/adddet.cpp @@ -41,6 +41,7 @@ AddDet::~AddDet() {} //--------------------------------------------------------------------------------------------------------------------- +// cppcheck-suppress unusedFunction void AddDet::undo() { QDomElement element; @@ -57,6 +58,7 @@ void AddDet::undo() } //--------------------------------------------------------------------------------------------------------------------- +// cppcheck-suppress unusedFunction void AddDet::redo() { QDomElement element; diff --git a/src/app/undocommands/adddet.h b/src/app/undocommands/adddet.h index d6bb40dec..b21bbe201 100644 --- a/src/app/undocommands/adddet.h +++ b/src/app/undocommands/adddet.h @@ -40,7 +40,9 @@ class AddDet : public QObject, public QUndoCommand public: AddDet(const QDomElement &xml, VPattern *doc, QUndoCommand *parent = 0); virtual ~AddDet(); + // cppcheck-suppress unusedFunction virtual void undo(); + // cppcheck-suppress unusedFunction virtual void redo(); signals: void NeedFullParsing(); diff --git a/src/app/undocommands/deletedetail.cpp b/src/app/undocommands/deletedetail.cpp index f6196604a..2a0c9345e 100644 --- a/src/app/undocommands/deletedetail.cpp +++ b/src/app/undocommands/deletedetail.cpp @@ -67,6 +67,7 @@ void DeleteDetail::redo() { parentNode.removeChild(domElement); + //When UnionDetail delete detail we can't use FullParsing. So we hide detail on scene directly. QHash* tools = doc->getTools(); SCASSERT(tools != nullptr); VToolDetail *toolDet = qobject_cast(tools->value(detId)); diff --git a/src/app/undocommands/movedetail.cpp b/src/app/undocommands/movedetail.cpp index 84270c8ac..8e5e173e8 100644 --- a/src/app/undocommands/movedetail.cpp +++ b/src/app/undocommands/movedetail.cpp @@ -107,6 +107,7 @@ void MoveDetail::redo() } //--------------------------------------------------------------------------------------------------------------------- +// cppcheck-suppress unusedFunction bool MoveDetail::mergeWith(const QUndoCommand *command) { const MoveDetail *moveCommand = static_cast(command); diff --git a/src/app/undocommands/movedetail.h b/src/app/undocommands/movedetail.h index aa5e8520b..d8871e6ee 100644 --- a/src/app/undocommands/movedetail.h +++ b/src/app/undocommands/movedetail.h @@ -43,6 +43,7 @@ public: virtual ~MoveDetail(); virtual void undo(); virtual void redo(); + // cppcheck-suppress unusedFunction virtual bool mergeWith(const QUndoCommand *command); virtual int id() const; quint32 getDetId() const; diff --git a/src/app/undocommands/savedetailoptions.cpp b/src/app/undocommands/savedetailoptions.cpp index 500bafe6b..491449ffc 100644 --- a/src/app/undocommands/savedetailoptions.cpp +++ b/src/app/undocommands/savedetailoptions.cpp @@ -65,6 +65,7 @@ void SaveDetailOptions::undo() { VAbstractNode *node = qobject_cast(tools->value(nodes.at(i).getId())); node->RestoreNode(); + doc->IncrementReferens(nodes.at(i).getId()); } } emit NeedLiteParsing(); @@ -102,6 +103,7 @@ void SaveDetailOptions::redo() { VAbstractNode *node = qobject_cast(tools->value(list.at(i))); node->DeleteNode(); + doc->DecrementReferens(list.at(i)); } } emit NeedLiteParsing(); diff --git a/src/app/widgets/vapplication.cpp b/src/app/widgets/vapplication.cpp index eb5d6b7d4..6e7bb7f47 100644 --- a/src/app/widgets/vapplication.cpp +++ b/src/app/widgets/vapplication.cpp @@ -1716,18 +1716,6 @@ QString VApplication::Description(const QString &measurement) const return descriptions.value(measurement).translate(); } -//--------------------------------------------------------------------------------------------------------------------- -QString VApplication::Variable(const QString &name) const -{ - return variables.value(name).translate(); -} - -//--------------------------------------------------------------------------------------------------------------------- -QString VApplication::Function(const QString &name) const -{ - return functions.value(name).translate(); -} - //--------------------------------------------------------------------------------------------------------------------- QString VApplication::PostfixOperator(const QString &name) const { diff --git a/src/app/widgets/vapplication.h b/src/app/widgets/vapplication.h index acbf8bb57..6f051bf91 100644 --- a/src/app/widgets/vapplication.h +++ b/src/app/widgets/vapplication.h @@ -67,8 +67,6 @@ public: QString VarFromUser(const QString &var) const; QString GuiText(const QString &measurement) const; QString Description(const QString &measurement) const; - QString Variable(const QString &name) const; - QString Function(const QString &name) const; QString PostfixOperator(const QString &name) const; QString FormulaFromUser(const QString &formula); QString FormulaToUser(const QString &formula); diff --git a/src/app/widgets/vcontrolpointspline.h b/src/app/widgets/vcontrolpointspline.h index b29686827..cb6283378 100644 --- a/src/app/widgets/vcontrolpointspline.h +++ b/src/app/widgets/vcontrolpointspline.h @@ -50,7 +50,7 @@ signals: * @param pos new posotion. */ void ControlPointChangePosition(const qint32 &indexSpline, SplinePointPosition position, - const QPointF pos); + const QPointF &pos); public slots: void RefreshLine(const qint32 &indexSpline, SplinePointPosition pos, const QPointF &controlPoint, const QPointF &splinePoint); diff --git a/src/app/widgets/vgraphicssimpletextitem.h b/src/app/widgets/vgraphicssimpletextitem.h index 89d7da52b..283473dd5 100644 --- a/src/app/widgets/vgraphicssimpletextitem.h +++ b/src/app/widgets/vgraphicssimpletextitem.h @@ -53,7 +53,7 @@ signals: * @brief NameChangePosition emit when label change position. * @param pos new posotion. */ - void NameChangePosition(const QPointF pos); + void NameChangePosition(const QPointF &pos); /** * @brief ShowContextMenu emit when need show tool context menu. * @param event context menu event. diff --git a/src/app/xml/vdomdocument.cpp b/src/app/xml/vdomdocument.cpp index e20845a25..e4c8e23f9 100644 --- a/src/app/xml/vdomdocument.cpp +++ b/src/app/xml/vdomdocument.cpp @@ -76,6 +76,7 @@ inline qint64 MessageHandler::column() const } //--------------------------------------------------------------------------------------------------------------------- +// cppcheck-suppress unusedFunction void MessageHandler::handleMessage(QtMsgType type, const QString &description, const QUrl &identifier, const QSourceLocation &sourceLocation) { diff --git a/src/app/xml/vpattern.cpp b/src/app/xml/vpattern.cpp index 4151e75e7..b56eff246 100644 --- a/src/app/xml/vpattern.cpp +++ b/src/app/xml/vpattern.cpp @@ -637,6 +637,7 @@ bool VPattern::SaveDocument(const QString &fileName) e.CriticalMessageBox(tr("Error no unique id.")); return false; } + GarbageCollector(); return VDomDocument::SaveDocument(fileName); } @@ -1868,17 +1869,19 @@ void VPattern::UpdateMeasurements() void VPattern::GarbageCollector() { QHashIterator t(tools); - while (t.hasNext()) { + while (t.hasNext()) + { t.next(); VDataTool *tool = t.value(); - if(tool->referens() <= 0){ + if(tool->referens() <= 1) + { QDomElement domElement = elementById(QString().setNum(t.key())); - if(domElement.isElement()){ + if(domElement.isElement()) + { QDomNode parent = domElement.parentNode(); - if(!parent.isNull()){ + if(parent.isNull() == false && parent.toElement().tagName() == TagModeling) + { parent.removeChild(domElement); - } else { - qWarning()<