From a69fdf64104670d970b255d555fbabaa9a81185d Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Mon, 27 Jan 2025 15:14:20 +0100 Subject: [PATCH] Update defaults for QPaintDevice A few values have meaningful defaults, for the rest only warn about implemented metric. Pick-to: 6.8 Change-Id: I80c6c8dba6c8d2715daac0463a411bc5117f0bc0 Reviewed-by: David Faure (cherry picked from commit da1fbf6053c07df76a4d2518103bdfc40d59cfa8) Reviewed-by: Qt Cherry-pick Bot --- src/gui/painting/qpaintdevice.cpp | 34 +++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/src/gui/painting/qpaintdevice.cpp b/src/gui/painting/qpaintdevice.cpp index 21c7e406f18..8f9232ac4f3 100644 --- a/src/gui/painting/qpaintdevice.cpp +++ b/src/gui/painting/qpaintdevice.cpp @@ -85,24 +85,36 @@ int QPaintDevice::metric(PaintDeviceMetric m) const // have implemented PdmDevicePixelRatio. if (m == PdmDevicePixelRatioScaled) return this->metric(PdmDevicePixelRatio) * devicePixelRatioFScale(); + if (m == PdmNumColors) + return 0; + if (m == PdmDevicePixelRatio) + return 1; qWarning("QPaintDevice::metrics: Device has no metric information"); - if (m == PdmDpiX) { + switch (m) { + case PdmDevicePixelRatioScaled: + case PdmDevicePixelRatio: + case PdmNumColors: + Q_UNREACHABLE(); + break; + case PdmDpiX: + case PdmDpiY: return 72; - } else if (m == PdmDpiY) { - return 72; - } else if (m == PdmNumColors) { - // FIXME: does this need to be a real value? - return 256; - } else if (m == PdmDevicePixelRatio) { - return 1; - } else if (m == PdmDevicePixelRatioF_EncodedA || m == PdmDevicePixelRatioF_EncodedB) { + case PdmDevicePixelRatioF_EncodedA: + case PdmDevicePixelRatioF_EncodedB: return 0; - } else { - qDebug("Unrecognised metric %d!",m); + case PdmWidth: + case PdmHeight: + case PdmWidthMM: + case PdmHeightMM: + case PdmDepth: + case PdmPhysicalDpiX: + case PdmPhysicalDpiY: return 0; } + qDebug("Unrecognized metric %d!", m); + return 0; } QT_END_NAMESPACE