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 pixmaps.files += dist/$${TARGET}.png
INSTALL_TRANSLATIONS += share/translations/valentina_ru.qm \ INSTALL_TRANSLATIONS += share/translations/valentina_ru.qm \
share/translations/valentina_uk.qm \ share/translations/valentina_uk.qm \
share/translations/valentina_de.qm \ share/translations/valentina_de.qm
translations.path = $$DATADIR/$${TARGET}/translations/ translations.path = $$DATADIR/$${TARGET}/translations/
translations.files = $$INSTALL_TRANSLATIONS translations.files = $$INSTALL_TRANSLATIONS
INSTALLS += target \ INSTALLS += target \

View File

@ -27,7 +27,6 @@
*************************************************************************/ *************************************************************************/
#include "vcontainer.h" #include "vcontainer.h"
#include "../exception/vexceptionbadid.h"
#include <QDebug> #include <QDebug>
#include <QtAlgorithms> #include <QtAlgorithms>
@ -63,7 +62,48 @@ VContainer::VContainer(const VContainer &data)
void VContainer::setData(const VContainer &data) void VContainer::setData(const VContainer &data)
{ {
base = *data.DataBase(); 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(); standartTable = *data.DataStandartTable();
incrementTable = *data.DataIncrementTable(); incrementTable = *data.DataIncrementTable();
lengthLines = *data.DataLengthLines(); lengthLines = *data.DataLengthLines();
@ -79,7 +119,7 @@ const VGObject *VContainer::GetGObject(qint64 id)const
} }
template <typename key, typename val> 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)) if (obj.contains(id))
{ {
@ -510,12 +550,15 @@ void VContainer::PrepareDetails(QVector<VItem *> &list) const
} }
template <typename val> 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_X(id > 0, Q_FUNC_INFO, "id <= 0");
Q_ASSERT(point != 0); Q_ASSERT(point != 0);
point->setId(id); point->setId(id);
delete GetObject(gObjects, id); // if (gObjects.contains(id))
// {
// delete gObjects.value(id);
// }
obj[id] = point; obj[id] = point;
UpdateId(id); UpdateId(id);
} }
@ -565,7 +608,15 @@ qreal VContainer::GetValueIncrementTableRow(const QString& name) const
void VContainer::Clear() void VContainer::Clear()
{ {
_id = 0; _id = 0;
if(standartTable.size()>0)
{
qDeleteAll(standartTable);
}
standartTable.clear(); standartTable.clear();
if(incrementTable.size()>0)
{
qDeleteAll(incrementTable);
}
incrementTable.clear(); incrementTable.clear();
lengthLines.clear(); lengthLines.clear();
lengthArcs.clear(); lengthArcs.clear();
@ -577,7 +628,10 @@ void VContainer::Clear()
void VContainer::ClearObject() void VContainer::ClearObject()
{ {
qDeleteAll(gObjects); if(gObjects.size()>0)
{
qDeleteAll(gObjects);
}
gObjects.clear(); gObjects.clear();
} }
@ -634,7 +688,7 @@ void VContainer::AddLine(const qint64 &firstPointId, const qint64 &secondPointId
} }
template <typename key, typename val> 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); Q_ASSERT(value != 0);
qint64 id = getNextId(); qint64 id = getNextId();

View File

@ -36,6 +36,7 @@
#include "../geometry/vdetail.h" #include "../geometry/vdetail.h"
#include "../widgets/vitem.h" #include "../widgets/vitem.h"
#include "../geometry/vgobject.h" #include "../geometry/vgobject.h"
#include "../exception/vexceptionbadid.h"
/** /**
* @brief The VContainer class container of all variables. * @brief The VContainer class container of all variables.
@ -67,7 +68,17 @@ public:
template <typename T> template <typename T>
const T GeometricObject(qint64 id) const 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); Q_ASSERT(obj != 0);
return obj; return obj;
} }
@ -481,7 +492,7 @@ private:
* @param id id of object * @param id id of object
* @return 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> template <typename key, typename val>
/** /**
* @brief GetObject return object from container * @brief GetObject return object from container
@ -497,7 +508,7 @@ private:
* @param id id of existing object * @param id id of existing object
* @param point 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> template <typename key, typename val>
/** /**
* @brief AddObject add object to container * @brief AddObject add object to container
@ -505,7 +516,7 @@ private:
* @param value object * @param value object
* @return id of object in container * @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 #endif // VCONTAINER_H

View File

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

View File

@ -29,20 +29,23 @@
#include "vdetail.h" #include "vdetail.h"
VDetail::VDetail() 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) 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; this->nodes = nodes;
} }
VDetail::VDetail(const VDetail &detail) 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()){} supplement(detail.getSupplement()), closed(detail.getClosed()), width(detail.getWidth()){}
VDetail &VDetail::operator =(const VDetail &detail) VDetail &VDetail::operator =(const VDetail &detail)
{ {
_id = detail.id();
nodes = detail.getNodes(); nodes = detail.getNodes();
name = detail.getName(); name = detail.getName();
mx = detail.getMx(); mx = detail.getMx();

View File

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

View File

@ -29,17 +29,17 @@
#include "vgobject.h" #include "vgobject.h"
VGObject::VGObject() 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) 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) 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) Q_DECLARE_OPERATORS_FOR_FLAGS(GObject::Types)
class VGObject class VGObject :public QObject
{ {
Q_DECLARE_TR_FUNCTIONS(VGObject) Q_OBJECT
public: public:
VGObject(); VGObject();
VGObject(const GObject::Type &type, const qint64 &idObject = 0, const Draw::Draws &mode = Draw::Calculation); VGObject(const GObject::Type &type, const qint64 &idObject = 0, const Draw::Draws &mode = Draw::Calculation);
@ -61,8 +61,8 @@ public:
Draw::Draws getMode() const; Draw::Draws getMode() const;
void setMode(const Draw::Draws &value); void setMode(const Draw::Draws &value);
GObject::Type getType() const; GObject::Type getType() const;
qint64 id() const; qint64 id() const;
void setId(const qint64 &id); void setId(const qint64 &id);
protected: protected:
/** /**
* @brief _id id in container. Ned for arcs, spline and spline paths. * @brief _id id in container. Ned for arcs, spline and spline paths.

View File

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

View File

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

View File

@ -51,7 +51,8 @@ Q_DECLARE_OPERATORS_FOR_FLAGS( SplinePoint::Positions )
*/ */
class VSplinePath :public VGObject class VSplinePath :public VGObject
{ {
Q_DECLARE_TR_FUNCTIONS(VSplinePath) Q_OBJECT
//Q_DECLARE_TR_FUNCTIONS(VSplinePath)
public: public:
/** /**
* @brief VSplinePath конструктор по замовчуванню. * @brief VSplinePath конструктор по замовчуванню.
@ -160,6 +161,7 @@ public:
*/ */
QPointF CutSplinePath(qreal length, qint32 &p1, qint32 &p2, QPointF &spl1p2, QPointF &spl1p3, QPointF &spl2p2, QPointF CutSplinePath(qreal length, qint32 &p1, qint32 &p2, QPointF &spl1p2, QPointF &spl1p3, QPointF &spl2p2,
QPointF &spl2p3) const; QPointF &spl2p3) const;
virtual QString name() const{return _name;}
protected: protected:
/** /**
* @brief path вектор з точок сплайна. * @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); VPointF *p = new VPointF(point.x(), point.y(), pointName, mx, my);
Q_ASSERT(p != 0); Q_ASSERT(p != 0);
id = data->AddGObject(p); id = data->AddGObject(p);
spl1id = id + 1;
spl2id = id + 2;
VSpline *spline1 = new VSpline(spl->GetP1(), spl1p2, spl1p3, *p, spl->GetKcurve()); VSpline *spline1 = new VSpline(spl->GetP1(), spl1p2, spl1p3, *p, spl->GetKcurve());
Q_ASSERT(spline1); Q_ASSERT(spline1);

View File

@ -130,7 +130,8 @@ void VToolSinglePoint::contextMenuEvent ( QGraphicsSceneContextMenuEvent * event
void VToolSinglePoint::FullUpdateFromFile() 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) void VToolSinglePoint::FullUpdateFromGui(int result)
@ -169,5 +170,5 @@ void VToolSinglePoint::ChangedActivDraw(const QString &newName)
void VToolSinglePoint::SetFactor(qreal factor) void VToolSinglePoint::SetFactor(qreal factor)
{ {
VDrawTool::SetFactor(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) const QPointF &pos)
{ {
VSplinePath splPath = *VAbstractTool::data.GeometricObject<const VSplinePath *>(id); VSplinePath splPath = *VAbstractTool::data.GeometricObject<const VSplinePath *>(id);
VSpline spl; VSpline spl = splPath.GetSpline(indexSpline);
if (position == SplinePoint::FirstPoint) if (position == SplinePoint::FirstPoint)
{ {
spl = VSpline(spl.GetP1(), pos, spl.GetP3(), spl.GetP4(), spl.GetKcurve()); spl = VSpline(spl.GetP1(), pos, spl.GetP3(), spl.GetP4(), spl.GetKcurve());

View File

@ -61,7 +61,7 @@ public:
* @brief setData * @brief setData
* @param value * @param value
*/ */
inline void setData(const VContainer *value) {data = *value;} inline void setData(const VContainer *value){data = *value;}
/** /**
* @brief referens * @brief referens
* @return * @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())); VPointF *point = new VPointF(*data->GeometricObject<const VPointF *>(detail[i].getId()));
Q_ASSERT(point != 0); Q_ASSERT(point != 0);
point->setMode(Draw::Modeling);
id = data->AddGObject(point); id = data->AddGObject(point);
VNodePoint::Create(doc, data, id, detail[i].getId(), Document::FullParse, Tool::FromGui); 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())); VArc *arc = new VArc(*data->GeometricObject<const VArc *>(detail[i].getId()));
Q_ASSERT(arc != 0); Q_ASSERT(arc != 0);
arc->setMode(Draw::Modeling);
id = data->AddGObject(arc); id = data->AddGObject(arc);
VNodeArc::Create(doc, data, id, detail[i].getId(), Document::FullParse, Tool::FromGui); 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())); VSpline *spline = new VSpline(*data->GeometricObject<const VSpline *>(detail[i].getId()));
Q_ASSERT(spline != 0); Q_ASSERT(spline != 0);
spline->setMode(Draw::Modeling);
id = data->AddGObject(spline); id = data->AddGObject(spline);
VNodeSpline::Create(doc, data, id, detail[i].getId(), Document::FullParse, Tool::FromGui); 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())); VSplinePath *splinePath = new VSplinePath(*data->GeometricObject<const VSplinePath *>(detail[i].getId()));
Q_ASSERT(splinePath != 0); Q_ASSERT(splinePath != 0);
splinePath->setMode(Draw::Modeling);
id = data->AddGObject(splinePath); id = data->AddGObject(splinePath);
VNodeSplinePath::Create(doc, data, id, detail[i].getId(), Document::FullParse, Tool::FromGui); 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); qreal param = parametr.replace(",", ".").toDouble(&ok);
if (ok == false) if (ok == false)
{ {
qDebug()<<"defValue"<<defValue;
qDebug()<<"parametr"<<parametr;
throw VExceptionConversionError(tr("Can't convert toDouble parameter"), name); throw VExceptionConversionError(tr("Can't convert toDouble parameter"), name);
} }
return param; return param;