diff options
author | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2022-05-23 11:03:04 +0200 |
---|---|---|
committer | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2022-05-24 22:11:51 +0200 |
commit | d1d75f3b72b2d4e8f4a75b552023b1ea6381fccc (patch) | |
tree | aa7f730962eeadbcef05139b99ae481689017b34 /src | |
parent | ba7a3b8d4a54564d4cf5392285376b36d80f60fd (diff) |
Refactor if-else snake into switch statement
Change-Id: I597d5cbdddf4a2fbbe8b9de2ae252cdeadce9d11
Reviewed-by: Thorbjørn Lund Martsum <tmartsum@gmail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/widgets/kernel/qwidget.cpp | 39 |
1 files changed, 20 insertions, 19 deletions
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); } /*! |