Merge branch 'feature/manual-layout' into 'feature/manual-layout'

Feature/manual layout

See merge request smart-pattern/valentina!10
This commit is contained in:
Roman Telezhynskyi 2020-11-07 14:18:32 +00:00
commit 0ee00369f7
10 changed files with 105 additions and 229 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,12 +92,15 @@ void VPGraphicsPiece::Init()
} }
// initialises the grainline // initialises the grainline
QVector<QPointF> grainLinepoints = m_piece->GetGrainline(); if(m_piece->IsGrainlineEnabled())
if(!grainLinepoints.isEmpty())
{ {
m_grainline.moveTo(grainLinepoints.first()); QVector<QPointF> grainLinepoints = m_piece->GetGrainline();
for (int i = 1; i < grainLinepoints.size(); ++i) if(!grainLinepoints.isEmpty())
m_grainline.lineTo(grainLinepoints.at(i)); {
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. // TODO : initialises the other elements labels, passmarks etc.

View File

@ -68,7 +68,13 @@ void VPGraphicsSheet::paint(QPainter *painter, const QStyleOptionGraphicsItem *o
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QRectF VPGraphicsSheet::GetSheetRect() const QRectF VPGraphicsSheet::GetSheetRect() const
{ {
QRectF rect = QRectF(QPointF(0,0), m_sheet->GetSheetSize()); QPoint topLeft = QPoint(0,0);
QSizeF size = m_sheet->GetSheetSize();
if(m_sheet->GetOrientation() == PageOrientation::Landscape)
{
size.transpose();
}
QRectF rect = QRectF(topLeft, size);
return rect; return rect;
} }
@ -77,6 +83,12 @@ QRectF VPGraphicsSheet::GetMarginsRect() const
{ {
QMarginsF margins = m_sheet->GetSheetMargins(); QMarginsF margins = m_sheet->GetSheetMargins();
QSizeF size = m_sheet->GetSheetSize(); QSizeF size = m_sheet->GetSheetSize();
if(m_sheet->GetOrientation() == PageOrientation::Landscape)
{
size.transpose();
}
QRectF rect = QRectF( QRectF rect = QRectF(
QPointF(margins.left(),margins.top()), QPointF(margins.left(),margins.top()),
QPointF(size.width()-margins.right(), size.height()-margins.bottom()) QPointF(size.width()-margins.right(), size.height()-margins.bottom())

View File

@ -67,8 +67,8 @@ VPMainWindow::VPMainWindow(const VPCommandLinePtr &cmd, QWidget *parent) :
m_layout->SetFocusedSheet(); m_layout->SetFocusedSheet();
// ----- for test purposes, to be removed------------------ // ----- for test purposes, to be removed------------------
sheet->SetSheetMarginsConverted(2, 2, 2, 2); sheet->SetSheetMarginsConverted(1, 1, 1, 1);
sheet->SetSheetSizeConverted(30.0, 45); sheet->SetSheetSizeConverted(84.1, 118.9);
sheet->SetPiecesGapConverted(1); sheet->SetPiecesGapConverted(1);
m_layout->SetUnit(Unit::Cm); m_layout->SetUnit(Unit::Cm);
@ -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!
@ -806,18 +795,6 @@ void VPMainWindow::on_SheetSizeChanged()
{ {
m_layout->GetFocusedSheet()->SetSheetSizeConverted(ui->doubleSpinBoxSheetWidth->value(), ui->doubleSpinBoxSheetLength->value()); m_layout->GetFocusedSheet()->SetSheetSizeConverted(ui->doubleSpinBoxSheetWidth->value(), ui->doubleSpinBoxSheetLength->value());
// updates orientation - no need to block signals because the signal reacts on "clicked"
if(ui->doubleSpinBoxSheetWidth->value() <= ui->doubleSpinBoxSheetLength->value())
{
//portrait
ui->radioButtonSheetPortrait->setChecked(true);
}
else
{
//landscape
ui->radioButtonSheetLandscape->setChecked(true);
}
// TODO Undo / Redo // TODO Undo / Redo
m_graphicsView->RefreshLayout(); m_graphicsView->RefreshLayout();
@ -826,14 +803,15 @@ void VPMainWindow::on_SheetSizeChanged()
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPMainWindow::on_SheetOrientationChanged() void VPMainWindow::on_SheetOrientationChanged()
{ {
// swap the width and length // Updates the orientation
qreal width_before = ui->doubleSpinBoxSheetWidth->value(); if(ui->radioButtonSheetPortrait->isChecked())
qreal length_before = ui->doubleSpinBoxSheetLength->value(); {
m_layout->GetFocusedSheet()->SetOrientation(PageOrientation::Portrait);
SetDoubleSpinBoxValue(ui->doubleSpinBoxSheetWidth, length_before); }
SetDoubleSpinBoxValue(ui->doubleSpinBoxSheetLength, width_before); else
{
m_layout->GetFocusedSheet()->SetSheetSizeConverted(ui->doubleSpinBoxSheetWidth->value(), ui->doubleSpinBoxSheetLength->value()); m_layout->GetFocusedSheet()->SetOrientation(PageOrientation::Landscape);
}
// TODO Undo / Redo // TODO Undo / Redo

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();
QPointF offset = boundingRect.topLeft();
matrix = GetMatrix();
matrix.translate(-offset.x() ,-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
{ {
@ -141,7 +106,7 @@ void VPPiece::SetPosition(QPointF point)
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QPointF VPPiece::GetPosition() QPointF VPPiece::GetPosition()
{ {
return QPointF(m_transform.dx(), m_transform.dy()); return QPointF(m_transform.dx(),m_transform.dy());
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -171,6 +136,7 @@ void VPPiece::SetRotation(qreal angle)
} }
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
qreal VPPiece::GetRotation() qreal VPPiece::GetRotation()
{ {
@ -206,41 +172,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 +186,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,17 +146,17 @@ signals:
*/ */
void PropertiesChanged(); void PropertiesChanged();
private: private:
Q_DISABLE_COPY(VPPiece) Q_DISABLE_COPY(VPPiece)
QUuid m_uuid{QUuid()};
QString m_name{QString()};
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};
qreal m_grainlineAngle{0}; qreal m_grainlineAngle{0};
// for now separate the position of the piece to the matrix coming from vlayoutpiece
// because it's difficult to have the origin of the piece by (0,0)
QTransform m_transform{QTransform()}; QTransform m_transform{QTransform()};
// use a separate value for now because it's not easy to get the angle from the transform matrix // use a separate value for now because it's not easy to get the angle from the transform matrix
qreal m_pieceAngle{0}; qreal m_pieceAngle{0};

View File

@ -107,6 +107,22 @@ QSizeF VPSheet::GetSheetSizeConverted() const
return convertedSize; return convertedSize;
} }
//---------------------------------------------------------------------------------------------------------------------
PageOrientation VPSheet::GetOrientation()
{
return m_orientation;
}
//---------------------------------------------------------------------------------------------------------------------
void VPSheet::SetOrientation(PageOrientation orientation)
{
if(orientation != m_orientation)
{
m_orientation = orientation;
}
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPSheet::SetSheetMargins(qreal left, qreal top, qreal right, qreal bottom) void VPSheet::SetSheetMargins(qreal left, qreal top, qreal right, qreal bottom)
{ {

View File

@ -104,6 +104,18 @@ public:
*/ */
QSizeF GetSheetSizeConverted() const; QSizeF GetSheetSizeConverted() const;
/**
* @brief GetOrientation Returns the orientation of the sheet
* @return orientation of the sheet
*/
PageOrientation GetOrientation();
/**
* @brief SetOrientation Sets the orientation of the sheet to the given value
* @param orientation the new page orientation
*/
void SetOrientation(PageOrientation orientation);
/** /**
* @brief SetSheetMargins, set the margins of the sheet, the values have to be in Unit::Px * @brief SetSheetMargins, set the margins of the sheet, the values have to be in Unit::Px
* @param left in Unit::Px * @param left in Unit::Px
@ -205,6 +217,11 @@ private:
*/ */
QSizeF m_size{}; QSizeF m_size{};
/**
* @brief holds the orientation of the sheet
*/
PageOrientation m_orientation {PageOrientation::Portrait};
// margins // margins
/** /**
* @brief m_margins the margins in Unit::Px * @brief m_margins the margins in Unit::Px

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