Implicit Sharing for class VDetail.

--HG--
branch : develop
This commit is contained in:
dismine 2014-08-20 14:11:12 +03:00
parent ada855b4e6
commit fb750ece99
5 changed files with 238 additions and 169 deletions

View File

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

View File

@ -27,27 +27,23 @@
*************************************************************************/
#include "vdetail.h"
#include "vdetail_p.h"
#include <QDebug>
#include <QString>
//---------------------------------------------------------------------------------------------------------------------
VDetail::VDetail()
:_id(NULL_ID), nodes(QVector<VNodeDetail>()), name(QString()), mx(0), my(0), seamAllowance(true), closed(true),
width(0)
:d(new VDetailData)
{}
//---------------------------------------------------------------------------------------------------------------------
VDetail::VDetail(const QString &name, const QVector<VNodeDetail> &nodes)
:_id(NULL_ID), nodes(QVector<VNodeDetail>()), name(name), mx(0), my(0), seamAllowance(true), closed(true),
width(0)
{
this->nodes = nodes;
}
:d(new VDetailData(name, nodes))
{}
//---------------------------------------------------------------------------------------------------------------------
VDetail::VDetail(const VDetail &detail)
:_id(NULL_ID), nodes(detail.getNodes()), name(detail.getName()), mx(detail.getMx()), my(detail.getMy()),
seamAllowance(detail.getSeamAllowance()), closed(detail.getClosed()), width(detail.getWidth())
:d (detail.d)
{}
//---------------------------------------------------------------------------------------------------------------------
@ -57,41 +53,38 @@ VDetail &VDetail::operator =(const VDetail &detail)
{
return *this;
}
_id = detail.id();
nodes = detail.getNodes();
name = detail.getName();
mx = detail.getMx();
my = detail.getMy();
seamAllowance = detail.getSeamAllowance();
closed = detail.getClosed();
width = detail.getWidth();
d = detail.d;
return *this;
}
//---------------------------------------------------------------------------------------------------------------------
VDetail::~VDetail()
{}
//---------------------------------------------------------------------------------------------------------------------
void VDetail::Clear()
{
nodes.clear();
name.clear();
mx = 0;
my = 0;
seamAllowance = true;
closed = true;
width = 0;
d->nodes.clear();
d->name.clear();
d->mx = 0;
d->my = 0;
d->seamAllowance = true;
d->closed = true;
d->width = 0;
}
//---------------------------------------------------------------------------------------------------------------------
void VDetail::ClearNodes()
{
nodes.clear();
d->nodes.clear();
}
//---------------------------------------------------------------------------------------------------------------------
bool VDetail::Containes(const quint32 &id) const
{
for (ptrdiff_t i = 0; i < nodes.size(); ++i)
for (int i = 0; i < d->nodes.size(); ++i)
{
VNodeDetail node = nodes.at(i);
VNodeDetail node = d->nodes.at(i);
if (node.getId() == id)
{
return true;
@ -101,33 +94,33 @@ bool VDetail::Containes(const quint32 &id) const
}
//---------------------------------------------------------------------------------------------------------------------
VNodeDetail &VDetail::operator [](ptrdiff_t indx)
VNodeDetail &VDetail::operator [](int indx)
{
return nodes[indx];
return d->nodes[indx];
}
//---------------------------------------------------------------------------------------------------------------------
const VNodeDetail &VDetail::at(ptrdiff_t indx) const
const VNodeDetail &VDetail::at(int indx) const
{
return nodes.at(indx);
return d->nodes.at(indx);
}
//---------------------------------------------------------------------------------------------------------------------
ptrdiff_t VDetail::indexOfNode(const quint32 &id) const
int VDetail::indexOfNode(const quint32 &id) const
{
return indexOfNode(nodes, id);
return indexOfNode(d->nodes, id);
}
//---------------------------------------------------------------------------------------------------------------------
quint32 VDetail::id() const
{
return _id;
return d->_id;
}
//---------------------------------------------------------------------------------------------------------------------
void VDetail::setId(const quint32 &id)
{
_id = id;
d->_id = id;
}
//---------------------------------------------------------------------------------------------------------------------
@ -139,8 +132,8 @@ bool VDetail::OnEdge(const quint32 &p1, const quint32 &p2) const
qDebug()<<"Not enough points.";
return false;
}
ptrdiff_t i = indexOfNode(list, p1);
ptrdiff_t j1 = 0, j2 = 0;
int i = indexOfNode(list, p1);
int j1 = 0, j2 = 0;
if (i == list.size() - 1)
{
@ -169,7 +162,7 @@ bool VDetail::OnEdge(const quint32 &p1, const quint32 &p2) const
}
//---------------------------------------------------------------------------------------------------------------------
ptrdiff_t VDetail::Edge(const quint32 &p1, const quint32 &p2) const
int VDetail::Edge(const quint32 &p1, const quint32 &p2) const
{
if (OnEdge(p1, p2) == false)
{
@ -178,10 +171,10 @@ ptrdiff_t VDetail::Edge(const quint32 &p1, const quint32 &p2) const
}
QVector<VNodeDetail> list = listNodePoint();
ptrdiff_t i = indexOfNode(list, p1);
ptrdiff_t j = indexOfNode(list, p2);
int i = indexOfNode(list, p1);
int j = indexOfNode(list, p2);
ptrdiff_t min = qMin(i, j);
int min = qMin(i, j);
if (min == 0 && (i == list.size() - 1 || j == list.size() - 1))
{
@ -234,8 +227,8 @@ VDetail VDetail::RemoveEdge(const quint32 &index) const
VNodeDetail p1;
VNodeDetail p2;
this->NodeOnEdge(i, p1, p2);
ptrdiff_t j1 = this->indexOfNode(p1.getId());
ptrdiff_t j2 = this->indexOfNode(p2.getId());
int j1 = this->indexOfNode(p1.getId());
int j2 = this->indexOfNode(p2.getId());
if (j2 == 0)
{
j2 = this->CountNode()-1;
@ -246,7 +239,7 @@ VDetail VDetail::RemoveEdge(const quint32 &index) const
continue;
}
}
for (ptrdiff_t j=j1; j<j2; ++j)
for (int j=j1; j<j2; ++j)
{
det.append(this->at(j));
++k;
@ -259,15 +252,15 @@ VDetail VDetail::RemoveEdge(const quint32 &index) const
//---------------------------------------------------------------------------------------------------------------------
QList<quint32> VDetail::Missing(const VDetail &det) const
{
if (nodes.size() == det.CountNode())
if (d->nodes.size() == det.CountNode())
{
return QList<quint32>();
}
QSet<quint32> set1;
for (qint32 i = 0; i < nodes.size(); ++i)
for (qint32 i = 0; i < d->nodes.size(); ++i)
{
set1.insert(nodes.at(i).getId());
set1.insert(d->nodes.at(i).getId());
}
QSet<quint32> set2;
@ -285,20 +278,20 @@ QList<quint32> VDetail::Missing(const VDetail &det) const
QVector<VNodeDetail> VDetail::listNodePoint() const
{
QVector<VNodeDetail> list;
for (ptrdiff_t i = 0; i < nodes.size(); ++i)
for (int i = 0; i < d->nodes.size(); ++i)
{
if (nodes.at(i).getTypeTool() == Tool::NodePoint)
if (d->nodes.at(i).getTypeTool() == Tool::NodePoint)
{
list.append(nodes.at(i));
list.append(d->nodes.at(i));
}
}
return list;
}
//---------------------------------------------------------------------------------------------------------------------
ptrdiff_t VDetail::indexOfNode(const QVector<VNodeDetail> &list, const quint32 &id)
int VDetail::indexOfNode(const QVector<VNodeDetail> &list, const quint32 &id)
{
for (ptrdiff_t i = 0; i < list.size(); ++i)
for (int i = 0; i < list.size(); ++i)
{
if (list.at(i).getId() == id)
{
@ -308,3 +301,99 @@ ptrdiff_t VDetail::indexOfNode(const QVector<VNodeDetail> &list, const quint32 &
qDebug()<<"Can't find node.";
return -1;
}
//---------------------------------------------------------------------------------------------------------------------
void VDetail::append(const VNodeDetail &node)
{
d->nodes.append(node);
}
//---------------------------------------------------------------------------------------------------------------------
qint32 VDetail::CountNode() const
{
return d->nodes.size();
}
//---------------------------------------------------------------------------------------------------------------------
QString VDetail::getName() const
{
return d->name;
}
//---------------------------------------------------------------------------------------------------------------------
void VDetail::setName(const QString &value)
{
d->name = value;
}
//---------------------------------------------------------------------------------------------------------------------
qreal VDetail::getMx() const
{
return d->mx;
}
//---------------------------------------------------------------------------------------------------------------------
void VDetail::setMx(const qreal &value)
{
d->mx = value;
}
//---------------------------------------------------------------------------------------------------------------------
qreal VDetail::getMy() const
{
return d->my;
}
//---------------------------------------------------------------------------------------------------------------------
void VDetail::setMy(const qreal &value)
{
d->my = value;
}
//---------------------------------------------------------------------------------------------------------------------
bool VDetail::getSeamAllowance() const
{
return d->seamAllowance;
}
//---------------------------------------------------------------------------------------------------------------------
void VDetail::setSeamAllowance(bool value)
{
d->seamAllowance = value;
}
//---------------------------------------------------------------------------------------------------------------------
bool VDetail::getClosed() const
{
return d->closed;
}
//---------------------------------------------------------------------------------------------------------------------
void VDetail::setClosed(bool value)
{
d->closed = value;
}
//---------------------------------------------------------------------------------------------------------------------
qreal VDetail::getWidth() const
{
return d->width;
}
//---------------------------------------------------------------------------------------------------------------------
void VDetail::setWidth(const qreal &value)
{
d->width = value;
}
//---------------------------------------------------------------------------------------------------------------------
QVector<VNodeDetail> VDetail::getNodes() const
{
return d->nodes;
}
//---------------------------------------------------------------------------------------------------------------------
void VDetail::setNodes(const QVector<VNodeDetail> &value)
{
d->nodes = value;
}

View File

@ -34,9 +34,7 @@
#include <QVector>
class QString;
enum class Contour : char { OpenContour, CloseContour };
enum class EquidistantType : char { OpenEquidistant, CloseEquidistant };
class VDetailData;
/**
* @brief The VDetail class for path of object (points, arcs, splines).
@ -65,6 +63,7 @@ public:
* @return new detail.
*/
VDetail &operator=(const VDetail &detail);
~VDetail();
/**
* @brief append append in the end of list node.
* @param node new node.
@ -224,38 +223,7 @@ public:
*/
QList<quint32> Missing(const VDetail &det) const;
private:
/**
* @brief _id id detail.
*/
quint32 _id;
/**
* @brief nodes list detail nodes.
*/
QVector<VNodeDetail> nodes;
/**
* @brief name detail name.
*/
QString name;
/**
* @brief mx bias x axis.
*/
qreal mx;
/**
* @brief my bias y axis.
*/
qreal my;
/**
* @brief seamAllowance status seamAllowance detail.
*/
bool seamAllowance;
/**
* @brief closed status equdistant detail.
*/
bool closed;
/**
* @brief width value seamAllowance in mm.
*/
qreal width;
QSharedDataPointer<VDetailData> d;
/**
* @brief listNodePoint return list nodes only with points.
* @return list points node.
@ -267,87 +235,7 @@ private:
* @param id object (arc, point, spline, splinePath) id.
* @return index in list or -1 id can't find.
*/
static ptrdiff_t indexOfNode(const QVector<VNodeDetail> &list, const quint32 &id);
static int indexOfNode(const QVector<VNodeDetail> &list, const quint32 &id);
};
inline void VDetail::append(const VNodeDetail &node)
{
nodes.append(node);
}
inline qint32 VDetail::CountNode() const
{
return nodes.size();
}
inline QString VDetail::getName() const
{
return name;
}
inline void VDetail::setName(const QString &value)
{
name = value;
}
inline qreal VDetail::getMx() const
{
return mx;
}
inline void VDetail::setMx(const qreal &value)
{
mx = value;
}
inline qreal VDetail::getMy() const
{
return my;
}
inline void VDetail::setMy(const qreal &value)
{
my = value;
}
inline bool VDetail::getSeamAllowance() const
{
return seamAllowance;
}
inline void VDetail::setSeamAllowance(bool value)
{
seamAllowance = value;
}
inline bool VDetail::getClosed() const
{
return closed;
}
inline void VDetail::setClosed(bool value)
{
closed = value;
}
inline qreal VDetail::getWidth() const
{
return width;
}
inline void VDetail::setWidth(const qreal &value)
{
width = value;
}
inline QVector<VNodeDetail> VDetail::getNodes() const
{
return nodes;
}
inline void VDetail::setNodes(const QVector<VNodeDetail> &value)
{
nodes = value;
}
#endif // VDETAIL_H

View File

@ -0,0 +1,89 @@
/************************************************************************
**
** @file vdetail_p.h
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 20 8, 2014
**
** @brief
** @copyright
** This source code is part of the Valentine project, a pattern making
** program, whose allow create and modeling patterns of clothing.
** Copyright (C) 2014 Valentina project
** <https://bitbucket.org/dismine/valentina> All Rights Reserved.
**
** Valentina is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** Valentina is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
**
*************************************************************************/
#ifndef VDETAIL_P_H
#define VDETAIL_P_H
#include <QSharedData>
#include "../options.h"
#include "vnodedetail.h"
class VDetailData : public QSharedData
{
public:
VDetailData()
:_id(NULL_ID), nodes(QVector<VNodeDetail>()), name(QString()), mx(0), my(0), seamAllowance(true), closed(true),
width(0)
{}
VDetailData(const QString &name, const QVector<VNodeDetail> &nodes)
:_id(NULL_ID), nodes(nodes), name(name), mx(0), my(0), seamAllowance(true), closed(true), width(0)
{}
VDetailData(const VDetailData &detail)
:QSharedData(detail), _id(NULL_ID), nodes(detail.nodes), name(detail.name), mx(detail.mx), my(detail.my),
seamAllowance(detail.seamAllowance), closed(detail.closed), width(detail.width)
{}
~VDetailData() {}
/**
* @brief _id id detail.
*/
quint32 _id;
/**
* @brief nodes list detail nodes.
*/
QVector<VNodeDetail> nodes;
/**
* @brief name detail name.
*/
QString name;
/**
* @brief mx bias x axis.
*/
qreal mx;
/**
* @brief my bias y axis.
*/
qreal my;
/**
* @brief seamAllowance status seamAllowance detail.
*/
bool seamAllowance;
/**
* @brief closed status equdistant detail.
*/
bool closed;
/**
* @brief width value seamAllowance in mm.
*/
qreal width;
};
#endif // VDETAIL_P_H

View File

@ -76,6 +76,8 @@ enum class Draw : char { Calculation, Modeling };
enum class Unit : char { Mm, Cm, Inch };
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 GHeights : unsigned char { ALL,
H92=92, H98=98, H104=104, H110=110, H116=116, H122=122, H128=128, H134=134,