Fixed crashes. Still have memory leak.

--HG--
branch : feature
This commit is contained in:
dismine 2013-12-30 13:28:33 +02:00
parent 41f5f207d8
commit eddcaf8ff2
17 changed files with 113 additions and 32 deletions

View file

@ -126,7 +126,7 @@ pixmaps.path = $$DATADIR/pixmaps/
pixmaps.files += dist/$${TARGET}.png
INSTALL_TRANSLATIONS += share/translations/valentina_ru.qm \
share/translations/valentina_uk.qm \
share/translations/valentina_de.qm \
share/translations/valentina_de.qm
translations.path = $$DATADIR/$${TARGET}/translations/
translations.files = $$INSTALL_TRANSLATIONS
INSTALLS += target \

View file

@ -27,7 +27,6 @@
*************************************************************************/
#include "vcontainer.h"
#include "../exception/vexceptionbadid.h"
#include <QDebug>
#include <QtAlgorithms>
@ -63,7 +62,48 @@ VContainer::VContainer(const VContainer &data)
void VContainer::setData(const VContainer &data)
{
base = *data.DataBase();
gObjects = *data.DataGObjects();
qDeleteAll(gObjects);
gObjects.clear();
const QHash<qint64, VGObject*> *obj = data.DataGObjects();
Q_ASSERT(obj != 0);
QHashIterator<qint64, VGObject*> i(*obj);
while (i.hasNext())
{
i.next();
switch(i.value()->getType())
{
case(GObject::Arc):
{
VArc *arc = new VArc(*data.GeometricObject<const VArc *>(i.key()));
Q_ASSERT(arc != 0);
gObjects.insert(i.key(), arc);
break;
}
case(GObject::Point):
{
VPointF *point = new VPointF(*data.GeometricObject<const VPointF *>(i.key()));
Q_ASSERT(point != 0);
gObjects.insert(i.key(), point);
break;
}
case(GObject::Spline):
{
VSpline *spl = new VSpline(*data.GeometricObject<const VSpline *>(i.key()));
Q_ASSERT(spl != 0);
gObjects.insert(i.key(), spl);
break;
}
case(GObject::SplinePath):
{
VSplinePath *path = new VSplinePath(*data.GeometricObject<const VSplinePath *>(i.key()));
Q_ASSERT(path != 0);
gObjects.insert(i.key(), path);
break;
}
}
}
//gObjects = *data.DataGObjects();
standartTable = *data.DataStandartTable();
incrementTable = *data.DataIncrementTable();
lengthLines = *data.DataLengthLines();
@ -79,7 +119,7 @@ const VGObject *VContainer::GetGObject(qint64 id)const
}
template <typename key, typename val>
const val *VContainer::GetObject(const QHash<key, val*> &obj, key id) const
const val VContainer::GetObject(const QHash<key, val> &obj, key id) const
{
if (obj.contains(id))
{
@ -510,12 +550,15 @@ void VContainer::PrepareDetails(QVector<VItem *> &list) const
}
template <typename val>
void VContainer::UpdateObject(QHash<qint64, val *> &obj, const qint64 &id, val *point)
void VContainer::UpdateObject(QHash<qint64, val> &obj, const qint64 &id, val point)
{
Q_ASSERT_X(id > 0, Q_FUNC_INFO, "id <= 0");
Q_ASSERT(point != 0);
point->setId(id);
delete GetObject(gObjects, id);
point->setId(id);
// if (gObjects.contains(id))
// {
// delete gObjects.value(id);
// }
obj[id] = point;
UpdateId(id);
}
@ -565,7 +608,15 @@ qreal VContainer::GetValueIncrementTableRow(const QString& name) const
void VContainer::Clear()
{
_id = 0;
if(standartTable.size()>0)
{
qDeleteAll(standartTable);
}
standartTable.clear();
if(incrementTable.size()>0)
{
qDeleteAll(incrementTable);
}
incrementTable.clear();
lengthLines.clear();
lengthArcs.clear();
@ -577,7 +628,10 @@ void VContainer::Clear()
void VContainer::ClearObject()
{
qDeleteAll(gObjects);
if(gObjects.size()>0)
{
qDeleteAll(gObjects);
}
gObjects.clear();
}
@ -634,7 +688,7 @@ void VContainer::AddLine(const qint64 &firstPointId, const qint64 &secondPointId
}
template <typename key, typename val>
qint64 VContainer::AddObject(QHash<key, val*> &obj, val *value)
qint64 VContainer::AddObject(QHash<key, val> &obj, val value)
{
Q_ASSERT(value != 0);
qint64 id = getNextId();

View file

@ -36,6 +36,7 @@
#include "../geometry/vdetail.h"
#include "../widgets/vitem.h"
#include "../geometry/vgobject.h"
#include "../exception/vexceptionbadid.h"
/**
* @brief The VContainer class container of all variables.
@ -67,7 +68,17 @@ public:
template <typename T>
const T GeometricObject(qint64 id) const
{
const T obj = dynamic_cast<T>(GetObject(gObjects, id));
VGObject *gObj = 0;
if (gObjects.contains(id))
{
gObj = gObjects.value(id);
}
else
{
throw VExceptionBadId(tr("Can't find object"), id);
}
//T obj = dynamic_cast<T>(gObj);
T obj = qobject_cast<T>(gObj);
Q_ASSERT(obj != 0);
return obj;
}
@ -481,7 +492,7 @@ private:
* @param id id of object
* @return Object
*/
const val *GetObject(const QHash<key, val*> &obj, key id) const;
const val GetObject(const QHash<key, val> &obj, key id) const;
template <typename key, typename val>
/**
* @brief GetObject return object from container
@ -497,7 +508,7 @@ private:
* @param id id of existing object
* @param point object
*/
void UpdateObject(QHash<qint64, val *> &obj, const qint64 &id, val* point);
void UpdateObject(QHash<qint64, val > &obj, const qint64 &id, val point);
template <typename key, typename val>
/**
* @brief AddObject add object to container
@ -505,7 +516,7 @@ private:
* @param value object
* @return id of object in container
*/
static qint64 AddObject(QHash<key, val*> &obj, val *value);
static qint64 AddObject(QHash<key, val> &obj, val value);
};
#endif // VCONTAINER_H

View file

@ -42,7 +42,8 @@ class QPainterPath;
*/
class VArc: public VGObject
{
Q_DECLARE_TR_FUNCTIONS(VArc)
Q_OBJECT
//Q_DECLARE_TR_FUNCTIONS(VArc)
public:
/**
* @brief VArc конструктор по замовчуванню.
@ -144,6 +145,7 @@ public:
* @return
*/
QVector<QPointF> SplOfArc( qint32 number ) const;
virtual QString name() const{return _name;}
private:
/**
* @brief f1 початковий кут в градусах

View file

@ -29,20 +29,23 @@
#include "vdetail.h"
VDetail::VDetail()
:_id(0), nodes(QVector<VNodeDetail>()), name(QString()), mx(0), my(0), supplement(true), closed(true), width(10){}
:QObject(), _id(0), nodes(QVector<VNodeDetail>()), name(QString()), mx(0), my(0), supplement(true), closed(true),
width(10){}
VDetail::VDetail(const QString &name, const QVector<VNodeDetail> &nodes)
:_id(0), nodes(QVector<VNodeDetail>()), name(name), mx(0), my(0), supplement(true), closed(true), width(10)
:QObject(), _id(0), nodes(QVector<VNodeDetail>()), name(name), mx(0), my(0), supplement(true), closed(true),
width(10)
{
this->nodes = nodes;
}
VDetail::VDetail(const VDetail &detail)
:_id(0), nodes(detail.getNodes()), name(detail.getName()), mx(detail.getMx()), my(detail.getMy()),
:QObject(), _id(0), nodes(detail.getNodes()), name(detail.getName()), mx(detail.getMx()), my(detail.getMy()),
supplement(detail.getSupplement()), closed(detail.getClosed()), width(detail.getWidth()){}
VDetail &VDetail::operator =(const VDetail &detail)
{
_id = detail.id();
nodes = detail.getNodes();
name = detail.getName();
mx = detail.getMx();

View file

@ -54,8 +54,9 @@ Q_DECLARE_OPERATORS_FOR_FLAGS(Detail::Equidistants)
/**
* @brief The VDetail class
*/
class VDetail
class VDetail: public QObject
{
Q_OBJECT
public:
/**
* @brief VDetail

View file

@ -29,17 +29,17 @@
#include "vgobject.h"
VGObject::VGObject()
:_id(0), type(GObject::Point), idObject(0), _name(QString()), mode(Draw::Calculation)
:QObject(), _id(0), type(GObject::Point), idObject(0), _name(QString()), mode(Draw::Calculation)
{
}
VGObject::VGObject(const GObject::Type &type, const qint64 &idObject, const Draw::Draws &mode)
:_id(0), type(type), idObject(idObject), _name(QString()), mode(mode)
:QObject(), _id(0), type(type), idObject(idObject), _name(QString()), mode(mode)
{
}
VGObject::VGObject(const VGObject &obj)
:_id(obj.id()), type(obj.getType()), idObject(obj.getIdObject()), _name(obj.name()), mode(obj.getMode())
:QObject(), _id(obj.id()), type(obj.getType()), idObject(obj.getIdObject()), _name(obj.name()), mode(obj.getMode())
{
}

View file

@ -45,9 +45,9 @@ namespace GObject
}
Q_DECLARE_OPERATORS_FOR_FLAGS(GObject::Types)
class VGObject
class VGObject :public QObject
{
Q_DECLARE_TR_FUNCTIONS(VGObject)
Q_OBJECT
public:
VGObject();
VGObject(const GObject::Type &type, const qint64 &idObject = 0, const Draw::Draws &mode = Draw::Calculation);
@ -61,8 +61,8 @@ public:
Draw::Draws getMode() const;
void setMode(const Draw::Draws &value);
GObject::Type getType() const;
qint64 id() const;
void setId(const qint64 &id);
qint64 id() const;
void setId(const qint64 &id);
protected:
/**
* @brief _id id in container. Ned for arcs, spline and spline paths.

View file

@ -39,6 +39,7 @@
*/
class VPointF:public VGObject
{
Q_OBJECT
public:
/**
* @brief VPointF creat empty point
@ -114,6 +115,7 @@ public:
* @param value y coordinate
*/
inline void setY(const qreal &value){_y = value;}
virtual QString name() const{return _name;}
private:
/**
* @brief _mx offset name respect to x

View file

@ -45,6 +45,7 @@ class QString;
*/
class VSpline :public VGObject
{
Q_OBJECT
public:
/**
* @brief VSpline default constructor

View file

@ -51,7 +51,8 @@ Q_DECLARE_OPERATORS_FOR_FLAGS( SplinePoint::Positions )
*/
class VSplinePath :public VGObject
{
Q_DECLARE_TR_FUNCTIONS(VSplinePath)
Q_OBJECT
//Q_DECLARE_TR_FUNCTIONS(VSplinePath)
public:
/**
* @brief VSplinePath конструктор по замовчуванню.
@ -160,6 +161,7 @@ public:
*/
QPointF CutSplinePath(qreal length, qint32 &p1, qint32 &p2, QPointF &spl1p2, QPointF &spl1p3, QPointF &spl2p2,
QPointF &spl2p3) const;
virtual QString name() const{return _name;}
protected:
/**
* @brief path вектор з точок сплайна.

View file

@ -104,8 +104,6 @@ void VToolCutSpline::Create(const qint64 _id, const QString &pointName,
VPointF *p = new VPointF(point.x(), point.y(), pointName, mx, my);
Q_ASSERT(p != 0);
id = data->AddGObject(p);
spl1id = id + 1;
spl2id = id + 2;
VSpline *spline1 = new VSpline(spl->GetP1(), spl1p2, spl1p3, *p, spl->GetKcurve());
Q_ASSERT(spline1);

View file

@ -130,7 +130,8 @@ void VToolSinglePoint::contextMenuEvent ( QGraphicsSceneContextMenuEvent * event
void VToolSinglePoint::FullUpdateFromFile()
{
RefreshPointGeometry(*VAbstractTool::data.GeometricObject<const VPointF *>(id));
VPointF point = *VAbstractTool::data.GeometricObject<const VPointF *>(id);
RefreshPointGeometry(point);
}
void VToolSinglePoint::FullUpdateFromGui(int result)
@ -169,5 +170,5 @@ void VToolSinglePoint::ChangedActivDraw(const QString &newName)
void VToolSinglePoint::SetFactor(qreal factor)
{
VDrawTool::SetFactor(factor);
RefreshPointGeometry(*VAbstractTool::data.GeometricObject<const VPointF *>(id));
RefreshPointGeometry(*(VAbstractTool::data.GeometricObject<const VPointF *>(id)));
}

View file

@ -171,7 +171,7 @@ void VToolSplinePath::ControlPointChangePosition(const qint32 &indexSpline, cons
const QPointF &pos)
{
VSplinePath splPath = *VAbstractTool::data.GeometricObject<const VSplinePath *>(id);
VSpline spl;
VSpline spl = splPath.GetSpline(indexSpline);
if (position == SplinePoint::FirstPoint)
{
spl = VSpline(spl.GetP1(), pos, spl.GetP3(), spl.GetP4(), spl.GetKcurve());

View file

@ -61,7 +61,7 @@ public:
* @brief setData
* @param value
*/
inline void setData(const VContainer *value) {data = *value;}
inline void setData(const VContainer *value){data = *value;}
/**
* @brief referens
* @return

View file

@ -100,6 +100,7 @@ void VToolDetail::Create(QSharedPointer<DialogDetail> &dialog, VMainGraphicsScen
{
VPointF *point = new VPointF(*data->GeometricObject<const VPointF *>(detail[i].getId()));
Q_ASSERT(point != 0);
point->setMode(Draw::Modeling);
id = data->AddGObject(point);
VNodePoint::Create(doc, data, id, detail[i].getId(), Document::FullParse, Tool::FromGui);
}
@ -108,6 +109,7 @@ void VToolDetail::Create(QSharedPointer<DialogDetail> &dialog, VMainGraphicsScen
{
VArc *arc = new VArc(*data->GeometricObject<const VArc *>(detail[i].getId()));
Q_ASSERT(arc != 0);
arc->setMode(Draw::Modeling);
id = data->AddGObject(arc);
VNodeArc::Create(doc, data, id, detail[i].getId(), Document::FullParse, Tool::FromGui);
}
@ -116,6 +118,7 @@ void VToolDetail::Create(QSharedPointer<DialogDetail> &dialog, VMainGraphicsScen
{
VSpline *spline = new VSpline(*data->GeometricObject<const VSpline *>(detail[i].getId()));
Q_ASSERT(spline != 0);
spline->setMode(Draw::Modeling);
id = data->AddGObject(spline);
VNodeSpline::Create(doc, data, id, detail[i].getId(), Document::FullParse, Tool::FromGui);
}
@ -124,6 +127,7 @@ void VToolDetail::Create(QSharedPointer<DialogDetail> &dialog, VMainGraphicsScen
{
VSplinePath *splinePath = new VSplinePath(*data->GeometricObject<const VSplinePath *>(detail[i].getId()));
Q_ASSERT(splinePath != 0);
splinePath->setMode(Draw::Modeling);
id = data->AddGObject(splinePath);
VNodeSplinePath::Create(doc, data, id, detail[i].getId(), Document::FullParse, Tool::FromGui);
}

View file

@ -461,6 +461,8 @@ qreal VDomDocument::GetParametrDouble(const QDomElement &domElement, const QStri
qreal param = parametr.replace(",", ".").toDouble(&ok);
if (ok == false)
{
qDebug()<<"defValue"<<defValue;
qDebug()<<"parametr"<<parametr;
throw VExceptionConversionError(tr("Can't convert toDouble parameter"), name);
}
return param;