diff --git a/OMEdit/OMEditGUI/Annotations/BitmapAnnotation.cpp b/OMEdit/OMEditGUI/Annotations/BitmapAnnotation.cpp index 005fada1c06..79554e52ebd 100644 --- a/OMEdit/OMEditGUI/Annotations/BitmapAnnotation.cpp +++ b/OMEdit/OMEditGUI/Annotations/BitmapAnnotation.cpp @@ -101,8 +101,10 @@ void BitmapAnnotation::parseShapeAnnotation(QString annotation) } if (!mImageSource.isEmpty()) { mImage.loadFromData(QByteArray::fromBase64(mImageSource.toLatin1())); - } else { + } else if (!mFileName.isEmpty()) { mImage.load(mFileName); + } else { + mImage = QImage(":/Resources/icons/bitmap-shape.svg"); } } diff --git a/OMEdit/OMEditGUI/Annotations/ShapeAnnotation.cpp b/OMEdit/OMEditGUI/Annotations/ShapeAnnotation.cpp index aa7142f7a12..465f14537b9 100644 --- a/OMEdit/OMEditGUI/Annotations/ShapeAnnotation.cpp +++ b/OMEdit/OMEditGUI/Annotations/ShapeAnnotation.cpp @@ -566,8 +566,9 @@ QString ShapeAnnotation::getShapeAnnotation() } /*! - Initializes the transformation matrix with the default transformation values of the shape. - */ + * \brief ShapeAnnotation::initializeTransformation + * Initializes the transformation matrix with the default transformation values of the shape. + */ void ShapeAnnotation::initializeTransformation() { mTransformation.setOrigin(mOrigin); @@ -578,11 +579,12 @@ void ShapeAnnotation::initializeTransformation() } /*! - Draws the CornerItem around the shape.\n - If the shape is LineAnnotation or PolygonAnnotation then their points are used to draw CornerItem's.\n - If the shape is RectangleAnnotation, EllipseAnnotation, TextAnnotation or BitmapAnnotation - then their extents are used to draw CornerItem's. - */ + * \brief ShapeAnnotation::drawCornerItems + * Draws the CornerItem around the shape.\n + * If the shape is LineAnnotation or PolygonAnnotation then their points are used to draw CornerItem's.\n + * If the shape is RectangleAnnotation, EllipseAnnotation, TextAnnotation or BitmapAnnotation + * then their extents are used to draw CornerItem's. + */ void ShapeAnnotation::drawCornerItems() { if (dynamic_cast(this) || dynamic_cast(this)) { @@ -627,205 +629,42 @@ void ShapeAnnotation::setCornerItemsActiveOrPassive() } /*! - Removes the CornerItem's around the shape. - */ + * \brief ShapeAnnotation::removeCornerItems + * Removes the CornerItem's around the shape. + */ void ShapeAnnotation::removeCornerItems() { - foreach (CornerItem *pCornerItem, mCornerItemsList) - { + foreach (CornerItem *pCornerItem, mCornerItemsList) { pCornerItem->deleteLater(); } mCornerItemsList.clear(); } /*! - Adds the extent point value. - \param index - the index of extent point. - \param point - the point value to add. - */ + * \brief ShapeAnnotation::replaceExtent + * Adds the extent point value. + * \param index - the index of extent point. + * \param point - the point value to add. + */ void ShapeAnnotation::replaceExtent(int index, QPointF point) { - if (index >= 0 && index <= 1) - { + if (index >= 0 && index <= 1) { mExtents.replace(index, point); } } /*! - Returns the GraphicsView object. - \return the pointer to GraphicsView. - */ + * \brief ShapeAnnotation::updateEndExtent + * Updates the end extent point. + * \param point + */ void ShapeAnnotation::updateEndExtent(QPointF point) { - if (mExtents.size() > 1) - { + if (mExtents.size() > 1) { mExtents.replace(1, point); } } -/*! - Sets the start arrow value. - \return startArrow - the start arrow value. - */ -void ShapeAnnotation::setStartArrow(StringHandler::Arrow startArrow) -{ - mArrow.replace(0, startArrow); -} - -/*! - Returns the start arrow value. - \return the start arrow value. - */ -StringHandler::Arrow ShapeAnnotation::getStartArrow() -{ - return mArrow.at(0); -} - -/*! - Sets the end arrow value. - \return endArrow - the end arrow value. - */ -void ShapeAnnotation::setEndArrow(StringHandler::Arrow endArrow) -{ - mArrow.replace(1, endArrow); -} - -/*! - Returns the end arrow value. - \return the end arrow value. - */ -StringHandler::Arrow ShapeAnnotation::getEndArrow() -{ - return mArrow.at(1); -} - -/*! - Sets the arrow size. - \return arrowSize - the arrow size. - */ -void ShapeAnnotation::setArrowSize(qreal arrowSize) -{ - mArrowSize = arrowSize; -} - -/*! - Returns the arrow size value. - \return the arrow size value. - */ -qreal ShapeAnnotation::getArrowSize() -{ - return mArrowSize; -} - -/*! - Sets the smooth value. - \return smooth - the smooth value. - */ -void ShapeAnnotation::setSmooth(StringHandler::Smooth smooth) -{ - mSmooth = smooth; -} - - -/*! - Returns the smooth value. - \return the smooth value. - */ -StringHandler::Smooth ShapeAnnotation::getSmooth() -{ - return mSmooth; -} - -/*! - Sets the extents list. - \param extents - the extents list. - */ -void ShapeAnnotation::setExtents(QList extents) -{ - mExtents = extents; -} - -/*! - Returns the points list. - \return the points list. - */ -QList ShapeAnnotation::getExtents() -{ - return mExtents; -} - -/*! - Sets the border pattern value. - \param pattern - the border pattern. - */ -void ShapeAnnotation::setBorderPattern(StringHandler::BorderPattern pattern) -{ - mBorderPattern = pattern; -} - -/*! - Returns the border pattern value. - \return the border pattern value. - */ -StringHandler::BorderPattern ShapeAnnotation::getBorderPattern() -{ - return mBorderPattern; -} - -/*! - Sets the corner radius size. - \return radius - the corner radius. - */ -void ShapeAnnotation::setRadius(qreal radius) -{ - mRadius = radius; -} - -/*! - Returns the corner radius value. - \return the corner radius. - */ -qreal ShapeAnnotation::getRadius() -{ - return mRadius; -} - -/*! - Sets the start angle. - \return startAngle - the start angle. - */ -void ShapeAnnotation::setStartAngle(qreal startAngle) -{ - mStartAngle = startAngle; -} - -/*! - Returns the start angle. - \return the start angle. - */ -qreal ShapeAnnotation::getStartAngle() -{ - return mStartAngle; -} - -/*! - Sets the end angle. - \return endAngle - the end angle. - */ -void ShapeAnnotation::setEndAngle(qreal endAngle) -{ - mEndAngle = endAngle; -} - -/*! - Returns the end angle. - \return the end angle. - */ -qreal ShapeAnnotation::getEndAngle() -{ - return mEndAngle; -} - /*! Sets the text string. \return textString - the string to set. @@ -837,107 +676,24 @@ void ShapeAnnotation::setTextString(QString textString) } /*! - Returns the text string. - \return the text string. - */ -QString ShapeAnnotation::getTextString() -{ - return mOriginalTextString; -} - -/*! - Sets the font name. - \return fontName - the font name. - */ -void ShapeAnnotation::setFontName(QString fontName) -{ - mFontName = fontName; -} - -/*! - Returns the font name. - \return the font name. - */ -QString ShapeAnnotation::getFontName() -{ - return mFontName; -} - -/*! - Sets the font size. - \return fontSize - the font size. - */ -void ShapeAnnotation::setFontSize(qreal fontSize) -{ - mFontSize = fontSize; -} - -/*! - Returns the font size. - \return the font size. - */ -qreal ShapeAnnotation::getFontSize() -{ - return mFontSize; -} - -/*! - Sets the text styles. - \return textStyles - the text styles. - */ -void ShapeAnnotation::setTextStyles(QList textStyles) -{ - mTextStyles = textStyles; -} - -/*! - Returns the text styles. - \return the text styles. - */ -QList ShapeAnnotation::getTextStyles() -{ - return mTextStyles; -} - -/*! - Sets the text horizontal alignment. - \return textStyles - the text horizontal alignment. - */ -void ShapeAnnotation::setTextHorizontalAlignment(StringHandler::TextAlignment textAlignment) -{ - mHorizontalAlignment = textAlignment; -} - -/*! - Returns the text horizontal alignment. - \return the text horizontal alignment. - */ -StringHandler::TextAlignment ShapeAnnotation::getTextHorizontalAlignment() -{ - return mHorizontalAlignment; -} - -/*! - Sets the file name. - \return fileName - the file name to set. - */ + * \brief ShapeAnnotation::setFileName + * Sets the file name. + * \param fileName + * \param pComponent + */ void ShapeAnnotation::setFileName(QString fileName, Component *pComponent) { - if (fileName.isEmpty()) - { + if (fileName.isEmpty()) { mOriginalFileName = fileName; mFileName = fileName; return; } OMCProxy *pOMCProxy = 0; - if (pComponent) - { + if (pComponent) { pOMCProxy = pComponent->getGraphicsView()->getModelWidget()->getModelWidgetContainer()->getMainWindow()->getOMCProxy(); - } - else - { - pOMCProxy = mpGraphicsView->getModelWidget()->getModelWidgetContainer()->getMainWindow()->getOMCProxy(); + } else { + pOMCProxy = mpGraphicsView->getModelWidget()->getModelWidgetContainer()->getMainWindow()->getOMCProxy(); } mOriginalFileName = fileName; @@ -946,20 +702,13 @@ void ShapeAnnotation::setFileName(QString fileName, Component *pComponent) QFileInfo classFileInfo(mClassFileName); /* if its a modelica:// link then make it absolute path */ - if (fileUrl.scheme().toLower().compare("modelica") == 0) - { + if (fileUrl.scheme().toLower().compare("modelica") == 0) { mFileName = pOMCProxy->uriToFilename(mOriginalFileName); - } - else if (fileInfo.isRelative()) - { + } else if (fileInfo.isRelative()) { mFileName = QString(classFileInfo.absoluteDir().absolutePath()).append("/").append(mOriginalFileName); - } - else if (fileInfo.isAbsolute()) - { + } else if (fileInfo.isAbsolute()) { mFileName = mOriginalFileName; - } - else - { + } else { mFileName = ""; } } @@ -1701,12 +1450,14 @@ bool ShapeAnnotation::isLineStraight(QPointF point1, QPointF point2) } /*! - Slot activated when Properties option is choosen from context menu of the shape. - */ + * \brief ShapeAnnotation::showShapeProperties + * Slot activated when Properties option is choosen from context menu of the shape. + */ void ShapeAnnotation::showShapeProperties() { - if (!mpGraphicsView || mpGraphicsView->getModelWidget()->getLibraryTreeItem()->getLibraryType()== LibraryTreeItem::TLM) + if (!mpGraphicsView || mpGraphicsView->getModelWidget()->getLibraryTreeItem()->getLibraryType()== LibraryTreeItem::TLM) { return; + } MainWindow *pMainWindow = mpGraphicsView->getModelWidget()->getModelWidgetContainer()->getMainWindow(); ShapePropertiesDialog *pShapePropertiesDialog = new ShapePropertiesDialog(this, pMainWindow); pShapePropertiesDialog->exec(); diff --git a/OMEdit/OMEditGUI/Annotations/ShapeAnnotation.h b/OMEdit/OMEditGUI/Annotations/ShapeAnnotation.h index d021ad542fc..3ef7a3b84cb 100644 --- a/OMEdit/OMEditGUI/Annotations/ShapeAnnotation.h +++ b/OMEdit/OMEditGUI/Annotations/ShapeAnnotation.h @@ -144,34 +144,34 @@ class ShapeAnnotation : public QObject, public QGraphicsItem, public GraphicItem GraphicsView* getGraphicsView() {return mpGraphicsView;} void setPoints(QList points) {mPoints = points;} QList getPoints() {return mPoints;} - void setStartArrow(StringHandler::Arrow startArrow); - StringHandler::Arrow getStartArrow(); - void setEndArrow(StringHandler::Arrow endArrow); - StringHandler::Arrow getEndArrow(); - void setArrowSize(qreal arrowSize); - qreal getArrowSize(); - void setSmooth(StringHandler::Smooth smooth); - StringHandler::Smooth getSmooth(); - void setExtents(QList extents); - QList getExtents(); - void setBorderPattern(StringHandler::BorderPattern pattern); - StringHandler::BorderPattern getBorderPattern(); - void setRadius(qreal radius); - qreal getRadius(); - void setStartAngle(qreal startAngle); - qreal getStartAngle(); - void setEndAngle(qreal endAngle); - qreal getEndAngle(); + void setStartArrow(StringHandler::Arrow startArrow) {mArrow.replace(0, startArrow);} + StringHandler::Arrow getStartArrow() {return mArrow.at(0);} + void setEndArrow(StringHandler::Arrow endArrow) {mArrow.replace(1, endArrow);} + StringHandler::Arrow getEndArrow() {return mArrow.at(1);} + void setArrowSize(qreal arrowSize) {mArrowSize = arrowSize;} + qreal getArrowSize() {return mArrowSize;} + void setSmooth(StringHandler::Smooth smooth) {mSmooth = smooth;} + StringHandler::Smooth getSmooth() {return mSmooth;} + void setExtents(QList extents) {mExtents = extents;} + QList getExtents() {return mExtents;} + void setBorderPattern(StringHandler::BorderPattern pattern) {mBorderPattern = pattern;} + StringHandler::BorderPattern getBorderPattern() {return mBorderPattern;} + void setRadius(qreal radius) {mRadius = radius;} + qreal getRadius() {return mRadius;} + void setStartAngle(qreal startAngle) {mStartAngle = startAngle;} + qreal getStartAngle() {return mStartAngle;} + void setEndAngle(qreal endAngle) {mEndAngle = endAngle;} + qreal getEndAngle() {return mEndAngle;} void setTextString(QString textString); - QString getTextString(); - void setFontName(QString fontName); - QString getFontName(); - void setFontSize(qreal fontSize); - qreal getFontSize(); - void setTextStyles(QList textStyles); - QList getTextStyles(); - void setTextHorizontalAlignment(StringHandler::TextAlignment textAlignment); - StringHandler::TextAlignment getTextHorizontalAlignment(); + QString getTextString() {return mOriginalTextString;} + void setFontName(QString fontName) {mFontName = fontName;} + QString getFontName() {return mFontName;} + void setFontSize(qreal fontSize) {mFontSize = fontSize;} + qreal getFontSize() {return mFontSize;} + void setTextStyles(QList textStyles) {mTextStyles = textStyles;} + QList getTextStyles() {return mTextStyles;} + void setTextHorizontalAlignment(StringHandler::TextAlignment textAlignment) {mHorizontalAlignment = textAlignment;} + StringHandler::TextAlignment getTextHorizontalAlignment() {return mHorizontalAlignment;} void setFileName(QString fileName, Component *pComponent = 0); QString getFileName(); void setImageSource(QString imageSource); diff --git a/OMEdit/OMEditGUI/Annotations/ShapePropertiesDialog.cpp b/OMEdit/OMEditGUI/Annotations/ShapePropertiesDialog.cpp index 0eb1986ac9f..7255719b78e 100644 --- a/OMEdit/OMEditGUI/Annotations/ShapePropertiesDialog.cpp +++ b/OMEdit/OMEditGUI/Annotations/ShapePropertiesDialog.cpp @@ -481,7 +481,6 @@ ShapePropertiesDialog::ShapePropertiesDialog(ShapeAnnotation *pShapeAnnotation, pMainLayout->addWidget(mpFontAndTextStyleGroupBox, row++, 0, 1, colSpan); } if (mpBitmapAnnotation) { - pMainLayout->addWidget(mpLineStyleGroupBox, row++, 0, 1, colSpan); pMainLayout->addWidget(mpImageGroupBox, row++, 0, 1, colSpan); } else { pMainLayout->addWidget(mpLineStyleGroupBox, row, 0); @@ -877,7 +876,7 @@ void ShapePropertiesDialog::storeImageInModelToggled(bool checked) */ if (!checked) { MainWindow *pMainWindow = mpBitmapAnnotation->getGraphicsView()->getModelWidget()->getModelWidgetContainer()->getMainWindow(); - if (mpBitmapAnnotation->getGraphicsView()->getModelWidget()->getLibraryTreeItem()->getFileName().isEmpty()) { + if (!mpBitmapAnnotation->getGraphicsView()->getModelWidget()->getLibraryTreeItem()->isFilePathValid()) { if (pMainWindow->getOptionsDialog()->getNotificationsPage()->getSaveModelForBitmapInsertionCheckBox()->isChecked()) { NotificationsDialog *pNotificationsDialog = new NotificationsDialog(NotificationsDialog::SaveModelForBitmapInsertion, NotificationsDialog::InformationIcon, diff --git a/OMEdit/OMEditGUI/Modeling/ModelWidgetContainer.cpp b/OMEdit/OMEditGUI/Modeling/ModelWidgetContainer.cpp index ef668aef523..e9e31ee6209 100644 --- a/OMEdit/OMEditGUI/Modeling/ModelWidgetContainer.cpp +++ b/OMEdit/OMEditGUI/Modeling/ModelWidgetContainer.cpp @@ -827,7 +827,6 @@ void GraphicsView::createTextShape(QPointF point) mpTextShapeAnnotation->initializeTransformation(); // draw corner items for the text shape mpTextShapeAnnotation->drawCornerItems(); - mpTextShapeAnnotation->setSelected(true); // make the toolbar button of text unchecked pMainWindow->getTextShapeAction()->setChecked(false); pMainWindow->getConnectModeAction()->setChecked(true); @@ -835,6 +834,7 @@ void GraphicsView::createTextShape(QPointF point) mpModelWidget->updateClassAnnotationIfNeeded(); mpModelWidget->updateModelicaText(); mpTextShapeAnnotation->showShapeProperties(); + mpTextShapeAnnotation->setSelected(true); } } @@ -861,17 +861,14 @@ void GraphicsView::createBitmapShape(QPointF point) mpBitmapShapeAnnotation->initializeTransformation(); // draw corner items for the bitmap shape mpBitmapShapeAnnotation->drawCornerItems(); - mpBitmapShapeAnnotation->setSelected(true); - ShapePropertiesDialog *pShapePropertiesDialog; - pShapePropertiesDialog = new ShapePropertiesDialog(mpBitmapShapeAnnotation, mpModelWidget->getModelWidgetContainer()->getMainWindow()); - if (!pShapePropertiesDialog->exec()) { - /* if user cancels the bitmap shape properties then remove the bitmap shape from the scene */ - deleteShapeFromList(mpBitmapShapeAnnotation); - mpBitmapShapeAnnotation->deleteLater(); - } // make the toolbar button of text unchecked pMainWindow->getBitmapShapeAction()->setChecked(false); pMainWindow->getConnectModeAction()->setChecked(true); + mpModelWidget->getLibraryTreeItem()->emitShapeAdded(mpBitmapShapeAnnotation, this); + mpModelWidget->updateClassAnnotationIfNeeded(); + mpModelWidget->updateModelicaText(); + mpBitmapShapeAnnotation->showShapeProperties(); + mpBitmapShapeAnnotation->setSelected(true); } } @@ -1499,9 +1496,11 @@ void GraphicsView::mousePressEvent(QMouseEvent *event) } else if (pMainWindow->getTextShapeAction()->isChecked()) { /* if text shape tool button is checked then create a text */ createTextShape(snappedPoint); + eventConsumed = true; } else if (pMainWindow->getBitmapShapeAction()->isChecked()) { /* if bitmap shape tool button is checked then create a bitmap */ createBitmapShape(snappedPoint); + eventConsumed = true; } else if (dynamic_cast(itemAt(event->pos()))) { // do nothing if resizer item is clicked. It will be handled in its class mousePressEvent(); } else { diff --git a/OMEdit/OMEditGUI/Util/Helper.cpp b/OMEdit/OMEditGUI/Util/Helper.cpp index 4927e27f167..020ba4aa132 100644 --- a/OMEdit/OMEditGUI/Util/Helper.cpp +++ b/OMEdit/OMEditGUI/Util/Helper.cpp @@ -53,7 +53,7 @@ QString Helper::omFileTypes = "Modelica Files (*.mo)"; QString Helper::omnotebookFileTypes = "OMNotebook Files (*.onb *.onbz *.nb)"; QString Helper::ngspiceNetlistFileTypes = "ngspice Netlist Files (*.cir *.sp *.spice)"; QString Helper::imageFileTypes = "SVG (*.svg);;PNG image (*.png);;Windows BMP image (*.bmp);;TIFF (*.tiff)"; -QString Helper::bitmapFileTypes = "PNG image (*.png);;Windows BMP image (*.bmp);;JPEG (*.jpg *.jpeg)"; +QString Helper::bitmapFileTypes = "PNG image (*.png);Windows BMP image (*.bmp);JPEG (*.jpg *.jpeg)"; QString Helper::fmuFileTypes = "FMU Files (*.fmu)"; QString Helper::xmlFileTypes = "XML Files (*.xml)"; QString Helper::infoXmlFileTypes = "OM Info Files (*_info.xml *_info.json)";