diff --git a/src/common/KReportDesign_p.h b/src/common/KReportDesign_p.h --- a/src/common/KReportDesign_p.h +++ b/src/common/KReportDesign_p.h @@ -22,6 +22,7 @@ #include "KReportDesign.h" #include "KReportUnit.h" +#include "KReportUtils_p.h" #include #include @@ -90,7 +91,7 @@ KReportUnit pageUnit; // END OF: Visual settings only QString title; - QPageLayout pageLayout; + KReportPrivate::PageLayout pageLayout; QVarLengthArray sections; #ifdef KREPORT_SCRIPTING QString script; @@ -114,7 +115,7 @@ QString sectionTypeName(KReportSection::Type sectionType); - QPageLayout defaultPageLayout; + KReportPrivate::PageLayout defaultPageLayout; qreal defaultSectionHeight; QColor defaultSectionBackgroundColor; diff --git a/src/common/KReportDocument.cpp b/src/common/KReportDocument.cpp --- a/src/common/KReportDocument.cpp +++ b/src/common/KReportDocument.cpp @@ -38,7 +38,7 @@ QString interpreter; #endif bool externalData; - QPageLayout page; + KReportPrivate::PageLayout page; QString pageSize; QString labelType; }; diff --git a/src/common/KReportRenderObjects.cpp b/src/common/KReportRenderObjects.cpp --- a/src/common/KReportRenderObjects.cpp +++ b/src/common/KReportRenderObjects.cpp @@ -16,6 +16,7 @@ * License along with this library. If not, see . */ #include "KReportRenderObjects.h" +#include "KReportUtils_p.h" #include "kreport_debug.h" @@ -37,7 +38,7 @@ QString title; QList pages; QList sections; - QPageLayout pageLayout; + KReportPrivate::PageLayout pageLayout; }; ORODocument::Private::Private() diff --git a/src/common/KReportUtils_p.h b/src/common/KReportUtils_p.h --- a/src/common/KReportUtils_p.h +++ b/src/common/KReportUtils_p.h @@ -33,6 +33,7 @@ #include #include #include +#include #ifdef Q_WS_X11 #include @@ -168,6 +169,17 @@ int dpiY(); +//! This class is wrapper that fixes a critical QTBUG-47551 bug in default constructor of QPageLayout +//! Default constructor of QPageLayout does not initialize units. +//! https://bugreports.qt.io/browse/QTBUG-47551 +//! @todo remove this class and go back to QPageLayout when the faulty QPageLayout implementations are no longer on the wild. That's probably for Qt 6. +class PageLayout: public QPageLayout { +public: + PageLayout(); + PageLayout(const QPageLayout& pageLayout); + PageLayout& operator=(const QPageLayout& other); +}; + } // KReportPrivate #endif diff --git a/src/common/KReportUtils_p.cpp b/src/common/KReportUtils_p.cpp --- a/src/common/KReportUtils_p.cpp +++ b/src/common/KReportUtils_p.cpp @@ -310,4 +310,18 @@ return s_instance->m_dpiY; } +PageLayout::PageLayout() : QPageLayout(QPageSize(QPageSize::A4), QPageLayout::Portrait, QMarginsF(0,0,0,0)) +{ +} + +PageLayout::PageLayout(const QPageLayout& pageLayout) : QPageLayout(pageLayout) +{ +} + +KReportPrivate::PageLayout & PageLayout::operator=(const QPageLayout& other) +{ + QPageLayout::operator=(other); + return *this; +} + } diff --git a/src/wrtembed/KReportDesigner.cpp b/src/wrtembed/KReportDesigner.cpp --- a/src/wrtembed/KReportDesigner.cpp +++ b/src/wrtembed/KReportDesigner.cpp @@ -844,9 +844,8 @@ int KReportDesigner::pageWidthPx() const { - QPageLayout layout; - layout.setPageSize(QPageSize(KReportPageSize::pageSize(d->set->property("page-size").value().toString()))); - layout.setOrientation(d->set->property("print-orientation").value().toString() == QLatin1String("portrait") ? QPageLayout::Portrait : QPageLayout::Landscape); + QPageLayout layout = QPageLayout(QPageSize(KReportPageSize::pageSize(d->set->property("page-size").value().toString())), d->set->property("print-orientation").value().toString() == QLatin1String("portrait") ? QPageLayout::Portrait : QPageLayout::Landscape, QMarginsF(0,0,0,0));; + QSize pageSizePx = layout.fullRectPixels(KReportPrivate::dpiX()).size(); int width = pageSizePx.width();