Skip to content

Commit

Permalink
ticket:4771 Use square brackets instead of curly brackets for dimension
Browse files Browse the repository at this point in the history
  • Loading branch information
adeas31 committed Feb 20, 2018
1 parent a45068d commit 86eb441
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 24 deletions.
8 changes: 5 additions & 3 deletions OMEdit/OMEditGUI/Component/ComponentProperties.cpp
Expand Up @@ -1299,7 +1299,7 @@ void ComponentAttributes::setUpDialog()
// dimensions
mpDimensionsLabel = new Label(tr("Dimensions:"));
mpDimensionsTextBox = new QLineEdit;
mpDimensionsTextBox->setToolTip(tr("Array of dimensions e.g {1, 5, 2}"));
mpDimensionsTextBox->setToolTip(tr("Array of dimensions e.g [1, 5, 2]"));
mpCommentLabel = new Label(Helper::comment);
mpCommentTextBox = new QLineEdit;
mpPathLabel = new Label(Helper::path);
Expand Down Expand Up @@ -1399,7 +1399,8 @@ void ComponentAttributes::initializeDialog()
mpNameTextBox->setText(mpComponent->getComponentInfo()->getName());
mpNameTextBox->setCursorPosition(0);
// get dimensions
mpDimensionsTextBox->setText(mpComponent->getComponentInfo()->getArrayIndex());
QString dimensions = StringHandler::removeFirstLastCurlBrackets(mpComponent->getComponentInfo()->getArrayIndex());
mpDimensionsTextBox->setText(QString("[%1]").arg(dimensions));
// get Comment
mpCommentTextBox->setText(mpComponent->getComponentInfo()->getComment());
mpCommentTextBox->setCursorPosition(0);
Expand Down Expand Up @@ -1505,7 +1506,8 @@ void ComponentAttributes::updateComponentAttributes()
newComponentInfo.setInner(mpInnerCheckBox->isChecked());
newComponentInfo.setOuter(mpOuterCheckBox->isChecked());
newComponentInfo.setCausality(causality);
newComponentInfo.setArrayIndex(mpDimensionsTextBox->text());
QString dimensions = StringHandler::removeFirstLastSquareBrackets(mpDimensionsTextBox->text());
newComponentInfo.setArrayIndex(QString("{%1}").arg(dimensions));
/* If user has really changed the Component's attributes then push that change on the stack.
*/
if (oldComponentInfo != newComponentInfo) {
Expand Down
2 changes: 1 addition & 1 deletion OMEdit/OMEditGUI/Component/Transformation.cpp
Expand Up @@ -96,7 +96,7 @@ void Transformation::parseTransformationString(QString value, qreal width, qreal
foreach (QString annotation, annotations) {
if (annotation.startsWith("Placement")) {
annotation = annotation.mid(QString("Placement").length());
annotation = StringHandler::removeFirstLastBrackets(annotation);
annotation = StringHandler::removeFirstLastParentheses(annotation);
QStringList list = StringHandler::getStrings(annotation);
// get transformations of diagram
// get the visible value
Expand Down
22 changes: 11 additions & 11 deletions OMEdit/OMEditGUI/Modeling/ModelWidgetContainer.cpp
Expand Up @@ -3296,7 +3296,7 @@ void ModelWidget::getModelConnections()
foreach (QString shape, shapesList) {
if (shape.startsWith("Line")) {
lineShape = shape.mid(QString("Line").length());
lineShape = StringHandler::removeFirstLastBrackets(lineShape);
lineShape = StringHandler::removeFirstLastParentheses(lineShape);
break; // break the loop once we have got the line annotation.
}
}
Expand Down Expand Up @@ -4741,7 +4741,7 @@ void ModelWidget::getModelIconDiagramShapes(StringHandler::ViewType viewType)
foreach (QString shape, shapesList) {
if (shape.startsWith("Line")) {
shape = shape.mid(QString("Line").length());
shape = StringHandler::removeFirstLastBrackets(shape);
shape = StringHandler::removeFirstLastParentheses(shape);
LineAnnotation *pLineAnnotation = new LineAnnotation(shape, pGraphicsView);
pLineAnnotation->initializeTransformation();
pLineAnnotation->drawCornerItems();
Expand All @@ -4750,7 +4750,7 @@ void ModelWidget::getModelIconDiagramShapes(StringHandler::ViewType viewType)
pGraphicsView->addItem(pLineAnnotation);
} else if (shape.startsWith("Polygon")) {
shape = shape.mid(QString("Polygon").length());
shape = StringHandler::removeFirstLastBrackets(shape);
shape = StringHandler::removeFirstLastParentheses(shape);
PolygonAnnotation *pPolygonAnnotation = new PolygonAnnotation(shape, pGraphicsView);
pPolygonAnnotation->initializeTransformation();
pPolygonAnnotation->drawCornerItems();
Expand All @@ -4759,7 +4759,7 @@ void ModelWidget::getModelIconDiagramShapes(StringHandler::ViewType viewType)
pGraphicsView->addItem(pPolygonAnnotation);
} else if (shape.startsWith("Rectangle")) {
shape = shape.mid(QString("Rectangle").length());
shape = StringHandler::removeFirstLastBrackets(shape);
shape = StringHandler::removeFirstLastParentheses(shape);
RectangleAnnotation *pRectangleAnnotation = new RectangleAnnotation(shape, pGraphicsView);
pRectangleAnnotation->initializeTransformation();
pRectangleAnnotation->drawCornerItems();
Expand All @@ -4768,7 +4768,7 @@ void ModelWidget::getModelIconDiagramShapes(StringHandler::ViewType viewType)
pGraphicsView->addItem(pRectangleAnnotation);
} else if (shape.startsWith("Ellipse")) {
shape = shape.mid(QString("Ellipse").length());
shape = StringHandler::removeFirstLastBrackets(shape);
shape = StringHandler::removeFirstLastParentheses(shape);
EllipseAnnotation *pEllipseAnnotation = new EllipseAnnotation(shape, pGraphicsView);
pEllipseAnnotation->initializeTransformation();
pEllipseAnnotation->drawCornerItems();
Expand All @@ -4777,7 +4777,7 @@ void ModelWidget::getModelIconDiagramShapes(StringHandler::ViewType viewType)
pGraphicsView->addItem(pEllipseAnnotation);
} else if (shape.startsWith("Text")) {
shape = shape.mid(QString("Text").length());
shape = StringHandler::removeFirstLastBrackets(shape);
shape = StringHandler::removeFirstLastParentheses(shape);
TextAnnotation *pTextAnnotation = new TextAnnotation(shape, pGraphicsView);
pTextAnnotation->initializeTransformation();
pTextAnnotation->drawCornerItems();
Expand All @@ -4787,7 +4787,7 @@ void ModelWidget::getModelIconDiagramShapes(StringHandler::ViewType viewType)
} else if (shape.startsWith("Bitmap")) {
/* create the bitmap shape */
shape = shape.mid(QString("Bitmap").length());
shape = StringHandler::removeFirstLastBrackets(shape);
shape = StringHandler::removeFirstLastParentheses(shape);
BitmapAnnotation *pBitmapAnnotation = new BitmapAnnotation(mpLibraryTreeItem->mClassInformation.fileName, shape, pGraphicsView);
pBitmapAnnotation->initializeTransformation();
pBitmapAnnotation->drawCornerItems();
Expand Down Expand Up @@ -5036,10 +5036,10 @@ void ModelWidget::getModelTransitions()
foreach (QString shape, shapesList) {
if (shape.startsWith("Line")) {
lineShape = shape.mid(QString("Line").length());
lineShape = StringHandler::removeFirstLastBrackets(lineShape);
lineShape = StringHandler::removeFirstLastParentheses(lineShape);
} else if (shape.startsWith("Text")) {
textShape = shape.mid(QString("Text").length());
textShape = StringHandler::removeFirstLastBrackets(textShape);
textShape = StringHandler::removeFirstLastParentheses(textShape);
}
}
LineAnnotation *pTransitionLineAnnotation;
Expand Down Expand Up @@ -5077,7 +5077,7 @@ void ModelWidget::getModelInitialStates()
foreach (QString shape, shapesList) {
if (shape.startsWith("Line")) {
lineShape = shape.mid(QString("Line").length());
lineShape = StringHandler::removeFirstLastBrackets(lineShape);
lineShape = StringHandler::removeFirstLastParentheses(lineShape);
}
}
LineAnnotation *pInitialStateLineAnnotation;
Expand Down Expand Up @@ -5274,7 +5274,7 @@ void ModelWidget::getCompositeModelConnections()
foreach (QString shape, shapesList) {
if (shape.startsWith("Line")) {
lineShape = shape.mid(QString("Line").length());
lineShape = StringHandler::removeFirstLastBrackets(lineShape);
lineShape = StringHandler::removeFirstLastParentheses(lineShape);
break; // break the loop once we have got the line annotation.
}
}
Expand Down
2 changes: 1 addition & 1 deletion OMEdit/OMEditGUI/OMC/OMCProxy.cpp
Expand Up @@ -2522,7 +2522,7 @@ QString OMCProxy::makeDocumentationUriToFileName(QString documentation)
QString OMCProxy::uriToFilename(QString uri)
{
sendCommand("uriToFilename(\"" + uri + "\")");
QString result = StringHandler::removeFirstLastBrackets(getResult());
QString result = StringHandler::removeFirstLastParentheses(getResult());
result = result.prepend("{").append("}");
QStringList results = StringHandler::unparseStrings(result);
/* the second argument of uriToFilename result is error string. */
Expand Down
37 changes: 30 additions & 7 deletions OMEdit/OMEditGUI/Util/StringHandler.cpp
Expand Up @@ -782,8 +782,12 @@ QString StringHandler::getTextStyleString(StringHandler::TextStyle textStyle)
}
}

//! Removes the first and last curly brackest {} from the string.
//! @param value is the string which is parsed.
/*!
* \brief StringHandler::removeFirstLastCurlBrackets
* Removes the first and last curly brackets {} from the string.
* \param value is the string which is parsed.
* \return
*/
QString StringHandler::removeFirstLastCurlBrackets(QString value)
{
value = value.trimmed();
Expand All @@ -793,9 +797,13 @@ QString StringHandler::removeFirstLastCurlBrackets(QString value)
return value;
}

//! Removes the first and last brackest () from the string.
//! @param value is the string which is parsed.
QString StringHandler::removeFirstLastBrackets(QString value)
/*!
* \brief StringHandler::removeFirstLastParentheses
* Removes the first and last parentheses () from the string.
* \param value is the string which is parsed.
* \return
*/
QString StringHandler::removeFirstLastParentheses(QString value)
{
value = value.trimmed();
if (value.length() > 1 && value.at(0) == '(' && value.at(value.length() - 1) == ')') {
Expand All @@ -804,6 +812,21 @@ QString StringHandler::removeFirstLastBrackets(QString value)
return value;
}

/*!
* \brief StringHandler::removeFirstLastSquareBrackets
* Removes the first and last sqaure brackets [] from the string.
* \param value is the string which is parsed.
* \return
*/
QString StringHandler::removeFirstLastSquareBrackets(QString value)
{
value = value.trimmed();
if (value.length() > 1 && value.at(0) == '[' && value.at(value.length() - 1) == ']') {
value = value.mid(1, (value.length() - 2));
}
return value;
}

//! Removes the first and last quotes "" from the string.
//! @param value is the string which is parsed.
QString StringHandler::removeFirstLastQuotes(QString value)
Expand Down Expand Up @@ -1358,7 +1381,7 @@ QStringList StringHandler::getAnnotation(QString componentAnnotation, QString an
foreach (QString annotation, annotations) {
if (annotation.startsWith(annotationName)) {
annotation = annotation.mid(QString(annotationName).length());
annotation = StringHandler::removeFirstLastBrackets(annotation);
annotation = StringHandler::removeFirstLastParentheses(annotation);
if (annotation.toLower().contains("error")) {
return QStringList();
} else {
Expand All @@ -1378,7 +1401,7 @@ QString StringHandler::getPlacementAnnotation(QString componentAnnotation)
QStringList annotations = StringHandler::getStrings(componentAnnotation, '(', ')');
foreach (QString annotation, annotations) {
if (annotation.startsWith("Placement")) {
QString placementAnnotation = StringHandler::removeFirstLastBrackets(annotation);
QString placementAnnotation = StringHandler::removeFirstLastParentheses(annotation);
if (placementAnnotation.toLower().contains("error")) {
return "";
} else {
Expand Down
3 changes: 2 additions & 1 deletion OMEdit/OMEditGUI/Util/StringHandler.h
Expand Up @@ -107,7 +107,8 @@ class StringHandler : public QObject
static QString getTextAlignmentString(StringHandler::TextAlignment alignment);
static QString getTextStyleString(StringHandler::TextStyle textStyle);
static QString removeFirstLastCurlBrackets(QString value);
static QString removeFirstLastBrackets(QString value);
static QString removeFirstLastParentheses(QString value);
static QString removeFirstLastSquareBrackets(QString value);
static QString removeFirstLastQuotes(QString value);
static QString removeFirstLastSingleQuotes(QString value);
static QStringList getStrings(QString value);
Expand Down

0 comments on commit 86eb441

Please sign in to comment.