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:
@@ -156,7 +156,7 @@ void MaterialsEditor::getFavorites()
|
||||
auto param = App::GetApplication().GetParameterGroupByPath(
|
||||
"User parameter:BaseApp/Preferences/Mod/Material/Favorites");
|
||||
int count = param->GetInt("Favorites", 0);
|
||||
for (int i = 0; i < count; i++) {
|
||||
for (int i = 0; static_cast<long>(i) < count; i++) {
|
||||
QString key = QString::fromLatin1("FAV%1").arg(i);
|
||||
QString uuid = QString::fromStdString(param->GetASCII(key.toStdString().c_str(), ""));
|
||||
_favorites.push_back(uuid);
|
||||
@@ -170,7 +170,7 @@ void MaterialsEditor::saveFavorites()
|
||||
|
||||
// Clear out the existing favorites
|
||||
int count = param->GetInt("Favorites", 0);
|
||||
for (int i = 0; i < count; i++) {
|
||||
for (int i = 0; static_cast<long>(i) < count; i++) {
|
||||
QString key = QString::fromLatin1("FAV%1").arg(i);
|
||||
param->RemoveASCII(key.toStdString().c_str());
|
||||
}
|
||||
@@ -232,7 +232,7 @@ void MaterialsEditor::getRecents()
|
||||
"User parameter:BaseApp/Preferences/Mod/Material/Recent");
|
||||
_recentMax = param->GetInt("RecentMax", 5);
|
||||
int count = param->GetInt("Recent", 0);
|
||||
for (int i = 0; i < count; i++) {
|
||||
for (int i = 0; static_cast<long>(i) < count; i++) {
|
||||
QString key = QString::fromLatin1("MRU%1").arg(i);
|
||||
QString uuid = QString::fromStdString(param->GetASCII(key.toStdString().c_str(), ""));
|
||||
_recents.push_back(uuid);
|
||||
@@ -246,7 +246,7 @@ void MaterialsEditor::saveRecents()
|
||||
|
||||
// Clear out the existing favorites
|
||||
int count = param->GetInt("Recent", 0);
|
||||
for (int i = 0; i < count; i++) {
|
||||
for (int i = 0; static_cast<long>(i) < count; i++) {
|
||||
QString key = QString::fromLatin1("MRU%1").arg(i);
|
||||
param->RemoveASCII(key.toStdString().c_str());
|
||||
}
|
||||
@@ -342,6 +342,7 @@ void MaterialsEditor::propertyChange(const QString& property, const QString valu
|
||||
_material->setAppearanceValue(property, value);
|
||||
updatePreview();
|
||||
}
|
||||
update();
|
||||
_edited = true;
|
||||
}
|
||||
|
||||
@@ -514,6 +515,15 @@ void MaterialsEditor::onOk(bool checked)
|
||||
{
|
||||
Q_UNUSED(checked)
|
||||
|
||||
// Ensure data is saved (or discarded) before exiting
|
||||
if (_material->getEditState() != Materials::Material::ModelEdit_None) {
|
||||
// Prompt the user to save or discard changes
|
||||
int res = confirmSave(this);
|
||||
if (res == QMessageBox::Cancel) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
accept();
|
||||
}
|
||||
|
||||
@@ -606,7 +616,7 @@ void MaterialsEditor::saveMaterialTree(const Base::Reference<ParameterGrp>& para
|
||||
treeParam->Clear();
|
||||
|
||||
auto tree = ui->treeMaterials;
|
||||
auto model = static_cast<QStandardItemModel*>(tree->model());
|
||||
auto model = dynamic_cast<QStandardItemModel*>(tree->model());
|
||||
|
||||
auto root = model->invisibleRootItem();
|
||||
for (int i = 0; i < root->rowCount(); i++) {
|
||||
@@ -796,7 +806,7 @@ void MaterialsEditor::fillMaterialTree()
|
||||
"User parameter:BaseApp/Preferences/Mod/Material/Editor/MaterialTree");
|
||||
|
||||
auto tree = ui->treeMaterials;
|
||||
auto model = static_cast<QStandardItemModel*>(tree->model());
|
||||
auto model = dynamic_cast<QStandardItemModel*>(tree->model());
|
||||
|
||||
auto lib = new QStandardItem(tr("Favorites"));
|
||||
lib->setFlags(Qt::ItemIsEnabled | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled);
|
||||
@@ -835,7 +845,7 @@ void MaterialsEditor::createMaterialTree()
|
||||
void MaterialsEditor::refreshMaterialTree()
|
||||
{
|
||||
auto tree = ui->treeMaterials;
|
||||
auto model = static_cast<QStandardItemModel*>(tree->model());
|
||||
auto model = dynamic_cast<QStandardItemModel*>(tree->model());
|
||||
model->clear();
|
||||
|
||||
fillMaterialTree();
|
||||
@@ -925,7 +935,7 @@ QString MaterialsEditor::getColorHash(const QString& colorString, int colorRange
|
||||
void MaterialsEditor::updateMaterialAppearance()
|
||||
{
|
||||
QTreeView* tree = ui->treeAppearance;
|
||||
auto treeModel = static_cast<QStandardItemModel*>(tree->model());
|
||||
auto treeModel = dynamic_cast<QStandardItemModel*>(tree->model());
|
||||
treeModel->clear();
|
||||
|
||||
QStringList headers;
|
||||
@@ -1099,7 +1109,7 @@ void MaterialsEditor::onSelectMaterial(const QItemSelection& selected,
|
||||
|
||||
// Get the UUID before changing the underlying data model
|
||||
QString uuid;
|
||||
auto model = static_cast<QStandardItemModel*>(ui->treeMaterials->model());
|
||||
auto model = dynamic_cast<QStandardItemModel*>(ui->treeMaterials->model());
|
||||
QModelIndexList indexes = selected.indexes();
|
||||
for (auto it = indexes.begin(); it != indexes.end(); it++) {
|
||||
QStandardItem* item = model->itemFromIndex(*it);
|
||||
@@ -1140,6 +1150,15 @@ void MaterialsEditor::onDoubleClick(const QModelIndex& index)
|
||||
{
|
||||
Q_UNUSED(index)
|
||||
|
||||
// Ensure data is saved (or discarded) before exiting
|
||||
if (_material->getEditState() != Materials::Material::ModelEdit_None) {
|
||||
// Prompt the user to save or discard changes
|
||||
int res = confirmSave(this);
|
||||
if (res == QMessageBox::Cancel) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
accept();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user