From a6bcdf151647ab7a97c9fe1d2c8c8dd2b718244e Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Wed, 22 Apr 2015 13:50:21 +0200 Subject: Clean up API of QPlatformPrintDevice (QPA). MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The class inherited QSharedData, had a non-virtual clone() function and a non-virtual operator==() which compared QPlatformPrintDevice::id(). Derived classes implemented clone() and operator==() comparing ids to no effect. The class does not have any setters modifying its values, so detaching, copying and assigning does not make sense. Remove the inheritance, clone(), and operator==() and make the class a non-copyable base class. Use a QSharedPointer instead of a QSharedDataPointer to store it in QPrintDevice. Remove copy constructors and clone() reimplementations that were never called in implementations. Found while investigating QTBUG-44991. Task-number: QTBUG-44991 Change-Id: Ib79354b37048d04d50d936f1d0ae06c36efaac00 Reviewed-by: Morten Johan Sørvig Reviewed-by: Paul Olav Tvete --- src/plugins/platforms/cocoa/qcocoaprintdevice.h | 5 ---- src/plugins/platforms/cocoa/qcocoaprintdevice.mm | 28 ---------------------- src/plugins/platforms/cocoa/qprintengine_mac.mm | 4 ++-- src/plugins/platforms/cocoa/qprintengine_mac_p.h | 2 +- src/plugins/printsupport/cups/qppdprintdevice.cpp | 24 ------------------- src/plugins/printsupport/cups/qppdprintdevice.h | 7 ------ .../printsupport/windows/qwindowsprintdevice.cpp | 17 ------------- .../printsupport/windows/qwindowsprintdevice.h | 7 ------ src/printsupport/kernel/qplatformprintdevice.cpp | 5 ---- src/printsupport/kernel/qplatformprintdevice.h | 7 ++---- src/printsupport/kernel/qprintdevice.cpp | 2 +- src/printsupport/kernel/qprintdevice_p.h | 2 +- 12 files changed, 7 insertions(+), 103 deletions(-) diff --git a/src/plugins/platforms/cocoa/qcocoaprintdevice.h b/src/plugins/platforms/cocoa/qcocoaprintdevice.h index 2133900048..3ac112781f 100644 --- a/src/plugins/platforms/cocoa/qcocoaprintdevice.h +++ b/src/plugins/platforms/cocoa/qcocoaprintdevice.h @@ -60,13 +60,8 @@ class QCocoaPrintDevice : public QPlatformPrintDevice public: QCocoaPrintDevice(); explicit QCocoaPrintDevice(const QString &id); - QCocoaPrintDevice(const QCocoaPrintDevice &other); virtual ~QCocoaPrintDevice(); - QCocoaPrintDevice *clone(); - - bool operator==(const QCocoaPrintDevice &other) const; - bool isValid() const Q_DECL_OVERRIDE; bool isDefault() const Q_DECL_OVERRIDE; diff --git a/src/plugins/platforms/cocoa/qcocoaprintdevice.mm b/src/plugins/platforms/cocoa/qcocoaprintdevice.mm index b92ec31a11..4d319e149b 100644 --- a/src/plugins/platforms/cocoa/qcocoaprintdevice.mm +++ b/src/plugins/platforms/cocoa/qcocoaprintdevice.mm @@ -96,24 +96,6 @@ QCocoaPrintDevice::QCocoaPrintDevice(const QString &id) } } -QCocoaPrintDevice::QCocoaPrintDevice(const QCocoaPrintDevice &other) - : QPlatformPrintDevice(other), - m_printer(0), - m_session(0), - m_ppd(0) -{ - m_printer = other.m_printer; - PMRetain(m_printer); - m_session = other.m_session; - PMRetain(m_session); - m_macPapers = other.m_macPapers; - foreach (PMPaper paper, m_macPapers.values()) - PMRetain(paper); - openPpdFile(); - m_customMargins = other.m_customMargins; - m_printableMargins = other.m_printableMargins; -} - QCocoaPrintDevice::~QCocoaPrintDevice() { if (m_ppd) @@ -127,16 +109,6 @@ QCocoaPrintDevice::~QCocoaPrintDevice() PMRelease(m_printer); } -QCocoaPrintDevice *QCocoaPrintDevice::clone() -{ - return new QCocoaPrintDevice(*this); -} - -bool QCocoaPrintDevice::operator==(const QCocoaPrintDevice &other) const -{ - return (m_id == other.m_id); -} - bool QCocoaPrintDevice::isValid() const { return m_printer ? true : false; diff --git a/src/plugins/platforms/cocoa/qprintengine_mac.mm b/src/plugins/platforms/cocoa/qprintengine_mac.mm index 348b537691..9e8fe8f1c8 100644 --- a/src/plugins/platforms/cocoa/qprintengine_mac.mm +++ b/src/plugins/platforms/cocoa/qprintengine_mac.mm @@ -50,7 +50,7 @@ QMacPrintEngine::QMacPrintEngine(QPrinter::PrinterMode mode) : QPaintEngine(*(ne { Q_D(QMacPrintEngine); d->mode = mode; - d->m_printDevice = new QCocoaPrintDevice(QCocoaPrinterSupport().defaultPrintDeviceId()); + d->m_printDevice.reset(new QCocoaPrintDevice(QCocoaPrinterSupport().defaultPrintDeviceId())); d->m_pageLayout.setPageSize(d->m_printDevice->defaultPageSize()); d->initialize(); } @@ -558,7 +558,7 @@ void QMacPrintEngine::setProperty(PrintEnginePropertyKey key, const QVariant &va id = QCocoaPrinterSupport().defaultPrintDeviceId(); else if (!QCocoaPrinterSupport().availablePrintDeviceIds().contains(id)) break; - d->m_printDevice = new QCocoaPrintDevice(id); + d->m_printDevice.reset(new QCocoaPrintDevice(id)); PMPrinter printer = d->m_printDevice->macPrinter(); PMRetain(printer); PMSessionSetCurrentPMPrinter(d->session(), printer); diff --git a/src/plugins/platforms/cocoa/qprintengine_mac_p.h b/src/plugins/platforms/cocoa/qprintengine_mac_p.h index 6a795a55d8..494fb5b9d1 100644 --- a/src/plugins/platforms/cocoa/qprintengine_mac_p.h +++ b/src/plugins/platforms/cocoa/qprintengine_mac_p.h @@ -116,7 +116,7 @@ class QMacPrintEnginePrivate : public QPaintEnginePrivate public: QPrinter::PrinterMode mode; QPrinter::PrinterState state; - QSharedDataPointer m_printDevice; + QSharedPointer m_printDevice; QPageLayout m_pageLayout; NSPrintInfo *printInfo; PMResolution resolution; diff --git a/src/plugins/printsupport/cups/qppdprintdevice.cpp b/src/plugins/printsupport/cups/qppdprintdevice.cpp index c2bd2872a9..808424b1ed 100644 --- a/src/plugins/printsupport/cups/qppdprintdevice.cpp +++ b/src/plugins/printsupport/cups/qppdprintdevice.cpp @@ -89,16 +89,6 @@ QPpdPrintDevice::QPpdPrintDevice(const QString &id) } } -QPpdPrintDevice::QPpdPrintDevice(const QPpdPrintDevice &other) - : QPlatformPrintDevice(other), - m_cupsDest(0), - m_ppd(0) -{ - m_cupsName = other.m_cupsName; - m_cupsInstance = other.m_cupsInstance; - loadPrinter(); -} - QPpdPrintDevice::~QPpdPrintDevice() { if (m_ppd) @@ -109,20 +99,6 @@ QPpdPrintDevice::~QPpdPrintDevice() m_ppd = 0; } -QPpdPrintDevice &QPpdPrintDevice::operator=(const QPpdPrintDevice &other) -{ - m_cupsName = other.m_cupsName; - m_cupsInstance = other.m_cupsInstance; - if (other.m_cupsDest && other.m_ppd) - loadPrinter(); - return *this; -} - -bool QPpdPrintDevice::operator==(const QPpdPrintDevice &other) const -{ - return (m_id == other.m_id); -} - bool QPpdPrintDevice::isValid() const { return m_cupsDest && m_ppd; diff --git a/src/plugins/printsupport/cups/qppdprintdevice.h b/src/plugins/printsupport/cups/qppdprintdevice.h index 0d618192fe..5ebcf39566 100644 --- a/src/plugins/printsupport/cups/qppdprintdevice.h +++ b/src/plugins/printsupport/cups/qppdprintdevice.h @@ -59,15 +59,8 @@ class QPpdPrintDevice : public QPlatformPrintDevice public: QPpdPrintDevice(); explicit QPpdPrintDevice(const QString &id); - QPpdPrintDevice(const QPpdPrintDevice &other); virtual ~QPpdPrintDevice(); - QPpdPrintDevice &operator=(const QPpdPrintDevice &other); - - QPpdPrintDevice *clone(); - - bool operator==(const QPpdPrintDevice &other) const; - bool isValid() const Q_DECL_OVERRIDE; bool isDefault() const Q_DECL_OVERRIDE; diff --git a/src/plugins/printsupport/windows/qwindowsprintdevice.cpp b/src/plugins/printsupport/windows/qwindowsprintdevice.cpp index af8e07edd2..505f3138ca 100644 --- a/src/plugins/printsupport/windows/qwindowsprintdevice.cpp +++ b/src/plugins/printsupport/windows/qwindowsprintdevice.cpp @@ -113,28 +113,11 @@ QWindowsPrintDevice::QWindowsPrintDevice(const QString &id) } } -QWindowsPrintDevice::QWindowsPrintDevice(const QWindowsPrintDevice &other) - : QPlatformPrintDevice(other) -{ - OpenPrinter((LPWSTR)other.m_id.utf16(), &m_hPrinter, NULL); -} - QWindowsPrintDevice::~QWindowsPrintDevice() { ClosePrinter(m_hPrinter); } -QWindowsPrintDevice &QWindowsPrintDevice::operator=(const QWindowsPrintDevice &other) -{ - OpenPrinter((LPWSTR)other.m_id.utf16(), &m_hPrinter, NULL); - return *this; -} - -bool QWindowsPrintDevice::operator==(const QWindowsPrintDevice &other) const -{ - return (m_id == other.m_id); -} - bool QWindowsPrintDevice::isValid() const { return m_hPrinter; diff --git a/src/plugins/printsupport/windows/qwindowsprintdevice.h b/src/plugins/printsupport/windows/qwindowsprintdevice.h index 2e0f6e4658..8ab487a59c 100644 --- a/src/plugins/printsupport/windows/qwindowsprintdevice.h +++ b/src/plugins/printsupport/windows/qwindowsprintdevice.h @@ -58,15 +58,8 @@ class QWindowsPrintDevice : public QPlatformPrintDevice public: QWindowsPrintDevice(); explicit QWindowsPrintDevice(const QString &id); - QWindowsPrintDevice(const QWindowsPrintDevice &other); virtual ~QWindowsPrintDevice(); - QWindowsPrintDevice &operator=(const QWindowsPrintDevice &other); - - QWindowsPrintDevice *clone(); - - bool operator==(const QWindowsPrintDevice &other) const; - bool isValid() const Q_DECL_OVERRIDE; bool isDefault() const Q_DECL_OVERRIDE; diff --git a/src/printsupport/kernel/qplatformprintdevice.cpp b/src/printsupport/kernel/qplatformprintdevice.cpp index bd6d81774c..6385f58aa1 100644 --- a/src/printsupport/kernel/qplatformprintdevice.cpp +++ b/src/printsupport/kernel/qplatformprintdevice.cpp @@ -75,11 +75,6 @@ QPlatformPrintDevice::~QPlatformPrintDevice() { } -bool QPlatformPrintDevice::operator==(const QPlatformPrintDevice &other) const -{ - return m_id == other.m_id; -} - QString QPlatformPrintDevice::id() const { return m_id; diff --git a/src/printsupport/kernel/qplatformprintdevice.h b/src/printsupport/kernel/qplatformprintdevice.h index 1e21e608ad..8bb87a70f9 100644 --- a/src/printsupport/kernel/qplatformprintdevice.h +++ b/src/printsupport/kernel/qplatformprintdevice.h @@ -55,17 +55,14 @@ QT_BEGIN_NAMESPACE #ifndef QT_NO_PRINTER -class Q_PRINTSUPPORT_EXPORT QPlatformPrintDevice : public QSharedData +class Q_PRINTSUPPORT_EXPORT QPlatformPrintDevice { + Q_DISABLE_COPY(QPlatformPrintDevice) public: QPlatformPrintDevice(); explicit QPlatformPrintDevice(const QString &id); virtual ~QPlatformPrintDevice(); - QPlatformPrintDevice *clone(); - - bool operator==(const QPlatformPrintDevice &other) const; - virtual QString id() const; virtual QString name() const; virtual QString location() const; diff --git a/src/printsupport/kernel/qprintdevice.cpp b/src/printsupport/kernel/qprintdevice.cpp index 7c18b53e09..a640c14483 100644 --- a/src/printsupport/kernel/qprintdevice.cpp +++ b/src/printsupport/kernel/qprintdevice.cpp @@ -73,7 +73,7 @@ QPrintDevice &QPrintDevice::operator=(const QPrintDevice &other) bool QPrintDevice::operator==(const QPrintDevice &other) const { if (d && other.d) - return *d == *other.d; + return d->id() == other.d->id(); return d == other.d; } diff --git a/src/printsupport/kernel/qprintdevice_p.h b/src/printsupport/kernel/qprintdevice_p.h index ad55cded0e..ddf5595734 100644 --- a/src/printsupport/kernel/qprintdevice_p.h +++ b/src/printsupport/kernel/qprintdevice_p.h @@ -136,7 +136,7 @@ private: friend class QPlatformPrinterSupport; friend class QPlatformPrintDevice; QPrintDevice(QPlatformPrintDevice *dd); - QSharedDataPointer d; + QSharedPointer d; }; Q_DECLARE_SHARED(QPrintDevice) -- cgit v1.2.3