Tried fix some memory leaks.

--HG--
branch : feature
This commit is contained in:
dismine 2014-01-02 19:16:16 +02:00
parent 7cf058bf70
commit 75b125194b
17 changed files with 80 additions and 50 deletions

View File

@ -160,7 +160,7 @@ public:
* @param name name of row of standart table
* @param cell row of standart table
*/
inline void AddStandartTableCell(const QString& name, VStandartTableRow cell)
inline void AddStandartTableCell(const QString& name, const VStandartTableRow &cell)
{standartTable[name] = cell;}
/**
* @brief AddIncrementTableRow add new row of increment table

View File

@ -33,8 +33,8 @@ const QString VAbstractNode::AttrIdObject = QStringLiteral("idObject");
const QString VAbstractNode::AttrIdTool = QStringLiteral("idTool");
VAbstractNode::VAbstractNode(VDomDocument *doc, VContainer *data, const qint64 &id, const qint64 &idNode,
const qint64 &idTool)
: VAbstractTool(doc, data, id), idNode(idNode), idTool(idTool)
const qint64 &idTool, QObject *parent)
: VAbstractTool(doc, data, id, parent), idNode(idNode), idTool(idTool)
{
_referens = 0;
}

View File

@ -47,7 +47,7 @@ public:
* @param parent
*/
VAbstractNode(VDomDocument *doc, VContainer *data, const qint64 &id, const qint64 &idNode,
const qint64 &idTool);
const qint64 &idTool, QObject *parent = 0);
virtual ~VAbstractNode() {}
/**
* @brief AttrIdObject

View File

@ -34,8 +34,8 @@ const QString VNodeArc::TagName = QStringLiteral("arc");
const QString VNodeArc::ToolType = QStringLiteral("modeling");
VNodeArc::VNodeArc(VDomDocument *doc, VContainer *data, qint64 id, qint64 idArc, const Tool::Sources &typeCreation,
const qint64 &idTool, QGraphicsItem * parent)
:VAbstractNode(doc, data, id, idArc, idTool), QGraphicsPathItem(parent)
const qint64 &idTool, QObject *qoParent, QGraphicsItem *parent)
:VAbstractNode(doc, data, id, idArc, idTool, qoParent), QGraphicsPathItem(parent)
{
RefreshGeometry();
this->setPen(QPen(baseColor, widthHairLine));
@ -51,17 +51,21 @@ VNodeArc::VNodeArc(VDomDocument *doc, VContainer *data, qint64 id, qint64 idArc,
}
void VNodeArc::Create(VDomDocument *doc, VContainer *data, qint64 id, qint64 idArc, const Document::Documents &parse,
const Tool::Sources &typeCreation, const qint64 &idTool)
const Tool::Sources &typeCreation, const qint64 &idTool, QObject *parent)
{
VAbstractTool::AddRecord(id, Tool::NodeArc, doc);
if (parse == Document::FullParse)
{
VNodeArc *arc = new VNodeArc(doc, data, id, idArc, typeCreation, idTool);
VNodeArc *arc = new VNodeArc(doc, data, id, idArc, typeCreation, idTool, parent);
Q_ASSERT(arc != 0);
doc->AddTool(id, arc);
if(idTool != 0)
{
doc->IncrementReferens(idTool);
//Some nodes we don't show on scene. Tool that create this nodes must free memory.
VDataTool *tool = doc->getTool(idTool);
Q_ASSERT(tool != 0);
arc->setParent(tool);
}
else
{

View File

@ -49,7 +49,8 @@ public:
* @param parent
*/
VNodeArc(VDomDocument *doc, VContainer *data, qint64 id, qint64 idArc,
const Tool::Sources &typeCreation, const qint64 &idTool = 0, QGraphicsItem * parent = 0);
const Tool::Sources &typeCreation, const qint64 &idTool = 0, QObject *qoParent = 0,
QGraphicsItem * parent = 0);
/**
* @brief Create
* @param doc dom document container
@ -60,7 +61,7 @@ public:
* @param typeCreation
*/
static void Create(VDomDocument *doc, VContainer *data, qint64 id, qint64 idArc, const Document::Documents &parse,
const Tool::Sources &typeCreation, const qint64 &idTool = 0);
const Tool::Sources &typeCreation, const qint64 &idTool = 0, QObject *parent = 0);
/**
* @brief TagName
*/

View File

@ -34,9 +34,10 @@ const QString VNodePoint::TagName = QStringLiteral("point");
const QString VNodePoint::ToolType = QStringLiteral("modeling");
VNodePoint::VNodePoint(VDomDocument *doc, VContainer *data, qint64 id, qint64 idPoint,
const Tool::Sources &typeCreation, const qint64 &idTool, QGraphicsItem *parent)
:VAbstractNode(doc, data, id, idPoint, idTool), QGraphicsEllipseItem(parent), radius(toPixel(1.5)), namePoint(0),
lineName(0)
const Tool::Sources &typeCreation, const qint64 &idTool, QObject *qoParent,
QGraphicsItem *parent)
:VAbstractNode(doc, data, id, idPoint, idTool, qoParent), QGraphicsEllipseItem(parent), radius(toPixel(1.5)),
namePoint(0), lineName(0)
{
namePoint = new VGraphicsSimpleTextItem(this);
lineName = new QGraphicsLineItem(this);
@ -58,17 +59,24 @@ VNodePoint::VNodePoint(VDomDocument *doc, VContainer *data, qint64 id, qint64 id
}
void VNodePoint::Create(VDomDocument *doc, VContainer *data, qint64 id, qint64 idPoint,
const Document::Documents &parse, const Tool::Sources &typeCreation, const qint64 &idTool)
const Document::Documents &parse, const Tool::Sources &typeCreation, const qint64 &idTool,
QObject *parent)
{
VAbstractTool::AddRecord(id, Tool::NodePoint, doc);
if (parse == Document::FullParse)
{
VNodePoint *point = new VNodePoint(doc, data, id, idPoint, typeCreation, idTool);
//TODO Need create garbage collector and remove all nodes, that 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);
Q_ASSERT(point != 0);
doc->AddTool(id, point);
if(idTool != 0)
{
doc->IncrementReferens(idTool);
//Some nodes we don't show on scene. Tool that create this nodes must free memory.
VDataTool *tool = doc->getTool(idTool);
Q_ASSERT(tool != 0);
point->setParent(tool);
}
else
{

View File

@ -49,7 +49,8 @@ public:
* @param parent
*/
VNodePoint(VDomDocument *doc, VContainer *data, qint64 id, qint64 idPoint,
const Tool::Sources &typeCreation, const qint64 &idTool = 0, QGraphicsItem * parent = 0 );
const Tool::Sources &typeCreation, const qint64 &idTool = 0, QObject *qoParent = 0,
QGraphicsItem * parent = 0 );
/**
* @brief Create
* @param doc dom document container
@ -60,7 +61,8 @@ public:
* @param typeCreation
*/
static void Create(VDomDocument *doc, VContainer *data, qint64 id, qint64 idPoint,
const Document::Documents &parse, const Tool::Sources &typeCreation, const qint64 &idTool = 0);
const Document::Documents &parse, const Tool::Sources &typeCreation, const qint64 &idTool = 0,
QObject *parent = 0);
/**
* @brief TagName
*/

View File

@ -34,8 +34,9 @@ const QString VNodeSpline::TagName = QStringLiteral("spline");
const QString VNodeSpline::ToolType = QStringLiteral("modelingSpline");
VNodeSpline::VNodeSpline(VDomDocument *doc, VContainer *data, qint64 id, qint64 idSpline,
const Tool::Sources &typeCreation, const qint64 &idTool, QGraphicsItem * parent)
:VAbstractNode(doc, data, id, idSpline, idTool), QGraphicsPathItem(parent)
const Tool::Sources &typeCreation, const qint64 &idTool, QObject *qoParent,
QGraphicsItem * parent)
:VAbstractNode(doc, data, id, idSpline, idTool, qoParent), QGraphicsPathItem(parent)
{
RefreshGeometry();
this->setPen(QPen(baseColor, widthHairLine));
@ -52,17 +53,21 @@ VNodeSpline::VNodeSpline(VDomDocument *doc, VContainer *data, qint64 id, qint64
VNodeSpline *VNodeSpline::Create(VDomDocument *doc, VContainer *data, qint64 id, qint64 idSpline,
const Document::Documents &parse, const Tool::Sources &typeCreation,
const qint64 &idTool)
const qint64 &idTool, QObject *parent)
{
VAbstractTool::AddRecord(id, Tool::NodeSpline, doc);
VNodeSpline *spl = 0;
if (parse == Document::FullParse)
{
spl = new VNodeSpline(doc, data, id, idSpline, typeCreation, idTool);
spl = new VNodeSpline(doc, data, id, idSpline, typeCreation, idTool, parent);
doc->AddTool(id, spl);
if(idTool != 0)
{
doc->IncrementReferens(idTool);
//Some nodes we don't show on scene. Tool that create this nodes must free memory.
VDataTool *tool = doc->getTool(idTool);
Q_ASSERT(tool != 0);
spl->setParent(tool);
}
else
{

View File

@ -49,7 +49,8 @@ public:
* @param parent
*/
VNodeSpline(VDomDocument *doc, VContainer *data, qint64 id, qint64 idSpline,
const Tool::Sources &typeCreation, const qint64 &idTool = 0, QGraphicsItem * parent = 0);
const Tool::Sources &typeCreation, const qint64 &idTool = 0, QObject *qoParent = 0,
QGraphicsItem * parent = 0);
/**
* @brief Create
* @param doc dom document container
@ -62,7 +63,7 @@ public:
*/
static VNodeSpline *Create(VDomDocument *doc, VContainer *data, qint64 id, qint64 idSpline,
const Document::Documents &parse, const Tool::Sources &typeCreation,
const qint64 &idTool = 0);
const qint64 &idTool = 0, QObject *parent = 0);
/**
* @brief TagName
*/

View File

@ -34,8 +34,9 @@ const QString VNodeSplinePath::TagName = QStringLiteral("spline");
const QString VNodeSplinePath::ToolType = QStringLiteral("modelingPath");
VNodeSplinePath::VNodeSplinePath(VDomDocument *doc, VContainer *data, qint64 id, qint64 idSpline,
const Tool::Sources &typeCreation, const qint64 &idTool, QGraphicsItem * parent)
:VAbstractNode(doc, data, id, idSpline, idTool), QGraphicsPathItem(parent)
const Tool::Sources &typeCreation, const qint64 &idTool, QObject *qoParent,
QGraphicsItem * parent)
:VAbstractNode(doc, data, id, idSpline, idTool, qoParent), QGraphicsPathItem(parent)
{
RefreshGeometry();
this->setPen(QPen(baseColor, widthHairLine));
@ -51,12 +52,13 @@ VNodeSplinePath::VNodeSplinePath(VDomDocument *doc, VContainer *data, qint64 id,
}
void VNodeSplinePath::Create(VDomDocument *doc, VContainer *data, qint64 id, qint64 idSpline,
const Document::Documents &parse, const Tool::Sources &typeCreation, const qint64 &idTool)
const Document::Documents &parse, const Tool::Sources &typeCreation, const qint64 &idTool,
QObject *parent)
{
VAbstractTool::AddRecord(id, Tool::NodeSplinePath, doc);
if (parse == Document::FullParse)
{
VNodeSplinePath *splPath = new VNodeSplinePath(doc, data, id, idSpline, typeCreation, idTool);
VNodeSplinePath *splPath = new VNodeSplinePath(doc, data, id, idSpline, typeCreation, idTool, parent);
Q_ASSERT(splPath != 0);
doc->AddTool(id, splPath);
const VSplinePath *path = data->GeometricObject<const VSplinePath *>(id);
@ -66,6 +68,10 @@ void VNodeSplinePath::Create(VDomDocument *doc, VContainer *data, qint64 id, qin
if(idTool != 0)
{
doc->IncrementReferens(idTool);
//Some nodes we don't show on scene. Tool that create this nodes must free memory.
VDataTool *tool = doc->getTool(idTool);
Q_ASSERT(tool != 0);
splPath->setParent(tool);
}
else
{

View File

@ -49,7 +49,7 @@ public:
* @param parent
*/
VNodeSplinePath(VDomDocument *doc, VContainer *data, qint64 id, qint64 idSpline,
const Tool::Sources &typeCreation, const qint64 &idTool = 0,
const Tool::Sources &typeCreation, const qint64 &idTool = 0, QObject *qoParent = 0,
QGraphicsItem * parent = 0);
/**
* @brief Create
@ -61,7 +61,8 @@ public:
* @param typeCreation
*/
static void Create(VDomDocument *doc, VContainer *data, qint64 id, qint64 idSpline,
const Document::Documents &parse, const Tool::Sources &typeCreation, const qint64 &idTool = 0);
const Document::Documents &parse, const Tool::Sources &typeCreation, const qint64 &idTool = 0,
QObject *parent = 0);
/**
* @brief TagName
*/

View File

@ -65,8 +65,8 @@ const QString VAbstractTool::AttrAxisP2 = QStringLiteral("axisP2");
const QString VAbstractTool::TypeLineNone = QStringLiteral("none");
const QString VAbstractTool::TypeLineLine = QStringLiteral("hair");
VAbstractTool::VAbstractTool(VDomDocument *doc, VContainer *data, qint64 id)
:VDataTool(data), doc(doc), id(id), baseColor(Qt::black), currentColor(Qt::black)
VAbstractTool::VAbstractTool(VDomDocument *doc, VContainer *data, qint64 id, QObject *parent)
:VDataTool(data, parent), doc(doc), id(id), baseColor(Qt::black), currentColor(Qt::black)
{
Q_ASSERT(doc != 0);
connect(this, &VAbstractTool::toolhaveChange, this->doc, &VDomDocument::haveLiteChange);

View File

@ -46,7 +46,7 @@ public:
* @param id
* @param parent
*/
VAbstractTool(VDomDocument *doc, VContainer *data, qint64 id);
VAbstractTool(VDomDocument *doc, VContainer *data, qint64 id, QObject *parent = 0);
virtual ~VAbstractTool() {}
/**
* @brief LineIntersectRect

View File

@ -130,7 +130,7 @@ void VToolDetail::Create(QSharedPointer<DialogDetail> &dialog, VMainGraphicsScen
Create(0, det, scene, doc, data, Document::FullParse, Tool::FromGui);
}
void VToolDetail::Create(const qint64 _id, VDetail newDetail, VMainGraphicsScene *scene, VDomDocument *doc,
void VToolDetail::Create(const qint64 &_id, const VDetail &newDetail, VMainGraphicsScene *scene, VDomDocument *doc,
VContainer *data, const Document::Documents &parse, const Tool::Sources &typeCreation)
{
qint64 id = _id;

View File

@ -84,7 +84,7 @@ public:
* @param parse
* @param typeCreation
*/
static void Create(const qint64 _id, VDetail newDetail, VMainGraphicsScene *scene,
static void Create(const qint64 &_id, const VDetail &newDetail, VMainGraphicsScene *scene,
VDomDocument *doc, VContainer *data, const Document::Documents &parse,
const Tool::Sources &typeCreation);
template <typename T>

View File

@ -43,8 +43,8 @@ const QString VToolUnionDetails::NodeTypeModeling = QStringLiteral("Modeling");
VToolUnionDetails::VToolUnionDetails(VDomDocument *doc, VContainer *data, const qint64 &id, const VDetail &d1,
const VDetail &d2, const ptrdiff_t &indexD1, const ptrdiff_t &indexD2,
const Tool::Sources &typeCreation)
:VAbstractTool(doc, data, id), d1(d1), d2(d2), indexD1(indexD1), indexD2(indexD2)
const Tool::Sources &typeCreation, QObject *parent)
:VAbstractTool(doc, data, id, parent), d1(d1), d2(d2), indexD1(indexD1), indexD2(indexD2)
{
if (typeCreation == Tool::FromGui)
{
@ -56,9 +56,9 @@ VToolUnionDetails::VToolUnionDetails(VDomDocument *doc, VContainer *data, const
}
}
void VToolUnionDetails::AddToNewDetail(VDomDocument *doc, VContainer *data, VDetail &newDetail, const VDetail &det,
const ptrdiff_t &i, const qint64 &idTool, const qreal &dx, const qreal &dy,
const qint64 &pRotate, const qreal &angle)
void VToolUnionDetails::AddToNewDetail(QObject *tool, VDomDocument *doc, VContainer *data, VDetail &newDetail,
const VDetail &det, const ptrdiff_t &i, const qint64 &idTool, const qreal &dx,
const qreal &dy, const qint64 &pRotate, const qreal &angle)
{
qint64 id = 0, idObject = 0;
switch (det.at(i).getTypeTool())
@ -81,7 +81,7 @@ void VToolUnionDetails::AddToNewDetail(VDomDocument *doc, VContainer *data, VDet
Q_ASSERT(point1 != 0);
point1->setMode(Draw::Modeling);
id = data->AddGObject(point1);
VNodePoint::Create(doc, data, id, idObject, Document::FullParse, Tool::FromGui, idTool);
VNodePoint::Create(doc, data, id, idObject, Document::FullParse, Tool::FromGui, idTool, tool);
}
}
break;
@ -119,7 +119,7 @@ void VToolUnionDetails::AddToNewDetail(VDomDocument *doc, VContainer *data, VDet
arc2->setMode(Draw::Modeling);
id = data->AddGObject(arc2);
VNodeArc::Create(doc, data, id, idObject, Document::FullParse, Tool::FromGui, idTool);
VNodeArc::Create(doc, data, id, idObject, Document::FullParse, Tool::FromGui, idTool, tool);
}
}
break;
@ -158,7 +158,7 @@ void VToolUnionDetails::AddToNewDetail(VDomDocument *doc, VContainer *data, VDet
Q_ASSERT(spl1 != 0);
spl1->setMode(Draw::Modeling);
idObject = data->AddGObject(spl1);
VNodeSpline::Create(doc, data, id, idObject, Document::FullParse, Tool::FromGui, idTool);
VNodeSpline::Create(doc, data, id, idObject, Document::FullParse, Tool::FromGui, idTool, tool);
}
}
break;
@ -215,7 +215,7 @@ void VToolUnionDetails::AddToNewDetail(VDomDocument *doc, VContainer *data, VDet
Q_ASSERT(path1 != 0);
path1->setMode(Draw::Modeling);
id = data->AddGObject(path1);
VNodeSplinePath::Create(doc, data, id, idObject, Document::FullParse, Tool::FromGui, idTool);
VNodeSplinePath::Create(doc, data, id, idObject, Document::FullParse, Tool::FromGui, idTool, tool);
}
}
break;
@ -390,6 +390,7 @@ void VToolUnionDetails::Create(const qint64 _id, const VDetail &d1, const VDetai
VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data,
const Document::Documents &parse, const Tool::Sources &typeCreation)
{
VToolUnionDetails *unionDetails = 0;
qint64 id = _id;
if (typeCreation == Tool::FromGui)
{
@ -405,7 +406,8 @@ void VToolUnionDetails::Create(const qint64 _id, const VDetail &d1, const VDetai
VAbstractTool::AddRecord(id, Tool::UnionDetails, doc);
if (parse == Document::FullParse)
{
VToolUnionDetails *unionDetails = new VToolUnionDetails(doc, data, id, d1, d2, indexD1, indexD2, typeCreation);
//Scene doesn't show this tool, so doc will destroy this object.
unionDetails = new VToolUnionDetails(doc, data, id, d1, d2, indexD1, indexD2, typeCreation, doc);
QHash<qint64, VDataTool*>* tools = doc->getTools();
tools->insert(id, unionDetails);
for (ptrdiff_t i = 0; i < d1.CountNode(); ++i)
@ -429,7 +431,7 @@ void VToolUnionDetails::Create(const qint64 _id, const VDetail &d1, const VDetai
do
{
AddToNewDetail(doc, data, newDetail, d1, i, id);
AddToNewDetail(unionDetails, doc, data, newDetail, d1, i, id);
++i;
if (i > indexD1 && pointsD2 < nD2-2)
{
@ -483,7 +485,7 @@ void VToolUnionDetails::Create(const qint64 _id, const VDetail &d1, const VDetai
{
j=0;
}
AddToNewDetail(doc, data, newDetail, d2, j, id, dx, dy, det1p1.getId(), angle);
AddToNewDetail(unionDetails, doc, data, newDetail, d2, j, id, dx, dy, det1p1.getId(), angle);
++pointsD2;
++j;
} while (pointsD2 < nD2);

View File

@ -38,7 +38,7 @@ class VToolUnionDetails : public VAbstractTool
public:
VToolUnionDetails(VDomDocument *doc, VContainer *data, const qint64 &id, const VDetail &d1, const VDetail &d2,
const ptrdiff_t &indexD1, const ptrdiff_t &indexD2,
const Tool::Sources &typeCreation);
const Tool::Sources &typeCreation, QObject *parent = 0);
virtual void setDialog() {}
/**
* @brief Create
@ -77,9 +77,9 @@ public:
static const QString NodeTypeContour;
static const QString NodeTypeModeling;
static void AddToNewDetail(VDomDocument *doc, VContainer *data, VDetail &newDetail, const VDetail &det,
const ptrdiff_t &i, const qint64 &idTool, const qreal &dx = 0, const qreal &dy = 0,
const qint64 &pRotate = 0, const qreal &angle = 0);
static void AddToNewDetail(QObject *tool, VDomDocument *doc, VContainer *data, VDetail &newDetail,
const VDetail &det, const ptrdiff_t &i, const qint64 &idTool, const qreal &dx = 0,
const qreal &dy = 0, const qint64 &pRotate = 0, const qreal &angle = 0);
static void UpdatePoints(const qint64 &idDetail, VContainer *data, const VDetail &det, const ptrdiff_t &i,
qint64 &idCount, const qreal &dx = 0, const qreal &dy = 0, const qint64 &pRotate = 0,
const qreal &angle = 0);