From 37173fb0e4f9b838e5c8b71009728d8f68bf6cee Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Tue, 8 Nov 2016 12:53:14 +0200 Subject: [PATCH] VPiece class. Added members for storing a piece position. --HG-- branch : feature --- src/libs/vpatterndb/vpiece.cpp | 58 ++++++++++++++++++++++++---------- src/libs/vpatterndb/vpiece.h | 8 ++++- src/libs/vpatterndb/vpiece_p.h | 13 ++++++-- 3 files changed, 58 insertions(+), 21 deletions(-) diff --git a/src/libs/vpatterndb/vpiece.cpp b/src/libs/vpatterndb/vpiece.cpp index 6c7c31709..5a44c47ae 100644 --- a/src/libs/vpatterndb/vpiece.cpp +++ b/src/libs/vpatterndb/vpiece.cpp @@ -69,7 +69,7 @@ VPiece::~VPiece() */ void VPiece::Append(const VPieceNode &node) { - d->nodes.append(node); + d->m_nodes.append(node); } //--------------------------------------------------------------------------------------------------------------------- @@ -83,7 +83,7 @@ void VPiece::Clear() /** @brief ClearNodes clear list of nodes. */ void VPiece::ClearNodes() { - d->nodes.clear(); + d->m_nodes.clear(); } //--------------------------------------------------------------------------------------------------------------------- @@ -91,9 +91,9 @@ void VPiece::ClearNodes() * @brief CountNode return count nodes. * @return count. */ -qint32 VPiece::CountNode() const +qint32 VPiece::CountNodes() const { - return d->nodes.size(); + return d->m_nodes.size(); } //--------------------------------------------------------------------------------------------------------------------- @@ -104,7 +104,7 @@ qint32 VPiece::CountNode() const */ VPieceNode &VPiece::operator [](int indx) { - return d->nodes[indx]; + return d->m_nodes[indx]; } //--------------------------------------------------------------------------------------------------------------------- @@ -115,7 +115,7 @@ VPieceNode &VPiece::operator [](int indx) */ const VPieceNode &VPiece::at(int indx) const { - return d->nodes.at(indx); + return d->m_nodes.at(indx); } //--------------------------------------------------------------------------------------------------------------------- @@ -125,7 +125,7 @@ const VPieceNode &VPiece::at(int indx) const */ QVector VPiece::GetNodes() const { - return d->nodes; + return d->m_nodes; } //--------------------------------------------------------------------------------------------------------------------- @@ -136,14 +136,14 @@ QVector VPiece::GetNodes() const // cppcheck-suppress unusedFunction void VPiece::SetNodes(const QVector &nodes) { - d->nodes = nodes; + d->m_nodes = nodes; } //--------------------------------------------------------------------------------------------------------------------- QVector VPiece::MainPathPoints(const VContainer *data) const { QVector points; - for (int i = 0; i < CountNode(); ++i) + for (int i = 0; i < CountNodes(); ++i) { switch (at(i).GetTypeTool()) { @@ -179,7 +179,7 @@ QVector VPiece::MainPathPoints(const VContainer *data) const QVector VPiece::MainPathNodePoints(const VContainer *data) const { QVector points; - for (int i = 0; i < CountNode(); ++i) + for (int i = 0; i < CountNodes(); ++i) { switch (at(i).GetTypeTool()) { @@ -220,10 +220,34 @@ QPainterPath VPiece::MainPathPath(const VContainer *data) const return path; } +//--------------------------------------------------------------------------------------------------------------------- +qreal VPiece::GetMx() const +{ + return d->m_mx; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPiece::SetMx(qreal value) +{ + d->m_mx = value; +} + +//--------------------------------------------------------------------------------------------------------------------- +qreal VPiece::GetMy() const +{ + return d->m_my; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPiece::SetMy(qreal value) +{ + d->m_my = value; +} + //--------------------------------------------------------------------------------------------------------------------- QPointF VPiece::StartSegment(const VContainer *data, const int &i, bool reverse) const { - if (i < 0 && i > CountNode()-1) + if (i < 0 && i > CountNodes()-1) { return QPointF(); } @@ -237,13 +261,13 @@ QPointF VPiece::StartSegment(const VContainer *data, const int &i, bool reverse) } QPointF begin = points.first(); - if (CountNode() > 1) + if (CountNodes() > 1) { if (i == 0) { - if (at(CountNode()-1).GetTypeTool() == Tool::NodePoint) + if (at(CountNodes()-1).GetTypeTool() == Tool::NodePoint) { - begin = *data->GeometricObject(at(CountNode()-1).GetId()); + begin = *data->GeometricObject(at(CountNodes()-1).GetId()); } } else @@ -260,7 +284,7 @@ QPointF VPiece::StartSegment(const VContainer *data, const int &i, bool reverse) //--------------------------------------------------------------------------------------------------------------------- QPointF VPiece::EndSegment(const VContainer *data, const int &i, bool reverse) const { - if (i < 0 && i > CountNode()-1) + if (i < 0 && i > CountNodes()-1) { return QPointF(); } @@ -274,9 +298,9 @@ QPointF VPiece::EndSegment(const VContainer *data, const int &i, bool reverse) c } QPointF end = points.last(); - if (CountNode() > 2) + if (CountNodes() > 2) { - if (i == CountNode() - 1) + if (i == CountNodes() - 1) { if (at(0).GetTypeTool() == Tool::NodePoint) { diff --git a/src/libs/vpatterndb/vpiece.h b/src/libs/vpatterndb/vpiece.h index 13541f829..4ae3a267a 100644 --- a/src/libs/vpatterndb/vpiece.h +++ b/src/libs/vpatterndb/vpiece.h @@ -52,7 +52,7 @@ public: void Append(const VPieceNode &node); void Clear(); void ClearNodes(); - qint32 CountNode() const; + qint32 CountNodes() const; VPieceNode & operator[](int indx); const VPieceNode & at ( int indx ) const; @@ -65,6 +65,12 @@ public: QPainterPath MainPathPath(const VContainer *data) const; + qreal GetMx() const; + void SetMx(qreal value); + + qreal GetMy() const; + void SetMy(qreal value); + private: QSharedDataPointer d; diff --git a/src/libs/vpatterndb/vpiece_p.h b/src/libs/vpatterndb/vpiece_p.h index f673dc340..79001e36a 100644 --- a/src/libs/vpatterndb/vpiece_p.h +++ b/src/libs/vpatterndb/vpiece_p.h @@ -42,18 +42,25 @@ class VPieceData : public QSharedData { public: VPieceData() - : nodes() + : m_nodes(), + m_mx(0), + m_my(0) {} VPieceData(const VPieceData &detail) : QSharedData(detail), - nodes(detail.nodes) + m_nodes(detail.m_nodes), + m_mx(detail.m_mx), + m_my(detail.m_my) {} ~VPieceData(); /** @brief nodes list detail nodes. */ - QVector nodes; + QVector m_nodes; + + qreal m_mx; + qreal m_my; private: VPieceData &operator=(const VPieceData &) Q_DECL_EQ_DELETE;