From a58a479db556e20a79fe0a5e3789a59723bec146 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Tue, 31 Jan 2017 16:26:28 +0200 Subject: [PATCH] Refactor VPiece class. Instead of method AppendInternalPath() use overloaded getter. --HG-- branch : feature --- src/libs/vpatterndb/vpiece.cpp | 28 +++++++++++++++---- src/libs/vpatterndb/vpiece.h | 8 ++++-- src/libs/vpatterndb/vpiece_p.h | 3 ++ .../dialogs/tools/dialogseamallowance.cpp | 10 +++---- .../tools/nodeDetails/vtoolpiecepath.cpp | 8 ++---- src/libs/vtools/tools/vtoolseamallowance.cpp | 12 ++++---- src/libs/vtools/tools/vtooluniondetails.cpp | 28 +++++++------------ 7 files changed, 53 insertions(+), 44 deletions(-) diff --git a/src/libs/vpatterndb/vpiece.cpp b/src/libs/vpatterndb/vpiece.cpp index 704921167..5a0896270 100644 --- a/src/libs/vpatterndb/vpiece.cpp +++ b/src/libs/vpatterndb/vpiece.cpp @@ -304,6 +304,12 @@ QVector VPiece::GetInternalPaths() const return d->m_internalPaths; } +//--------------------------------------------------------------------------------------------------------------------- +QVector &VPiece::GetInternalPaths() +{ + return d->m_internalPaths; +} + //--------------------------------------------------------------------------------------------------------------------- void VPiece::SetInternalPaths(const QVector &iPaths) { @@ -311,13 +317,13 @@ void VPiece::SetInternalPaths(const QVector &iPaths) } //--------------------------------------------------------------------------------------------------------------------- -void VPiece::AppendInternalPath(quint32 path) +QVector VPiece::GetCustomSARecords() const { - d->m_internalPaths.append(path); + return d->m_customSARecords; } //--------------------------------------------------------------------------------------------------------------------- -QVector VPiece::GetCustomSARecords() const +QVector &VPiece::GetCustomSARecords() { return d->m_customSARecords; } @@ -329,9 +335,21 @@ void VPiece::SetCustomSARecords(const QVector &records) } //--------------------------------------------------------------------------------------------------------------------- -void VPiece::AppendCustomSARecord(const CustomSARecord &record) +QVector VPiece::GetPins() const { - d->m_customSARecords.append(record); + return d->m_pins; +} + +//--------------------------------------------------------------------------------------------------------------------- +QVector &VPiece::GetPins() +{ + return d->m_pins; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPiece::SetPins(const QVector &pins) +{ + d->m_pins = pins; } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vpatterndb/vpiece.h b/src/libs/vpatterndb/vpiece.h index 111d368c7..c721d0a17 100644 --- a/src/libs/vpatterndb/vpiece.h +++ b/src/libs/vpatterndb/vpiece.h @@ -85,12 +85,16 @@ public: void SetFormulaSAWidth(const QString &formula, qreal value); QVector GetInternalPaths() const; + QVector &GetInternalPaths(); void SetInternalPaths(const QVector &iPaths); - void AppendInternalPath(quint32 path); QVector GetCustomSARecords() const; + QVector &GetCustomSARecords(); void SetCustomSARecords(const QVector &records); - void AppendCustomSARecord(const CustomSARecord &record); + + QVector GetPins() const; + QVector &GetPins(); + void SetPins(const QVector &pins); QVector MissingNodes(const VPiece &det) const; QVector MissingCSAPath(const VPiece &det) const; diff --git a/src/libs/vpatterndb/vpiece_p.h b/src/libs/vpatterndb/vpiece_p.h index f937e8488..cc28158eb 100644 --- a/src/libs/vpatterndb/vpiece_p.h +++ b/src/libs/vpatterndb/vpiece_p.h @@ -54,6 +54,7 @@ public: m_united(false), m_customSARecords(), m_internalPaths(), + m_pins(), m_ppData(), m_piPatternInfo(), m_glGrainline(), @@ -69,6 +70,7 @@ public: m_united(detail.m_united), m_customSARecords(detail.m_customSARecords), m_internalPaths(detail.m_internalPaths), + m_pins(detail.m_pins), m_ppData(detail.m_ppData), m_piPatternInfo(detail.m_piPatternInfo), m_glGrainline(detail.m_glGrainline), @@ -88,6 +90,7 @@ public: QVector m_customSARecords; QVector m_internalPaths; + QVector m_pins; /** @brief Pattern piece data */ VPatternPieceData m_ppData; diff --git a/src/libs/vtools/dialogs/tools/dialogseamallowance.cpp b/src/libs/vtools/dialogs/tools/dialogseamallowance.cpp index eec2e4cc1..5ff72a5dc 100644 --- a/src/libs/vtools/dialogs/tools/dialogseamallowance.cpp +++ b/src/libs/vtools/dialogs/tools/dialogseamallowance.cpp @@ -127,18 +127,16 @@ void DialogSeamAllowance::SetPiece(const VPiece &piece) ui->listWidgetCustomSA->blockSignals(true); ui->listWidgetCustomSA->clear(); - const QVector records = piece.GetCustomSARecords(); - for (int i = 0; i < records.size(); ++i) + for (int i = 0; i < piece.GetCustomSARecords().size(); ++i) { - NewCustomSA(records.at(i)); + NewCustomSA(piece.GetCustomSARecords().at(i)); } ui->listWidgetCustomSA->blockSignals(false); ui->listWidgetInternalPaths->clear(); - const QVector iPaths = piece.GetInternalPaths(); - for (int i = 0; i < iPaths.size(); ++i) + for (int i = 0; i < piece.GetInternalPaths().size(); ++i) { - NewInternalPath(iPaths.at(i)); + NewInternalPath(piece.GetInternalPaths().at(i)); } ui->comboBoxStartPoint->blockSignals(true); diff --git a/src/libs/vtools/tools/nodeDetails/vtoolpiecepath.cpp b/src/libs/vtools/tools/nodeDetails/vtoolpiecepath.cpp index 0a3cb028c..ba50869a1 100644 --- a/src/libs/vtools/tools/nodeDetails/vtoolpiecepath.cpp +++ b/src/libs/vtools/tools/nodeDetails/vtoolpiecepath.cpp @@ -211,18 +211,14 @@ void VToolPiecePath::AddToFile() if (path.GetType() == PiecePathType::InternalPath) { - QVector iPaths = newDet.GetInternalPaths(); - iPaths.append(id); - newDet.SetInternalPaths(iPaths); + newDet.GetInternalPaths().append(id); } else if (path.GetType() == PiecePathType::CustomSeamAllowance) { CustomSARecord record; record.path = id; - QVector records = newDet.GetCustomSARecords(); - records.append(record); - newDet.SetCustomSARecords(records); + newDet.GetCustomSARecords().append(record); } SavePieceOptions *saveCommand = new SavePieceOptions(oldDet, newDet, doc, m_pieceId); diff --git a/src/libs/vtools/tools/vtoolseamallowance.cpp b/src/libs/vtools/tools/vtoolseamallowance.cpp index 7a13ae281..4aa42288f 100644 --- a/src/libs/vtools/tools/vtoolseamallowance.cpp +++ b/src/libs/vtools/tools/vtoolseamallowance.cpp @@ -1116,25 +1116,23 @@ void VToolSeamAllowance::InitNodes(const VPiece &detail, VMainGraphicsScene *sce //--------------------------------------------------------------------------------------------------------------------- void VToolSeamAllowance::InitCSAPaths(const VPiece &detail) { - QVector records = detail.GetCustomSARecords(); - for (int i = 0; i < records.size(); ++i) + for (int i = 0; i < detail.GetCustomSARecords().size(); ++i) { - doc->IncrementReferens(records.at(i).path); + doc->IncrementReferens(detail.GetCustomSARecords().at(i).path); } } //--------------------------------------------------------------------------------------------------------------------- void VToolSeamAllowance::InitInternalPaths(const VPiece &detail) { - QVector records = detail.GetInternalPaths(); - for (int i = 0; i < records.size(); ++i) + for (int i = 0; i < detail.GetInternalPaths().size(); ++i) { - VToolPiecePath *tool = qobject_cast(doc->getTool(records.at(i))); + VToolPiecePath *tool = qobject_cast(doc->getTool(detail.GetInternalPaths().at(i))); SCASSERT(tool != nullptr); tool->setParentItem(this); tool->SetParentType(ParentType::Item); tool->show(); - doc->IncrementReferens(records.at(i)); + doc->IncrementReferens(detail.GetInternalPaths().at(i)); } } diff --git a/src/libs/vtools/tools/vtooluniondetails.cpp b/src/libs/vtools/tools/vtooluniondetails.cpp index 22d1c157e..ebed39f2d 100644 --- a/src/libs/vtools/tools/vtooluniondetails.cpp +++ b/src/libs/vtools/tools/vtooluniondetails.cpp @@ -958,12 +958,10 @@ void CreateUnitedDetailCSA(VPiece &newDetail, const VPiece &d, QVector const QString &drawName, const VToolUnionDetailsInitData &initData, qreal dx, qreal dy, quint32 pRotate, qreal angle) { - QVector newList = newDetail.GetCustomSARecords(); - const QVector oldList = d.GetCustomSARecords(); QVector nodeChildren; - for(int i=0; i < oldList.size(); ++i) + for(int i=0; i < d.GetCustomSARecords().size(); ++i) { - CustomSARecord record = oldList.at(i); + CustomSARecord record = d.GetCustomSARecords().at(i); const VPiecePath path = initData.data->GetPiecePath(record.path); VPiecePath newPath = path; newPath.Clear();//Clear nodes @@ -975,21 +973,19 @@ void CreateUnitedDetailCSA(VPiece &newDetail, const VPiece &d, QVector VToolPiecePath::Create(idPath, newPath, NULL_ID, initData.scene, initData.doc, initData.data, initData.parse, Source::FromTool, drawName, id); record.path = idPath; - newList.append(record); + newDetail.GetCustomSARecords().append(record); nodeChildren.prepend(idPath); } children += nodeChildren; - newDetail.SetCustomSARecords(newList); } //--------------------------------------------------------------------------------------------------------------------- void CreateUnitedCSA(VPiece &newDetail, const VPiece &d1, const VPiece &d2, quint32 id, const QString &drawName, const VToolUnionDetailsInitData &initData, qreal dx, qreal dy, quint32 pRotate, qreal angle) { - const QVector d1Records = d1.GetCustomSARecords(); - for (int i = 0; i < d1Records.size(); ++i) + for (int i = 0; i < d1.GetCustomSARecords().size(); ++i) { - newDetail.AppendCustomSARecord(d1Records.at(i)); + newDetail.GetCustomSARecords().append(d1.GetCustomSARecords().at(i)); } QVector children; @@ -1004,12 +1000,10 @@ void CreateUnitedDetailInternalPaths(VPiece &newDetail, const VPiece &d, QVector const QString &drawName, const VToolUnionDetailsInitData &initData, qreal dx, qreal dy, quint32 pRotate, qreal angle) { - QVector newList = newDetail.GetInternalPaths(); - const QVector oldList = d.GetInternalPaths(); QVector nodeChildren; - for(int i=0; i < oldList.size(); ++i) + for(int i=0; i < d.GetInternalPaths().size(); ++i) { - const VPiecePath path = initData.data->GetPiecePath(oldList.at(i)); + const VPiecePath path = initData.data->GetPiecePath(d.GetInternalPaths().at(i)); VPiecePath newPath = path; newPath.Clear();//Clear nodes @@ -1020,11 +1014,10 @@ void CreateUnitedDetailInternalPaths(VPiece &newDetail, const VPiece &d, QVector const quint32 idPath = initData.data->AddPiecePath(newPath); VToolPiecePath::Create(idPath, newPath, NULL_ID, initData.scene, initData.doc, initData.data, initData.parse, Source::FromTool, drawName, id); - newList.append(idPath); + newDetail.GetInternalPaths().append(idPath); nodeChildren.prepend(idPath); } children += nodeChildren; - newDetail.SetInternalPaths(newList); } //--------------------------------------------------------------------------------------------------------------------- @@ -1032,10 +1025,9 @@ void CreateUnitedInternalPaths(VPiece &newDetail, const VPiece &d1, const VPiece const QString &drawName, const VToolUnionDetailsInitData &initData, qreal dx, qreal dy, quint32 pRotate, qreal angle) { - const QVector d1Internal = d1.GetInternalPaths(); - for (int i = 0; i < d1Internal.size(); ++i) + for (int i = 0; i < d1.GetInternalPaths().size(); ++i) { - newDetail.AppendInternalPath(d1Internal.at(i)); + newDetail.GetInternalPaths().append(d1.GetInternalPaths().at(i)); } QVector children;