Skip to content

Commit

Permalink
Merge pull request #3 from adeas31/indentation
Browse files Browse the repository at this point in the history
Improved OMEdit
  • Loading branch information
adeas31 committed Dec 4, 2015
2 parents b1c9a9e + d19f45a commit 53f5b7b
Show file tree
Hide file tree
Showing 87 changed files with 13,065 additions and 8,192 deletions.
128 changes: 90 additions & 38 deletions OMEdit/OMEditGUI/Annotations/BitmapAnnotation.cpp
Expand Up @@ -37,63 +37,74 @@
*/

#include "BitmapAnnotation.h"
#include "Commands.h"

BitmapAnnotation::BitmapAnnotation(QString classFileName, QString annotation, Component *pParent)
: ShapeAnnotation(pParent), mpComponent(pParent)
BitmapAnnotation::BitmapAnnotation(QString classFileName, QString annotation, GraphicsView *pGraphicsView)
: ShapeAnnotation(false, pGraphicsView, 0)
{
mpComponent = 0;
mClassFileName = classFileName;
// set the default values
GraphicItem::setDefaults();
ShapeAnnotation::setDefaults();
// set users default value by reading the settings file.
ShapeAnnotation::setUserDefaults();
parseShapeAnnotation(annotation);
setShapeFlags(true);
}

BitmapAnnotation::BitmapAnnotation(ShapeAnnotation *pShapeAnnotation, Component *pParent)
: ShapeAnnotation(pParent), mpComponent(pParent)
{
updateShape(pShapeAnnotation);
setPos(mOrigin);
setRotation(mRotation);
connect(pShapeAnnotation, SIGNAL(updateReferenceShapes()), pShapeAnnotation, SIGNAL(changed()));
connect(pShapeAnnotation, SIGNAL(added()), this, SLOT(referenceShapeAdded()));
connect(pShapeAnnotation, SIGNAL(changed()), this, SLOT(referenceShapeChanged()));
connect(pShapeAnnotation, SIGNAL(deleted()), this, SLOT(referenceShapeDeleted()));
}

BitmapAnnotation::BitmapAnnotation(QString classFileName, QString annotation, bool inheritedShape, GraphicsView *pGraphicsView)
: ShapeAnnotation(inheritedShape, pGraphicsView, 0)
BitmapAnnotation::BitmapAnnotation(ShapeAnnotation *pShapeAnnotation, GraphicsView *pGraphicsView)
: ShapeAnnotation(true, pGraphicsView, 0)
{
mpComponent = 0;
mClassFileName = classFileName;
// set the default values
GraphicItem::setDefaults();
ShapeAnnotation::setDefaults();
// set users default value by reading the settings file.
ShapeAnnotation::setUserDefaults();
parseShapeAnnotation(annotation);
updateShape(pShapeAnnotation);
setShapeFlags(true);
mpGraphicsView->addShapeObject(this);
mpGraphicsView->scene()->addItem(this);
connect(this, SIGNAL(updateClassAnnotation()), mpGraphicsView, SLOT(addClassAnnotation()));
mpGraphicsView->addItem(this);
connect(pShapeAnnotation, SIGNAL(updateReferenceShapes()), pShapeAnnotation, SIGNAL(changed()));
connect(pShapeAnnotation, SIGNAL(added()), this, SLOT(referenceShapeAdded()));
connect(pShapeAnnotation, SIGNAL(changed()), this, SLOT(referenceShapeChanged()));
connect(pShapeAnnotation, SIGNAL(deleted()), this, SLOT(referenceShapeDeleted()));
}

void BitmapAnnotation::parseShapeAnnotation(QString annotation)
{
GraphicItem::parseShapeAnnotation(annotation);
// parse the shape to get the list of attributes of Bitmap.
QStringList list = StringHandler::getStrings(annotation);
if (list.size() < 5)
if (list.size() < 5) {
return;
}
// 4th item is the extent points
QStringList extentsList = StringHandler::getStrings(StringHandler::removeFirstLastCurlBrackets(list.at(3)));
for (int i = 0 ; i < qMin(extentsList.size(), 2) ; i++)
{
for (int i = 0 ; i < qMin(extentsList.size(), 2) ; i++) {
QStringList extentPoints = StringHandler::getStrings(StringHandler::removeFirstLastCurlBrackets(extentsList[i]));
if (extentPoints.size() >= 2)
mExtents.replace(i, QPointF(extentPoints.at(0).toFloat(), extentPoints.at(1).toFloat()));
}
// 5th item is the fileName
setFileName(StringHandler::removeFirstLastQuotes(list.at(4)), mpComponent);
// 6th item is the imageSource
if (list.size() >= 6)
if (list.size() >= 6) {
mImageSource = StringHandler::removeFirstLastQuotes(list.at(5));
if (!mImageSource.isEmpty())
{
mImage.loadFromData(QByteArray::fromBase64(mImageSource.toLatin1()));
}
else
{
if (!mImageSource.isEmpty()) {
mImage.loadFromData(QByteArray::fromBase64(mImageSource.toLatin1()));
} else if (!mFileName.isEmpty()) {
mImage.load(mFileName);
} else {
mImage = QImage(":/Resources/icons/bitmap-shape.svg");
}
}

Expand Down Expand Up @@ -122,13 +133,42 @@ void BitmapAnnotation::drawBitmapAnnotaion(QPainter *painter)
painter->drawImage(getBoundingRect(), mImage.mirrored());
}

/*!
* \brief BitmapAnnotation::getOMCShapeAnnotation
* Returns Bitmap annotation in format as returned by OMC.
* \return
*/
QString BitmapAnnotation::getOMCShapeAnnotation()
{
QStringList annotationString;
annotationString.append(GraphicItem::getOMCShapeAnnotation());
// get the extents
QString extentString;
extentString.append("{");
extentString.append("{").append(QString::number(mExtents.at(0).x())).append(",");
extentString.append(QString::number(mExtents.at(0).y())).append("},");
extentString.append("{").append(QString::number(mExtents.at(1).x())).append(",");
extentString.append(QString::number(mExtents.at(1).y())).append("}");
extentString.append("}");
annotationString.append(extentString);
// get the file name
annotationString.append(QString("\"").append(mOriginalFileName).append("\""));
// get the image source
annotationString.append(QString("\"").append(mImageSource).append("\""));
return annotationString.join(",");
}

/*!
* \brief BitmapAnnotation::getShapeAnnotation
* Returns Bitmap annotation.
* \return
*/
QString BitmapAnnotation::getShapeAnnotation()
{
QStringList annotationString;
annotationString.append(GraphicItem::getShapeAnnotation());
// get the extents
if (mExtents.size() > 1)
{
if (mExtents.size() > 1) {
QString extentString;
extentString.append("extent={");
extentString.append("{").append(QString::number(mExtents.at(0).x())).append(",");
Expand All @@ -139,29 +179,41 @@ QString BitmapAnnotation::getShapeAnnotation()
annotationString.append(extentString);
}
// get the file name
if (!mOriginalFileName.isEmpty())
if (!mOriginalFileName.isEmpty()) {
annotationString.append(QString("fileName=\"").append(mOriginalFileName).append("\""));
}
// get the image source
if (!mImageSource.isEmpty())
if (!mImageSource.isEmpty()) {
annotationString.append(QString("imageSource=\"").append(mImageSource).append("\""));
}
return QString("Bitmap(").append(annotationString.join(",")).append(")");
}

void BitmapAnnotation::updateShape(ShapeAnnotation *pShapeAnnotation)
{
// set the default values
GraphicItem::setDefaults(pShapeAnnotation);
FilledShape::setDefaults(pShapeAnnotation);
ShapeAnnotation::setDefaults(pShapeAnnotation);
}

/*!
* \brief BitmapAnnotation::duplicate
* Duplicates the shape.
*/
void BitmapAnnotation::duplicate()
{
BitmapAnnotation *pBitmapAnnotation = new BitmapAnnotation(mClassFileName, "", false, mpGraphicsView);
QPointF gridStep(mpGraphicsView->getCoOrdinateSystem()->getHorizontalGridStep(),
mpGraphicsView->getCoOrdinateSystem()->getVerticalGridStep());
BitmapAnnotation *pBitmapAnnotation = new BitmapAnnotation(mClassFileName, "", mpGraphicsView);
pBitmapAnnotation->updateShape(this);
QPointF gridStep(mpGraphicsView->mCoOrdinateSystem.getHorizontalGridStep() * 5,
mpGraphicsView->mCoOrdinateSystem.getVerticalGridStep() * 5);
pBitmapAnnotation->setOrigin(mOrigin + gridStep);
pBitmapAnnotation->setRotationAngle(mRotation);
pBitmapAnnotation->initializeTransformation();
pBitmapAnnotation->setExtents(getExtents());
pBitmapAnnotation->setFileName(getFileName());
pBitmapAnnotation->setImageSource(getImageSource());
pBitmapAnnotation->setImage(getImage());
pBitmapAnnotation->drawCornerItems();
pBitmapAnnotation->setCornerItemsPassive();
pBitmapAnnotation->setCornerItemsActiveOrPassive();
pBitmapAnnotation->update();
mpGraphicsView->addClassAnnotation();
mpGraphicsView->setCanAddClassAnnotation(true);
mpGraphicsView->getModelWidget()->getUndoStack()->push(new AddShapeCommand(pBitmapAnnotation));
mpGraphicsView->getModelWidget()->getLibraryTreeItem()->emitShapeAdded(pBitmapAnnotation, mpGraphicsView);
setSelected(false);
pBitmapAnnotation->setSelected(true);
}
10 changes: 8 additions & 2 deletions OMEdit/OMEditGUI/Annotations/BitmapAnnotation.h
Expand Up @@ -48,14 +48,20 @@ class BitmapAnnotation : public ShapeAnnotation
{
Q_OBJECT
public:
BitmapAnnotation(QString classFileName, QString annotation, Component *pParent);
BitmapAnnotation(QString classFileName, QString annotation, bool inheritedShape, GraphicsView *pGraphicsView);
// Used for icon/diagram shape
BitmapAnnotation(QString classFileName, QString annotation, GraphicsView *pGraphicsView);
// Used for shape inside a component
BitmapAnnotation(ShapeAnnotation *pShapeAnnotation, Component *pParent);
// Used for icon/diagram inherited shape
BitmapAnnotation(ShapeAnnotation *pShapeAnnotation, GraphicsView *pGraphicsView);
void parseShapeAnnotation(QString annotation);
QRectF boundingRect() const;
QPainterPath shape() const;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
void drawBitmapAnnotaion(QPainter *painter);
QString getOMCShapeAnnotation();
QString getShapeAnnotation();
void updateShape(ShapeAnnotation *pShapeAnnotation);
private:
Component *mpComponent;
public slots:
Expand Down

0 comments on commit 53f5b7b

Please sign in to comment.