diff --git a/GUI/coregui/Models/MaterialItem.cpp b/GUI/coregui/Models/MaterialItem.cpp index e325044c91f33f1061ada8b6e907bee75d9a1e54..5db870c3ff9dfcb77be04db44ca0a697bfd6c88e 100644 --- a/GUI/coregui/Models/MaterialItem.cpp +++ b/GUI/coregui/Models/MaterialItem.cpp @@ -15,11 +15,12 @@ // ************************************************************************** // #include "MaterialItem.h" -#include "ColorProperty.h" +#include "ExternalProperty.h" #include "GUIHelpers.h" #include "MaterialDataItem.h" #include "MaterialFactoryFuncs.h" #include "SessionItemUtils.h" +#include "MaterialItemUtils.h" using SessionItemUtils::GetVectorItem; @@ -38,8 +39,9 @@ MaterialItem::MaterialItem() { setItemName(Constants::HomogeneousMaterialType); - ColorProperty color; - addProperty(P_COLOR, color.getVariant()); + ExternalProperty color = MaterialItemUtils::colorProperty(QColor(Qt::red)); + addProperty(P_COLOR, color.variant())->setEditorType(Constants::ColorEditorExternalType); + addGroupProperty(P_MATERIAL_DATA, Constants::MaterialDataType); addGroupProperty(P_MAGNETIZATION, Constants::VectorType)->setToolTip(magnetization_tooltip); addProperty(P_IDENTIFIER, GUIHelpers::createUuid()); @@ -53,8 +55,8 @@ QString MaterialItem::getIdentifier() const QColor MaterialItem::getColor() const { - ColorProperty property = getItemValue(P_COLOR).value<ColorProperty>(); - return property.getColor(); + ExternalProperty property = getItemValue(P_COLOR).value<ExternalProperty>(); + return property.color(); } //TODO: make this function create proper type of material (refractive index m-l or wl-indp. mat-l) diff --git a/GUI/coregui/Models/MaterialModel.cpp b/GUI/coregui/Models/MaterialModel.cpp index 430529c76e56a9c916285259ecc0022f44c06e79..daa30a2590bb2cd8b6ca9b4a579f114067d3dac6 100644 --- a/GUI/coregui/Models/MaterialModel.cpp +++ b/GUI/coregui/Models/MaterialModel.cpp @@ -53,8 +53,8 @@ MaterialItem* MaterialModel::addMaterial(const QString& name, double material_da materialDataItem->setReal(material_data_real); materialDataItem->setImag(material_data_imag); - ColorProperty color(MaterialItemUtils::suggestMaterialColor(name)); - materialItem->setItemValue(MaterialItem::P_COLOR, color.getVariant()); + QColor color = MaterialItemUtils::suggestMaterialColor(name); + materialItem->setItemValue(MaterialItem::P_COLOR, MaterialItemUtils::colorProperty(color).variant()); return materialItem; } diff --git a/GUI/coregui/Views/MaterialEditor/MaterialItemUtils.cpp b/GUI/coregui/Views/MaterialEditor/MaterialItemUtils.cpp index e6fe1cd458632ad80d8e4b08188592b1cccf0b4c..6b4cfa95ed5f43044e38525ee461845c1feb6e9e 100644 --- a/GUI/coregui/Views/MaterialEditor/MaterialItemUtils.cpp +++ b/GUI/coregui/Views/MaterialEditor/MaterialItemUtils.cpp @@ -99,14 +99,23 @@ ExternalProperty MaterialItemUtils::materialProperty(const SessionItem& material { ExternalProperty result; - ColorProperty colorProperty = materialItem.getItemValue(MaterialItem::P_COLOR).value<ColorProperty>(); + ExternalProperty colorProperty = materialItem.getItemValue(MaterialItem::P_COLOR).value<ExternalProperty>(); result.setIdentifier(materialItem.getItemValue(MaterialItem::P_IDENTIFIER).toString()); - result.setColor(colorProperty.getColor()); + result.setColor(colorProperty.color()); result.setText(materialItem.itemName()); return result; } +ExternalProperty MaterialItemUtils::colorProperty(const QColor& color) +{ + ExternalProperty result; + result.setColor(color); + result.setText(QString("[%1, %2, %3] (%4)") + .arg(color.red()).arg(color.green()).arg(color.blue()).arg(color.alpha())); + return result; +} + ExternalProperty MaterialItemUtils::selectMaterialProperty(const ExternalProperty& previous) { MaterialEditorDialog dialog(AppSvc::materialModel()); @@ -126,12 +135,8 @@ ExternalProperty MaterialItemUtils::selectColorProperty(const ExternalProperty& bool ok = false; QRgb oldRgba = previous.color().rgba(); QRgb newRgba = QColorDialog::getRgba(oldRgba, &ok, nullptr); - if (ok && newRgba != oldRgba) { - QColor col = QColor::fromRgba(newRgba); - result.setColor(col); - result.setText(QString("[%1, %2, %3] (%4)") - .arg(col.red()).arg(col.green()).arg(col.blue()).arg(col.alpha())); - } + if (ok && newRgba != oldRgba) + result = MaterialItemUtils::colorProperty(QColor::fromRgba(newRgba)); return result; } diff --git a/GUI/coregui/Views/MaterialEditor/MaterialItemUtils.h b/GUI/coregui/Views/MaterialEditor/MaterialItemUtils.h index dc28de456b7bf78026d31f38d5d0151605309c41..3f662b7eb2c36f2f259fcfd7a91e8372da02ed5e 100644 --- a/GUI/coregui/Views/MaterialEditor/MaterialItemUtils.h +++ b/GUI/coregui/Views/MaterialEditor/MaterialItemUtils.h @@ -40,6 +40,9 @@ BA_CORE_API_ QStringList materialRelatedModelTypes(); //! Constructs material property corresponding to given material. BA_CORE_API_ ExternalProperty materialProperty(const SessionItem& materialItem); +//! Constructs color property from given color. +BA_CORE_API_ ExternalProperty colorProperty(const QColor& color); + //! Calls material selector dialog. BA_CORE_API_ ExternalProperty selectMaterialProperty(const ExternalProperty &previous=ExternalProperty()); diff --git a/Tests/UnitTests/GUI/TestMaterialPropertyController.h b/Tests/UnitTests/GUI/TestMaterialPropertyController.h index 1da1e70af02c526d7d5afef6bcebd9451122a01c..1c19bfd8945a3b294164867f44855710ffadf18c 100644 --- a/Tests/UnitTests/GUI/TestMaterialPropertyController.h +++ b/Tests/UnitTests/GUI/TestMaterialPropertyController.h @@ -47,8 +47,8 @@ inline void TestMaterialPropertyController::test_ControllerForLayer() QCOMPARE(property.color(), mat1->getColor()); // changing color of MaterialItem - ColorProperty colorProperty(Qt::red); - mat1->setItemValue(MaterialItem::P_COLOR, colorProperty.getVariant()); + ExternalProperty colorProperty = MaterialItemUtils::colorProperty(QColor(Qt::red)); + mat1->setItemValue(MaterialItem::P_COLOR, colorProperty.variant()); // QCOMPARE(property_changed, 2); property = layer->getItemValue(LayerItem::P_MATERIAL).value<ExternalProperty>(); QCOMPARE(property.identifier(), mat1->getIdentifier());