Cppcheck. Fix for garbage collector.

--HG--
branch : develop
This commit is contained in:
dismine 2014-06-16 20:08:23 +03:00
parent 0101a6f56c
commit 3e363aea81
17 changed files with 24 additions and 76 deletions

View File

@ -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 * @brief AddLine add line to container

View File

@ -127,7 +127,6 @@ public:
QString SizeName()const; QString SizeName()const;
qreal height() const; qreal height() const;
QString HeightName()const; QString HeightName()const;
qreal FindVar(const QString& name, bool *ok)const;
bool IncrementTableContains(const QString& name); bool IncrementTableContains(const QString& name);
static quint32 getNextId(); static quint32 getNextId();
void RemoveIncrementTableRow(const QString& name); void RemoveIncrementTableRow(const QString& name);

View File

@ -133,6 +133,7 @@ QString VException::DetailedInformation() const
* @brief clone clone exception * @brief clone clone exception
* @return new exception * @return new exception
*/ */
// cppcheck-suppress unusedFunction
VException *VException::clone() const VException *VException::clone() const
{ {
return new VException(*this); return new VException(*this);

View File

@ -47,6 +47,7 @@ public:
virtual ~VException() noexcept (true){} virtual ~VException() noexcept (true){}
virtual void raise() const; virtual void raise() const;
// cppcheck-suppress unusedFunction
virtual VException *clone() const; virtual VException *clone() const;
virtual QString ErrorMessage() const; virtual QString ErrorMessage() const;
virtual QString DetailedInformation() const; virtual QString DetailedInformation() const;

View File

@ -586,4 +586,5 @@ void VToolDetail::InitTool(VMainGraphicsScene *scene, const VNodeDetail &node)
SCASSERT(tool != nullptr); SCASSERT(tool != nullptr);
connect(tool, &Tool::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); connect(tool, &Tool::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
tool->setParentItem(this); tool->setParentItem(this);
doc->IncrementReferens(node.getId());
} }

View File

@ -41,6 +41,7 @@ AddDet::~AddDet()
{} {}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
// cppcheck-suppress unusedFunction
void AddDet::undo() void AddDet::undo()
{ {
QDomElement element; QDomElement element;
@ -57,6 +58,7 @@ void AddDet::undo()
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
// cppcheck-suppress unusedFunction
void AddDet::redo() void AddDet::redo()
{ {
QDomElement element; QDomElement element;

View File

@ -40,7 +40,9 @@ class AddDet : public QObject, public QUndoCommand
public: public:
AddDet(const QDomElement &xml, VPattern *doc, QUndoCommand *parent = 0); AddDet(const QDomElement &xml, VPattern *doc, QUndoCommand *parent = 0);
virtual ~AddDet(); virtual ~AddDet();
// cppcheck-suppress unusedFunction
virtual void undo(); virtual void undo();
// cppcheck-suppress unusedFunction
virtual void redo(); virtual void redo();
signals: signals:
void NeedFullParsing(); void NeedFullParsing();

View File

@ -67,6 +67,7 @@ void DeleteDetail::redo()
{ {
parentNode.removeChild(domElement); parentNode.removeChild(domElement);
//When UnionDetail delete detail we can't use FullParsing. So we hide detail on scene directly.
QHash<quint32, VDataTool*>* tools = doc->getTools(); QHash<quint32, VDataTool*>* tools = doc->getTools();
SCASSERT(tools != nullptr); SCASSERT(tools != nullptr);
VToolDetail *toolDet = qobject_cast<VToolDetail*>(tools->value(detId)); VToolDetail *toolDet = qobject_cast<VToolDetail*>(tools->value(detId));

View File

@ -107,6 +107,7 @@ void MoveDetail::redo()
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
// cppcheck-suppress unusedFunction
bool MoveDetail::mergeWith(const QUndoCommand *command) bool MoveDetail::mergeWith(const QUndoCommand *command)
{ {
const MoveDetail *moveCommand = static_cast<const MoveDetail *>(command); const MoveDetail *moveCommand = static_cast<const MoveDetail *>(command);

View File

@ -43,6 +43,7 @@ public:
virtual ~MoveDetail(); virtual ~MoveDetail();
virtual void undo(); virtual void undo();
virtual void redo(); virtual void redo();
// cppcheck-suppress unusedFunction
virtual bool mergeWith(const QUndoCommand *command); virtual bool mergeWith(const QUndoCommand *command);
virtual int id() const; virtual int id() const;
quint32 getDetId() const; quint32 getDetId() const;

View File

@ -65,6 +65,7 @@ void SaveDetailOptions::undo()
{ {
VAbstractNode *node = qobject_cast<VAbstractNode *>(tools->value(nodes.at(i).getId())); VAbstractNode *node = qobject_cast<VAbstractNode *>(tools->value(nodes.at(i).getId()));
node->RestoreNode(); node->RestoreNode();
doc->IncrementReferens(nodes.at(i).getId());
} }
} }
emit NeedLiteParsing(); emit NeedLiteParsing();
@ -102,6 +103,7 @@ void SaveDetailOptions::redo()
{ {
VAbstractNode *node = qobject_cast<VAbstractNode *>(tools->value(list.at(i))); VAbstractNode *node = qobject_cast<VAbstractNode *>(tools->value(list.at(i)));
node->DeleteNode(); node->DeleteNode();
doc->DecrementReferens(list.at(i));
} }
} }
emit NeedLiteParsing(); emit NeedLiteParsing();

View File

@ -1716,18 +1716,6 @@ QString VApplication::Description(const QString &measurement) const
return descriptions.value(measurement).translate(); 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 QString VApplication::PostfixOperator(const QString &name) const
{ {

View File

@ -67,8 +67,6 @@ public:
QString VarFromUser(const QString &var) const; QString VarFromUser(const QString &var) const;
QString GuiText(const QString &measurement) const; QString GuiText(const QString &measurement) const;
QString Description(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 PostfixOperator(const QString &name) const;
QString FormulaFromUser(const QString &formula); QString FormulaFromUser(const QString &formula);
QString FormulaToUser(const QString &formula); QString FormulaToUser(const QString &formula);

View File

@ -50,7 +50,7 @@ signals:
* @param pos new posotion. * @param pos new posotion.
*/ */
void ControlPointChangePosition(const qint32 &indexSpline, SplinePointPosition position, void ControlPointChangePosition(const qint32 &indexSpline, SplinePointPosition position,
const QPointF pos); const QPointF &pos);
public slots: public slots:
void RefreshLine(const qint32 &indexSpline, SplinePointPosition pos, const QPointF &controlPoint, void RefreshLine(const qint32 &indexSpline, SplinePointPosition pos, const QPointF &controlPoint,
const QPointF &splinePoint); const QPointF &splinePoint);

View File

@ -53,7 +53,7 @@ signals:
* @brief NameChangePosition emit when label change position. * @brief NameChangePosition emit when label change position.
* @param pos new posotion. * @param pos new posotion.
*/ */
void NameChangePosition(const QPointF pos); void NameChangePosition(const QPointF &pos);
/** /**
* @brief ShowContextMenu emit when need show tool context menu. * @brief ShowContextMenu emit when need show tool context menu.
* @param event context menu event. * @param event context menu event.

View File

@ -76,6 +76,7 @@ inline qint64 MessageHandler::column() const
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
// cppcheck-suppress unusedFunction
void MessageHandler::handleMessage(QtMsgType type, const QString &description, const QUrl &identifier, void MessageHandler::handleMessage(QtMsgType type, const QString &description, const QUrl &identifier,
const QSourceLocation &sourceLocation) const QSourceLocation &sourceLocation)
{ {

View File

@ -637,6 +637,7 @@ bool VPattern::SaveDocument(const QString &fileName)
e.CriticalMessageBox(tr("Error no unique id.")); e.CriticalMessageBox(tr("Error no unique id."));
return false; return false;
} }
GarbageCollector();
return VDomDocument::SaveDocument(fileName); return VDomDocument::SaveDocument(fileName);
} }
@ -1868,17 +1869,19 @@ void VPattern::UpdateMeasurements()
void VPattern::GarbageCollector() void VPattern::GarbageCollector()
{ {
QHashIterator<quint32, VDataTool*> t(tools); QHashIterator<quint32, VDataTool*> t(tools);
while (t.hasNext()) { while (t.hasNext())
{
t.next(); t.next();
VDataTool *tool = t.value(); VDataTool *tool = t.value();
if(tool->referens() <= 0){ if(tool->referens() <= 1)
{
QDomElement domElement = elementById(QString().setNum(t.key())); QDomElement domElement = elementById(QString().setNum(t.key()));
if(domElement.isElement()){ if(domElement.isElement())
{
QDomNode parent = domElement.parentNode(); QDomNode parent = domElement.parentNode();
if(!parent.isNull()){ if(parent.isNull() == false && parent.toElement().tagName() == TagModeling)
{
parent.removeChild(domElement); parent.removeChild(domElement);
} else {
qWarning()<<tr("Can't get parent for object id = %1").arg(t.key());
} }
} }
} }