diff options
author | David Robillard <d@drobilla.net> | 2024-09-29 19:43:45 -0400 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2024-10-12 14:07:10 -0400 |
commit | 801e6b38d0b8de39aa7027db78069695d9c35404 (patch) | |
tree | d34b036e11d3aa7754f2107c7e2a26d6a62ba642 /src/jalv_qt.cpp | |
parent | 76056507e733a4dbdc3828a679c7c1c8a0c170fa (diff) | |
download | jalv-801e6b38d0b8de39aa7027db78069695d9c35404.tar.gz jalv-801e6b38d0b8de39aa7027db78069695d9c35404.tar.bz2 jalv-801e6b38d0b8de39aa7027db78069695d9c35404.zip |
Avoid static downcasts
Diffstat (limited to 'src/jalv_qt.cpp')
-rw-r--r-- | src/jalv_qt.cpp | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/src/jalv_qt.cpp b/src/jalv_qt.cpp index f13ee6f..ef29858 100644 --- a/src/jalv_qt.cpp +++ b/src/jalv_qt.cpp @@ -253,17 +253,22 @@ FlowLayout::doLayout(const QRect& rect, bool testOnly) const int FlowLayout::smartSpacing(QStyle::PixelMetric pm) const { - QObject* parent = this->parent(); + QObject* const parent = this->parent(); if (!parent) { return -1; } - if (parent->isWidgetType()) { - auto* const pw = static_cast<QWidget*>(parent); - return pw->style()->pixelMetric(pm, nullptr, pw); + auto* const parentWidget = qobject_cast<QWidget*>(parent); + if (parentWidget) { + return parentWidget->style()->pixelMetric(pm, nullptr, parentWidget); } - return static_cast<QLayout*>(parent)->spacing(); + auto* const parentLayout = qobject_cast<QLayout*>(parent); + if (parentLayout) { + return parentLayout->spacing(); + } + + return -1; } class Timer : public QTimer @@ -672,13 +677,13 @@ jalv_frontend_open(Jalv* jalv) if (jalv->ui_instance) { widget = static_cast<QWidget*>(suil_instance_get_widget(jalv->ui_instance)); } else { - QWidget* controlWidget = build_control_widget(jalv); - - widget = new QScrollArea(); - static_cast<QScrollArea*>(widget)->setWidget(controlWidget); - static_cast<QScrollArea*>(widget)->setWidgetResizable(true); - widget->setMinimumWidth(800); - widget->setMinimumHeight(600); + auto* const controlWidget = build_control_widget(jalv); + auto* const scrollArea = new QScrollArea(); + scrollArea->setWidget(controlWidget); + scrollArea->setWidgetResizable(true); + scrollArea->setMinimumWidth(800); + scrollArea->setMinimumHeight(600); + widget = scrollArea; } LilvNode* name = lilv_plugin_get_name(jalv->plugin); |