Cleaning.
This commit is contained in:
parent
bc0b271f16
commit
2eecf95af9
|
@ -52,30 +52,14 @@ Q_LOGGING_CATEGORY(pGraphicsPiece, "p.graphicsPiece")
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
VPGraphicsPiece::VPGraphicsPiece(VPPiece *piece, QGraphicsItem *parent) :
|
VPGraphicsPiece::VPGraphicsPiece(VPPiece *piece, QGraphicsItem *parent) :
|
||||||
QGraphicsObject(parent),
|
QGraphicsObject(parent),
|
||||||
m_piece(piece),
|
m_piece(piece)
|
||||||
m_cuttingLine(QPainterPath()),
|
|
||||||
m_seamLine(QPainterPath()),
|
|
||||||
m_grainline(QPainterPath()),
|
|
||||||
m_passmarks(QPainterPath()),
|
|
||||||
m_internalPaths(QVector<QPainterPath>()),
|
|
||||||
m_internalPathsPenStyle(QVector<Qt::PenStyle>()),
|
|
||||||
m_placeLabels(QVector<QPainterPath>()),
|
|
||||||
m_rotationStartPoint(QPointF()),
|
|
||||||
m_rotateCursor(QCursor())
|
|
||||||
{
|
{
|
||||||
|
|
||||||
QPixmap cursor_pixmap = QIcon("://puzzleicon/svg/cursor_rotate.svg").pixmap(QSize(32,32));
|
QPixmap cursor_pixmap = QIcon("://puzzleicon/svg/cursor_rotate.svg").pixmap(QSize(32,32));
|
||||||
m_rotateCursor= QCursor(cursor_pixmap, 16, 16);
|
m_rotateCursor= QCursor(cursor_pixmap, 16, 16);
|
||||||
|
|
||||||
Init();
|
Init();
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
|
||||||
VPGraphicsPiece::~VPGraphicsPiece()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void VPGraphicsPiece::Init()
|
void VPGraphicsPiece::Init()
|
||||||
{
|
{
|
||||||
|
@ -89,18 +73,22 @@ void VPGraphicsPiece::Init()
|
||||||
if(!seamLinePoints.isEmpty())
|
if(!seamLinePoints.isEmpty())
|
||||||
{
|
{
|
||||||
m_seamLine.moveTo(seamLinePoints.first());
|
m_seamLine.moveTo(seamLinePoints.first());
|
||||||
for (int i = 0; i < seamLinePoints.size(); i++)
|
for (int i = 1; i < seamLinePoints.size(); i++)
|
||||||
|
{
|
||||||
m_seamLine.lineTo(seamLinePoints.at(i));
|
m_seamLine.lineTo(seamLinePoints.at(i));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// initiliases the cutting line
|
// initiliases the cutting line
|
||||||
QVector<QPointF> cuttingLinepoints = m_piece->GetMappedSeamAllowancePoints();
|
QVector<QPointF> cuttingLinepoints = m_piece->GetMappedSeamAllowancePoints();
|
||||||
if(!cuttingLinepoints.isEmpty())
|
if(!cuttingLinepoints.isEmpty())
|
||||||
{
|
{
|
||||||
m_cuttingLine.moveTo(cuttingLinepoints.first());
|
m_cuttingLine.moveTo(cuttingLinepoints.first());
|
||||||
for (int i = 0; i < cuttingLinepoints.size(); i++)
|
for (int i = 1; i < cuttingLinepoints.size(); i++)
|
||||||
|
{
|
||||||
m_cuttingLine.lineTo(cuttingLinepoints.at(i));
|
m_cuttingLine.lineTo(cuttingLinepoints.at(i));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// initialises the grainline
|
// initialises the grainline
|
||||||
if(m_piece->IsGrainlineEnabled())
|
if(m_piece->IsGrainlineEnabled())
|
||||||
|
@ -109,16 +97,17 @@ void VPGraphicsPiece::Init()
|
||||||
if(!grainLinepoints.isEmpty())
|
if(!grainLinepoints.isEmpty())
|
||||||
{
|
{
|
||||||
m_grainline.moveTo(grainLinepoints.first());
|
m_grainline.moveTo(grainLinepoints.first());
|
||||||
for (int i = 0; i < grainLinepoints.size(); i++)
|
for (int i = 1; i < grainLinepoints.size(); i++)
|
||||||
|
{
|
||||||
m_grainline.lineTo(grainLinepoints.at(i));
|
m_grainline.lineTo(grainLinepoints.at(i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// initialises the internal paths
|
// initialises the internal paths
|
||||||
QVector<VLayoutPiecePath> internalPaths = m_piece->GetInternalPaths();
|
QVector<VLayoutPiecePath> internalPaths = m_piece->GetInternalPaths();
|
||||||
for (int i = 0; i < internalPaths.size(); i++)
|
for (const auto& piecePath : internalPaths)
|
||||||
{
|
{
|
||||||
VLayoutPiecePath piecePath = internalPaths.at(i);
|
|
||||||
QPainterPath path = m_piece->GetMatrix().map(piecePath.GetPainterPath());
|
QPainterPath path = m_piece->GetMatrix().map(piecePath.GetPainterPath());
|
||||||
m_internalPaths.append(path);
|
m_internalPaths.append(path);
|
||||||
m_internalPathsPenStyle.append(piecePath.PenStyle());
|
m_internalPathsPenStyle.append(piecePath.PenStyle());
|
||||||
|
@ -159,13 +148,13 @@ void VPGraphicsPiece::Init()
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
VPPiece* VPGraphicsPiece::GetPiece()
|
auto VPGraphicsPiece::GetPiece() -> VPPiece*
|
||||||
{
|
{
|
||||||
return m_piece;
|
return m_piece;
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
QRectF VPGraphicsPiece::boundingRect() const
|
auto VPGraphicsPiece::boundingRect() const -> QRectF
|
||||||
{
|
{
|
||||||
if(!m_cuttingLine.isEmpty())
|
if(!m_cuttingLine.isEmpty())
|
||||||
{
|
{
|
||||||
|
@ -176,7 +165,7 @@ QRectF VPGraphicsPiece::boundingRect() const
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
QPainterPath VPGraphicsPiece::shape() const
|
auto VPGraphicsPiece::shape() const -> QPainterPath
|
||||||
{
|
{
|
||||||
if(!m_cuttingLine.isEmpty())
|
if(!m_cuttingLine.isEmpty())
|
||||||
{
|
{
|
||||||
|
@ -457,16 +446,17 @@ void VPGraphicsPiece::on_PieceRotationChanged()
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void VPGraphicsPiece::on_PiecePropertiesChanged()
|
void VPGraphicsPiece::on_PiecePropertiesChanged()
|
||||||
{
|
{
|
||||||
if(scene())
|
if(scene() != nullptr)
|
||||||
{
|
{
|
||||||
scene()->update();
|
scene()->update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
QVariant VPGraphicsPiece::itemChange(GraphicsItemChange change, const QVariant &value)
|
auto VPGraphicsPiece::itemChange(GraphicsItemChange change, const QVariant &value) -> QVariant
|
||||||
|
{
|
||||||
|
if (scene() != nullptr)
|
||||||
{
|
{
|
||||||
if (scene()) {
|
|
||||||
|
|
||||||
// we do this in the mouseRelease button to avoid updated this property all the time.
|
// we do this in the mouseRelease button to avoid updated this property all the time.
|
||||||
// if(change == ItemPositionHasChanged)
|
// if(change == ItemPositionHasChanged)
|
||||||
|
|
|
@ -38,15 +38,16 @@ class VPGraphicsPiece : public QGraphicsObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
VPGraphicsPiece(VPPiece *piece, QGraphicsItem *parent = nullptr);
|
explicit VPGraphicsPiece(VPPiece *piece, QGraphicsItem *parent = nullptr);
|
||||||
~VPGraphicsPiece();
|
~VPGraphicsPiece() = default;
|
||||||
|
|
||||||
void Init();
|
void Init();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief GetPiece Returns the piece that corresponds to the graphics piece
|
* @brief GetPiece Returns the piece that corresponds to the graphics piece
|
||||||
* @return the piece
|
* @return the piece
|
||||||
*/
|
*/
|
||||||
VPPiece* GetPiece();
|
auto GetPiece() -> VPPiece*;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
/**
|
/**
|
||||||
|
@ -70,8 +71,8 @@ public slots:
|
||||||
void on_PiecePropertiesChanged();
|
void on_PiecePropertiesChanged();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QRectF boundingRect() const override;
|
auto boundingRect() const -> QRectF override;
|
||||||
QPainterPath shape() const override;
|
auto shape() const -> QPainterPath override;
|
||||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
|
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
|
||||||
|
|
||||||
void mousePressEvent(QGraphicsSceneMouseEvent * event) override;
|
void mousePressEvent(QGraphicsSceneMouseEvent * event) override;
|
||||||
|
@ -80,7 +81,7 @@ protected:
|
||||||
|
|
||||||
void hoverMoveEvent(QGraphicsSceneHoverEvent *event) override;
|
void hoverMoveEvent(QGraphicsSceneHoverEvent *event) override;
|
||||||
|
|
||||||
QVariant itemChange(GraphicsItemChange change, const QVariant &value) override;
|
auto itemChange(GraphicsItemChange change, const QVariant &value) -> QVariant override;
|
||||||
|
|
||||||
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override;
|
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override;
|
||||||
|
|
||||||
|
@ -88,19 +89,19 @@ private:
|
||||||
Q_DISABLE_COPY(VPGraphicsPiece)
|
Q_DISABLE_COPY(VPGraphicsPiece)
|
||||||
VPPiece *m_piece;
|
VPPiece *m_piece;
|
||||||
|
|
||||||
QPainterPath m_cuttingLine;
|
QPainterPath m_cuttingLine{};
|
||||||
QPainterPath m_seamLine;
|
QPainterPath m_seamLine{};
|
||||||
QPainterPath m_grainline;
|
QPainterPath m_grainline{};
|
||||||
QPainterPath m_passmarks;
|
QPainterPath m_passmarks{};
|
||||||
|
|
||||||
QVector<QPainterPath> m_internalPaths;
|
QVector<QPainterPath> m_internalPaths{};
|
||||||
QVector<Qt::PenStyle> m_internalPathsPenStyle;
|
QVector<Qt::PenStyle> m_internalPathsPenStyle{};
|
||||||
|
|
||||||
QVector<QPainterPath> m_placeLabels;
|
QVector<QPainterPath> m_placeLabels{};
|
||||||
|
|
||||||
QPointF m_rotationStartPoint;
|
QPointF m_rotationStartPoint{};
|
||||||
|
|
||||||
QCursor m_rotateCursor;
|
QCursor m_rotateCursor{};
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // VPGRAPHICSPIECE_H
|
#endif // VPGRAPHICSPIECE_H
|
||||||
|
|
|
@ -101,7 +101,7 @@ void VPMainGraphicsView::RefreshPieces()
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
VMainGraphicsScene* VPMainGraphicsView::GetScene()
|
auto VPMainGraphicsView::GetScene() -> VMainGraphicsScene*
|
||||||
{
|
{
|
||||||
return m_scene;
|
return m_scene;
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,7 +55,7 @@ public:
|
||||||
* @brief GetScene Returns the scene of the view
|
* @brief GetScene Returns the scene of the view
|
||||||
* @return scene of the view
|
* @return scene of the view
|
||||||
*/
|
*/
|
||||||
VMainGraphicsScene* GetScene();
|
auto GetScene() -> VMainGraphicsScene*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief PrepareForExport prepares the graphic for an export (i.e hide margin etc)
|
* @brief PrepareForExport prepares the graphic for an export (i.e hide margin etc)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user