From 36f469bdb1c705f0082610a4fe9fd88b90accd24 Mon Sep 17 00:00:00 2001 From: John Layt Date: Mon, 14 May 2012 20:17:16 +0100 Subject: 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 Reviewed-by: Lars Knoll --- src/printsupport/kernel/qprinterinfo.cpp | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) (limited to 'src/printsupport/kernel/qprinterinfo.cpp') 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 -- cgit v1.2.3