Skip to content

Commit 8c9729e

Browse files
authored
Use the choice comment only for display (#12789)
#12756 Do not add the comment in the modification in the source code.
1 parent 8a3de6a commit 8c9729e

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

OMEdit/OMEditLIB/Element/ElementProperties.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,7 @@ void Parameter::createValueWidget()
684684
}
685685
QString constrainedByClassName = QStringLiteral("$Any");
686686
QString replaceable = "", replaceableText = "", replaceableChoice = "", parentClassName = "", restriction = "", elementName = "";
687-
QStringList enumerationLiterals, enumerationLiteralsDisplay, replaceableChoices, choices;
687+
QStringList enumerationLiterals, enumerationLiteralsDisplay, replaceableChoices, choices, choicesComment;
688688

689689
switch (mValueType) {
690690
case Parameter::Boolean:
@@ -740,7 +740,8 @@ void Parameter::createValueWidget()
740740
}
741741
}
742742
if (mpModelInstanceElement->getAnnotation()->getChoices()) {
743-
choices = mpModelInstanceElement->getAnnotation()->getChoices()->getChoicesStringList();
743+
choices = mpModelInstanceElement->getAnnotation()->getChoices()->getChoicesValueStringList();
744+
choicesComment = mpModelInstanceElement->getAnnotation()->getChoices()->getChoicesCommentStringList();
744745
}
745746
parentClassName = mpElementParameters->getElementParentClassName();
746747
if (mpModelInstanceElement->getModel()) {
@@ -772,7 +773,7 @@ void Parameter::createValueWidget()
772773
QString choice = choices[i];
773774
QString comment;
774775
if (MainWindow::instance()->isNewApi()) {
775-
comment = choice;
776+
comment = i < choicesComment.size() ? choicesComment[i] : choice;
776777
} else {
777778
comment = StringHandler::removeFirstLastQuotes(FlatModelica::Parser::getModelicaComment(choice));
778779
}

OMEdit/OMEditLIB/Modeling/Model.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,7 @@ namespace ModelInstance
761761
}
762762
}
763763

764-
QString Modifier::toString(bool skipTopLevel) const
764+
QString Modifier::toString(bool skipTopLevel, bool includeComment) const
765765
{
766766
if (mpElement) {
767767
return mpElement->toString(skipTopLevel);
@@ -782,7 +782,7 @@ namespace ModelInstance
782782
if (!mValue.isEmpty()) {
783783
value.append(mName.isEmpty() ? mValue : " = " % mValue);
784784
}
785-
if (!mComment.isEmpty()) {
785+
if (includeComment && !mComment.isEmpty()) {
786786
value.append(" \"" % mComment % "\"");
787787
}
788788

@@ -1763,7 +1763,7 @@ namespace ModelInstance
17631763
}
17641764
}
17651765

1766-
QStringList Choices::getChoicesStringList() const
1766+
QStringList Choices::getChoicesValueStringList() const
17671767
{
17681768
QStringList choices;
17691769
foreach (auto *pChoice, mChoices) {
@@ -1772,6 +1772,15 @@ namespace ModelInstance
17721772
return choices;
17731773
}
17741774

1775+
QStringList Choices::getChoicesCommentStringList() const
1776+
{
1777+
QStringList choices;
1778+
foreach (auto *pChoice, mChoices) {
1779+
choices.append(pChoice->toString(false, true));
1780+
}
1781+
return choices;
1782+
}
1783+
17751784
Element::Element(Model *pParentModel)
17761785
{
17771786
mpParentModel = pParentModel;

OMEdit/OMEditLIB/Modeling/Model.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,8 @@ namespace ModelInstance
365365
bool isCheckBox() const {return mCheckBox;}
366366
bool isDymolaCheckBox() const {return mDymolaCheckBox;}
367367
const QList<Modifier*> &getChoices() const {return mChoices;}
368-
QStringList getChoicesStringList() const;
368+
QStringList getChoicesValueStringList() const;
369+
QStringList getChoicesCommentStringList() const;
369370
private:
370371
Model *mpParentModel;
371372
BooleanAnnotation mCheckBox;
@@ -468,7 +469,7 @@ namespace ModelInstance
468469
const QString &getType() const {return mType;}
469470
QString getValueWithoutQuotes() const {return StringHandler::removeFirstLastQuotes(getValue());}
470471
bool isValueDefined() const {return mValueDefined;}
471-
QString toString(bool skipTopLevel = false) const;
472+
QString toString(bool skipTopLevel = false, bool includeComment = false) const;
472473
Modifier *getModifier(const QString &modifier) const;
473474
QPair<QString, bool> getModifierValue(const QString &modifier) const;
474475
bool hasModifier(const QString &modifier) const;

0 commit comments

Comments
 (0)