Replace some uses of static_cast with qobject_cast

This commit is contained in:
Jonas Kvinge 2020-07-17 01:32:07 +02:00
parent 9e32f0d778
commit 71a1ea481b
12 changed files with 21 additions and 21 deletions

View File

@ -102,10 +102,10 @@ void _MessageHandlerBase::WriteMessage(const QByteArray &data) {
// Sorry.
if (flush_abstract_socket_) {
((static_cast<QAbstractSocket*>(device_))->*(flush_abstract_socket_))();
((qobject_cast<QAbstractSocket*>(device_))->*(flush_abstract_socket_))();
}
else if (flush_local_socket_) {
((static_cast<QLocalSocket*>(device_))->*(flush_local_socket_))();
((qobject_cast<QLocalSocket*>(device_))->*(flush_local_socket_))();
}
}

View File

@ -131,7 +131,7 @@ void SCollection::Exit() {
void SCollection::ExitReceived() {
QObject *obj = static_cast<QObject*>(sender());
QObject *obj = qobject_cast<QObject*>(sender());
disconnect(obj, nullptr, this, nullptr);
qLog(Debug) << obj << "successfully exited.";
wait_for_exit_.removeAll(obj);

View File

@ -193,7 +193,7 @@ void MergedProxyModel::SourceModelReset() {
void MergedProxyModel::SubModelReset() {
QAbstractItemModel *submodel = static_cast<QAbstractItemModel*>(sender());
QAbstractItemModel *submodel = qobject_cast<QAbstractItemModel*>(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<int>::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<QAbstractItemModel*>(sender()))), start, end);
beginInsertRows(mapFromSource(GetActualSourceParent(source_parent, qobject_cast<QAbstractItemModel*>(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<QAbstractItemModel*>(sender()))), start, end);
beginRemoveRows(mapFromSource(GetActualSourceParent(source_parent, qobject_cast<QAbstractItemModel*>(sender()))), start, end);
}
void MergedProxyModel::RowsRemoved(const QModelIndex&, int, int) {

View File

@ -205,7 +205,7 @@ void DeviceManager::CloseBackend() {
void DeviceManager::BackendClosed() {
QObject *obj = static_cast<QObject*>(sender());
QObject *obj = qobject_cast<QObject*>(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<DeviceLister*>(sender());
DeviceLister *lister = qobject_cast<DeviceLister*>(sender());
if (!lister) return;
disconnect(lister, nullptr, this, nullptr);
@ -228,7 +228,7 @@ void DeviceManager::ListerClosed() {
void DeviceManager::DeviceDestroyed() {
ConnectedDevice *device = static_cast<ConnectedDevice*>(sender());
ConnectedDevice *device = qobject_cast<ConnectedDevice*>(sender());
if (!wait_for_exit_.contains(device) || !backend_) return;
wait_for_exit_.removeAll(device);
@ -645,7 +645,7 @@ std::shared_ptr<ConnectedDevice> DeviceManager::Connect(DeviceInfo *info) {
Q_ARG(int, info->database_id_),
Q_ARG(bool, first_time));
ret.reset(static_cast<ConnectedDevice*>(instance));
ret.reset(qobject_cast<ConnectedDevice*>(instance));
if (!ret) {
qLog(Warning) << "Could not create device for" << device_url.toString();

View File

@ -105,7 +105,7 @@ void FilesystemDevice::Close() {
void FilesystemDevice::ExitFinished() {
QObject *obj = static_cast<QObject*>(sender());
QObject *obj = qobject_cast<QObject*>(sender());
if (!obj) return;
disconnect(obj, nullptr, this, nullptr);
qLog(Debug) << obj << "successfully exited.";

View File

@ -178,7 +178,7 @@ void GlobalShortcuts::Unregister() {
bool GlobalShortcuts::IsMacAccessibilityEnabled() const {
#ifdef Q_OS_MACOS
if (system_backend_) return static_cast<GlobalShortcutBackendMacOS*>(system_backend_)->IsAccessibilityEnabled();
if (system_backend_) return qobject_cast<GlobalShortcutBackendMacOS*>(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<GlobalShortcutBackendMacOS*>(system_backend_)->ShowAccessibilityDialog();
if (system_backend_) qobject_cast<GlobalShortcutBackendMacOS*>(system_backend_)->ShowAccessibilityDialog();
#endif
}

View File

@ -56,7 +56,7 @@ class AudioScrobbler : public QObject {
template <typename T>
T *Service() {
return static_cast<T*>(this->ServiceByName(T::kName));
return qobject_cast<T*>(this->ServiceByName(T::kName));
}
public slots:

View File

@ -48,7 +48,7 @@ class ScrobblerServices : public QObject {
ScrobblerService *ServiceByName(const QString &name);
template <typename T>
T *Service() {
return static_cast<T*>(this->ServiceByName(T::kName));
return qobject_cast<T*>(this->ServiceByName(T::kName));
}
private:

View File

@ -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<QAbstractItemView*>(ui_->list)->sizeHintForColumn(0));
ui_->list->setMinimumWidth(qobject_cast<QAbstractItemView*>(ui_->list)->sizeHintForColumn(0));
ui_->buttonBox->button(QDialogButtonBox::Cancel)->setShortcut(QKeySequence::Close);

View File

@ -224,7 +224,7 @@ void TidalService::Exit() {
void TidalService::ExitReceived() {
QObject *obj = static_cast<QObject*>(sender());
QObject *obj = qobject_cast<QObject*>(sender());
disconnect(obj, nullptr, this, nullptr);
qLog(Debug) << obj << "successfully exited.";
wait_for_exit_.removeAll(obj);

View File

@ -72,7 +72,7 @@ QList<QUrl> FileViewList::UrlListFromSelection() const {
QList<QUrl> urls;
for (const QModelIndex& index : menu_selection_.indexes()) {
if (index.column() == 0)
urls << QUrl::fromLocalFile(static_cast<QFileSystemModel*>(model())->fileInfo(index).canonicalFilePath());
urls << QUrl::fromLocalFile(qobject_cast<QFileSystemModel*>(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<QFileSystemModel*>(model())->rootPath();
QString path = qobject_cast<QFileSystemModel*>(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<QFileSystemModel*>(model())->filePath(index);
filenames << qobject_cast<QFileSystemModel*>(model())->filePath(index);
}
return filenames;

View File

@ -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<QBoxLayout*>(layout());
QBoxLayout *l = qobject_cast<QBoxLayout*>(layout());
int margin = l->margin() + kDropShadowSize;
l->setMargin(margin);