summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeng Wenhao <pengwenhao@uniontech.com>2020-08-27 14:21:07 +0800
committerPeng Wenhao <pengwenhao@uniontech.com>2020-09-01 04:57:48 +0800
commitf0ae973244026ca5382f05630bd799b44154d224 (patch)
tree630eef965e2fe07745c41fffdfa00b30c3ce2485
parent90358f6042d1fe2db849e17e1b0c875fb0560b20 (diff)
Qpagedpaintdevice: Use marginsF instead of internal struct margins
resolve remaining Qt6 TODOs Change-Id: Iad659a09ddfe136bdc545bc0635b4c695540c58b Reviewed-by: Lars Knoll <lars.knoll@qt.io>
-rw-r--r--src/gui/painting/qpagedpaintdevice.cpp14
-rw-r--r--src/gui/painting/qpagedpaintdevice.h12
-rw-r--r--src/gui/painting/qpdfwriter.cpp4
-rw-r--r--src/gui/painting/qpdfwriter.h2
-rw-r--r--src/gui/text/qtextdocument.cpp9
-rw-r--r--src/printsupport/kernel/qprinter.cpp4
-rw-r--r--src/printsupport/kernel/qprinter.h2
-rw-r--r--tests/auto/gui/painting/qpdfwriter/tst_qpdfwriter.cpp56
-rw-r--r--tests/auto/printsupport/kernel/qprinter/tst_qprinter.cpp62
9 files changed, 75 insertions, 90 deletions
diff --git a/src/gui/painting/qpagedpaintdevice.cpp b/src/gui/painting/qpagedpaintdevice.cpp
index e6d3a38427..ecb952a8bd 100644
--- a/src/gui/painting/qpagedpaintdevice.cpp
+++ b/src/gui/painting/qpagedpaintdevice.cpp
@@ -343,9 +343,9 @@ QSizeF QPagedPaintDevice::pageSizeMM() const
\sa margins()
*/
-void QPagedPaintDevice::setMargins(const Margins &margins)
+void QPagedPaintDevice::setMargins(const QMarginsF &margins)
{
- d->setPageMargins(QMarginsF(margins.left, margins.top, margins.right, margins.bottom), QPageLayout::Millimeter);
+ d->setPageMargins(margins, QPageLayout::Millimeter);
}
/*!
@@ -355,15 +355,9 @@ void QPagedPaintDevice::setMargins(const Margins &margins)
\sa setMargins()
*/
-QPagedPaintDevice::Margins QPagedPaintDevice::margins() const
+QMarginsF QPagedPaintDevice::margins() const
{
- QMarginsF margins = d->pageLayout().margins(QPageLayout::Millimeter);
- Margins result;
- result.left = margins.left();
- result.top = margins.top();
- result.right = margins.right();
- result.bottom = margins.bottom();
- return result;
+ return d->pageLayout().margins(QPageLayout::Millimeter);
}
/*!
diff --git a/src/gui/painting/qpagedpaintdevice.h b/src/gui/painting/qpagedpaintdevice.h
index 21e23e0eb4..914a72b7be 100644
--- a/src/gui/painting/qpagedpaintdevice.h
+++ b/src/gui/painting/qpagedpaintdevice.h
@@ -230,16 +230,8 @@ public:
virtual void setPageSizeMM(const QSizeF &size);
QSizeF pageSizeMM() const;
- // ### Qt6 Remove in favor of QMarginsF
- struct Margins {
- qreal left;
- qreal right;
- qreal top;
- qreal bottom;
- };
-
- virtual void setMargins(const Margins &margins);
- Margins margins() const;
+ virtual void setMargins(const QMarginsF &margins);
+ QMarginsF margins() const;
protected:
QPagedPaintDevice(QPagedPaintDevicePrivate *dd);
diff --git a/src/gui/painting/qpdfwriter.cpp b/src/gui/painting/qpdfwriter.cpp
index 32f2194da3..1de8ff0bcc 100644
--- a/src/gui/painting/qpdfwriter.cpp
+++ b/src/gui/painting/qpdfwriter.cpp
@@ -480,9 +480,9 @@ QT_WARNING_DISABLE_DEPRECATED
\sa setPageMargins()
*/
-void QPdfWriter::setMargins(const Margins &m)
+void QPdfWriter::setMargins(const QMarginsF &m)
{
- setPageMargins(QMarginsF(m.left, m.top, m.right, m.bottom), QPageLayout::Millimeter);
+ setPageMargins(m, QPageLayout::Millimeter);
}
QT_WARNING_POP
#endif
diff --git a/src/gui/painting/qpdfwriter.h b/src/gui/painting/qpdfwriter.h
index 04039a0104..fa5750dcf0 100644
--- a/src/gui/painting/qpdfwriter.h
+++ b/src/gui/painting/qpdfwriter.h
@@ -97,7 +97,7 @@ public:
QT_DEPRECATED_X("Use setPageSize(QPageSize(size, QPageSize::Millimeter)) instead")
void setPageSizeMM(const QSizeF &size) override;
QT_DEPRECATED_X("Use setPageMargins(QMarginsF(l, t, r, b), QPageLayout::Millimeter) instead")
- void setMargins(const Margins &m) override;
+ void setMargins(const QMarginsF &m) override;
#endif
protected:
diff --git a/src/gui/text/qtextdocument.cpp b/src/gui/text/qtextdocument.cpp
index 3cee66095b..877bae0f0a 100644
--- a/src/gui/text/qtextdocument.cpp
+++ b/src/gui/text/qtextdocument.cpp
@@ -1918,9 +1918,12 @@ void QTextDocument::print(QPagedPaintDevice *printer) const
QPagedPaintDevicePrivate *pd = QPagedPaintDevicePrivate::get(printer);
// ### set page size to paginated size?
- QPagedPaintDevice::Margins m = printer->margins();
- if (!documentPaginated && m.left == 0. && m.right == 0. && m.top == 0. && m.bottom == 0.) {
- m.left = m.right = m.top = m.bottom = 2.;
+ QMarginsF m = printer->margins();
+ if (!documentPaginated && m.left() == 0. && m.right() == 0. && m.top() == 0. && m.bottom() == 0.) {
+ m.setLeft(2);
+ m.setRight(2);
+ m.setTop(2);
+ m.setBottom(2);
printer->setMargins(m);
}
// ### use the margins correctly
diff --git a/src/printsupport/kernel/qprinter.cpp b/src/printsupport/kernel/qprinter.cpp
index 8fd98d1e4c..227b2af023 100644
--- a/src/printsupport/kernel/qprinter.cpp
+++ b/src/printsupport/kernel/qprinter.cpp
@@ -1740,9 +1740,9 @@ void QPrinter::setPageMargins(qreal left, qreal top, qreal right, qreal bottom,
\sa setPageMargins()
*/
-void QPrinter::setMargins(const Margins &m)
+void QPrinter::setMargins(const QMarginsF &m)
{
- setPageMargins(QMarginsF(m.left, m.top, m.right, m.bottom), QPageLayout::Millimeter);
+ setPageMargins(m, QPageLayout::Millimeter);
}
/*!
diff --git a/src/printsupport/kernel/qprinter.h b/src/printsupport/kernel/qprinter.h
index e606ceba47..50b84e72d7 100644
--- a/src/printsupport/kernel/qprinter.h
+++ b/src/printsupport/kernel/qprinter.h
@@ -255,7 +255,7 @@ public:
void setPrintRange(PrintRange range);
PrintRange printRange() const;
- void setMargins(const Margins &m) override;
+ void setMargins(const QMarginsF &m) override;
void setPageMargins(qreal left, qreal top, qreal right, qreal bottom, Unit unit);
void getPageMargins(qreal *left, qreal *top, qreal *right, qreal *bottom, Unit unit) const;
diff --git a/tests/auto/gui/painting/qpdfwriter/tst_qpdfwriter.cpp b/tests/auto/gui/painting/qpdfwriter/tst_qpdfwriter.cpp
index 3fbe16575d..36b8a4726b 100644
--- a/tests/auto/gui/painting/qpdfwriter/tst_qpdfwriter.cpp
+++ b/tests/auto/gui/painting/qpdfwriter/tst_qpdfwriter.cpp
@@ -90,25 +90,25 @@ void tst_QPdfWriter::basics()
QCOMPARE(writer.pageLayout().margins(), QMarginsF(10, 10, 10, 10));
QCOMPARE(writer.pageLayout().units(), QPageLayout::Point);
- QCOMPARE(writer.margins().left, 3.53); // mm
- QCOMPARE(writer.margins().right, 3.53);
- QCOMPARE(writer.margins().top, 3.53);
- QCOMPARE(writer.margins().bottom, 3.53);
+ QCOMPARE(writer.margins().left(), 3.53); // mm
+ QCOMPARE(writer.margins().right(), 3.53);
+ QCOMPARE(writer.margins().top(), 3.53);
+ QCOMPARE(writer.margins().bottom(), 3.53);
writer.setPageMargins(QMarginsF(20, 20, 20, 20), QPageLayout::Millimeter);
QCOMPARE(writer.pageLayout().margins(), QMarginsF(20, 20, 20, 20));
QCOMPARE(writer.pageLayout().units(), QPageLayout::Millimeter);
- QCOMPARE(writer.margins().left, 20.0);
- QCOMPARE(writer.margins().right, 20.0);
- QCOMPARE(writer.margins().top, 20.0);
- QCOMPARE(writer.margins().bottom, 20.0);
+ QCOMPARE(writer.margins().left(), 20.0);
+ QCOMPARE(writer.margins().right(), 20.0);
+ QCOMPARE(writer.margins().top(), 20.0);
+ QCOMPARE(writer.margins().bottom(), 20.0);
const QMarginsF margins = {50, 50, 50, 50};
writer.setPageMargins(margins, QPageLayout::Millimeter);
QCOMPARE(writer.pageLayout().margins(), margins);
QCOMPARE(writer.pageLayout().units(), QPageLayout::Millimeter);
- QCOMPARE(writer.margins().left, 50.0);
- QCOMPARE(writer.margins().right, 50.0);
- QCOMPARE(writer.margins().top, 50.0);
- QCOMPARE(writer.margins().bottom, 50.0);
+ QCOMPARE(writer.margins().left(), 50.0);
+ QCOMPARE(writer.margins().right(), 50.0);
+ QCOMPARE(writer.margins().top(), 50.0);
+ QCOMPARE(writer.margins().bottom(), 50.0);
QCOMPARE(writer.pageLayout().fullRect(QPageLayout::Millimeter), QRectF(0, 0, 297, 210));
QCOMPARE(writer.pageLayout().paintRect(QPageLayout::Millimeter), QRectF(50, 50, 197, 110));
@@ -185,10 +185,10 @@ void tst_QPdfWriter::testPageMetrics()
if (setMargins) {
// Setup the given margins
writer.setPageMargins({leftMMf, topMMf, rightMMf, bottomMMf}, QPageLayout::Millimeter);
- QCOMPARE(writer.margins().left, leftMMf);
- QCOMPARE(writer.margins().right, rightMMf);
- QCOMPARE(writer.margins().top, topMMf);
- QCOMPARE(writer.margins().bottom, bottomMMf);
+ QCOMPARE(writer.margins().left(), leftMMf);
+ QCOMPARE(writer.margins().right(), rightMMf);
+ QCOMPARE(writer.margins().top(), topMMf);
+ QCOMPARE(writer.margins().bottom(), bottomMMf);
}
// Set the given size, in Portrait mode
@@ -199,10 +199,10 @@ void tst_QPdfWriter::testPageMetrics()
QCOMPARE(int(writer.pageSize()), int(pageSizeId));
QCOMPARE(writer.pageLayout().orientation(), QPageLayout::Portrait);
- QCOMPARE(writer.margins().left, leftMMf);
- QCOMPARE(writer.margins().right, rightMMf);
- QCOMPARE(writer.margins().top, topMMf);
- QCOMPARE(writer.margins().bottom, bottomMMf);
+ QCOMPARE(writer.margins().left(), leftMMf);
+ QCOMPARE(writer.margins().right(), rightMMf);
+ QCOMPARE(writer.margins().top(), topMMf);
+ QCOMPARE(writer.margins().bottom(), bottomMMf);
// QPagedPaintDevice::pageSizeMM() always returns Portrait
QCOMPARE(writer.pageSizeMM(), sizeMMf);
@@ -216,10 +216,10 @@ void tst_QPdfWriter::testPageMetrics()
QCOMPARE(writer.pageLayout().pageSize().id(), pageSizeId);
QCOMPARE(int(writer.pageSize()), int(pageSizeId));
QCOMPARE(writer.pageLayout().orientation(), QPageLayout::Landscape);
- QCOMPARE(writer.margins().left, leftMMf);
- QCOMPARE(writer.margins().right, rightMMf);
- QCOMPARE(writer.margins().top, topMMf);
- QCOMPARE(writer.margins().bottom, bottomMMf);
+ QCOMPARE(writer.margins().left(), leftMMf);
+ QCOMPARE(writer.margins().right(), rightMMf);
+ QCOMPARE(writer.margins().top(), topMMf);
+ QCOMPARE(writer.margins().bottom(), bottomMMf);
// QPagedPaintDevice::pageSizeMM() always returns Portrait
QCOMPARE(writer.pageSizeMM(), sizeMMf);
@@ -240,10 +240,10 @@ void tst_QPdfWriter::testPageMetrics()
QCOMPARE(writer.pageLayout().pageSize().id(), pageSizeId);
QCOMPARE(int(writer.pageSize()), int(pageSizeId));
QCOMPARE(writer.pageLayout().orientation(), QPageLayout::Landscape);
- QCOMPARE(writer.margins().left, leftMMf);
- QCOMPARE(writer.margins().right, rightMMf);
- QCOMPARE(writer.margins().top, topMMf);
- QCOMPARE(writer.margins().bottom, bottomMMf);
+ QCOMPARE(writer.margins().left(), leftMMf);
+ QCOMPARE(writer.margins().right(), rightMMf);
+ QCOMPARE(writer.margins().top(), topMMf);
+ QCOMPARE(writer.margins().bottom(), bottomMMf);
// QPagedPaintDevice::pageSizeMM() always returns Portrait
QCOMPARE(writer.pageSizeMM(), sizeMMf);
diff --git a/tests/auto/printsupport/kernel/qprinter/tst_qprinter.cpp b/tests/auto/printsupport/kernel/qprinter/tst_qprinter.cpp
index 7529bad833..f3a6c4c695 100644
--- a/tests/auto/printsupport/kernel/qprinter/tst_qprinter.cpp
+++ b/tests/auto/printsupport/kernel/qprinter/tst_qprinter.cpp
@@ -1816,16 +1816,12 @@ void tst_QPrinter::testPageMetrics()
if (setMargins) {
// Setup the given margins
- QPrinter::Margins margins;
- margins.left = leftMMf;
- margins.right = rightMMf;
- margins.top = topMMf;
- margins.bottom = bottomMMf;
+ QMarginsF margins(leftMMf, topMMf, rightMMf, bottomMMf);
printer.setMargins(margins);
- QCOMPARE(printer.margins().left, leftMMf);
- QCOMPARE(printer.margins().right, rightMMf);
- QCOMPARE(printer.margins().top, topMMf);
- QCOMPARE(printer.margins().bottom, bottomMMf);
+ QCOMPARE(printer.margins().left(), leftMMf);
+ QCOMPARE(printer.margins().right(), rightMMf);
+ QCOMPARE(printer.margins().top(), topMMf);
+ QCOMPARE(printer.margins().bottom(), bottomMMf);
}
@@ -1840,17 +1836,17 @@ void tst_QPrinter::testPageMetrics()
QCOMPARE(printer.orientation(), QPrinter::Portrait);
if (setMargins) {
// Check margins unchanged from page size change
- QCOMPARE(printer.margins().left, leftMMf);
- QCOMPARE(printer.margins().right, rightMMf);
- QCOMPARE(printer.margins().top, topMMf);
- QCOMPARE(printer.margins().bottom, bottomMMf);
+ QCOMPARE(printer.margins().left(), leftMMf);
+ QCOMPARE(printer.margins().right(), rightMMf);
+ QCOMPARE(printer.margins().top(), topMMf);
+ QCOMPARE(printer.margins().bottom(), bottomMMf);
} else {
// Fetch the default margins for the printer and page size
// TODO Check against margins from print device when api added
- leftMMf = printer.margins().left;
- rightMMf = printer.margins().right;
- topMMf = printer.margins().top;
- bottomMMf = printer.margins().bottom;
+ leftMMf = printer.margins().left();
+ rightMMf = printer.margins().right();
+ topMMf = printer.margins().top();
+ bottomMMf = printer.margins().bottom();
}
// QPagedPaintDevice::pageSizeMM() always returns Portrait
@@ -1880,17 +1876,17 @@ void tst_QPrinter::testPageMetrics()
QCOMPARE(printer.orientation(), QPrinter::Landscape);
if (setMargins) {
// Check margins unchanged from page size change
- QCOMPARE(printer.margins().left, leftMMf);
- QCOMPARE(printer.margins().right, rightMMf);
- QCOMPARE(printer.margins().top, topMMf);
- QCOMPARE(printer.margins().bottom, bottomMMf);
+ QCOMPARE(printer.margins().left(), leftMMf);
+ QCOMPARE(printer.margins().right(), rightMMf);
+ QCOMPARE(printer.margins().top(), topMMf);
+ QCOMPARE(printer.margins().bottom(), bottomMMf);
} else {
// Fetch the default margins for the printer and page size
// TODO Check against margins from print device when api added
- leftMMf = printer.margins().left;
- rightMMf = printer.margins().right;
- topMMf = printer.margins().top;
- bottomMMf = printer.margins().bottom;
+ leftMMf = printer.margins().left();
+ rightMMf = printer.margins().right();
+ topMMf = printer.margins().top();
+ bottomMMf = printer.margins().bottom();
}
// QPagedPaintDevice::pageSizeMM() always returns Portrait
@@ -1921,17 +1917,17 @@ void tst_QPrinter::testPageMetrics()
QCOMPARE(printer.orientation(), QPrinter::Landscape);
if (setMargins) {
// Check margins unchanged from page size change
- QCOMPARE(printer.margins().left, leftMMf);
- QCOMPARE(printer.margins().right, rightMMf);
- QCOMPARE(printer.margins().top, topMMf);
- QCOMPARE(printer.margins().bottom, bottomMMf);
+ QCOMPARE(printer.margins().left(), leftMMf);
+ QCOMPARE(printer.margins().right(), rightMMf);
+ QCOMPARE(printer.margins().top(), topMMf);
+ QCOMPARE(printer.margins().bottom(), bottomMMf);
} else {
// Fetch the default margins for the printer and page size
// TODO Check against margins from print device when api added
- leftMMf = printer.margins().left;
- rightMMf = printer.margins().right;
- topMMf = printer.margins().top;
- bottomMMf = printer.margins().bottom;
+ leftMMf = printer.margins().left();
+ rightMMf = printer.margins().right();
+ topMMf = printer.margins().top();
+ bottomMMf = printer.margins().bottom();
}
// QPagedPaintDevice::pageSizeMM() always returns Portrait