summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Hayzen <ahayzen@gmail.com>2016-11-22 11:55:50 +0000
committerAndrew Hayzen <ahayzen@gmail.com>2016-12-09 14:36:56 +0000
commit4aebbef8ab94723d59679f30005b114197c995b9 (patch)
tree6c274495ca5e10dd1e658ed3323e52b85547db21
parente51173a2b2f04c97ad03cb3aea5fa82c9a1d1e68 (diff)
Add support for selecting the printer plugin via the env var
Task-number: QTBUG-57260 Change-Id: I046c8ce5af242cdc7efd23468bbe670d782bdfc0 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> Reviewed-by: Andy Shaw <andy.shaw@qt.io>
-rw-r--r--src/printsupport/kernel/qplatformprintplugin.cpp14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/printsupport/kernel/qplatformprintplugin.cpp b/src/printsupport/kernel/qplatformprintplugin.cpp
index 9bc4b61829..a80f369040 100644
--- a/src/printsupport/kernel/qplatformprintplugin.cpp
+++ b/src/printsupport/kernel/qplatformprintplugin.cpp
@@ -42,6 +42,7 @@
#include "qprinterinfo.h"
#include "private/qfactoryloader_p.h"
#include <qcoreapplication.h>
+#include <qdebug.h>
#ifndef QT_NO_PRINTER
@@ -79,8 +80,17 @@ QPlatformPrinterSupport *QPlatformPrinterSupportPlugin::get()
{
if (!printerSupport) {
const QMultiMap<int, QString> keyMap = loader()->keyMap();
- if (!keyMap.isEmpty())
- printerSupport = qLoadPlugin<QPlatformPrinterSupport, QPlatformPrinterSupportPlugin>(loader(), keyMap.constBegin().value());
+ QMultiMap<int, QString>::const_iterator it = keyMap.cbegin();
+ if (!qEnvironmentVariableIsEmpty("QT_PRINTER_MODULE")) {
+ QString module = QString::fromLocal8Bit(qgetenv("QT_PRINTER_MODULE"));
+ QMultiMap<int, QString>::const_iterator it2 = std::find_if(keyMap.cbegin(), keyMap.cend(), [module](const QString &value){ return value == module; });
+ if (it2 == keyMap.cend())
+ qWarning() << "Unable to load printer plugin" << module;
+ else
+ it = it2;
+ }
+ if (it != keyMap.cend())
+ printerSupport = qLoadPlugin<QPlatformPrinterSupport, QPlatformPrinterSupportPlugin>(loader(), it.value());
if (printerSupport)
qAddPostRoutine(cleanupPrinterSupport);
}