+ implement PropertyMaterialListItem
This commit is contained in:
@@ -2604,7 +2604,8 @@ void PropertyMaterialList::setPyObject(PyObject *value)
|
||||
|
||||
for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
|
||||
if (PyObject_TypeCheck((*it).ptr(), &(MaterialPy::Type))) {
|
||||
materials.push_back(*static_cast<MaterialPy*>(value)->getMaterialPtr());
|
||||
Material mat = *static_cast<MaterialPy*>((*it).ptr())->getMaterialPtr();
|
||||
materials.push_back(mat);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2679,7 +2680,7 @@ void PropertyMaterialList::RestoreDocFile(Base::Reader &reader)
|
||||
|
||||
const char* PropertyMaterialList::getEditorName(void) const
|
||||
{
|
||||
return "";// "Gui::PropertyEditor::PropertyMaterialListItem";
|
||||
return "Gui::PropertyEditor::PropertyMaterialListItem";
|
||||
}
|
||||
|
||||
Property *PropertyMaterialList::Copy(void) const
|
||||
|
||||
@@ -139,6 +139,7 @@ void Gui::SoFCDB::init()
|
||||
PropertyIntegerListItem ::init();
|
||||
PropertyColorItem ::init();
|
||||
PropertyMaterialItem ::init();
|
||||
PropertyMaterialListItem ::init();
|
||||
PropertyFileItem ::init();
|
||||
PropertyPathItem ::init();
|
||||
PropertyTransientFileItem ::init();
|
||||
|
||||
@@ -2640,6 +2640,7 @@ TYPESYSTEM_SOURCE(Gui::PropertyEditor::PropertyMaterialListItem, Gui::PropertyEd
|
||||
|
||||
TYPESYSTEM_SOURCE(Gui::PropertyEditor::PropertyMaterialListItem, Gui::PropertyEditor::PropertyItem);
|
||||
|
||||
PropertyMaterialListItem::PropertyMaterialListItem()
|
||||
{
|
||||
// This editor gets a list of materials but it only edits the first item.
|
||||
diffuse = static_cast<PropertyColorItem*>(PropertyColorItem::create());
|
||||
@@ -2685,8 +2686,15 @@ QColor PropertyMaterialListItem::getDiffuseColor() const
|
||||
{
|
||||
QVariant value = data(1, Qt::EditRole);
|
||||
if (!value.canConvert<QVariantList>())
|
||||
return QColor();
|
||||
|
||||
return QColor();
|
||||
|
||||
QVariantList list = value.toList();
|
||||
if (list.isEmpty())
|
||||
return QColor();
|
||||
|
||||
if (!list[0].canConvert<Material>())
|
||||
return QColor();
|
||||
|
||||
Material mat = list[0].value<Material>();
|
||||
return mat.diffuseColor;
|
||||
}
|
||||
@@ -2695,9 +2703,17 @@ void PropertyMaterialListItem::setDiffuseColor(const QColor& color)
|
||||
{
|
||||
QVariant value = data(1, Qt::EditRole);
|
||||
if (!value.canConvert<QVariantList>())
|
||||
return;
|
||||
|
||||
QVariantList val = value.toList();
|
||||
return;
|
||||
|
||||
QVariantList list = value.toList();
|
||||
if (list.isEmpty())
|
||||
return;
|
||||
|
||||
if (!list[0].canConvert<Material>())
|
||||
return;
|
||||
|
||||
Material mat = list[0].value<Material>();
|
||||
mat.diffuseColor = color;
|
||||
list[0] = QVariant::fromValue<Material>(mat);
|
||||
setValue(list);
|
||||
}
|
||||
@@ -2706,8 +2722,15 @@ QColor PropertyMaterialListItem::getAmbientColor() const
|
||||
{
|
||||
QVariant value = data(1, Qt::EditRole);
|
||||
if (!value.canConvert<QVariantList>())
|
||||
return QColor();
|
||||
|
||||
return QColor();
|
||||
|
||||
QVariantList list = value.toList();
|
||||
if (list.isEmpty())
|
||||
return QColor();
|
||||
|
||||
if (!list[0].canConvert<Material>())
|
||||
return QColor();
|
||||
|
||||
Material mat = list[0].value<Material>();
|
||||
return mat.ambientColor;
|
||||
}
|
||||
@@ -2716,9 +2739,17 @@ void PropertyMaterialListItem::setAmbientColor(const QColor& color)
|
||||
{
|
||||
QVariant value = data(1, Qt::EditRole);
|
||||
if (!value.canConvert<QVariantList>())
|
||||
return;
|
||||
|
||||
QVariantList val = value.toList();
|
||||
return;
|
||||
|
||||
QVariantList list = value.toList();
|
||||
if (list.isEmpty())
|
||||
return;
|
||||
|
||||
if (!list[0].canConvert<Material>())
|
||||
return;
|
||||
|
||||
Material mat = list[0].value<Material>();
|
||||
mat.ambientColor = color;
|
||||
list[0] = QVariant::fromValue<Material>(mat);
|
||||
setValue(list);
|
||||
}
|
||||
@@ -2727,8 +2758,15 @@ QColor PropertyMaterialListItem::getSpecularColor() const
|
||||
{
|
||||
QVariant value = data(1, Qt::EditRole);
|
||||
if (!value.canConvert<QVariantList>())
|
||||
return QColor();
|
||||
|
||||
return QColor();
|
||||
|
||||
QVariantList list = value.toList();
|
||||
if (list.isEmpty())
|
||||
return QColor();
|
||||
|
||||
if (!list[0].canConvert<Material>())
|
||||
return QColor();
|
||||
|
||||
Material mat = list[0].value<Material>();
|
||||
return mat.specularColor;
|
||||
}
|
||||
@@ -2737,9 +2775,17 @@ void PropertyMaterialListItem::setSpecularColor(const QColor& color)
|
||||
{
|
||||
QVariant value = data(1, Qt::EditRole);
|
||||
if (!value.canConvert<QVariantList>())
|
||||
return;
|
||||
|
||||
QVariantList val = value.toList();
|
||||
return;
|
||||
|
||||
QVariantList list = value.toList();
|
||||
if (list.isEmpty())
|
||||
return;
|
||||
|
||||
if (!list[0].canConvert<Material>())
|
||||
return;
|
||||
|
||||
Material mat = list[0].value<Material>();
|
||||
mat.specularColor = color;
|
||||
list[0] = QVariant::fromValue<Material>(mat);
|
||||
setValue(list);
|
||||
}
|
||||
@@ -2748,8 +2794,15 @@ QColor PropertyMaterialListItem::getEmissiveColor() const
|
||||
{
|
||||
QVariant value = data(1, Qt::EditRole);
|
||||
if (!value.canConvert<QVariantList>())
|
||||
return QColor();
|
||||
|
||||
return QColor();
|
||||
|
||||
QVariantList list = value.toList();
|
||||
if (list.isEmpty())
|
||||
return QColor();
|
||||
|
||||
if (!list[0].canConvert<Material>())
|
||||
return QColor();
|
||||
|
||||
Material mat = list[0].value<Material>();
|
||||
return mat.emissiveColor;
|
||||
}
|
||||
@@ -2758,9 +2811,17 @@ void PropertyMaterialListItem::setEmissiveColor(const QColor& color)
|
||||
{
|
||||
QVariant value = data(1, Qt::EditRole);
|
||||
if (!value.canConvert<QVariantList>())
|
||||
return;
|
||||
|
||||
QVariantList val = value.toList();
|
||||
return;
|
||||
|
||||
QVariantList list = value.toList();
|
||||
if (list.isEmpty())
|
||||
return;
|
||||
|
||||
if (!list[0].canConvert<Material>())
|
||||
return;
|
||||
|
||||
Material mat = list[0].value<Material>();
|
||||
mat.emissiveColor = color;
|
||||
list[0] = QVariant::fromValue<Material>(mat);
|
||||
setValue(list);
|
||||
}
|
||||
@@ -2769,8 +2830,15 @@ float PropertyMaterialListItem::getShininess() const
|
||||
{
|
||||
QVariant value = data(1, Qt::EditRole);
|
||||
if (!value.canConvert<QVariantList>())
|
||||
return 0;
|
||||
|
||||
return 0;
|
||||
|
||||
QVariantList list = value.toList();
|
||||
if (list.isEmpty())
|
||||
return 0;
|
||||
|
||||
if (!list[0].canConvert<Material>())
|
||||
return 0;
|
||||
|
||||
Material mat = list[0].value<Material>();
|
||||
return mat.shininess;
|
||||
}
|
||||
@@ -2779,9 +2847,17 @@ void PropertyMaterialListItem::setShininess(float s)
|
||||
{
|
||||
QVariant value = data(1, Qt::EditRole);
|
||||
if (!value.canConvert<QVariantList>())
|
||||
return;
|
||||
|
||||
QVariantList val = value.toList();
|
||||
return;
|
||||
|
||||
QVariantList list = value.toList();
|
||||
if (list.isEmpty())
|
||||
return;
|
||||
|
||||
if (!list[0].canConvert<Material>())
|
||||
return;
|
||||
|
||||
Material mat = list[0].value<Material>();
|
||||
mat.shininess = s;
|
||||
list[0] = QVariant::fromValue<Material>(mat);
|
||||
setValue(list);
|
||||
}
|
||||
@@ -2790,8 +2866,15 @@ float PropertyMaterialListItem::getTransparency() const
|
||||
{
|
||||
QVariant value = data(1, Qt::EditRole);
|
||||
if (!value.canConvert<QVariantList>())
|
||||
return 0;
|
||||
|
||||
return 0;
|
||||
|
||||
QVariantList list = value.toList();
|
||||
if (list.isEmpty())
|
||||
return 0;
|
||||
|
||||
if (!list[0].canConvert<Material>())
|
||||
return 0;
|
||||
|
||||
Material mat = list[0].value<Material>();
|
||||
return mat.transparency;
|
||||
}
|
||||
@@ -2800,16 +2883,34 @@ void PropertyMaterialListItem::setTransparency(float t)
|
||||
{
|
||||
QVariant value = data(1, Qt::EditRole);
|
||||
if (!value.canConvert<QVariantList>())
|
||||
return;
|
||||
|
||||
QVariantList val = value.toList();
|
||||
return;
|
||||
|
||||
QVariantList list = value.toList();
|
||||
if (list.isEmpty())
|
||||
return;
|
||||
|
||||
if (!list[0].canConvert<Material>())
|
||||
return;
|
||||
|
||||
Material mat = list[0].value<Material>();
|
||||
mat.transparency = t;
|
||||
list[0] = QVariant::fromValue<Material>(mat);
|
||||
setValue(list);
|
||||
}
|
||||
|
||||
QVariant PropertyMaterialListItem::decoration(const QVariant& value) const
|
||||
{
|
||||
if (!value.canConvert<QVariantList>())
|
||||
return QVariant();
|
||||
|
||||
QVariantList list = value.toList();
|
||||
if (list.isEmpty())
|
||||
return QVariant();
|
||||
|
||||
if (!list[0].canConvert<Material>())
|
||||
return QVariant();
|
||||
{
|
||||
// use the diffuse color
|
||||
|
||||
// use the diffuse color
|
||||
Material mat = list[0].value<Material>();
|
||||
QColor color = mat.diffuseColor;
|
||||
|
||||
@@ -2820,9 +2921,19 @@ QVariant PropertyMaterialListItem::decoration(const QVariant& value) const
|
||||
return QVariant(p);
|
||||
}
|
||||
|
||||
QVariant PropertyMaterialListItem::toString(const QVariant& prop) const
|
||||
{
|
||||
if (!prop.canConvert<QVariantList>())
|
||||
return QVariant();
|
||||
|
||||
QVariantList list = prop.toList();
|
||||
if (list.isEmpty())
|
||||
return QVariant();
|
||||
|
||||
if (!list[0].canConvert<Material>())
|
||||
return QVariant();
|
||||
{
|
||||
// use the diffuse color
|
||||
|
||||
// use the diffuse color
|
||||
Material mat = list[0].value<Material>();
|
||||
QColor value = mat.diffuseColor;
|
||||
QString color = QString::fromLatin1("[%1, %2, %3]")
|
||||
@@ -2830,9 +2941,13 @@ QVariant PropertyMaterialListItem::toString(const QVariant& prop) const
|
||||
return QVariant(color);
|
||||
}
|
||||
|
||||
QVariant PropertyMaterialListItem::toolTip(const App::Property* prop) const
|
||||
QVariant PropertyMaterialListItem::toolTip(const App::Property* prop) const
|
||||
{
|
||||
assert(prop && prop->getTypeId().isDerivedFrom(App::PropertyMaterial::getClassTypeId()));
|
||||
assert(prop && prop->getTypeId().isDerivedFrom(App::PropertyMaterialList::getClassTypeId()));
|
||||
|
||||
const std::vector<App::Material>& values = static_cast<const App::PropertyMaterialList*>(prop)->getValues();
|
||||
if (values.empty())
|
||||
return QVariant();
|
||||
|
||||
App::Material value = values.front();
|
||||
QColor dc = toQColor(value.diffuseColor);
|
||||
@@ -2859,17 +2974,22 @@ QVariant PropertyMaterialListItem::toolTip(const App::Property* prop) const
|
||||
return QVariant(data);
|
||||
}
|
||||
|
||||
QVariant PropertyMaterialListItem::value(const App::Property* prop) const
|
||||
QVariant PropertyMaterialListItem::value(const App::Property* prop) const
|
||||
{
|
||||
assert(prop && prop->getTypeId().isDerivedFrom(App::PropertyMaterial::getClassTypeId()));
|
||||
assert(prop && prop->getTypeId().isDerivedFrom(App::PropertyMaterialList::getClassTypeId()));
|
||||
|
||||
const std::vector<App::Material>& value = static_cast<const App::PropertyMaterialList*>(prop)->getValues();
|
||||
QVariantList variantList;
|
||||
|
||||
variantList << QVariant(toQColor(value.diffuseColor));
|
||||
variantList << QVariant(toQColor(value.ambientColor));
|
||||
variantList << QVariant(toQColor(value.specularColor));
|
||||
variantList << QVariant(toQColor(value.emissiveColor));
|
||||
QVariantList variantList;
|
||||
|
||||
for (std::vector<App::Material>::const_iterator it = value.begin(); it != value.end(); ++it) {
|
||||
Material mat;
|
||||
mat.diffuseColor = toQColor(it->diffuseColor);
|
||||
mat.ambientColor = toQColor(it->ambientColor);
|
||||
mat.specularColor = toQColor(it->specularColor);
|
||||
mat.emissiveColor = toQColor(it->emissiveColor);
|
||||
mat.shininess = it->shininess;
|
||||
mat.transparency = it->transparency;
|
||||
|
||||
variantList << QVariant::fromValue<Material>(mat);
|
||||
}
|
||||
|
||||
@@ -2879,39 +2999,52 @@ void PropertyMaterialListItem::setValue(const QVariant& value)
|
||||
void PropertyMaterialListItem::setValue(const QVariant& value)
|
||||
{
|
||||
if (!value.canConvert<QVariantList>())
|
||||
return;
|
||||
|
||||
QVariantList val = value.toList();
|
||||
App::Color dc = fromQColor(val[0].value<QColor>());
|
||||
App::Color ac = fromQColor(val[1].value<QColor>());
|
||||
App::Color sc = fromQColor(val[2].value<QColor>());
|
||||
App::Color ec = fromQColor(val[3].value<QColor>());
|
||||
return;
|
||||
|
||||
QVariantList list = value.toList();
|
||||
if (list.isEmpty())
|
||||
float t = val[5].toFloat();
|
||||
|
||||
QString data = QString::fromLatin1(
|
||||
"App.Material("
|
||||
"DiffuseColor=(%1,%2,%3),"
|
||||
"AmbientColor=(%4,%5,%6),"
|
||||
"SpecularColor=(%7,%8,%9),"
|
||||
"EmissiveColor=(%10,%11,%12),"
|
||||
"Shininess=(%13),"
|
||||
"Transparency=(%14),"
|
||||
")"
|
||||
)
|
||||
.arg(dc.r, 0, 'f', decimals())
|
||||
.arg(dc.g, 0, 'f', decimals())
|
||||
.arg(dc.b, 0, 'f', decimals())
|
||||
.arg(ac.r, 0, 'f', decimals())
|
||||
.arg(ac.g, 0, 'f', decimals())
|
||||
.arg(ac.b, 0, 'f', decimals())
|
||||
.arg(sc.r, 0, 'f', decimals())
|
||||
.arg(sc.g, 0, 'f', decimals())
|
||||
.arg(sc.b, 0, 'f', decimals())
|
||||
.arg(ec.r, 0, 'f', decimals())
|
||||
.arg(ec.g, 0, 'f', decimals())
|
||||
.arg(ec.b, 0, 'f', decimals())
|
||||
.arg(s, 0, 'f', decimals())
|
||||
return;
|
||||
|
||||
QString data;
|
||||
QTextStream str(&data);
|
||||
str << "(";
|
||||
|
||||
for (QVariantList::iterator it = list.begin(); it != list.end(); ++it) {
|
||||
Material mat = it->value<Material>();
|
||||
App::Color dc = fromQColor(mat.diffuseColor);
|
||||
App::Color ac = fromQColor(mat.ambientColor);
|
||||
App::Color sc = fromQColor(mat.specularColor);
|
||||
App::Color ec = fromQColor(mat.emissiveColor);
|
||||
float s = mat.shininess;
|
||||
float t = mat.transparency;
|
||||
|
||||
QString item = QString::fromLatin1(
|
||||
"App.Material("
|
||||
"DiffuseColor=(%1,%2,%3),"
|
||||
"AmbientColor=(%4,%5,%6),"
|
||||
"SpecularColor=(%7,%8,%9),"
|
||||
"EmissiveColor=(%10,%11,%12),"
|
||||
"Shininess=(%13),"
|
||||
"Transparency=(%14),"
|
||||
")"
|
||||
)
|
||||
.arg(dc.r, 0, 'f', decimals())
|
||||
.arg(dc.g, 0, 'f', decimals())
|
||||
.arg(dc.b, 0, 'f', decimals())
|
||||
.arg(ac.r, 0, 'f', decimals())
|
||||
.arg(ac.g, 0, 'f', decimals())
|
||||
.arg(ac.b, 0, 'f', decimals())
|
||||
.arg(sc.r, 0, 'f', decimals())
|
||||
.arg(sc.g, 0, 'f', decimals())
|
||||
.arg(sc.b, 0, 'f', decimals())
|
||||
.arg(ec.r, 0, 'f', decimals())
|
||||
.arg(ec.g, 0, 'f', decimals())
|
||||
.arg(ec.b, 0, 'f', decimals())
|
||||
.arg(s, 0, 'f', decimals())
|
||||
.arg(t, 0, 'f', decimals())
|
||||
;
|
||||
str << item << ", ";
|
||||
}
|
||||
|
||||
str << ")";
|
||||
|
||||
@@ -2926,8 +3059,22 @@ QWidget* PropertyMaterialListItem::createEditor(QWidget* parent, const QObject*
|
||||
return cb;
|
||||
}
|
||||
|
||||
void PropertyMaterialListItem::setEditorData(QWidget *editor, const QVariant& data) const
|
||||
{
|
||||
if (!data.canConvert<QVariantList>())
|
||||
return;
|
||||
|
||||
QVariantList list = data.toList();
|
||||
if (list.isEmpty())
|
||||
return;
|
||||
|
||||
if (!list[0].canConvert<Material>())
|
||||
return;
|
||||
|
||||
// use the diffuse color
|
||||
Material mat = list[0].value<Material>();
|
||||
QColor color = mat.diffuseColor;
|
||||
{
|
||||
|
||||
Gui::ColorButton *cb = qobject_cast<Gui::ColorButton*>(editor);
|
||||
cb->setColor(color);
|
||||
}
|
||||
@@ -2937,9 +3084,19 @@ QVariant PropertyMaterialListItem::editorData(QWidget *editor) const
|
||||
Gui::ColorButton *cb = qobject_cast<Gui::ColorButton*>(editor);
|
||||
QVariant value = data(1, Qt::EditRole);
|
||||
if (!value.canConvert<QVariantList>())
|
||||
return QVariant();
|
||||
|
||||
QVariantList val = value.toList();
|
||||
return QVariant();
|
||||
|
||||
QVariantList list = value.toList();
|
||||
if (list.isEmpty())
|
||||
return QVariant();
|
||||
|
||||
if (!list[0].canConvert<Material>())
|
||||
return QVariant();
|
||||
|
||||
// use the diffuse color
|
||||
Material mat = list[0].value<Material>();
|
||||
mat.diffuseColor = cb->color();
|
||||
list[0] = QVariant::fromValue<Material>(mat);
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user