Skip to content

Commit

Permalink
fix ticket:5663, handle '%%' in text annotation
Browse files Browse the repository at this point in the history
Don't restart the lookup. Use the current position.
  • Loading branch information
adrpo authored and adeas31 committed Oct 21, 2019
1 parent 820af85 commit a9e5097
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions OMEdit/OMEdit/OMEditGUI/Annotations/TextAnnotation.cpp
Expand Up @@ -528,7 +528,7 @@ void TextAnnotation::updateTextStringHelper(QRegExp regExp)
{
int pos = 0;
while ((pos = regExp.indexIn(mTextString, pos)) != -1) {
QString variable = regExp.cap(0);
QString variable = regExp.cap(0).trimmed();
if ((!variable.isEmpty()) && (variable.compare("%%") != 0) && (variable.compare("%name") != 0) && (variable.compare("%class") != 0)) {
variable.remove("%");
if (!variable.isEmpty()) {
Expand All @@ -550,17 +550,21 @@ void TextAnnotation::updateTextStringHelper(QRegExp regExp)
}
if (displaytUnit.isEmpty()) {
mTextString.replace(pos, regExp.matchedLength(), textValue);
pos += textValue.length();
} else {
mTextString.replace(pos, regExp.matchedLength(), QString("%1 %2").arg(textValue, displaytUnit));
QString textValueWithDisplayUnit = QString("%1 %2").arg(textValue, displaytUnit);
mTextString.replace(pos, regExp.matchedLength(), textValueWithDisplayUnit);
pos += textValueWithDisplayUnit.length();
}
} else { /* if the value of %\\W* is empty then remove the % sign. */
mTextString.replace(pos, 1, "");
}
} else { /* if there is just alone % then remove it. Because if you want to print % then use %%. */
mTextString.replace(pos, 1, "");
}
} else if (variable.compare("%%") == 0) { /* if string is %% then just move over it. We replace it with % in TextAnnotation::updateTextString(). */
pos += regExp.matchedLength();
}
pos = 0;
}
}

Expand Down

0 comments on commit a9e5097

Please sign in to comment.