summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorVolker Hilsheimer <volker.hilsheimer@qt.io>2020-09-03 18:42:30 +0200
committerVolker Hilsheimer <volker.hilsheimer@qt.io>2020-09-04 08:37:59 +0200
commit00a5629d8de18bc1a5dfb6e2526c03b4b021c903 (patch)
treed444ede3eb66e5455e09c4de3fda32bcd7437a4a /tests
parent6b171dc6c0c0f0a822b212df77b58b28bd92716c (diff)
Remove deprecated QPrinter and QPagedPaintDevice APIs
Adjusting the QPrinter test case - some use cases no longer exist, or are already tested in QPageSize and QPageLayout tests. Adjust examples and manual tests. Change-Id: I01cbc65f3d8031aea2dac86dd942126ba708b111 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/gui/painting/qpdfwriter/tst_qpdfwriter.cpp91
-rw-r--r--tests/auto/gui/text/qtexttable/tst_qtexttable.cpp2
-rw-r--r--tests/auto/printsupport/kernel/qprinter/tst_qprinter.cpp696
-rw-r--r--tests/manual/dialogs/printdialogpanel.cpp139
4 files changed, 290 insertions, 638 deletions
diff --git a/tests/auto/gui/painting/qpdfwriter/tst_qpdfwriter.cpp b/tests/auto/gui/painting/qpdfwriter/tst_qpdfwriter.cpp
index 36b8a4726b..8c98a8ad98 100644
--- a/tests/auto/gui/painting/qpdfwriter/tst_qpdfwriter.cpp
+++ b/tests/auto/gui/painting/qpdfwriter/tst_qpdfwriter.cpp
@@ -65,50 +65,49 @@ void tst_QPdfWriter::basics()
QCOMPARE(writer.resolution(), 600);
QCOMPARE(writer.pageLayout().pageSize().id(), QPageSize::A4);
- QCOMPARE(writer.pageSize(), QPdfWriter::A4);
- QCOMPARE(writer.pageSizeMM(), QSizeF(210, 297));
+ QCOMPARE(writer.pageLayout().pageSize().id(), QPageSize::A4);
+ QCOMPARE(writer.pageLayout().pageSize().size(QPageSize::Millimeter), QSizeF(210, 297));
writer.setPageSize(QPageSize(QPageSize::A5));
QCOMPARE(writer.pageLayout().pageSize().id(), QPageSize::A5);
- QCOMPARE(writer.pageSize(), QPdfWriter::A5);
- QCOMPARE(writer.pageSizeMM(), QSizeF(148, 210));
+ QCOMPARE(writer.pageLayout().pageSize().size(QPageSize::Millimeter), QSizeF(148, 210));
writer.setPageSize(QPageSize(QPageSize::A3));
QCOMPARE(writer.pageLayout().pageSize().id(), QPageSize::A3);
- QCOMPARE(writer.pageSize(), QPdfWriter::A3);
- QCOMPARE(writer.pageSizeMM(), QSizeF(297, 420));
+ QCOMPARE(writer.pageLayout().pageSize().id(), QPageSize::A3);
+ QCOMPARE(writer.pageLayout().pageSize().size(QPageSize::Millimeter), QSizeF(297, 420));
writer.setPageSize(QPageSize(QSize(210, 297), QPageSize::Millimeter));
QCOMPARE(writer.pageLayout().pageSize().id(), QPageSize::A4);
- QCOMPARE(writer.pageSize(), QPdfWriter::A4);
- QCOMPARE(writer.pageSizeMM(), QSizeF(210, 297));
+ QCOMPARE(writer.pageLayout().pageSize().id(), QPageSize::A4);
+ QCOMPARE(writer.pageLayout().pageSize().size(QPageSize::Millimeter), QSizeF(210, 297));
QCOMPARE(writer.pageLayout().orientation(), QPageLayout::Portrait);
writer.setPageOrientation(QPageLayout::Landscape);
QCOMPARE(writer.pageLayout().orientation(), QPageLayout::Landscape);
- QCOMPARE(writer.pageSizeMM(), QSizeF(210, 297));
+ QCOMPARE(writer.pageLayout().pageSize().size(QPageSize::Millimeter), QSizeF(210, 297));
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.pageLayout().margins(QPageLayout::Millimeter).left(), 3.53); // mm
+ QCOMPARE(writer.pageLayout().margins(QPageLayout::Millimeter).right(), 3.53);
+ QCOMPARE(writer.pageLayout().margins(QPageLayout::Millimeter).top(), 3.53);
+ QCOMPARE(writer.pageLayout().margins(QPageLayout::Millimeter).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.pageLayout().margins().left(), 20.0);
+ QCOMPARE(writer.pageLayout().margins().right(), 20.0);
+ QCOMPARE(writer.pageLayout().margins().top(), 20.0);
+ QCOMPARE(writer.pageLayout().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.pageLayout().margins().left(), 50.0);
+ QCOMPARE(writer.pageLayout().margins().right(), 50.0);
+ QCOMPARE(writer.pageLayout().margins().top(), 50.0);
+ QCOMPARE(writer.pageLayout().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 +184,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.pageLayout().margins().left(), leftMMf);
+ QCOMPARE(writer.pageLayout().margins().right(), rightMMf);
+ QCOMPARE(writer.pageLayout().margins().top(), topMMf);
+ QCOMPARE(writer.pageLayout().margins().bottom(), bottomMMf);
}
// Set the given size, in Portrait mode
@@ -196,16 +195,16 @@ void tst_QPdfWriter::testPageMetrics()
? QPageSize(sizeMMf, QPageSize::Millimeter) : QPageSize(pageSizeId);
writer.setPageSize(pageSize);
QCOMPARE(writer.pageLayout().pageSize().id(), pageSizeId);
- QCOMPARE(int(writer.pageSize()), int(pageSizeId));
+ QCOMPARE(int(writer.pageLayout().pageSize().id()), 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.pageLayout().margins(QPageLayout::Millimeter).left(), leftMMf);
+ QCOMPARE(writer.pageLayout().margins(QPageLayout::Millimeter).right(), rightMMf);
+ QCOMPARE(writer.pageLayout().margins(QPageLayout::Millimeter).top(), topMMf);
+ QCOMPARE(writer.pageLayout().margins(QPageLayout::Millimeter).bottom(), bottomMMf);
- // QPagedPaintDevice::pageSizeMM() always returns Portrait
- QCOMPARE(writer.pageSizeMM(), sizeMMf);
+ // QPagedPaintDevice::pageLayout().pageSize().size(QPageSize::Millimeter) always returns Portrait
+ QCOMPARE(writer.pageLayout().pageSize().size(QPageSize::Millimeter), sizeMMf);
// QPagedPaintDevice::widthMM() and heightMM() are paint metrics and always return set orientation
QCOMPARE(writer.widthMM(), qRound(widthMMf - leftMMf - rightMMf));
@@ -214,15 +213,15 @@ void tst_QPdfWriter::testPageMetrics()
// Now switch to Landscape mode, size should be unchanged, but rect and metrics should change
writer.setPageOrientation(QPageLayout::Landscape);
QCOMPARE(writer.pageLayout().pageSize().id(), pageSizeId);
- QCOMPARE(int(writer.pageSize()), int(pageSizeId));
+ QCOMPARE(int(writer.pageLayout().pageSize().id()), 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.pageLayout().margins(QPageLayout::Millimeter).left(), leftMMf);
+ QCOMPARE(writer.pageLayout().margins(QPageLayout::Millimeter).right(), rightMMf);
+ QCOMPARE(writer.pageLayout().margins(QPageLayout::Millimeter).top(), topMMf);
+ QCOMPARE(writer.pageLayout().margins(QPageLayout::Millimeter).bottom(), bottomMMf);
- // QPagedPaintDevice::pageSizeMM() always returns Portrait
- QCOMPARE(writer.pageSizeMM(), sizeMMf);
+ // QPagedPaintDevice::pageLayout().pageSize().size(QPageSize::Millimeter) always returns Portrait
+ QCOMPARE(writer.pageLayout().pageSize().size(QPageSize::Millimeter), sizeMMf);
// QPagedPaintDevice::widthMM() and heightMM() are paint metrics and always return set orientation
QCOMPARE(writer.widthMM(), qRound(heightMMf - leftMMf - rightMMf));
@@ -238,15 +237,15 @@ void tst_QPdfWriter::testPageMetrics()
// Now while in Landscape mode, set the size again, results should be the same
writer.setPageSize(pageSize);
QCOMPARE(writer.pageLayout().pageSize().id(), pageSizeId);
- QCOMPARE(int(writer.pageSize()), int(pageSizeId));
+ QCOMPARE(int(writer.pageLayout().pageSize().id()), 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.pageLayout().margins(QPageLayout::Millimeter).left(), leftMMf);
+ QCOMPARE(writer.pageLayout().margins(QPageLayout::Millimeter).right(), rightMMf);
+ QCOMPARE(writer.pageLayout().margins(QPageLayout::Millimeter).top(), topMMf);
+ QCOMPARE(writer.pageLayout().margins(QPageLayout::Millimeter).bottom(), bottomMMf);
- // QPagedPaintDevice::pageSizeMM() always returns Portrait
- QCOMPARE(writer.pageSizeMM(), sizeMMf);
+ // QPagedPaintDevice::pageLayout().pageSize().size(QPageSize::Millimeter) always returns Portrait
+ QCOMPARE(writer.pageLayout().pageSize().size(QPageSize::Millimeter), sizeMMf);
// QPagedPaintDevice::widthMM() and heightMM() are paint metrics and always return set orientation
QCOMPARE(writer.widthMM(), qRound(heightMMf - leftMMf - rightMMf));
diff --git a/tests/auto/gui/text/qtexttable/tst_qtexttable.cpp b/tests/auto/gui/text/qtexttable/tst_qtexttable.cpp
index 474079037b..2b0236339c 100644
--- a/tests/auto/gui/text/qtexttable/tst_qtexttable.cpp
+++ b/tests/auto/gui/text/qtexttable/tst_qtexttable.cpp
@@ -1161,7 +1161,7 @@ void tst_QTextTable::QTBUG31330_renderBackground()
}
QTBUG31330_PaintDevice::PaintEngine engine;
QTBUG31330_PaintDevice paintDevice(&engine);
- paintDevice.setPageSize(QPagedPaintDevice::A4);
+ paintDevice.setPageSize(QPageSize(QPageSize::A4));
doc.print(&paintDevice);
QVERIFY(paintDevice.pages >= 2);
diff --git a/tests/auto/printsupport/kernel/qprinter/tst_qprinter.cpp b/tests/auto/printsupport/kernel/qprinter/tst_qprinter.cpp
index f3a6c4c695..d6c236e76e 100644
--- a/tests/auto/printsupport/kernel/qprinter/tst_qprinter.cpp
+++ b/tests/auto/printsupport/kernel/qprinter/tst_qprinter.cpp
@@ -52,8 +52,6 @@
typedef QSharedPointer<QPrinter> PrinterPtr;
Q_DECLARE_METATYPE(PrinterPtr)
-Q_DECLARE_METATYPE(QPrinter::Orientation)
-Q_DECLARE_METATYPE(QPrinter::PageSize)
#endif // printer
static int fileNumber = 0;
@@ -72,8 +70,8 @@ private slots:
void testMargins();
void testPageSetupDialog();
void testPrintPreviewDialog();
- void testMulitpleSets_data();
- void testMulitpleSets();
+ void testMultipleSets_data();
+ void testMultipleSets();
void testPageMargins_data();
void testPageMargins();
void outputFormatFromSuffix();
@@ -82,7 +80,6 @@ private slots:
void customPaperSizeAndMargins_data();
void customPaperSizeAndMargins();
void customPaperNameSettingBySize();
- void customPaperNameSettingByName();
#if QT_CONFIG(completer) && QT_CONFIG(filedialog)
void printDialogCompleter();
#endif
@@ -97,7 +94,6 @@ private slots:
void copyCount();
void creator();
void docName();
- void doubleSidedPrinting();
void duplex();
void fontEmbedding();
void fullPage();
@@ -105,7 +101,6 @@ private slots:
void outputFileName();
void pageOrder();
void pageSize();
- void paperSize();
void paperSource();
void printerName();
void printerSelectionOption();
@@ -114,7 +109,6 @@ private slots:
void resolution();
void supportedPaperSources();
void supportedResolutions();
- void windowsPageSize();
// Test QPrinter setters/getters for non-QPrintEngine options
void outputFormat();
@@ -198,61 +192,61 @@ void tst_QPrinter::testPrintPreviewDialog()
void tst_QPrinter::testPageRectAndPaperRect_data()
{
QTest::addColumn<PrinterPtr>("printer");
- QTest::addColumn<QPrinter::Orientation>("orientation");
+ QTest::addColumn<QPageLayout::Orientation>("orientation");
QTest::addColumn<bool>("withPainter");
QTest::addColumn<int>("resolution");
QTest::addColumn<bool>("doPaperRect");
const PrinterPtr printer(new QPrinter(QPrinter::HighResolution));
// paperrect
- QTest::newRow("paperRect0") << printer << QPrinter::Portrait << true << 300 << true;
- QTest::newRow("paperRect1") << printer << QPrinter::Portrait << false << 300 << true;
- QTest::newRow("paperRect2") << printer << QPrinter::Landscape << true << 300 << true;
- QTest::newRow("paperRect3") << printer << QPrinter::Landscape << false << 300 << true;
- QTest::newRow("paperRect4") << printer << QPrinter::Portrait << true << 600 << true;
- QTest::newRow("paperRect5") << printer << QPrinter::Portrait << false << 600 << true;
- QTest::newRow("paperRect6") << printer << QPrinter::Landscape << true << 600 << true;
- QTest::newRow("paperRect7") << printer << QPrinter::Landscape << false << 600 << true;
- QTest::newRow("paperRect8") << printer << QPrinter::Portrait << true << 1200 << true;
- QTest::newRow("paperRect9") << printer << QPrinter::Portrait << false << 1200 << true;
- QTest::newRow("paperRect10") << printer << QPrinter::Landscape << true << 1200 << true;
- QTest::newRow("paperRect11") << printer << QPrinter::Landscape << false << 1200 << true;
+ QTest::newRow("paperRect0") << printer << QPageLayout::Portrait << true << 300 << true;
+ QTest::newRow("paperRect1") << printer << QPageLayout::Portrait << false << 300 << true;
+ QTest::newRow("paperRect2") << printer << QPageLayout::Landscape << true << 300 << true;
+ QTest::newRow("paperRect3") << printer << QPageLayout::Landscape << false << 300 << true;
+ QTest::newRow("paperRect4") << printer << QPageLayout::Portrait << true << 600 << true;
+ QTest::newRow("paperRect5") << printer << QPageLayout::Portrait << false << 600 << true;
+ QTest::newRow("paperRect6") << printer << QPageLayout::Landscape << true << 600 << true;
+ QTest::newRow("paperRect7") << printer << QPageLayout::Landscape << false << 600 << true;
+ QTest::newRow("paperRect8") << printer << QPageLayout::Portrait << true << 1200 << true;
+ QTest::newRow("paperRect9") << printer << QPageLayout::Portrait << false << 1200 << true;
+ QTest::newRow("paperRect10") << printer << QPageLayout::Landscape << true << 1200 << true;
+ QTest::newRow("paperRect11") << printer << QPageLayout::Landscape << false << 1200 << true;
// page rect
- QTest::newRow("pageRect0") << printer << QPrinter::Portrait << true << 300 << false;
- QTest::newRow("pageRect1") << printer << QPrinter::Portrait << false << 300 << false;
- QTest::newRow("pageRect2") << printer << QPrinter::Landscape << true << 300 << false;
- QTest::newRow("pageRect3") << printer << QPrinter::Landscape << false << 300 << false;
- QTest::newRow("pageRect4") << printer << QPrinter::Portrait << true << 600 << false;
- QTest::newRow("pageRect5") << printer << QPrinter::Portrait << false << 600 << false;
- QTest::newRow("pageRect6") << printer << QPrinter::Landscape << true << 600 << false;
- QTest::newRow("pageRect7") << printer << QPrinter::Landscape << false << 600 << false;
- QTest::newRow("pageRect8") << printer << QPrinter::Portrait << true << 1200 << false;
- QTest::newRow("pageRect9") << printer << QPrinter::Portrait << false << 1200 << false;
- QTest::newRow("pageRect10") << printer << QPrinter::Landscape << true << 1200 << false;
- QTest::newRow("pageRect11") << printer << QPrinter::Landscape << false << 1200 << false;
+ QTest::newRow("pageRect0") << printer << QPageLayout::Portrait << true << 300 << false;
+ QTest::newRow("pageRect1") << printer << QPageLayout::Portrait << false << 300 << false;
+ QTest::newRow("pageRect2") << printer << QPageLayout::Landscape << true << 300 << false;
+ QTest::newRow("pageRect3") << printer << QPageLayout::Landscape << false << 300 << false;
+ QTest::newRow("pageRect4") << printer << QPageLayout::Portrait << true << 600 << false;
+ QTest::newRow("pageRect5") << printer << QPageLayout::Portrait << false << 600 << false;
+ QTest::newRow("pageRect6") << printer << QPageLayout::Landscape << true << 600 << false;
+ QTest::newRow("pageRect7") << printer << QPageLayout::Landscape << false << 600 << false;
+ QTest::newRow("pageRect8") << printer << QPageLayout::Portrait << true << 1200 << false;
+ QTest::newRow("pageRect9") << printer << QPageLayout::Portrait << false << 1200 << false;
+ QTest::newRow("pageRect10") << printer << QPageLayout::Landscape << true << 1200 << false;
+ QTest::newRow("pageRect11") << printer << QPageLayout::Landscape << false << 1200 << false;
}
void tst_QPrinter::testPageRectAndPaperRect()
{
QFETCH(PrinterPtr, printer);
QFETCH(bool, withPainter);
- QFETCH(QPrinter::Orientation, orientation);
+ QFETCH(QPageLayout::Orientation, orientation);
QFETCH(int, resolution);
QFETCH(bool, doPaperRect);
QPainter *painter = 0;
- printer->setOrientation(orientation);
+ printer->setPageOrientation(orientation);
printer->setOutputFileName(testFileName(QLatin1String("silly"), QString()));
- QRect pageRect = doPaperRect ? printer->paperRect() : printer->pageRect();
+ QRect pageRect = (doPaperRect ? printer->paperRect(QPrinter::DevicePixel) : printer->pageRect(QPrinter::DevicePixel)).toRect();
float inchesX = float(pageRect.width()) / float(printer->resolution());
float inchesY = float(pageRect.height()) / float(printer->resolution());
printer->setResolution(resolution);
if (withPainter)
painter = new QPainter(printer.data());
- QRect otherRect = doPaperRect ? printer->paperRect() : printer->pageRect();
+ QRect otherRect = (doPaperRect ? printer->paperRect(QPrinter::DevicePixel) : printer->pageRect(QPrinter::DevicePixel)).toRect();
float otherInchesX = float(otherRect.width()) / float(printer->resolution());
float otherInchesY = float(otherRect.height()) / float(printer->resolution());
if (painter != 0)
@@ -261,8 +255,8 @@ void tst_QPrinter::testPageRectAndPaperRect()
QVERIFY(qAbs(otherInchesX - inchesX) < 0.01);
QVERIFY(qAbs(otherInchesY - inchesY) < 0.01);
- QVERIFY(printer->orientation() == QPrinter::Portrait || pageRect.width() > pageRect.height());
- QVERIFY(printer->orientation() != QPrinter::Portrait || pageRect.width() < pageRect.height());
+ QVERIFY(printer->pageLayout().orientation() == QPageLayout::Portrait || pageRect.width() > pageRect.height());
+ QVERIFY(printer->pageLayout().orientation() != QPageLayout::Portrait || pageRect.width() < pageRect.height());
}
void tst_QPrinter::testSetOptions()
@@ -295,34 +289,34 @@ void tst_QPrinter::testSetOptions()
void tst_QPrinter::testMargins_data()
{
QTest::addColumn<PrinterPtr>("printer");
- QTest::addColumn<QPrinter::Orientation>("orientation");
+ QTest::addColumn<QPageLayout::Orientation>("orientation");
QTest::addColumn<bool>("fullpage");
- QTest::addColumn<QPrinter::PageSize>("pagesize");
+ QTest::addColumn<QPageSize::PageSizeId>("pagesize");
QTest::addColumn<bool>("withPainter");
const PrinterPtr printer(new QPrinter);
- QTest::newRow("data0") << printer << QPrinter::Portrait << true << QPrinter::A4 << false;
- QTest::newRow("data1") << printer << QPrinter::Landscape << true << QPrinter::A4 << false;
- QTest::newRow("data2") << printer << QPrinter::Landscape << false << QPrinter::A4 << false;
- QTest::newRow("data3") << printer << QPrinter::Portrait << false << QPrinter::A4 << false;
- QTest::newRow("data4") << printer << QPrinter::Portrait << true << QPrinter::A4 << true;
- QTest::newRow("data5") << printer << QPrinter::Landscape << true << QPrinter::A4 << true;
- QTest::newRow("data6") << printer << QPrinter::Landscape << false << QPrinter::A4 << true;
- QTest::newRow("data7") << printer << QPrinter::Portrait << false << QPrinter::A4 << true;
+ QTest::newRow("data0") << printer << QPageLayout::Portrait << true << QPageSize::A4 << false;
+ QTest::newRow("data1") << printer << QPageLayout::Landscape << true << QPageSize::A4 << false;
+ QTest::newRow("data2") << printer << QPageLayout::Landscape << false << QPageSize::A4 << false;
+ QTest::newRow("data3") << printer << QPageLayout::Portrait << false << QPageSize::A4 << false;
+ QTest::newRow("data4") << printer << QPageLayout::Portrait << true << QPageSize::A4 << true;
+ QTest::newRow("data5") << printer << QPageLayout::Landscape << true << QPageSize::A4 << true;
+ QTest::newRow("data6") << printer << QPageLayout::Landscape << false << QPageSize::A4 << true;
+ QTest::newRow("data7") << printer << QPageLayout::Portrait << false << QPageSize::A4 << true;
}
void tst_QPrinter::testMargins()
{
QFETCH(PrinterPtr, printer);
QFETCH(bool, withPainter);
- QFETCH(QPrinter::Orientation, orientation);
- QFETCH(QPrinter::PageSize, pagesize);
+ QFETCH(QPageLayout::Orientation, orientation);
+ QFETCH(QPageSize::PageSizeId, pagesize);
QFETCH(bool, fullpage);
QPainter *painter = 0;
printer->setOutputFileName(testFileName(QLatin1String("silly"), QString()));
- printer->setOrientation(orientation);
+ printer->setPageOrientation(orientation);
printer->setFullPage(fullpage);
- printer->setPageSize(pagesize);
+ printer->setPageSize(QPageSize(pagesize));
if (withPainter)
painter = new QPainter(printer.data());
@@ -330,57 +324,55 @@ void tst_QPrinter::testMargins()
delete painter;
}
-void tst_QPrinter::testMulitpleSets_data()
+void tst_QPrinter::testMultipleSets_data()
{
QTest::addColumn<int>("resolution");
- QTest::addColumn<int>("pageSize");
+ QTest::addColumn<QPageSize::PageSizeId>("pageSize");
QTest::addColumn<int>("widthMMAfter");
QTest::addColumn<int>("heightMMAfter");
- QTest::newRow("lowRes") << int(QPrinter::ScreenResolution) << int(QPrinter::A4) << 210 << 297;
- QTest::newRow("lowResLetter") << int(QPrinter::ScreenResolution) << int(QPrinter::Letter) << 216 << 279;
- QTest::newRow("lowResA5") << int(QPrinter::ScreenResolution) << int(QPrinter::A5) << 148 << 210;
- QTest::newRow("midRes") << int(QPrinter::PrinterResolution) << int(QPrinter::A4) << 210 << 297;
- QTest::newRow("midResLetter") << int(QPrinter::PrinterResolution) << int(QPrinter::Letter) << 216 << 279;
- QTest::newRow("midResA5") << int(QPrinter::PrinterResolution) << int(QPrinter::A5) << 148 << 210;
- QTest::newRow("highRes") << int(QPrinter::HighResolution) << int(QPrinter::A4) << 210 << 297;
- QTest::newRow("highResLetter") << int(QPrinter::HighResolution) << int(QPrinter::Letter) << 216 << 279;
- QTest::newRow("highResA5") << int(QPrinter::HighResolution) << int(QPrinter::A5) << 148 << 210;
+ QTest::newRow("lowRes") << int(QPrinter::ScreenResolution) << QPageSize::A4 << 210 << 297;
+ QTest::newRow("lowResLetter") << int(QPrinter::ScreenResolution) << QPageSize::Letter << 216 << 279;
+ QTest::newRow("lowResA5") << int(QPrinter::ScreenResolution) << QPageSize::A5 << 148 << 210;
+ QTest::newRow("midRes") << int(QPrinter::PrinterResolution) << QPageSize::A4 << 210 << 297;
+ QTest::newRow("midResLetter") << int(QPrinter::PrinterResolution) << QPageSize::Letter << 216 << 279;
+ QTest::newRow("midResA5") << int(QPrinter::PrinterResolution) << QPageSize::A5 << 148 << 210;
+ QTest::newRow("highRes") << int(QPrinter::HighResolution) << QPageSize::A4 << 210 << 297;
+ QTest::newRow("highResLetter") << int(QPrinter::HighResolution) << QPageSize::Letter << 216 << 279;
+ QTest::newRow("highResA5") << int(QPrinter::HighResolution) << QPageSize::A5 << 148 << 210;
}
-static void computePageValue(const QPrinter &printer, int &retWidth, int &retHeight)
-{
- const double Inch2MM = 25.4;
-
- double width = double(printer.paperRect().width()) / printer.logicalDpiX() * Inch2MM;
- double height = double(printer.paperRect().height()) / printer.logicalDpiY() * Inch2MM;
- retWidth = qRound(width);
- retHeight = qRound(height);
-}
-
-void tst_QPrinter::testMulitpleSets()
+void tst_QPrinter::testMultipleSets()
{
// A very simple test, but Mac needs to have its format "validated" if the format is changed
// This takes care of that.
QFETCH(int, resolution);
- QFETCH(int, pageSize);
+ QFETCH(QPageSize::PageSizeId, pageSize);
QFETCH(int, widthMMAfter);
QFETCH(int, heightMMAfter);
QPrinter::PrinterMode mode = QPrinter::PrinterMode(resolution);
- QPrinter::PageSize printerPageSize = QPrinter::PageSize(pageSize);
QPrinter printer(mode);
printer.setFullPage(true);
int paperWidth, paperHeight;
//const int Tolerance = 2;
- computePageValue(printer, paperWidth, paperHeight);
- printer.setPageSize(printerPageSize);
+ const auto computePageValue = [&printer](int &retWidth, int &retHeight)
+ {
+ const double Inch2MM = 25.4;
+ double width = double(printer.paperRect(QPrinter::DevicePixel).width()) / printer.logicalDpiX() * Inch2MM;
+ double height = double(printer.paperRect(QPrinter::DevicePixel).height()) / printer.logicalDpiY() * Inch2MM;
+ retWidth = qRound(width);
+ retHeight = qRound(height);
+ };
+
+ computePageValue(paperWidth, paperHeight);
+ printer.setPageSize(QPageSize(pageSize));
- if (printer.pageSize() != printerPageSize) {
+ if (printer.pageLayout().pageSize().id() != pageSize) {
QSKIP("Current page size is not supported on this printer");
return;
}
@@ -388,18 +380,18 @@ void tst_QPrinter::testMulitpleSets()
QVERIFY(qAbs(printer.widthMM() - widthMMAfter) <= 2);
QVERIFY(qAbs(printer.heightMM() - heightMMAfter) <= 2);
- computePageValue(printer, paperWidth, paperHeight);
+ computePageValue(paperWidth, paperHeight);
QVERIFY(qAbs(paperWidth - widthMMAfter) <= 2);
QVERIFY(qAbs(paperHeight - heightMMAfter) <= 2);
// Set it again and see if it still works.
- printer.setPageSize(printerPageSize);
+ printer.setPageSize(QPageSize(pageSize));
QVERIFY(qAbs(printer.widthMM() - widthMMAfter) <= 2);
QVERIFY(qAbs(printer.heightMM() - heightMMAfter) <= 2);
- printer.setOrientation(QPrinter::Landscape);
- computePageValue(printer, paperWidth, paperHeight);
+ printer.setPageOrientation(QPageLayout::Landscape);
+ computePageValue(paperWidth, paperHeight);
QVERIFY(qAbs(paperWidth - heightMMAfter) <= 2);
QVERIFY(qAbs(paperHeight - widthMMAfter) <= 2);
}
@@ -422,15 +414,15 @@ void tst_QPrinter::testPageMargins_data()
QTest::addColumn<qreal>("top");
QTest::addColumn<qreal>("right");
QTest::addColumn<qreal>("bottom");
- QTest::addColumn<int>("unit");
+ QTest::addColumn<QPageLayout::Unit>("unit");
// Use custom margins that will exceed most printers minimum allowed
- QTest::newRow("data0") << qreal(25.5) << qreal(26.5) << qreal(27.5) << qreal(28.5) << static_cast<int>(QPrinter::Millimeter);
- QTest::newRow("data1") << qreal(55.5) << qreal(56.5) << qreal(57.5) << qreal(58.5) << static_cast<int>(QPrinter::Point);
- QTest::newRow("data2") << qreal(5.5) << qreal(6.5) << qreal(7.5) << qreal(8.5) << static_cast<int>(QPrinter::Inch);
- QTest::newRow("data3") << qreal(5.5) << qreal(6.5) << qreal(7.5) << qreal(8.5) << static_cast<int>(QPrinter::Pica);
- QTest::newRow("data4") << qreal(55.5) << qreal(56.5) << qreal(57.5) << qreal(58.5) << static_cast<int>(QPrinter::Didot);
- QTest::newRow("data5") << qreal(5.5) << qreal(6.5) << qreal(7.5) << qreal(8.5) << static_cast<int>(QPrinter::Cicero);
+ QTest::newRow("data0") << qreal(25.5) << qreal(26.5) << qreal(27.5) << qreal(28.5) << QPageLayout::Millimeter;
+ QTest::newRow("data1") << qreal(55.5) << qreal(56.5) << qreal(57.5) << qreal(58.5) << QPageLayout::Point;
+ QTest::newRow("data2") << qreal(5.5) << qreal(6.5) << qreal(7.5) << qreal(8.5) << QPageLayout::Inch;
+ QTest::newRow("data3") << qreal(5.5) << qreal(6.5) << qreal(7.5) << qreal(8.5) << QPageLayout::Pica;
+ QTest::newRow("data4") << qreal(55.5) << qreal(56.5) << qreal(57.5) << qreal(58.5) << QPageLayout::Didot;
+ QTest::newRow("data5") << qreal(5.5) << qreal(6.5) << qreal(7.5) << qreal(8.5) << QPageLayout::Cicero;
}
void tst_QPrinter::testPageMargins()
@@ -441,50 +433,23 @@ void tst_QPrinter::testPageMargins()
QFETCH(qreal, top);
QFETCH(qreal, right);
QFETCH(qreal, bottom);
- QFETCH(int, unit);
+ QFETCH(QPageLayout::Unit, unit);
QPageLayout layout = QPageLayout(QPageSize(QPageSize::A0), QPageLayout::Portrait,
- QMarginsF(left, top, right, bottom), QPageLayout::Unit(unit));
-
- qreal nLeft, nTop, nRight, nBottom;
-
- obj1.setPageMargins(left, top, right, bottom, QPrinter::Unit(unit));
-
- obj1.getPageMargins(&nLeft, &nTop, &nRight, &nBottom, QPrinter::Millimeter);
- QCOMPARE(nLeft, layout.margins(QPageLayout::Millimeter).left());
- QCOMPARE(nRight, layout.margins(QPageLayout::Millimeter).right());
- QCOMPARE(nTop, layout.margins(QPageLayout::Millimeter).top());
- QCOMPARE(nBottom, layout.margins(QPageLayout::Millimeter).bottom());
-
- obj1.getPageMargins(&nLeft, &nTop, &nRight, &nBottom, QPrinter::Point);
- QCOMPARE(nLeft, layout.margins(QPageLayout::Point).left());
- QCOMPARE(nRight, layout.margins(QPageLayout::Point).right());
- QCOMPARE(nTop, layout.margins(QPageLayout::Point).top());
- QCOMPARE(nBottom, layout.margins(QPageLayout::Point).bottom());
-
- obj1.getPageMargins(&nLeft, &nTop, &nRight, &nBottom, QPrinter::Inch);
- QCOMPARE(nLeft, layout.margins(QPageLayout::Inch).left());
- QCOMPARE(nRight, layout.margins(QPageLayout::Inch).right());
- QCOMPARE(nTop, layout.margins(QPageLayout::Inch).top());
- QCOMPARE(nBottom, layout.margins(QPageLayout::Inch).bottom());
-
- obj1.getPageMargins(&nLeft, &nTop, &nRight, &nBottom, QPrinter::Pica);
- QCOMPARE(nLeft, layout.margins(QPageLayout::Pica).left());
- QCOMPARE(nRight, layout.margins(QPageLayout::Pica).right());
- QCOMPARE(nTop, layout.margins(QPageLayout::Pica).top());
- QCOMPARE(nBottom, layout.margins(QPageLayout::Pica).bottom());
-
- obj1.getPageMargins(&nLeft, &nTop, &nRight, &nBottom, QPrinter::Didot);
- QCOMPARE(nLeft, layout.margins(QPageLayout::Didot).left());
- QCOMPARE(nRight, layout.margins(QPageLayout::Didot).right());
- QCOMPARE(nTop, layout.margins(QPageLayout::Didot).top());
- QCOMPARE(nBottom, layout.margins(QPageLayout::Didot).bottom());
-
- obj1.getPageMargins(&nLeft, &nTop, &nRight, &nBottom, QPrinter::Cicero);
- QCOMPARE(nLeft, layout.margins(QPageLayout::Cicero).left());
- QCOMPARE(nRight, layout.margins(QPageLayout::Cicero).right());
- QCOMPARE(nTop, layout.margins(QPageLayout::Cicero).top());
- QCOMPARE(nBottom, layout.margins(QPageLayout::Cicero).bottom());
+ QMarginsF(left, top, right, bottom), unit);
+
+ const QMarginsF margins(left, top, right, bottom);
+ obj1.setPageMargins(margins, unit);
+
+ for (const auto compareUnit : { QPageLayout::Millimeter,
+ QPageLayout::Point,
+ QPageLayout::Inch,
+ QPageLayout::Pica,
+ QPageLayout::Didot,
+ QPageLayout::Cicero}) {
+ QMarginsF actualMargins = obj1.pageLayout().margins(compareUnit);
+ QCOMPARE(actualMargins, layout.margins(compareUnit));
+ }
}
void tst_QPrinter::errorReporting()
@@ -508,28 +473,29 @@ void tst_QPrinter::testCustomPageSizes()
{
QPrinter p;
- QSizeF customSize(7.0, 11.0);
- p.setPaperSize(customSize, QPrinter::Inch);
+ const QPageSize customSize(QSizeF(7.0, 11.0), QPageSize::Inch);
+ p.setPageSize(customSize);
- QSizeF paperSize = p.paperSize(QPrinter::Inch);
- QCOMPARE(paperSize.width(), customSize.width());
- QCOMPARE(paperSize.height(), customSize.height());
+ QSizeF paperSize = p.pageLayout().pageSize().size(QPageSize::Inch);
+ QCOMPARE(paperSize.width(), customSize.size(QPageSize::Inch).width());
+ QCOMPARE(paperSize.height(), customSize.size(QPageSize::Inch).height());
QPrinter p2(QPrinter::HighResolution);
- p2.setPaperSize(customSize, QPrinter::Inch);
- paperSize = p.paperSize(QPrinter::Inch);
- QCOMPARE(paperSize.width(), customSize.width());
- QCOMPARE(paperSize.height(), customSize.height());
+ p2.setPageSize(customSize);
+ paperSize = p.pageLayout().pageSize().size(QPageSize::Inch);
+ QCOMPARE(paperSize.width(), customSize.size(QPageSize::Inch).width());
+ QCOMPARE(paperSize.height(), customSize.size(QPageSize::Inch).height());
+
+ const QPageSize pageSize = customSize;
+ const QSizeF sizeInPixels = p.paperRect(QPrinter::DevicePixel).size();
- const QSizeF sizeInPixels = p.paperSize(QPrinter::DevicePixel);
QPrinter p3;
- p3.setPaperSize(sizeInPixels, QPrinter::DevicePixel);
- paperSize = p3.paperSize(QPrinter::Inch);
- QCOMPARE(paperSize.width(), customSize.width());
- QCOMPARE(paperSize.height(), customSize.height());
- QPageSize pageSize = p3.pageLayout().pageSize();
- QCOMPARE(pageSize.key(), QString("Custom.504x792"));
- QCOMPARE(pageSize.name(), QString("Custom (504pt x 792pt)"));
+ p3.setPageSize(QPageSize(sizeInPixels / p.resolution(), QPageSize::Inch));
+ paperSize = p3.pageLayout().pageSize().size(QPageSize::Inch);
+ QCOMPARE(paperSize.width(), customSize.size(QPageSize::Inch).width());
+ QCOMPARE(paperSize.height(), customSize.size(QPageSize::Inch).height());
+ QCOMPARE(p3.pageLayout().pageSize().key(), QString("Custom.7x11in"));
+ QCOMPARE(p3.pageLayout().pageSize().name(), QString("Custom (7in x 11in)"));
}
void tst_QPrinter::customPaperSizeAndMargins_data()
@@ -558,34 +524,27 @@ void tst_QPrinter::customPaperSizeAndMargins()
QFETCH(qreal, bottom);
qreal tolerance = 0.05;
- qreal getLeft = 0;
- qreal getRight = 0;
- qreal getTop = 0;
- qreal getBottom = 0;
// Use a custom page size that most printers should support, A4 is 210x297
// TODO Use print device api when available
QSizeF customSize(200.0, 300.0);
+ const QMarginsF margins(left, top, right, bottom);
QPrinter p;
if (pdf)
p.setOutputFormat(QPrinter::PdfFormat);
if (before)
- p.setPageMargins(left, top, right, bottom, QPrinter::Millimeter);
- p.setPaperSize(customSize, QPrinter::Millimeter);
- p.getPageMargins(&getLeft, &getTop, &getRight, &getBottom, QPrinter::Millimeter);
- if (before) {
- QVERIFY(fabs(left - getLeft) < tolerance);
- QVERIFY(fabs(left - getTop) < tolerance);
- QVERIFY(fabs(left - getRight) < tolerance);
- QVERIFY(fabs(left - getBottom) < tolerance);
- } else {
- p.setPageMargins(left, top, right, bottom, QPrinter::Millimeter);
- p.getPageMargins(&getLeft, &getTop, &getRight, &getBottom, QPrinter::Millimeter);
- QVERIFY(fabs(left - getLeft) < tolerance);
- QVERIFY(fabs(left - getTop) < tolerance);
- QVERIFY(fabs(left - getRight) < tolerance);
- QVERIFY(fabs(left - getBottom) < tolerance);
+ p.setPageMargins(margins, QPageLayout::Millimeter);
+ QPageSize customPageSize(customSize, QPageSize::Millimeter);
+ p.setPageSize(customPageSize);
+ QMarginsF actual = p.pageLayout().margins(QPageLayout::Millimeter);
+ if (!before) {
+ p.setPageMargins(margins, QPageLayout::Millimeter);
+ actual = p.pageLayout().margins(QPageLayout::Millimeter);
}
+ QVERIFY(fabs(left - actual.left()) < tolerance);
+ QVERIFY(fabs(top - actual.top()) < tolerance);
+ QVERIFY(fabs(right - actual.right()) < tolerance);
+ QVERIFY(fabs(bottom - actual.bottom()) < tolerance);
}
#if QT_CONFIG(completer) && QT_CONFIG(filedialog)
@@ -707,22 +666,22 @@ void tst_QPrinter::customPaperNameSettingBySize()
{
QPrinter printer(QPrinter::HighResolution);
QPrinterInfo info(printer);
- QList<QPageSize> sizes = info.supportedPageSizes();
+ const QList<QPageSize> sizes = info.supportedPageSizes();
if (sizes.size() == 0)
QSKIP("No printers installed on this machine");
- for (int i=0; i<sizes.size(); i++) {
- printer.setPaperSize(sizes.at(i).size(QPageSize::Millimeter), QPrinter::Millimeter);
- QCOMPARE(sizes.at(i).size(QPageSize::Millimeter), printer.paperSize(QPrinter::Millimeter));
+ for (const auto &pageSize : sizes) {
+ printer.setPageSize(pageSize);
+ QCOMPARE(pageSize.size(QPageSize::Millimeter), printer.pageLayout().pageSize().size(QPageSize::Millimeter));
// Some printers have the same size under different names which can cause a problem for the test
// So we look at all the other sizes to see if one also matches as we don't know which order they are in
- QSizeF paperSize = sizes.at(i).size(QPageSize::Millimeter);
- QString paperName = printer.paperName();
- bool paperNameFound = (sizes.at(i).name() == paperName);
+ const QSizeF paperSize = pageSize.size(QPageSize::Millimeter);
+ const QString paperName = printer.pageLayout().pageSize().name();
+ bool paperNameFound = (pageSize.name() == paperName);
if (!paperNameFound) {
- for (int j = 0; j < sizes.size(); ++j) {
- if (j != i
- && sizes.at(j).size(QPageSize::Millimeter) == paperSize
- && sizes.at(j).name() == paperName) {
+ for (const auto &pageSize2 : sizes) {
+ if (pageSize != pageSize2
+ && pageSize2.size(QPageSize::Millimeter) == paperSize
+ && pageSize2.name() == paperName) {
paperNameFound = true;
break;
}
@@ -732,34 +691,21 @@ void tst_QPrinter::customPaperNameSettingBySize()
if (!paperNameFound) {
qDebug() << "supportedPageSizes() = " << sizes;
QEXPECT_FAIL("", "Paper Name mismatch: please report this failure at bugreports.qt.io", Continue);
- QCOMPARE(sizes.at(i).name(), printer.paperName());
+ QCOMPARE(pageSize.name(), printer.pageLayout().pageSize().name());
}
}
// Check setting a custom size after setting a standard one works
- QSizeF customSize(200, 300);
- printer.setPaperSize(customSize, QPrinter::Millimeter);
- QCOMPARE(printer.paperSize(QPrinter::Millimeter), customSize);
- QCOMPARE(printer.paperSize(), QPrinter::Custom);
+ const QSizeF customSize(200, 300);
+ printer.setPageSize(QPageSize(customSize, QPageSize::Millimeter));
+ QCOMPARE(printer.pageLayout().pageSize().size(QPageSize::Millimeter), customSize);
+ QCOMPARE(printer.pageLayout().pageSize().id(), QPageSize::Custom);
// Finally check setting a standard size after a custom one works
- printer.setPaperSize(sizes.at(0).size(QPageSize::Millimeter), QPrinter::Millimeter);
- QCOMPARE(printer.paperName(), sizes.at(0).name());
- QCOMPARE(printer.paperSize(QPrinter::Millimeter), sizes.at(0).size(QPageSize::Millimeter));
-}
-
-void tst_QPrinter::customPaperNameSettingByName()
-{
- QPrinter printer(QPrinter::HighResolution);
- QPrinterInfo info(printer);
- QList<QPageSize> sizes = info.supportedPageSizes();
- if (sizes.size() == 0)
- QSKIP("No printers installed on this machine");
- for (int i=0; i<sizes.size(); i++) {
- printer.setPaperName(sizes.at(i).name());
- QCOMPARE(sizes.at(i).name(), printer.paperName());
- QCOMPARE(sizes.at(i).size(QPageSize::Millimeter), printer.paperSize(QPrinter::Millimeter));
- }
+ const QPageSize standardPageSize = sizes.first();
+ printer.setPageSize(standardPageSize);
+ QCOMPARE(printer.pageLayout().pageSize().name(), standardPageSize.name());
+ QCOMPARE(printer.pageLayout().pageSize().size(QPageSize::Millimeter), standardPageSize.size(QPageSize::Millimeter));
}
// Test QPrintEngine keys and their QPrinter setters/getters
@@ -772,21 +718,21 @@ void tst_QPrinter::testMultipleKeys()
if (native.outputFormat() == QPrinter::NativeFormat) {
// Check default values
QCOMPARE(native.fullPage(), false);
- QCOMPARE(native.orientation(), QPrinter::Portrait);
+ QCOMPARE(native.pageLayout().orientation(), QPageLayout::Portrait);
QCOMPARE(native.copyCount(), 1);
QCOMPARE(native.collateCopies(), true);
QCOMPARE(native.printRange(), QPrinter::AllPages);
// Change values
native.setFullPage(true);
- native.setOrientation(QPrinter::Landscape);
+ native.setPageOrientation(QPageLayout::Landscape);
native.setCopyCount(9);
native.setCollateCopies(false);
native.setPrintRange(QPrinter::CurrentPage);
// Check changed values
QCOMPARE(native.fullPage(), true);
- QCOMPARE(native.orientation(), QPrinter::Landscape);
+ QCOMPARE(native.pageLayout().orientation(), QPageLayout::Landscape);
QCOMPARE(native.copyCount(), 9);
QCOMPARE(native.collateCopies(), false);
QCOMPARE(native.printRange(), QPrinter::CurrentPage);
@@ -794,21 +740,21 @@ void tst_QPrinter::testMultipleKeys()
// Test value preservation
native.setOutputFormat(QPrinter::PdfFormat);
QCOMPARE(native.fullPage(), true);
- QCOMPARE(native.orientation(), QPrinter::Landscape);
+ QCOMPARE(native.pageLayout().orientation(), QPageLayout::Landscape);
QCOMPARE(native.copyCount(), 9);
QCOMPARE(native.collateCopies(), false);
QCOMPARE(native.printRange(), QPrinter::CurrentPage);
// Change values
native.setFullPage(false);
- native.setOrientation(QPrinter::Portrait);
+ native.setPageOrientation(QPageLayout::Portrait);
native.setCopyCount(5);
native.setCollateCopies(true);
native.setPrintRange(QPrinter::PageRange);
// Check changed values
QCOMPARE(native.fullPage(), false);
- QCOMPARE(native.orientation(), QPrinter::Portrait);
+ QCOMPARE(native.pageLayout().orientation(), QPageLayout::Portrait);
QCOMPARE(native.copyCount(), 5);
QCOMPARE(native.collateCopies(), true);
QCOMPARE(native.printRange(), QPrinter::PageRange);
@@ -891,56 +837,33 @@ void tst_QPrinter::colorMode()
void tst_QPrinter::copyCount()
{
- // copyCount() / setCopyCount() / PPK_CopyCount
- // numCopies() / setNumCopies() / PPK_NumberOfCopies
- // actualNumCopies() / supportsMultipleCopies()
- // PdfFormat: Supported, multiple copies unsupported, default 1
- // NativeFormat, Cups: Supported, multiple copies supported, default 1
- // NativeFormat, Win: Supported, multiple copies supported, default 1
- // NativeFormat, Mac: Supported, multiple copies supported, default 1
-
QPrinter pdf;
pdf.setOutputFormat(QPrinter::PdfFormat);
QCOMPARE(pdf.supportsMultipleCopies(), false);
QCOMPARE(pdf.copyCount(), 1);
- QCOMPARE(pdf.numCopies(), 1);
- QCOMPARE(pdf.actualNumCopies(), 1);
pdf.setCopyCount(9);
QCOMPARE(pdf.copyCount(), 9);
- QCOMPARE(pdf.numCopies(), 9);
- QCOMPARE(pdf.actualNumCopies(), 9);
- pdf.setNumCopies(7);
+ pdf.setCopyCount(7);
QCOMPARE(pdf.copyCount(), 7);
- QCOMPARE(pdf.numCopies(), 7);
- QCOMPARE(pdf.actualNumCopies(), 7);
QPrinter native;
if (native.outputFormat() == QPrinter::NativeFormat) {
// Test default
QCOMPARE(native.supportsMultipleCopies(), true);
QCOMPARE(native.copyCount(), 1);
- QCOMPARE(native.numCopies(), 1);
- QCOMPARE(native.actualNumCopies(), 1);
// Test set/get
native.setCopyCount(9);
QCOMPARE(native.copyCount(), 9);
- QCOMPARE(native.numCopies(), 1);
- QCOMPARE(native.actualNumCopies(), 9);
- native.setNumCopies(7);
+ native.setCopyCount(7);
QCOMPARE(native.copyCount(), 7);
- QCOMPARE(native.numCopies(), 1);
- QCOMPARE(native.actualNumCopies(), 7);
// Test value preservation
native.setOutputFormat(QPrinter::PdfFormat);
QCOMPARE(native.copyCount(), 7);
- QCOMPARE(native.numCopies(), 7);
- QCOMPARE(native.actualNumCopies(), 7);
+
native.setOutputFormat(QPrinter::NativeFormat);
QCOMPARE(native.copyCount(), 7);
- QCOMPARE(native.numCopies(), 1);
- QCOMPARE(native.actualNumCopies(), 7);
} else {
QSKIP("No printers installed, cannot test NativeFormat, please install printers to test");
}
@@ -1060,41 +983,6 @@ void tst_QPrinter::duplex()
}
}
-void tst_QPrinter::doubleSidedPrinting()
-{
- // PdfFormat: Supported, default false
- // NativeFormat, Cups: Supported, default to printer default
- // NativeFormat, Win: Supported, default to printer default
- // NativeFormat, Mac: Supported, default to printer default
-
- QPrinter pdf;
- pdf.setOutputFormat(QPrinter::PdfFormat);
- QCOMPARE(pdf.doubleSidedPrinting(), false);
- pdf.setDoubleSidedPrinting(true);
- QCOMPARE(pdf.doubleSidedPrinting(), false); // pdf doesn't have the concept of duplex
-
- QPrinter native;
- if (native.outputFormat() == QPrinter::NativeFormat) {
- // Test default
- QPrinterInfo printerInfo(native);
- bool expected = (printerInfo.defaultDuplexMode() != QPrinter::DuplexNone);
- QCOMPARE(native.doubleSidedPrinting(), expected);
-
- // Test set/get, changing the expected value if possible
- expected = expected ? false : (printerInfo.supportedDuplexModes().count() > 1);
- native.setDoubleSidedPrinting(expected);
- QCOMPARE(native.doubleSidedPrinting(), expected);
-
- // Test value preservation
- native.setOutputFormat(QPrinter::PdfFormat);
- QCOMPARE(native.doubleSidedPrinting(), expected);
- native.setOutputFormat(QPrinter::NativeFormat);
- QCOMPARE(native.doubleSidedPrinting(), expected);
- } else {
- QSKIP("No printers installed, cannot test NativeFormat, please install printers to test");
- }
-}
-
void tst_QPrinter::fontEmbedding()
{
// fontEmbeddingEnabled() / setFontEmbeddingEnabled() / PPK_FontEmbedding
@@ -1176,44 +1064,44 @@ void tst_QPrinter::fullPage()
void tst_QPrinter::orientation()
{
// orientation() / setOrientation() / PPK_Orientation
- // PdfFormat: Supported, default QPrinter::Portrait
- // NativeFormat, Cups: Supported, default QPrinter::Portrait
- // NativeFormat, Win: Supported, default QPrinter::Portrait
- // NativeFormat, Mac: Supported, default QPrinter::Portrait
+ // PdfFormat: Supported, default QPageLayout::Portrait
+ // NativeFormat, Cups: Supported, default QPageLayout::Portrait
+ // NativeFormat, Win: Supported, default QPageLayout::Portrait
+ // NativeFormat, Mac: Supported, default QPageLayout::Portrait
QPrinter pdf;
pdf.setOutputFormat(QPrinter::PdfFormat);
- QCOMPARE(pdf.orientation(), QPrinter::Portrait);
- pdf.setOrientation(QPrinter::Landscape);
- QCOMPARE(pdf.orientation(), QPrinter::Landscape);
+ QCOMPARE(pdf.pageLayout().orientation(), QPageLayout::Portrait);
+ pdf.setPageOrientation(QPageLayout::Landscape);
+ QCOMPARE(pdf.pageLayout().orientation(), QPageLayout::Landscape);
QPrinter native;
if (native.outputFormat() == QPrinter::NativeFormat) {
// Test default
// TODO Printer specific, need QPrinterInfo::orientation()
- //QCOMPARE(native.orientation(), QPrinter::Portrait);
+ //QCOMPARE(native.orientation(), QPageLayout::Portrait);
// Test set/get
- QPrinter::Orientation expected = QPrinter::Landscape;
- native.setOrientation(expected);
- QCOMPARE(native.orientation(), expected);
+ QPageLayout::Orientation expected = QPageLayout::Landscape;
+ native.setPageOrientation(expected);
+ QCOMPARE(native.pageLayout().orientation(), expected);
// Test value preservation
native.setOutputFormat(QPrinter::PdfFormat);
- QCOMPARE(native.orientation(), expected);
+ QCOMPARE(native.pageLayout().orientation(), expected);
native.setOutputFormat(QPrinter::NativeFormat);
- QCOMPARE(native.orientation(), expected);
+ QCOMPARE(native.pageLayout().orientation(), expected);
// Test set/get
- expected = QPrinter::Portrait;
- native.setOrientation(expected);
- QCOMPARE(native.orientation(), expected);
+ expected = QPageLayout::Portrait;
+ native.setPageOrientation(expected);
+ QCOMPARE(native.pageLayout().orientation(), expected);
// Test value preservation
native.setOutputFormat(QPrinter::PdfFormat);
- QCOMPARE(native.orientation(), expected);
+ QCOMPARE(native.pageLayout().orientation(), expected);
native.setOutputFormat(QPrinter::NativeFormat);
- QCOMPARE(native.orientation(), expected);
+ QCOMPARE(native.pageLayout().orientation(), expected);
} else {
QSKIP("No printers installed, cannot test NativeFormat, please install printers to test");
}
@@ -1295,92 +1183,47 @@ void tst_QPrinter::pageSize()
{
// Note PPK_PaperSize == PPK_PageSize
// pageSize() / setPageSize() / PPK_PageSize
- // PdfFormat: Supported, defaults to QPrinter::A4
+ // PdfFormat: Supported, defaults to QPageSize::A4
// NativeFormat, Cups: Supported, defaults to printer default
// NativeFormat, Win: Supported, defaults to printer default
// NativeFormat, Mac: Supported, must be supported size, defaults to printer default
QPrinter pdf;
pdf.setOutputFormat(QPrinter::PdfFormat);
- QCOMPARE(pdf.pageSize(), QPrinter::A4);
- pdf.setPageSize(QPrinter::A1);
- QCOMPARE(pdf.pageSize(), QPrinter::A1);
+ QCOMPARE(pdf.pageLayout().pageSize().id(), QPageSize::A4);
+ pdf.setPageSize(QPageSize(QPageSize::A1));
+ QCOMPARE(pdf.pageLayout().pageSize().id(), QPageSize::A1);
QPrinter native;
if (native.outputFormat() == QPrinter::NativeFormat) {
// Test default
// TODO Printer specific, need QPrinterInfo::paperSize()
- //QCOMPARE(native.pageSize(), QPrinter::A4);
+ //QCOMPARE(native.pageSize(), QPageSize::A4);
// Test set/get
- QPrinter::PaperSize expected = QPrinter::A4;
+ QPageSize expected(QPageSize::A4);
QPrinterInfo info = QPrinterInfo::printerInfo(native.printerName());
const auto &pageSizes = info.supportedPageSizes();
for (const auto &pageSize : pageSizes) {
- const QPrinter::PaperSize supported = QPrinter::PaperSize(pageSize.id());
- if (supported != QPrinter::Custom && supported != native.paperSize()) {
- expected = supported;
+ const auto supported = pageSize.id();
+ if (supported != QPageSize::Custom && supported != native.pageLayout().pageSize().id()) {
+ expected = QPageSize(supported);
break;
}
}
native.setPageSize(expected);
- QCOMPARE(native.pageSize(), expected);
+ QCOMPARE(native.pageLayout().pageSize().id(), expected.id());
// Test value preservation
native.setOutputFormat(QPrinter::PdfFormat);
- QCOMPARE(native.pageSize(), expected);
+ QCOMPARE(native.pageLayout().pageSize().id(), expected.id());
native.setOutputFormat(QPrinter::NativeFormat);
- QCOMPARE(native.pageSize(), expected);
+ QCOMPARE(native.pageLayout().pageSize().id(), expected.id());
} else {
QSKIP("No printers installed, cannot test NativeFormat, please install printers to test");
}
}
-void tst_QPrinter::paperSize()
-{
- // PPK_PaperSize == PPK_PageSize
- // paperSize() / setPaperSize() / PPK_PaperSize
- // pageSize() / setPageSize() / PPK_PageSize
- // PdfFormat: Supported, defaults to QPrinter::A4
- // NativeFormat, Cups: Supported, defaults to printer default
- // NativeFormat, Win: Supported, defaults to printer default
- // NativeFormat, Mac: Supported, must be supported size, defaults to printer default
-
- QPrinter pdf;
- pdf.setOutputFormat(QPrinter::PdfFormat);
- QCOMPARE(pdf.paperSize(), QPrinter::A4);
- pdf.setPaperSize(QPrinter::A1);
- QCOMPARE(pdf.paperSize(), QPrinter::A1);
-
- QPrinter native;
- if (native.outputFormat() == QPrinter::NativeFormat) {
- // Test default
- // TODO Printer specific, need QPrinterInfo::paperSize()
- //QCOMPARE(native.paperSize(), QPrinter::A4);
-
- // Test set/get
- QPrinter::PaperSize expected = QPrinter::A4;
- QPrinterInfo info = QPrinterInfo::printerInfo(native.printerName());
- const auto &pageSizes = info.supportedPageSizes();
- for (const auto &pageSize : pageSizes) {
- const QPrinter::PaperSize supported = QPrinter::PaperSize(pageSize.id());
- if (supported != QPrinter::Custom && supported != native.paperSize()) {
- expected = supported;
- break;
- }
- }
- native.setPaperSize(expected);
- QCOMPARE(native.paperSize(), expected);
-
- // Test value preservation
- native.setOutputFormat(QPrinter::PdfFormat);
- QCOMPARE(native.paperSize(), expected);
- native.setOutputFormat(QPrinter::NativeFormat);
- QCOMPARE(native.paperSize(), expected);
- } else {
- QSKIP("No printers installed, cannot test NativeFormat, please install printers to test");
- }
-}
void tst_QPrinter::paperSource()
{
@@ -1693,51 +1536,6 @@ void tst_QPrinter::supportedResolutions()
}
}
-void tst_QPrinter::windowsPageSize()
-{
- // winPageSize() / setWinPageSize() / PPK_WindowsPageSize
- // PdfFormat: Supported, defaults to printer default
- // NativeFormat, Cups: Supported, defaults to printer default
- // NativeFormat, Win: Supported, defaults to printer default
- // NativeFormat, Mac: Supported, defaults to printer default
-
- QPrinter pdf;
- pdf.setOutputFormat(QPrinter::PdfFormat);
- QCOMPARE(pdf.winPageSize(), 9); // DMPAPER_A4
- pdf.setWinPageSize(1); // DMPAPER_LETTER
- QCOMPARE(pdf.winPageSize(), 1);
-
- QPrinter native;
- if (native.outputFormat() == QPrinter::NativeFormat) {
- // Test set/get
- native.setPaperSize(QPrinter::A4);
- QCOMPARE(native.pageSize(), QPrinter::A4);
- QCOMPARE(native.winPageSize(), 9); // DMPAPER_A4
-
- native.setPaperSize(QPrinter::Letter);
- QCOMPARE(native.pageSize(), QPrinter::Letter);
- QCOMPARE(native.winPageSize(), 1); // DMPAPER_LETTER
-
- native.setWinPageSize(9); // DMPAPER_A4
- QCOMPARE(native.pageSize(), QPrinter::A4);
- QCOMPARE(native.winPageSize(), 9); // DMPAPER_A4
-
- native.setWinPageSize(1); // DMPAPER_LETTER
- QCOMPARE(native.pageSize(), QPrinter::Letter);
- QCOMPARE(native.winPageSize(), 1); // DMPAPER_LETTER
-
- // Test value preservation
- native.setOutputFormat(QPrinter::PdfFormat);
- QCOMPARE(native.pageSize(), QPrinter::Letter);
- QCOMPARE(native.winPageSize(), 1); // DMPAPER_LETTER
- native.setOutputFormat(QPrinter::NativeFormat);
- QCOMPARE(native.pageSize(), QPrinter::Letter);
- QCOMPARE(native.winPageSize(), 1); // DMPAPER_LETTER
- } else {
- QSKIP("No printers installed, cannot test NativeFormat, please install printers to test");
- }
-}
-
// Test QPrinter setters/getters for non-QPrintEngine options
void tst_QPrinter::outputFormat()
@@ -1778,10 +1576,10 @@ void tst_QPrinter::testPageMetrics_data()
QTest::addColumn<qreal>("topMMf");
QTest::addColumn<qreal>("bottomMMf");
- QTest::newRow("PDF A4") << int(QPrinter::PdfFormat) << int(QPrinter::A4) << 210.0 << 297.0 << false << 0.0 << 0.0 << 0.0 << 0.0;
- QTest::newRow("PDF A4 Margins") << int(QPrinter::PdfFormat) << int(QPrinter::A4) << 210.0 << 297.0 << true << 20.0 << 30.0 << 40.0 << 50.0;
- QTest::newRow("Native A4") << int(QPrinter::NativeFormat) << int(QPrinter::A4) << 210.0 << 297.0 << false << 0.0 << 0.0 << 0.0 << 0.0;
- QTest::newRow("Native A4 Margins") << int(QPrinter::NativeFormat) << int(QPrinter::A4) << 210.0 << 297.0 << true << 20.0 << 30.0 << 40.0 << 50.0;
+ QTest::newRow("PDF A4") << int(QPrinter::PdfFormat) << int(QPageSize::A4) << 210.0 << 297.0 << false << 0.0 << 0.0 << 0.0 << 0.0;
+ QTest::newRow("PDF A4 Margins") << int(QPrinter::PdfFormat) << int(QPageSize::A4) << 210.0 << 297.0 << true << 20.0 << 30.0 << 40.0 << 50.0;
+ QTest::newRow("Native A4") << int(QPrinter::NativeFormat) << int(QPageSize::A4) << 210.0 << 297.0 << false << 0.0 << 0.0 << 0.0 << 0.0;
+ QTest::newRow("Native A4 Margins") << int(QPrinter::NativeFormat) << int(QPageSize::A4) << 210.0 << 297.0 << true << 20.0 << 30.0 << 40.0 << 50.0;
QTest::newRow("PDF Portrait") << int(QPrinter::PdfFormat) << -1 << 200.0 << 300.0 << false << 0.0 << 0.0 << 0.0 << 0.0;
QTest::newRow("PDF Portrait Margins") << int(QPrinter::PdfFormat) << -1 << 200.0 << 300.0 << true << 20.0 << 30.0 << 40.0 << 50.0;
@@ -1805,57 +1603,52 @@ void tst_QPrinter::testPageMetrics()
QFETCH(qreal, topMMf);
QFETCH(qreal, bottomMMf);
- QSizeF sizeMMf = QSizeF(widthMMf, heightMMf);
+ const QSizeF sizeMMf = QSizeF(widthMMf, heightMMf);
QPrinter printer;
printer.setOutputFormat(QPrinter::OutputFormat(outputFormat));
if (printer.outputFormat() != QPrinter::OutputFormat(outputFormat))
QSKIP("Please install a native printer to run this test");
QCOMPARE(printer.outputFormat(), QPrinter::OutputFormat(outputFormat));
- QCOMPARE(printer.orientation(), QPrinter::Portrait);
+ QCOMPARE(printer.pageLayout().orientation(), QPageLayout::Portrait);
if (setMargins) {
// Setup the given margins
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);
+ printer.setPageMargins(margins);
+ QCOMPARE(printer.pageLayout().margins(), margins);
}
-
// Set the given size, in Portrait mode
if (pageSize < 0) {
- printer.setPageSizeMM(sizeMMf);
- QCOMPARE(printer.pageSize(), QPrinter::Custom);
+ printer.setPageSize(QPageSize(sizeMMf, QPageSize::Millimeter));
+ QCOMPARE(printer.pageLayout().pageSize().id(), QPageSize::Custom);
} else {
- printer.setPageSize(QPrinter::PageSize(pageSize));
- QCOMPARE(printer.pageSize(), QPrinter::PageSize(pageSize));
+ printer.setPageSize(QPageSize(QPageSize::PageSizeId(pageSize)));
+ QCOMPARE(printer.pageLayout().pageSize().id(), QPageSize::PageSizeId(pageSize));
}
- QCOMPARE(printer.orientation(), QPrinter::Portrait);
+ QCOMPARE(printer.pageLayout().orientation(), QPageLayout::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);
+ QMarginsF margins(leftMMf, topMMf, rightMMf, bottomMMf);
+ QCOMPARE(printer.pageLayout().margins(), margins);
} 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.pageLayout().margins(QPageLayout::Millimeter).left();
+ rightMMf = printer.pageLayout().margins(QPageLayout::Millimeter).right();
+ topMMf = printer.pageLayout().margins(QPageLayout::Millimeter).top();
+ bottomMMf = printer.pageLayout().margins(QPageLayout::Millimeter).bottom();
}
- // QPagedPaintDevice::pageSizeMM() always returns Portrait
- QCOMPARE(printer.pageSizeMM(), sizeMMf);
+ // QPageLayout::pageSize() always returns Portrait
+ QCOMPARE(printer.pageLayout().pageSize().size(QPageSize::Millimeter), sizeMMf);
- // QPrinter::paperSize() always returns set orientation
- QCOMPARE(printer.paperSize(QPrinter::Millimeter), sizeMMf);
+ // QPrinter::paperRect() always returns set orientation
+ QCOMPARE(printer.paperRect(QPrinter::Millimeter).size(), sizeMMf);
- // QPagedPaintDevice::widthMM() and heightMM() are paint metrics and always return set orientation
+
+ // QPaintDevice::widthMM() and heightMM() are paint metrics and always return set orientation
QCOMPARE(printer.widthMM(), qRound(widthMMf - leftMMf - rightMMf));
QCOMPARE(printer.heightMM(), qRound(heightMMf - topMMf - bottomMMf));
@@ -1867,35 +1660,33 @@ void tst_QPrinter::testPageMetrics()
// Now switch to Landscape mode, size should be unchanged, but rect and metrics should change
- printer.setOrientation(QPrinter::Landscape);
+ printer.setPageOrientation(QPageLayout::Landscape);
if (pageSize < 0) {
- QCOMPARE(printer.pageSize(), QPrinter::Custom);
+ QCOMPARE(printer.pageLayout().pageSize().id(), QPageSize::Custom);
} else {
- QCOMPARE(printer.pageSize(), QPrinter::PageSize(pageSize));
+ QCOMPARE(printer.pageLayout().pageSize().id(), QPageSize::PageSizeId(pageSize));
}
- QCOMPARE(printer.orientation(), QPrinter::Landscape);
+ QCOMPARE(printer.pageLayout().orientation(), QPageLayout::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);
+ QMarginsF margins(leftMMf, topMMf, rightMMf, bottomMMf);
+ QCOMPARE(printer.pageLayout().margins(), margins);
} 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.pageLayout().margins(QPageLayout::Millimeter).left();
+ rightMMf = printer.pageLayout().margins(QPageLayout::Millimeter).right();
+ topMMf = printer.pageLayout().margins(QPageLayout::Millimeter).top();
+ bottomMMf = printer.pageLayout().margins(QPageLayout::Millimeter).bottom();
}
- // QPagedPaintDevice::pageSizeMM() always returns Portrait
- QCOMPARE(printer.pageSizeMM(), sizeMMf);
+ // QPageLayout::pageSize() always returns Portrait
+ QCOMPARE(printer.pageLayout().pageSize().size(QPageSize::Millimeter), sizeMMf);
- // QPrinter::paperSize() always returns set orientation
- QCOMPARE(printer.paperSize(QPrinter::Millimeter), sizeMMf.transposed());
+ // QPrinter::paperRect() always returns set orientation
+ QCOMPARE(printer.paperRect(QPrinter::Millimeter).size(), sizeMMf.transposed());
- // QPagedPaintDevice::widthMM() and heightMM() are paint metrics and always return set orientation
+ // QPaintDevice::widthMM() and heightMM() are paint metrics and always return set orientation
QCOMPARE(printer.widthMM(), qRound(heightMMf - leftMMf - rightMMf));
QCOMPARE(printer.heightMM(), qRound(widthMMf - topMMf - bottomMMf));
@@ -1905,36 +1696,33 @@ void tst_QPrinter::testPageMetrics()
// QPrinter::pageRect() always returns set orientation
QCOMPARE(printer.pageRect(QPrinter::Millimeter), QRectF(leftMMf, topMMf, heightMMf - leftMMf - rightMMf, widthMMf - topMMf - bottomMMf));
-
// Now while in Landscape mode, set the size again, results should be the same
if (pageSize < 0) {
- printer.setPageSizeMM(sizeMMf);
- QCOMPARE(printer.pageSize(), QPrinter::Custom);
+ printer.setPageSize(QPageSize(sizeMMf, QPageSize::Millimeter));
+ QCOMPARE(printer.pageLayout().pageSize().id(), QPageSize::Custom);
} else {
- printer.setPageSize(QPrinter::PageSize(pageSize));
- QCOMPARE(printer.pageSize(), QPrinter::PageSize(pageSize));
+ printer.setPageSize(QPageSize(QPageSize::PageSizeId(pageSize)));
+ QCOMPARE(printer.pageLayout().pageSize().id(), QPageSize::PageSizeId(pageSize));
}
- QCOMPARE(printer.orientation(), QPrinter::Landscape);
+ QCOMPARE(printer.pageLayout().orientation(), QPageLayout::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);
+ QMarginsF margins(leftMMf, topMMf, rightMMf, bottomMMf);
+ QCOMPARE(printer.pageLayout().margins(), margins);
} 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.pageLayout().margins(QPageLayout::Millimeter).left();
+ rightMMf = printer.pageLayout().margins(QPageLayout::Millimeter).right();
+ topMMf = printer.pageLayout().margins(QPageLayout::Millimeter).top();
+ bottomMMf = printer.pageLayout().margins(QPageLayout::Millimeter).bottom();
}
- // QPagedPaintDevice::pageSizeMM() always returns Portrait
- QCOMPARE(printer.pageSizeMM(), sizeMMf);
+ // QPageLayout::pageSize() always returns Portrait
+ QCOMPARE(printer.pageLayout().pageSize().size(QPageSize::Millimeter), sizeMMf);
- // QPrinter::paperSize() always returns set orientation
- QCOMPARE(printer.paperSize(QPrinter::Millimeter), sizeMMf.transposed());
+ // QPrinter::paperRect() always returns set orientation
+ QCOMPARE(printer.paperRect(QPrinter::Millimeter).size(), sizeMMf.transposed());
// QPagedPaintDevice::widthMM() and heightMM() are paint metrics and always return set orientation
QCOMPARE(printer.widthMM(), qRound(heightMMf - leftMMf - rightMMf));
diff --git a/tests/manual/dialogs/printdialogpanel.cpp b/tests/manual/dialogs/printdialogpanel.cpp
index 7f834399e4..29dc33285b 100644
--- a/tests/manual/dialogs/printdialogpanel.cpp
+++ b/tests/manual/dialogs/printdialogpanel.cpp
@@ -53,10 +53,7 @@
#include <QDebug>
#include <QTextStream>
#include <QDir>
-
-#if QT_VERSION >= 0x050000
-# include <QScreen>
-#endif
+#include <QScreen>
const FlagData printerModeComboData[] =
{
@@ -65,42 +62,6 @@ const FlagData printerModeComboData[] =
{"HighResolution", QPrinter::HighResolution}
};
-#if QT_VERSION < 0x050300
-const FlagData pageSizeComboData[] =
-{
- {"A4", QPrinter::A4},
- {"B5", QPrinter::B5},
- {"Letter", QPrinter::Letter},
- {"Legal", QPrinter::Legal},
- {"Executive", QPrinter::Executive},
- {"A0", QPrinter::A0},
- {"A1", QPrinter::A1},
- {"A2", QPrinter::A2},
- {"A3", QPrinter::A3},
- {"A5", QPrinter::A5},
- {"A6", QPrinter::A6},
- {"A7", QPrinter::A7},
- {"A8", QPrinter::A8},
- {"A9", QPrinter::A9},
- {"B0", QPrinter::B0},
- {"B1", QPrinter::B1},
- {"B10", QPrinter::B10},
- {"B2", QPrinter::B2},
- {"B3", QPrinter::B3},
- {"B4", QPrinter::B4},
- {"B6", QPrinter::B6},
- {"B7", QPrinter::B7},
- {"B8", QPrinter::B8},
- {"B9", QPrinter::B9},
- {"C5E", QPrinter::C5E},
- {"Comm10E", QPrinter::Comm10E},
- {"DLE", QPrinter::DLE},
- {"Folio", QPrinter::Folio},
- {"Ledger", QPrinter::Ledger},
- {"Tabloid", QPrinter::Tabloid},
- {"Custom", QPrinter::Custom}
-};
-#endif
const FlagData printRangeComboData[] =
{
@@ -197,9 +158,7 @@ QTextStream &operator<<(QTextStream &s, const QRectF &rect)
QTextStream &operator<<(QTextStream &s, const QPrinter &printer)
{
s << '"' << printer.printerName() << "\"\nPaper #" <<printer.paperSize()
-#if QT_VERSION >= 0x050000
<< " \"" << printer.paperName() << '"'
-#endif
<< (printer.orientation() == QPrinter::Portrait ? ", Portrait" : ", Landscape");
if (printer.fullPage())
s << ", full page";
@@ -208,9 +167,7 @@ QTextStream &operator<<(QTextStream &s, const QPrinter &printer)
<< printer.paperSize(QPrinter::Millimeter) << "mm "
<< "\n " << printer.paperSize(QPrinter::DevicePixel) << "device pt "
<< printer.paperSize(QPrinter::Inch) << "inch "
-#if QT_VERSION >= 0x050000
<< "\nPagedPaintDevSize: " << printer.pageSizeMM() << "mm"
-#endif
<< "\nLogical resolution : " << printer.logicalDpiX() << ',' << printer.logicalDpiY() << "DPI"
<< "\nPhysical resolution: " << printer.physicalDpiX() << ',' << printer.physicalDpiY() << "DPI"
<< "\nPaperRect: " << printer.paperRect(QPrinter::Point) << "pt "
@@ -290,9 +247,7 @@ static bool print(QPrinter *printer, QString *errorMessage)
QString msg;
QTextStream str(&msg);
str << "Qt "<< QT_VERSION_STR;
-#if QT_VERSION >= 0x050000
str << ' ' << QGuiApplication::platformName();
-#endif
str << ' ' << QDateTime::currentDateTime().toString()
<< "\nFont: " << font.family() << ' ' << font.pointSize() << '\n'
<< *printer;
@@ -346,10 +301,6 @@ public slots:
PrintDialogPanel::PrintDialogPanel(QWidget *parent)
: QWidget(parent), m_blockSignals(true)
{
-#if QT_VERSION < 0x050300
- m_printerLayout.setOutputFormat(QPrinter::PdfFormat);
-#endif
-
m_panel.setupUi(this);
// Setup the Create box
@@ -360,14 +311,10 @@ PrintDialogPanel::PrintDialogPanel(QWidget *parent)
// Setup the Page Layout box
populateCombo(m_panel.m_unitsCombo, unitsComboData, sizeof(unitsComboData)/sizeof(FlagData));
connect(m_panel.m_unitsCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(unitsChanged()));
-#if QT_VERSION >= 0x050300
for (int i = QPageSize::A4; i < QPageSize::LastPageSize; ++i) {
QPageSize::PageSizeId id = QPageSize::PageSizeId(i);
m_panel.m_pageSizeCombo->addItem(QPageSize::name(id), QVariant(id));
}
-#else
- populateCombo(m_panel.m_pageSizeCombo, pageSizeComboData, sizeof(pageSizeComboData)/sizeof(FlagData));
-#endif
connect(m_panel.m_pageSizeCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(pageSizeChanged()));
connect(m_panel.m_pageWidth, SIGNAL(valueChanged(double)), this, SLOT(pageDimensionsChanged()));
connect(m_panel.m_pageHeight, SIGNAL(valueChanged(double)), this, SLOT(pageDimensionsChanged()));
@@ -382,13 +329,8 @@ PrintDialogPanel::PrintDialogPanel(QWidget *parent)
// Setup the Print Job box
m_panel.m_printerCombo->addItem(tr("Print to PDF"), QVariant("PdfFormat"));
-#if QT_VERSION >= 0x050300
foreach (const QString &name, QPrinterInfo::availablePrinterNames())
m_panel.m_printerCombo->addItem(name, QVariant(name));
-#else
- foreach (const QPrinterInfo &printer, QPrinterInfo::availablePrinters())
- m_panel.m_printerCombo->addItem(printer.printerName(), QVariant(printer.printerName()));
-#endif
connect(m_panel.m_printerCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(printerChanged()));
populateCombo(m_panel.m_printRangeCombo, printRangeComboData, sizeof(printRangeComboData)/sizeof(FlagData));
populateCombo(m_panel.m_pageOrderCombo, pageOrderComboData, sizeof(pageOrderComboData)/sizeof(FlagData));
@@ -462,19 +404,7 @@ void PrintDialogPanel::applySettings(QPrinter *printer) const
printer->setColorMode(comboBoxValue<QPrinter::ColorMode>(m_panel.m_colorModeCombo));
printer->setResolution(m_panel.m_resolution->value());
-#if QT_VERSION >= 0x050300
printer->setPageLayout(m_pageLayout);
-#else
- if (m_printerLayout.pageSize() == QPrinter::Custom)
- printer->setPaperSize(customPageSize(), m_units);
- else
- printer->setPageSize(m_printerLayout.pageSize());
- printer->setOrientation(m_printerLayout.orientation());
- printer->setFullPage(m_printerLayout.fullPage());
- double left, top, right, bottom;
- m_printerLayout.getPageMargins(&left, &top, &right, &bottom, m_units);
- printer->setPageMargins(left, top, right, bottom, m_units);
-#endif
}
// Retrieve the settings from the QPrinter
@@ -508,26 +438,13 @@ void PrintDialogPanel::retrieveSettings(const QPrinter *printer)
m_panel.availPaperSourceLabel->setText(QLatin1String("N/A"));
#endif
-#if QT_VERSION >= 0x050300
m_pageLayout = printer->pageLayout();
-#else
- if (printer->pageSize() == QPrinter::Custom)
- m_printerLayout.setPaperSize(customPageSize(), m_units);
- else
- m_printerLayout.setPageSize(printer->pageSize());
- m_printerLayout.setOrientation(printer->orientation());
- m_printerLayout.setFullPage(printer->fullPage());
- double left, top, right, bottom;
- printer->getPageMargins(&left, &top, &right, &bottom, m_units);
- m_printerLayout.setPageMargins(left, top, right, bottom, m_units);
-#endif
updatePageLayoutWidgets();
}
void PrintDialogPanel::updatePageLayoutWidgets()
{
m_blockSignals = true;
-#if QT_VERSION >= 0x050300
setComboBoxValue(m_panel.m_unitsCombo, m_pageLayout.units());
setComboBoxValue(m_panel.m_pageSizeCombo, m_pageLayout.pageSize().id());
QSizeF sizef = m_pageLayout.pageSize().size(QPageSize::Unit(m_pageLayout.units()));
@@ -539,24 +456,7 @@ void PrintDialogPanel::updatePageLayoutWidgets()
m_panel.m_bottomMargin->setValue(m_pageLayout.margins().bottom());
setComboBoxValue(m_panel.m_layoutModeCombo, m_pageLayout.mode());
QRectF rectf = m_pageLayout.paintRect();
-#else
- setComboBoxValue(m_panel.m_unitsCombo, m_units);
- setComboBoxValue(m_panel.m_pageSizeCombo, m_printerLayout.pageSize());
- QSizeF sizef = m_printerLayout.paperSize(m_units);
- bool custom = (m_printerLayout.pageSize() == QPrinter::Custom);
- setComboBoxValue(m_panel.m_orientationCombo, m_printerLayout.orientation());
- double left, top, right, bottom;
- m_printerLayout.getPageMargins(&left, &top, &right, &bottom, m_units);
- m_panel.m_leftMargin->setValue(left);
- m_panel.m_topMargin->setValue(top);
- m_panel.m_rightMargin->setValue(right);
- m_panel.m_bottomMargin->setValue(bottom);
- if (m_printerLayout.fullPage())
- setComboBoxValue(m_panel.m_layoutModeCombo, QPageLayout::FullPageMode);
- else
- setComboBoxValue(m_panel.m_layoutModeCombo, QPageLayout::StandardMode);
- QRectF rectf = m_printerLayout.pageRect(m_units);
-#endif
+
m_panel.m_pageWidth->setValue(sizef.width());
m_panel.m_pageHeight->setValue(sizef.height());
m_panel.m_pageWidth->setEnabled(custom);
@@ -603,11 +503,7 @@ void PrintDialogPanel::unitsChanged()
{
if (m_blockSignals)
return;
-#if QT_VERSION >= 0x050300
m_pageLayout.setUnits(comboBoxValue<QPageLayout::Unit>(m_panel.m_unitsCombo));
-#else
- m_units = comboBoxValue<QPrinter::Unit>(m_panel.m_unitsCombo);
-#endif
updatePageLayoutWidgets();
}
@@ -615,7 +511,6 @@ void PrintDialogPanel::pageSizeChanged()
{
if (m_blockSignals)
return;
-#if QT_VERSION >= 0x050300
const QPageSize::PageSizeId pageSizeId = comboBoxValue<QPageSize::PageSizeId>(m_panel.m_pageSizeCombo);
QPageSize pageSize;
if (pageSizeId == QPageSize::Custom)
@@ -623,13 +518,6 @@ void PrintDialogPanel::pageSizeChanged()
else
pageSize = QPageSize(pageSizeId);
m_pageLayout.setPageSize(pageSize);
-#else
- const QPrinter::PageSize pageSize = comboBoxValue<QPrinter::PageSize>(m_panel.m_pageSizeCombo);
- if (pageSize == QPrinter::Custom)
- m_printerLayout.setPaperSize(QSizeF(200, 200), m_units);
- else
- m_printerLayout.setPageSize(pageSize);
-#endif
updatePageLayoutWidgets();
}
@@ -637,11 +525,7 @@ void PrintDialogPanel::pageDimensionsChanged()
{
if (m_blockSignals)
return;
-#if QT_VERSION >= 0x050300
m_pageLayout.setPageSize(QPageSize(customPageSize(), QPageSize::Unit(m_pageLayout.units())));
-#else
- m_printerLayout.setPaperSize(customPageSize(), m_units);
-#endif
updatePageLayoutWidgets();
}
@@ -649,11 +533,7 @@ void PrintDialogPanel::orientationChanged()
{
if (m_blockSignals)
return;
-#if QT_VERSION >= 0x050300
m_pageLayout.setOrientation(comboBoxValue<QPageLayout::Orientation>(m_panel.m_orientationCombo));
-#else
- m_printerLayout.setOrientation(comboBoxValue<QPrinter::Orientation>(m_panel.m_orientationCombo));
-#endif
updatePageLayoutWidgets();
}
@@ -661,14 +541,8 @@ void PrintDialogPanel::marginsChanged()
{
if (m_blockSignals)
return;
-#if QT_VERSION >= 0x050300
m_pageLayout.setMargins(QMarginsF(m_panel.m_leftMargin->value(), m_panel.m_topMargin->value(),
m_panel.m_rightMargin->value(), m_panel.m_bottomMargin->value()));
-#else
- m_printerLayout.setPageMargins(m_panel.m_leftMargin->value(), m_panel.m_topMargin->value(),
- m_panel.m_rightMargin->value(), m_panel.m_bottomMargin->value(),
- m_units);
-#endif
updatePageLayoutWidgets();
}
@@ -676,12 +550,7 @@ void PrintDialogPanel::layoutModeChanged()
{
if (m_blockSignals)
return;
-#if QT_VERSION >= 0x050300
m_pageLayout.setMode(comboBoxValue<QPageLayout::Mode>(m_panel.m_layoutModeCombo));
-#else
- bool fullPage = (comboBoxValue<QPageLayout::Mode>(m_panel.m_layoutModeCombo) == QPageLayout::FullPageMode);
- m_printerLayout.setFullPage(fullPage);
-#endif
updatePageLayoutWidgets();
}
@@ -709,11 +578,7 @@ void PrintDialogPanel::showPreviewDialog()
{
applySettings(m_printer.data());
PrintPreviewDialog dialog(m_printer.data(), this);
-#if QT_VERSION >= 0x050000
const QSize availableSize = screen()->availableSize();
-#else
- const QSize availableSize = QApplication::desktop()->availableGeometry().size();
-#endif
dialog.resize(availableSize * 4/ 5);
if (dialog.exec() == QDialog::Accepted)
retrieveSettings(m_printer.data());