summaryrefslogtreecommitdiffstats
path: root/src/printsupport/kernel/qprinter.cpp
diff options
context:
space:
mode:
authorAlbert Astals Cid <albert.astals.cid@kdab.com>2018-02-07 14:41:53 +0100
committerAlbert Astals Cid <albert.astals.cid@kdab.com>2018-02-16 08:10:49 +0000
commit21e5da2fe0a3c9450de60b846d2f0836e4455976 (patch)
treeab99d3bbc09223dde9e5c9dd67bcb815eeb21625 /src/printsupport/kernel/qprinter.cpp
parent048d8dee52545a9b0a548b4c56958a75a99d9aee (diff)
QPagedPainterDevicePrivate: Remove m_pageLayout
Having it there is awkward since all the subclasses of QPagedPaintDevice, that is QPdfWriter and QPrinter, have their own m_pageLayout via their private engine classes so we ended up with code like pd->engine->setPageMargins(margins, units); // Set QPagedPaintDevice layout to match the current paint engine layout m_pageLayout = pd->engine->pageLayout(); Now we just use the subclass for it's page layout and all is simpler since we don't need to make sure the two variables are updated to have the same contents. Unfortunately this means that we have to implement a dummy subclass for QPagedPaintDevice(). That constructor doesn't make any sense since QPagedPaintDevice is not really a leaf you want to instantiate, it's there to provide common api for the subclasses and the QPagedPaintDevice(QPagedPaintDevicePrivate *dd) constructor should be used. Since it's a public class we can't remove that constructor and that's why we have that QDummyPagedPaintDevicePrivate. QPageLayout &QPagedPaintDevice::devicePageLayout() is also deprecated now since there's no "device" page layout anymore. Those functions were marked internal and as far as I can see unused outside QPdfWriter/QPrinter so it should be fine. [ChangeLog][QtGui] QPagedPaintDevice constructor has been deprecated since that class is not meant to be used standalone, its two public but internal devicePageLayout() methods are now deprecated. Change-Id: I054601b66afcb7dd662db6247c5ed7820fbee212 Reviewed-by: Frederik Gladhorn <frederik.gladhorn@qt.io>
Diffstat (limited to 'src/printsupport/kernel/qprinter.cpp')
-rw-r--r--src/printsupport/kernel/qprinter.cpp43
1 files changed, 15 insertions, 28 deletions
diff --git a/src/printsupport/kernel/qprinter.cpp b/src/printsupport/kernel/qprinter.cpp
index 8a2cdcb34f..ed4292ff3d 100644
--- a/src/printsupport/kernel/qprinter.cpp
+++ b/src/printsupport/kernel/qprinter.cpp
@@ -224,8 +224,8 @@ void QPrinterPrivate::setProperty(QPrintEngine::PrintEnginePropertyKey key, cons
class QPrinterPagedPaintDevicePrivate : public QPagedPaintDevicePrivate
{
public:
- QPrinterPagedPaintDevicePrivate(QPrinterPrivate *d)
- : QPagedPaintDevicePrivate(), pd(d)
+ QPrinterPagedPaintDevicePrivate(QPrinter *p)
+ : QPagedPaintDevicePrivate(), m_printer(p)
{}
virtual ~QPrinterPagedPaintDevicePrivate()
@@ -233,6 +233,8 @@ public:
bool setPageLayout(const QPageLayout &newPageLayout) override
{
+ QPrinterPrivate *pd = QPrinterPrivate::get(m_printer);
+
if (pd->paintEngine->type() != QPaintEngine::Pdf
&& pd->printEngine->printerState() == QPrinter::Active) {
qWarning("QPrinter::setPageLayout: Cannot be changed while printer is active");
@@ -242,14 +244,13 @@ public:
// Try to set the print engine page layout
pd->setProperty(QPrintEngine::PPK_QPageLayout, QVariant::fromValue(newPageLayout));
- // Set QPagedPaintDevice layout to match the current print engine value
- m_pageLayout = pageLayout();
-
return pageLayout().isEquivalentTo(newPageLayout);
}
bool setPageSize(const QPageSize &pageSize) override
{
+ QPrinterPrivate *pd = QPrinterPrivate::get(m_printer);
+
if (pd->paintEngine->type() != QPaintEngine::Pdf
&& pd->printEngine->printerState() == QPrinter::Active) {
qWarning("QPrinter::setPageLayout: Cannot be changed while printer is active");
@@ -260,46 +261,38 @@ public:
// Try to set the print engine page size
pd->setProperty(QPrintEngine::PPK_QPageSize, QVariant::fromValue(pageSize));
- // Set QPagedPaintDevice layout to match the current print engine value
- m_pageLayout = pageLayout();
-
return pageLayout().pageSize().isEquivalentTo(pageSize);
}
bool setPageOrientation(QPageLayout::Orientation orientation) override
{
+ QPrinterPrivate *pd = QPrinterPrivate::get(m_printer);
+
// Set the print engine value
pd->setProperty(QPrintEngine::PPK_Orientation, orientation);
- // Set QPagedPaintDevice layout to match the current print engine value
- m_pageLayout = pageLayout();
-
return pageLayout().orientation() == orientation;
}
- bool setPageMargins(const QMarginsF &margins) override
- {
- return setPageMargins(margins, pageLayout().units());
- }
-
bool setPageMargins(const QMarginsF &margins, QPageLayout::Unit units) override
{
+ QPrinterPrivate *pd = QPrinterPrivate::get(m_printer);
+
// Try to set print engine margins
QPair<QMarginsF, QPageLayout::Unit> pair = qMakePair(margins, units);
pd->setProperty(QPrintEngine::PPK_QPageMargins, QVariant::fromValue(pair));
- // Set QPagedPaintDevice layout to match the current print engine value
- m_pageLayout = pageLayout();
-
return pageLayout().margins() == margins && pageLayout().units() == units;
}
QPageLayout pageLayout() const override
{
+ QPrinterPrivate *pd = QPrinterPrivate::get(m_printer);
+
return pd->printEngine->property(QPrintEngine::PPK_QPageLayout).value<QPageLayout>();
}
- QPrinterPrivate *pd;
+ QPrinter *m_printer;
};
@@ -554,11 +547,9 @@ public:
Creates a new printer object with the given \a mode.
*/
QPrinter::QPrinter(PrinterMode mode)
- : QPagedPaintDevice(),
+ : QPagedPaintDevice(new QPrinterPagedPaintDevicePrivate(this)),
d_ptr(new QPrinterPrivate(this))
{
- delete d;
- d = new QPrinterPagedPaintDevicePrivate(d_func());
d_ptr->init(QPrinterInfo(), mode);
}
@@ -568,11 +559,9 @@ QPrinter::QPrinter(PrinterMode mode)
Creates a new printer object with the given \a printer and \a mode.
*/
QPrinter::QPrinter(const QPrinterInfo& printer, PrinterMode mode)
- : QPagedPaintDevice(),
+ : QPagedPaintDevice(new QPrinterPagedPaintDevicePrivate(this)),
d_ptr(new QPrinterPrivate(this))
{
- delete d;
- d = new QPrinterPagedPaintDevicePrivate(d_func());
d_ptr->init(printer, mode);
}
@@ -1469,8 +1458,6 @@ void QPrinter::setFullPage(bool fp)
Q_D(QPrinter);
// Set the print engine
d->setProperty(QPrintEngine::PPK_FullPage, fp);
- // Set QPagedPaintDevice layout to match the current print engine value
- devicePageLayout() = pageLayout();
}