Skip to content

Commit 86eb441

Browse files
committed
ticket:4771 Use square brackets instead of curly brackets for dimension
1 parent a45068d commit 86eb441

File tree

6 files changed

+50
-24
lines changed

6 files changed

+50
-24
lines changed

OMEdit/OMEditGUI/Component/ComponentProperties.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1299,7 +1299,7 @@ void ComponentAttributes::setUpDialog()
12991299
// dimensions
13001300
mpDimensionsLabel = new Label(tr("Dimensions:"));
13011301
mpDimensionsTextBox = new QLineEdit;
1302-
mpDimensionsTextBox->setToolTip(tr("Array of dimensions e.g {1, 5, 2}"));
1302+
mpDimensionsTextBox->setToolTip(tr("Array of dimensions e.g [1, 5, 2]"));
13031303
mpCommentLabel = new Label(Helper::comment);
13041304
mpCommentTextBox = new QLineEdit;
13051305
mpPathLabel = new Label(Helper::path);
@@ -1399,7 +1399,8 @@ void ComponentAttributes::initializeDialog()
13991399
mpNameTextBox->setText(mpComponent->getComponentInfo()->getName());
14001400
mpNameTextBox->setCursorPosition(0);
14011401
// get dimensions
1402-
mpDimensionsTextBox->setText(mpComponent->getComponentInfo()->getArrayIndex());
1402+
QString dimensions = StringHandler::removeFirstLastCurlBrackets(mpComponent->getComponentInfo()->getArrayIndex());
1403+
mpDimensionsTextBox->setText(QString("[%1]").arg(dimensions));
14031404
// get Comment
14041405
mpCommentTextBox->setText(mpComponent->getComponentInfo()->getComment());
14051406
mpCommentTextBox->setCursorPosition(0);
@@ -1505,7 +1506,8 @@ void ComponentAttributes::updateComponentAttributes()
15051506
newComponentInfo.setInner(mpInnerCheckBox->isChecked());
15061507
newComponentInfo.setOuter(mpOuterCheckBox->isChecked());
15071508
newComponentInfo.setCausality(causality);
1508-
newComponentInfo.setArrayIndex(mpDimensionsTextBox->text());
1509+
QString dimensions = StringHandler::removeFirstLastSquareBrackets(mpDimensionsTextBox->text());
1510+
newComponentInfo.setArrayIndex(QString("{%1}").arg(dimensions));
15091511
/* If user has really changed the Component's attributes then push that change on the stack.
15101512
*/
15111513
if (oldComponentInfo != newComponentInfo) {

OMEdit/OMEditGUI/Component/Transformation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ void Transformation::parseTransformationString(QString value, qreal width, qreal
9696
foreach (QString annotation, annotations) {
9797
if (annotation.startsWith("Placement")) {
9898
annotation = annotation.mid(QString("Placement").length());
99-
annotation = StringHandler::removeFirstLastBrackets(annotation);
99+
annotation = StringHandler::removeFirstLastParentheses(annotation);
100100
QStringList list = StringHandler::getStrings(annotation);
101101
// get transformations of diagram
102102
// get the visible value

OMEdit/OMEditGUI/Modeling/ModelWidgetContainer.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3296,7 +3296,7 @@ void ModelWidget::getModelConnections()
32963296
foreach (QString shape, shapesList) {
32973297
if (shape.startsWith("Line")) {
32983298
lineShape = shape.mid(QString("Line").length());
3299-
lineShape = StringHandler::removeFirstLastBrackets(lineShape);
3299+
lineShape = StringHandler::removeFirstLastParentheses(lineShape);
33003300
break; // break the loop once we have got the line annotation.
33013301
}
33023302
}
@@ -4741,7 +4741,7 @@ void ModelWidget::getModelIconDiagramShapes(StringHandler::ViewType viewType)
47414741
foreach (QString shape, shapesList) {
47424742
if (shape.startsWith("Line")) {
47434743
shape = shape.mid(QString("Line").length());
4744-
shape = StringHandler::removeFirstLastBrackets(shape);
4744+
shape = StringHandler::removeFirstLastParentheses(shape);
47454745
LineAnnotation *pLineAnnotation = new LineAnnotation(shape, pGraphicsView);
47464746
pLineAnnotation->initializeTransformation();
47474747
pLineAnnotation->drawCornerItems();
@@ -4750,7 +4750,7 @@ void ModelWidget::getModelIconDiagramShapes(StringHandler::ViewType viewType)
47504750
pGraphicsView->addItem(pLineAnnotation);
47514751
} else if (shape.startsWith("Polygon")) {
47524752
shape = shape.mid(QString("Polygon").length());
4753-
shape = StringHandler::removeFirstLastBrackets(shape);
4753+
shape = StringHandler::removeFirstLastParentheses(shape);
47544754
PolygonAnnotation *pPolygonAnnotation = new PolygonAnnotation(shape, pGraphicsView);
47554755
pPolygonAnnotation->initializeTransformation();
47564756
pPolygonAnnotation->drawCornerItems();
@@ -4759,7 +4759,7 @@ void ModelWidget::getModelIconDiagramShapes(StringHandler::ViewType viewType)
47594759
pGraphicsView->addItem(pPolygonAnnotation);
47604760
} else if (shape.startsWith("Rectangle")) {
47614761
shape = shape.mid(QString("Rectangle").length());
4762-
shape = StringHandler::removeFirstLastBrackets(shape);
4762+
shape = StringHandler::removeFirstLastParentheses(shape);
47634763
RectangleAnnotation *pRectangleAnnotation = new RectangleAnnotation(shape, pGraphicsView);
47644764
pRectangleAnnotation->initializeTransformation();
47654765
pRectangleAnnotation->drawCornerItems();
@@ -4768,7 +4768,7 @@ void ModelWidget::getModelIconDiagramShapes(StringHandler::ViewType viewType)
47684768
pGraphicsView->addItem(pRectangleAnnotation);
47694769
} else if (shape.startsWith("Ellipse")) {
47704770
shape = shape.mid(QString("Ellipse").length());
4771-
shape = StringHandler::removeFirstLastBrackets(shape);
4771+
shape = StringHandler::removeFirstLastParentheses(shape);
47724772
EllipseAnnotation *pEllipseAnnotation = new EllipseAnnotation(shape, pGraphicsView);
47734773
pEllipseAnnotation->initializeTransformation();
47744774
pEllipseAnnotation->drawCornerItems();
@@ -4777,7 +4777,7 @@ void ModelWidget::getModelIconDiagramShapes(StringHandler::ViewType viewType)
47774777
pGraphicsView->addItem(pEllipseAnnotation);
47784778
} else if (shape.startsWith("Text")) {
47794779
shape = shape.mid(QString("Text").length());
4780-
shape = StringHandler::removeFirstLastBrackets(shape);
4780+
shape = StringHandler::removeFirstLastParentheses(shape);
47814781
TextAnnotation *pTextAnnotation = new TextAnnotation(shape, pGraphicsView);
47824782
pTextAnnotation->initializeTransformation();
47834783
pTextAnnotation->drawCornerItems();
@@ -4787,7 +4787,7 @@ void ModelWidget::getModelIconDiagramShapes(StringHandler::ViewType viewType)
47874787
} else if (shape.startsWith("Bitmap")) {
47884788
/* create the bitmap shape */
47894789
shape = shape.mid(QString("Bitmap").length());
4790-
shape = StringHandler::removeFirstLastBrackets(shape);
4790+
shape = StringHandler::removeFirstLastParentheses(shape);
47914791
BitmapAnnotation *pBitmapAnnotation = new BitmapAnnotation(mpLibraryTreeItem->mClassInformation.fileName, shape, pGraphicsView);
47924792
pBitmapAnnotation->initializeTransformation();
47934793
pBitmapAnnotation->drawCornerItems();
@@ -5036,10 +5036,10 @@ void ModelWidget::getModelTransitions()
50365036
foreach (QString shape, shapesList) {
50375037
if (shape.startsWith("Line")) {
50385038
lineShape = shape.mid(QString("Line").length());
5039-
lineShape = StringHandler::removeFirstLastBrackets(lineShape);
5039+
lineShape = StringHandler::removeFirstLastParentheses(lineShape);
50405040
} else if (shape.startsWith("Text")) {
50415041
textShape = shape.mid(QString("Text").length());
5042-
textShape = StringHandler::removeFirstLastBrackets(textShape);
5042+
textShape = StringHandler::removeFirstLastParentheses(textShape);
50435043
}
50445044
}
50455045
LineAnnotation *pTransitionLineAnnotation;
@@ -5077,7 +5077,7 @@ void ModelWidget::getModelInitialStates()
50775077
foreach (QString shape, shapesList) {
50785078
if (shape.startsWith("Line")) {
50795079
lineShape = shape.mid(QString("Line").length());
5080-
lineShape = StringHandler::removeFirstLastBrackets(lineShape);
5080+
lineShape = StringHandler::removeFirstLastParentheses(lineShape);
50815081
}
50825082
}
50835083
LineAnnotation *pInitialStateLineAnnotation;
@@ -5274,7 +5274,7 @@ void ModelWidget::getCompositeModelConnections()
52745274
foreach (QString shape, shapesList) {
52755275
if (shape.startsWith("Line")) {
52765276
lineShape = shape.mid(QString("Line").length());
5277-
lineShape = StringHandler::removeFirstLastBrackets(lineShape);
5277+
lineShape = StringHandler::removeFirstLastParentheses(lineShape);
52785278
break; // break the loop once we have got the line annotation.
52795279
}
52805280
}

OMEdit/OMEditGUI/OMC/OMCProxy.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2522,7 +2522,7 @@ QString OMCProxy::makeDocumentationUriToFileName(QString documentation)
25222522
QString OMCProxy::uriToFilename(QString uri)
25232523
{
25242524
sendCommand("uriToFilename(\"" + uri + "\")");
2525-
QString result = StringHandler::removeFirstLastBrackets(getResult());
2525+
QString result = StringHandler::removeFirstLastParentheses(getResult());
25262526
result = result.prepend("{").append("}");
25272527
QStringList results = StringHandler::unparseStrings(result);
25282528
/* the second argument of uriToFilename result is error string. */

OMEdit/OMEditGUI/Util/StringHandler.cpp

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -782,8 +782,12 @@ QString StringHandler::getTextStyleString(StringHandler::TextStyle textStyle)
782782
}
783783
}
784784

785-
//! Removes the first and last curly brackest {} from the string.
786-
//! @param value is the string which is parsed.
785+
/*!
786+
* \brief StringHandler::removeFirstLastCurlBrackets
787+
* Removes the first and last curly brackets {} from the string.
788+
* \param value is the string which is parsed.
789+
* \return
790+
*/
787791
QString StringHandler::removeFirstLastCurlBrackets(QString value)
788792
{
789793
value = value.trimmed();
@@ -793,9 +797,13 @@ QString StringHandler::removeFirstLastCurlBrackets(QString value)
793797
return value;
794798
}
795799

796-
//! Removes the first and last brackest () from the string.
797-
//! @param value is the string which is parsed.
798-
QString StringHandler::removeFirstLastBrackets(QString value)
800+
/*!
801+
* \brief StringHandler::removeFirstLastParentheses
802+
* Removes the first and last parentheses () from the string.
803+
* \param value is the string which is parsed.
804+
* \return
805+
*/
806+
QString StringHandler::removeFirstLastParentheses(QString value)
799807
{
800808
value = value.trimmed();
801809
if (value.length() > 1 && value.at(0) == '(' && value.at(value.length() - 1) == ')') {
@@ -804,6 +812,21 @@ QString StringHandler::removeFirstLastBrackets(QString value)
804812
return value;
805813
}
806814

815+
/*!
816+
* \brief StringHandler::removeFirstLastSquareBrackets
817+
* Removes the first and last sqaure brackets [] from the string.
818+
* \param value is the string which is parsed.
819+
* \return
820+
*/
821+
QString StringHandler::removeFirstLastSquareBrackets(QString value)
822+
{
823+
value = value.trimmed();
824+
if (value.length() > 1 && value.at(0) == '[' && value.at(value.length() - 1) == ']') {
825+
value = value.mid(1, (value.length() - 2));
826+
}
827+
return value;
828+
}
829+
807830
//! Removes the first and last quotes "" from the string.
808831
//! @param value is the string which is parsed.
809832
QString StringHandler::removeFirstLastQuotes(QString value)
@@ -1358,7 +1381,7 @@ QStringList StringHandler::getAnnotation(QString componentAnnotation, QString an
13581381
foreach (QString annotation, annotations) {
13591382
if (annotation.startsWith(annotationName)) {
13601383
annotation = annotation.mid(QString(annotationName).length());
1361-
annotation = StringHandler::removeFirstLastBrackets(annotation);
1384+
annotation = StringHandler::removeFirstLastParentheses(annotation);
13621385
if (annotation.toLower().contains("error")) {
13631386
return QStringList();
13641387
} else {
@@ -1378,7 +1401,7 @@ QString StringHandler::getPlacementAnnotation(QString componentAnnotation)
13781401
QStringList annotations = StringHandler::getStrings(componentAnnotation, '(', ')');
13791402
foreach (QString annotation, annotations) {
13801403
if (annotation.startsWith("Placement")) {
1381-
QString placementAnnotation = StringHandler::removeFirstLastBrackets(annotation);
1404+
QString placementAnnotation = StringHandler::removeFirstLastParentheses(annotation);
13821405
if (placementAnnotation.toLower().contains("error")) {
13831406
return "";
13841407
} else {

OMEdit/OMEditGUI/Util/StringHandler.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ class StringHandler : public QObject
107107
static QString getTextAlignmentString(StringHandler::TextAlignment alignment);
108108
static QString getTextStyleString(StringHandler::TextStyle textStyle);
109109
static QString removeFirstLastCurlBrackets(QString value);
110-
static QString removeFirstLastBrackets(QString value);
110+
static QString removeFirstLastParentheses(QString value);
111+
static QString removeFirstLastSquareBrackets(QString value);
111112
static QString removeFirstLastQuotes(QString value);
112113
static QString removeFirstLastSingleQuotes(QString value);
113114
static QStringList getStrings(QString value);

0 commit comments

Comments
 (0)