VPPiece now inherits form VLayoutPiece

This commit is contained in:
Ronan Le Tiec 2020-06-25 14:17:31 +02:00
parent e419ccfece
commit 4ad2c854b2
7 changed files with 51 additions and 207 deletions

View File

@ -76,10 +76,10 @@ void VPCarrouselPiece::RefreshSelection()
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QIcon VPCarrouselPiece::CreatePieceIcon(const QSize &size) const QIcon VPCarrouselPiece::CreatePieceIcon(const QSize &size) const
{ {
QVector<QPointF> points = m_piece->GetSeamLine(); QVector<QPointF> points = m_piece->GetMappedContourPoints(); // seamline
if(points.isEmpty()) if(points.isEmpty())
{ {
points = m_piece->GetCuttingLine(); points = m_piece->GetMappedSeamAllowancePoints(); // cutting line
} }
QPolygonF shape(points); QPolygonF shape(points);

View File

@ -74,7 +74,7 @@ void VPGraphicsPiece::Init()
setCursor(QCursor(Qt::OpenHandCursor)); setCursor(QCursor(Qt::OpenHandCursor));
// initialises the seam line // initialises the seam line
QVector<QPointF> seamLinePoints = m_piece->GetSeamLine(); QVector<QPointF> seamLinePoints = m_piece->GetMappedContourPoints();
if(!seamLinePoints.isEmpty()) if(!seamLinePoints.isEmpty())
{ {
m_seamLine.moveTo(seamLinePoints.first()); m_seamLine.moveTo(seamLinePoints.first());
@ -83,7 +83,7 @@ void VPGraphicsPiece::Init()
} }
// initiliases the cutting line // initiliases the cutting line
QVector<QPointF> cuttingLinepoints = m_piece->GetCuttingLine(); QVector<QPointF> cuttingLinepoints = m_piece->GetMappedSeamAllowancePoints();
if(!cuttingLinepoints.isEmpty()) if(!cuttingLinepoints.isEmpty())
{ {
m_cuttingLine.moveTo(cuttingLinepoints.first()); m_cuttingLine.moveTo(cuttingLinepoints.first());
@ -92,6 +92,8 @@ void VPGraphicsPiece::Init()
} }
// initialises the grainline // initialises the grainline
if(m_piece->IsGrainlineEnabled())
{
QVector<QPointF> grainLinepoints = m_piece->GetGrainline(); QVector<QPointF> grainLinepoints = m_piece->GetGrainline();
if(!grainLinepoints.isEmpty()) if(!grainLinepoints.isEmpty())
{ {
@ -99,6 +101,7 @@ void VPGraphicsPiece::Init()
for (int i = 1; i < grainLinepoints.size(); ++i) for (int i = 1; i < grainLinepoints.size(); ++i)
m_grainline.lineTo(grainLinepoints.at(i)); m_grainline.lineTo(grainLinepoints.at(i));
} }
}
// TODO : initialises the other elements labels, passmarks etc. // TODO : initialises the other elements labels, passmarks etc.

View File

@ -155,12 +155,6 @@ void VPMainWindow::ImportRawLayouts(const QStringList &rawLayouts)
{ {
VLayoutPiece rawPiece = data.pieces.at(i); 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 // 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* VPMainWindow::CreatePiece(const VLayoutPiece &rawPiece)
{ {
VPPiece *piece = new VPPiece(); VPPiece *piece = new VPPiece(rawPiece);
piece->SetName(rawPiece.GetName());
piece->SetUuid(rawPiece.GetUUID());
piece->SetCuttingLine(rawPiece.GetMappedSeamAllowancePoints());
piece->SetSeamLine(rawPiece.GetMappedContourPoints());
piece->SetIsGrainlineEnabled(rawPiece.IsGrainlineEnabled()); // cutting line : GetMappedSeamAllowancePoints();
if(rawPiece.IsGrainlineEnabled()) // seamline : GetMappedContourPoints();
{
piece->SetGrainlineAngle(rawPiece.GrainlineAngle()); // rawPiece.IsGrainlineEnabled() , GrainlineAngle , GetGrainline
piece->SetGrainline(rawPiece.GetGrainline());
}
// TODO : set all the information we need for the piece! // TODO : set all the information we need for the piece!

View File

@ -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() 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<QPointF> VPPiece::GetCuttingLine() const
{
return m_cuttingLine;
}
//---------------------------------------------------------------------------------------------------------------------
void VPPiece::SetCuttingLine(const QVector<QPointF> &cuttingLine)
{
m_cuttingLine = cuttingLine;
}
//---------------------------------------------------------------------------------------------------------------------
QVector<QPointF> VPPiece::GetSeamLine() const
{
return m_seamLine;
}
//---------------------------------------------------------------------------------------------------------------------
void VPPiece::SetSeamLine(const QVector<QPointF> &seamLine)
{
m_seamLine = seamLine;
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
bool VPPiece::GetShowSeamLine() const bool VPPiece::GetShowSeamLine() const
{ {
@ -133,7 +98,9 @@ void VPPiece::SetPieceMirrored(bool value)
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPPiece::SetPosition(QPointF point) 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(); emit PositionChanged();
} }
@ -141,7 +108,7 @@ void VPPiece::SetPosition(QPointF point)
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QPointF VPPiece::GetPosition() 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() qreal VPPiece::GetRotation()
{ {
@ -206,41 +174,6 @@ bool VPPiece::GetIsSelected()
return m_isSelected; 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<QPointF> grainline)
{
m_grainline = grainline;
}
//---------------------------------------------------------------------------------------------------------------------
QVector<QPointF> VPPiece::GetGrainline()
{
return m_grainline;
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VPPieceList* VPPiece::GetPieceList() VPPieceList* VPPiece::GetPieceList()
{ {
@ -255,5 +188,3 @@ void VPPiece::SetPieceList(VPPieceList* pieceList)
m_pieceList = pieceList; m_pieceList = pieceList;
} }
} }

View File

@ -33,61 +33,19 @@
#include <QPoint> #include <QPoint>
#include <QTransform> #include <QTransform>
#include "../vlayout/vlayoutpiece.h"
class VPPieceList; class VPPieceList;
class VPPiece : public QObject class VPPiece : public QObject, public VLayoutPiece
{ {
Q_OBJECT Q_OBJECT
public: public:
VPPiece(); VPPiece();
VPPiece(VLayoutPiece layoutPiece);
~VPPiece(); ~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<QPointF> 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<QPointF> &cuttingLine);
/**
* @brief GetSeamLine Returns the vector points of the seam line
* @return the vector points of the seam line
*/
QVector<QPointF> 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<QPointF> &seamLine);
/** /**
* @brief GetShowSeamLine returns wether the seam line of the piece has to be shown or not * @brief GetShowSeamLine returns wether the seam line of the piece has to be shown or not
@ -137,43 +95,6 @@ public:
*/ */
qreal GetRotation(); 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<QPointF> grainline);
/**
* @brief GetGrainline Returns the grainline for this piece
* @return the vector
*/
QVector<QPointF> GetGrainline();
/** /**
* @brief SetIsSelected Sets wether the piece is selected * @brief SetIsSelected Sets wether the piece is selected
* @param value true if the piece is selected * @param value true if the piece is selected
@ -225,12 +146,12 @@ signals:
*/ */
void PropertiesChanged(); void PropertiesChanged();
private: private:
Q_DISABLE_COPY(VPPiece) Q_DISABLE_COPY(VPPiece)
QUuid m_uuid{QUuid()};
QString m_name{QString()}; QPointF m_offset{QPointF()};
QVector<QPointF> m_cuttingLine{QVector<QPointF>()};
QVector<QPointF> m_seamLine{QVector<QPointF>()};
QVector<QPointF> m_grainline{QVector<QPointF>()}; QVector<QPointF> m_grainline{QVector<QPointF>()};
bool m_isGrainlineEnabled{false}; bool m_isGrainlineEnabled{false};

View File

@ -241,7 +241,7 @@ void VPLayoutFileReader::ReadPiece(VPPiece *piece)
piece->SetName(ReadAttributeString(attribs, ML::AttrName, tr("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? 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); bool showSeamline = ReadAttributeBool(attribs, ML::AttrShowSeamline, trueStr);
piece->SetShowSeamLine(showSeamline); piece->SetShowSeamLine(showSeamline);

View File

@ -167,7 +167,7 @@ void VPLayoutFileWriter::WritePiece(VPPiece *piece)
Q_UNUSED(piece); Q_UNUSED(piece);
writeStartElement(ML::TagPiece); writeStartElement(ML::TagPiece);
SetAttribute(ML::AttrID, piece->GetUuid().toString()); SetAttribute(ML::AttrID, piece->GetUUID().toString());
SetAttribute(ML::AttrName, piece->GetName()); SetAttribute(ML::AttrName, piece->GetName());
SetAttribute(ML::AttrMirrored, piece->GetPieceMirrored()); // TODO / Fixme get the right value SetAttribute(ML::AttrMirrored, piece->GetPieceMirrored()); // TODO / Fixme get the right value
SetAttribute(ML::AttrShowSeamline, piece->GetShowSeamLine()); // TODO / Fixme get the right value SetAttribute(ML::AttrShowSeamline, piece->GetShowSeamLine()); // TODO / Fixme get the right value