From d1d75f3b72b2d4e8f4a75b552023b1ea6381fccc Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Mon, 23 May 2022 11:03:04 +0200 Subject: Refactor if-else snake into switch statement MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I597d5cbdddf4a2fbbe8b9de2ae252cdeadce9d11 Reviewed-by: Thorbjørn Lund Martsum --- src/widgets/kernel/qwidget.cpp | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index e96b0df94f..01a8905c79 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -12697,41 +12697,42 @@ int QWidget::metric(PaintDeviceMetric m) const return 72; return QPaintDevice::metric(m); } - int val; - if (m == PdmWidth) { - val = data->crect.width(); - } else if (m == PdmWidthMM) { - val = data->crect.width() * screen->physicalSize().width() / screen->geometry().width(); - } else if (m == PdmHeight) { - val = data->crect.height(); - } else if (m == PdmHeightMM) { - val = data->crect.height() * screen->physicalSize().height() / screen->geometry().height(); - } else if (m == PdmDepth) { + + switch (m) { + case PdmWidth: + return data->crect.width(); + case PdmWidthMM: + return data->crect.width() * screen->physicalSize().width() / screen->geometry().width(); + case PdmHeight: + return data->crect.height(); + case PdmHeightMM: + return data->crect.height() * screen->physicalSize().height() / screen->geometry().height(); + case PdmDepth: return screen->depth(); - } else if (m == PdmDpiX) { + case PdmDpiX: for (const QWidget *p = this; p; p = p->parentWidget()) { if (p->d_func()->extra && p->d_func()->extra->customDpiX) return p->d_func()->extra->customDpiX; } return qRound(screen->logicalDotsPerInchX()); - } else if (m == PdmDpiY) { + case PdmDpiY: for (const QWidget *p = this; p; p = p->parentWidget()) { if (p->d_func()->extra && p->d_func()->extra->customDpiY) return p->d_func()->extra->customDpiY; } return qRound(screen->logicalDotsPerInchY()); - } else if (m == PdmPhysicalDpiX) { + case PdmPhysicalDpiX: return qRound(screen->physicalDotsPerInchX()); - } else if (m == PdmPhysicalDpiY) { + case PdmPhysicalDpiY: return qRound(screen->physicalDotsPerInchY()); - } else if (m == PdmDevicePixelRatio) { + case PdmDevicePixelRatio: return screen->devicePixelRatio(); - } else if (m == PdmDevicePixelRatioScaled) { + case PdmDevicePixelRatioScaled: return QPaintDevice::devicePixelRatioFScale() * screen->devicePixelRatio(); - } else { - val = QPaintDevice::metric(m); + default: + break; } - return val; + return QPaintDevice::metric(m); } /*! -- cgit v1.2.3