update expressions when relabelling a document object

This commit is contained in:
wmayer
2017-10-08 01:45:39 +02:00
parent e3d8daac4c
commit 88962a8c45
2 changed files with 42 additions and 6 deletions

View File

@@ -528,12 +528,19 @@ void DocumentObject::connectRelabelSignals()
if (ExpressionEngine.numExpressions() > 0) {
// Not already connected?
if (!onRelabledObjectConnection.connected())
onRelabledObjectConnection = getDocument()->signalRelabelObject.connect(boost::bind(&PropertyExpressionEngine::slotObjectRenamed, &ExpressionEngine, _1));
if (!onRelabledObjectConnection.connected()) {
onRelabledObjectConnection = getDocument()->signalRelabelObject
.connect(boost::bind(&PropertyExpressionEngine::slotObjectRenamed,
&ExpressionEngine, _1));
}
// Connect to signalDeletedObject, to properly track deletion of other objects that might be referenced in an expression
if (!onDeletedObjectConnection.connected())
onDeletedObjectConnection = getDocument()->signalDeletedObject.connect(boost::bind(&PropertyExpressionEngine::slotObjectDeleted, &ExpressionEngine, _1));
// Connect to signalDeletedObject, to properly track deletion of other objects
// that might be referenced in an expression
if (!onDeletedObjectConnection.connected()) {
onDeletedObjectConnection = getDocument()->signalDeletedObject
.connect(boost::bind(&PropertyExpressionEngine::slotObjectDeleted,
&ExpressionEngine, _1));
}
try {
// Crude method to resolve all expression dependencies

View File

@@ -362,6 +362,24 @@ bool ObjectIdentifier::renameDocumentObject(const std::string &oldName, const st
return true;
}
}
// If object identifier uses the label then resolving the document object will fail.
// So, it must be checked if using the new label will succeed
if (!components.empty() && components[0].getName() == oldName) {
ObjectIdentifier id(*this);
id.components[0].name = newName;
ResolveResults result(id);
if (result.propertyIndex == 1 && result.resolvedDocumentObjectName == newName) {
if (ExpressionParser::isTokenAnIndentifier(newName))
components[0].name = newName;
else
components[0].name = ObjectIdentifier::String(newName, true);
return true;
}
}
return false;
}
@@ -385,6 +403,18 @@ bool ObjectIdentifier::validDocumentObjectRename(const std::string &oldName, con
if (result.propertyIndex == 1 && result.resolvedDocumentObjectName == oldName)
return true;
}
// If object identifier uses the label then resolving the document object will fail.
// So, it must be checked if using the new label will succeed
if (!components.empty() && components[0].getName() == oldName) {
ObjectIdentifier id(*this);
id.components[0].name = newName;
ResolveResults result(id);
if (result.propertyIndex == 1 && result.resolvedDocumentObjectName == newName)
return true;
}
return false;
}
@@ -411,7 +441,6 @@ bool ObjectIdentifier::renameDocument(const std::string &oldName, const std::str
return true;
}
}
return false;
}