Material: Material editor enhancements (#11764)
Continues the work of the material subsystem improvements. Add support for embedded SVG files. These are not the same as image files so need to be handled differently. Add the ability to filter materials in the editor when called from code. This allows programs to select objects supporting specific models, complete models, older models, etc. Updated tests, and refactored code. New models and materials supporting patterns such as used by the TechDraw workbench. fixes #11686 - checks for the presense of a model property before assinging a value. This can happen when a required model definition is not available. --------- Co-authored-by: Chris Hennes <chennes@pioneerlibrarysystem.org>
This commit is contained in:
@@ -41,6 +41,25 @@ using namespace Materials;
|
||||
|
||||
TYPESYSTEM_SOURCE(Materials::MaterialValue, Base::BaseClass)
|
||||
|
||||
QMap<QString, MaterialValue::ValueType> MaterialValue::_typeMap {
|
||||
{QString::fromStdString("String"), String},
|
||||
{QString::fromStdString("Boolean"), Boolean},
|
||||
{QString::fromStdString("Integer"), Integer},
|
||||
{QString::fromStdString("Float"), Float},
|
||||
{QString::fromStdString("Quantity"), Quantity},
|
||||
{QString::fromStdString("Distribution"), Distribution},
|
||||
{QString::fromStdString("List"), List},
|
||||
{QString::fromStdString("2DArray"), Array2D},
|
||||
{QString::fromStdString("3DArray"), Array3D},
|
||||
{QString::fromStdString("Color"), Color},
|
||||
{QString::fromStdString("Image"), Image},
|
||||
{QString::fromStdString("File"), File},
|
||||
{QString::fromStdString("URL"), URL},
|
||||
{QString::fromStdString("MultiLineString"), MultiLineString},
|
||||
{QString::fromStdString("FileList"), FileList},
|
||||
{QString::fromStdString("ImageList"), ImageList},
|
||||
{QString::fromStdString("SVG"), SVG}};
|
||||
|
||||
MaterialValue::MaterialValue()
|
||||
: _valueType(None)
|
||||
{
|
||||
@@ -93,10 +112,16 @@ QString MaterialValue::escapeString(const QString& source)
|
||||
return res;
|
||||
}
|
||||
|
||||
MaterialValue::ValueType MaterialValue::mapType(const QString& stringType)
|
||||
{
|
||||
// If not found, return None
|
||||
return _typeMap.value(stringType, None);
|
||||
}
|
||||
|
||||
void MaterialValue::setInitialValue(ValueType inherited)
|
||||
{
|
||||
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
|
||||
if (_valueType == String || _valueType == MultiLineString) {
|
||||
if (_valueType == String || _valueType == MultiLineString || _valueType == SVG) {
|
||||
_value = QVariant(static_cast<QVariant::Type>(QMetaType::QString));
|
||||
}
|
||||
else if (_valueType == Boolean) {
|
||||
@@ -121,7 +146,7 @@ void MaterialValue::setInitialValue(ValueType inherited)
|
||||
_value = QVariant(static_cast<QVariant::Type>(QMetaType::QString));
|
||||
}
|
||||
#else
|
||||
if (_valueType == String || _valueType == MultiLineString) {
|
||||
if (_valueType == String || _valueType == MultiLineString || _valueType == SVG) {
|
||||
_value = QVariant(QMetaType(QMetaType::QString));
|
||||
}
|
||||
else if (_valueType == Boolean) {
|
||||
@@ -237,7 +262,7 @@ QString MaterialValue::getYAMLStringImageList() const
|
||||
QString MaterialValue::getYAMLStringMultiLine() const
|
||||
{
|
||||
QString yaml;
|
||||
yaml = QString::fromStdString(" >2");
|
||||
yaml = QString::fromStdString(" |2");
|
||||
auto list =
|
||||
getValue().toString().split(QRegExp(QString::fromStdString("[\r\n]")), Qt::SkipEmptyParts);
|
||||
for (auto& it : list) {
|
||||
@@ -259,7 +284,7 @@ QString MaterialValue::getYAMLString() const
|
||||
if (getType() == MaterialValue::ImageList) {
|
||||
return getYAMLStringImageList();
|
||||
}
|
||||
if (getType() == MaterialValue::MultiLineString) {
|
||||
if (getType() == MaterialValue::MultiLineString || getType() == MaterialValue::SVG) {
|
||||
return getYAMLStringMultiLine();
|
||||
}
|
||||
if (getType() == MaterialValue::Quantity) {
|
||||
@@ -272,16 +297,6 @@ QString MaterialValue::getYAMLString() const
|
||||
yaml += QString::fromLatin1("%1").arg(value.toFloat(), 0, 'g', 6);
|
||||
}
|
||||
}
|
||||
else if (getType() == MaterialValue::MultiLineString) {
|
||||
yaml = QString::fromLatin1(">2");
|
||||
auto list =
|
||||
getValue().toString().split(QRegularExpression(QString::fromLatin1("[\r\n]")),
|
||||
Qt::SkipEmptyParts);
|
||||
for (auto& it : list) {
|
||||
yaml += QString::fromLatin1("\n ") + it;
|
||||
}
|
||||
return yaml;
|
||||
}
|
||||
else if (getType() == MaterialValue::List) {
|
||||
for (auto& it : getList()) {
|
||||
yaml += QString::fromLatin1("\n - \"") + escapeString(it.toString())
|
||||
@@ -293,7 +308,7 @@ QString MaterialValue::getYAMLString() const
|
||||
yaml += getValue().toString();
|
||||
}
|
||||
}
|
||||
yaml = QString::fromLatin1("\"") + escapeString(yaml) + QString::fromLatin1("\"");
|
||||
yaml = QString::fromLatin1(" \"") + escapeString(yaml) + QString::fromLatin1("\"");
|
||||
return yaml;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user