Skip to content

Commit

Permalink
Fix the modifier value in setElementModifierValue for $Code (#12046)
Browse files Browse the repository at this point in the history
Do the same in setExtendsModifierValue
#11790 and #11891
  • Loading branch information
adeas31 committed Feb 29, 2024
1 parent a894ed4 commit a941258
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
3 changes: 2 additions & 1 deletion OMEdit/OMEditLIB/Element/Element.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3624,7 +3624,8 @@ void Element::duplicate()
QPointF gridStep(mpGraphicsView->mMergedCoOrdinateSystem.getHorizontalGridStep() * 5, mpGraphicsView->mMergedCoOrdinateSystem.getVerticalGridStep() * 5);
// add component
if (mpGraphicsView->getModelWidget()->isNewApi()) {
ModelInstance::Component *pModelInstanceComponent = GraphicsView::createModelInstanceComponent(mpGraphicsView->getModelWidget()->getModelInstance(), name, getClassName(), false);
ModelInstance::Component *pModelInstanceComponent = GraphicsView::createModelInstanceComponent(mpGraphicsView->getModelWidget()->getModelInstance(), name,
getClassName(), mpModel->isConnector());
mpGraphicsView->addElementToView(pModelInstanceComponent, false, true, false, QPointF(0, 0), getOMCPlacementAnnotation(gridStep), false);
// set modifiers
if (mpModelComponent->getModifier()) {
Expand Down
6 changes: 0 additions & 6 deletions OMEdit/OMEditLIB/Element/ElementProperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1901,7 +1901,6 @@ void ElementParameters::updateElementParameters()
QStringList modifiersList;
foreach (ElementModifier elementModifier, elementModifiersList) {
int index = elementModifier.mValue.indexOf('(');
bool onlyName = false;
QString modifierStartStr;
if (index > -1) {
modifierStartStr = elementModifier.mValue.left(index);
Expand All @@ -1910,7 +1909,6 @@ void ElementParameters::updateElementParameters()
QString modifierValue;
if (elementModifier.mValue.isEmpty()) {
modifierValue = QString(elementModifier.mKey);
onlyName = true;
} else if (elementModifier.mValue.startsWith(QStringLiteral("redeclare")) || ((index > -1) && (modifierStartStr.compare(elementModifier.mKey) == 0))) {
modifierValue = QString(elementModifier.mValue);
} else {
Expand All @@ -1934,10 +1932,6 @@ void ElementParameters::updateElementParameters()
modifierValue.prepend(modifier);
}
}
// skip adding empty parameter names
if (onlyName && modifierValue.compare(elementModifier.mKey) == 0) {
continue;
}
modifiersList.append(modifierValue);
}
if (mNested) {
Expand Down
10 changes: 9 additions & 1 deletion OMEdit/OMEditLIB/OMC/OMCProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ void OMCProxy::sendCommand(const QString expression, bool saveToHistory)

/* Check if any custom command updates the program.
* saveToHistory is true for custom commands.
* Fixes issuse #8052
* Fixes issue #8052
*/
if (saveToHistory) {
try {
Expand Down Expand Up @@ -1124,6 +1124,10 @@ bool OMCProxy::setElementModifierValueOld(QString className, QString modifierNam
*/
bool OMCProxy::setElementModifierValue(QString className, QString modifierName, QString modifierValue)
{
/* Issue #11790 and #11891.
* Remove extra parentheses if there are any.
*/
modifierValue = StringHandler::removeFirstLastParentheses(modifierValue);
const QString expression = "setElementModifierValue(" % className % ", " % modifierName % ", $Code((" % modifierValue % ")))";
sendCommand(expression);
if (StringHandler::unparseBool(getResult())) {
Expand Down Expand Up @@ -1230,6 +1234,10 @@ bool OMCProxy::setExtendsModifierValueOld(QString className, QString extendsClas
*/
bool OMCProxy::setExtendsModifierValue(QString className, QString extendsClassName, QString modifierName, QString modifierValue)
{
/* Issue #11790 and #11891.
* Remove extra parentheses if there are any.
*/
modifierValue = StringHandler::removeFirstLastParentheses(modifierValue);
const QString expression = "setExtendsModifierValue(" % className % ", " % extendsClassName % ", " % modifierName % ", $Code((" % modifierValue % ")))";
sendCommand(expression);
if (StringHandler::unparseBool(getResult())) {
Expand Down

0 comments on commit a941258

Please sign in to comment.