From eddcaf8ff2b5026a97840135e65cf41c08d109a1 Mon Sep 17 00:00:00 2001 From: dismine Date: Mon, 30 Dec 2013 13:28:33 +0200 Subject: [PATCH] Fixed crashes. Still have memory leak. --HG-- branch : feature --- Valentina.pro | 2 +- src/container/vcontainer.cpp | 70 +++++++++++++++++++++--- src/container/vcontainer.h | 19 +++++-- src/geometry/varc.h | 4 +- src/geometry/vdetail.cpp | 9 ++- src/geometry/vdetail.h | 3 +- src/geometry/vgobject.cpp | 6 +- src/geometry/vgobject.h | 8 +-- src/geometry/vpointf.h | 2 + src/geometry/vspline.h | 1 + src/geometry/vsplinepath.h | 4 +- src/tools/drawTools/vtoolcutspline.cpp | 2 - src/tools/drawTools/vtoolsinglepoint.cpp | 5 +- src/tools/drawTools/vtoolsplinepath.cpp | 2 +- src/tools/vdatatool.h | 2 +- src/tools/vtooldetail.cpp | 4 ++ src/xml/vdomdocument.cpp | 2 + 17 files changed, 113 insertions(+), 32 deletions(-) diff --git a/Valentina.pro b/Valentina.pro index 508c984d5..fb54f3f3c 100644 --- a/Valentina.pro +++ b/Valentina.pro @@ -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 \ diff --git a/src/container/vcontainer.cpp b/src/container/vcontainer.cpp index 6cc374f3d..02f22013d 100644 --- a/src/container/vcontainer.cpp +++ b/src/container/vcontainer.cpp @@ -27,7 +27,6 @@ *************************************************************************/ #include "vcontainer.h" -#include "../exception/vexceptionbadid.h" #include #include @@ -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 *obj = data.DataGObjects(); + Q_ASSERT(obj != 0); + QHashIterator i(*obj); + while (i.hasNext()) + { + i.next(); + switch(i.value()->getType()) + { + case(GObject::Arc): + { + VArc *arc = new VArc(*data.GeometricObject(i.key())); + Q_ASSERT(arc != 0); + gObjects.insert(i.key(), arc); + break; + } + case(GObject::Point): + { + VPointF *point = new VPointF(*data.GeometricObject(i.key())); + Q_ASSERT(point != 0); + gObjects.insert(i.key(), point); + break; + } + case(GObject::Spline): + { + VSpline *spl = new VSpline(*data.GeometricObject(i.key())); + Q_ASSERT(spl != 0); + gObjects.insert(i.key(), spl); + break; + } + case(GObject::SplinePath): + { + VSplinePath *path = new VSplinePath(*data.GeometricObject(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 -const val *VContainer::GetObject(const QHash &obj, key id) const +const val VContainer::GetObject(const QHash &obj, key id) const { if (obj.contains(id)) { @@ -510,12 +550,15 @@ void VContainer::PrepareDetails(QVector &list) const } template -void VContainer::UpdateObject(QHash &obj, const qint64 &id, val *point) +void VContainer::UpdateObject(QHash &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 -qint64 VContainer::AddObject(QHash &obj, val *value) +qint64 VContainer::AddObject(QHash &obj, val value) { Q_ASSERT(value != 0); qint64 id = getNextId(); diff --git a/src/container/vcontainer.h b/src/container/vcontainer.h index c776860c8..14c86bed8 100644 --- a/src/container/vcontainer.h +++ b/src/container/vcontainer.h @@ -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 const T GeometricObject(qint64 id) const { - const T obj = dynamic_cast(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(gObj); + T obj = qobject_cast(gObj); Q_ASSERT(obj != 0); return obj; } @@ -481,7 +492,7 @@ private: * @param id id of object * @return Object */ - const val *GetObject(const QHash &obj, key id) const; + const val GetObject(const QHash &obj, key id) const; template /** * @brief GetObject return object from container @@ -497,7 +508,7 @@ private: * @param id id of existing object * @param point object */ - void UpdateObject(QHash &obj, const qint64 &id, val* point); + void UpdateObject(QHash &obj, const qint64 &id, val point); template /** * @brief AddObject add object to container @@ -505,7 +516,7 @@ private: * @param value object * @return id of object in container */ - static qint64 AddObject(QHash &obj, val *value); + static qint64 AddObject(QHash &obj, val value); }; #endif // VCONTAINER_H diff --git a/src/geometry/varc.h b/src/geometry/varc.h index e412c0279..e1af9dda1 100644 --- a/src/geometry/varc.h +++ b/src/geometry/varc.h @@ -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 SplOfArc( qint32 number ) const; + virtual QString name() const{return _name;} private: /** * @brief f1 початковий кут в градусах diff --git a/src/geometry/vdetail.cpp b/src/geometry/vdetail.cpp index 15dfe150d..86b3129bd 100644 --- a/src/geometry/vdetail.cpp +++ b/src/geometry/vdetail.cpp @@ -29,20 +29,23 @@ #include "vdetail.h" VDetail::VDetail() - :_id(0), nodes(QVector()), name(QString()), mx(0), my(0), supplement(true), closed(true), width(10){} + :QObject(), _id(0), nodes(QVector()), name(QString()), mx(0), my(0), supplement(true), closed(true), + width(10){} VDetail::VDetail(const QString &name, const QVector &nodes) - :_id(0), nodes(QVector()), name(name), mx(0), my(0), supplement(true), closed(true), width(10) + :QObject(), _id(0), nodes(QVector()), 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(); diff --git a/src/geometry/vdetail.h b/src/geometry/vdetail.h index ffb362f1f..239a2ce6e 100644 --- a/src/geometry/vdetail.h +++ b/src/geometry/vdetail.h @@ -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 diff --git a/src/geometry/vgobject.cpp b/src/geometry/vgobject.cpp index 94d025598..ddec0e5f0 100644 --- a/src/geometry/vgobject.cpp +++ b/src/geometry/vgobject.cpp @@ -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()) { } diff --git a/src/geometry/vgobject.h b/src/geometry/vgobject.h index 6c9f5b24a..b71a5496b 100644 --- a/src/geometry/vgobject.h +++ b/src/geometry/vgobject.h @@ -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. diff --git a/src/geometry/vpointf.h b/src/geometry/vpointf.h index 86e91d629..ffa62b7be 100644 --- a/src/geometry/vpointf.h +++ b/src/geometry/vpointf.h @@ -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 diff --git a/src/geometry/vspline.h b/src/geometry/vspline.h index 7575c370a..18db98a62 100644 --- a/src/geometry/vspline.h +++ b/src/geometry/vspline.h @@ -45,6 +45,7 @@ class QString; */ class VSpline :public VGObject { + Q_OBJECT public: /** * @brief VSpline default constructor diff --git a/src/geometry/vsplinepath.h b/src/geometry/vsplinepath.h index a50aeb5a8..bbd4b2792 100644 --- a/src/geometry/vsplinepath.h +++ b/src/geometry/vsplinepath.h @@ -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 вектор з точок сплайна. diff --git a/src/tools/drawTools/vtoolcutspline.cpp b/src/tools/drawTools/vtoolcutspline.cpp index 7e3bd24dc..cf2927c93 100644 --- a/src/tools/drawTools/vtoolcutspline.cpp +++ b/src/tools/drawTools/vtoolcutspline.cpp @@ -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); diff --git a/src/tools/drawTools/vtoolsinglepoint.cpp b/src/tools/drawTools/vtoolsinglepoint.cpp index f40c0ef71..cc2d15f13 100644 --- a/src/tools/drawTools/vtoolsinglepoint.cpp +++ b/src/tools/drawTools/vtoolsinglepoint.cpp @@ -130,7 +130,8 @@ void VToolSinglePoint::contextMenuEvent ( QGraphicsSceneContextMenuEvent * event void VToolSinglePoint::FullUpdateFromFile() { - RefreshPointGeometry(*VAbstractTool::data.GeometricObject(id)); + VPointF point = *VAbstractTool::data.GeometricObject(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(id)); + RefreshPointGeometry(*(VAbstractTool::data.GeometricObject(id))); } diff --git a/src/tools/drawTools/vtoolsplinepath.cpp b/src/tools/drawTools/vtoolsplinepath.cpp index 9b7373240..3c2d4f003 100644 --- a/src/tools/drawTools/vtoolsplinepath.cpp +++ b/src/tools/drawTools/vtoolsplinepath.cpp @@ -171,7 +171,7 @@ void VToolSplinePath::ControlPointChangePosition(const qint32 &indexSpline, cons const QPointF &pos) { VSplinePath splPath = *VAbstractTool::data.GeometricObject(id); - VSpline spl; + VSpline spl = splPath.GetSpline(indexSpline); if (position == SplinePoint::FirstPoint) { spl = VSpline(spl.GetP1(), pos, spl.GetP3(), spl.GetP4(), spl.GetKcurve()); diff --git a/src/tools/vdatatool.h b/src/tools/vdatatool.h index a7b0cfcf5..0b7a30070 100644 --- a/src/tools/vdatatool.h +++ b/src/tools/vdatatool.h @@ -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 diff --git a/src/tools/vtooldetail.cpp b/src/tools/vtooldetail.cpp index 472ee1098..38d0c8f70 100644 --- a/src/tools/vtooldetail.cpp +++ b/src/tools/vtooldetail.cpp @@ -100,6 +100,7 @@ void VToolDetail::Create(QSharedPointer &dialog, VMainGraphicsScen { VPointF *point = new VPointF(*data->GeometricObject(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 &dialog, VMainGraphicsScen { VArc *arc = new VArc(*data->GeometricObject(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 &dialog, VMainGraphicsScen { VSpline *spline = new VSpline(*data->GeometricObject(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 &dialog, VMainGraphicsScen { VSplinePath *splinePath = new VSplinePath(*data->GeometricObject(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); } diff --git a/src/xml/vdomdocument.cpp b/src/xml/vdomdocument.cpp index b8287798c..57a7f45ab 100644 --- a/src/xml/vdomdocument.cpp +++ b/src/xml/vdomdocument.cpp @@ -461,6 +461,8 @@ qreal VDomDocument::GetParametrDouble(const QDomElement &domElement, const QStri qreal param = parametr.replace(",", ".").toDouble(&ok); if (ok == false) { + qDebug()<<"defValue"<