Qpagedpaintdevice: Use marginsF instead of internal struct margins

resolve remaining Qt6 TODOs

Change-Id: Iad659a09ddfe136bdc545bc0635b4c695540c58b
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
bb10
Peng Wenhao 2020-08-27 14:21:07 +08:00
parent 90358f6042
commit f0ae973244
9 changed files with 75 additions and 90 deletions

View File

@ -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);
}
/*!

View File

@ -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);

View File

@ -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

View File

@ -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:

View File

@ -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

View File

@ -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);
}
/*!

View File

@ -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;

View File

@ -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);

View File

@ -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