summaryrefslogtreecommitdiffstats
path: root/src/printsupport/kernel
diff options
context:
space:
mode:
authorJohn Layt <jlayt@kde.org>2012-05-14 20:17:16 +0100
committerQt by Nokia <qt-info@nokia.com>2012-05-24 09:48:27 +0200
commit36f469bdb1c705f0082610a4fe9fd88b90accd24 (patch)
treefa96b0b3091d1730966a20d142add5d12d87d400 /src/printsupport/kernel
parentce5c1db2d3db7d7c7af28e9053ca591f76c6101c (diff)
QtPrintSupport - Modify Platform Plugin QPrinterInfo api
Change the way the printsupport plugin creates QPrinterInfo objects, provide platform api to return a named printer, and expose this as static public api in QPrinterInfo. Only the Mac plugin used the old api, the other plugins will have direct support added in separate commits, but will use the default implementation for now. Change-Id: I7d6b6556eb39919cfb15bc0e814afbaf13c5712c Reviewed-by: Bradley T. Hughes <bradley.hughes@nokia.com> Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
Diffstat (limited to 'src/printsupport/kernel')
-rw-r--r--src/printsupport/kernel/qplatformprintersupport.h2
-rw-r--r--src/printsupport/kernel/qplatformprintersupport_qpa.cpp11
-rw-r--r--src/printsupport/kernel/qprinterinfo.cpp31
-rw-r--r--src/printsupport/kernel/qprinterinfo.h2
4 files changed, 35 insertions, 11 deletions
diff --git a/src/printsupport/kernel/qplatformprintersupport.h b/src/printsupport/kernel/qplatformprintersupport.h
index f0efa3d6af..37fb9e89de 100644
--- a/src/printsupport/kernel/qplatformprintersupport.h
+++ b/src/printsupport/kernel/qplatformprintersupport.h
@@ -73,12 +73,12 @@ public:
virtual QList<QPrinterInfo> availablePrinters();
virtual QPrinterInfo defaultPrinter();
+ virtual QPrinterInfo printerInfo(const QString &printerName);
static QPrinter::PaperSize convertQSizeFToPaperSize(const QSizeF &sizef);
static QSizeF convertPaperSizeToQSizeF(QPrinter::PaperSize paperSize);
protected:
- static QPrinterInfo printerInfo(const QString &printerName, bool isDefault = false);
static void setPrinterInfoDefault(QPrinterInfo *p, bool isDefault);
static bool printerInfoIsDefault(const QPrinterInfo &p);
static int printerInfoCupsPrinterIndex(const QPrinterInfo &p);
diff --git a/src/printsupport/kernel/qplatformprintersupport_qpa.cpp b/src/printsupport/kernel/qplatformprintersupport_qpa.cpp
index 9c0c3f131c..35441df5fc 100644
--- a/src/printsupport/kernel/qplatformprintersupport_qpa.cpp
+++ b/src/printsupport/kernel/qplatformprintersupport_qpa.cpp
@@ -97,11 +97,14 @@ QPrinterInfo QPlatformPrinterSupport::defaultPrinter()
return printers.isEmpty() ? QPrinterInfo() : printers.front();
}
-QPrinterInfo QPlatformPrinterSupport::printerInfo(const QString &printerName, bool isDefault)
+QPrinterInfo QPlatformPrinterSupport::printerInfo(const QString &printerName)
{
- QPrinterInfo pi = QPrinterInfo(printerName);
- pi.d_func()->isDefault = isDefault;
- return pi;
+ const QList<QPrinterInfo> printers = availablePrinters();
+ foreach (const QPrinterInfo &printerInfo, printers) {
+ if (printerInfo.printerName() == printerName)
+ return printerInfo;
+ }
+ return QPrinterInfo();
}
void QPlatformPrinterSupport::setPrinterInfoDefault(QPrinterInfo *p, bool isDefault)
diff --git a/src/printsupport/kernel/qprinterinfo.cpp b/src/printsupport/kernel/qprinterinfo.cpp
index 3d0ba7f31d..fbf2e4de33 100644
--- a/src/printsupport/kernel/qprinterinfo.cpp
+++ b/src/printsupport/kernel/qprinterinfo.cpp
@@ -96,11 +96,10 @@ QPrinterInfo::QPrinterInfo(const QPrinterInfo &other)
QPrinterInfo::QPrinterInfo(const QPrinter &printer)
: d_ptr(&QPrinterInfoPrivate::shared_null)
{
- foreach (const QPrinterInfo &printerInfo, availablePrinters()) {
- if (printerInfo.printerName() == printer.printerName()) {
- d_ptr.reset(new QPrinterInfoPrivate(*printerInfo.d_ptr));
- break;
- }
+ QPlatformPrinterSupport *ps = QPlatformPrinterSupportPlugin::get();
+ if (ps) {
+ QPrinterInfo pi = ps->printerInfo(printer.printerName());
+ d_ptr.reset(new QPrinterInfoPrivate(*pi.d_ptr));
}
}
@@ -195,7 +194,27 @@ QPrinterInfo QPrinterInfo::defaultPrinter()
QPlatformPrinterSupport *ps = QPlatformPrinterSupportPlugin::get();
if (!ps)
return QPrinterInfo();
- return QPlatformPrinterSupportPlugin::get()->defaultPrinter();
+ return ps->defaultPrinter();
+}
+
+/*!
+ \fn QPrinterInfo QPrinterInfo::printerInfo()
+ \since 5.0
+
+ Returns the named printer.
+
+ The return value should be checked using isNull() before being
+ used, in case the named printer does not exist.
+
+ \sa isNull()
+*/
+
+QPrinterInfo QPrinterInfo::printerInfo(const QString &printerName)
+{
+ QPlatformPrinterSupport *ps = QPlatformPrinterSupportPlugin::get();
+ if (!ps)
+ return QPrinterInfo();
+ return ps->printerInfo(printerName);
}
QT_END_NAMESPACE
diff --git a/src/printsupport/kernel/qprinterinfo.h b/src/printsupport/kernel/qprinterinfo.h
index d26b70dee0..8b3ab448c8 100644
--- a/src/printsupport/kernel/qprinterinfo.h
+++ b/src/printsupport/kernel/qprinterinfo.h
@@ -71,6 +71,7 @@ public:
static QList<QPrinterInfo> availablePrinters();
static QPrinterInfo defaultPrinter();
+ static QPrinterInfo printerInfo(const QString &printerName);
private:
explicit QPrinterInfo(const QString &name);
@@ -78,6 +79,7 @@ private:
private:
friend class QPlatformPrinterSupport;
friend class QWindowsPrinterSupport;
+ friend class QCocoaPrinterSupport;
Q_DECLARE_PRIVATE(QPrinterInfo)
QScopedPointer<QPrinterInfoPrivate, QPrinterInfoPrivateDeleter> d_ptr;
};