summaryrefslogtreecommitdiffstats
path: root/tests/auto/printsupport/kernel/qprinter/tst_qprinter.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/printsupport/kernel/qprinter/tst_qprinter.cpp')
-rw-r--r--tests/auto/printsupport/kernel/qprinter/tst_qprinter.cpp809
1 files changed, 273 insertions, 536 deletions
diff --git a/tests/auto/printsupport/kernel/qprinter/tst_qprinter.cpp b/tests/auto/printsupport/kernel/qprinter/tst_qprinter.cpp
index 7529bad833..d2ccf7b990 100644
--- a/tests/auto/printsupport/kernel/qprinter/tst_qprinter.cpp
+++ b/tests/auto/printsupport/kernel/qprinter/tst_qprinter.cpp
@@ -1,32 +1,7 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <QtTest/QtTest>
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+#include <QTest>
#include <qprinter.h>
#include <qpagesetupdialog.h>
@@ -45,15 +20,13 @@
#include <math.h>
#ifdef Q_OS_WIN
-#include <windows.h>
+#include <qt_windows.h>
#endif
#if QT_CONFIG(printer)
typedef QSharedPointer<QPrinter> PrinterPtr;
Q_DECLARE_METATYPE(PrinterPtr)
-Q_DECLARE_METATYPE(QPrinter::Orientation)
-Q_DECLARE_METATYPE(QPrinter::PageSize)
#endif // printer
static int fileNumber = 0;
@@ -67,13 +40,12 @@ private slots:
#if QT_CONFIG(printer)
void testPageRectAndPaperRect();
void testPageRectAndPaperRect_data();
- void testSetOptions();
void testMargins_data();
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 +54,6 @@ private slots:
void customPaperSizeAndMargins_data();
void customPaperSizeAndMargins();
void customPaperNameSettingBySize();
- void customPaperNameSettingByName();
#if QT_CONFIG(completer) && QT_CONFIG(filedialog)
void printDialogCompleter();
#endif
@@ -97,7 +68,6 @@ private slots:
void copyCount();
void creator();
void docName();
- void doubleSidedPrinting();
void duplex();
void fontEmbedding();
void fullPage();
@@ -105,7 +75,6 @@ private slots:
void outputFileName();
void pageOrder();
void pageSize();
- void paperSize();
void paperSource();
void printerName();
void printerSelectionOption();
@@ -114,7 +83,6 @@ private slots:
void resolution();
void supportedPaperSources();
void supportedResolutions();
- void windowsPageSize();
// Test QPrinter setters/getters for non-QPrintEngine options
void outputFormat();
@@ -141,8 +109,6 @@ void tst_QPrinter::initTestCase()
#if QT_CONFIG(printer)
-#define MYCOMPARE(a, b) QCOMPARE(QVariant((int)a), QVariant((int)b))
-
void tst_QPrinter::testPageSetupDialog()
{
// Make sure this doesn't crash at least
@@ -198,131 +164,104 @@ 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);
+ QPainter *painter = nullptr;
+ 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)
+ if (painter != nullptr)
delete painter;
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());
-}
-
-void tst_QPrinter::testSetOptions()
-{
- QPrinter prn;
- QPrintDialog dlg(&prn);
-
- // Verify default values
- MYCOMPARE(dlg.isOptionEnabled(QAbstractPrintDialog::PrintToFile), true);
- MYCOMPARE(dlg.isOptionEnabled(QAbstractPrintDialog::PrintSelection), false);
- MYCOMPARE(dlg.isOptionEnabled(QAbstractPrintDialog::PrintPageRange), true);
-
- dlg.setEnabledOptions(QAbstractPrintDialog::PrintPageRange);
- MYCOMPARE(dlg.isOptionEnabled(QAbstractPrintDialog::PrintToFile), false);
- MYCOMPARE(dlg.isOptionEnabled(QAbstractPrintDialog::PrintSelection), false);
- MYCOMPARE(dlg.isOptionEnabled(QAbstractPrintDialog::PrintPageRange), true);
-
- dlg.setEnabledOptions((QAbstractPrintDialog::PrintDialogOptions(QAbstractPrintDialog::PrintSelection
- | QAbstractPrintDialog::PrintPageRange)));
- MYCOMPARE(dlg.isOptionEnabled(QAbstractPrintDialog::PrintToFile), false);
- MYCOMPARE(dlg.isOptionEnabled(QAbstractPrintDialog::PrintSelection), true);
- MYCOMPARE(dlg.isOptionEnabled(QAbstractPrintDialog::PrintPageRange), true);
-
- dlg.setEnabledOptions(QAbstractPrintDialog::PrintSelection);
- MYCOMPARE(dlg.isOptionEnabled(QAbstractPrintDialog::PrintToFile), false);
- MYCOMPARE(dlg.isOptionEnabled(QAbstractPrintDialog::PrintSelection), true);
- MYCOMPARE(dlg.isOptionEnabled(QAbstractPrintDialog::PrintPageRange), false);
+ QVERIFY(printer->pageLayout().orientation() == QPageLayout::Portrait || pageRect.width() > pageRect.height());
+ QVERIFY(printer->pageLayout().orientation() != QPageLayout::Portrait || pageRect.width() < pageRect.height());
}
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;
+ QPainter *painter = nullptr;
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 +269,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);
+ };
- if (printer.pageSize() != printerPageSize) {
+ computePageValue(paperWidth, paperHeight);
+ printer.setPageSize(QPageSize(pageSize));
+
+ if (printer.pageLayout().pageSize().id() != pageSize) {
QSKIP("Current page size is not supported on this printer");
return;
}
@@ -388,18 +325,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 +359,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 +378,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 +418,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 +469,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)
@@ -597,7 +501,7 @@ void tst_QPrinter::printDialogCompleter()
if (dialog.printer()->outputFormat() != QPrinter::NativeFormat)
QSKIP("Dialog cannot be used with non-native formats");
#endif
- dialog.setEnabledOptions(QAbstractPrintDialog::PrintToFile);
+ dialog.setOption(QAbstractPrintDialog::PrintToFile);
dialog.show();
QVERIFY(QTest::qWaitForWindowActive(&dialog));
@@ -666,11 +570,11 @@ void tst_QPrinter::testCurrentPage()
QPrintDialog dialog(&printer);
// Test default Current Page option to off
- QCOMPARE(dialog.isOptionEnabled(QPrintDialog::PrintCurrentPage), false);
+ QVERIFY(!dialog.testOption(QPrintDialog::PrintCurrentPage));
// Test enable Current Page option
dialog.setOption(QPrintDialog::PrintCurrentPage);
- QCOMPARE(dialog.isOptionEnabled(QPrintDialog::PrintCurrentPage), true);
+ QVERIFY(dialog.testOption(QPrintDialog::PrintCurrentPage));
}
@@ -707,22 +611,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 +636,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 +663,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 +685,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 +782,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");
}
@@ -1035,7 +903,8 @@ void tst_QPrinter::duplex()
QPrinter::DuplexMode expected = printerInfo.defaultDuplexMode();
QCOMPARE(native.duplex(), expected);
// Test set/get (skipping Auto as that will return something different)
- foreach (QPrinter::DuplexMode mode, printerInfo.supportedDuplexModes()) {
+ const auto supported = printerInfo.supportedDuplexModes();
+ for (QPrinter::DuplexMode mode : supported) {
if (mode != expected && mode != QPrinter::DuplexAuto) {
expected = mode;
break;
@@ -1044,11 +913,10 @@ void tst_QPrinter::duplex()
native.setDuplex(expected);
QCOMPARE(native.duplex(), expected);
- // Test value preservation
+ // Test that PdfFormat printer has no duplex.
native.setOutputFormat(QPrinter::PdfFormat);
- QCOMPARE(native.duplex(), expected);
+ QCOMPARE(native.duplex(), QPrinter::DuplexNone);
native.setOutputFormat(QPrinter::NativeFormat);
- QCOMPARE(native.duplex(), expected);
// Test setting invalid option
if (!printerInfo.supportedDuplexModes().contains(QPrinter::DuplexLongSide)) {
@@ -1060,41 +928,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 +1009,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 +1128,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()
{
@@ -1406,7 +1194,8 @@ void tst_QPrinter::paperSource()
QPrinter::PaperSource expected = QPrinter::Manual;
#ifdef Q_OS_WIN
expected = QPrinter::Auto;
- foreach (QPrinter::PaperSource supported, native.supportedPaperSources()) {
+ const auto sources = native.supportedPaperSources();
+ for (QPrinter::PaperSource supported : sources) {
if (supported != QPrinter::Auto) {
expected = supported;
break;
@@ -1528,7 +1317,8 @@ void tst_QPrinter::printerName()
// Test set/get
QString expected = QPrinterInfo::defaultPrinter().printerName();
- foreach (const QPrinterInfo &available, QPrinterInfo::availablePrinters()) {
+ const auto allAvailable = QPrinterInfo::availablePrinters();
+ for (const QPrinterInfo &available : allAvailable) {
if (available.printerName() != expected) {
expected = available.printerName();
break;
@@ -1621,7 +1411,7 @@ void tst_QPrinter::resolution()
#ifdef Q_OS_MAC
// QMacPrintEngine chooses the closest supported resolution.
const QList<int> all_supported = native.supportedResolutions();
- foreach (int supported, all_supported) {
+ for (int supported : all_supported) {
// Test setting a supported resolution
int requested = supported;
native.setResolution(requested);
@@ -1693,51 +1483,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()
@@ -1748,7 +1493,13 @@ void tst_QPrinter::outputFormat()
QCOMPARE(printer.printerName(), QString());
} else {
QCOMPARE(printer.outputFormat(), QPrinter::NativeFormat);
- QCOMPARE(printer.printerName(), QPrinterInfo::defaultPrinter().printerName());
+
+ // If no printer is default, the first available printer should be used.
+ // Otherwise, the default printer should be used.
+ if (QPrinterInfo::defaultPrinter().isNull())
+ QCOMPARE(printer.printerName(), QPrinterInfo::availablePrinters().at(0).printerName());
+ else
+ QCOMPARE(printer.printerName(), QPrinterInfo::defaultPrinter().printerName());
}
printer.setOutputFormat(QPrinter::PdfFormat);
@@ -1778,10 +1529,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,61 +1556,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
- QPrinter::Margins margins;
- margins.left = leftMMf;
- margins.right = rightMMf;
- margins.top = topMMf;
- margins.bottom = bottomMMf;
- printer.setMargins(margins);
- 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);
+ 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));
@@ -1871,35 +1613,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));
@@ -1909,36 +1649,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));
@@ -1968,7 +1705,7 @@ void tst_QPrinter::reusePageMetrics()
QPrinter defaultP;
QPrinterInfo info(defaultP);
QString otherPrinterName;
- for (QPrinterInfo i : qAsConst(availablePrinters)) {
+ for (QPrinterInfo i : std::as_const(availablePrinters)) {
if (i.printerName() != defaultP.printerName()) {
otherPrinterName = i.printerName();
break;
@@ -1978,9 +1715,9 @@ void tst_QPrinter::reusePageMetrics()
QList<QPageSize> defaultPageSizes = info.supportedPageSizes();
QList<QPageSize> otherPageSizes = QPrinterInfo(otherP).supportedPageSizes();
QPageSize unavailableSizeToSet;
- for (QPageSize s : qAsConst(defaultPageSizes)) {
+ for (QPageSize s : std::as_const(defaultPageSizes)) {
bool found = false;
- for (QPageSize os : qAsConst(otherPageSizes)) {
+ for (QPageSize os : std::as_const(otherPageSizes)) {
if (os.isEquivalentTo(s)) {
found = true;
break;