Implicit Sharing for class VGObject.

--HG--
branch : develop
This commit is contained in:
dismine 2014-08-20 15:01:35 +03:00
parent fb750ece99
commit d75969b331
9 changed files with 52 additions and 58 deletions

View file

@ -10,7 +10,9 @@ HEADERS += \
geometry/vequidistant.h \
geometry/vabstractcurve.h \
geometry/vnodedetail_p.h \
geometry/vdetail_p.h
geometry/vdetail_p.h \
geometry/vgobject_p.h \
geometry/varc_p.h
SOURCES += \
geometry/vsplinepoint.cpp \

View file

@ -44,20 +44,9 @@ public:
VAbstractCurve& operator= (const VAbstractCurve &curve);
virtual QVector<QPointF> GetPoints() const =0;
virtual QPainterPath GetPath(PathDirection direction = PathDirection::Hide) const;
virtual QString name() const;
virtual qreal GetLength() const =0;
protected:
QPainterPath ShowDirection(const QVector<QPointF> &points) const;
};
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief name return curve name. This name used in variables.
* @return name
*/
inline QString VAbstractCurve::name() const
{
return _name;
}
#endif // VABSTRACTCURVE_H

View file

@ -59,7 +59,7 @@ VArc::VArc (VPointF center, qreal radius, QString formulaRadius, qreal f1, QStri
: VAbstractCurve(GOType::Arc, idObject, mode), f1(f1), formulaF1(formulaF1), f2(f2), formulaF2(formulaF2),
radius(radius), formulaRadius(formulaRadius), center(center)
{
_name = QString (arc_+"%1").arg(this->GetCenter().name());
setName(QString (arc_+"%1").arg(this->GetCenter().name()));
}
//---------------------------------------------------------------------------------------------------------------------
@ -67,7 +67,7 @@ VArc::VArc(VPointF center, qreal radius, qreal f1, qreal f2)
: VAbstractCurve(GOType::Arc, 0, Draw::Calculation), f1(f1), formulaF1(QStringLiteral("")), f2(f2),
formulaF2(QStringLiteral("")), radius(radius), formulaRadius(QStringLiteral("")), center(center)
{
_name = QString (arc_+"%1").arg(this->GetCenter().name());
setName(QString (arc_+"%1").arg(this->GetCenter().name()));
formulaF1 = QString("%1").arg(f1);
formulaF2 = QString("%1").arg(f2);
formulaRadius = QString("%1").arg(radius);
@ -215,10 +215,10 @@ QPointF VArc::CutArc(const qreal &length, VArc &arc1, VArc &arc2) const
line.setAngle(line.angle()+n);
arc1 = VArc (center, radius, formulaRadius, f1, formulaF1, line.angle(), QString().setNum(line.angle()),
idObject, mode);
getIdObject(), getMode());
arc2 = VArc (center, radius, formulaRadius, line.angle(), QString().setNum(line.angle()), f2, formulaF2,
idObject, mode);
getIdObject(), getMode());
return line.p2();
}
@ -238,6 +238,6 @@ QPointF VArc::CutArc(const qreal &length) const
*/
void VArc::setId(const quint32 &id)
{
_id = id;
_name = QString (arc_+"%1_%2").arg(center.name()).arg(id);
VAbstractCurve::setId(id);
setName(QString (arc_+"%1_%2").arg(center.name()).arg(id));
}

View file

@ -27,13 +27,14 @@
*************************************************************************/
#include "vgobject.h"
#include "vgobject_p.h"
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief VGObject default constructor.
*/
VGObject::VGObject()
:_id(NULL_ID), type(GOType::Unknown), idObject(NULL_ID), _name(QString()), mode(Draw::Calculation)
:d(new VGObjectData)
{}
//---------------------------------------------------------------------------------------------------------------------
@ -44,7 +45,7 @@ VGObject::VGObject()
* @param mode mode creation. Used in modeling mode.
*/
VGObject::VGObject(const GOType &type, const quint32 &idObject, const Draw &mode)
:_id(NULL_ID), type(type), idObject(idObject), _name(QString()), mode(mode)
:d(new VGObjectData(type, idObject, mode))
{}
//---------------------------------------------------------------------------------------------------------------------
@ -53,7 +54,7 @@ VGObject::VGObject(const GOType &type, const quint32 &idObject, const Draw &mode
* @param obj object.
*/
VGObject::VGObject(const VGObject &obj)
:_id(obj.id()), type(obj.getType()), idObject(obj.getIdObject()), _name(obj.name()), mode(obj.getMode())
:d (obj.d)
{}
//---------------------------------------------------------------------------------------------------------------------
@ -68,14 +69,14 @@ VGObject &VGObject::operator=(const VGObject &obj)
{
return *this;
}
this->_id = obj.id();
this->type = obj.getType();
this->idObject = obj.getIdObject();
this->_name = obj.name();
this->mode = obj.getMode();
d = obj.d;
return *this;
}
//---------------------------------------------------------------------------------------------------------------------
VGObject::~VGObject()
{}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief getIdObject return parent id.
@ -83,7 +84,7 @@ VGObject &VGObject::operator=(const VGObject &obj)
*/
quint32 VGObject::getIdObject() const
{
return idObject;
return d->idObject;
}
//---------------------------------------------------------------------------------------------------------------------
@ -93,7 +94,7 @@ quint32 VGObject::getIdObject() const
*/
void VGObject::setIdObject(const quint32 &value)
{
idObject = value;
d->idObject = value;
}
//---------------------------------------------------------------------------------------------------------------------
@ -103,7 +104,7 @@ void VGObject::setIdObject(const quint32 &value)
*/
QString VGObject::name() const
{
return _name;
return d->_name;
}
//---------------------------------------------------------------------------------------------------------------------
@ -113,7 +114,7 @@ QString VGObject::name() const
*/
void VGObject::setName(const QString &name)
{
_name = name;
d->_name = name;
}
//---------------------------------------------------------------------------------------------------------------------
@ -123,7 +124,7 @@ void VGObject::setName(const QString &name)
*/
Draw VGObject::getMode() const
{
return mode;
return d->mode;
}
//---------------------------------------------------------------------------------------------------------------------
@ -133,7 +134,7 @@ Draw VGObject::getMode() const
*/
void VGObject::setMode(const Draw &value)
{
mode = value;
d->mode = value;
}
//---------------------------------------------------------------------------------------------------------------------
@ -143,7 +144,13 @@ void VGObject::setMode(const Draw &value)
*/
GOType VGObject::getType() const
{
return type;
return d->type;
}
//---------------------------------------------------------------------------------------------------------------------
void VGObject::setType(const GOType &type)
{
d->type = type;
}
//---------------------------------------------------------------------------------------------------------------------
@ -153,7 +160,7 @@ GOType VGObject::getType() const
*/
quint32 VGObject::id() const
{
return _id;
return d->_id;
}
//---------------------------------------------------------------------------------------------------------------------
@ -163,5 +170,5 @@ quint32 VGObject::id() const
*/
void VGObject::setId(const quint32 &id)
{
_id = id;
d->_id = id;
}

View file

@ -32,8 +32,9 @@
#include "../options.h"
#include <QString>
#include <QtGlobal>
#include <QSharedDataPointer>
enum class GOType : char { Point, Arc, Spline, SplinePath, Unknown };
class VGObjectData;
/**
* @brief The VGObject class keep information graphical objects.
@ -45,31 +46,24 @@ public:
VGObject(const GOType &type, const quint32 &idObject = 0, const Draw &mode = Draw::Calculation);
VGObject(const VGObject &obj);
VGObject& operator= (const VGObject &obj);
virtual ~VGObject(){}
virtual ~VGObject();
quint32 getIdObject() const;
void setIdObject(const quint32 &value);
virtual QString name() const;
void setName(const QString &name);
Draw getMode() const;
void setMode(const Draw &value);
GOType getType() const;
void setType(const GOType &type);
quint32 id() const;
virtual void setId(const quint32 &id);
protected:
/** @brief _id id in container. Ned for arcs, spline and spline paths. */
quint32 _id;
/** @brief type type of graphical object */
GOType type;
/** @brief idObject id of parent object. Only for modeling. All another return 0. */
quint32 idObject;
/** @brief _name object name */
QString _name;
/** @brief mode object created in calculation or drawing mode */
Draw mode;
private:
QSharedDataPointer<VGObjectData> d;
};
#endif // VGOBJECT_H

View file

@ -42,7 +42,7 @@
VPointF::VPointF(qreal x, qreal y, const QString &name, qreal mx, qreal my, quint32 idObject, const Draw &mode)
:VGObject(GOType::Point, idObject, mode), _mx(mx), _my(my), _x(x), _y(y)
{
this->_name = name;
setName(name);
}
//---------------------------------------------------------------------------------------------------------------------
@ -56,7 +56,7 @@ VPointF::VPointF(qreal x, qreal y, const QString &name, qreal mx, qreal my, quin
VPointF::VPointF(const QPointF &point, const QString &name, qreal mx, qreal my, quint32 idObject, const Draw &mode)
:VGObject(GOType::Point, idObject, mode), _mx(mx), _my(my), _x(point.x()), _y(point.y())
{
this->_name = name;
setName(name);
}
//---------------------------------------------------------------------------------------------------------------------

View file

@ -652,7 +652,7 @@ qreal VSpline::CalcSqDistance (qreal x1, qreal y1, qreal x2, qreal y2)
*/
void VSpline::CreateName()
{
_name = QString(spl_+"%1_%2").arg(this->GetP1().name(), this->GetP4().name());
setName(QString(spl_+"%1_%2").arg(this->GetP1().name(), this->GetP4().name()));
}
//---------------------------------------------------------------------------------------------------------------------

View file

@ -45,12 +45,13 @@ VSplinePath::VSplinePath(const VSplinePath &splPath)
void VSplinePath::append(const VSplinePoint &point)
{
path.append(point);
_name = splPath;
_name.append(QString("_%1").arg(path.first().P().name()));
QString name = splPath;
name.append(QString("_%1").arg(path.first().P().name()));
if (path.size() > 1)
{
_name.append(QString("_%1").arg(path.last().P().name()));
name.append(QString("_%1").arg(path.last().P().name()));
}
setName(name);
}
//---------------------------------------------------------------------------------------------------------------------

View file

@ -78,6 +78,7 @@ enum class MeasurementsType : char { Standard, Individual };
enum class NodeDetail : char { Contour, Modeling };
enum class Contour : char { OpenContour, CloseContour };
enum class EquidistantType : char { OpenEquidistant, CloseEquidistant };
enum class GOType : char { Point, Arc, Spline, SplinePath, Unknown };
enum class GHeights : unsigned char { ALL,
H92=92, H98=98, H104=104, H110=110, H116=116, H122=122, H128=128, H134=134,