Misc: Replace dynamic_cast with qobject_cast

This commit is contained in:
Kacper Donat
2025-04-07 20:00:08 +02:00
committed by Benjamin Nauck
parent f2cd99c50a
commit b14d3a224b
10 changed files with 20 additions and 20 deletions

View File

@@ -1130,7 +1130,7 @@ void Model::renameAcceptedSlot()
assert(selections.size() == 1);
const GraphLinkRecord &record = findRecord(selections.front(), *graphLink);
auto lineEdit = dynamic_cast<LineEdit*>(proxy->widget());
auto lineEdit = qobject_cast<LineEdit*>(proxy->widget());
assert(lineEdit);
const_cast<App::DocumentObject*>(record.DObject)->Label.setValue(lineEdit->text().toUtf8().constData()); //const hack

View File

@@ -43,7 +43,7 @@ ExpressionBindingPy::ExpressionBindingPy(Py::PythonClassInstance* self, Py::Tupl
PythonWrapper wrap;
wrap.loadWidgetsModule();
QWidget* obj = dynamic_cast<QWidget*>(wrap.toQObject(Py::Object(pyObj)));
QWidget* obj = qobject_cast<QWidget*>(wrap.toQObject(Py::Object(pyObj)));
expr = asBinding(obj);
if (!expr) {

View File

@@ -136,7 +136,7 @@ void Flag::mouseMoveEvent(QMouseEvent *e)
move(e->globalPosition().toPoint() - dragPosition);
#endif
e->accept();
auto viewer = dynamic_cast<View3DInventorViewer*>(parentWidget());
auto viewer = qobject_cast<View3DInventorViewer*>(parentWidget());
if (viewer)
viewer->getSoRenderManager()->scheduleRedraw();
}

View File

@@ -1042,7 +1042,7 @@ bool MainWindow::eventFilter(QObject* o, QEvent* e)
if (e->type() == QEvent::WindowStateChange) {
// notify all mdi views when the active view receives a show normal, show minimized
// or show maximized event
auto view = qobject_cast<MDIView*>(o);
auto view = dynamic_cast<MDIView*>(o);
if (view) { // emit this signal
Qt::WindowStates oldstate = static_cast<QWindowStateChangeEvent*>(e)->oldState();
Qt::WindowStates newstate = view->windowState();
@@ -1691,7 +1691,7 @@ void MainWindow::switchToDockedMode()
// Search for all top-level MDI views
QWidgetList toplevel = QApplication::topLevelWidgets();
for (const auto & it : toplevel) {
auto view = qobject_cast<MDIView*>(it);
auto view = dynamic_cast<MDIView*>(it);
if (view)
view->setCurrentViewMode(MDIView::Child);
}

View File

@@ -127,7 +127,7 @@ Py::Object MainWindowPy::getWindows(const Py::Tuple& args)
if (_mw) {
QList<QWidget*> windows = _mw->windows();
for (auto it : windows) {
auto view = qobject_cast<MDIView*>(it);
auto view = dynamic_cast<MDIView*>(it);
if (view) {
mdis.append(Py::asObject(view->getPyObject()));
}
@@ -149,7 +149,7 @@ Py::Object MainWindowPy::getWindowsOfType(const Py::Tuple& args)
if (_mw) {
QList<QWidget*> windows = _mw->windows();
for (auto it : windows) {
auto view = qobject_cast<MDIView*>(it);
auto view = dynamic_cast<MDIView*>(it);
if (view && view->isDerivedFrom(typeId)) {
mdis.append(Py::asObject(view->getPyObject()));
}

View File

@@ -270,7 +270,7 @@ void DlgSettingsWorkbenchesImp::saveSettings()
};
for (int i = 0; i < ui->wbList->count(); i++) {
wbListItem* wbItem = dynamic_cast<wbListItem*>(ui->wbList->itemWidget(ui->wbList->item(i)));
wbListItem* wbItem = qobject_cast<wbListItem*>(ui->wbList->itemWidget(ui->wbList->item(i)));
if (!wbItem)
continue;
std::string wbName = wbItem->objectName().toStdString();
@@ -546,7 +546,7 @@ void DlgSettingsWorkbenchesImp::wbToggled(const QString& wbName, bool enabled)
//reorder the list of items.
int wbIndex = 0;
for (int i = 0; i < ui->wbList->count(); i++) {
wbListItem* wbItem = dynamic_cast<wbListItem*>(ui->wbList->itemWidget(ui->wbList->item(i)));
wbListItem* wbItem = qobject_cast<wbListItem*>(ui->wbList->itemWidget(ui->wbList->item(i)));
if (wbItem && wbItem->objectName() == wbName) {
wbIndex = i;
}
@@ -555,7 +555,7 @@ void DlgSettingsWorkbenchesImp::wbToggled(const QString& wbName, bool enabled)
int destinationIndex = ui->wbList->count();
for (int i = 0; i < ui->wbList->count(); i++) {
wbListItem* wbItem = dynamic_cast<wbListItem*>(ui->wbList->itemWidget(ui->wbList->item(i)));
wbListItem* wbItem = qobject_cast<wbListItem*>(ui->wbList->itemWidget(ui->wbList->item(i)));
if (wbItem && !wbItem->isEnabled() && (enabled || ((wbItem->objectName()).toStdString() > wbName.toStdString()))) {
//If the wb was enabled, then it was in the disabled wbs. So it moves to the row of the currently first disabled wb
//If the wb was disabled. Then it goes to the disabled wb where it belongs alphabetically.
@@ -574,7 +574,7 @@ void DlgSettingsWorkbenchesImp::setStartWorkbenchComboItems()
// fills the combo box with activated workbenches.
QStringList enabledWbs;
for (int i = 0; i < ui->wbList->count(); i++) {
wbListItem* wbItem = dynamic_cast<wbListItem*>(ui->wbList->itemWidget(ui->wbList->item(i)));
wbListItem* wbItem = qobject_cast<wbListItem*>(ui->wbList->itemWidget(ui->wbList->item(i)));
if (wbItem && wbItem->isEnabled()) {
enabledWbs << wbItem->objectName();
}
@@ -614,7 +614,7 @@ void DlgSettingsWorkbenchesImp::setStartWorkbenchComboItems()
void DlgSettingsWorkbenchesImp::wbItemMoved()
{
for (int i = 0; i < ui->wbList->count(); i++) {
wbListItem* wbItem = dynamic_cast<wbListItem*>(ui->wbList->itemWidget(ui->wbList->item(i)));
wbListItem* wbItem = qobject_cast<wbListItem*>(ui->wbList->itemWidget(ui->wbList->item(i)));
if (wbItem) {
wbItem->setShortcutLabel(i);
}
@@ -630,7 +630,7 @@ void DlgSettingsWorkbenchesImp::onStartWbChanged(int index)
//Change wb that user can't deactivate.
for (int i = 0; i < ui->wbList->count(); i++) {
wbListItem* wbItem = dynamic_cast<wbListItem*>(ui->wbList->itemWidget(ui->wbList->item(i)));
wbListItem* wbItem = qobject_cast<wbListItem*>(ui->wbList->itemWidget(ui->wbList->item(i)));
if (wbItem) {
wbItem->setStartupWb(wbItem->objectName() == wbName);
}

View File

@@ -182,7 +182,7 @@ View3DInventorViewer* TaskImage::getViewer() const
if (!feature.expired()) {
auto vp = Application::Instance->getViewProvider(feature.get());
auto doc = static_cast<ViewProviderDocumentObject*>(vp)->getDocument(); // NOLINT
auto view = dynamic_cast<View3DInventor*>(doc->getViewOfViewProvider(vp));
auto view = qobject_cast<View3DInventor*>(doc->getViewOfViewProvider(vp));
if (view) {
return view->getViewer();
}
@@ -633,7 +633,7 @@ bool InteractiveScale::eventFilter(QObject* object, QEvent* event)
/* If user press enter in the spinbox, then we validate the tool.*/
if ((keyEvent->key() == Qt::Key_Enter || keyEvent->key() == Qt::Key_Return)
&& dynamic_cast<QuantitySpinBox*>(object)) {
&& qobject_cast<QuantitySpinBox*>(object)) {
Q_EMIT scaleRequired();
}

View File

@@ -1011,13 +1011,13 @@ Base::BoundBox3d ViewProvider::getBoundingBox(const char *subname, bool transfor
if(!view)
view = Application::Instance->activeView();
auto iview = dynamic_cast<View3DInventor*>(view);
auto iview = qobject_cast<View3DInventor*>(view);
if(!iview) {
auto doc = Application::Instance->activeDocument();
if(doc) {
auto views = doc->getMDIViewsOfType(View3DInventor::getClassTypeId());
if(!views.empty())
iview = dynamic_cast<View3DInventor*>(views.front());
iview = qobject_cast<View3DInventor*>(views.front());
}
if(!iview) {
FC_ERR("no view");

View File

@@ -86,7 +86,7 @@ QWidget* WidgetFactoryInst::createWidget (const char* sName, QWidget* parent) co
try {
#ifdef FC_DEBUG
const char* cName = dynamic_cast<QWidget*>(w)->metaObject()->className();
const char* cName = qobject_cast<QWidget*>(w)->metaObject()->className();
Base::Console().Log("Widget of type '%s' created.\n", cName);
#endif
}

View File

@@ -4746,13 +4746,13 @@ QWidget* PropertyLinkItem::createEditor(QWidget* parent,
void PropertyLinkItem::setEditorData(QWidget* editor, const QVariant& data) const
{
(void)data;
auto ll = dynamic_cast<LinkLabel*>(editor);
auto ll = qobject_cast<LinkLabel*>(editor);
return ll->updatePropertyLink();
}
QVariant PropertyLinkItem::editorData(QWidget* editor) const
{
auto ll = dynamic_cast<LinkLabel*>(editor);
auto ll = qobject_cast<LinkLabel*>(editor);
return ll->propertyLink();
}