From 56fbcfd2b78bc62eca953a5cd3af831a8964e9e1 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Fri, 7 Jun 2019 23:48:53 +0200 Subject: [PATCH] QPdfWriter: replace a QHash with a static_cast MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The QHash was mapping equivalent values of different enums to each other. The enums have the same enumerators, though, so if we take care to keep the two in sync in the future, we can just static_cast them into each other via int. Change-Id: Ie67978604f8c3b9477419bc6029bbb869061e938 Reviewed-by: Giuseppe D'Angelo Reviewed-by: MÃ¥rten Nordheim --- src/gui/painting/qpagedpaintdevice.h | 1 + src/gui/painting/qpdf_p.h | 1 + src/gui/painting/qpdfwriter.cpp | 8 +------- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/gui/painting/qpagedpaintdevice.h b/src/gui/painting/qpagedpaintdevice.h index 1c37c17fa3..21e23e0eb4 100644 --- a/src/gui/painting/qpagedpaintdevice.h +++ b/src/gui/painting/qpagedpaintdevice.h @@ -213,6 +213,7 @@ public: Envelope10 = Comm10E }; + // keep in sync with QPdfEngine::PdfVersion! enum PdfVersion { PdfVersion_1_4, PdfVersion_A1b, PdfVersion_1_6 }; // ### Qt6 Make these virtual diff --git a/src/gui/painting/qpdf_p.h b/src/gui/painting/qpdf_p.h index e337c61f64..e5649eb9dc 100644 --- a/src/gui/painting/qpdf_p.h +++ b/src/gui/painting/qpdf_p.h @@ -168,6 +168,7 @@ class Q_GUI_EXPORT QPdfEngine : public QPaintEngine Q_DECLARE_PRIVATE(QPdfEngine) friend class QPdfWriter; public: + // keep in sync with QPagedPaintDevice::PdfVersion! enum PdfVersion { Version_1_4, diff --git a/src/gui/painting/qpdfwriter.cpp b/src/gui/painting/qpdfwriter.cpp index 7f18ce42be..bf7e2d3dca 100644 --- a/src/gui/painting/qpdfwriter.cpp +++ b/src/gui/painting/qpdfwriter.cpp @@ -170,17 +170,11 @@ void QPdfWriter::setPdfVersion(PdfVersion version) { Q_D(QPdfWriter); - static const QHash engineMapping { - {QPdfWriter::PdfVersion_1_4, QPdfEngine::Version_1_4}, - {QPdfWriter::PdfVersion_A1b, QPdfEngine::Version_A1b}, - {QPdfWriter::PdfVersion_1_6, QPdfEngine::Version_1_6} - }; - if (d->pdfVersion == version) return; d->pdfVersion = version; - d->engine->setPdfVersion(engineMapping.value(version, QPdfEngine::Version_1_4)); + d->engine->setPdfVersion(static_cast(static_cast(version))); } /*!