Core: Update expressions on property rename

This includes both expressions in generic containers and in
spreadsheets.
This commit is contained in:
Pieter Hijma
2025-05-18 15:16:31 +02:00
committed by Yorik van Havre
parent 18d87df6f1
commit 5bdfba3a1a
4 changed files with 35 additions and 0 deletions

View File

@@ -53,6 +53,8 @@ PropertyExpressionContainer::PropertyExpressionContainer()
inited = true;
GetApplication().signalRelabelDocument.connect(
PropertyExpressionContainer::slotRelabelDocument);
GetApplication().signalRenameDynamicProperty.connect(
PropertyExpressionContainer::slotRenameDynamicProperty);
}
_ExprContainers.insert(this);
}
@@ -75,6 +77,13 @@ void PropertyExpressionContainer::slotRelabelDocument(const App::Document& doc)
}
}
void PropertyExpressionContainer::slotRenameDynamicProperty(const App::Property& prop, const char* oldName)
{
for (auto container : _ExprContainers) {
container->onRenameDynamicProperty(prop, oldName);
}
}
///////////////////////////////////////////////////////////////////////////////////////
struct PropertyExpressionEngine::Private
@@ -1208,6 +1217,17 @@ void PropertyExpressionEngine::onRelabeledDocument(const App::Document& doc)
}
}
void PropertyExpressionEngine::onRenameDynamicProperty(const App::Property& prop, const char* oldName)
{
ObjectIdentifier oldNameId = ObjectIdentifier(prop.getContainer(), std::string(oldName));
ObjectIdentifier newNameId = ObjectIdentifier(prop);
const std::map<ObjectIdentifier, ObjectIdentifier> paths = {
{oldNameId, newNameId},
};
renameObjectIdentifiers(paths);
}
void PropertyExpressionEngine::getLinksTo(std::vector<App::ObjectIdentifier>& identifiers,
App::DocumentObject* obj,
const char* subname,

View File

@@ -59,9 +59,11 @@ public:
protected:
virtual void onRelabeledDocument(const App::Document& doc) = 0;
virtual void onRenameDynamicProperty(const App::Property& prop, const char* oldName) = 0;
private:
static void slotRelabelDocument(const App::Document& doc);
static void slotRenameDynamicProperty(const App::Property& prop, const char* oldName);
};
class AppExport PropertyExpressionEngine
@@ -117,6 +119,7 @@ public:
std::map<App::ObjectIdentifier, const App::Expression*> getExpressions() const override;
void setExpressions(std::map<App::ObjectIdentifier, App::ExpressionPtr>&& exprs) override;
void onRelabeledDocument(const App::Document& doc) override;
void onRenameDynamicProperty(const App::Property& prop, const char* oldName) override;
void setValue()
{} // Dummy

View File

@@ -1577,6 +1577,17 @@ void PropertySheet::onRelabeledDocument(const App::Document& doc)
}
}
void PropertySheet::onRenameDynamicProperty(const App::Property& prop, const char* oldName)
{
ObjectIdentifier oldNameId = ObjectIdentifier(prop.getContainer(), std::string(oldName));
ObjectIdentifier newNameId = ObjectIdentifier(prop);
const std::map<ObjectIdentifier, ObjectIdentifier> paths = {
{oldNameId, newNameId},
};
renameObjectIdentifiers(paths);
}
void PropertySheet::renameObjectIdentifiers(
const std::map<App::ObjectIdentifier, App::ObjectIdentifier>& paths)
{

View File

@@ -51,6 +51,7 @@ public:
std::map<App::ObjectIdentifier, const App::Expression*> getExpressions() const override;
void setExpressions(std::map<App::ObjectIdentifier, App::ExpressionPtr>&& exprs) override;
void onRelabeledDocument(const App::Document& doc) override;
void onRenameDynamicProperty(const App::Property& prop, const char* oldName) override;
void updateElementReference(App::DocumentObject* feature,
bool reverse = false,