Clean up API of QPlatformPrintDevice (QPA).
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 <morten.sorvig@theqtcompany.com> Reviewed-by: Paul Olav Tvete <paul.tvete@theqtcompany.com>
This commit is contained in:
parent
7c6b6876aa
commit
a6bcdf1516
@ -60,13 +60,8 @@ class QCocoaPrintDevice : public QPlatformPrintDevice
|
|||||||
public:
|
public:
|
||||||
QCocoaPrintDevice();
|
QCocoaPrintDevice();
|
||||||
explicit QCocoaPrintDevice(const QString &id);
|
explicit QCocoaPrintDevice(const QString &id);
|
||||||
QCocoaPrintDevice(const QCocoaPrintDevice &other);
|
|
||||||
virtual ~QCocoaPrintDevice();
|
virtual ~QCocoaPrintDevice();
|
||||||
|
|
||||||
QCocoaPrintDevice *clone();
|
|
||||||
|
|
||||||
bool operator==(const QCocoaPrintDevice &other) const;
|
|
||||||
|
|
||||||
bool isValid() const Q_DECL_OVERRIDE;
|
bool isValid() const Q_DECL_OVERRIDE;
|
||||||
bool isDefault() const Q_DECL_OVERRIDE;
|
bool isDefault() const Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
|
@ -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()
|
QCocoaPrintDevice::~QCocoaPrintDevice()
|
||||||
{
|
{
|
||||||
if (m_ppd)
|
if (m_ppd)
|
||||||
@ -127,16 +109,6 @@ QCocoaPrintDevice::~QCocoaPrintDevice()
|
|||||||
PMRelease(m_printer);
|
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
|
bool QCocoaPrintDevice::isValid() const
|
||||||
{
|
{
|
||||||
return m_printer ? true : false;
|
return m_printer ? true : false;
|
||||||
|
@ -50,7 +50,7 @@ QMacPrintEngine::QMacPrintEngine(QPrinter::PrinterMode mode) : QPaintEngine(*(ne
|
|||||||
{
|
{
|
||||||
Q_D(QMacPrintEngine);
|
Q_D(QMacPrintEngine);
|
||||||
d->mode = mode;
|
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->m_pageLayout.setPageSize(d->m_printDevice->defaultPageSize());
|
||||||
d->initialize();
|
d->initialize();
|
||||||
}
|
}
|
||||||
@ -558,7 +558,7 @@ void QMacPrintEngine::setProperty(PrintEnginePropertyKey key, const QVariant &va
|
|||||||
id = QCocoaPrinterSupport().defaultPrintDeviceId();
|
id = QCocoaPrinterSupport().defaultPrintDeviceId();
|
||||||
else if (!QCocoaPrinterSupport().availablePrintDeviceIds().contains(id))
|
else if (!QCocoaPrinterSupport().availablePrintDeviceIds().contains(id))
|
||||||
break;
|
break;
|
||||||
d->m_printDevice = new QCocoaPrintDevice(id);
|
d->m_printDevice.reset(new QCocoaPrintDevice(id));
|
||||||
PMPrinter printer = d->m_printDevice->macPrinter();
|
PMPrinter printer = d->m_printDevice->macPrinter();
|
||||||
PMRetain(printer);
|
PMRetain(printer);
|
||||||
PMSessionSetCurrentPMPrinter(d->session(), printer);
|
PMSessionSetCurrentPMPrinter(d->session(), printer);
|
||||||
|
@ -116,7 +116,7 @@ class QMacPrintEnginePrivate : public QPaintEnginePrivate
|
|||||||
public:
|
public:
|
||||||
QPrinter::PrinterMode mode;
|
QPrinter::PrinterMode mode;
|
||||||
QPrinter::PrinterState state;
|
QPrinter::PrinterState state;
|
||||||
QSharedDataPointer<QCocoaPrintDevice> m_printDevice;
|
QSharedPointer<QCocoaPrintDevice> m_printDevice;
|
||||||
QPageLayout m_pageLayout;
|
QPageLayout m_pageLayout;
|
||||||
NSPrintInfo *printInfo;
|
NSPrintInfo *printInfo;
|
||||||
PMResolution resolution;
|
PMResolution resolution;
|
||||||
|
@ -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()
|
QPpdPrintDevice::~QPpdPrintDevice()
|
||||||
{
|
{
|
||||||
if (m_ppd)
|
if (m_ppd)
|
||||||
@ -109,20 +99,6 @@ QPpdPrintDevice::~QPpdPrintDevice()
|
|||||||
m_ppd = 0;
|
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
|
bool QPpdPrintDevice::isValid() const
|
||||||
{
|
{
|
||||||
return m_cupsDest && m_ppd;
|
return m_cupsDest && m_ppd;
|
||||||
|
@ -59,15 +59,8 @@ class QPpdPrintDevice : public QPlatformPrintDevice
|
|||||||
public:
|
public:
|
||||||
QPpdPrintDevice();
|
QPpdPrintDevice();
|
||||||
explicit QPpdPrintDevice(const QString &id);
|
explicit QPpdPrintDevice(const QString &id);
|
||||||
QPpdPrintDevice(const QPpdPrintDevice &other);
|
|
||||||
virtual ~QPpdPrintDevice();
|
virtual ~QPpdPrintDevice();
|
||||||
|
|
||||||
QPpdPrintDevice &operator=(const QPpdPrintDevice &other);
|
|
||||||
|
|
||||||
QPpdPrintDevice *clone();
|
|
||||||
|
|
||||||
bool operator==(const QPpdPrintDevice &other) const;
|
|
||||||
|
|
||||||
bool isValid() const Q_DECL_OVERRIDE;
|
bool isValid() const Q_DECL_OVERRIDE;
|
||||||
bool isDefault() const Q_DECL_OVERRIDE;
|
bool isDefault() const Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
|
@ -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()
|
QWindowsPrintDevice::~QWindowsPrintDevice()
|
||||||
{
|
{
|
||||||
ClosePrinter(m_hPrinter);
|
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
|
bool QWindowsPrintDevice::isValid() const
|
||||||
{
|
{
|
||||||
return m_hPrinter;
|
return m_hPrinter;
|
||||||
|
@ -58,15 +58,8 @@ class QWindowsPrintDevice : public QPlatformPrintDevice
|
|||||||
public:
|
public:
|
||||||
QWindowsPrintDevice();
|
QWindowsPrintDevice();
|
||||||
explicit QWindowsPrintDevice(const QString &id);
|
explicit QWindowsPrintDevice(const QString &id);
|
||||||
QWindowsPrintDevice(const QWindowsPrintDevice &other);
|
|
||||||
virtual ~QWindowsPrintDevice();
|
virtual ~QWindowsPrintDevice();
|
||||||
|
|
||||||
QWindowsPrintDevice &operator=(const QWindowsPrintDevice &other);
|
|
||||||
|
|
||||||
QWindowsPrintDevice *clone();
|
|
||||||
|
|
||||||
bool operator==(const QWindowsPrintDevice &other) const;
|
|
||||||
|
|
||||||
bool isValid() const Q_DECL_OVERRIDE;
|
bool isValid() const Q_DECL_OVERRIDE;
|
||||||
bool isDefault() const Q_DECL_OVERRIDE;
|
bool isDefault() const Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
|
@ -75,11 +75,6 @@ QPlatformPrintDevice::~QPlatformPrintDevice()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QPlatformPrintDevice::operator==(const QPlatformPrintDevice &other) const
|
|
||||||
{
|
|
||||||
return m_id == other.m_id;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString QPlatformPrintDevice::id() const
|
QString QPlatformPrintDevice::id() const
|
||||||
{
|
{
|
||||||
return m_id;
|
return m_id;
|
||||||
|
@ -55,17 +55,14 @@ QT_BEGIN_NAMESPACE
|
|||||||
|
|
||||||
#ifndef QT_NO_PRINTER
|
#ifndef QT_NO_PRINTER
|
||||||
|
|
||||||
class Q_PRINTSUPPORT_EXPORT QPlatformPrintDevice : public QSharedData
|
class Q_PRINTSUPPORT_EXPORT QPlatformPrintDevice
|
||||||
{
|
{
|
||||||
|
Q_DISABLE_COPY(QPlatformPrintDevice)
|
||||||
public:
|
public:
|
||||||
QPlatformPrintDevice();
|
QPlatformPrintDevice();
|
||||||
explicit QPlatformPrintDevice(const QString &id);
|
explicit QPlatformPrintDevice(const QString &id);
|
||||||
virtual ~QPlatformPrintDevice();
|
virtual ~QPlatformPrintDevice();
|
||||||
|
|
||||||
QPlatformPrintDevice *clone();
|
|
||||||
|
|
||||||
bool operator==(const QPlatformPrintDevice &other) const;
|
|
||||||
|
|
||||||
virtual QString id() const;
|
virtual QString id() const;
|
||||||
virtual QString name() const;
|
virtual QString name() const;
|
||||||
virtual QString location() const;
|
virtual QString location() const;
|
||||||
|
@ -73,7 +73,7 @@ QPrintDevice &QPrintDevice::operator=(const QPrintDevice &other)
|
|||||||
bool QPrintDevice::operator==(const QPrintDevice &other) const
|
bool QPrintDevice::operator==(const QPrintDevice &other) const
|
||||||
{
|
{
|
||||||
if (d && other.d)
|
if (d && other.d)
|
||||||
return *d == *other.d;
|
return d->id() == other.d->id();
|
||||||
return d == other.d;
|
return d == other.d;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -136,7 +136,7 @@ private:
|
|||||||
friend class QPlatformPrinterSupport;
|
friend class QPlatformPrinterSupport;
|
||||||
friend class QPlatformPrintDevice;
|
friend class QPlatformPrintDevice;
|
||||||
QPrintDevice(QPlatformPrintDevice *dd);
|
QPrintDevice(QPlatformPrintDevice *dd);
|
||||||
QSharedDataPointer<QPlatformPrintDevice> d;
|
QSharedPointer<QPlatformPrintDevice> d;
|
||||||
};
|
};
|
||||||
|
|
||||||
Q_DECLARE_SHARED(QPrintDevice)
|
Q_DECLARE_SHARED(QPrintDevice)
|
||||||
|
Loading…
Reference in New Issue
Block a user