Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

frontend: Use qobject_cast when casting QObjects #11784

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion frontend/components/SourceTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ bool SourceTree::Edit(int row)

QModelIndex index = stm->createIndex(row, 0);
QWidget *widget = indexWidget(index);
SourceTreeItem *itemWidget = reinterpret_cast<SourceTreeItem *>(widget);
SourceTreeItem *itemWidget = qobject_cast<SourceTreeItem *>(widget);
if (itemWidget->IsEditing()) {
#ifdef __APPLE__
itemWidget->ExitEditMode(true);
Expand Down
4 changes: 2 additions & 2 deletions frontend/components/SourceTree.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ class SourceTree : public QListView {
void UpdateWidget(const QModelIndex &idx, obs_sceneitem_t *item);
void UpdateWidgets(bool force = false);

inline SourceTreeModel *GetStm() const { return reinterpret_cast<SourceTreeModel *>(model()); }
inline SourceTreeModel *GetStm() const { return qobject_cast<SourceTreeModel *>(model()); }

public:
inline SourceTreeItem *GetItemWidget(int idx)
{
QWidget *widget = indexWidget(GetStm()->createIndex(idx, 0));
return reinterpret_cast<SourceTreeItem *>(widget);
return qobject_cast<SourceTreeItem *>(widget);
}

explicit SourceTree(QWidget *parent = nullptr);
Expand Down
2 changes: 1 addition & 1 deletion frontend/dialogs/OBSYoutubeActions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const QString IndexOfGamingCategory = "20";
OBSYoutubeActions::OBSYoutubeActions(QWidget *parent, Auth *auth, bool broadcastReady)
: QDialog(parent),
ui(new Ui::OBSYoutubeActions),
apiYouTube(dynamic_cast<YoutubeApiWrappers *>(auth)),
apiYouTube(qobject_cast<YoutubeApiWrappers *>(auth)),
workerThread(new WorkerThread(apiYouTube)),
broadcastReady(broadcastReady)
{
Expand Down
2 changes: 1 addition & 1 deletion frontend/docks/YouTubeAppDock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ YoutubeApiWrappers *YouTubeAppDock::GetYTApi()
{
Auth *auth = OBSBasic::Get()->GetAuth();
if (auth) {
YoutubeApiWrappers *apiYouTube(dynamic_cast<YoutubeApiWrappers *>(auth));
YoutubeApiWrappers *apiYouTube(qobject_cast<YoutubeApiWrappers *>(auth));
if (apiYouTube) {
return apiYouTube;
} else {
Expand Down
2 changes: 1 addition & 1 deletion frontend/importer/ImporterEntryPathItemDelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ void ImporterEntryPathItemDelegate::handleClear(QWidget *container)

void ImporterEntryPathItemDelegate::updateText()
{
QLineEdit *lineEdit = dynamic_cast<QLineEdit *>(sender());
QLineEdit *lineEdit = qobject_cast<QLineEdit *>(sender());
QWidget *editor = lineEdit->parentWidget();
emit commitData(editor);
}
12 changes: 6 additions & 6 deletions frontend/settings/OBSBasicSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ static inline bool SetInvalidValue(QComboBox *combo, const char *name, const cha
{
combo->insertItem(0, name, data);

QStandardItemModel *model = dynamic_cast<QStandardItemModel *>(combo->model());
QStandardItemModel *model = qobject_cast<QStandardItemModel *>(combo->model());
if (!model)
return false;

Expand Down Expand Up @@ -1199,7 +1199,7 @@ void OBSBasicSettings::LoadBranchesList()

// Disable item if branch is disabled
if (!branch.is_enabled) {
QStandardItemModel *model = dynamic_cast<QStandardItemModel *>(ui->updateChannelBox->model());
QStandardItemModel *model = qobject_cast<QStandardItemModel *>(ui->updateChannelBox->model());
QStandardItem *item = model->item(ui->updateChannelBox->count() - 1);
item->setFlags(Qt::NoItemFlags);
}
Expand Down Expand Up @@ -4480,7 +4480,7 @@ static void DisableIncompatibleCodecs(QComboBox *cbox, const QString &format, co
is_compatible = FFCodecAndFormatCompatible(codec, ext.c_str());
}

QStandardItemModel *model = dynamic_cast<QStandardItemModel *>(cbox->model());
QStandardItemModel *model = qobject_cast<QStandardItemModel *>(cbox->model());
QStandardItem *item = model->item(idx);

if (is_compatible) {
Expand Down Expand Up @@ -4538,7 +4538,7 @@ static void ResetInvalidSelection(QComboBox *cbox)
if (idx < 0)
return;

QStandardItemModel *model = dynamic_cast<QStandardItemModel *>(cbox->model());
QStandardItemModel *model = qobject_cast<QStandardItemModel *>(cbox->model());
QStandardItem *item = model->item(idx);

if (item->isEnabled())
Expand Down Expand Up @@ -5091,7 +5091,7 @@ static void DisableIncompatibleSimpleCodecs(QComboBox *cbox, const QString &form
codec = obs_get_encoder_codec(encoder_id);
}

QStandardItemModel *model = dynamic_cast<QStandardItemModel *>(cbox->model());
QStandardItemModel *model = qobject_cast<QStandardItemModel *>(cbox->model());
QStandardItem *item = model->item(idx);

if (ContainerSupportsCodec(format.toStdString(), codec.toStdString())) {
Expand Down Expand Up @@ -5121,7 +5121,7 @@ static void DisableIncompatibleSimpleContainer(QComboBox *cbox, const QString &c
QString format = cbox->itemData(idx).toString();
string formatStr = format.toStdString();

QStandardItemModel *model = dynamic_cast<QStandardItemModel *>(cbox->model());
QStandardItemModel *model = qobject_cast<QStandardItemModel *>(cbox->model());
QStandardItem *item = model->item(idx);

if (ContainerSupportsCodec(formatStr, vCodec) && ContainerSupportsCodec(formatStr, aCodec)) {
Expand Down
2 changes: 1 addition & 1 deletion frontend/settings/OBSBasicSettings_Stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@ OBSService OBSBasicSettings::SpawnTempService()

void OBSBasicSettings::OnOAuthStreamKeyConnected()
{
OAuthStreamKey *a = reinterpret_cast<OAuthStreamKey *>(auth.get());
OAuthStreamKey *a = qobject_cast<OAuthStreamKey *>(auth.get());

if (a) {
bool validKey = !a->key().empty();
Expand Down
2 changes: 1 addition & 1 deletion frontend/settings/OBSHotkeyWidget.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class OBSHotkeyWidget : public QWidget {
bool ignoreChangedBindings = false;
OBSBasicSettings *settings;

QVBoxLayout *layout() const { return dynamic_cast<QVBoxLayout *>(QWidget::layout()); }
QVBoxLayout *layout() const { return qobject_cast<QVBoxLayout *>(QWidget::layout()); }

private slots:
void HandleChangedBindings(obs_hotkey_id id_);
Expand Down
6 changes: 3 additions & 3 deletions frontend/utility/ExtraBrowsersDelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ QWidget *ExtraBrowsersDelegate::createEditor(QWidget *parent, const QStyleOption

void ExtraBrowsersDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
{
QLineEdit *text = reinterpret_cast<QLineEdit *>(editor);
QLineEdit *text = qobject_cast<QLineEdit *>(editor);
text->blockSignals(true);
text->setText(index.data().toString());
text->blockSignals(false);
Expand Down Expand Up @@ -65,7 +65,7 @@ bool ExtraBrowsersDelegate::ValidName(const QString &name) const

void ExtraBrowsersDelegate::RevertText(QLineEdit *edit_)
{
EditWidget *edit = reinterpret_cast<EditWidget *>(edit_);
EditWidget *edit = qobject_cast<EditWidget *>(edit_);
int row = edit->index.row();
int col = edit->index.column();
bool newItem = (row == model->items.size());
Expand All @@ -82,7 +82,7 @@ void ExtraBrowsersDelegate::RevertText(QLineEdit *edit_)

bool ExtraBrowsersDelegate::UpdateText(QLineEdit *edit_)
{
EditWidget *edit = reinterpret_cast<EditWidget *>(edit_);
EditWidget *edit = qobject_cast<EditWidget *>(edit_);
int row = edit->index.row();
int col = edit->index.column();
bool newItem = (row == model->items.size());
Expand Down
10 changes: 5 additions & 5 deletions frontend/utility/ExtraBrowsersModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ Qt::ItemFlags ExtraBrowsersModel::flags(const QModelIndex &index) const
}
void ExtraBrowsersModel::AddDeleteButton(int idx)
{
QTableView *widget = reinterpret_cast<QTableView *>(parent());
QTableView *widget = qobject_cast<QTableView *>(parent());

QModelIndex index = createIndex(idx, (int)Column::Delete, nullptr);

Expand Down Expand Up @@ -134,7 +134,7 @@ void ExtraBrowsersModel::UpdateItem(Item &item)
int idx = item.prevIdx;

OBSBasic *main = OBSBasic::Get();
BrowserDock *dock = reinterpret_cast<BrowserDock *>(main->extraBrowserDocks[idx].get());
BrowserDock *dock = qobject_cast<BrowserDock *>(main->extraBrowserDocks[idx].get());
dock->setWindowTitle(item.title);
dock->setObjectName(item.title + OBJ_NAME_SUFFIX);

Expand All @@ -152,9 +152,9 @@ void ExtraBrowsersModel::UpdateItem(Item &item)

void ExtraBrowsersModel::DeleteItem()
{
QTableView *widget = reinterpret_cast<QTableView *>(parent());
QTableView *widget = qobject_cast<QTableView *>(parent());

DelButton *del = reinterpret_cast<DelButton *>(sender());
DelButton *del = qobject_cast<DelButton *>(sender());
int row = del->index.row();

/* there's some sort of internal bug in Qt and deleting certain index
Expand Down Expand Up @@ -211,7 +211,7 @@ void ExtraBrowsersModel::Apply()

void ExtraBrowsersModel::TabSelection(bool forward)
{
QListView *widget = reinterpret_cast<QListView *>(parent());
QListView *widget = qobject_cast<QListView *>(parent());
QItemSelectionModel *selModel = widget->selectionModel();

QModelIndex sel = selModel->currentIndex();
Expand Down
2 changes: 1 addition & 1 deletion frontend/utility/RemuxEntryPathItemDelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ void RemuxEntryPathItemDelegate::handleClear(QWidget *container)

void RemuxEntryPathItemDelegate::updateText()
{
QLineEdit *lineEdit = dynamic_cast<QLineEdit *>(sender());
QLineEdit *lineEdit = qobject_cast<QLineEdit *>(sender());
QWidget *editor = lineEdit->parentWidget();
emit commitData(editor);
}
2 changes: 1 addition & 1 deletion frontend/utility/YoutubeApiWrappers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ bool IsUserSignedIntoYT()
{
Auth *auth = OBSBasic::Get()->GetAuth();
if (auth) {
YoutubeApiWrappers *apiYouTube(dynamic_cast<YoutubeApiWrappers *>(auth));
YoutubeApiWrappers *apiYouTube(qobject_cast<YoutubeApiWrappers *>(auth));
if (apiYouTube) {
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/widgets/OBSBasic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1904,7 +1904,7 @@ void OBSBasic::UpdateTitleBar()

OBSBasic *OBSBasic::Get()
{
return reinterpret_cast<OBSBasic *>(App()->GetMainWindow());
return qobject_cast<OBSBasic *>(App()->GetMainWindow());
}

void OBSBasic::UpdatePatronJson(const QString &text, const QString &error)
Expand Down
4 changes: 2 additions & 2 deletions frontend/widgets/OBSBasic_Clipboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ void OBSBasic::SourcePasteFilters(OBSSource source, OBSSource dstSource)

void OBSBasic::AudioMixerCopyFilters()
{
QAction *action = reinterpret_cast<QAction *>(sender());
QAction *action = qobject_cast<QAction *>(sender());
VolControl *vol = action->property("volControl").value<VolControl *>();
obs_source_t *source = vol->GetSource();

Expand All @@ -174,7 +174,7 @@ void OBSBasic::AudioMixerCopyFilters()

void OBSBasic::AudioMixerPasteFilters()
{
QAction *action = reinterpret_cast<QAction *>(sender());
QAction *action = qobject_cast<QAction *>(sender());
VolControl *vol = action->property("volControl").value<VolControl *>();
obs_source_t *dstSource = vol->GetSource();

Expand Down
4 changes: 2 additions & 2 deletions frontend/widgets/OBSBasic_ContextToolbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,10 @@ void OBSBasic::UpdateContextBar(bool force)
bool updateNeeded = true;
QLayoutItem *la = ui->emptySpace->layout()->itemAt(0);
if (la) {
if (SourceToolbar *toolbar = dynamic_cast<SourceToolbar *>(la->widget())) {
if (SourceToolbar *toolbar = qobject_cast<SourceToolbar *>(la->widget())) {
if (toolbar->GetSource() == source)
updateNeeded = false;
} else if (MediaControls *toolbar = dynamic_cast<MediaControls *>(la->widget())) {
} else if (MediaControls *toolbar = qobject_cast<MediaControls *>(la->widget())) {
if (toolbar->GetSource() == source)
updateNeeded = false;
}
Expand Down
4 changes: 2 additions & 2 deletions frontend/widgets/OBSBasic_Docks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ QAction *OBSBasic::AddDockWidget(QDockWidget *dock)

void OBSBasic::RepairOldExtraDockName()
{
QDockWidget *dock = reinterpret_cast<QDockWidget *>(sender());
QDockWidget *dock = qobject_cast<QDockWidget *>(sender());
int idx = oldExtraDocks.indexOf(dock);
QSignalBlocker block(dock);

Expand Down Expand Up @@ -336,7 +336,7 @@ void OBSBasic::AddCustomDockWidget(QDockWidget *dock)

void OBSBasic::RepairCustomExtraDockName()
{
QDockWidget *dock = reinterpret_cast<QDockWidget *>(sender());
QDockWidget *dock = qobject_cast<QDockWidget *>(sender());
int idx = extraCustomDocks.indexOf(dock);
QSignalBlocker block(dock);

Expand Down
2 changes: 1 addition & 1 deletion frontend/widgets/OBSBasic_Profiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ void OBSBasic::DeleteProfile(const QString &name)

void OBSBasic::ChangeProfile()
{
QAction *action = reinterpret_cast<QAction *>(sender());
QAction *action = qobject_cast<QAction *>(sender());

if (!action) {
return;
Expand Down
2 changes: 1 addition & 1 deletion frontend/widgets/OBSBasic_SceneCollections.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ void OBSBasic::DeleteSceneCollection(const QString &name)

void OBSBasic::ChangeSceneCollection()
{
QAction *action = reinterpret_cast<QAction *>(sender());
QAction *action = qobject_cast<QAction *>(sender());

if (!action) {
return;
Expand Down
16 changes: 8 additions & 8 deletions frontend/widgets/OBSBasic_SceneItems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ void OBSBasic::RenameSources(OBSSource source, QString newName, QString prevName

void OBSBasic::GetAudioSourceFilters()
{
QAction *action = reinterpret_cast<QAction *>(sender());
QAction *action = qobject_cast<QAction *>(sender());
VolControl *vol = action->property("volControl").value<VolControl *>();
obs_source_t *source = vol->GetSource();

Expand All @@ -120,7 +120,7 @@ void OBSBasic::GetAudioSourceFilters()

void OBSBasic::GetAudioSourceProperties()
{
QAction *action = reinterpret_cast<QAction *>(sender());
QAction *action = qobject_cast<QAction *>(sender());
VolControl *vol = action->property("volControl").value<VolControl *>();
obs_source_t *source = vol->GetSource();

Expand All @@ -129,7 +129,7 @@ void OBSBasic::GetAudioSourceProperties()

void OBSBasic::MixerRenameSource()
{
QAction *action = reinterpret_cast<QAction *>(sender());
QAction *action = qobject_cast<QAction *>(sender());
VolControl *vol = action->property("volControl").value<VolControl *>();
OBSSource source = vol->GetSource();

Expand Down Expand Up @@ -364,7 +364,7 @@ void OBSBasic::ResetAudioDevice(const char *sourceId, const char *deviceId, cons

void OBSBasic::SetDeinterlacingMode()
{
QAction *action = reinterpret_cast<QAction *>(sender());
QAction *action = qobject_cast<QAction *>(sender());
obs_deinterlace_mode mode = (obs_deinterlace_mode)action->property("mode").toInt();
OBSSceneItem sceneItem = GetCurrentSceneItem();
obs_source_t *source = obs_sceneitem_get_source(sceneItem);
Expand All @@ -374,7 +374,7 @@ void OBSBasic::SetDeinterlacingMode()

void OBSBasic::SetDeinterlacingOrder()
{
QAction *action = reinterpret_cast<QAction *>(sender());
QAction *action = qobject_cast<QAction *>(sender());
obs_deinterlace_field_order order = (obs_deinterlace_field_order)action->property("order").toInt();
OBSSceneItem sceneItem = GetCurrentSceneItem();
obs_source_t *source = obs_sceneitem_get_source(sceneItem);
Expand Down Expand Up @@ -422,7 +422,7 @@ QMenu *OBSBasic::AddDeinterlacingMenu(QMenu *menu, obs_source_t *source)

void OBSBasic::SetScaleFilter()
{
QAction *action = reinterpret_cast<QAction *>(sender());
QAction *action = qobject_cast<QAction *>(sender());
obs_scale_type mode = (obs_scale_type)action->property("mode").toInt();
OBSSceneItem sceneItem = GetCurrentSceneItem();

Expand Down Expand Up @@ -453,7 +453,7 @@ QMenu *OBSBasic::AddScaleFilteringMenu(QMenu *menu, obs_sceneitem_t *item)

void OBSBasic::SetBlendingMethod()
{
QAction *action = reinterpret_cast<QAction *>(sender());
QAction *action = qobject_cast<QAction *>(sender());
obs_blending_method method = (obs_blending_method)action->property("method").toInt();
OBSSceneItem sceneItem = GetCurrentSceneItem();

Expand All @@ -480,7 +480,7 @@ QMenu *OBSBasic::AddBlendingMethodMenu(QMenu *menu, obs_sceneitem_t *item)

void OBSBasic::SetBlendingMode()
{
QAction *action = reinterpret_cast<QAction *>(sender());
QAction *action = qobject_cast<QAction *>(sender());
obs_blending_type mode = (obs_blending_type)action->property("mode").toInt();
OBSSceneItem sceneItem = GetCurrentSceneItem();

Expand Down
8 changes: 4 additions & 4 deletions frontend/widgets/OBSBasic_Transitions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1100,7 +1100,7 @@ void OBSBasic::AddQuickTransitionId(int id)
button->setMenu(buttonMenu);
connect(button, &QAbstractButton::clicked, this, &OBSBasic::QuickTransitionClicked);

QVBoxLayout *programLayout = reinterpret_cast<QVBoxLayout *>(programOptions->layout());
QVBoxLayout *programLayout = qobject_cast<QVBoxLayout *>(programOptions->layout());

int idx = 3;
for (;; idx++) {
Expand Down Expand Up @@ -1144,7 +1144,7 @@ void OBSBasic::ClearQuickTransitions()
if (!programOptions)
return;

QVBoxLayout *programLayout = reinterpret_cast<QVBoxLayout *>(programOptions->layout());
QVBoxLayout *programLayout = qobject_cast<QVBoxLayout *>(programOptions->layout());

for (int idx = 0;; idx++) {
QLayoutItem *item = programLayout->itemAt(idx);
Expand Down Expand Up @@ -1218,7 +1218,7 @@ void OBSBasic::ClearQuickTransitionWidgets()
if (!IsPreviewProgramMode())
return;

QVBoxLayout *programLayout = reinterpret_cast<QVBoxLayout *>(programOptions->layout());
QVBoxLayout *programLayout = qobject_cast<QVBoxLayout *>(programOptions->layout());

for (int idx = 0;; idx++) {
QLayoutItem *item = programLayout->itemAt(idx);
Expand Down Expand Up @@ -1260,7 +1260,7 @@ void OBSBasic::EnableTransitionWidgets(bool enable)
if (!IsPreviewProgramMode())
return;

QVBoxLayout *programLayout = reinterpret_cast<QVBoxLayout *>(programOptions->layout());
QVBoxLayout *programLayout = qobject_cast<QVBoxLayout *>(programOptions->layout());

for (int idx = 0;; idx++) {
QLayoutItem *item = programLayout->itemAt(idx);
Expand Down
Loading
Loading