From 6a9252744d899d6e85d64fa8cbcd973baa614ad0 Mon Sep 17 00:00:00 2001 From: wmayer Date: Sat, 27 Dec 2014 00:56:46 +0100 Subject: [PATCH] + fixes #0000976: Usability: default Material drop-down is not the active material type --- src/Gui/DlgDisplayPropertiesImp.cpp | 60 +++++++++++++++-------------- src/Gui/DlgDisplayPropertiesImp.h | 3 +- 2 files changed, 32 insertions(+), 31 deletions(-) diff --git a/src/Gui/DlgDisplayPropertiesImp.cpp b/src/Gui/DlgDisplayPropertiesImp.cpp index e776d4560..f90f3b33c 100644 --- a/src/Gui/DlgDisplayPropertiesImp.cpp +++ b/src/Gui/DlgDisplayPropertiesImp.cpp @@ -246,10 +246,11 @@ void DlgDisplayPropertiesImp::on_buttonColorPlot_clicked() /** * Sets the 'ShapeMaterial' property of all selected view providers. */ -void DlgDisplayPropertiesImp::on_changeMaterial_activated(const QString& material) +void DlgDisplayPropertiesImp::on_changeMaterial_activated(int index) { std::vector Provider = getSelection(); - App::Material mat(Materials[material]); + App::Material::MaterialType matType = static_cast(changeMaterial->itemData(index).toInt()); + App::Material mat(matType); App::Color diffuseColor = mat.diffuseColor; buttonColor->setColor(QColor((int)(diffuseColor.r*255.0f), (int)(diffuseColor.g*255.0f), (int)(diffuseColor.b*255.0f))); @@ -418,14 +419,20 @@ void DlgDisplayPropertiesImp::setDisplayModes(const std::vector& views) { bool material = false; + App::Material::MaterialType matType = App::Material::DEFAULT; for (std::vector::const_iterator it = views.begin(); it != views.end(); ++it) { App::Property* prop = (*it)->getPropertyByName("ShapeMaterial"); if (prop && prop->getTypeId() == App::PropertyMaterial::getClassTypeId()) { material = true; + matType = static_cast(prop)->getValue().getType(); break; } } + int index = changeMaterial->findData(matType); + if (index >= 0) { + changeMaterial->setCurrentIndex(index); + } changeMaterial->setEnabled(material); buttonUserDefinedMaterial->setEnabled(material); } @@ -446,33 +453,28 @@ void DlgDisplayPropertiesImp::setColorPlot(const std::vector void DlgDisplayPropertiesImp::fillupMaterials() { - Materials[QLatin1String("Brass")] = App::Material::BRASS; - Materials[QLatin1String("Bronze")] = App::Material::BRONZE; - Materials[QLatin1String("Copper")] = App::Material::COPPER; - Materials[QLatin1String("Gold")] = App::Material::GOLD; - Materials[QLatin1String("Pewter")] = App::Material::PEWTER; - Materials[QLatin1String("Plaster")] = App::Material::PLASTER; - Materials[QLatin1String("Plastic")] = App::Material::PLASTIC; - Materials[QLatin1String("Silver")] = App::Material::SILVER; - Materials[QLatin1String("Steel")] = App::Material::STEEL; - Materials[QLatin1String("Stone")] = App::Material::STONE; - Materials[QLatin1String("Shiny plastic")] = App::Material::SHINY_PLASTIC; - Materials[QLatin1String("Satin")] = App::Material::SATIN; - Materials[QLatin1String("Metalized")] = App::Material::METALIZED; - Materials[QLatin1String("Neon GNC")] = App::Material::NEON_GNC; - Materials[QLatin1String("Chrome")] = App::Material::CHROME; - Materials[QLatin1String("Aluminium")] = App::Material::ALUMINIUM; - Materials[QLatin1String("Obsidian")] = App::Material::OBSIDIAN; - Materials[QLatin1String("Neon PHC")] = App::Material::NEON_PHC; - Materials[QLatin1String("Jade")] = App::Material::JADE; - Materials[QLatin1String("Ruby")] = App::Material::RUBY; - Materials[QLatin1String("Emerald")] = App::Material::EMERALD; - - QStringList material = Materials.keys(); - material.sort(); - changeMaterial->addItem(QLatin1String("Default")); - changeMaterial->addItems(material); - Materials[QLatin1String("Default")] = App::Material::DEFAULT; + changeMaterial->addItem(tr("Default"), App::Material::DEFAULT); + changeMaterial->addItem(tr("Aluminium"), App::Material::ALUMINIUM); + changeMaterial->addItem(tr("Brass"), App::Material::BRASS); + changeMaterial->addItem(tr("Bronze"), App::Material::BRONZE); + changeMaterial->addItem(tr("Copper"), App::Material::COPPER); + changeMaterial->addItem(tr("Chrome"), App::Material::CHROME); + changeMaterial->addItem(tr("Emerald"), App::Material::EMERALD); + changeMaterial->addItem(tr("Gold"), App::Material::GOLD); + changeMaterial->addItem(tr("Jade"), App::Material::JADE); + changeMaterial->addItem(tr("Metalized"), App::Material::METALIZED); + changeMaterial->addItem(tr("Neon GNC"), App::Material::NEON_GNC); + changeMaterial->addItem(tr("Neon PHC"), App::Material::NEON_PHC); + changeMaterial->addItem(tr("Obsidian"), App::Material::OBSIDIAN); + changeMaterial->addItem(tr("Pewter"), App::Material::PEWTER); + changeMaterial->addItem(tr("Plaster"), App::Material::PLASTER); + changeMaterial->addItem(tr("Plastic"), App::Material::PLASTIC); + changeMaterial->addItem(tr("Ruby"), App::Material::RUBY); + changeMaterial->addItem(tr("Satin"), App::Material::SATIN); + changeMaterial->addItem(tr("Shiny plastic"), App::Material::SHINY_PLASTIC); + changeMaterial->addItem(tr("Silver"), App::Material::SILVER); + changeMaterial->addItem(tr("Steel"), App::Material::STEEL); + changeMaterial->addItem(tr("Stone"), App::Material::STONE); } void DlgDisplayPropertiesImp::setShapeColor(const std::vector& views) diff --git a/src/Gui/DlgDisplayPropertiesImp.h b/src/Gui/DlgDisplayPropertiesImp.h index 1f9e07517..2e89b465e 100644 --- a/src/Gui/DlgDisplayPropertiesImp.h +++ b/src/Gui/DlgDisplayPropertiesImp.h @@ -62,7 +62,7 @@ public: Gui::SelectionSingleton::MessageType Reason); private Q_SLOTS: - void on_changeMaterial_activated(const QString&); + void on_changeMaterial_activated(int); void on_changeMode_activated(const QString&); void on_changePlot_activated(const QString&); void on_buttonColor_changed(); @@ -91,7 +91,6 @@ private: void setTransparency(const std::vector&); void setLineTransparency(const std::vector&); std::vector getSelection() const; - QMap Materials; DlgDisplayPropertiesImp_Connection connectChangedObject; };