diff --git a/src/Gui/DlgDisplayPropertiesImp.cpp b/src/Gui/DlgDisplayPropertiesImp.cpp index 7a5495080a..e05269ce45 100644 --- a/src/Gui/DlgDisplayPropertiesImp.cpp +++ b/src/Gui/DlgDisplayPropertiesImp.cpp @@ -64,13 +64,10 @@ public: { bool hasElementColor = false; for (const auto & view : views) { - App::Property* prop = view->getPropertyByName(property); - if (prop && prop->getTypeId() == App::PropertyColor::getClassTypeId()) { - App::Color c = static_cast(prop)->getValue(); - QColor shape; - shape.setRgb((int)(c.r * 255.0f), (int)(c.g * 255.0f), (int)(c.b * 255.0f)); + if (auto* prop = dynamic_cast(view->getPropertyByName(property))) { + App::Color color = prop->getValue(); QSignalBlocker block(buttonColor); - buttonColor->setColor(shape); + buttonColor->setColor(color.asValue()); hasElementColor = true; break; } @@ -83,10 +80,9 @@ public: { bool hasDrawStyle = false; for (const auto & view : views) { - App::Property* prop = view->getPropertyByName(property); - if (prop && prop->getTypeId().isDerivedFrom(App::PropertyFloat::getClassTypeId())) { + if (auto* prop = dynamic_cast(view->getPropertyByName(property))) { QSignalBlocker block(spinbox); - spinbox->setValue((int)static_cast(prop)->getValue()); + spinbox->setValue(int(prop->getValue())); hasDrawStyle = true; break; } @@ -99,13 +95,12 @@ public: { bool hasTransparency = false; for (const auto & view : views) { - App::Property* prop = view->getPropertyByName(property); - if (prop && prop->getTypeId().isDerivedFrom(App::PropertyInteger::getClassTypeId())) { + if (auto* prop = dynamic_cast(view->getPropertyByName(property))) { QSignalBlocker blockSpinBox(spinbox); - spinbox->setValue(static_cast(prop)->getValue()); + spinbox->setValue(prop->getValue()); QSignalBlocker blockSlider(slider); - slider->setValue(static_cast(prop)->getValue()); + slider->setValue(prop->getValue()); hasTransparency = true; break; } @@ -358,11 +353,9 @@ void DlgDisplayPropertiesImp::onChangeMaterialActivated(int index) (int)(diffuseColor.g*255.0f), (int)(diffuseColor.b*255.0f))); - for (auto It= Provider.begin(); It != Provider.end(); ++It) { - App::Property* prop = (*It)->getPropertyByName("ShapeMaterial"); - if (prop && prop->getTypeId() == App::PropertyMaterial::getClassTypeId()) { - auto ShapeMaterial = static_cast(prop); - ShapeMaterial->setValue(mat); + for (auto it : Provider) { + if (auto* prop = dynamic_cast(it->getPropertyByName("ShapeMaterial"))) { + prop->setValue(mat); } } } @@ -374,11 +367,9 @@ void DlgDisplayPropertiesImp::onChangeModeActivated(const QString& s) { Gui::WaitCursor wc; std::vector Provider = getSelection(); - for (auto It= Provider.begin();It!=Provider.end();++It) { - App::Property* prop = (*It)->getPropertyByName("DisplayMode"); - if (prop && prop->getTypeId() == App::PropertyEnumeration::getClassTypeId()) { - auto Display = static_cast(prop); - Display->setValue(static_cast(s.toLatin1())); + for (auto it : Provider) { + if (auto* prop = dynamic_cast(it->getPropertyByName("DisplayMode"))) { + prop->setValue(static_cast(s.toLatin1())); } } } @@ -396,11 +387,9 @@ void DlgDisplayPropertiesImp::onButtonColorChanged() std::vector Provider = getSelection(); QColor s = d->ui.buttonColor->color(); App::Color c(s.red() / 255.0, s.green() / 255.0, s.blue() / 255.0); - for (auto It= Provider.begin();It!=Provider.end();++It) { - App::Property* prop = (*It)->getPropertyByName("ShapeColor"); - if (prop && prop->getTypeId() == App::PropertyColor::getClassTypeId()) { - auto ShapeColor = static_cast(prop); - ShapeColor->setValue(c); + for (auto it : Provider) { + if (auto* prop = dynamic_cast(it->getPropertyByName("ShapeColor"))) { + prop->setValue(c); } } } @@ -411,11 +400,9 @@ void DlgDisplayPropertiesImp::onButtonColorChanged() void DlgDisplayPropertiesImp::onSpinTransparencyValueChanged(int transparency) { std::vector Provider = getSelection(); - for (auto It= Provider.begin();It!=Provider.end();++It) { - App::Property* prop = (*It)->getPropertyByName("Transparency"); - if (prop && prop->getTypeId().isDerivedFrom(App::PropertyInteger::getClassTypeId())) { - auto Transparency = static_cast(prop); - Transparency->setValue(transparency); + for (auto it : Provider) { + if (auto* prop = dynamic_cast(it->getPropertyByName("Transparency"))) { + prop->setValue(transparency); } } } @@ -426,11 +413,9 @@ void DlgDisplayPropertiesImp::onSpinTransparencyValueChanged(int transparency) void DlgDisplayPropertiesImp::onSpinPointSizeValueChanged(int pointsize) { std::vector Provider = getSelection(); - for (const auto & It : Provider) { - App::Property* prop = It->getPropertyByName("PointSize"); - if (prop && prop->getTypeId().isDerivedFrom(App::PropertyFloat::getClassTypeId())) { - auto PointSize = static_cast(prop); - PointSize->setValue(static_cast(pointsize)); + for (auto it : Provider) { + if (auto* prop = dynamic_cast(it->getPropertyByName("PointSize"))) { + prop->setValue(static_cast(pointsize)); } } } @@ -441,11 +426,9 @@ void DlgDisplayPropertiesImp::onSpinPointSizeValueChanged(int pointsize) void DlgDisplayPropertiesImp::onSpinLineWidthValueChanged(int linewidth) { std::vector Provider = getSelection(); - for (const auto & It : Provider) { - App::Property* prop = It->getPropertyByName("LineWidth"); - if (prop && prop->getTypeId().isDerivedFrom(App::PropertyFloat::getClassTypeId())) { - auto LineWidth = static_cast(prop); - LineWidth->setValue(static_cast(linewidth)); + for (auto it : Provider) { + if (auto* prop = dynamic_cast(it->getPropertyByName("LineWidth"))) { + prop->setValue(static_cast(linewidth)); } } } @@ -455,11 +438,9 @@ void DlgDisplayPropertiesImp::onButtonLineColorChanged() std::vector Provider = getSelection(); QColor s = d->ui.buttonLineColor->color(); App::Color c(s.red() / 255.0, s.green() / 255.0, s.blue() / 255.0); - for (const auto & It : Provider) { - App::Property* prop = It->getPropertyByName("LineColor"); - if (prop && prop->getTypeId() == App::PropertyColor::getClassTypeId()) { - auto LineColor = static_cast(prop); - LineColor->setValue(c); + for (auto it : Provider) { + if (auto* prop = dynamic_cast(it->getPropertyByName("LineColor"))) { + prop->setValue(c); } } } @@ -469,11 +450,9 @@ void DlgDisplayPropertiesImp::onButtonPointColorChanged() std::vector Provider = getSelection(); QColor s = d->ui.buttonPointColor->color(); App::Color c(s.red() / 255.0, s.green() / 255.0, s.blue() / 255.0); - for (const auto & It : Provider) { - App::Property* prop = It->getPropertyByName("PointColor"); - if (prop && prop->getTypeId() == App::PropertyColor::getClassTypeId()) { - auto PointColor = static_cast(prop); - PointColor->setValue(c); + for (auto it : Provider) { + if (auto* prop = dynamic_cast(it->getPropertyByName("PointColor"))) { + prop->setValue(c); } } } @@ -481,11 +460,9 @@ void DlgDisplayPropertiesImp::onButtonPointColorChanged() void DlgDisplayPropertiesImp::onSpinLineTransparencyValueChanged(int transparency) { std::vector Provider = getSelection(); - for (const auto & It : Provider) { - App::Property* prop = It->getPropertyByName("LineTransparency"); - if (prop && prop->getTypeId().isDerivedFrom(App::PropertyInteger::getClassTypeId())) { - auto Transparency = static_cast(prop); - Transparency->setValue(transparency); + for (auto it : Provider) { + if (auto* prop = dynamic_cast(it->getPropertyByName("LineTransparency"))) { + prop->setValue(transparency); } } } @@ -494,12 +471,10 @@ void DlgDisplayPropertiesImp::setDisplayModes(const std::vectorgetPropertyByName("DisplayMode"); - if (prop && prop->getTypeId() == App::PropertyEnumeration::getClassTypeId()) { - auto display = static_cast(prop); - if (!display->hasEnums()) + if (auto* prop = dynamic_cast((*it)->getPropertyByName("DisplayMode"))) { + if (!prop->hasEnums()) return; - std::vector value = display->getEnumVector(); + std::vector value = prop->getEnumVector(); if (it == views.begin()) { for (const auto & jt : value) commonModes << QLatin1String(jt.c_str()); @@ -522,10 +497,8 @@ void DlgDisplayPropertiesImp::setDisplayModes(const std::vectorgetPropertyByName("DisplayMode"); - if (prop && prop->getTypeId() == App::PropertyEnumeration::getClassTypeId()) { - auto display = static_cast(prop); - QString activeMode = QString::fromLatin1(display->getValueAsString()); + if (auto* prop = dynamic_cast(view->getPropertyByName("DisplayMode"))) { + QString activeMode = QString::fromLatin1(prop->getValueAsString()); int index = d->ui.changeMode->findText(activeMode); if (index != -1) { d->ui.changeMode->setCurrentIndex(index); @@ -539,11 +512,10 @@ void DlgDisplayPropertiesImp::setMaterial(const std::vector& { bool material = false; App::Material::MaterialType matType = App::Material::DEFAULT; - for (const auto & view : views) { - App::Property* prop = view->getPropertyByName("ShapeMaterial"); - if (prop && prop->getTypeId() == App::PropertyMaterial::getClassTypeId()) { + for (auto view : views) { + if (auto* prop = dynamic_cast(view->getPropertyByName("ShapeMaterial"))) { material = true; - matType = static_cast(prop)->getValue().getType(); + matType = prop->getValue().getType(); break; } } @@ -559,9 +531,9 @@ void DlgDisplayPropertiesImp::setMaterial(const std::vector& void DlgDisplayPropertiesImp::setColorPlot(const std::vector& views) { bool material = false; - for (const auto & view : views) { - App::Property* prop = view->getPropertyByName("TextureMaterial"); - if (prop && prop->getTypeId() == App::PropertyMaterial::getClassTypeId()) { + for (auto view : views) { + auto* prop = dynamic_cast(view->getPropertyByName("TextureMaterial")); + if (prop) { material = true; break; }