Skip to content
Snippets Groups Projects
Commit 0448b337 authored by Pospelov, Gennady's avatar Pospelov, Gennady
Browse files

MaterialItem switched to ExternalProperty to store color.

parent 9e19770b
No related branches found
No related tags found
No related merge requests found
......@@ -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)
......
......@@ -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;
}
......
......@@ -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;
}
......@@ -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());
......
......@@ -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());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment