From bcb7def7b861153f76f36daee982482652c59091 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Fri, 28 Dec 2018 15:57:24 +0200 Subject: [PATCH] Improving contour edge for empty sheet. It must follow sheet orientation, plus added control of numbers of points with shift option. --HG-- branch : develop --- src/libs/vlayout/vcontour.cpp | 23 ++++++++++++++++------- src/libs/vlayout/vcontour.h | 2 ++ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/libs/vlayout/vcontour.cpp b/src/libs/vlayout/vcontour.cpp index 42814c464..72278f988 100644 --- a/src/libs/vlayout/vcontour.cpp +++ b/src/libs/vlayout/vcontour.cpp @@ -211,27 +211,30 @@ int VContour::GlobalEdgesCount() const int count = 0; if (not d->globalContour.isEmpty()) { - return 10; + count = d->globalContour.count(); } else { - return d->globalContour.count(); + const qreal shift = d->shift == 0 ? ToPixel(0.5, Unit::Cm) : d->shift; + count = qFloor(EmptySheetEdge().length()/shift); } + return count; } //--------------------------------------------------------------------------------------------------------------------- QLineF VContour::GlobalEdge(int i) const { + QLineF edge; if (d->globalContour.isEmpty()) //-V807 { - // Because sheet is blank we have one global edge for all cases - Ox axis. + // Because sheet is blank we have one global edge for all cases. if (i < 1 || i > GlobalEdgesCount()) { // Doesn't exist such edge return EmptySheetEdge(); } const qreal nShift = EmptySheetEdge().length()/GlobalEdgesCount(); - return QLineF(nShift*(i-1), 0, nShift*i, 0); + edge = IsPortrait() ? QLineF(nShift*(i-1), 0, nShift*i, 0) : QLineF(0, nShift*(i-1), 0, nShift*i); } else { @@ -239,7 +242,7 @@ QLineF VContour::GlobalEdge(int i) const { // Doesn't exist such edge return QLineF(); } - QLineF edge; + if (i < GlobalEdgesCount()) { edge = QLineF(d->globalContour.at(i-1), d->globalContour.at(i)); @@ -248,8 +251,8 @@ QLineF VContour::GlobalEdge(int i) const { // Closed countour edge = QLineF(d->globalContour.at(GlobalEdgesCount()-1), d->globalContour.at(0)); } - return edge; } + return edge; } //--------------------------------------------------------------------------------------------------------------------- @@ -355,8 +358,14 @@ void VContour::AppendWhole(QVector &contour, const VLayoutPiece &detail }while (processedEdges < nD); } +//--------------------------------------------------------------------------------------------------------------------- +bool VContour::IsPortrait() const +{ + return d->paperHeight >= d->paperWidth; +} + //--------------------------------------------------------------------------------------------------------------------- QLineF VContour::EmptySheetEdge() const { - return QLineF(0, 0, d->paperWidth - 5, 0); + return IsPortrait() ? QLineF(0, 0, d->paperWidth, 0) : QLineF(0, 0, 0, d->paperHeight); } diff --git a/src/libs/vlayout/vcontour.h b/src/libs/vlayout/vcontour.h index 0ea60e5a4..f8e5cbc4c 100644 --- a/src/libs/vlayout/vcontour.h +++ b/src/libs/vlayout/vcontour.h @@ -93,6 +93,8 @@ private: QSharedDataPointer d; void AppendWhole(QVector &contour, const VLayoutPiece &detail, int detJ) const; + + bool IsPortrait() const; }; Q_DECLARE_TYPEINFO(VContour, Q_MOVABLE_TYPE);