From 3ca666fba35700bbe814036c559f14cbc16aa2f7 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Tue, 18 Jun 2019 14:36:20 +0300 Subject: [PATCH] Pass original paper orientation. We cannot rely on paper size because it can be stripped. --HG-- branch : develop --- src/libs/vlayout/vbestsquare.cpp | 6 +++--- src/libs/vlayout/vbestsquare.h | 2 +- src/libs/vlayout/vbestsquare_p.h | 9 ++++++--- src/libs/vlayout/vlayoutgenerator.cpp | 8 ++++---- src/libs/vlayout/vlayoutpaper.cpp | 2 +- src/libs/vlayout/vposition.cpp | 2 +- 6 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/libs/vlayout/vbestsquare.cpp b/src/libs/vlayout/vbestsquare.cpp index e3c35d708..00f43ced4 100644 --- a/src/libs/vlayout/vbestsquare.cpp +++ b/src/libs/vlayout/vbestsquare.cpp @@ -42,8 +42,8 @@ Q_DECL_CONSTEXPR inline qint64 Square(QSizeF size) } // anonymous namespace //--------------------------------------------------------------------------------------------------------------------- -VBestSquare::VBestSquare(QSizeF sheetSize, bool saveLength) - : d(new VBestSquareData(sheetSize, saveLength)) +VBestSquare::VBestSquare(QSizeF sheetSize, bool saveLength, bool isPortrait) + : d(new VBestSquareData(sheetSize, saveLength, isPortrait)) {} //--------------------------------------------------------------------------------------------------------------------- @@ -190,5 +190,5 @@ bool VBestSquare::IsImprovedSidePosition(qreal sidePosition) const //--------------------------------------------------------------------------------------------------------------------- bool VBestSquare::IsPortrait() const { - return d->sheetSize.height() >= d->sheetSize.width(); + return d->isPortrait; } diff --git a/src/libs/vlayout/vbestsquare.h b/src/libs/vlayout/vbestsquare.h index bad0a0688..97b91b9c0 100644 --- a/src/libs/vlayout/vbestsquare.h +++ b/src/libs/vlayout/vbestsquare.h @@ -42,7 +42,7 @@ class VBestSquareData; class VBestSquare { public: - VBestSquare(QSizeF sheetSize, bool saveLength); + VBestSquare(QSizeF sheetSize, bool saveLength, bool isPortrait); VBestSquare(const VBestSquare &res); virtual ~VBestSquare(); diff --git a/src/libs/vlayout/vbestsquare_p.h b/src/libs/vlayout/vbestsquare_p.h index 90548f327..f5940f6d8 100644 --- a/src/libs/vlayout/vbestsquare_p.h +++ b/src/libs/vlayout/vbestsquare_p.h @@ -41,9 +41,10 @@ QT_WARNING_DISABLE_GCC("-Wnon-virtual-dtor") class VBestSquareData : public QSharedData { public: - VBestSquareData(const QSizeF &sheetSize, bool saveLength) + VBestSquareData(const QSizeF &sheetSize, bool saveLength, bool isPortrait) : sheetSize(sheetSize), - saveLength(saveLength) + saveLength(saveLength), + isPortrait(isPortrait) { data.bestSize = QSizeF(sheetSize.width()+10, sheetSize.height()+10); } @@ -54,7 +55,8 @@ public: valideResult(res.valideResult), saveLength(res.saveLength), depthPosition(res.depthPosition), - data(res.data) + data(res.data), + isPortrait(res.isPortrait) {} ~VBestSquareData() {} @@ -64,6 +66,7 @@ public: bool saveLength; qreal depthPosition{INT_MAX}; VBestSquareResData data{}; + bool isPortrait{true}; private: VBestSquareData &operator=(const VBestSquareData &) Q_DECL_EQ_DELETE; diff --git a/src/libs/vlayout/vlayoutgenerator.cpp b/src/libs/vlayout/vlayoutgenerator.cpp index c130a12e5..904303ce6 100644 --- a/src/libs/vlayout/vlayoutgenerator.cpp +++ b/src/libs/vlayout/vlayoutgenerator.cpp @@ -106,6 +106,9 @@ void VLayoutGenerator::Generate(QElapsedTimer timer, qint64 timeout) bank->Reset(); state = LayoutErrors::NoError; + int width = PageWidth(); + int height = PageHeight(); + if (VFuzzyComparePossibleNulls(shift, -1)) { if (bank->PrepareDetails()) @@ -118,9 +121,6 @@ void VLayoutGenerator::Generate(QElapsedTimer timer, qint64 timeout) return; } - int width = PageWidth(); - int height = PageHeight(); - if (stripOptimization) { const qreal b = bank->GetBiggestDiagonal() * multiplier + bank->GetLayoutWidth(); @@ -172,7 +172,7 @@ void VLayoutGenerator::Generate(QElapsedTimer timer, qint64 timeout) return; } - VLayoutPaper paper(PageHeight(), PageWidth(), bank->GetLayoutWidth()); + VLayoutPaper paper(height, width, bank->GetLayoutWidth()); paper.SetShift(shift); paper.SetPaperIndex(static_cast(papers.count())); paper.SetRotate(rotate); diff --git a/src/libs/vlayout/vlayoutpaper.cpp b/src/libs/vlayout/vlayoutpaper.cpp index 47ef7e60b..e6bb6744f 100644 --- a/src/libs/vlayout/vlayoutpaper.cpp +++ b/src/libs/vlayout/vlayoutpaper.cpp @@ -243,7 +243,7 @@ int VLayoutPaper::Count() const //--------------------------------------------------------------------------------------------------------------------- bool VLayoutPaper::AddToSheet(const VLayoutPiece &detail, std::atomic_bool &stop) { - VBestSquare bestResult(d->globalContour.GetSize(), d->saveLength); + VBestSquare bestResult(d->globalContour.GetSize(), d->saveLength, d->originPaperOrientation); QThreadPool *thread_pool = QThreadPool::globalInstance(); thread_pool->setExpiryTimeout(1000); QVector threads; diff --git a/src/libs/vlayout/vposition.cpp b/src/libs/vlayout/vposition.cpp index 7f165991a..9ac38660e 100644 --- a/src/libs/vlayout/vposition.cpp +++ b/src/libs/vlayout/vposition.cpp @@ -136,7 +136,7 @@ QPainterPath DrawDetails(const QVector &details) //--------------------------------------------------------------------------------------------------------------------- VPosition::VPosition(const VPositionData &data, std::atomic_bool *stop, bool saveLength) : QRunnable(), - m_bestResult(VBestSquare(data.gContour.GetSize(), saveLength)), + m_bestResult(VBestSquare(data.gContour.GetSize(), saveLength, data.isOriginPaperOrientationPortrait)), m_data(data), #ifdef LAYOUT_DEBUG paperIndex(0),