From 3782400aae5136e22f1d3403065f99fb1b97cc78 Mon Sep 17 00:00:00 2001 From: dismine Date: Mon, 30 Sep 2013 19:29:03 +0300 Subject: [PATCH] Added option delete object ( for tools, details ). --HG-- branch : feature --- container/vcontainer.cpp | 70 -------- container/vcontainer.h | 1 - container/vpointf.cpp | 92 ----------- container/vpointf.h | 66 ++++---- geometry/varc.cpp | 36 +---- geometry/varc.h | 5 - geometry/vdetail.h | 6 +- geometry/vnodedetail.h | 1 - geometry/vspline.cpp | 27 +--- geometry/vspline.h | 4 - geometry/vsplinepath.cpp | 40 ++--- geometry/vsplinepath.h | 15 +- geometry/vsplinepoint.h | 1 - mainwindow.cpp | 2 +- tools/drawTools/vdrawtool.h | 13 +- tools/drawTools/vtoolalongline.cpp | 25 ++- tools/drawTools/vtoolalongline.h | 2 +- tools/drawTools/vtoolarc.cpp | 23 ++- tools/drawTools/vtoolarc.h | 1 + tools/drawTools/vtoolbisector.cpp | 26 ++- tools/drawTools/vtoolbisector.h | 1 + tools/drawTools/vtoolendline.cpp | 18 +-- tools/drawTools/vtoolline.cpp | 20 +-- tools/drawTools/vtoolline.h | 1 + tools/drawTools/vtoollineintersect.cpp | 28 ++-- tools/drawTools/vtoollineintersect.h | 33 ++-- tools/drawTools/vtoollinepoint.cpp | 4 + tools/drawTools/vtoollinepoint.h | 13 +- tools/drawTools/vtoolnormal.cpp | 24 ++- tools/drawTools/vtoolnormal.h | 1 + tools/drawTools/vtoolpoint.h | 11 +- tools/drawTools/vtoolpointofcontact.cpp | 26 ++- tools/drawTools/vtoolpointofcontact.h | 1 + tools/drawTools/vtoolshoulderpoint.cpp | 26 ++- tools/drawTools/vtoolshoulderpoint.h | 1 + tools/drawTools/vtoolsinglepoint.cpp | 6 + tools/drawTools/vtoolsinglepoint.h | 1 + tools/drawTools/vtoolspline.cpp | 25 ++- tools/drawTools/vtoolspline.h | 1 + tools/drawTools/vtoolsplinepath.cpp | 27 ++-- tools/drawTools/vtoolsplinepath.h | 15 +- tools/modelingTools/vmodelingalongline.cpp | 19 ++- tools/modelingTools/vmodelingalongline.h | 38 ++--- tools/modelingTools/vmodelingarc.cpp | 17 +- tools/modelingTools/vmodelingarc.h | 18 +-- tools/modelingTools/vmodelingbisector.cpp | 22 +-- tools/modelingTools/vmodelingbisector.h | 45 +++--- tools/modelingTools/vmodelingendline.cpp | 12 +- tools/modelingTools/vmodelingendline.h | 34 ++-- tools/modelingTools/vmodelingline.cpp | 18 +-- tools/modelingTools/vmodelingline.h | 35 ++-- .../modelingTools/vmodelinglineintersect.cpp | 21 ++- tools/modelingTools/vmodelinglineintersect.h | 33 ++-- tools/modelingTools/vmodelinglinepoint.cpp | 4 + tools/modelingTools/vmodelinglinepoint.h | 14 +- tools/modelingTools/vmodelingnormal.cpp | 19 ++- tools/modelingTools/vmodelingnormal.h | 27 ++-- tools/modelingTools/vmodelingpoint.h | 11 +- .../modelingTools/vmodelingpointofcontact.cpp | 22 +-- tools/modelingTools/vmodelingpointofcontact.h | 50 +++--- .../modelingTools/vmodelingshoulderpoint.cpp | 33 ++-- tools/modelingTools/vmodelingshoulderpoint.h | 47 +++--- tools/modelingTools/vmodelingspline.cpp | 14 +- tools/modelingTools/vmodelingspline.h | 19 +-- tools/modelingTools/vmodelingsplinepath.cpp | 23 +-- tools/modelingTools/vmodelingsplinepath.h | 15 +- tools/modelingTools/vmodelingtool.cpp | 17 ++ tools/modelingTools/vmodelingtool.h | 5 +- tools/nodeDetails/vabstractnode.cpp | 20 ++- tools/nodeDetails/vabstractnode.h | 5 +- tools/nodeDetails/vnodearc.cpp | 10 +- tools/nodeDetails/vnodearc.h | 18 +-- tools/nodeDetails/vnodepoint.cpp | 10 +- tools/nodeDetails/vnodepoint.h | 13 +- tools/nodeDetails/vnodespline.cpp | 1 + tools/nodeDetails/vnodesplinepath.cpp | 16 +- tools/nodeDetails/vnodesplinepath.h | 9 +- tools/vabstracttool.cpp | 2 - tools/vabstracttool.h | 3 +- tools/vdatatool.cpp | 6 + tools/vdatatool.h | 21 +-- tools/vtooldetail.cpp | 129 +++++++++------ tools/vtooldetail.h | 27 ++-- xml/vdomdocument.cpp | 153 +++++------------- xml/vdomdocument.h | 2 + 85 files changed, 801 insertions(+), 1015 deletions(-) diff --git a/container/vcontainer.cpp b/container/vcontainer.cpp index e9b7de59f..8f20e2036 100644 --- a/container/vcontainer.cpp +++ b/container/vcontainer.cpp @@ -165,76 +165,6 @@ void VContainer::UpdateId(qint64 newId){ } } -void VContainer::IncrementReferens(qint64 id, Scene::Scenes obj, Draw::Draws mode){ - switch( obj ){ - case(Scene::Line): - break; - case(Scene::Point):{ - VPointF point; - if(mode == Draw::Calculation){ - point = GetPoint(id); - } else { - point = GetModelingPoint(id); - } - point.incrementReferens(); - if(mode == Draw::Calculation){ - UpdatePoint(id, point); - } else { - UpdateModelingPoint(id, point); - } - } - break; - case(Scene::Arc):{ - VArc arc; - if(mode == Draw::Calculation){ - arc = GetArc(id); - } else { - arc = GetModelingArc(id); - } - arc.incrementReferens(); - if(mode == Draw::Calculation){ - UpdateArc(id, arc); - } else { - UpdateModelingArc(id, arc); - } - } - break; - case(Scene::Spline):{ - VSpline spl; - if(mode == Draw::Calculation){ - spl = GetSpline(id); - } else { - spl = GetModelingSpline(id); - } - spl.incrementReferens(); - if(mode == Draw::Calculation){ - UpdateSpline(id, spl); - } else { - UpdateModelingSpline(id, spl); - } - } - break; - case(Scene::SplinePath):{ - VSplinePath splPath; - if(mode == Draw::Calculation){ - splPath = GetSplinePath(id); - } else { - splPath = GetModelingSplinePath(id); - } - splPath.incrementReferens(); - if(mode == Draw::Calculation){ - UpdateSplinePath(id, splPath); - } else { - UpdateModelingSplinePath(id, splPath); - } - } - break; - default: - qWarning()<<"Get wrong scene type."; - break; - } -} - QPainterPath VContainer::ContourPath(qint64 idDetail) const{ VDetail detail = GetDetail(idDetail); QVector points; diff --git a/container/vcontainer.h b/container/vcontainer.h index 8dd77a356..33ed7eede 100644 --- a/container/vcontainer.h +++ b/container/vcontainer.h @@ -143,7 +143,6 @@ public: const QMap *DataModelingSplinePaths() const; const QMap *DataDetails() const; static void UpdateId(qint64 newId); - void IncrementReferens(qint64 id, Scene::Scenes obj, Draw::Draws mode = Draw::Calculation); QPainterPath ContourPath(qint64 idDetail) const; QPainterPath Equidistant(QVector points, const Detail::Equidistant &eqv, const qreal &width)const; diff --git a/container/vpointf.cpp b/container/vpointf.cpp index ae429b3e3..b9ae72544 100644 --- a/container/vpointf.cpp +++ b/container/vpointf.cpp @@ -21,105 +21,13 @@ #include "vpointf.h" -VPointF::VPointF():_name(QString()), _mx(0), _my(0), _x(0), _y(0), _referens(0), mode(Draw::Calculation), - idObject(0){ -} - -VPointF::VPointF ( const VPointF & point ):_name(point.name()), _mx(point.mx()), _my(point.my()), - _x(point.x()), _y(point.y()), _referens(point.referens()), mode(point.getMode()), idObject(point.getIdObject()){ -} - -VPointF::VPointF (qreal x, qreal y , QString name, qreal mx, qreal my, Draw::Draws mode, qint64 idObject):_name(name), _mx(mx), - _my(my), _x(x), _y(y), _referens(0), mode(mode), idObject(idObject){ -} - VPointF &VPointF::operator =(const VPointF &point){ _name = point.name(); _mx = point.mx(); _my = point.my(); _x = point.x(); _y = point.y(); - _referens = point.referens(); mode = point.getMode(); idObject = point.getIdObject(); return *this; } - -VPointF::~VPointF(){ -} - -QString VPointF::name() const{ - return _name; -} - -qreal VPointF::mx() const{ - return _mx; -} - -qreal VPointF::my() const{ - return _my; -} - -void VPointF::setName(const QString& name){ - _name = name; -} - -void VPointF::setMx(qreal mx){ - _mx = mx; -} - -void VPointF::setMy(qreal my){ - _my = my; -} - -QPointF VPointF::toQPointF()const{ - return QPointF(_x, _y); -} - -qreal VPointF::y() const{ - return _y; -} - -void VPointF::setY(const qreal &value){ - _y = value; -} - -qreal VPointF::x() const{ - return _x; -} - -void VPointF::setX(const qreal &value){ - _x = value; -} - -qint32 VPointF::referens() const{ - return _referens; -} - -void VPointF::incrementReferens(){ - ++_referens; -} - -void VPointF::decrementReferens(){ - if(_referens > 0){ - --_referens; - } -} - -Draw::Draws VPointF::getMode() const -{ - return mode; -} - -void VPointF::setMode(const Draw::Draws &value) -{ - mode = value; -} - -qint64 VPointF::getIdObject() const{ - return idObject; -} - -void VPointF::setIdObject(const qint64 &value){ - idObject = value; -} diff --git a/container/vpointf.h b/container/vpointf.h index 8db65792e..cfe7c8f1a 100644 --- a/container/vpointf.h +++ b/container/vpointf.h @@ -28,41 +28,39 @@ class VPointF{ public: - VPointF(); - VPointF (const VPointF &point ); - VPointF ( qreal x, qreal y, QString name, qreal mx, qreal my, Draw::Draws mode = Draw::Calculation, - qint64 idObject = 0); - VPointF &operator=(const VPointF &point); - ~VPointF(); - QString name() const; - qreal mx() const; - qreal my() const; - void setName(const QString &name); - void setMx(qreal mx); - void setMy(qreal my); - QPointF toQPointF()const; - qreal x() const; - void setX(const qreal &value); - qreal y() const; - void setY(const qreal &value); - qint32 referens() const; - void incrementReferens(); - void decrementReferens(); - Draw::Draws getMode() const; - void setMode(const Draw::Draws &value); - - qint64 getIdObject() const; - void setIdObject(const qint64 &value); - + inline VPointF () + :_name(QString()), _mx(0), _my(0), _x(0), _y(0), mode(Draw::Calculation), idObject(0){} + inline VPointF (const VPointF &point ) + :_name(point.name()), _mx(point.mx()), _my(point.my()), _x(point.x()), _y(point.y()), + mode(point.getMode()), idObject(point.getIdObject()){} + inline VPointF ( qreal x, qreal y, QString name, qreal mx, qreal my, + Draw::Draws mode = Draw::Calculation, qint64 idObject = 0) + :_name(name), _mx(mx), _my(my), _x(x), _y(y), mode(mode), idObject(idObject){} + VPointF &operator=(const VPointF &point); + ~VPointF(){} + inline QString name() const { return _name;} + inline qreal mx() const {return _mx;} + inline qreal my() const {return _my;} + inline void setName(const QString &name) {_name = name;} + inline void setMx(qreal mx) {_mx = mx;} + inline void setMy(qreal my) {_my = my;} + inline QPointF toQPointF()const {return QPointF(_x, _y);} + inline qreal x() const {return _x;} + inline void setX(const qreal &value){_x = value;} + inline qreal y() const {return _y;} + inline void setY(const qreal &value){_y = value;} + inline Draw::Draws getMode() const{return mode;} + inline void setMode(const Draw::Draws &value) {mode = value;} + inline qint64 getIdObject() const {return idObject;} + inline void setIdObject(const qint64 &value) {idObject = value;} private: - QString _name; - qreal _mx; - qreal _my; - qreal _x; - qreal _y; - qint32 _referens; - Draw::Draws mode; - qint64 idObject; + QString _name; + qreal _mx; + qreal _my; + qreal _x; + qreal _y; + Draw::Draws mode; + qint64 idObject; }; #endif // VPOINTF_H diff --git a/geometry/varc.cpp b/geometry/varc.cpp index a0194bc11..3ab6180c9 100644 --- a/geometry/varc.cpp +++ b/geometry/varc.cpp @@ -19,24 +19,22 @@ ** ****************************************************************************/ -#define _USE_MATH_DEFINES -#include #include "varc.h" #include VArc::VArc () : f1(0), formulaF1(QString()), f2(0), formulaF2(QString()), radius(0), formulaRadius(QString()), - center(0), points(0), _referens(0), mode(Draw::Calculation), idObject(0){ + center(0), points(0), mode(Draw::Calculation), idObject(0){ } VArc::VArc (const QMap *points, qint64 center, qreal radius, QString formulaRadius, qreal f1, QString formulaF1, qreal f2, QString formulaF2, Draw::Draws mode, qint64 idObject) : f1(f1), formulaF1(formulaF1), f2(f2), formulaF2(formulaF2), radius(radius), formulaRadius(formulaRadius), - center(center), points(points), _referens(0), mode(mode), idObject(idObject){ + center(center), points(points), mode(mode), idObject(idObject){ } VArc::VArc(const VArc &arc): f1(arc.GetF1()), formulaF1(arc.GetFormulaF1()), f2(arc.GetF2()), formulaF2(arc.GetFormulaF2()), radius(arc.GetRadius()), formulaRadius(arc.GetFormulaRadius()), - center(arc.GetCenter()), points(arc.GetDataPoints()), _referens(0), mode(arc.getMode()), + center(arc.GetCenter()), points(arc.GetDataPoints()), mode(arc.getMode()), idObject(arc.getIdObject()){ } @@ -50,7 +48,6 @@ VArc &VArc::operator =(const VArc &arc){ this->formulaRadius = arc.GetFormulaRadius(); this->center = arc.GetCenter(); this->mode = arc.getMode(); - this->_referens = 0; this->idObject = arc.getIdObject(); return *this; } @@ -198,37 +195,18 @@ QVector VArc::SplOfArc(qint32 number) const{ return QVector(); } -qint32 VArc::referens() const{ - return _referens; -} - -void VArc::incrementReferens(){ - ++_referens; -} - -void VArc::decrementReferens(){ - if(_referens > 0){ - --_referens; - } -} - - -Draw::Draws VArc::getMode() const -{ +Draw::Draws VArc::getMode() const{ return mode; } -void VArc::setMode(const Draw::Draws &value) -{ +void VArc::setMode(const Draw::Draws &value){ mode = value; } -qint64 VArc::getIdObject() const -{ +qint64 VArc::getIdObject() const{ return idObject; } -void VArc::setIdObject(const qint64 &value) -{ +void VArc::setIdObject(const qint64 &value){ idObject = value; } diff --git a/geometry/varc.h b/geometry/varc.h index 2bd06c6b0..f467a15f9 100644 --- a/geometry/varc.h +++ b/geometry/varc.h @@ -98,12 +98,8 @@ public: qint32 NumberSplOfArc () const; QVector GetPoints () const; QVector SplOfArc( qint32 number ) const; - qint32 referens() const; - void incrementReferens(); - void decrementReferens(); Draw::Draws getMode() const; void setMode(const Draw::Draws &value); - qint64 getIdObject() const; void setIdObject(const qint64 &value); @@ -128,7 +124,6 @@ private: */ qint64 center; const QMap *points; - qint32 _referens; Draw::Draws mode; qint64 idObject; }; diff --git a/geometry/vdetail.h b/geometry/vdetail.h index 0c314604a..45cf841fb 100644 --- a/geometry/vdetail.h +++ b/geometry/vdetail.h @@ -37,8 +37,7 @@ namespace Detail { Q_DECLARE_OPERATORS_FOR_FLAGS(Detail::Contours) Q_DECLARE_OPERATORS_FOR_FLAGS(Detail::Equidistants) -class VDetail -{ +class VDetail{ public: VDetail(); VDetail(const QString &name, const QVector &nodes); @@ -49,13 +48,10 @@ public: VNodeDetail & operator[](int indx); QString getName() const; void setName(const QString &value); - qreal getMx() const; void setMx(const qreal &value); - qreal getMy() const; void setMy(const qreal &value); - private: QVector nodes; QString name; diff --git a/geometry/vnodedetail.h b/geometry/vnodedetail.h index 7ea0da2c3..71763a677 100644 --- a/geometry/vnodedetail.h +++ b/geometry/vnodedetail.h @@ -22,7 +22,6 @@ #ifndef VNODEDETAIL_H #define VNODEDETAIL_H -#include #include #include "options.h" diff --git a/geometry/vspline.cpp b/geometry/vspline.cpp index ad1f1b189..69f6ff495 100644 --- a/geometry/vspline.cpp +++ b/geometry/vspline.cpp @@ -19,31 +19,29 @@ ** ****************************************************************************/ -#define _USE_MATH_DEFINES -#include #include "vspline.h" #include VSpline::VSpline():p1(0), p2(QPointF()), p3(QPointF()), p4(0), angle1(0), angle2(0), kAsm1(1), kAsm2(1), - kCurve(1), points(0), _referens(0), mode(Draw::Calculation), idObject(0){ + kCurve(1), points(0), mode(Draw::Calculation), idObject(0){ } VSpline::VSpline ( const VSpline & spline ):p1(spline.GetP1 ()), p2(spline.GetP2 ()), p3(spline.GetP3 ()), p4(spline.GetP4 ()), angle1(spline.GetAngle1 ()), angle2(spline.GetAngle2 ()), kAsm1(spline.GetKasm1()), - kAsm2(spline.GetKasm2()), kCurve(spline.GetKcurve()), points(spline.GetDataPoints()), _referens(0), + kAsm2(spline.GetKasm2()), kCurve(spline.GetKcurve()), points(spline.GetDataPoints()), mode(spline.getMode()), idObject(spline.getIdObject()){ } VSpline::VSpline (const QMap *points, qint64 p1, qint64 p4, qreal angle1, qreal angle2, qreal kAsm1, qreal kAsm2 , qreal kCurve, Draw::Draws mode, qint64 idObject):p1(p1), p2(QPointF()), p3(QPointF()), p4(p4), angle1(angle1), angle2(angle2), kAsm1(kAsm1), kAsm2(kAsm2), kCurve(kCurve), points(points), - _referens(0), mode(mode), idObject(idObject){ + mode(mode), idObject(idObject){ ModifiSpl ( p1, p4, angle1, angle2, kAsm1, kAsm2, kCurve ); } VSpline::VSpline (const QMap *points, qint64 p1, QPointF p2, QPointF p3, qint64 p4, - qreal kCurve, Draw::Draws mode, qint64 idObject):p1(p1), p2(p2), p3(p3), p4(p4), angle1(0), angle2(0), kAsm1(1), kAsm2(1), - kCurve(1), points(points), _referens(0), mode(mode), idObject(idObject){ + qreal kCurve, Draw::Draws mode, qint64 idObject):p1(p1), p2(p2), p3(p3), p4(p4), angle1(0), + angle2(0), kAsm1(1), kAsm2(1), kCurve(1), points(points), mode(mode), idObject(idObject){ ModifiSpl ( p1, p2, p3, p4, kCurve); } @@ -629,20 +627,6 @@ QPainterPath VSpline::GetPath() const{ return splinePath; } -qint32 VSpline::referens() const{ - return _referens; -} - -void VSpline::incrementReferens(){ - ++_referens; -} - -void VSpline::decrementReferens(){ - if(_referens > 0){ - --_referens; - } -} - /* Cubic equation solution. Real coefficients case. int Cubic(double *x,double a,double b,double c); @@ -811,7 +795,6 @@ VSpline &VSpline::operator =(const VSpline &spline){ this->kAsm2 = spline.GetKasm2(); this->kCurve = spline.GetKcurve(); this->points = spline.GetDataPoints(); - this->_referens = 0; this->mode = spline.getMode(); this->idObject = spline.getIdObject(); return *this; diff --git a/geometry/vspline.h b/geometry/vspline.h index 38dff39ab..72898a9fb 100644 --- a/geometry/vspline.h +++ b/geometry/vspline.h @@ -180,9 +180,6 @@ public: * @param Pmirror точка відносно якої відбувається вертикальне дзеркалення сплайну. */ // void Mirror(const QPointF Pmirror); - qint32 referens() const; - void incrementReferens(); - void decrementReferens(); Draw::Draws getMode() const; void setMode(const Draw::Draws &value); static QVector SplinePoints(QPointF p1, QPointF p4, qreal angle1, @@ -229,7 +226,6 @@ private: qreal kAsm2; qreal kCurve; const QMap *points; - qint32 _referens; Draw::Draws mode; qint64 idObject; /** diff --git a/geometry/vsplinepath.cpp b/geometry/vsplinepath.cpp index ab1d5da7f..8e3823ee3 100644 --- a/geometry/vsplinepath.cpp +++ b/geometry/vsplinepath.cpp @@ -20,17 +20,18 @@ ****************************************************************************/ #include "vsplinepath.h" +#include "exception/vexception.h" VSplinePath::VSplinePath(): path(QVector()), kCurve(1), mode(Draw::Calculation), points(0), - _referens(0), idObject(0){ + idObject(0){ } VSplinePath::VSplinePath(const QMap *points, qreal kCurve, Draw::Draws mode, qint64 idObject): path(QVector()), - kCurve(kCurve), mode(mode), points(points), _referens(0), idObject(idObject){ + kCurve(kCurve), mode(mode), points(points), idObject(idObject){ } VSplinePath::VSplinePath(const VSplinePath &splPath): path(*splPath.GetPoint()), - kCurve(splPath.getKCurve()), mode(splPath.getMode()), points( splPath.GetDataPoints()), _referens(0), + kCurve(splPath.getKCurve()), mode(splPath.getMode()), points( splPath.GetDataPoints()), idObject(splPath.getIdObject()){ } @@ -60,10 +61,10 @@ qint32 VSplinePath::CountPoint() const{ VSpline VSplinePath::GetSpline(qint32 index) const{ if(Count()<1){ - throw "Недостатня кількість точок для створення сплайну."; + throw VException(tr("Not enough points to create the spline.")); } if(index < 1 || index > Count()){ - throw "Такого сплайну немає."; + throw VException(tr("This spline is not exist.")); } VSpline spl(points, path[index-1].P(), path[index].P(), path[index-1].Angle2(), path[index].Angle1(), path[index-1].KAsm2(), path[index].KAsm1(), this->kCurve); @@ -113,7 +114,7 @@ const QMap *VSplinePath::GetDataPoints() const{ void VSplinePath::UpdatePoint(qint32 indexSpline, SplinePoint::Position pos, VSplinePoint point){ if(indexSpline < 1 || indexSpline > Count()){ - throw "Такого сплайну немає."; + throw VException(tr("This spline is not exist.")); } if(pos == SplinePoint::FirstPoint){ path[indexSpline-1] = point; @@ -124,7 +125,7 @@ void VSplinePath::UpdatePoint(qint32 indexSpline, SplinePoint::Position pos, VSp VSplinePoint VSplinePath::GetSplinePoint(qint32 indexSpline, SplinePoint::Position pos) const{ if(indexSpline < 1 || indexSpline > Count()){ - throw "Такого сплайну немає."; + throw VException(tr("This spline is not exist.")); } if(pos == SplinePoint::FirstPoint){ return path.at(indexSpline-1); @@ -154,7 +155,6 @@ VSplinePath &VSplinePath::operator =(const VSplinePath &path){ this->kCurve = path.getKCurve(); this->mode = path.getMode(); this->points = path.GetDataPoints(); - this->_referens = 0; this->idObject = path.getIdObject(); return *this; } @@ -163,26 +163,10 @@ VSplinePoint & VSplinePath::operator[](int indx){ return path[indx]; } -qint32 VSplinePath::referens() const{ - return _referens; +qint64 VSplinePath::getIdObject() const{ + return idObject; } -void VSplinePath::incrementReferens(){ - ++_referens; -} - -void VSplinePath::decrementReferens(){ - if(_referens > 0){ - --_referens; - } -} - -qint64 VSplinePath::getIdObject() const -{ -return idObject; -} - -void VSplinePath::setIdObject(const qint64 &value) -{ -idObject = value; +void VSplinePath::setIdObject(const qint64 &value){ + idObject = value; } diff --git a/geometry/vsplinepath.h b/geometry/vsplinepath.h index b78fabb97..3170668b7 100644 --- a/geometry/vsplinepath.h +++ b/geometry/vsplinepath.h @@ -23,22 +23,21 @@ #define VSPLINEPATH_H #include "vsplinepoint.h" -#include #include "vspline.h" #include "options.h" +#include namespace SplinePoint{ - enum Position - { - FirstPoint, - LastPoint - }; +enum Position { FirstPoint, LastPoint }; +Q_DECLARE_FLAGS(Positions, Position) } +Q_DECLARE_OPERATORS_FOR_FLAGS( SplinePoint::Positions ) /** * @brief The VSplinePath клас, що розраховує шлях сплайнів. */ class VSplinePath{ + Q_DECLARE_TR_FUNCTIONS(VSplinePath) public: /** * @brief VSplinePath конструктор по замовчуванню. @@ -74,9 +73,6 @@ public: const QVector *GetPoint() const; VSplinePath& operator=(const VSplinePath &path); VSplinePoint & operator[](int indx); - qint32 referens() const; - void incrementReferens(); - void decrementReferens(); Draw::Draws getMode() const; void setMode(const Draw::Draws &value); @@ -91,7 +87,6 @@ protected: qreal kCurve; Draw::Draws mode; const QMap *points; - qint32 _referens; qint64 idObject; }; diff --git a/geometry/vsplinepoint.h b/geometry/vsplinepoint.h index caed526f4..219e9fa96 100644 --- a/geometry/vsplinepoint.h +++ b/geometry/vsplinepoint.h @@ -22,7 +22,6 @@ #ifndef VSPLINEPOINT_H #define VSPLINEPOINT_H -#include "QtGlobal" #include /** diff --git a/mainwindow.cpp b/mainwindow.cpp index 3455b67f2..65cdfb791 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -729,7 +729,7 @@ void MainWindow::ActionSaveAs(){ QString filters("Lekalo files (*.xml);;All files (*.*)"); QString defaultFilter("Lekalo files (*.xml)"); QString fName = QFileDialog::getSaveFileName(this, "Зберегти файл як", QDir::homePath(), - filters, &defaultFilter); + filters, &defaultFilter); if(fName.isEmpty()) return; if(fName.indexOf(".xml",fName.size()-4)<0){ diff --git a/tools/drawTools/vdrawtool.h b/tools/drawTools/vdrawtool.h index 263424814..6f322f33e 100644 --- a/tools/drawTools/vdrawtool.h +++ b/tools/drawTools/vdrawtool.h @@ -25,8 +25,7 @@ #include "../vabstracttool.h" #include -class VDrawTool : public VAbstractTool -{ +class VDrawTool : public VAbstractTool{ Q_OBJECT public: VDrawTool(VDomDocument *doc, VContainer *data, qint64 id, QObject *parent = 0); @@ -54,9 +53,11 @@ protected: QAction *actionRemove; if(showRemove){ actionRemove = menu.addAction(tr("Delete")); - } else { - actionRemove = menu.addAction(tr("Delete")); - actionRemove->setEnabled(false); + if(_referens > 1){ + actionRemove->setEnabled(false); + } else { + actionRemove->setEnabled(true); + } } QAction *selectedAction = menu.exec(event->screenPos()); if(selectedAction == actionOption){ @@ -73,6 +74,8 @@ protected: dialog->show(); } if(selectedAction == actionRemove){ + //deincrement referens + RemoveReferens(); //remove form xml file QDomElement domElement = doc->elementById(QString().setNum(id)); if(domElement.isElement()){ diff --git a/tools/drawTools/vtoolalongline.cpp b/tools/drawTools/vtoolalongline.cpp index 02c278b73..c2c59128f 100644 --- a/tools/drawTools/vtoolalongline.cpp +++ b/tools/drawTools/vtoolalongline.cpp @@ -65,12 +65,7 @@ void VToolAlongLine::FullUpdateFromGui(int result){ } void VToolAlongLine::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){ - VPointF point = VDrawTool::data.GetPoint(id); - if(point.referens() > 1){ - ContextMenu(dialogAlongLine, this, event, false); - } else { - ContextMenu(dialogAlongLine, this, event); - } + ContextMenu(dialogAlongLine, this, event); } void VToolAlongLine::AddToFile(){ @@ -91,6 +86,11 @@ void VToolAlongLine::AddToFile(){ AddToCalculation(domElement); } +void VToolAlongLine::RemoveReferens(){ + doc->DecrementReferens(secondPointId); + VToolLinePoint::RemoveReferens(); +} + void VToolAlongLine::setDialog(){ Q_ASSERT(!dialogAlongLine.isNull()); if(!dialogAlongLine.isNull()){ @@ -132,12 +132,7 @@ void VToolAlongLine::Create(const qint64 _id, const QString &pointName, const QS } else { data->UpdatePoint(id, VPointF(line.p2().x(), line.p2().y(), pointName, mx, my)); if(parse != Document::FullParse){ - QMap* tools = doc->getTools(); - VDataTool *tool = tools->value(id); - if(tool != 0){ - tool->VDataTool::setData(data); - data->IncrementReferens(id, Scene::Point); - } + doc->UpdateToolData(id, data); } } VDrawTool::AddRecord(id, Tool::AlongLineTool, doc); @@ -149,9 +144,9 @@ void VToolAlongLine::Create(const qint64 _id, const QString &pointName, const QS scene->addItem(point); connect(point, &VToolAlongLine::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); connect(point, &VToolAlongLine::RemoveTool, scene, &VMainGraphicsScene::RemoveTool); - QMap* tools = doc->getTools(); - tools->insert(id,point); - + doc->AddTool(id, point); + doc->IncrementReferens(firstPointId); + doc->IncrementReferens(secondPointId); } } } diff --git a/tools/drawTools/vtoolalongline.h b/tools/drawTools/vtoolalongline.h index cbc88828d..aede99661 100644 --- a/tools/drawTools/vtoolalongline.h +++ b/tools/drawTools/vtoolalongline.h @@ -45,7 +45,7 @@ public slots: protected: virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); virtual void AddToFile(); - + virtual void RemoveReferens(); private: qint64 secondPointId; QSharedPointer dialogAlongLine; diff --git a/tools/drawTools/vtoolarc.cpp b/tools/drawTools/vtoolarc.cpp index 1f7350973..d8f1c50be 100644 --- a/tools/drawTools/vtoolarc.cpp +++ b/tools/drawTools/vtoolarc.cpp @@ -91,12 +91,7 @@ void VToolArc::Create(const qint64 _id, const qint64 ¢er, const QString &rad } else { data->UpdateArc(id, arc); if(parse != Document::FullParse){ - QMap* tools = doc->getTools(); - VDataTool *tool = tools->value(id); - if(tool != 0){ - tool->VDataTool::setData(data); - data->IncrementReferens(id, Scene::Arc); - } + doc->UpdateToolData(id, data); } } data->AddLengthArc(data->GetNameArc(center,id), arc.GetLength()); @@ -106,8 +101,8 @@ void VToolArc::Create(const qint64 _id, const qint64 ¢er, const QString &rad scene->addItem(toolArc); connect(toolArc, &VToolArc::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); connect(toolArc, &VToolArc::RemoveTool, scene, &VMainGraphicsScene::RemoveTool); - QMap* tools = doc->getTools(); - tools->insert(id,toolArc); + doc->AddTool(id, toolArc); + doc->IncrementReferens(center); } } @@ -156,12 +151,7 @@ void VToolArc::ShowTool(qint64 id, Qt::GlobalColor color, bool enable){ } void VToolArc::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){ - VArc arc = VDrawTool::data.GetArc(id); - if(arc.referens() > 1){ - ContextMenu(dialogArc, this, event, false); - } else { - ContextMenu(dialogArc, this, event); - } + ContextMenu(dialogArc, this, event); } void VToolArc::AddToFile(){ @@ -195,6 +185,11 @@ void VToolArc::hoverLeaveEvent(QGraphicsSceneHoverEvent *event){ this->setPen(QPen(currentColor, widthHairLine)); } +void VToolArc::RemoveReferens(){ + VArc arc = VAbstractTool::data.GetArc(id); + doc->DecrementReferens(arc.GetCenter()); +} + void VToolArc::RefreshGeometry(){ VArc arc = VAbstractTool::data.GetArc(id); QPainterPath path; diff --git a/tools/drawTools/vtoolarc.h b/tools/drawTools/vtoolarc.h index 43c6ae195..00c5a43a3 100644 --- a/tools/drawTools/vtoolarc.h +++ b/tools/drawTools/vtoolarc.h @@ -52,6 +52,7 @@ protected: virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ); virtual void hoverMoveEvent ( QGraphicsSceneHoverEvent * event ); virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ); + virtual void RemoveReferens(); private: QSharedPointer dialogArc; void RefreshGeometry(); diff --git a/tools/drawTools/vtoolbisector.cpp b/tools/drawTools/vtoolbisector.cpp index ccad2a3b2..65dfd66eb 100644 --- a/tools/drawTools/vtoolbisector.cpp +++ b/tools/drawTools/vtoolbisector.cpp @@ -95,12 +95,7 @@ void VToolBisector::Create(const qint64 _id, const QString &formula, const qint6 } else { data->UpdatePoint(id, VPointF(fPoint.x(), fPoint.y(), pointName, mx, my)); if(parse != Document::FullParse){ - QMap* tools = doc->getTools(); - VDataTool *tool = tools->value(id); - if(tool != 0){ - tool->VDataTool::setData(data); - data->IncrementReferens(id, Scene::Point); - } + doc->UpdateToolData(id, data); } } data->AddLine(firstPointId, id); @@ -112,8 +107,10 @@ void VToolBisector::Create(const qint64 _id, const QString &formula, const qint6 scene->addItem(point); connect(point, &VToolBisector::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); connect(point, &VToolBisector::RemoveTool, scene, &VMainGraphicsScene::RemoveTool); - QMap* tools = doc->getTools(); - tools->insert(id,point); + doc->AddTool(id, point); + doc->IncrementReferens(firstPointId); + doc->IncrementReferens(secondPointId); + doc->IncrementReferens(thirdPointId); } } } @@ -147,12 +144,7 @@ void VToolBisector::FullUpdateFromGui(int result){ } void VToolBisector::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){ - VPointF point = VDrawTool::data.GetPoint(id); - if(point.referens() > 1){ - ContextMenu(dialogBisector, this, event, false); - } else { - ContextMenu(dialogBisector, this, event); - } + ContextMenu(dialogBisector, this, event); } void VToolBisector::AddToFile(){ @@ -173,3 +165,9 @@ void VToolBisector::AddToFile(){ AddToCalculation(domElement); } + +void VToolBisector::RemoveReferens(){ + doc->DecrementReferens(firstPointId); + doc->DecrementReferens(thirdPointId); + VToolLinePoint::RemoveReferens(); +} diff --git a/tools/drawTools/vtoolbisector.h b/tools/drawTools/vtoolbisector.h index c9b23323e..2f257fd1e 100644 --- a/tools/drawTools/vtoolbisector.h +++ b/tools/drawTools/vtoolbisector.h @@ -49,6 +49,7 @@ public slots: protected: virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); virtual void AddToFile(); + virtual void RemoveReferens(); private: qint64 firstPointId; qint64 thirdPointId; diff --git a/tools/drawTools/vtoolendline.cpp b/tools/drawTools/vtoolendline.cpp index 5b27d4888..a118ba707 100644 --- a/tools/drawTools/vtoolendline.cpp +++ b/tools/drawTools/vtoolendline.cpp @@ -77,11 +77,7 @@ void VToolEndLine::Create(const qint64 _id, const QString &pointName, const QStr } else { data->UpdatePoint(id, VPointF(line.p2().x(), line.p2().y(), pointName, mx, my)); if(parse != Document::FullParse){ - QMap* tools = doc->getTools(); - VDataTool *tool = tools->value(id); - Q_CHECK_PTR(tool); - data->IncrementReferens(id, Scene::Point); - tool->VDataTool::setData(data); + doc->UpdateToolData(id, data); } } data->AddLine(basePointId, id); @@ -92,9 +88,8 @@ void VToolEndLine::Create(const qint64 _id, const QString &pointName, const QStr scene->addItem(point); connect(point, &VToolPoint::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); connect(point, &VToolPoint::RemoveTool, scene, &VMainGraphicsScene::RemoveTool); - QMap* tools = doc->getTools(); - Q_CHECK_PTR(tools); - tools->insert(id,point); + doc->AddTool(id, point); + doc->IncrementReferens(basePointId); } } } @@ -111,12 +106,7 @@ void VToolEndLine::FullUpdateFromFile(){ } void VToolEndLine::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){ - VPointF point = VDrawTool::data.GetPoint(id); - if(point.referens() > 1){ - ContextMenu(dialogEndLine, this, event, false); - } else { - ContextMenu(dialogEndLine, this, event); - } + ContextMenu(dialogEndLine, this, event); } void VToolEndLine::FullUpdateFromGui(int result){ diff --git a/tools/drawTools/vtoolline.cpp b/tools/drawTools/vtoolline.cpp index 6eca70621..bd83d48c9 100644 --- a/tools/drawTools/vtoolline.cpp +++ b/tools/drawTools/vtoolline.cpp @@ -53,18 +53,14 @@ void VToolLine::Create(QSharedPointer &dialog, VMainGraphicsScene *s } void VToolLine::Create(const qint64 &id, const qint64 &firstPoint, const qint64 &secondPoint, - VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data, const Document::Documents &parse, - Tool::Sources typeCreation){ + VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data, + const Document::Documents &parse, Tool::Sources typeCreation){ Q_CHECK_PTR(scene); Q_CHECK_PTR(doc); Q_CHECK_PTR(data); data->AddLine(firstPoint, secondPoint); if(parse != Document::FullParse){ - QMap* tools = doc->getTools(); - Q_CHECK_PTR(tools); - VDataTool *tool = tools->value(id); - Q_CHECK_PTR(tool); - tool->VDataTool::setData(data); + doc->UpdateToolData(id, data); } VDrawTool::AddRecord(id, Tool::LineTool, doc); if(parse == Document::FullParse){ @@ -74,8 +70,9 @@ void VToolLine::Create(const qint64 &id, const qint64 &firstPoint, const qint64 scene->addItem(line); connect(line, &VToolLine::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); connect(line, &VToolLine::RemoveTool, scene, &VMainGraphicsScene::RemoveTool); - QMap* tools = doc->getTools(); - tools->insert(id,line); + doc->AddTool(id, line); + doc->IncrementReferens(firstPoint); + doc->IncrementReferens(secondPoint); } } @@ -150,3 +147,8 @@ void VToolLine::hoverLeaveEvent(QGraphicsSceneHoverEvent *event){ this->setPen(QPen(currentColor, widthHairLine)); } +void VToolLine::RemoveReferens(){ + doc->DecrementReferens(firstPoint); + doc->DecrementReferens(secondPoint); +} + diff --git a/tools/drawTools/vtoolline.h b/tools/drawTools/vtoolline.h index e39493385..fa6fbe1db 100644 --- a/tools/drawTools/vtoolline.h +++ b/tools/drawTools/vtoolline.h @@ -48,6 +48,7 @@ protected: virtual void AddToFile(); virtual void hoverMoveEvent ( QGraphicsSceneHoverEvent * event ); virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ); + virtual void RemoveReferens(); private: qint64 firstPoint; qint64 secondPoint; diff --git a/tools/drawTools/vtoollineintersect.cpp b/tools/drawTools/vtoollineintersect.cpp index 9e642db4b..e1a0abbd0 100644 --- a/tools/drawTools/vtoollineintersect.cpp +++ b/tools/drawTools/vtoollineintersect.cpp @@ -75,12 +75,7 @@ void VToolLineIntersect::Create(const qint64 _id, const qint64 &p1Line1Id, const } else { data->UpdatePoint(id, VPointF(fPoint.x(), fPoint.y(), pointName, mx, my)); if(parse != Document::FullParse){ - QMap* tools = doc->getTools(); - VDataTool *tool = tools->value(id); - if(tool != 0){ - tool->VDataTool::setData(data); - data->IncrementReferens(id, Scene::Point); - } + doc->UpdateToolData(id, data); } } data->AddLine(p1Line1Id, id); @@ -95,8 +90,11 @@ void VToolLineIntersect::Create(const qint64 _id, const qint64 &p1Line1Id, const scene->addItem(point); connect(point, &VToolLineIntersect::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); connect(point, &VToolLineIntersect::RemoveTool, scene, &VMainGraphicsScene::RemoveTool); - QMap* tools = doc->getTools(); - tools->insert(id,point); + doc->AddTool(id, point); + doc->IncrementReferens(p1Line1Id); + doc->IncrementReferens(p2Line1Id); + doc->IncrementReferens(p1Line2Id); + doc->IncrementReferens(p2Line2Id); } } } @@ -128,12 +126,7 @@ void VToolLineIntersect::FullUpdateFromGui(int result){ } void VToolLineIntersect::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){ - VPointF point = VDrawTool::data.GetPoint(id); - if(point.referens() > 1){ - ContextMenu(dialogLineIntersect, this, event, false); - } else { - ContextMenu(dialogLineIntersect, this, event); - } + ContextMenu(dialogLineIntersect, this, event); } void VToolLineIntersect::AddToFile(){ @@ -153,3 +146,10 @@ void VToolLineIntersect::AddToFile(){ AddToCalculation(domElement); } + +void VToolLineIntersect::RemoveReferens(){ + doc->DecrementReferens(p1Line1); + doc->DecrementReferens(p2Line1); + doc->DecrementReferens(p1Line2); + doc->DecrementReferens(p2Line2); +} diff --git a/tools/drawTools/vtoollineintersect.h b/tools/drawTools/vtoollineintersect.h index 272cf81cb..1c5b36cfd 100644 --- a/tools/drawTools/vtoollineintersect.h +++ b/tools/drawTools/vtoollineintersect.h @@ -25,29 +25,32 @@ #include "vtoolpoint.h" #include "dialogs/dialoglineintersect.h" -class VToolLineIntersect:public VToolPoint -{ +class VToolLineIntersect:public VToolPoint{ Q_OBJECT public: - VToolLineIntersect(VDomDocument *doc, VContainer *data, - const qint64 &id, - const qint64 &p1Line1, - const qint64 &p2Line1, const qint64 &p1Line2, - const qint64 &p2Line2, Tool::Sources typeCreation, - QGraphicsItem * parent = 0); - virtual void setDialog(); - static void Create(QSharedPointer &dialog, VMainGraphicsScene *scene, - VDomDocument *doc,VContainer *data); - static void Create(const qint64 _id, const qint64 &p1Line1Id, const qint64 &p2Line1Id, - const qint64 &p1Line2Id, const qint64 &p2Line2Id, const QString &pointName, - const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VDomDocument *doc, - VContainer *data, const Document::Documents &parse, Tool::Sources typeCreation); + VToolLineIntersect(VDomDocument *doc, VContainer *data, + const qint64 &id, + const qint64 &p1Line1, + const qint64 &p2Line1, const qint64 &p1Line2, + const qint64 &p2Line2, Tool::Sources typeCreation, + QGraphicsItem * parent = 0); + virtual void setDialog(); + static void Create(QSharedPointer &dialog, + VMainGraphicsScene *scene, VDomDocument *doc, + VContainer *data); + static void Create(const qint64 _id, const qint64 &p1Line1Id, + const qint64 &p2Line1Id, const qint64 &p1Line2Id, + const qint64 &p2Line2Id, const QString &pointName, + const qreal &mx, const qreal &my, VMainGraphicsScene *scene, + VDomDocument *doc, VContainer *data, + const Document::Documents &parse, Tool::Sources typeCreation); public slots: virtual void FullUpdateFromFile(); virtual void FullUpdateFromGui(int result); protected: virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); virtual void AddToFile(); + virtual void RemoveReferens(); private: qint64 p1Line1; qint64 p2Line1; diff --git a/tools/drawTools/vtoollinepoint.cpp b/tools/drawTools/vtoollinepoint.cpp index f5088faa5..b7536c1ae 100644 --- a/tools/drawTools/vtoollinepoint.cpp +++ b/tools/drawTools/vtoollinepoint.cpp @@ -60,3 +60,7 @@ void VToolLinePoint::RefreshGeometry(){ mainLine->setVisible(true); } } + +void VToolLinePoint::RemoveReferens(){ + doc->DecrementReferens(basePointId); +} diff --git a/tools/drawTools/vtoollinepoint.h b/tools/drawTools/vtoollinepoint.h index e9ed1562f..a298bc5f1 100644 --- a/tools/drawTools/vtoollinepoint.h +++ b/tools/drawTools/vtoollinepoint.h @@ -24,13 +24,12 @@ #include "vtoolpoint.h" -class VToolLinePoint : public VToolPoint -{ +class VToolLinePoint : public VToolPoint{ Q_OBJECT public: - VToolLinePoint(VDomDocument *doc, VContainer *data, const qint64 &id, - const QString &typeLine, const QString &formula, - const qint64 &basePointId, const qreal &angle, QGraphicsItem * parent = 0); + VToolLinePoint(VDomDocument *doc, VContainer *data, const qint64 &id, + const QString &typeLine, const QString &formula, + const qint64 &basePointId, const qreal &angle, QGraphicsItem * parent = 0); public slots: virtual void ChangedActivDraw(const QString newName); protected: @@ -40,9 +39,9 @@ protected: qint64 basePointId; QGraphicsLineItem *mainLine; virtual void RefreshGeometry(); + virtual void RemoveReferens(); private: - VToolLinePoint(const VToolLinePoint &tool); - const VToolLinePoint &operator=(const VToolLinePoint &tool); + Q_DISABLE_COPY(VToolLinePoint) }; #endif // VTOOLLINEPOINT_H diff --git a/tools/drawTools/vtoolnormal.cpp b/tools/drawTools/vtoolnormal.cpp index c699b4e30..701089c16 100644 --- a/tools/drawTools/vtoolnormal.cpp +++ b/tools/drawTools/vtoolnormal.cpp @@ -78,12 +78,7 @@ void VToolNormal::Create(const qint64 _id, const QString &formula, const qint64 } else { data->UpdatePoint(id, VPointF(fPoint.x(), fPoint.y(), pointName, mx, my)); if(parse != Document::FullParse){ - QMap* tools = doc->getTools(); - VDataTool *tool = tools->value(id); - if(tool != 0){ - tool->VDataTool::setData(data); - data->IncrementReferens(id, Scene::Point); - } + doc->UpdateToolData(id, data); } } data->AddLine(firstPointId, id); @@ -94,8 +89,9 @@ void VToolNormal::Create(const qint64 _id, const QString &formula, const qint64 scene->addItem(point); connect(point, &VToolNormal::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); connect(point, &VToolNormal::RemoveTool, scene, &VMainGraphicsScene::RemoveTool); - QMap* tools = doc->getTools(); - tools->insert(id,point); + doc->AddTool(id, point); + doc->IncrementReferens(firstPointId); + doc->IncrementReferens(secondPointId); } } } @@ -138,12 +134,7 @@ void VToolNormal::FullUpdateFromGui(int result){ } void VToolNormal::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){ - VPointF point = VDrawTool::data.GetPoint(id); - if(point.referens() > 1){ - ContextMenu(dialogNormal, this, event, false); - } else { - ContextMenu(dialogNormal, this, event); - } + ContextMenu(dialogNormal, this, event); } void VToolNormal::AddToFile(){ @@ -164,3 +155,8 @@ void VToolNormal::AddToFile(){ AddToCalculation(domElement); } + +void VToolNormal::RemoveReferens(){ + doc->DecrementReferens(secondPointId); + VToolLinePoint::RemoveReferens(); +} diff --git a/tools/drawTools/vtoolnormal.h b/tools/drawTools/vtoolnormal.h index 4b258f882..2410bc163 100644 --- a/tools/drawTools/vtoolnormal.h +++ b/tools/drawTools/vtoolnormal.h @@ -50,6 +50,7 @@ public slots: protected: virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); virtual void AddToFile(); + virtual void RemoveReferens(); private: qint64 secondPointId; QSharedPointer dialogNormal; diff --git a/tools/drawTools/vtoolpoint.h b/tools/drawTools/vtoolpoint.h index 4154afc43..1a6a15f4c 100644 --- a/tools/drawTools/vtoolpoint.h +++ b/tools/drawTools/vtoolpoint.h @@ -26,12 +26,12 @@ #include "widgets/vgraphicssimpletextitem.h" #include "options.h" -class VToolPoint: public VDrawTool, public QGraphicsEllipseItem -{ +class VToolPoint: public VDrawTool, public QGraphicsEllipseItem{ Q_OBJECT public: - VToolPoint(VDomDocument *doc, VContainer *data, qint64 id, QGraphicsItem * parent = 0); - virtual ~VToolPoint(); + VToolPoint(VDomDocument *doc, VContainer *data, qint64 id, + QGraphicsItem * parent = 0); + virtual ~VToolPoint(); public slots: void NameChangePosition(const QPointF pos); virtual void ChangedActivDraw(const QString newName); @@ -48,8 +48,7 @@ protected: virtual void RefreshPointGeometry(const VPointF &point); void RefreshLine(); private: - VToolPoint(const VToolPoint &tool); - const VToolPoint &operator=(const VToolPoint &tool); + Q_DISABLE_COPY(VToolPoint) }; #endif // VTOOLPOINT_H diff --git a/tools/drawTools/vtoolpointofcontact.cpp b/tools/drawTools/vtoolpointofcontact.cpp index 2649502e4..a87391f74 100644 --- a/tools/drawTools/vtoolpointofcontact.cpp +++ b/tools/drawTools/vtoolpointofcontact.cpp @@ -99,12 +99,7 @@ void VToolPointOfContact::Create(const qint64 _id, const QString &radius, const } else { data->UpdatePoint(id,VPointF(fPoint.x(), fPoint.y(), pointName, mx, my)); if(parse != Document::FullParse){ - QMap* tools = doc->getTools(); - VDataTool *tool = tools->value(id); - if(tool != 0){ - tool->VDataTool::setData(data); - data->IncrementReferens(id, Scene::Point); - } + doc->UpdateToolData(id, data); } } VDrawTool::AddRecord(id, Tool::PointOfContact, doc); @@ -114,8 +109,10 @@ void VToolPointOfContact::Create(const qint64 _id, const QString &radius, const scene->addItem(point); connect(point, &VToolPointOfContact::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); connect(point, &VToolPointOfContact::RemoveTool, scene, &VMainGraphicsScene::RemoveTool); - QMap* tools = doc->getTools(); - tools->insert(id,point); + doc->AddTool(id, point); + doc->IncrementReferens(center); + doc->IncrementReferens(firstPointId); + doc->IncrementReferens(secondPointId); } } } @@ -147,12 +144,7 @@ void VToolPointOfContact::FullUpdateFromGui(int result){ } void VToolPointOfContact::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){ - VPointF point = VDrawTool::data.GetPoint(id); - if(point.referens() > 1){ - ContextMenu(dialogPointOfContact, this, event, false); - } else { - ContextMenu(dialogPointOfContact, this, event); - } + ContextMenu(dialogPointOfContact, this, event); } void VToolPointOfContact::AddToFile(){ @@ -172,3 +164,9 @@ void VToolPointOfContact::AddToFile(){ AddToCalculation(domElement); } + +void VToolPointOfContact::RemoveReferens(){ + doc->DecrementReferens(center); + doc->DecrementReferens(firstPointId); + doc->DecrementReferens(secondPointId); +} diff --git a/tools/drawTools/vtoolpointofcontact.h b/tools/drawTools/vtoolpointofcontact.h index 8da8368ea..4ed8e0c97 100644 --- a/tools/drawTools/vtoolpointofcontact.h +++ b/tools/drawTools/vtoolpointofcontact.h @@ -46,6 +46,7 @@ public slots: protected: virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); virtual void AddToFile(); + virtual void RemoveReferens(); private: QString radius; qint64 center; diff --git a/tools/drawTools/vtoolshoulderpoint.cpp b/tools/drawTools/vtoolshoulderpoint.cpp index a3737c402..bd137bf4a 100644 --- a/tools/drawTools/vtoolshoulderpoint.cpp +++ b/tools/drawTools/vtoolshoulderpoint.cpp @@ -103,12 +103,7 @@ void VToolShoulderPoint::Create(const qint64 _id, const QString &formula, const } else { data->UpdatePoint(id,VPointF(fPoint.x(), fPoint.y(), pointName, mx, my)); if(parse != Document::FullParse){ - QMap* tools = doc->getTools(); - VDataTool *tool = tools->value(id); - if(tool != 0){ - tool->VDataTool::setData(data); - data->IncrementReferens(id, Scene::Point); - } + doc->UpdateToolData(id, data); } } data->AddLine(p1Line, id); @@ -121,8 +116,10 @@ void VToolShoulderPoint::Create(const qint64 _id, const QString &formula, const scene->addItem(point); connect(point, &VToolShoulderPoint::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); connect(point, &VToolShoulderPoint::RemoveTool, scene, &VMainGraphicsScene::RemoveTool); - QMap* tools = doc->getTools(); - tools->insert(id,point); + doc->AddTool(id, point); + doc->IncrementReferens(p1Line); + doc->IncrementReferens(p2Line); + doc->IncrementReferens(pShoulder); } } } @@ -156,12 +153,7 @@ void VToolShoulderPoint::FullUpdateFromGui(int result){ } void VToolShoulderPoint::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){ - VPointF point = VDrawTool::data.GetPoint(id); - if(point.referens() > 1){ - ContextMenu(dialogShoulderPoint, this, event, false); - } else { - ContextMenu(dialogShoulderPoint, this, event); - } + ContextMenu(dialogShoulderPoint, this, event); } void VToolShoulderPoint::AddToFile(){ @@ -182,3 +174,9 @@ void VToolShoulderPoint::AddToFile(){ AddToCalculation(domElement); } + +void VToolShoulderPoint::RemoveReferens(){ + doc->DecrementReferens(p2Line); + doc->DecrementReferens(pShoulder); + VToolLinePoint::RemoveReferens(); +} diff --git a/tools/drawTools/vtoolshoulderpoint.h b/tools/drawTools/vtoolshoulderpoint.h index 82fc40057..91f682ecb 100644 --- a/tools/drawTools/vtoolshoulderpoint.h +++ b/tools/drawTools/vtoolshoulderpoint.h @@ -47,6 +47,7 @@ public slots: protected: virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); virtual void AddToFile(); + virtual void RemoveReferens(); private: qint64 p2Line; qint64 pShoulder; diff --git a/tools/drawTools/vtoolsinglepoint.cpp b/tools/drawTools/vtoolsinglepoint.cpp index 46e2c9dcc..3da725ceb 100644 --- a/tools/drawTools/vtoolsinglepoint.cpp +++ b/tools/drawTools/vtoolsinglepoint.cpp @@ -89,6 +89,12 @@ QVariant VToolSinglePoint::itemChange(QGraphicsItem::GraphicsItemChange change, return QGraphicsItem::itemChange(change, value); } +void VToolSinglePoint::decrementReferens(){ + if(_referens > 1){ + --_referens; + } +} + void VToolSinglePoint::contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ){ ContextMenu(dialogSinglePoint, this, event, false); } diff --git a/tools/drawTools/vtoolsinglepoint.h b/tools/drawTools/vtoolsinglepoint.h index ae12a1b7f..f2ff140a1 100644 --- a/tools/drawTools/vtoolsinglepoint.h +++ b/tools/drawTools/vtoolsinglepoint.h @@ -44,6 +44,7 @@ protected: virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); virtual void AddToFile(); QVariant itemChange ( GraphicsItemChange change, const QVariant &value ); + virtual void decrementReferens(); private: QSharedPointer dialogSinglePoint; }; diff --git a/tools/drawTools/vtoolspline.cpp b/tools/drawTools/vtoolspline.cpp index a657f78a5..30dc78755 100644 --- a/tools/drawTools/vtoolspline.cpp +++ b/tools/drawTools/vtoolspline.cpp @@ -98,12 +98,7 @@ void VToolSpline::Create(const qint64 _id, const qint64 &p1, const qint64 &p4, c } else { data->UpdateSpline(id, spline); if(parse != Document::FullParse){ - QMap* tools = doc->getTools(); - VDataTool *tool = tools->value(id); - if(tool != 0){ - tool->VDataTool::setData(data); - data->IncrementReferens(id, Scene::Spline); - } + doc->UpdateToolData(id, data); } } data->AddLengthSpline(data->GetNameSpline(p1, p4), spline.GetLength()); @@ -113,8 +108,9 @@ void VToolSpline::Create(const qint64 _id, const qint64 &p1, const qint64 &p4, c scene->addItem(spl); connect(spl, &VToolSpline::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); connect(spl, &VToolSpline::RemoveTool, scene, &VMainGraphicsScene::RemoveTool); - QMap* tools = doc->getTools(); - tools->insert(id,spl); + doc->AddTool(id, spl); + doc->IncrementReferens(p1); + doc->IncrementReferens(p4); } } @@ -177,12 +173,7 @@ void VToolSpline::ControlPointChangePosition(const qint32 &indexSpline, SplinePo } void VToolSpline::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){ - VSpline spl = VDrawTool::data.GetSpline(id); - if(spl.referens() > 1){ - ContextMenu(dialogSpline, this, event, false); - } else { - ContextMenu(dialogSpline, this, event); - } + ContextMenu(dialogSpline, this, event); } void VToolSpline::AddToFile(){ @@ -219,6 +210,12 @@ void VToolSpline::hoverLeaveEvent(QGraphicsSceneHoverEvent *event){ this->setPen(QPen(currentColor, widthHairLine)); } +void VToolSpline::RemoveReferens(){ + VSpline spl = VAbstractTool::data.GetSpline(id); + doc->DecrementReferens(spl.GetP1()); + doc->DecrementReferens(spl.GetP4()); +} + void VToolSpline::RefreshGeometry(){ VSpline spl = VAbstractTool::data.GetSpline(id); QPainterPath path; diff --git a/tools/drawTools/vtoolspline.h b/tools/drawTools/vtoolspline.h index 79580a0fd..74ece8b89 100644 --- a/tools/drawTools/vtoolspline.h +++ b/tools/drawTools/vtoolspline.h @@ -61,6 +61,7 @@ protected: virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ); virtual void hoverMoveEvent ( QGraphicsSceneHoverEvent * event ); virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ); + virtual void RemoveReferens(); private: QSharedPointer dialogSpline; QVector controlPoints; diff --git a/tools/drawTools/vtoolsplinepath.cpp b/tools/drawTools/vtoolsplinepath.cpp index e33e21678..b862f6815 100644 --- a/tools/drawTools/vtoolsplinepath.cpp +++ b/tools/drawTools/vtoolsplinepath.cpp @@ -70,6 +70,9 @@ void VToolSplinePath::setDialog(){ void VToolSplinePath::Create(QSharedPointer &dialog, VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data){ VSplinePath path = dialog->GetPath(); + for(qint32 i = 0; i < path.CountPoint(); ++i){ + doc->IncrementReferens(path[i].P()); + } Create(0, path, scene, doc, data, Document::FullParse, Tool::FromGui); } @@ -82,12 +85,7 @@ void VToolSplinePath::Create(const qint64 _id, const VSplinePath &path, VMainGra } else { data->UpdateSplinePath(id, path); if(parse != Document::FullParse){ - QMap* tools = doc->getTools(); - VDataTool *tool = tools->value(id); - if(tool != 0){ - tool->VDataTool::setData(data); - data->IncrementReferens(id, Scene::SplinePath); - } + doc->UpdateToolData(id, data); } } data->AddLengthSpline(data->GetNameSplinePath(path), path.GetLength()); @@ -97,8 +95,7 @@ void VToolSplinePath::Create(const qint64 _id, const VSplinePath &path, VMainGra scene->addItem(spl); connect(spl, &VToolSplinePath::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); connect(spl, &VToolSplinePath::RemoveTool, scene, &VMainGraphicsScene::RemoveTool); - QMap* tools = doc->getTools(); - tools->insert(id,spl); + doc->AddTool(id, spl); } } @@ -216,12 +213,7 @@ void VToolSplinePath::ShowTool(qint64 id, Qt::GlobalColor color, bool enable){ } void VToolSplinePath::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){ - VSplinePath path = VDrawTool::data.GetSplinePath(id); - if(path.referens() > 1){ - ContextMenu(dialogSplinePath, this, event, false); - } else { - ContextMenu(dialogSplinePath, this, event); - } + ContextMenu(dialogSplinePath, this, event); } void VToolSplinePath::AddToFile(){ @@ -267,6 +259,13 @@ void VToolSplinePath::hoverLeaveEvent(QGraphicsSceneHoverEvent *event){ this->setPen(QPen(currentColor, widthHairLine)); } +void VToolSplinePath::RemoveReferens(){ + VSplinePath splPath = VAbstractTool::data.GetSplinePath(id); + for(qint32 i = 0; i < splPath.Count(); ++i){ + doc->DecrementReferens(splPath[i].P()); + } +} + void VToolSplinePath::RefreshGeometry(){ VSplinePath splPath = VAbstractTool::data.GetSplinePath(id); QPainterPath path; diff --git a/tools/drawTools/vtoolsplinepath.h b/tools/drawTools/vtoolsplinepath.h index b96e78105..f4559e6ec 100644 --- a/tools/drawTools/vtoolsplinepath.h +++ b/tools/drawTools/vtoolsplinepath.h @@ -29,18 +29,18 @@ #include "widgets/vcontrolpointspline.h" #include "container/vcontainer.h" -class VToolSplinePath:public VDrawTool, public QGraphicsPathItem -{ +class VToolSplinePath:public VDrawTool, public QGraphicsPathItem{ Q_OBJECT public: VToolSplinePath(VDomDocument *doc, VContainer *data, qint64 id, Tool::Sources typeCreation, QGraphicsItem * parent = 0); - virtual void setDialog(); - static void Create(QSharedPointer &dialog, VMainGraphicsScene *scene, - VDomDocument *doc, VContainer *data); - static void Create(const qint64 _id, const VSplinePath &path, VMainGraphicsScene *scene, - VDomDocument *doc, VContainer *data, const Document::Documents &parse, Tool::Sources typeCreation); + virtual void setDialog(); + static void Create(QSharedPointer &dialog, + VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data); + static void Create(const qint64 _id, const VSplinePath &path, + VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data, + const Document::Documents &parse, Tool::Sources typeCreation); signals: void RefreshLine(const qint32 &indexSpline, SplinePoint::Position pos, const QPointF &controlPoint, const QPointF &splinePoint); @@ -59,6 +59,7 @@ protected: virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ); virtual void hoverMoveEvent ( QGraphicsSceneHoverEvent * event ); virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ); + virtual void RemoveReferens(); private: QSharedPointer dialogSplinePath; QVector controlPoints; diff --git a/tools/modelingTools/vmodelingalongline.cpp b/tools/modelingTools/vmodelingalongline.cpp index ee4049c6b..3423e2db8 100644 --- a/tools/modelingTools/vmodelingalongline.cpp +++ b/tools/modelingTools/vmodelingalongline.cpp @@ -86,6 +86,11 @@ void VModelingAlongLine::AddToFile(){ AddToModeling(domElement); } +void VModelingAlongLine::RemoveReferens(){ + doc->DecrementReferens(secondPointId); + VModelingLinePoint::RemoveReferens(); +} + void VModelingAlongLine::setDialog(){ Q_ASSERT(!dialogAlongLine.isNull()); if(!dialogAlongLine.isNull()){ @@ -130,24 +135,18 @@ VModelingAlongLine *VModelingAlongLine::Create(const qint64 _id, const QString & } else { data->UpdateModelingPoint(id, VPointF(line.p2().x(), line.p2().y(), pointName, mx, my)); if(parse != Document::FullParse){ - QMap* tools = doc->getTools(); - VDataTool *tool = tools->value(id); - if(tool != 0){ - tool->VDataTool::setData(data); - data->IncrementReferens(id, Scene::Point, Draw::Modeling); - } + doc->UpdateToolData(id, data); } } data->AddLine(firstPointId, id); data->AddLine(id, secondPointId); - data->IncrementReferens(firstPointId, Scene::Point, Draw::Modeling); - data->IncrementReferens(secondPointId, Scene::Point, Draw::Modeling); if(parse == Document::FullParse){ point = new VModelingAlongLine(doc, data, id, formula, firstPointId, secondPointId, typeLine, typeCreation); - QMap* tools = doc->getTools(); - tools->insert(id,point); + doc->AddTool(id, point); + doc->IncrementReferens(firstPointId); + doc->IncrementReferens(secondPointId); } } return point; diff --git a/tools/modelingTools/vmodelingalongline.h b/tools/modelingTools/vmodelingalongline.h index 421594b60..c5d88407d 100644 --- a/tools/modelingTools/vmodelingalongline.h +++ b/tools/modelingTools/vmodelingalongline.h @@ -25,30 +25,30 @@ #include "vmodelinglinepoint.h" #include "dialogs/dialogalongline.h" -class VModelingAlongLine : public VModelingLinePoint -{ +class VModelingAlongLine : public VModelingLinePoint{ Q_OBJECT public: - VModelingAlongLine(VDomDocument *doc, VContainer *data, qint64 id, const QString &formula, - const qint64 &firstPointId, const qint64 &secondPointId, const QString &typeLine, - Tool::Sources typeCreation, QGraphicsItem * parent = 0); - virtual void setDialog(); - static VModelingAlongLine* Create(QSharedPointer &dialog, VDomDocument *doc, - VContainer *data); - static VModelingAlongLine* Create(const qint64 _id, const QString &pointName, const QString &typeLine, - const QString &formula, const qint64 &firstPointId, - const qint64 &secondPointId, const qreal &mx, const qreal &my, - VDomDocument *doc, VContainer *data, const Document::Documents &parse, - Tool::Sources typeCreation); + VModelingAlongLine(VDomDocument *doc, VContainer *data, qint64 id, + const QString &formula, const qint64 &firstPointId, + const qint64 &secondPointId, const QString &typeLine, + Tool::Sources typeCreation, QGraphicsItem * parent = 0); + virtual void setDialog(); + static VModelingAlongLine* Create(QSharedPointer &dialog, VDomDocument *doc, + VContainer *data); + static VModelingAlongLine* Create(const qint64 _id, const QString &pointName, const QString &typeLine, + const QString &formula, const qint64 &firstPointId, + const qint64 &secondPointId, const qreal &mx, const qreal &my, + VDomDocument *doc, VContainer *data, + const Document::Documents &parse, Tool::Sources typeCreation); public slots: - virtual void FullUpdateFromFile(); - virtual void FullUpdateFromGui(int result); + virtual void FullUpdateFromFile(); + virtual void FullUpdateFromGui(int result); protected: - virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); - virtual void AddToFile(); - + virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); + virtual void AddToFile(); + virtual void RemoveReferens(); private: - qint64 secondPointId; + qint64 secondPointId; QSharedPointer dialogAlongLine; }; diff --git a/tools/modelingTools/vmodelingarc.cpp b/tools/modelingTools/vmodelingarc.cpp index 8dba9111b..a04ed9310 100644 --- a/tools/modelingTools/vmodelingarc.cpp +++ b/tools/modelingTools/vmodelingarc.cpp @@ -91,20 +91,14 @@ VModelingArc* VModelingArc::Create(const qint64 _id, const qint64 ¢er, const } else { data->UpdateModelingArc(id, arc); if(parse != Document::FullParse){ - QMap* tools = doc->getTools(); - VDataTool *tool = tools->value(id); - if(tool != 0){ - tool->VDataTool::setData(data); - data->IncrementReferens(id, Scene::Arc, Draw::Modeling); - } + doc->UpdateToolData(id, data); } } data->AddLengthArc(data->GetNameArc(center,id, Draw::Modeling), arc.GetLength()); - data->IncrementReferens(center, Scene::Point, Draw::Modeling); if(parse == Document::FullParse){ toolArc = new VModelingArc(doc, data, id, typeCreation); - QMap* tools = doc->getTools(); - tools->insert(id,toolArc); + doc->AddTool(id, toolArc); + doc->IncrementReferens(center); } return toolArc; } @@ -162,6 +156,11 @@ void VModelingArc::hoverLeaveEvent(QGraphicsSceneHoverEvent *event){ this->setPen(QPen(currentColor, widthHairLine)); } +void VModelingArc::RemoveReferens(){ + VArc arc = VAbstractTool::data.GetModelingArc(id); + doc->DecrementReferens(arc.GetCenter()); +} + void VModelingArc::RefreshGeometry(){ VArc arc = VAbstractTool::data.GetModelingArc(id); QPainterPath path; diff --git a/tools/modelingTools/vmodelingarc.h b/tools/modelingTools/vmodelingarc.h index fc077b526..1ef1807e5 100644 --- a/tools/modelingTools/vmodelingarc.h +++ b/tools/modelingTools/vmodelingarc.h @@ -29,17 +29,16 @@ #include "widgets/vcontrolpointspline.h" #include "container/vcontainer.h" -class VModelingArc :public VModelingTool, public QGraphicsPathItem -{ +class VModelingArc :public VModelingTool, public QGraphicsPathItem{ Q_OBJECT public: - VModelingArc(VDomDocument *doc, VContainer *data, qint64 id, Tool::Sources typeCreation, - QGraphicsItem * parent = 0); - virtual void setDialog(); - static VModelingArc* Create(QSharedPointer &dialog, VDomDocument *doc, VContainer *data); - static VModelingArc* Create(const qint64 _id, const qint64 ¢er, const QString &radius, - const QString &f1, const QString &f2, VDomDocument *doc, VContainer *data, - const Document::Documents &parse, Tool::Sources typeCreation); + VModelingArc(VDomDocument *doc, VContainer *data, qint64 id, + Tool::Sources typeCreation, QGraphicsItem * parent = 0); + virtual void setDialog(); + static VModelingArc* Create(QSharedPointer &dialog, VDomDocument *doc, VContainer *data); + static VModelingArc* Create(const qint64 _id, const qint64 ¢er, const QString &radius, + const QString &f1, const QString &f2, VDomDocument *doc, VContainer *data, + const Document::Documents &parse, Tool::Sources typeCreation); public slots: virtual void FullUpdateFromFile(); virtual void FullUpdateFromGui(int result); @@ -49,6 +48,7 @@ protected: virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ); virtual void hoverMoveEvent ( QGraphicsSceneHoverEvent * event ); virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ); + virtual void RemoveReferens(); private: QSharedPointer dialogArc; void RefreshGeometry(); diff --git a/tools/modelingTools/vmodelingbisector.cpp b/tools/modelingTools/vmodelingbisector.cpp index 835b6ff7a..158b19ad0 100644 --- a/tools/modelingTools/vmodelingbisector.cpp +++ b/tools/modelingTools/vmodelingbisector.cpp @@ -97,23 +97,17 @@ VModelingBisector *VModelingBisector::Create(const qint64 _id, const QString &fo } else { data->UpdateModelingPoint(id, VPointF(fPoint.x(), fPoint.y(), pointName, mx, my)); if(parse != Document::FullParse){ - QMap* tools = doc->getTools(); - VDataTool *tool = tools->value(id); - if(tool != 0){ - tool->VDataTool::setData(data); - data->IncrementReferens(id, Scene::Point, Draw::Modeling); - } + doc->UpdateToolData(id, data); } } data->AddLine(firstPointId, id, Draw::Modeling); - data->IncrementReferens(firstPointId, Scene::Point, Draw::Modeling); - data->IncrementReferens(secondPointId, Scene::Point, Draw::Modeling); - data->IncrementReferens(thirdPointId, Scene::Point, Draw::Modeling); if(parse == Document::FullParse){ point = new VModelingBisector(doc, data, id, typeLine, formula, firstPointId, secondPointId, thirdPointId, typeCreation); - QMap* tools = doc->getTools(); - tools->insert(id,point); + doc->AddTool(id, point); + doc->IncrementReferens(firstPointId); + doc->IncrementReferens(secondPointId); + doc->IncrementReferens(thirdPointId); } } return point; @@ -169,3 +163,9 @@ void VModelingBisector::AddToFile(){ AddToModeling(domElement); } + +void VModelingBisector::RemoveReferens(){ + doc->DecrementReferens(firstPointId); + doc->DecrementReferens(thirdPointId); + VModelingLinePoint::RemoveReferens(); +} diff --git a/tools/modelingTools/vmodelingbisector.h b/tools/modelingTools/vmodelingbisector.h index 74901745c..dd8180b13 100644 --- a/tools/modelingTools/vmodelingbisector.h +++ b/tools/modelingTools/vmodelingbisector.h @@ -26,33 +26,34 @@ #include "vmodelinglinepoint.h" #include "dialogs/dialogbisector.h" -class VModelingBisector : public VModelingLinePoint -{ +class VModelingBisector : public VModelingLinePoint{ Q_OBJECT public: - VModelingBisector(VDomDocument *doc, VContainer *data, const qint64 &id, - const QString &typeLine, const QString &formula, const qint64 &firstPointId, - const qint64 &secondPointId, const qint64 &thirdPointId, Tool::Sources typeCreation, - QGraphicsItem * parent = 0); - static QPointF FindPoint(const QPointF &firstPoint, const QPointF &secondPoint, - const QPointF &thirdPoint, const qreal& length); - virtual void setDialog(); - static VModelingBisector* Create(QSharedPointer &dialog, VDomDocument *doc, - VContainer *data); - static VModelingBisector* Create(const qint64 _id, const QString &formula, const qint64 &firstPointId, - const qint64 &secondPointId, const qint64 &thirdPointId, - const QString &typeLine, const QString &pointName, const qreal &mx, - const qreal &my, VDomDocument *doc, VContainer *data, - const Document::Documents &parse, Tool::Sources typeCreation); + VModelingBisector(VDomDocument *doc, VContainer *data, const qint64 &id, + const QString &typeLine, const QString &formula, + const qint64 &firstPointId, const qint64 &secondPointId, + const qint64 &thirdPointId, Tool::Sources typeCreation, + QGraphicsItem * parent = 0); + static QPointF FindPoint(const QPointF &firstPoint, const QPointF &secondPoint, + const QPointF &thirdPoint, const qreal& length); + virtual void setDialog(); + static VModelingBisector* Create(QSharedPointer &dialog, VDomDocument *doc, + VContainer *data); + static VModelingBisector* Create(const qint64 _id, const QString &formula, const qint64 &firstPointId, + const qint64 &secondPointId, const qint64 &thirdPointId, + const QString &typeLine, const QString &pointName, const qreal &mx, + const qreal &my, VDomDocument *doc, VContainer *data, + const Document::Documents &parse, Tool::Sources typeCreation); public slots: - virtual void FullUpdateFromFile(); - virtual void FullUpdateFromGui(int result); + virtual void FullUpdateFromFile(); + virtual void FullUpdateFromGui(int result); protected: - virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); - virtual void AddToFile(); + virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); + virtual void AddToFile(); + virtual void RemoveReferens(); private: - qint64 firstPointId; - qint64 thirdPointId; + qint64 firstPointId; + qint64 thirdPointId; QSharedPointer dialogBisector; }; diff --git a/tools/modelingTools/vmodelingendline.cpp b/tools/modelingTools/vmodelingendline.cpp index 9ed074c6f..17021859d 100644 --- a/tools/modelingTools/vmodelingendline.cpp +++ b/tools/modelingTools/vmodelingendline.cpp @@ -78,20 +78,14 @@ VModelingEndLine *VModelingEndLine::Create(const qint64 _id, const QString &poin } else { data->UpdateModelingPoint(id, VPointF(line.p2().x(), line.p2().y(), pointName, mx, my)); if(parse != Document::FullParse){ - QMap* tools = doc->getTools(); - VDataTool *tool = tools->value(id); - if(tool != 0){ - tool->VDataTool::setData(data); - data->IncrementReferens(id, Scene::Point, Draw::Modeling); - } + doc->UpdateToolData(id, data); } } data->AddLine(basePointId, id, Draw::Modeling); - data->IncrementReferens(basePointId, Scene::Point, Draw::Modeling); if(parse == Document::FullParse){ point = new VModelingEndLine(doc, data, id, typeLine, formula, angle, basePointId, typeCreation); - QMap* tools = doc->getTools(); - tools->insert(id,point); + doc->AddTool(id, point); + doc->IncrementReferens(basePointId); } } return point; diff --git a/tools/modelingTools/vmodelingendline.h b/tools/modelingTools/vmodelingendline.h index 27ea0c8c5..0708e9a75 100644 --- a/tools/modelingTools/vmodelingendline.h +++ b/tools/modelingTools/vmodelingendline.h @@ -26,27 +26,27 @@ #include "vmodelinglinepoint.h" #include "dialogs/dialogendline.h" -class VModelingEndLine : public VModelingLinePoint -{ +class VModelingEndLine : public VModelingLinePoint{ Q_OBJECT public: - VModelingEndLine(VDomDocument *doc, VContainer *data, const qint64 &id, - const QString &typeLine, const QString &formula, const qreal &angle, - const qint64 &basePointId, Tool::Sources typeCreation, - QGraphicsItem * parent = 0); - virtual void setDialog(); - static VModelingEndLine* Create(QSharedPointer &dialog, VDomDocument *doc, - VContainer *data); - static VModelingEndLine* Create(const qint64 _id, const QString &pointName, const QString &typeLine, - const QString &formula, const qreal &angle, const qint64 &basePointId, - const qreal &mx, const qreal &my, VDomDocument *doc, VContainer *data, - const Document::Documents &parse, Tool::Sources typeCreation); + VModelingEndLine(VDomDocument *doc, VContainer *data, const qint64 &id, + const QString &typeLine, const QString &formula, + const qreal &angle, const qint64 &basePointId, + Tool::Sources typeCreation, + QGraphicsItem * parent = 0); + virtual void setDialog(); + static VModelingEndLine* Create(QSharedPointer &dialog, VDomDocument *doc, + VContainer *data); + static VModelingEndLine* Create(const qint64 _id, const QString &pointName, const QString &typeLine, + const QString &formula, const qreal &angle, const qint64 &basePointId, + const qreal &mx, const qreal &my, VDomDocument *doc, VContainer *data, + const Document::Documents &parse, Tool::Sources typeCreation); public slots: - virtual void FullUpdateFromFile(); - virtual void FullUpdateFromGui(int result); + virtual void FullUpdateFromFile(); + virtual void FullUpdateFromGui(int result); protected: - virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); - virtual void AddToFile(); + virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); + virtual void AddToFile(); private: QSharedPointer dialogEndLine; }; diff --git a/tools/modelingTools/vmodelingline.cpp b/tools/modelingTools/vmodelingline.cpp index 958048248..b434adfbb 100644 --- a/tools/modelingTools/vmodelingline.cpp +++ b/tools/modelingTools/vmodelingline.cpp @@ -59,20 +59,15 @@ VModelingLine *VModelingLine::Create(const qint64 &id, const qint64 &firstPoint, Q_CHECK_PTR(doc); Q_CHECK_PTR(data); data->AddLine(firstPoint, secondPoint, Draw::Modeling); - data->IncrementReferens(firstPoint, Scene::Point, Draw::Modeling); - data->IncrementReferens(secondPoint, Scene::Point, Draw::Modeling); if(parse != Document::FullParse){ - QMap* tools = doc->getTools(); - Q_CHECK_PTR(tools); - VDataTool *tool = tools->value(id); - Q_CHECK_PTR(tool); - tool->VDataTool::setData(data); + doc->UpdateToolData(id, data); } if(parse == Document::FullParse){ qint64 id = data->getNextId(); line = new VModelingLine(doc, data, id, firstPoint, secondPoint, typeCreation); - QMap* tools = doc->getTools(); - tools->insert(id,line); + doc->AddTool(id, line); + doc->IncrementReferens(firstPoint); + doc->IncrementReferens(secondPoint); } return line; } @@ -122,3 +117,8 @@ void VModelingLine::hoverLeaveEvent(QGraphicsSceneHoverEvent *event){ Q_UNUSED(event); this->setPen(QPen(currentColor, widthHairLine)); } + +void VModelingLine::RemoveReferens(){ + doc->DecrementReferens(firstPoint); + doc->DecrementReferens(secondPoint); +} diff --git a/tools/modelingTools/vmodelingline.h b/tools/modelingTools/vmodelingline.h index 30fdf0024..9ffe7e440 100644 --- a/tools/modelingTools/vmodelingline.h +++ b/tools/modelingTools/vmodelingline.h @@ -26,28 +26,29 @@ #include "QGraphicsLineItem" #include "dialogs/dialogline.h" -class VModelingLine: public VModelingTool, public QGraphicsLineItem -{ +class VModelingLine: public VModelingTool, public QGraphicsLineItem{ Q_OBJECT public: - VModelingLine(VDomDocument *doc, VContainer *data, qint64 id, qint64 firstPoint, - qint64 secondPoint, Tool::Sources typeCreation, QGraphicsItem * parent = 0); - virtual void setDialog(); - static VModelingLine* Create(QSharedPointer &dialog, VDomDocument *doc, VContainer *data); - static VModelingLine* Create(const qint64 &id, const qint64 &firstPoint, const qint64 &secondPoint, - VDomDocument *doc, VContainer *data, const Document::Documents &parse, - Tool::Sources typeCreation); + VModelingLine(VDomDocument *doc, VContainer *data, qint64 id, qint64 firstPoint, + qint64 secondPoint, Tool::Sources typeCreation, + QGraphicsItem * parent = 0); + virtual void setDialog(); + static VModelingLine* Create(QSharedPointer &dialog, VDomDocument *doc, VContainer *data); + static VModelingLine* Create(const qint64 &id, const qint64 &firstPoint, const qint64 &secondPoint, + VDomDocument *doc, VContainer *data, const Document::Documents &parse, + Tool::Sources typeCreation); public slots: - virtual void FullUpdateFromFile(); - virtual void FullUpdateFromGui(int result); + virtual void FullUpdateFromFile(); + virtual void FullUpdateFromGui(int result); protected: - virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); - virtual void AddToFile(); - virtual void hoverMoveEvent ( QGraphicsSceneHoverEvent * event ); - virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ); + virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); + virtual void AddToFile(); + virtual void hoverMoveEvent ( QGraphicsSceneHoverEvent * event ); + virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ); + virtual void RemoveReferens(); private: - qint64 firstPoint; - qint64 secondPoint; + qint64 firstPoint; + qint64 secondPoint; QSharedPointer dialogLine; }; diff --git a/tools/modelingTools/vmodelinglineintersect.cpp b/tools/modelingTools/vmodelinglineintersect.cpp index 971a0b205..d7d473194 100644 --- a/tools/modelingTools/vmodelinglineintersect.cpp +++ b/tools/modelingTools/vmodelinglineintersect.cpp @@ -78,12 +78,7 @@ VModelingLineIntersect *VModelingLineIntersect::Create(const qint64 _id, const q } else { data->UpdateModelingPoint(id, VPointF(fPoint.x(), fPoint.y(), pointName, mx, my)); if(parse != Document::FullParse){ - QMap* tools = doc->getTools(); - VDataTool *tool = tools->value(id); - if(tool != 0){ - tool->VDataTool::setData(data); - data->IncrementReferens(id, Scene::Point, Draw::Modeling); - } + doc->UpdateToolData(id, data); } } data->AddLine(p1Line1Id, id, Draw::Modeling); @@ -93,8 +88,11 @@ VModelingLineIntersect *VModelingLineIntersect::Create(const qint64 _id, const q if(parse == Document::FullParse){ point = new VModelingLineIntersect(doc, data, id, p1Line1Id, p2Line1Id, p1Line2Id, p2Line2Id, typeCreation); - QMap* tools = doc->getTools(); - tools->insert(id,point); + doc->AddTool(id, point); + doc->IncrementReferens(p1Line1Id); + doc->IncrementReferens(p2Line1Id); + doc->IncrementReferens(p1Line2Id); + doc->IncrementReferens(p2Line2Id); } } return point; @@ -147,3 +145,10 @@ void VModelingLineIntersect::AddToFile(){ AddToModeling(domElement); } + +void VModelingLineIntersect::RemoveReferens(){ + doc->DecrementReferens(p1Line1); + doc->DecrementReferens(p2Line1); + doc->DecrementReferens(p1Line2); + doc->DecrementReferens(p2Line2); +} diff --git a/tools/modelingTools/vmodelinglineintersect.h b/tools/modelingTools/vmodelinglineintersect.h index 599f0cdd7..e2af48470 100644 --- a/tools/modelingTools/vmodelinglineintersect.h +++ b/tools/modelingTools/vmodelinglineintersect.h @@ -25,30 +25,31 @@ #include "vmodelingpoint.h" #include "dialogs/dialoglineintersect.h" -class VModelingLineIntersect:public VModelingPoint -{ +class VModelingLineIntersect:public VModelingPoint{ Q_OBJECT public: - VModelingLineIntersect(VDomDocument *doc, VContainer *data, - const qint64 &id, - const qint64 &p1Line1, - const qint64 &p2Line1, const qint64 &p1Line2, - const qint64 &p2Line2, Tool::Sources typeCreation, - QGraphicsItem * parent = 0); - virtual void setDialog(); - static VModelingLineIntersect* Create(QSharedPointer &dialog, - VDomDocument *doc,VContainer *data); - static VModelingLineIntersect* Create(const qint64 _id, const qint64 &p1Line1Id, const qint64 &p2Line1Id, - const qint64 &p1Line2Id, const qint64 &p2Line2Id, - const QString &pointName, const qreal &mx, const qreal &my, - VDomDocument *doc, VContainer *data, const Document::Documents &parse, - Tool::Sources typeCreation); + VModelingLineIntersect(VDomDocument *doc, VContainer *data, + const qint64 &id, const qint64 &p1Line1, + const qint64 &p2Line1, const qint64 &p1Line2, + const qint64 &p2Line2, + Tool::Sources typeCreation, + QGraphicsItem * parent = 0); + virtual void setDialog(); + static VModelingLineIntersect* Create(QSharedPointer &dialog, + VDomDocument *doc,VContainer *data); + static VModelingLineIntersect* Create(const qint64 _id, const qint64 &p1Line1Id, + const qint64 &p2Line1Id, const qint64 &p1Line2Id, + const qint64 &p2Line2Id, const QString &pointName, + const qreal &mx, const qreal &my, VDomDocument *doc, + VContainer *data, const Document::Documents &parse, + Tool::Sources typeCreation); public slots: virtual void FullUpdateFromFile(); virtual void FullUpdateFromGui(int result); protected: virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); virtual void AddToFile(); + virtual void RemoveReferens(); private: qint64 p1Line1; qint64 p2Line1; diff --git a/tools/modelingTools/vmodelinglinepoint.cpp b/tools/modelingTools/vmodelinglinepoint.cpp index 36b3239a7..c326a4079 100644 --- a/tools/modelingTools/vmodelinglinepoint.cpp +++ b/tools/modelingTools/vmodelinglinepoint.cpp @@ -50,3 +50,7 @@ void VModelingLinePoint::RefreshGeometry(){ mainLine->setVisible(true); } } + +void VModelingLinePoint::RemoveReferens(){ + doc->DecrementReferens(basePointId); +} diff --git a/tools/modelingTools/vmodelinglinepoint.h b/tools/modelingTools/vmodelinglinepoint.h index d72920bf4..762ce1fc5 100644 --- a/tools/modelingTools/vmodelinglinepoint.h +++ b/tools/modelingTools/vmodelinglinepoint.h @@ -24,13 +24,13 @@ #include "vmodelingpoint.h" -class VModelingLinePoint : public VModelingPoint -{ +class VModelingLinePoint : public VModelingPoint{ Q_OBJECT public: - VModelingLinePoint(VDomDocument *doc, VContainer *data, const qint64 &id, - const QString &typeLine, const QString &formula, - const qint64 &basePointId, const qreal &angle, QGraphicsItem * parent = 0); + VModelingLinePoint(VDomDocument *doc, VContainer *data, const qint64 &id, + const QString &typeLine, const QString &formula, + const qint64 &basePointId, const qreal &angle, + QGraphicsItem * parent = 0); protected: QString typeLine; QString formula; @@ -38,9 +38,9 @@ protected: qint64 basePointId; QGraphicsLineItem *mainLine; virtual void RefreshGeometry(); + virtual void RemoveReferens(); private: - VModelingLinePoint(const VModelingLinePoint &tool); - const VModelingLinePoint &operator=(const VModelingLinePoint &tool); + Q_DISABLE_COPY(VModelingLinePoint) }; #endif // VMODELINGLINEPOINT_H diff --git a/tools/modelingTools/vmodelingnormal.cpp b/tools/modelingTools/vmodelingnormal.cpp index e2c1a9164..d7c7a3274 100644 --- a/tools/modelingTools/vmodelingnormal.cpp +++ b/tools/modelingTools/vmodelingnormal.cpp @@ -81,22 +81,16 @@ VModelingNormal *VModelingNormal::Create(const qint64 _id, const QString &formul } else { data->UpdateModelingPoint(id, VPointF(fPoint.x(), fPoint.y(), pointName, mx, my)); if(parse != Document::FullParse){ - QMap* tools = doc->getTools(); - VDataTool *tool = tools->value(id); - if(tool != 0){ - tool->VDataTool::setData(data); - data->IncrementReferens(id, Scene::Point, Draw::Modeling); - } + doc->UpdateToolData(id, data); } } data->AddLine(firstPointId, id, Draw::Modeling); - data->IncrementReferens(firstPointId, Scene::Point, Draw::Modeling); - data->IncrementReferens(secondPointId, Scene::Point, Draw::Modeling); if(parse == Document::FullParse){ point = new VModelingNormal(doc, data, id, typeLine, formula, angle, firstPointId, secondPointId, typeCreation); - QMap* tools = doc->getTools(); - tools->insert(id,point); + doc->AddTool(id, point); + doc->IncrementReferens(firstPointId); + doc->IncrementReferens(secondPointId); } } return point; @@ -161,3 +155,8 @@ void VModelingNormal::AddToFile(){ AddToModeling(domElement); } + +void VModelingNormal::RemoveReferens(){ + doc->DecrementReferens(secondPointId); + VModelingLinePoint::RemoveReferens(); +} diff --git a/tools/modelingTools/vmodelingnormal.h b/tools/modelingTools/vmodelingnormal.h index a16d0435e..97c2c71aa 100644 --- a/tools/modelingTools/vmodelingnormal.h +++ b/tools/modelingTools/vmodelingnormal.h @@ -26,22 +26,22 @@ #include "vmodelinglinepoint.h" #include "dialogs/dialognormal.h" -class VModelingNormal : public VModelingLinePoint -{ +class VModelingNormal : public VModelingLinePoint{ Q_OBJECT public: VModelingNormal(VDomDocument *doc, VContainer *data, const qint64 &id, - const QString &typeLine, const QString &formula, - const qreal &angle, const qint64 &firstPointId, - const qint64 &secondPointId, Tool::Sources typeCreation, - QGraphicsItem * parent = 0); - virtual void setDialog(); - static VModelingNormal* Create(QSharedPointer &dialog, VDomDocument *doc, VContainer *data); - static VModelingNormal* Create(const qint64 _id, const QString &formula, const qint64 &firstPointId, - const qint64 &secondPointId, const QString typeLine, - const QString pointName, const qreal angle, const qreal &mx, - const qreal &my, VDomDocument *doc, VContainer *data, const Document::Documents &parse, - Tool::Sources typeCreation); + const QString &typeLine, const QString &formula, + const qreal &angle, const qint64 &firstPointId, + const qint64 &secondPointId, Tool::Sources typeCreation, + QGraphicsItem * parent = 0); + virtual void setDialog(); + static VModelingNormal* Create(QSharedPointer &dialog, VDomDocument *doc, + VContainer *data); + static VModelingNormal* Create(const qint64 _id, const QString &formula, const qint64 &firstPointId, + const qint64 &secondPointId, const QString typeLine, + const QString pointName, const qreal angle, const qreal &mx, + const qreal &my, VDomDocument *doc, VContainer *data, + const Document::Documents &parse, Tool::Sources typeCreation); static QPointF FindPoint(const QPointF &firstPoint, const QPointF &secondPoint, const qreal &length, const qreal &angle = 0); public slots: @@ -50,6 +50,7 @@ public slots: protected: virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); virtual void AddToFile(); + virtual void RemoveReferens(); private: qint64 secondPointId; QSharedPointer dialogNormal; diff --git a/tools/modelingTools/vmodelingpoint.h b/tools/modelingTools/vmodelingpoint.h index df931a155..c851f3d6b 100644 --- a/tools/modelingTools/vmodelingpoint.h +++ b/tools/modelingTools/vmodelingpoint.h @@ -26,12 +26,12 @@ #include "widgets/vgraphicssimpletextitem.h" #include "options.h" -class VModelingPoint: public VModelingTool, public QGraphicsEllipseItem -{ +class VModelingPoint: public VModelingTool, public QGraphicsEllipseItem{ Q_OBJECT public: - VModelingPoint(VDomDocument *doc, VContainer *data, qint64 id, QGraphicsItem * parent = 0); - virtual ~VModelingPoint(); + VModelingPoint(VDomDocument *doc, VContainer *data, qint64 id, + QGraphicsItem * parent = 0); + virtual ~VModelingPoint(); public slots: void NameChangePosition(const QPointF pos); virtual void FullUpdateFromGui(int result) = 0; @@ -46,8 +46,7 @@ protected: virtual void RefreshPointGeometry(const VPointF &point); void RefreshLine(); private: - VModelingPoint(const VModelingPoint &tool); - const VModelingPoint &operator=(const VModelingPoint &tool); + Q_DISABLE_COPY(VModelingPoint) }; #endif // VMODELINGPOINT_H diff --git a/tools/modelingTools/vmodelingpointofcontact.cpp b/tools/modelingTools/vmodelingpointofcontact.cpp index 02aaacef1..35d6e9c2e 100644 --- a/tools/modelingTools/vmodelingpointofcontact.cpp +++ b/tools/modelingTools/vmodelingpointofcontact.cpp @@ -102,22 +102,16 @@ VModelingPointOfContact *VModelingPointOfContact::Create(const qint64 _id, const } else { data->UpdateModelingPoint(id, VPointF(fPoint.x(), fPoint.y(), pointName, mx, my)); if(parse != Document::FullParse){ - QMap* tools = doc->getTools(); - VDataTool *tool = tools->value(id); - if(tool != 0){ - tool->VDataTool::setData(data); - data->IncrementReferens(id, Scene::Point, Draw::Modeling); - } + doc->UpdateToolData(id, data); } } - data->IncrementReferens(center, Scene::Point, Draw::Modeling); - data->IncrementReferens(firstPointId, Scene::Point, Draw::Modeling); - data->IncrementReferens(secondPointId, Scene::Point, Draw::Modeling); if(parse == Document::FullParse){ point = new VModelingPointOfContact(doc, data, id, radius, center, firstPointId, secondPointId, typeCreation); - QMap* tools = doc->getTools(); - tools->insert(id,point); + doc->AddTool(id, point); + doc->IncrementReferens(center); + doc->IncrementReferens(firstPointId); + doc->IncrementReferens(secondPointId); } } return point; @@ -170,3 +164,9 @@ void VModelingPointOfContact::AddToFile(){ AddToModeling(domElement); } + +void VModelingPointOfContact::RemoveReferens(){ + doc->DecrementReferens(center); + doc->DecrementReferens(firstPointId); + doc->DecrementReferens(secondPointId); +} diff --git a/tools/modelingTools/vmodelingpointofcontact.h b/tools/modelingTools/vmodelingpointofcontact.h index 63fcb02ef..02302bc45 100644 --- a/tools/modelingTools/vmodelingpointofcontact.h +++ b/tools/modelingTools/vmodelingpointofcontact.h @@ -25,34 +25,38 @@ #include "vmodelingpoint.h" #include "dialogs/dialogpointofcontact.h" -class VModelingPointOfContact : public VModelingPoint -{ +class VModelingPointOfContact : public VModelingPoint{ Q_OBJECT public: - VModelingPointOfContact(VDomDocument *doc, VContainer *data, const qint64 &id, - const QString &radius, const qint64 ¢er, const qint64 &firstPointId, - const qint64 &secondPointId, Tool::Sources typeCreation, QGraphicsItem * parent = 0); - virtual void setDialog(); - static QPointF FindPoint(const qreal &radius, const QPointF ¢er, const QPointF &firstPoint, - const QPointF &secondPoint); - static VModelingPointOfContact* Create(QSharedPointer &dialog, - VDomDocument *doc, VContainer *data); - static VModelingPointOfContact* Create(const qint64 _id, const QString &radius, const qint64 ¢er, - const qint64 &firstPointId, const qint64 &secondPointId, - const QString &pointName, const qreal &mx, const qreal &my, - VDomDocument *doc, VContainer *data, const Document::Documents &parse, - Tool::Sources typeCreation); + VModelingPointOfContact(VDomDocument *doc, VContainer *data, + const qint64 &id, const QString &radius, + const qint64 ¢er, + const qint64 &firstPointId, + const qint64 &secondPointId, + Tool::Sources typeCreation, + QGraphicsItem * parent = 0); + virtual void setDialog(); + static QPointF FindPoint(const qreal &radius, const QPointF ¢er, + const QPointF &firstPoint, const QPointF &secondPoint); + static VModelingPointOfContact* Create(QSharedPointer &dialog, + VDomDocument *doc, VContainer *data); + static VModelingPointOfContact* Create(const qint64 _id, const QString &radius, const qint64 ¢er, + const qint64 &firstPointId, const qint64 &secondPointId, + const QString &pointName, const qreal &mx, const qreal &my, + VDomDocument *doc, VContainer *data, + const Document::Documents &parse, Tool::Sources typeCreation); public slots: - virtual void FullUpdateFromFile(); - virtual void FullUpdateFromGui(int result); + virtual void FullUpdateFromFile(); + virtual void FullUpdateFromGui(int result); protected: - virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); - virtual void AddToFile(); + virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); + virtual void AddToFile(); + virtual void RemoveReferens(); private: - QString radius; - qint64 center; - qint64 firstPointId; - qint64 secondPointId; + QString radius; + qint64 center; + qint64 firstPointId; + qint64 secondPointId; QSharedPointer dialogPointOfContact; }; diff --git a/tools/modelingTools/vmodelingshoulderpoint.cpp b/tools/modelingTools/vmodelingshoulderpoint.cpp index 01e9d3cd8..c67f92427 100644 --- a/tools/modelingTools/vmodelingshoulderpoint.cpp +++ b/tools/modelingTools/vmodelingshoulderpoint.cpp @@ -83,11 +83,12 @@ VModelingShoulderPoint *VModelingShoulderPoint::Create(QSharedPointerGetModelingPoint(p1Line); VPointF secondPoint = data->GetModelingPoint(p2Line); @@ -105,24 +106,18 @@ VModelingShoulderPoint *VModelingShoulderPoint::Create(const qint64 _id, const Q } else { data->UpdateModelingPoint(id,VPointF(fPoint.x(), fPoint.y(), pointName, mx, my)); if(parse != Document::FullParse){ - QMap* tools = doc->getTools(); - VDataTool *tool = tools->value(id); - if(tool != 0){ - tool->VDataTool::setData(data); - data->IncrementReferens(id, Scene::Point, Draw::Modeling); - } + doc->UpdateToolData(id, data); } } data->AddLine(p1Line, id, Draw::Modeling); data->AddLine(p2Line, id, Draw::Modeling); - data->IncrementReferens(p1Line, Scene::Point, Draw::Modeling); - data->IncrementReferens(p2Line, Scene::Point, Draw::Modeling); - data->IncrementReferens(pShoulder, Scene::Point, Draw::Modeling); if(parse == Document::FullParse){ point = new VModelingShoulderPoint(doc, data, id, typeLine, formula, p1Line, p2Line, pShoulder, typeCreation); - QMap* tools = doc->getTools(); - tools->insert(id,point); + doc->AddTool(id, point); + doc->IncrementReferens(p1Line); + doc->IncrementReferens(p2Line); + doc->IncrementReferens(pShoulder); } } return point; @@ -178,3 +173,9 @@ void VModelingShoulderPoint::AddToFile(){ AddToModeling(domElement); } + +void VModelingShoulderPoint::RemoveReferens(){ + doc->DecrementReferens(p2Line); + doc->DecrementReferens(pShoulder); + VModelingLinePoint::RemoveReferens(); +} diff --git a/tools/modelingTools/vmodelingshoulderpoint.h b/tools/modelingTools/vmodelingshoulderpoint.h index 165146775..399c95868 100644 --- a/tools/modelingTools/vmodelingshoulderpoint.h +++ b/tools/modelingTools/vmodelingshoulderpoint.h @@ -25,33 +25,36 @@ #include "vmodelinglinepoint.h" #include "dialogs/dialogshoulderpoint.h" -class VModelingShoulderPoint : public VModelingLinePoint -{ +class VModelingShoulderPoint : public VModelingLinePoint{ Q_OBJECT public: - VModelingShoulderPoint(VDomDocument *doc, VContainer *data, const qint64 &id, - const QString &typeLine, const QString &formula, const qint64 &p1Line, - const qint64 &p2Line, const qint64 &pShoulder, Tool::Sources typeCreation, - QGraphicsItem * parent = 0); - virtual void setDialog(); - static QPointF FindPoint(const QPointF &p1Line, const QPointF &p2Line, const QPointF &pShoulder, - const qreal &length); - static VModelingShoulderPoint* Create(QSharedPointer &dialog, - VDomDocument *doc, VContainer *data); - static VModelingShoulderPoint* Create(const qint64 _id, const QString &formula, const qint64 &p1Line, - const qint64 &p2Line, const qint64 &pShoulder, - const QString &typeLine, const QString &pointName, - const qreal &mx, const qreal &my, VDomDocument *doc, - VContainer *data, const Document::Documents &parse, Tool::Sources typeCreation); + VModelingShoulderPoint(VDomDocument *doc, VContainer *data, + const qint64 &id, const QString &typeLine, + const QString &formula, const qint64 &p1Line, + const qint64 &p2Line, const qint64 &pShoulder, + Tool::Sources typeCreation, + QGraphicsItem * parent = 0); + virtual void setDialog(); + static QPointF FindPoint(const QPointF &p1Line, const QPointF &p2Line, + const QPointF &pShoulder, const qreal &length); + static VModelingShoulderPoint* Create(QSharedPointer &dialog, + VDomDocument *doc, VContainer *data); + static VModelingShoulderPoint* Create(const qint64 _id, const QString &formula, const qint64 &p1Line, + const qint64 &p2Line, const qint64 &pShoulder, + const QString &typeLine, const QString &pointName, + const qreal &mx, const qreal &my, VDomDocument *doc, + VContainer *data, const Document::Documents &parse, + const Tool::Sources &typeCreation); public slots: - virtual void FullUpdateFromFile(); - virtual void FullUpdateFromGui(int result); + virtual void FullUpdateFromFile(); + virtual void FullUpdateFromGui(int result); protected: - virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); - virtual void AddToFile(); + virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); + virtual void AddToFile(); + virtual void RemoveReferens(); private: - qint64 p2Line; - qint64 pShoulder; + qint64 p2Line; + qint64 pShoulder; QSharedPointer dialogShoulderPoint; }; diff --git a/tools/modelingTools/vmodelingspline.cpp b/tools/modelingTools/vmodelingspline.cpp index 27c3f043b..ddefbc81d 100644 --- a/tools/modelingTools/vmodelingspline.cpp +++ b/tools/modelingTools/vmodelingspline.cpp @@ -100,16 +100,14 @@ VModelingSpline *VModelingSpline::Create(const qint64 _id, const qint64 &p1, con data->UpdateModelingSpline(id, spline); if(parse != Document::FullParse){ doc->UpdateToolData(id, data); - data->IncrementReferens(id, Scene::Spline, Draw::Modeling); } } data->AddLengthSpline(data->GetNameSpline(p1, p4, Draw::Modeling), spline.GetLength()); - data->IncrementReferens(p1, Scene::Point, Draw::Modeling); - data->IncrementReferens(p4, Scene::Point, Draw::Modeling); if(parse == Document::FullParse){ spl = new VModelingSpline(doc, data, id, typeCreation); - QMap* tools = doc->getTools(); - tools->insert(id,spl); + doc->AddTool(id, spl); + doc->IncrementReferens(p1); + doc->IncrementReferens(p4); } return spl; } @@ -211,6 +209,12 @@ void VModelingSpline::hoverLeaveEvent(QGraphicsSceneHoverEvent *event){ this->setPen(QPen(currentColor, widthHairLine)); } +void VModelingSpline::RemoveReferens(){ + VSpline spl = VAbstractTool::data.GetModelingSpline(id); + doc->DecrementReferens(spl.GetP1()); + doc->DecrementReferens(spl.GetP4()); +} + void VModelingSpline::RefreshGeometry(){ VSpline spl = VAbstractTool::data.GetModelingSpline(id); QPainterPath path; diff --git a/tools/modelingTools/vmodelingspline.h b/tools/modelingTools/vmodelingspline.h index cb0ab88b6..09a7251d1 100644 --- a/tools/modelingTools/vmodelingspline.h +++ b/tools/modelingTools/vmodelingspline.h @@ -30,19 +30,19 @@ #include "container/vcontainer.h" #include "geometry/vsplinepath.h" -class VModelingSpline:public VModelingTool, public QGraphicsPathItem -{ +class VModelingSpline:public VModelingTool, public QGraphicsPathItem{ Q_OBJECT public: VModelingSpline (VDomDocument *doc, VContainer *data, qint64 id, Tool::Sources typeCreation, QGraphicsItem * parent = 0 ); - virtual void setDialog(); - static VModelingSpline* Create(QSharedPointer &dialog, VDomDocument *doc, - VContainer *data); - static VModelingSpline* Create(const qint64 _id, const qint64 &p1, const qint64 &p4, const qreal &kAsm1, - const qreal kAsm2, const qreal &angle1, const qreal &angle2, - const qreal &kCurve, VDomDocument *doc, VContainer *data, - const Document::Documents &parse, Tool::Sources typeCreation); + virtual void setDialog(); + static VModelingSpline* Create(QSharedPointer &dialog, VDomDocument *doc, + VContainer *data); + static VModelingSpline* Create(const qint64 _id, const qint64 &p1, const qint64 &p4, + const qreal &kAsm1, const qreal kAsm2, const qreal &angle1, + const qreal &angle2, const qreal &kCurve, VDomDocument *doc, + VContainer *data, const Document::Documents &parse, + Tool::Sources typeCreation); signals: void RefreshLine ( const qint32 &indexSpline, SplinePoint::Position position, const QPointF &controlPoint, const QPointF &splinePoint ); @@ -59,6 +59,7 @@ protected: virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ); virtual void hoverMoveEvent ( QGraphicsSceneHoverEvent * event ); virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ); + virtual void RemoveReferens(); private: QSharedPointer dialogSpline; QVector controlPoints; diff --git a/tools/modelingTools/vmodelingsplinepath.cpp b/tools/modelingTools/vmodelingsplinepath.cpp index 765e57010..2b024389a 100644 --- a/tools/modelingTools/vmodelingsplinepath.cpp +++ b/tools/modelingTools/vmodelingsplinepath.cpp @@ -70,6 +70,9 @@ void VModelingSplinePath::setDialog(){ VModelingSplinePath *VModelingSplinePath::Create(QSharedPointer &dialog, VDomDocument *doc, VContainer *data){ VSplinePath path = dialog->GetPath(); + for(qint32 i = 0; i < path.CountPoint(); ++i){ + doc->IncrementReferens(path[i].P()); + } return Create(0, path, doc, data, Document::FullParse, Tool::FromGui); } @@ -83,22 +86,13 @@ VModelingSplinePath * VModelingSplinePath::Create(const qint64 _id, const VSplin } else { data->UpdateModelingSplinePath(id, path); if(parse != Document::FullParse){ - QMap* tools = doc->getTools(); - VDataTool *tool = tools->value(id); - if(tool != 0){ - tool->VDataTool::setData(data); - data->IncrementReferens(id, Scene::SplinePath, Draw::Modeling); - } + doc->UpdateToolData(id, data); } } - for(qint32 i = 0; i < path.CountPoint(); ++i){ - data->IncrementReferens(path.getIdObject(), Scene::Point, Draw::Modeling); - } data->AddLengthSpline(data->GetNameSplinePath(path), path.GetLength()); if(parse == Document::FullParse){ spl = new VModelingSplinePath(doc, data, id, typeCreation); - QMap* tools = doc->getTools(); - tools->insert(id,spl); + doc->AddTool(id, spl); } return spl; } @@ -235,6 +229,13 @@ void VModelingSplinePath::hoverLeaveEvent(QGraphicsSceneHoverEvent *event){ this->setPen(QPen(currentColor, widthHairLine)); } +void VModelingSplinePath::RemoveReferens(){ + VSplinePath splPath = VAbstractTool::data.GetModelingSplinePath(id); + for(qint32 i = 0; i < splPath.Count(); ++i){ + doc->DecrementReferens(splPath[i].P()); + } +} + void VModelingSplinePath::RefreshGeometry(){ VSplinePath splPath = VAbstractTool::data.GetModelingSplinePath(id); QPainterPath path; diff --git a/tools/modelingTools/vmodelingsplinepath.h b/tools/modelingTools/vmodelingsplinepath.h index ba6e0961a..75494a2ea 100644 --- a/tools/modelingTools/vmodelingsplinepath.h +++ b/tools/modelingTools/vmodelingsplinepath.h @@ -29,18 +29,18 @@ #include "widgets/vcontrolpointspline.h" #include "container/vcontainer.h" -class VModelingSplinePath:public VModelingTool, public QGraphicsPathItem -{ +class VModelingSplinePath:public VModelingTool, public QGraphicsPathItem{ Q_OBJECT public: VModelingSplinePath(VDomDocument *doc, VContainer *data, qint64 id, Tool::Sources typeCreation, QGraphicsItem * parent = 0); - virtual void setDialog(); - static VModelingSplinePath* Create(QSharedPointer &dialog, - VDomDocument *doc, VContainer *data); - static VModelingSplinePath* Create(const qint64 _id, const VSplinePath &path, VDomDocument *doc, - VContainer *data, const Document::Documents &parse, Tool::Sources typeCreation); + virtual void setDialog(); + static VModelingSplinePath* Create(QSharedPointer &dialog, + VDomDocument *doc, VContainer *data); + static VModelingSplinePath* Create(const qint64 _id, const VSplinePath &path, VDomDocument *doc, + VContainer *data, const Document::Documents &parse, + Tool::Sources typeCreation); signals: void RefreshLine(const qint32 &indexSpline, SplinePoint::Position pos, const QPointF &controlPoint, const QPointF &splinePoint); @@ -57,6 +57,7 @@ protected: virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ); virtual void hoverMoveEvent ( QGraphicsSceneHoverEvent * event ); virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ); + virtual void RemoveReferens(); private: QSharedPointer dialogSplinePath; QVector controlPoints; diff --git a/tools/modelingTools/vmodelingtool.cpp b/tools/modelingTools/vmodelingtool.cpp index 0b2d84194..c651880dd 100644 --- a/tools/modelingTools/vmodelingtool.cpp +++ b/tools/modelingTools/vmodelingtool.cpp @@ -24,6 +24,7 @@ VModelingTool::VModelingTool(VDomDocument *doc, VContainer *data, qint64 id, QObject *parent): VAbstractTool(doc, data, id, parent), ignoreContextMenuEvent(false){ + _referens = 0; } VModelingTool::~VModelingTool(){ @@ -46,3 +47,19 @@ void VModelingTool::AddToModeling(const QDomElement &domElement){ } emit toolhaveChange(); } + +void VModelingTool::decrementReferens(){ + if(_referens > 0){ + --_referens; + } + if(_referens <= 0){ + RemoveReferens(); + QDomElement domElement = doc->elementById(QString().setNum(id)); + if(domElement.isElement()){ + QDomNode element = domElement.parentNode(); + if(!element.isNull()){ + element.removeChild(domElement); + } + } + } +} diff --git a/tools/modelingTools/vmodelingtool.h b/tools/modelingTools/vmodelingtool.h index a7d85d984..f5bb4bbc7 100644 --- a/tools/modelingTools/vmodelingtool.h +++ b/tools/modelingTools/vmodelingtool.h @@ -35,9 +35,12 @@ public: void ignoreContextMenu(bool enable); public slots: virtual void FullUpdateFromGui(int result)=0; +signals: + void RemoveTool(QGraphicsItem *tool); protected: bool ignoreContextMenuEvent; void AddToModeling(const QDomElement &domElement); + virtual void decrementReferens(); template void ContextMenu(QSharedPointer &dialog, Tool *tool, QGraphicsSceneContextMenuEvent *event, bool showRemove = true){ @@ -73,7 +76,7 @@ protected: //update xml file emit FullUpdateTree(); //remove form scene - //emit RemoveTool(tool); + emit RemoveTool(tool); } } } diff --git a/tools/nodeDetails/vabstractnode.cpp b/tools/nodeDetails/vabstractnode.cpp index b1df22222..ddd667825 100644 --- a/tools/nodeDetails/vabstractnode.cpp +++ b/tools/nodeDetails/vabstractnode.cpp @@ -25,9 +25,7 @@ VAbstractNode::VAbstractNode(VDomDocument *doc, VContainer *data, qint64 id, qint64 idNode, Draw::Draws typeobject, QObject *parent) : VAbstractTool(doc, data, id, parent), idNode(idNode), typeobject(typeobject){ -} - -VAbstractNode::~VAbstractNode(){ + _referens = 0; } void VAbstractNode::AddToModeling(const QDomElement &domElement){ @@ -40,3 +38,19 @@ void VAbstractNode::AddToModeling(const QDomElement &domElement){ } emit toolhaveChange(); } + +void VAbstractNode::decrementReferens(){ + if(_referens > 0){ + --_referens; + } + if(_referens <= 0){ + doc->DecrementReferens(idNode); + QDomElement domElement = doc->elementById(QString().setNum(id)); + if(domElement.isElement()){ + QDomNode element = domElement.parentNode(); + if(!element.isNull()){ + element.removeChild(domElement); + } + } + } +} diff --git a/tools/nodeDetails/vabstractnode.h b/tools/nodeDetails/vabstractnode.h index 6b25f52bb..3cd1a63cc 100644 --- a/tools/nodeDetails/vabstractnode.h +++ b/tools/nodeDetails/vabstractnode.h @@ -30,11 +30,12 @@ class VAbstractNode : public VAbstractTool public: VAbstractNode(VDomDocument *doc, VContainer *data, qint64 id, qint64 idNode, Draw::Draws typeobject, QObject *parent = 0 ); - virtual ~VAbstractNode(); + virtual ~VAbstractNode() {} protected: qint64 idNode; - Draw::Draws typeobject; + Draw::Draws typeobject; void AddToModeling(const QDomElement &domElement); + virtual void decrementReferens(); }; #endif // VABSTRACTNODE_H diff --git a/tools/nodeDetails/vnodearc.cpp b/tools/nodeDetails/vnodearc.cpp index e35e9f910..ea755e7f5 100644 --- a/tools/nodeDetails/vnodearc.cpp +++ b/tools/nodeDetails/vnodearc.cpp @@ -34,16 +34,16 @@ VNodeArc::VNodeArc(VDomDocument *doc, VContainer *data, qint64 id, qint64 idArc, } } -VNodeArc *VNodeArc::Create(VDomDocument *doc, VContainer *data, qint64 id, qint64 idArc, - Draw::Draws typeobject, const Document::Documents &parse, Tool::Sources typeCreation){ - VNodeArc *arc = 0; +void VNodeArc::Create(VDomDocument *doc, VContainer *data, qint64 id, qint64 idArc, + Draw::Draws typeobject, const Document::Documents &parse, Tool::Sources typeCreation){ if(parse == Document::FullParse){ - arc = new VNodeArc(doc, data, id, idArc, typeobject, typeCreation); + VNodeArc *arc = new VNodeArc(doc, data, id, idArc, typeobject, typeCreation); + Q_CHECK_PTR(arc); doc->AddTool(id, arc); + doc->IncrementReferens(idArc); } else { doc->UpdateToolData(id, data); } - return arc; } void VNodeArc::FullUpdateFromFile(){ diff --git a/tools/nodeDetails/vnodearc.h b/tools/nodeDetails/vnodearc.h index f82c3d776..6776776ad 100644 --- a/tools/nodeDetails/vnodearc.h +++ b/tools/nodeDetails/vnodearc.h @@ -29,19 +29,19 @@ class VNodeArc :public VAbstractNode, public QGraphicsPathItem { Q_OBJECT public: - VNodeArc(VDomDocument *doc, VContainer *data, qint64 id, qint64 idArc, Draw::Draws typeobject, - Tool::Sources typeCreation, QGraphicsItem * parent = 0); - static VNodeArc *Create(VDomDocument *doc, VContainer *data, qint64 id, qint64 idArc, - Draw::Draws typeobject, const Document::Documents &parse, Tool::Sources typeCreation); + VNodeArc(VDomDocument *doc, VContainer *data, qint64 id, qint64 idArc, Draw::Draws typeobject, + Tool::Sources typeCreation, QGraphicsItem * parent = 0); + static void Create(VDomDocument *doc, VContainer *data, qint64 id, qint64 idArc, + Draw::Draws typeobject, const Document::Documents &parse, Tool::Sources typeCreation); public slots: - virtual void FullUpdateFromFile(); + virtual void FullUpdateFromFile(); protected: - virtual void AddToFile(); - virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ); + virtual void AddToFile(); + virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ); virtual void hoverMoveEvent ( QGraphicsSceneHoverEvent * event ); virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ); private: - void RefreshGeometry(); + void RefreshGeometry(); }; -#endif // VNODEARC_H +#endif // VNODEARC_H4 diff --git a/tools/nodeDetails/vnodepoint.cpp b/tools/nodeDetails/vnodepoint.cpp index b43431789..21426313f 100644 --- a/tools/nodeDetails/vnodepoint.cpp +++ b/tools/nodeDetails/vnodepoint.cpp @@ -39,16 +39,16 @@ VNodePoint::VNodePoint(VDomDocument *doc, VContainer *data, qint64 id, qint64 id } } -VNodePoint *VNodePoint::Create(VDomDocument *doc, VContainer *data, qint64 id, qint64 idPoint, - Draw::Draws typeobject, const Document::Documents &parse, Tool::Sources typeCreation){ - VNodePoint *point = 0; +void VNodePoint::Create(VDomDocument *doc, VContainer *data, qint64 id, qint64 idPoint, + Draw::Draws typeobject, const Document::Documents &parse, Tool::Sources typeCreation){ if(parse == Document::FullParse){ - point = new VNodePoint(doc, data, id, idPoint, typeobject, typeCreation); + VNodePoint *point = new VNodePoint(doc, data, id, idPoint, typeobject, typeCreation); + Q_CHECK_PTR(point); doc->AddTool(id, point); + doc->IncrementReferens(idPoint); } else { doc->UpdateToolData(id, data); } - return point; } void VNodePoint::FullUpdateFromFile(){ diff --git a/tools/nodeDetails/vnodepoint.h b/tools/nodeDetails/vnodepoint.h index 336333053..f7e963a97 100644 --- a/tools/nodeDetails/vnodepoint.h +++ b/tools/nodeDetails/vnodepoint.h @@ -29,10 +29,12 @@ class VNodePoint: public VAbstractNode, public QGraphicsEllipseItem { Q_OBJECT public: - VNodePoint(VDomDocument *doc, VContainer *data, qint64 id, qint64 idPoint, Draw::Draws typeobject, - Tool::Sources typeCreation, QGraphicsItem * parent = 0 ); - static VNodePoint *Create(VDomDocument *doc, VContainer *data, qint64 id, qint64 idPoint, - Draw::Draws typeobject, const Document::Documents &parse, Tool::Sources typeCreation); + VNodePoint(VDomDocument *doc, VContainer *data, qint64 id, qint64 idPoint, + Draw::Draws typeobject, Tool::Sources typeCreation, + QGraphicsItem * parent = 0 ); + static void Create(VDomDocument *doc, VContainer *data, qint64 id, qint64 idPoint, + Draw::Draws typeobject, const Document::Documents &parse, + Tool::Sources typeCreation); public slots: virtual void FullUpdateFromFile(); void NameChangePosition(const QPointF pos); @@ -48,8 +50,7 @@ protected: virtual void RefreshPointGeometry(const VPointF &point); void RefreshLine(); private: - VNodePoint(const VNodePoint &point); - const VNodePoint &operator=(const VNodePoint &point); + Q_DISABLE_COPY(VNodePoint) }; #endif // VNODEPOINT_H diff --git a/tools/nodeDetails/vnodespline.cpp b/tools/nodeDetails/vnodespline.cpp index 00a7ffe91..cf4960b6f 100644 --- a/tools/nodeDetails/vnodespline.cpp +++ b/tools/nodeDetails/vnodespline.cpp @@ -40,6 +40,7 @@ VNodeSpline *VNodeSpline::Create(VDomDocument *doc, VContainer *data, qint64 id, if(parse == Document::FullParse){ spl = new VNodeSpline(doc, data, id, idSpline, typeobject, typeCreation); doc->AddTool(id, spl); + doc->IncrementReferens(idSpline); } else { doc->UpdateToolData(id, data); } diff --git a/tools/nodeDetails/vnodesplinepath.cpp b/tools/nodeDetails/vnodesplinepath.cpp index aa0d4b87c..493f5a397 100644 --- a/tools/nodeDetails/vnodesplinepath.cpp +++ b/tools/nodeDetails/vnodesplinepath.cpp @@ -35,17 +35,21 @@ VNodeSplinePath::VNodeSplinePath(VDomDocument *doc, VContainer *data, qint64 id, } } -VNodeSplinePath *VNodeSplinePath::Create(VDomDocument *doc, VContainer *data, qint64 id, - qint64 idSpline, Draw::Draws typeobject, const Document::Documents &parse, - Tool::Sources typeCreation){ - VNodeSplinePath *splPath = 0; +void VNodeSplinePath::Create(VDomDocument *doc, VContainer *data, qint64 id, qint64 idSpline, + Draw::Draws typeobject, const Document::Documents &parse, + Tool::Sources typeCreation){ if(parse == Document::FullParse){ - splPath = new VNodeSplinePath(doc, data, id, idSpline, typeobject, typeCreation); + VNodeSplinePath *splPath = new VNodeSplinePath(doc, data, id, idSpline, typeobject, typeCreation); + Q_CHECK_PTR(splPath); doc->AddTool(id, splPath); + VSplinePath path = data->GetModelingSplinePath(id); + const QVector *points = path.GetPoint(); + for(qint32 i = 0; isize(); ++i){ + doc->IncrementReferens(points->at(i).P()); + } } else { doc->UpdateToolData(id, data); } - return splPath; } void VNodeSplinePath::FullUpdateFromFile(){ diff --git a/tools/nodeDetails/vnodesplinepath.h b/tools/nodeDetails/vnodesplinepath.h index 542eae3d9..21b09dd36 100644 --- a/tools/nodeDetails/vnodesplinepath.h +++ b/tools/nodeDetails/vnodesplinepath.h @@ -29,10 +29,11 @@ class VNodeSplinePath : public VAbstractNode, public QGraphicsPathItem { Q_OBJECT public: - VNodeSplinePath(VDomDocument *doc, VContainer *data, qint64 id, qint64 idSpline, - Draw::Draws typeobject, Tool::Sources typeCreation, QGraphicsItem * parent = 0); - static VNodeSplinePath *Create(VDomDocument *doc, VContainer *data, qint64 id, qint64 idSpline, - Draw::Draws typeobject, const Document::Documents &parse, Tool::Sources typeCreation); + VNodeSplinePath(VDomDocument *doc, VContainer *data, qint64 id, qint64 idSpline, + Draw::Draws typeobject, Tool::Sources typeCreation, + QGraphicsItem * parent = 0); + static void Create(VDomDocument *doc, VContainer *data, qint64 id, qint64 idSpline, + Draw::Draws typeobject, const Document::Documents &parse, Tool::Sources typeCreation); public slots: virtual void FullUpdateFromFile(); protected: diff --git a/tools/vabstracttool.cpp b/tools/vabstracttool.cpp index 5bcc0ab8c..50838f4d7 100644 --- a/tools/vabstracttool.cpp +++ b/tools/vabstracttool.cpp @@ -24,8 +24,6 @@ VAbstractTool::VAbstractTool(VDomDocument *doc, VContainer *data, qint64 id, QObject *parent): VDataTool(data, parent), doc(doc), id(id), baseColor(Qt::black), currentColor(Qt::black){ - this->doc = doc; - this->id = id; connect(this, &VAbstractTool::toolhaveChange, this->doc, &VDomDocument::haveLiteChange); connect(this->doc, &VDomDocument::FullUpdateFromFile, this, &VAbstractTool::FullUpdateFromFile); diff --git a/tools/vabstracttool.h b/tools/vabstracttool.h index 49b9a9377..22fe67dfe 100644 --- a/tools/vabstracttool.h +++ b/tools/vabstracttool.h @@ -46,7 +46,7 @@ signals: void FullUpdateTree(); protected: VDomDocument *doc; - qint64 id; + const qint64 id; const Qt::GlobalColor baseColor; Qt::GlobalColor currentColor; virtual void AddToFile()=0; @@ -55,6 +55,7 @@ protected: void AddAttribute(QDomElement &domElement, const QString &name, const qreal &value); void AddAttribute(QDomElement &domElement, const QString &name, const QString &value); const VContainer *getData() const; + virtual void RemoveReferens(){} private: Q_DISABLE_COPY(VAbstractTool) }; diff --git a/tools/vdatatool.cpp b/tools/vdatatool.cpp index 987c237d8..eb5d6cf20 100644 --- a/tools/vdatatool.cpp +++ b/tools/vdatatool.cpp @@ -30,3 +30,9 @@ VDataTool &VDataTool::operator =(const VDataTool &tool){ void VDataTool::setData(const VContainer *value){ data = *value; } + +void VDataTool::decrementReferens(){ + if(_referens > 0){ + --_referens; + } +} diff --git a/tools/vdatatool.h b/tools/vdatatool.h index f6c114121..eed3f4e60 100644 --- a/tools/vdatatool.h +++ b/tools/vdatatool.h @@ -28,17 +28,18 @@ class VDataTool : public QObject{ Q_OBJECT public: - explicit VDataTool(VContainer *data, QObject *parent = 0): QObject(parent), data(*data), _referens(0){} - virtual ~VDataTool(){} - VDataTool& operator= (const VDataTool &tool); - VContainer getData() const { return data; } - void setData(const VContainer *value); - qint64 referens() const {return _referens;} - void incrementReferens(){++_referens;} - void decrementReferens(){--_referens;} + explicit VDataTool(VContainer *data, QObject *parent = 0) + : QObject(parent), data(*data), _referens(1){} + virtual ~VDataTool(){} + VDataTool &operator= (const VDataTool &tool); + inline VContainer getData() const { return data; } + void setData(const VContainer *value); + virtual inline qint64 referens() const {return _referens;} + virtual inline void incrementReferens(){++_referens;} + virtual void decrementReferens(); protected: - VContainer data; - qint64 _referens; + VContainer data; + qint64 _referens; }; #endif // VDATATOOL_H diff --git a/tools/vtooldetail.cpp b/tools/vtooldetail.cpp index ff1a6466a..06b9d8da7 100644 --- a/tools/vtooldetail.cpp +++ b/tools/vtooldetail.cpp @@ -25,136 +25,128 @@ #include "modelingTools/vmodelingtool.h" #include "modelingTools/modelingtools.h" -VToolDetail::VToolDetail(VDomDocument *doc, VContainer *data, const qint64 &id, VDetail &oldDetail, - Tool::Sources typeCreation, const Document::Documents &parse, +VToolDetail::VToolDetail(VDomDocument *doc, VContainer *data, const qint64 &id, Tool::Sources typeCreation, VMainGraphicsScene *scene, QGraphicsItem *parent) - :VAbstractTool(doc, data, id), QGraphicsPathItem(parent), - dialogDetail(QSharedPointer()), sceneDetails(scene){ + :VAbstractTool(doc, data, id), QGraphicsPathItem(parent), dialogDetail(QSharedPointer()), + sceneDetails(scene){ VDetail detail = data->GetDetail(id); + QMap* tools = doc->getTools(); + Q_CHECK_PTR(tools); for(qint32 i = 0; i< detail.CountNode(); ++i){ switch(detail[i].getTypeTool()){ case(Tool::NodePoint):{ - VNodePoint *point = VNodePoint::Create(doc, data, detail[i].getId(), oldDetail[i].getId(), - detail[i].getMode(), parse, typeCreation); - connect(point, &VNodePoint::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); - QMap* tools = doc->getTools(); - tools->insert(detail[i].getId(),point); + VNodePoint *point = qobject_cast(tools->value(detail[i].getId())); + Q_CHECK_PTR(point); + connect(point, &VNodePoint::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); point->setParentItem(this); break; } case(Tool::NodeArc):{ - VNodeArc *arc = VNodeArc::Create(doc, data, detail[i].getId(), oldDetail[i].getId(), - detail[i].getMode(), parse, typeCreation); + VNodeArc *arc = qobject_cast(tools->value(detail[i].getId())); + Q_CHECK_PTR(arc); connect(arc, &VNodeArc::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); - QMap* tools = doc->getTools(); - tools->insert(detail[i].getId(), arc); arc->setParentItem(this); break; } case(Tool::NodeSpline):{ - VNodeSpline *spl = VNodeSpline::Create(doc, data, detail[i].getId(), oldDetail[i].getId(), - detail[i].getMode(), parse, typeCreation); + VNodeSpline *spl = qobject_cast(tools->value(detail[i].getId())); + Q_CHECK_PTR(spl); connect(spl, &VNodeSpline::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); - QMap* tools = doc->getTools(); - tools->insert(detail[i].getId(), spl); spl->setParentItem(this); break; } case(Tool::NodeSplinePath):{ - VNodeSplinePath *splPath = VNodeSplinePath::Create(doc, data, detail[i].getId(), - oldDetail[i].getId(), - detail[i].getMode(), parse, typeCreation); + VNodeSplinePath *splPath = qobject_cast(tools->value(detail[i].getId())); + Q_CHECK_PTR(splPath); connect(splPath, &VNodeSplinePath::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); - QMap* tools = doc->getTools(); - tools->insert(detail[i].getId(), splPath); splPath->setParentItem(this); break; } case(Tool::AlongLineTool):{ - QMap* tools = doc->getTools(); VModelingAlongLine *tool = qobject_cast(tools->value(detail[i].getId())); Q_CHECK_PTR(tool); connect(tool, &VModelingAlongLine::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); + connect(tool, &VModelingAlongLine::RemoveTool, scene, &VMainGraphicsScene::RemoveTool); tool->setParentItem(this); break; } case(Tool::ArcTool):{ - QMap* tools = doc->getTools(); VModelingArc *tool = qobject_cast(tools->value(detail[i].getId())); Q_CHECK_PTR(tool); connect(tool, &VModelingArc::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); + connect(tool, &VModelingArc::RemoveTool, scene, &VMainGraphicsScene::RemoveTool); tool->setParentItem(this); break; } case(Tool::BisectorTool):{ - QMap* tools = doc->getTools(); VModelingBisector *tool = qobject_cast(tools->value(detail[i].getId())); Q_CHECK_PTR(tool); connect(tool, &VModelingBisector::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); + connect(tool, &VModelingBisector::RemoveTool, scene, &VMainGraphicsScene::RemoveTool); tool->setParentItem(this); break; } case(Tool::EndLineTool):{ - QMap* tools = doc->getTools(); VModelingEndLine *tool = qobject_cast(tools->value(detail[i].getId())); Q_CHECK_PTR(tool); connect(tool, &VModelingEndLine::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); + connect(tool, &VModelingEndLine::RemoveTool, scene, &VMainGraphicsScene::RemoveTool); tool->setParentItem(this); break; } case(Tool::LineIntersectTool):{ - QMap* tools = doc->getTools(); VModelingLineIntersect *tool = qobject_cast(tools->value(detail[i].getId())); Q_CHECK_PTR(tool); connect(tool, &VModelingLineIntersect::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); + connect(tool, &VModelingLineIntersect::RemoveTool, scene, &VMainGraphicsScene::RemoveTool); tool->setParentItem(this); break; } case(Tool::LineTool):{ - QMap* tools = doc->getTools(); VModelingLine *tool = qobject_cast(tools->value(detail[i].getId())); Q_CHECK_PTR(tool); connect(tool, &VModelingLine::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); + connect(tool, &VModelingLine::RemoveTool, scene, &VMainGraphicsScene::RemoveTool); tool->setParentItem(this); break; } case(Tool::NormalTool):{ - QMap* tools = doc->getTools(); VModelingNormal *tool = qobject_cast(tools->value(detail[i].getId())); Q_CHECK_PTR(tool); connect(tool, &VModelingNormal::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); + connect(tool, &VModelingNormal::RemoveTool, scene, &VMainGraphicsScene::RemoveTool); tool->setParentItem(this); break; } case(Tool::PointOfContact):{ - QMap* tools = doc->getTools(); VModelingPointOfContact *tool = qobject_cast(tools->value(detail[i].getId())); Q_CHECK_PTR(tool); connect(tool, &VModelingPointOfContact::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); + connect(tool, &VModelingPointOfContact::RemoveTool, scene, &VMainGraphicsScene::RemoveTool); tool->setParentItem(this); break; } case(Tool::ShoulderPointTool):{ - QMap* tools = doc->getTools(); VModelingShoulderPoint *tool = qobject_cast(tools->value(detail[i].getId())); Q_CHECK_PTR(tool); connect(tool, &VModelingShoulderPoint::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); + connect(tool, &VModelingShoulderPoint::RemoveTool, scene, &VMainGraphicsScene::RemoveTool); tool->setParentItem(this); break; } case(Tool::SplinePathTool):{ - QMap* tools = doc->getTools(); VModelingSplinePath *tool = qobject_cast(tools->value(detail[i].getId())); Q_CHECK_PTR(tool); connect(tool, &VModelingSplinePath::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); + connect(tool, &VModelingSplinePath::RemoveTool, scene, &VMainGraphicsScene::RemoveTool); tool->setParentItem(this); break; } case(Tool::SplineTool):{ - QMap* tools = doc->getTools(); VModelingSpline *tool = qobject_cast(tools->value(detail[i].getId())); Q_CHECK_PTR(tool); connect(tool, &VModelingSpline::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); + connect(tool, &VModelingSpline::RemoveTool, scene, &VMainGraphicsScene::RemoveTool); tool->setParentItem(this); break; } @@ -162,6 +154,7 @@ VToolDetail::VToolDetail(VDomDocument *doc, VContainer *data, const qint64 &id, qWarning()<<"Get wrong tool type. Ignore."; break; } + doc->IncrementReferens(detail[i].getId()); } this->setFlag(QGraphicsItem::ItemIsMovable, true); this->setFlag(QGraphicsItem::ItemIsSelectable, true); @@ -236,11 +229,10 @@ void VToolDetail::Create(QSharedPointer &dialog, VMainGraphicsScen det.append(node); } det.setName(detail.getName()); - Create(0, det, detail, scene, doc, data, Document::FullParse, Tool::FromGui); + Create(0, det, scene, doc, data, Document::FullParse, Tool::FromGui); } -void VToolDetail::Create(const qint64 _id, VDetail &newDetail, VDetail &oldDetail, - VMainGraphicsScene *scene, VDomDocument *doc, +void VToolDetail::Create(const qint64 _id, VDetail &newDetail, VMainGraphicsScene *scene, VDomDocument *doc, VContainer *data, const Document::Documents &parse, Tool::Sources typeCreation){ qint64 id = _id; if(typeCreation == Tool::FromGui){ @@ -248,25 +240,14 @@ void VToolDetail::Create(const qint64 _id, VDetail &newDetail, VDetail &oldDetai } else { data->UpdateDetail(id, newDetail); if(parse != Document::FullParse){ - QMap* tools = doc->getTools(); - VDataTool *tool = tools->value(id); - if(tool != 0){ - tool->VDataTool::setData(data); - } - - for(qint32 i = 0; i< newDetail.CountNode(); ++i){ - VDataTool *tool = tools->value(newDetail[i].getId()); - if(tool != 0){ - tool->VDataTool::setData(data); - } - } + doc->UpdateToolData(id, data); } } if(parse == Document::FullParse){ - VToolDetail *detail = new VToolDetail(doc, data, id, oldDetail, typeCreation, parse, scene); + VToolDetail *detail = new VToolDetail(doc, data, id, typeCreation, scene); scene->addItem(detail); connect(detail, &VToolDetail::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); - //connect(detail, &VToolBisector::RemoveTool, scene, &VMainGraphicsScene::RemoveTool); + connect(detail, &VToolDetail::RemoveTool, scene, &VMainGraphicsScene::RemoveTool); QMap* tools = doc->getTools(); tools->insert(id, detail); } @@ -323,6 +304,54 @@ void VToolDetail::mouseReleaseEvent(QGraphicsSceneMouseEvent *event){ QGraphicsItem::mouseReleaseEvent(event); } +void VToolDetail::contextMenuEvent(QGraphicsSceneContextMenuEvent *event){ + QMenu menu; + //QAction *actionOption = menu.addAction(tr("Options")); + QAction *actionRemove = menu.addAction(tr("Delete")); + if(_referens > 1){ + actionRemove->setEnabled(false); + } else { + actionRemove->setEnabled(true); + } + QAction *selectedAction = menu.exec(event->screenPos()); +// if(selectedAction == actionOption){ +// dialog = QSharedPointer(new Dialog(getData())); + +// connect(qobject_cast< VMainGraphicsScene * >(tool->scene()), &VMainGraphicsScene::ChoosedObject, +// dialog.data(), &Dialog::ChoosedObject); +// connect(dialog.data(), &Dialog::DialogClosed, tool, +// &Tool::FullUpdateFromGui); +// connect(doc, &VDomDocument::FullUpdateFromFile, dialog.data(), &Dialog::UpdateList); + +// tool->setDialog(); + +// dialog->show(); +// } + if(selectedAction == actionRemove){ + //deincrement referens + RemoveReferens(); + //remove form xml file + QDomElement domElement = doc->elementById(QString().setNum(id)); + if(domElement.isElement()){ + QDomNode element = domElement.parentNode(); + if(!element.isNull()){ + element.removeChild(domElement); + //update xml file + emit FullUpdateTree(); + //remove form scene + emit RemoveTool(this); + } + } + } +} + +void VToolDetail::RemoveReferens(){ + VDetail detail = VAbstractTool::data.GetDetail(id); + for(qint32 i = 0; i< detail.CountNode(); ++i){ + doc->DecrementReferens(detail[i].getId()); + } +} + void VToolDetail::AddNode(QDomElement &domElement, VNodeDetail &node){ QDomElement nod = doc->createElement("node"); diff --git a/tools/vtooldetail.h b/tools/vtooldetail.h index d275996cf..a0441e48f 100644 --- a/tools/vtooldetail.h +++ b/tools/vtooldetail.h @@ -26,19 +26,18 @@ #include #include "dialogs/dialogdetail.h" -class VToolDetail: public VAbstractTool, public QGraphicsPathItem -{ +class VToolDetail: public VAbstractTool, public QGraphicsPathItem{ Q_OBJECT public: - VToolDetail(VDomDocument *doc, VContainer *data, const qint64 &id, VDetail &oldDetail, - Tool::Sources typeCreation, const Document::Documents &parse, VMainGraphicsScene *scene, - QGraphicsItem * parent = 0); - virtual void setDialog(); - static void Create(QSharedPointer &dialog, VMainGraphicsScene *scene, VDomDocument *doc, - VContainer *data); - static void Create(const qint64 _id, VDetail &newDetail, VDetail &oldDetail, - VMainGraphicsScene *scene, - VDomDocument *doc, VContainer *data, const Document::Documents &parse, Tool::Sources typeCreation); + VToolDetail(VDomDocument *doc, VContainer *data, const qint64 &id, + Tool::Sources typeCreation, VMainGraphicsScene *scene, + QGraphicsItem * parent = 0); + virtual void setDialog(); + static void Create(QSharedPointer &dialog, VMainGraphicsScene *scene, + VDomDocument *doc, VContainer *data); + static void Create(const qint64 _id, VDetail &newDetail, VMainGraphicsScene *scene, + VDomDocument *doc, VContainer *data, const Document::Documents &parse, + Tool::Sources typeCreation); template void AddTool(T *tool, const qint64 &id, Tool::Tools typeTool){ tool->setParentItem(this); @@ -55,16 +54,20 @@ public: public slots: virtual void FullUpdateFromFile (); virtual void FullUpdateFromGui(int result); +signals: + void RemoveTool(QGraphicsItem *tool); protected: virtual void AddToFile (); QVariant itemChange ( GraphicsItemChange change, const QVariant &value ); virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ); + virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); + virtual void RemoveReferens(); private: Q_DISABLE_COPY(VToolDetail) QSharedPointer dialogDetail; VMainGraphicsScene *sceneDetails; void RefreshGeometry (); - void AddNode(QDomElement &domElement, VNodeDetail &node); + void AddNode(QDomElement &domElement, VNodeDetail &node); }; #endif // VTOOLDETAIL_H diff --git a/xml/vdomdocument.cpp b/xml/vdomdocument.cpp index 94bbe603a..151a6b522 100644 --- a/xml/vdomdocument.cpp +++ b/xml/vdomdocument.cpp @@ -494,7 +494,7 @@ void VDomDocument::ParseDetailElement(VMainGraphicsScene *sceneDetail, const QDo } } } - VToolDetail::Create(id, detail, oldDetail, sceneDetail, this, data, parse, Tool::FromFile); + VToolDetail::Create(id, detail, sceneDetail, this, data, parse, Tool::FromFile); } catch(const VExceptionBadId &e){ VExceptionObjectError excep(tr("Error creating or updating detail"), domElement); @@ -565,7 +565,6 @@ void VDomDocument::ParsePointElement(VMainGraphicsScene *scene, const QDomElemen QString formula = GetParametrString(domElement, "length"); qint64 basePointId = GetParametrLongLong(domElement, "basePoint"); qreal angle = GetParametrDouble(domElement, "angle"); - data->IncrementReferens(basePointId, Scene::Point, mode); if(mode == Draw::Calculation){ VToolEndLine::Create(id, name, typeLine, formula, angle, basePointId, mx, my, scene, this, data, parse, Tool::FromFile); @@ -591,8 +590,7 @@ void VDomDocument::ParsePointElement(VMainGraphicsScene *scene, const QDomElemen QString formula = GetParametrString(domElement, "length"); qint64 firstPointId = GetParametrLongLong(domElement, "firstPoint"); qint64 secondPointId = GetParametrLongLong(domElement, "secondPoint"); - data->IncrementReferens(firstPointId, Scene::Point, mode); - data->IncrementReferens(secondPointId, Scene::Point, mode); + if(mode == Draw::Calculation){ VToolAlongLine::Create(id, name, typeLine, formula, firstPointId, secondPointId, mx, my, scene, this, data, parse, Tool::FromFile); @@ -619,9 +617,7 @@ void VDomDocument::ParsePointElement(VMainGraphicsScene *scene, const QDomElemen qint64 p1Line = GetParametrLongLong(domElement, "p1Line"); qint64 p2Line = GetParametrLongLong(domElement, "p2Line"); qint64 pShoulder = GetParametrLongLong(domElement, "pShoulder"); - data->IncrementReferens(p1Line, Scene::Point, mode); - data->IncrementReferens(p2Line, Scene::Point, mode); - data->IncrementReferens(pShoulder, Scene::Point, mode); + if(mode == Draw::Calculation){ VToolShoulderPoint::Create(id, formula, p1Line, p2Line, pShoulder, typeLine, name, mx, my, scene, this, data, parse, Tool::FromFile); @@ -648,8 +644,7 @@ void VDomDocument::ParsePointElement(VMainGraphicsScene *scene, const QDomElemen qint64 firstPointId = GetParametrLongLong(domElement, "firstPoint"); qint64 secondPointId = GetParametrLongLong(domElement, "secondPoint"); qreal angle = GetParametrDouble(domElement, "angle"); - data->IncrementReferens(firstPointId, Scene::Point, mode); - data->IncrementReferens(secondPointId, Scene::Point, mode); + if(mode == Draw::Calculation){ VToolNormal::Create(id, formula, firstPointId, secondPointId, typeLine, name, angle, mx, my, scene, this, data, parse, Tool::FromFile); @@ -676,9 +671,7 @@ void VDomDocument::ParsePointElement(VMainGraphicsScene *scene, const QDomElemen qint64 firstPointId = GetParametrLongLong(domElement, "firstPoint"); qint64 secondPointId = GetParametrLongLong(domElement, "secondPoint"); qint64 thirdPointId = GetParametrLongLong(domElement, "thirdPoint"); - data->IncrementReferens(firstPointId, Scene::Point, mode); - data->IncrementReferens(secondPointId, Scene::Point, mode); - data->IncrementReferens(thirdPointId, Scene::Point, mode); + if(mode == Draw::Calculation){ VToolBisector::Create(id, formula, firstPointId, secondPointId, thirdPointId, typeLine, name, mx, my, scene, this, data, parse, Tool::FromFile); @@ -704,10 +697,7 @@ void VDomDocument::ParsePointElement(VMainGraphicsScene *scene, const QDomElemen qint64 p2Line1Id = GetParametrLongLong(domElement, "p2Line1"); qint64 p1Line2Id = GetParametrLongLong(domElement, "p1Line2"); qint64 p2Line2Id = GetParametrLongLong(domElement, "p2Line2"); - data->IncrementReferens(p1Line1Id, Scene::Point, mode); - data->IncrementReferens(p2Line1Id, Scene::Point, mode); - data->IncrementReferens(p1Line2Id, Scene::Point, mode); - data->IncrementReferens(p2Line2Id, Scene::Point, mode); + if(mode == Draw::Calculation){ VToolLineIntersect::Create(id, p1Line1Id, p2Line1Id, p1Line2Id, p2Line2Id, name, mx, my, scene, this, data, parse, Tool::FromFile); @@ -733,9 +723,7 @@ void VDomDocument::ParsePointElement(VMainGraphicsScene *scene, const QDomElemen qint64 center = GetParametrLongLong(domElement, "center"); qint64 firstPointId = GetParametrLongLong(domElement, "firstPoint"); qint64 secondPointId = GetParametrLongLong(domElement, "secondPoint"); - data->IncrementReferens(center, Scene::Point, mode); - data->IncrementReferens(firstPointId, Scene::Point, mode); - data->IncrementReferens(secondPointId, Scene::Point, mode); + if(mode == Draw::Calculation){ VToolPointOfContact::Create(id, radius, center, firstPointId, secondPointId, name, mx, my, scene, this, data, parse, Tool::FromFile); @@ -769,7 +757,7 @@ void VDomDocument::ParsePointElement(VMainGraphicsScene *scene, const QDomElemen qreal my = toPixel(GetParametrDouble(domElement, "my")); data->UpdateModelingPoint(id, VPointF(point.x(), point.y(), point.name(), mx, my, typeObject, idObject )); - data->IncrementReferens(idObject, Scene::Point, typeObject); + VNodePoint::Create(this, data, id, idObject, mode, parse, Tool::FromFile); return; } catch(const VExceptionBadId &e){ @@ -788,8 +776,7 @@ void VDomDocument::ParseLineElement(VMainGraphicsScene *scene, const QDomElement qint64 id = GetParametrId(domElement); qint64 firstPoint = GetParametrLongLong(domElement, "firstPoint"); qint64 secondPoint = GetParametrLongLong(domElement, "secondPoint"); - data->IncrementReferens(firstPoint, Scene::Point, mode); - data->IncrementReferens(secondPoint, Scene::Point, mode); + if(mode == Draw::Calculation){ VToolLine::Create(id, firstPoint, secondPoint, scene, this, data, parse, Tool::FromFile); } else { @@ -805,7 +792,8 @@ void VDomDocument::ParseLineElement(VMainGraphicsScene *scene, const QDomElement } void VDomDocument::ParseSplineElement(VMainGraphicsScene *scene, const QDomElement &domElement, - const Document::Documents &parse, const QString &type, Draw::Draws mode){ + const Document::Documents &parse, const QString &type, + Draw::Draws mode){ Q_CHECK_PTR(scene); Q_ASSERT_X(!domElement.isNull(), Q_FUNC_INFO, "domElement is null"); Q_ASSERT_X(!type.isEmpty(), Q_FUNC_INFO, "type of spline is empty"); @@ -819,8 +807,7 @@ void VDomDocument::ParseSplineElement(VMainGraphicsScene *scene, const QDomEleme qreal kAsm1 = GetParametrDouble(domElement, "kAsm1"); qreal kAsm2 = GetParametrDouble(domElement, "kAsm2"); qreal kCurve = GetParametrDouble(domElement, "kCurve"); - data->IncrementReferens(point1, Scene::Point, mode); - data->IncrementReferens(point4, Scene::Point, mode); + if(mode == Draw::Calculation){ VToolSpline::Create(id, point1, point4, kAsm1, kAsm2, angle1, angle2, kCurve, scene, this, data, parse, Tool::FromFile); @@ -855,7 +842,9 @@ void VDomDocument::ParseSplineElement(VMainGraphicsScene *scene, const QDomEleme qint64 pSpline = GetParametrLongLong(element, "pSpline"); VSplinePoint splPoint(pSpline, kAsm1, angle, kAsm2); path.append(splPoint); - data->IncrementReferens(pSpline, Scene::Point, mode); + if(parse == Document::FullParse){ + IncrementReferens(pSpline); + } } } } @@ -888,14 +877,8 @@ void VDomDocument::ParseSplineElement(VMainGraphicsScene *scene, const QDomEleme } spl.setMode(typeObject); spl.setIdObject(idObject); - if(typeObject == Draw::Calculation){ - data->IncrementReferens(spl.GetP1(), Scene::Point, Draw::Calculation); - data->IncrementReferens(spl.GetP4(), Scene::Point, Draw::Calculation); - } else { - data->IncrementReferens(spl.GetP1(), Scene::Point, Draw::Modeling); - data->IncrementReferens(spl.GetP4(), Scene::Point, Draw::Modeling); - } data->UpdateModelingSpline(id, spl); + VNodeSpline::Create(this, data, id, idObject,mode, parse, Tool::FromFile); return; } catch(const VExceptionBadId &e){ @@ -921,14 +904,7 @@ void VDomDocument::ParseSplineElement(VMainGraphicsScene *scene, const QDomEleme path.setMode(typeObject); path.setIdObject(idObject); data->UpdateModelingSplinePath(id, path); - const QVector *points = path.GetPoint(); - for(qint32 i = 0; isize(); ++i){ - if(typeObject == Draw::Calculation){ - data->IncrementReferens(points->at(i).P(), Scene::Point, Draw::Calculation); - } else { - data->IncrementReferens(points->at(i).P(), Scene::Point, Draw::Modeling); - } - } + VNodeSplinePath::Create(this, data, id, idObject, mode, parse, Tool::FromFile); return; } catch(const VExceptionBadId &e){ @@ -951,7 +927,7 @@ void VDomDocument::ParseArcElement(VMainGraphicsScene *scene, const QDomElement QString radius = GetParametrString(domElement, "radius"); QString f1 = GetParametrString(domElement, "angle1"); QString f2 = GetParametrString(domElement, "angle2"); - data->IncrementReferens(center, Scene::Point, mode); + if(mode == Draw::Calculation){ VToolArc::Create(id, center, radius, f1, f2, scene, this, data, parse, Tool::FromFile); } else { @@ -983,7 +959,7 @@ void VDomDocument::ParseArcElement(VMainGraphicsScene *scene, const QDomElement arc.setMode(typeObject); arc.setIdObject(idObject); data->UpdateModelingArc(id, arc); - data->IncrementReferens(idObject, Scene::Point, mode); + VNodeArc::Create(this, data, id, idObject, mode, parse, Tool::FromFile); return; } catch(const VExceptionBadId &e){ @@ -1059,73 +1035,18 @@ void VDomDocument::setCurrentData(){ } void VDomDocument::GarbageCollector(){ - const QMap *points = data->DataPoints(); - Q_CHECK_PTR(points); - QMapIterator p(*points); - while (p.hasNext()) { - p.next(); - VPointF point = p.value(); - if(point.referens() <= 0){ - QDomElement domElement = elementById(QString().setNum(p.key())); + QMapIterator t(tools); + while (t.hasNext()) { + t.next(); + VDataTool *tool = t.value(); + if(tool->referens() <= 0){ + QDomElement domElement = elementById(QString().setNum(t.key())); if(domElement.isElement()){ - QDomElement element; - bool ok = GetActivModelingElement(element); - if(ok){ - element.removeChild(domElement); - } - } - } - } - - const QMap *arc = data->DataArcs(); - Q_CHECK_PTR(arc); - QMapIterator a(*arc); - while (a.hasNext()) { - a.next(); - VArc arc = a.value(); - if(arc.referens() <= 0){ - QDomElement domElement = elementById(QString().setNum(a.key())); - if(domElement.isElement()){ - QDomElement element; - bool ok = GetActivModelingElement(element); - if(ok){ - element.removeChild(domElement); - } - } - } - } - - const QMap *spl = data->DataSplines(); - Q_CHECK_PTR(spl); - QMapIterator s(*spl); - while (s.hasNext()) { - s.next(); - VSpline spl = s.value(); - if(spl.referens() <= 0){ - QDomElement domElement = elementById(QString().setNum(s.key())); - if(domElement.isElement()){ - QDomElement element; - bool ok = GetActivModelingElement(element); - if(ok){ - element.removeChild(domElement); - } - } - } - } - - const QMap *splPath = data->DataSplinePaths(); - Q_CHECK_PTR(splPath); - QMapIterator q(*splPath); - while (q.hasNext()) { - q.next(); - VSplinePath splPath = q.value(); - if(splPath.referens() <= 0){ - QDomElement domElement = elementById(QString().setNum(q.key())); - if(domElement.isElement()){ - QDomElement element; - bool ok = GetActivModelingElement(element); - if(ok){ - element.removeChild(domElement); + QDomNode parent = domElement.parentNode(); + if(!parent.isNull()){ + parent.removeChild(domElement); + } else { + qWarning()<VDataTool::setData(data); } + +void VDomDocument::IncrementReferens(qint64 id) const{ + Q_ASSERT_X(id > 0, Q_FUNC_INFO, "id <= 0"); + VDataTool *tool = tools.value(id); + Q_CHECK_PTR(tool); + tool->incrementReferens(); +} + +void VDomDocument::DecrementReferens(qint64 id) const{ + Q_ASSERT_X(id > 0, Q_FUNC_INFO, "id <= 0"); + VDataTool *tool = tools.value(id); + Q_CHECK_PTR(tool); + tool->decrementReferens(); +} diff --git a/xml/vdomdocument.h b/xml/vdomdocument.h index 9a6d37270..62bbb275b 100644 --- a/xml/vdomdocument.h +++ b/xml/vdomdocument.h @@ -67,6 +67,8 @@ public: void GarbageCollector(); void AddTool(const qint64 &id, VDataTool *tool); void UpdateToolData(const qint64 &id, VContainer *data); + void IncrementReferens(qint64 id) const; + void DecrementReferens(qint64 id) const; signals: void ChangedActivDraw(const QString newName); void ChangedNameDraw(const QString oldName, const QString newName);