From 71a1ea481bf982e35fd1532e59c0ebebf4b5da69 Mon Sep 17 00:00:00 2001 From: Jonas Kvinge Date: Fri, 17 Jul 2020 01:32:07 +0200 Subject: [PATCH] Replace some uses of static_cast with qobject_cast --- ext/libstrawberry-common/core/messagehandler.cpp | 4 ++-- src/collection/collection.cpp | 2 +- src/core/mergedproxymodel.cpp | 6 +++--- src/device/devicemanager.cpp | 8 ++++---- src/device/filesystemdevice.cpp | 2 +- src/globalshortcuts/globalshortcuts.cpp | 4 ++-- src/scrobbler/audioscrobbler.h | 2 +- src/scrobbler/scrobblerservices.h | 2 +- src/settings/settingsdialog.cpp | 2 +- src/tidal/tidalservice.cpp | 2 +- src/widgets/fileviewlist.cpp | 6 +++--- src/widgets/osdpretty.cpp | 2 +- 12 files changed, 21 insertions(+), 21 deletions(-) diff --git a/ext/libstrawberry-common/core/messagehandler.cpp b/ext/libstrawberry-common/core/messagehandler.cpp index 95d7f83b6..52e2ab1f9 100644 --- a/ext/libstrawberry-common/core/messagehandler.cpp +++ b/ext/libstrawberry-common/core/messagehandler.cpp @@ -102,10 +102,10 @@ void _MessageHandlerBase::WriteMessage(const QByteArray &data) { // Sorry. if (flush_abstract_socket_) { - ((static_cast(device_))->*(flush_abstract_socket_))(); + ((qobject_cast(device_))->*(flush_abstract_socket_))(); } else if (flush_local_socket_) { - ((static_cast(device_))->*(flush_local_socket_))(); + ((qobject_cast(device_))->*(flush_local_socket_))(); } } diff --git a/src/collection/collection.cpp b/src/collection/collection.cpp index acbe36597..44276f0b0 100644 --- a/src/collection/collection.cpp +++ b/src/collection/collection.cpp @@ -131,7 +131,7 @@ void SCollection::Exit() { void SCollection::ExitReceived() { - QObject *obj = static_cast(sender()); + QObject *obj = qobject_cast(sender()); disconnect(obj, nullptr, this, nullptr); qLog(Debug) << obj << "successfully exited."; wait_for_exit_.removeAll(obj); diff --git a/src/core/mergedproxymodel.cpp b/src/core/mergedproxymodel.cpp index 57d15d893..633fc930f 100644 --- a/src/core/mergedproxymodel.cpp +++ b/src/core/mergedproxymodel.cpp @@ -193,7 +193,7 @@ void MergedProxyModel::SourceModelReset() { void MergedProxyModel::SubModelReset() { - QAbstractItemModel *submodel = static_cast(sender()); + QAbstractItemModel *submodel = qobject_cast(sender()); // TODO: When we require Qt 4.6, use beginResetModel() and endResetModel() in CollectionModel and catch those here // that will let us do away with this std::numeric_limits::max() hack. @@ -241,7 +241,7 @@ QModelIndex MergedProxyModel::GetActualSourceParent(const QModelIndex &source_pa } void MergedProxyModel::RowsAboutToBeInserted(const QModelIndex &source_parent, int start, int end) { - beginInsertRows(mapFromSource(GetActualSourceParent(source_parent, static_cast(sender()))), start, end); + beginInsertRows(mapFromSource(GetActualSourceParent(source_parent, qobject_cast(sender()))), start, end); } void MergedProxyModel::RowsInserted(const QModelIndex&, int, int) { @@ -249,7 +249,7 @@ void MergedProxyModel::RowsInserted(const QModelIndex&, int, int) { } void MergedProxyModel::RowsAboutToBeRemoved(const QModelIndex &source_parent, int start, int end) { - beginRemoveRows(mapFromSource(GetActualSourceParent(source_parent, static_cast(sender()))), start, end); + beginRemoveRows(mapFromSource(GetActualSourceParent(source_parent, qobject_cast(sender()))), start, end); } void MergedProxyModel::RowsRemoved(const QModelIndex&, int, int) { diff --git a/src/device/devicemanager.cpp b/src/device/devicemanager.cpp index 4a617fa5d..827b67a0e 100644 --- a/src/device/devicemanager.cpp +++ b/src/device/devicemanager.cpp @@ -205,7 +205,7 @@ void DeviceManager::CloseBackend() { void DeviceManager::BackendClosed() { - QObject *obj = static_cast(sender()); + QObject *obj = qobject_cast(sender()); disconnect(obj, nullptr, this, nullptr); qLog(Debug) << obj << "successfully closed."; wait_for_exit_.removeAll(obj); @@ -215,7 +215,7 @@ void DeviceManager::BackendClosed() { void DeviceManager::ListerClosed() { - DeviceLister *lister = static_cast(sender()); + DeviceLister *lister = qobject_cast(sender()); if (!lister) return; disconnect(lister, nullptr, this, nullptr); @@ -228,7 +228,7 @@ void DeviceManager::ListerClosed() { void DeviceManager::DeviceDestroyed() { - ConnectedDevice *device = static_cast(sender()); + ConnectedDevice *device = qobject_cast(sender()); if (!wait_for_exit_.contains(device) || !backend_) return; wait_for_exit_.removeAll(device); @@ -645,7 +645,7 @@ std::shared_ptr DeviceManager::Connect(DeviceInfo *info) { Q_ARG(int, info->database_id_), Q_ARG(bool, first_time)); - ret.reset(static_cast(instance)); + ret.reset(qobject_cast(instance)); if (!ret) { qLog(Warning) << "Could not create device for" << device_url.toString(); diff --git a/src/device/filesystemdevice.cpp b/src/device/filesystemdevice.cpp index 9a43dacb7..c49e4a955 100644 --- a/src/device/filesystemdevice.cpp +++ b/src/device/filesystemdevice.cpp @@ -105,7 +105,7 @@ void FilesystemDevice::Close() { void FilesystemDevice::ExitFinished() { - QObject *obj = static_cast(sender()); + QObject *obj = qobject_cast(sender()); if (!obj) return; disconnect(obj, nullptr, this, nullptr); qLog(Debug) << obj << "successfully exited."; diff --git a/src/globalshortcuts/globalshortcuts.cpp b/src/globalshortcuts/globalshortcuts.cpp index 72c28bb7d..7e5760129 100644 --- a/src/globalshortcuts/globalshortcuts.cpp +++ b/src/globalshortcuts/globalshortcuts.cpp @@ -178,7 +178,7 @@ void GlobalShortcuts::Unregister() { bool GlobalShortcuts::IsMacAccessibilityEnabled() const { #ifdef Q_OS_MACOS - if (system_backend_) return static_cast(system_backend_)->IsAccessibilityEnabled(); + if (system_backend_) return qobject_cast(system_backend_)->IsAccessibilityEnabled(); else return false; #else return true; @@ -187,6 +187,6 @@ bool GlobalShortcuts::IsMacAccessibilityEnabled() const { void GlobalShortcuts::ShowMacAccessibilityDialog() { #ifdef Q_OS_MACOS - if (system_backend_) static_cast(system_backend_)->ShowAccessibilityDialog(); + if (system_backend_) qobject_cast(system_backend_)->ShowAccessibilityDialog(); #endif } diff --git a/src/scrobbler/audioscrobbler.h b/src/scrobbler/audioscrobbler.h index 89575ac1d..23aac344e 100644 --- a/src/scrobbler/audioscrobbler.h +++ b/src/scrobbler/audioscrobbler.h @@ -56,7 +56,7 @@ class AudioScrobbler : public QObject { template T *Service() { - return static_cast(this->ServiceByName(T::kName)); + return qobject_cast(this->ServiceByName(T::kName)); } public slots: diff --git a/src/scrobbler/scrobblerservices.h b/src/scrobbler/scrobblerservices.h index b7dcddb1c..83275c955 100644 --- a/src/scrobbler/scrobblerservices.h +++ b/src/scrobbler/scrobblerservices.h @@ -48,7 +48,7 @@ class ScrobblerServices : public QObject { ScrobblerService *ServiceByName(const QString &name); template T *Service() { - return static_cast(this->ServiceByName(T::kName)); + return qobject_cast(this->ServiceByName(T::kName)); } private: diff --git a/src/settings/settingsdialog.cpp b/src/settings/settingsdialog.cpp index b8bf5ed59..e2a0f3669 100644 --- a/src/settings/settingsdialog.cpp +++ b/src/settings/settingsdialog.cpp @@ -168,7 +168,7 @@ SettingsDialog::SettingsDialog(Application *app, QMainWindow *mainwindow, QWidge ui_->list->setCurrentItem(pages_[Page_Behaviour].item_); // Make sure the list is big enough to show all the items - ui_->list->setMinimumWidth(static_cast(ui_->list)->sizeHintForColumn(0)); + ui_->list->setMinimumWidth(qobject_cast(ui_->list)->sizeHintForColumn(0)); ui_->buttonBox->button(QDialogButtonBox::Cancel)->setShortcut(QKeySequence::Close); diff --git a/src/tidal/tidalservice.cpp b/src/tidal/tidalservice.cpp index 05ef9980b..283a83a32 100644 --- a/src/tidal/tidalservice.cpp +++ b/src/tidal/tidalservice.cpp @@ -224,7 +224,7 @@ void TidalService::Exit() { void TidalService::ExitReceived() { - QObject *obj = static_cast(sender()); + QObject *obj = qobject_cast(sender()); disconnect(obj, nullptr, this, nullptr); qLog(Debug) << obj << "successfully exited."; wait_for_exit_.removeAll(obj); diff --git a/src/widgets/fileviewlist.cpp b/src/widgets/fileviewlist.cpp index e1a82cca1..6c2bf2003 100644 --- a/src/widgets/fileviewlist.cpp +++ b/src/widgets/fileviewlist.cpp @@ -72,7 +72,7 @@ QList FileViewList::UrlListFromSelection() const { QList urls; for (const QModelIndex& index : menu_selection_.indexes()) { if (index.column() == 0) - urls << QUrl::fromLocalFile(static_cast(model())->fileInfo(index).canonicalFilePath()); + urls << QUrl::fromLocalFile(qobject_cast(model())->fileInfo(index).canonicalFilePath()); } std::sort(urls.begin(), urls.end()); @@ -98,7 +98,7 @@ MimeData *FileViewList::MimeDataFromSelection() const { } // otherwise, use the current root path else { - QString path = static_cast(model())->rootPath(); + QString path = qobject_cast(model())->rootPath(); if (path.length() > 20) { QFileInfo info(path); if (info.isDir()) { @@ -122,7 +122,7 @@ QStringList FileViewList::FilenamesFromSelection() const { QStringList filenames; for (const QModelIndex& index : menu_selection_.indexes()) { if (index.column() == 0) - filenames << static_cast(model())->filePath(index); + filenames << qobject_cast(model())->filePath(index); } return filenames; diff --git a/src/widgets/osdpretty.cpp b/src/widgets/osdpretty.cpp index 55a831cb6..e284e4bf3 100644 --- a/src/widgets/osdpretty.cpp +++ b/src/widgets/osdpretty.cpp @@ -145,7 +145,7 @@ OSDPretty::OSDPretty(Mode mode, QWidget *parent) background_ = QPixmap(":/pictures/osd_background.png"); // Set the margins to allow for the drop shadow - QBoxLayout *l = static_cast(layout()); + QBoxLayout *l = qobject_cast(layout()); int margin = l->margin() + kDropShadowSize; l->setMargin(margin);