Skip to content

Commit

Permalink
Merge pull request #3340 from uklotzde/type_casts
Browse files Browse the repository at this point in the history
Use qobject_cast
  • Loading branch information
daschuer authored Nov 19, 2020
2 parents a76433f + 47b41d8 commit 0814bd8
Show file tree
Hide file tree
Showing 40 changed files with 57 additions and 57 deletions.
8 changes: 4 additions & 4 deletions src/controllers/controllerlearningeventfilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ ControllerLearningEventFilter::~ControllerLearningEventFilter() {
bool ControllerLearningEventFilter::eventFilter(QObject* pObject, QEvent* pEvent) {
//qDebug() << "ControllerLearningEventFilter::eventFilter" << pObject << pEvent;

WWidget* pWidget = dynamic_cast<WWidget*>(pObject);
WWidget* pWidget = qobject_cast<WWidget*>(pObject);
if (!pWidget || !m_bListening) {
return false;
}

WKnob* pKnob = dynamic_cast<WKnob*>(pObject);
WKnobComposed* pKnobComposed = dynamic_cast<WKnobComposed*>(pObject);
WSliderComposed* pSlider = dynamic_cast<WSliderComposed*>(pObject);
WKnob* pKnob = qobject_cast<WKnob*>(pObject);
WKnobComposed* pKnobComposed = qobject_cast<WKnobComposed*>(pObject);
WSliderComposed* pSlider = qobject_cast<WSliderComposed*>(pObject);
bool has_right_click_reset = pKnob || pKnobComposed || pSlider;

if (pEvent->type() == QEvent::KeyPress) {
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/delegates/controldelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void ControlDelegate::setEditorData(QWidget* editor,
const QModelIndex& index) const {
ConfigKey key = index.data(Qt::EditRole).value<ConfigKey>();

QLineEdit* pLineEdit = dynamic_cast<QLineEdit*>(editor);
QLineEdit* pLineEdit = qobject_cast<QLineEdit*>(editor);
if (pLineEdit == NULL) {
return;
}
Expand Down
4 changes: 2 additions & 2 deletions src/controllers/delegates/midibytedelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ QString MidiByteDelegate::displayText(const QVariant& value,
void MidiByteDelegate::setEditorData(QWidget* editor,
const QModelIndex& index) const {
int control = index.data(Qt::EditRole).toInt();
HexSpinBox* pSpinBox = dynamic_cast<HexSpinBox*>(editor);
HexSpinBox* pSpinBox = qobject_cast<HexSpinBox*>(editor);
if (pSpinBox == NULL) {
return;
}
Expand All @@ -40,7 +40,7 @@ void MidiByteDelegate::setEditorData(QWidget* editor,
void MidiByteDelegate::setModelData(QWidget* editor,
QAbstractItemModel* model,
const QModelIndex& index) const {
HexSpinBox* pSpinBox = dynamic_cast<HexSpinBox*>(editor);
HexSpinBox* pSpinBox = qobject_cast<HexSpinBox*>(editor);
if (pSpinBox == NULL) {
return;
}
Expand Down
4 changes: 2 additions & 2 deletions src/controllers/delegates/midichanneldelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ QString MidiChannelDelegate::displayText(const QVariant& value,
void MidiChannelDelegate::setEditorData(QWidget* editor,
const QModelIndex& index) const {
int channel = index.data(Qt::EditRole).toInt();
QSpinBox* pSpinBox = dynamic_cast<QSpinBox*>(editor);
QSpinBox* pSpinBox = qobject_cast<QSpinBox*>(editor);
if (pSpinBox == NULL) {
return;
}
Expand All @@ -45,7 +45,7 @@ void MidiChannelDelegate::setEditorData(QWidget* editor,
void MidiChannelDelegate::setModelData(QWidget* editor,
QAbstractItemModel* model,
const QModelIndex& index) const {
QSpinBox* pSpinBox = dynamic_cast<QSpinBox*>(editor);
QSpinBox* pSpinBox = qobject_cast<QSpinBox*>(editor);
if (pSpinBox == NULL) {
return;
}
Expand Down
4 changes: 2 additions & 2 deletions src/controllers/delegates/midiopcodedelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ QString MidiOpCodeDelegate::displayText(const QVariant& value,
void MidiOpCodeDelegate::setEditorData(QWidget* editor,
const QModelIndex& index) const {
int opCode = index.data(Qt::EditRole).toInt();
QComboBox* pComboBox = dynamic_cast<QComboBox*>(editor);
QComboBox* pComboBox = qobject_cast<QComboBox*>(editor);
if (pComboBox == NULL) {
return;
}
Expand All @@ -55,7 +55,7 @@ void MidiOpCodeDelegate::setEditorData(QWidget* editor,
void MidiOpCodeDelegate::setModelData(QWidget* editor,
QAbstractItemModel* model,
const QModelIndex& index) const {
QComboBox* pComboBox = dynamic_cast<QComboBox*>(editor);
QComboBox* pComboBox = qobject_cast<QComboBox*>(editor);
if (pComboBox == NULL) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/delegates/midioptionsdelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void MidiOptionsDelegate::setEditorData(QWidget* editor,
const QModelIndex& index) const {
MidiOptions options = index.data(Qt::EditRole).value<MidiOptions>();

QComboBox* pComboBox = dynamic_cast<QComboBox*>(editor);
QComboBox* pComboBox = qobject_cast<QComboBox*>(editor);
if (pComboBox == NULL) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/softtakeover.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ SoftTakeoverCtrl::~SoftTakeoverCtrl() {
}

void SoftTakeoverCtrl::enable(ControlObject* control) {
ControlPotmeter* cpo = dynamic_cast<ControlPotmeter*>(control);
ControlPotmeter* cpo = qobject_cast<ControlPotmeter*>(control);
if (cpo == NULL) {
// softtakecover works only for continuous ControlPotmeter based COs
return;
Expand Down
2 changes: 1 addition & 1 deletion src/library/autodj/dlgautodj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ DlgAutoDJ::DlgAutoDJ(
m_pTrackTableView,
&WTrackTableView::setSelectedClick);

QBoxLayout* box = dynamic_cast<QBoxLayout*>(layout());
QBoxLayout* box = qobject_cast<QBoxLayout*>(layout());
VERIFY_OR_DEBUG_ASSERT(box) { //Assumes the form layout is a QVBox/QHBoxLayout!
} else {
box->removeWidget(m_pTrackTablePlaceholder);
Expand Down
2 changes: 1 addition & 1 deletion src/library/coverartdelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ void CoverArtDelegate::paintItem(
return;
}
const double scaleFactor =
getDevicePixelRatioF(static_cast<QWidget*>(parent()));
getDevicePixelRatioF(qobject_cast<QWidget*>(parent()));
QPixmap pixmap = m_pCache->tryLoadCover(this,
coverInfo,
static_cast<int>(option.rect.width() * scaleFactor),
Expand Down
2 changes: 1 addition & 1 deletion src/library/dlganalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ DlgAnalysis::DlgAnalysis(WLibrary* parent,
this,
&DlgAnalysis::trackSelected);

QBoxLayout* box = dynamic_cast<QBoxLayout*>(layout());
QBoxLayout* box = qobject_cast<QBoxLayout*>(layout());
VERIFY_OR_DEBUG_ASSERT(box) { // Assumes the form layout is a QVBox/QHBoxLayout!
} else {
box->removeWidget(m_pTrackTablePlaceholder);
Expand Down
2 changes: 1 addition & 1 deletion src/library/dlghidden.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ DlgHidden::DlgHidden(
m_pTrackTableView->installEventFilter(pKeyboard);

// Install our own trackTable
QBoxLayout* box = dynamic_cast<QBoxLayout*>(layout());
QBoxLayout* box = qobject_cast<QBoxLayout*>(layout());
VERIFY_OR_DEBUG_ASSERT(box) { //Assumes the form layout is a QVBox/QHBoxLayout!
} else {
box->removeWidget(m_pTrackTablePlaceholder);
Expand Down
2 changes: 1 addition & 1 deletion src/library/dlgmissing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ DlgMissing::DlgMissing(
m_pTrackTableView->installEventFilter(pKeyboard);

// Install our own trackTable
QBoxLayout* box = dynamic_cast<QBoxLayout*>(layout());
QBoxLayout* box = qobject_cast<QBoxLayout*>(layout());
VERIFY_OR_DEBUG_ASSERT(box) { //Assumes the form layout is a QVBox/QHBoxLayout!
} else {
box->removeWidget(m_pTrackTablePlaceholder);
Expand Down
2 changes: 1 addition & 1 deletion src/library/previewbuttondelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class PreviewButtonDelegate : public TableItemDelegate {

private:
QTableView* parentTableView() const {
return static_cast<QTableView*>(parent());
return qobject_cast<QTableView*>(parent());
}
bool isPreviewDeckPlaying() const;
bool isTrackLoadedInPreviewDeck(
Expand Down
2 changes: 1 addition & 1 deletion src/library/recording/dlgrecording.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ DlgRecording::DlgRecording(
this,
&DlgRecording::slotDurationRecorded);

QBoxLayout* box = dynamic_cast<QBoxLayout*>(layout());
QBoxLayout* box = qobject_cast<QBoxLayout*>(layout());
VERIFY_OR_DEBUG_ASSERT(box) { //Assumes the form layout is a QVBox/QHBoxLayout!
} else {
box->removeWidget(m_pTrackTablePlaceholder);
Expand Down
2 changes: 1 addition & 1 deletion src/preferences/dialog/dlgpreferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ DlgPreferencePage* DlgPreferences::currentPage() {
}
pObject = children[0];
}
return dynamic_cast<DlgPreferencePage*>(pObject);
return qobject_cast<DlgPreferencePage*>(pObject);
}

void DlgPreferences::removePageWidget(DlgPreferencePage* pWidget) {
Expand Down
2 changes: 1 addition & 1 deletion src/util/compatibility.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ QString uuidToNullableStringWithoutBraces(const QUuid& uuid) {

inline QScreen* getPrimaryScreen() {
#if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)
QGuiApplication* app = static_cast<QGuiApplication*>(QCoreApplication::instance());
QGuiApplication* app = qobject_cast<QGuiApplication*>(QCoreApplication::instance());
VERIFY_OR_DEBUG_ASSERT(app) {
qWarning() << "Unable to get applications QCoreApplication instance, "
"cannot determine primary screen!";
Expand Down
3 changes: 1 addition & 2 deletions src/util/taskmonitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,8 @@ TaskMonitor::~TaskMonitor() {

Task* TaskMonitor::senderTask() const {
DEBUG_ASSERT_QOBJECT_THREAD_AFFINITY(this);
auto* pTask = static_cast<Task*>(sender());
auto* pTask = qobject_cast<Task*>(sender());
DEBUG_ASSERT(pTask);
DEBUG_ASSERT(dynamic_cast<Task*>(sender()));
return pTask;
}

Expand Down
2 changes: 1 addition & 1 deletion src/util/widgethelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ inline QScreen* getScreen(
if (!pWindow && widget.parent()) {
// The window might still be hidden and invisible. Then we
// try to obtain the screen from its parent recursively.
return getScreen(*static_cast<QWidget*>(widget.parent()));
return getScreen(*qobject_cast<QWidget*>(widget.parent()));
}
if (!pWindow) {
// This might happen if the widget is not yet displayed
Expand Down
6 changes: 3 additions & 3 deletions src/waveform/waveformwidgetfactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ bool shouldRenderWaveform(WaveformWidgetAbstract* pWaveformWidget) {
return false;
}

auto glw = dynamic_cast<QGLWidget*>(pWaveformWidget->getWidget());
auto* glw = qobject_cast<QGLWidget*>(pWaveformWidget->getWidget());
if (glw == nullptr) {
// Not a QGLWidget. We can simply use QWidget::isVisible.
auto qwidget = dynamic_cast<QWidget*>(pWaveformWidget->getWidget());
auto qwidget = qobject_cast<QWidget*>(pWaveformWidget->getWidget());
return qwidget != nullptr && qwidget->isVisible();
}

Expand Down Expand Up @@ -711,7 +711,7 @@ void WaveformWidgetFactory::swap() {
if (!shouldRenderWaveform(pWaveformWidget)) {
continue;
}
QGLWidget* glw = dynamic_cast<QGLWidget*>(pWaveformWidget->getWidget());
QGLWidget* glw = qobject_cast<QGLWidget*>(pWaveformWidget->getWidget());
if (glw != nullptr) {
glw->swapBuffers();
}
Expand Down
2 changes: 1 addition & 1 deletion src/waveform/widgets/emptywaveformwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ EmptyWaveformWidget::~EmptyWaveformWidget() {
}

void EmptyWaveformWidget::castToQWidget() {
m_widget = static_cast<QWidget*>(this);
m_widget = this;
}

void EmptyWaveformWidget::paintEvent(QPaintEvent* event) {
Expand Down
2 changes: 1 addition & 1 deletion src/waveform/widgets/glrgbwaveformwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ GLRGBWaveformWidget::~GLRGBWaveformWidget() {
}

void GLRGBWaveformWidget::castToQWidget() {
m_widget = static_cast<QWidget*>(static_cast<QGLWidget*>(this));
m_widget = this;
}

void GLRGBWaveformWidget::paintEvent(QPaintEvent* event) {
Expand Down
2 changes: 1 addition & 1 deletion src/waveform/widgets/glsimplewaveformwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ GLSimpleWaveformWidget::~GLSimpleWaveformWidget() {
}

void GLSimpleWaveformWidget::castToQWidget() {
m_widget = static_cast<QWidget*>(static_cast<QGLWidget*>(this));
m_widget = this;
}

void GLSimpleWaveformWidget::paintEvent(QPaintEvent* event) {
Expand Down
2 changes: 1 addition & 1 deletion src/waveform/widgets/glvsynctestwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ GLVSyncTestWidget::~GLVSyncTestWidget() {
}

void GLVSyncTestWidget::castToQWidget() {
m_widget = static_cast<QWidget*>(static_cast<QGLWidget*>(this));
m_widget = this;
}

void GLVSyncTestWidget::paintEvent(QPaintEvent* event) {
Expand Down
2 changes: 1 addition & 1 deletion src/waveform/widgets/glwaveformwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ GLWaveformWidget::~GLWaveformWidget() {
}

void GLWaveformWidget::castToQWidget() {
m_widget = static_cast<QWidget*>(static_cast<QGLWidget*>(this));
m_widget = this;
}

void GLWaveformWidget::paintEvent(QPaintEvent* event) {
Expand Down
2 changes: 1 addition & 1 deletion src/waveform/widgets/hsvwaveformwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ HSVWaveformWidget::~HSVWaveformWidget() {
}

void HSVWaveformWidget::castToQWidget() {
m_widget = static_cast<QWidget*>(this);
m_widget = this;
}

void HSVWaveformWidget::paintEvent(QPaintEvent* event) {
Expand Down
2 changes: 1 addition & 1 deletion src/waveform/widgets/qthsvwaveformwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ QtHSVWaveformWidget::~QtHSVWaveformWidget() {
}

void QtHSVWaveformWidget::castToQWidget() {
m_widget = static_cast<QWidget*>(static_cast<QGLWidget*>(this));
m_widget = this;
}

void QtHSVWaveformWidget::paintEvent(QPaintEvent* event) {
Expand Down
2 changes: 1 addition & 1 deletion src/waveform/widgets/qtrgbwaveformwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ QtRGBWaveformWidget::~QtRGBWaveformWidget() {
}

void QtRGBWaveformWidget::castToQWidget() {
m_widget = static_cast<QWidget*>(static_cast<QGLWidget*>(this));
m_widget = this;
}

void QtRGBWaveformWidget::paintEvent(QPaintEvent* event) {
Expand Down
2 changes: 1 addition & 1 deletion src/waveform/widgets/qtsimplewaveformwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ QtSimpleWaveformWidget::~QtSimpleWaveformWidget() {
}

void QtSimpleWaveformWidget::castToQWidget() {
m_widget = static_cast<QWidget*>(static_cast<QGLWidget*>(this));
m_widget = this;
}

void QtSimpleWaveformWidget::paintEvent(QPaintEvent* event) {
Expand Down
2 changes: 1 addition & 1 deletion src/waveform/widgets/qtvsynctestwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ QtVSyncTestWidget::~QtVSyncTestWidget() {
}

void QtVSyncTestWidget::castToQWidget() {
m_widget = static_cast<QWidget*>(static_cast<QGLWidget*>(this));
m_widget = this;
}

void QtVSyncTestWidget::paintEvent(QPaintEvent* event) {
Expand Down
2 changes: 1 addition & 1 deletion src/waveform/widgets/qtwaveformwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ QtWaveformWidget::~QtWaveformWidget() {
}

void QtWaveformWidget::castToQWidget() {
m_widget = static_cast<QWidget*>(static_cast<QGLWidget*>(this));
m_widget = this;
}

void QtWaveformWidget::paintEvent(QPaintEvent* event) {
Expand Down
2 changes: 1 addition & 1 deletion src/waveform/widgets/rgbwaveformwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ RGBWaveformWidget::~RGBWaveformWidget() {
}

void RGBWaveformWidget::castToQWidget() {
m_widget = static_cast<QWidget*>(this);
m_widget = this;
}

void RGBWaveformWidget::paintEvent(QPaintEvent* event) {
Expand Down
2 changes: 1 addition & 1 deletion src/waveform/widgets/softwarewaveformwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ SoftwareWaveformWidget::~SoftwareWaveformWidget() {
}

void SoftwareWaveformWidget::castToQWidget() {
m_widget = static_cast<QWidget*>(this);
m_widget = this;
}

void SoftwareWaveformWidget::paintEvent(QPaintEvent* event) {
Expand Down
3 changes: 2 additions & 1 deletion src/widget/hexspinbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
#include <QValidator>

class HexSpinBox : public QSpinBox {
Q_OBJECT
public:
explicit HexSpinBox(QWidget *pParent);
explicit HexSpinBox(QWidget* pParent);

protected:
QString textFromValue(int value) const override;
Expand Down
2 changes: 1 addition & 1 deletion src/widget/wbeatspinbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ WBeatSpinBox::WBeatSpinBox(QWidget* parent,
void WBeatSpinBox::setup(const QDomNode& node, const SkinContext& context) {
Q_UNUSED(node);
m_scaleFactor = context.getScaleFactor();
static_cast<WBeatLineEdit*>(lineEdit())->setScaleFactor(m_scaleFactor);
qobject_cast<WBeatLineEdit*>(lineEdit())->setScaleFactor(m_scaleFactor);
}

void WBeatSpinBox::stepBy(int steps) {
Expand Down
4 changes: 2 additions & 2 deletions src/widget/wcolorpicker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ WColorPicker::WColorPicker(Options options, const ColorPalette& palette, QWidget
}

void WColorPicker::removeColorButtons() {
QGridLayout* pLayout = static_cast<QGridLayout*>(layout());
QGridLayout* pLayout = qobject_cast<QGridLayout*>(layout());
VERIFY_OR_DEBUG_ASSERT(pLayout) {
qWarning() << "Color Picker has no layout!";
return;
Expand All @@ -100,7 +100,7 @@ void WColorPicker::removeColorButtons() {
}

void WColorPicker::addColorButtons() {
QGridLayout* pLayout = static_cast<QGridLayout*>(layout());
QGridLayout* pLayout = qobject_cast<QGridLayout*>(layout());
VERIFY_OR_DEBUG_ASSERT(pLayout) {
qWarning() << "Color Picker has no layout!";
return;
Expand Down
2 changes: 1 addition & 1 deletion src/widget/wcuemenupopup.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class WCueMenuPopup : public QWidget {
}

void popup(const QPoint& p) {
auto parentWidget = static_cast<QWidget*>(parent());
auto parentWidget = qobject_cast<QWidget*>(parent());
QPoint topLeft = mixxx::widgethelper::mapPopupToScreen(*parentWidget, p, size());
move(topLeft);
show();
Expand Down
Loading

0 comments on commit 0814bd8

Please sign in to comment.