From 4ad2c854b2e2dc4777d030e675d3fc222016b2da Mon Sep 17 00:00:00 2001 From: Ronan Le Tiec Date: Thu, 25 Jun 2020 14:17:31 +0200 Subject: [PATCH] VPPiece now inherits form VLayoutPiece --- src/app/puzzle/vpcarrouselpiece.cpp | 4 +- src/app/puzzle/vpgraphicspiece.cpp | 17 ++-- src/app/puzzle/vpmainwindow.cpp | 23 ++--- src/app/puzzle/vppiece.cpp | 113 +++++----------------- src/app/puzzle/vppiece.h | 97 ++----------------- src/app/puzzle/xml/vplayoutfilereader.cpp | 2 +- src/app/puzzle/xml/vplayoutfilewriter.cpp | 2 +- 7 files changed, 51 insertions(+), 207 deletions(-) diff --git a/src/app/puzzle/vpcarrouselpiece.cpp b/src/app/puzzle/vpcarrouselpiece.cpp index 93b737238..c5e651546 100644 --- a/src/app/puzzle/vpcarrouselpiece.cpp +++ b/src/app/puzzle/vpcarrouselpiece.cpp @@ -76,10 +76,10 @@ void VPCarrouselPiece::RefreshSelection() //--------------------------------------------------------------------------------------------------------------------- QIcon VPCarrouselPiece::CreatePieceIcon(const QSize &size) const { - QVector points = m_piece->GetSeamLine(); + QVector points = m_piece->GetMappedContourPoints(); // seamline if(points.isEmpty()) { - points = m_piece->GetCuttingLine(); + points = m_piece->GetMappedSeamAllowancePoints(); // cutting line } QPolygonF shape(points); diff --git a/src/app/puzzle/vpgraphicspiece.cpp b/src/app/puzzle/vpgraphicspiece.cpp index 4bf150701..d369e98ea 100644 --- a/src/app/puzzle/vpgraphicspiece.cpp +++ b/src/app/puzzle/vpgraphicspiece.cpp @@ -74,7 +74,7 @@ void VPGraphicsPiece::Init() setCursor(QCursor(Qt::OpenHandCursor)); // initialises the seam line - QVector seamLinePoints = m_piece->GetSeamLine(); + QVector seamLinePoints = m_piece->GetMappedContourPoints(); if(!seamLinePoints.isEmpty()) { m_seamLine.moveTo(seamLinePoints.first()); @@ -83,7 +83,7 @@ void VPGraphicsPiece::Init() } // initiliases the cutting line - QVector cuttingLinepoints = m_piece->GetCuttingLine(); + QVector cuttingLinepoints = m_piece->GetMappedSeamAllowancePoints(); if(!cuttingLinepoints.isEmpty()) { m_cuttingLine.moveTo(cuttingLinepoints.first()); @@ -92,12 +92,15 @@ void VPGraphicsPiece::Init() } // initialises the grainline - QVector grainLinepoints = m_piece->GetGrainline(); - if(!grainLinepoints.isEmpty()) + if(m_piece->IsGrainlineEnabled()) { - m_grainline.moveTo(grainLinepoints.first()); - for (int i = 1; i < grainLinepoints.size(); ++i) - m_grainline.lineTo(grainLinepoints.at(i)); + QVector grainLinepoints = m_piece->GetGrainline(); + if(!grainLinepoints.isEmpty()) + { + m_grainline.moveTo(grainLinepoints.first()); + for (int i = 1; i < grainLinepoints.size(); ++i) + m_grainline.lineTo(grainLinepoints.at(i)); + } } // TODO : initialises the other elements labels, passmarks etc. diff --git a/src/app/puzzle/vpmainwindow.cpp b/src/app/puzzle/vpmainwindow.cpp index a2bd21750..d6dae266a 100644 --- a/src/app/puzzle/vpmainwindow.cpp +++ b/src/app/puzzle/vpmainwindow.cpp @@ -155,12 +155,6 @@ void VPMainWindow::ImportRawLayouts(const QStringList &rawLayouts) { VLayoutPiece rawPiece = data.pieces.at(i); - // We translate the piece, so that the origin of the bounding rect of the piece is at (0,0) - // It makes positioning later on easier. - QRectF boundingRect = rawPiece.DetailBoundingRect(); - QPointF topLeft = boundingRect.topLeft(); - rawPiece.Translate(-topLeft.x(), -topLeft.y()); - // TODO / FIXME: make a few tests, on the data to check for validity. If not @@ -192,19 +186,14 @@ void VPMainWindow::ImportRawLayouts(const QStringList &rawLayouts) //--------------------------------------------------------------------------------------------------------------------- VPPiece* VPMainWindow::CreatePiece(const VLayoutPiece &rawPiece) { - VPPiece *piece = new VPPiece(); - piece->SetName(rawPiece.GetName()); - piece->SetUuid(rawPiece.GetUUID()); + VPPiece *piece = new VPPiece(rawPiece); - piece->SetCuttingLine(rawPiece.GetMappedSeamAllowancePoints()); - piece->SetSeamLine(rawPiece.GetMappedContourPoints()); - piece->SetIsGrainlineEnabled(rawPiece.IsGrainlineEnabled()); - if(rawPiece.IsGrainlineEnabled()) - { - piece->SetGrainlineAngle(rawPiece.GrainlineAngle()); - piece->SetGrainline(rawPiece.GetGrainline()); - } + // cutting line : GetMappedSeamAllowancePoints(); + // seamline : GetMappedContourPoints(); + + // rawPiece.IsGrainlineEnabled() , GrainlineAngle , GetGrainline + // TODO : set all the information we need for the piece! diff --git a/src/app/puzzle/vppiece.cpp b/src/app/puzzle/vppiece.cpp index ed3df5899..f1d06052f 100644 --- a/src/app/puzzle/vppiece.cpp +++ b/src/app/puzzle/vppiece.cpp @@ -44,64 +44,29 @@ VPPiece::VPPiece() } +//--------------------------------------------------------------------------------------------------------------------- +VPPiece::VPPiece(VLayoutPiece layoutPiece): VLayoutPiece(layoutPiece) +{ + // Resets the translation of the matrix + QTransform matrix = GetMatrix(); + matrix.translate(-matrix.dx() ,-matrix.dy()); + SetMatrix(matrix); + + // then translate the piece so that the top left corner of the bouding rect of the piece is at the position + // (0,0) in the sheet coordinate system + QRectF boundingRect = DetailBoundingRect(); + m_offset = boundingRect.topLeft(); + matrix = GetMatrix(); + matrix.translate(-m_offset.x() ,-m_offset.y()); + SetMatrix(matrix); +} + //--------------------------------------------------------------------------------------------------------------------- VPPiece::~VPPiece() { } - -//--------------------------------------------------------------------------------------------------------------------- -QString VPPiece::GetName() const -{ - return m_name; -} - - -//--------------------------------------------------------------------------------------------------------------------- -void VPPiece::SetName(const QString &name) -{ - m_name = name; -} - - -//--------------------------------------------------------------------------------------------------------------------- -QUuid VPPiece::GetUuid() const -{ - return m_uuid; -} - -//--------------------------------------------------------------------------------------------------------------------- -void VPPiece::SetUuid(const QUuid &uuid) -{ - m_uuid = uuid; -} - - -//--------------------------------------------------------------------------------------------------------------------- -QVector VPPiece::GetCuttingLine() const -{ - return m_cuttingLine; -} - -//--------------------------------------------------------------------------------------------------------------------- -void VPPiece::SetCuttingLine(const QVector &cuttingLine) -{ - m_cuttingLine = cuttingLine; -} - -//--------------------------------------------------------------------------------------------------------------------- -QVector VPPiece::GetSeamLine() const -{ - return m_seamLine; -} - -//--------------------------------------------------------------------------------------------------------------------- -void VPPiece::SetSeamLine(const QVector &seamLine) -{ - m_seamLine = seamLine; -} - //--------------------------------------------------------------------------------------------------------------------- bool VPPiece::GetShowSeamLine() const { @@ -133,7 +98,9 @@ void VPPiece::SetPieceMirrored(bool value) //--------------------------------------------------------------------------------------------------------------------- void VPPiece::SetPosition(QPointF point) { - m_transform.translate(point.x() - m_transform.dx(), point.y() - m_transform.dy()); + QTransform matrix = GetMatrix(); + matrix.translate(point.x() - matrix.dx() - m_offset.x(), point.y() - matrix.dy() - m_offset.y()); + SetMatrix(matrix); emit PositionChanged(); } @@ -141,7 +108,7 @@ void VPPiece::SetPosition(QPointF point) //--------------------------------------------------------------------------------------------------------------------- QPointF VPPiece::GetPosition() { - return QPointF(m_transform.dx(), m_transform.dy()); + return QPointF(GetMatrix().dx() + m_offset.x(), GetMatrix().dy()+m_offset.y()); } //--------------------------------------------------------------------------------------------------------------------- @@ -171,6 +138,7 @@ void VPPiece::SetRotation(qreal angle) } } + //--------------------------------------------------------------------------------------------------------------------- qreal VPPiece::GetRotation() { @@ -206,41 +174,6 @@ bool VPPiece::GetIsSelected() return m_isSelected; } -//--------------------------------------------------------------------------------------------------------------------- -void VPPiece::SetIsGrainlineEnabled(bool value) -{ - m_isGrainlineEnabled = value; -} - -//--------------------------------------------------------------------------------------------------------------------- -bool VPPiece::GetIsGrainlineEnabled() -{ - return m_isGrainlineEnabled; -} - -//--------------------------------------------------------------------------------------------------------------------- -void VPPiece::SetGrainlineAngle(qreal value) -{ - m_grainlineAngle = value; -} - -//--------------------------------------------------------------------------------------------------------------------- -qreal VPPiece::GetGrainlineAngle() -{ - return m_grainlineAngle; -} -//--------------------------------------------------------------------------------------------------------------------- -void VPPiece::SetGrainline(QVector grainline) -{ - m_grainline = grainline; -} - -//--------------------------------------------------------------------------------------------------------------------- -QVector VPPiece::GetGrainline() -{ - return m_grainline; -} - //--------------------------------------------------------------------------------------------------------------------- VPPieceList* VPPiece::GetPieceList() { @@ -255,5 +188,3 @@ void VPPiece::SetPieceList(VPPieceList* pieceList) m_pieceList = pieceList; } } - - diff --git a/src/app/puzzle/vppiece.h b/src/app/puzzle/vppiece.h index d536c569f..7a983a77a 100644 --- a/src/app/puzzle/vppiece.h +++ b/src/app/puzzle/vppiece.h @@ -33,61 +33,19 @@ #include #include +#include "../vlayout/vlayoutpiece.h" + class VPPieceList; -class VPPiece : public QObject +class VPPiece : public QObject, public VLayoutPiece { Q_OBJECT public: VPPiece(); + VPPiece(VLayoutPiece layoutPiece); + ~VPPiece(); - /** - * @brief GetName Returns the name of the piece - * @return the piece's name - */ - QString GetName() const; - - /** - * @brief SetName Sets the piece's name to the given name - * @param name new name of the piece - */ - void SetName(const QString &name); - - /** - * @brief GetUuid Returns the uuid of the piece - * @return the uuid of the piece - */ - QUuid GetUuid() const; - - /** - * @brief SetUuid Sets the uuid of the piece to the given value - */ - void SetUuid(const QUuid &uuid); - - /** - * @brief GetCuttingLine Returns the vector points of the cutting line - * @return the vector points of the cutting line - */ - QVector GetCuttingLine() const; - - /** - * @brief SetCuttingLine Sets the vector points of the cutting line to the given value - * @param cuttingLine the new vector points for the cutting line - */ - void SetCuttingLine(const QVector &cuttingLine); - - /** - * @brief GetSeamLine Returns the vector points of the seam line - * @return the vector points of the seam line - */ - QVector GetSeamLine() const; - - /** - * @brief SetSeamLine Sets the vector points of the seam line to the given value - * @param seamLine the new vector points for the seam line - */ - void SetSeamLine(const QVector &seamLine); /** * @brief GetShowSeamLine returns wether the seam line of the piece has to be shown or not @@ -137,43 +95,6 @@ public: */ qreal GetRotation(); - /** - * @brief SetIsGrainlineEnabled Wether the piece has a grainline or not - * @param value true or false - */ - void SetIsGrainlineEnabled(bool value); - - /** - * @brief GetIsGrainlineEnabled Returns wether the grainline is enabled for this piece - * @return true if enabled - */ - bool GetIsGrainlineEnabled(); - - /** - * @brief SetGrainlineAngle Sets the angle of the grainline - * @param value - */ - void SetGrainlineAngle(qreal value); - - /** - * @brief GetGrainlineAngle Returns the angle of the grainline for this piece - * @return the angle - */ - qreal GetGrainlineAngle(); - - /** - * @brief SetGrainline Sets the grainline to the given vector of points - * @param grainline the grainline - */ - void SetGrainline(QVector grainline); - - /** - * @brief GetGrainline Returns the grainline for this piece - * @return the vector - */ - QVector GetGrainline(); - - /** * @brief SetIsSelected Sets wether the piece is selected * @param value true if the piece is selected @@ -225,12 +146,12 @@ signals: */ void PropertiesChanged(); + + private: Q_DISABLE_COPY(VPPiece) - QUuid m_uuid{QUuid()}; - QString m_name{QString()}; - QVector m_cuttingLine{QVector()}; - QVector m_seamLine{QVector()}; + + QPointF m_offset{QPointF()}; QVector m_grainline{QVector()}; bool m_isGrainlineEnabled{false}; diff --git a/src/app/puzzle/xml/vplayoutfilereader.cpp b/src/app/puzzle/xml/vplayoutfilereader.cpp index 233bf6c65..ac5cea16d 100644 --- a/src/app/puzzle/xml/vplayoutfilereader.cpp +++ b/src/app/puzzle/xml/vplayoutfilereader.cpp @@ -241,7 +241,7 @@ void VPLayoutFileReader::ReadPiece(VPPiece *piece) piece->SetName(ReadAttributeString(attribs, ML::AttrName, tr("Piece"))); QString uuidStr = ReadAttributeString(attribs, ML::AttrID, QUuid().toString());// FIXME: is that correct to have a default value here? - piece->SetUuid(QUuid(uuidStr)); + piece->SetUUID(QUuid(uuidStr)); bool showSeamline = ReadAttributeBool(attribs, ML::AttrShowSeamline, trueStr); piece->SetShowSeamLine(showSeamline); diff --git a/src/app/puzzle/xml/vplayoutfilewriter.cpp b/src/app/puzzle/xml/vplayoutfilewriter.cpp index 327e01aaf..5f2295f41 100644 --- a/src/app/puzzle/xml/vplayoutfilewriter.cpp +++ b/src/app/puzzle/xml/vplayoutfilewriter.cpp @@ -167,7 +167,7 @@ void VPLayoutFileWriter::WritePiece(VPPiece *piece) Q_UNUSED(piece); writeStartElement(ML::TagPiece); - SetAttribute(ML::AttrID, piece->GetUuid().toString()); + SetAttribute(ML::AttrID, piece->GetUUID().toString()); SetAttribute(ML::AttrName, piece->GetName()); SetAttribute(ML::AttrMirrored, piece->GetPieceMirrored()); // TODO / Fixme get the right value SetAttribute(ML::AttrShowSeamline, piece->GetShowSeamLine()); // TODO / Fixme get the right value