Ignore:
Timestamp:
2012-10-20T20:27:24+02:00 (12 years ago)
Author:
adeas31
Message:
  • Removed some old classes.
  • Better connection support for array type connectors.
  • Don't call getClassNames every time for searching of Modelica classes.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/OMEdit/OMEditGUI/RectangleAnnotation.cpp

    r13405 r13537  
    3636#include "RectangleAnnotation.h"
    3737
    38 RectangleAnnotation_OMC::RectangleAnnotation_OMC(QString annotation, Component_OMC *pParent)
    39   : ShapeAnnotation_OMC(pParent)
     38RectangleAnnotation::RectangleAnnotation(QString annotation, Component *pParent)
     39  : ShapeAnnotation(pParent)
    4040{
    4141  parseShapeAnnotation(annotation);
    4242}
    4343
    44 void RectangleAnnotation_OMC::parseShapeAnnotation(QString annotation)
     44void RectangleAnnotation::parseShapeAnnotation(QString annotation)
    4545{
    4646  GraphicItem::parseShapeAnnotation(annotation);
     
    6464}
    6565
    66 QRectF RectangleAnnotation_OMC::boundingRect() const
     66QRectF RectangleAnnotation::boundingRect() const
    6767{
    6868  return shape().boundingRect();
    6969}
    7070
    71 QPainterPath RectangleAnnotation_OMC::shape() const
     71QPainterPath RectangleAnnotation::shape() const
    7272{
    7373  QPainterPath path;
     
    7676}
    7777
    78 void RectangleAnnotation_OMC::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
     78void RectangleAnnotation::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
    7979{
    8080  Q_UNUSED(option);
     
    8787}
    8888
    89 void RectangleAnnotation_OMC::drawRectangleAnnotaion(QPainter *painter)
     89void RectangleAnnotation::drawRectangleAnnotaion(QPainter *painter)
    9090{
    9191  applyLinePattern(painter);
     
    115115  painter->drawRoundedRect(getBoundingRect(), mRadius, mRadius);
    116116}
    117 
    118 
    119 
    120 
    121 
    122 RectangleAnnotation::RectangleAnnotation(QString shape, Component *pParent)
    123   : ShapeAnnotation(pParent), mpCompnent(pParent)
    124 {
    125   initializeFields();
    126   parseShapeAnnotation(shape, mpCompnent->getOMCProxy());
    127 }
    128 
    129 RectangleAnnotation::RectangleAnnotation(GraphicsView *graphicsView, QGraphicsItem *pParent)
    130   : ShapeAnnotation(graphicsView, pParent)
    131 {
    132   // initialize all fields with default values
    133   initializeFields();
    134   mIsCustomShape = true;
    135   setAcceptHoverEvents(true);
    136   connect(this, SIGNAL(updateShapeAnnotation()), mpGraphicsView, SLOT(addClassAnnotation()));
    137 }
    138 
    139 RectangleAnnotation::RectangleAnnotation(QString shape, GraphicsView *graphicsView, QGraphicsItem *pParent)
    140   : ShapeAnnotation(graphicsView, pParent)
    141 {
    142   // initialize all fields with default values
    143   initializeFields();
    144   parseShapeAnnotation(shape, mpGraphicsView->getModelWidget()->getModelWidgetContainer()->getMainWindow()->getOMCProxy());
    145   mIsCustomShape = true;
    146   setAcceptHoverEvents(true);
    147   connect(this, SIGNAL(updateShapeAnnotation()), mpGraphicsView, SLOT(addClassAnnotation()));
    148 }
    149 
    150 QRectF RectangleAnnotation::boundingRect() const
    151 {
    152   return shape().boundingRect();
    153 }
    154 
    155 QPainterPath RectangleAnnotation::shape() const
    156 {
    157   QPainterPath path;
    158   path.addRoundedRect(getBoundingRect(), mCornerRadius, mCornerRadius);
    159   return addPathStroker(path);
    160 }
    161 
    162 void RectangleAnnotation::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
    163 {
    164   Q_UNUSED(option);
    165   Q_UNUSED(widget);
    166 
    167   if (transformOriginPoint() != boundingRect().center())
    168   {
    169     setTransformOriginPoint(boundingRect().center());
    170   }
    171 
    172   drawRectangleAnnotaion(painter);
    173 }
    174 
    175 void RectangleAnnotation::drawRectangleAnnotaion(QPainter *painter)
    176 {
    177   QPainterPath path;
    178 
    179   switch (this->mFillPattern)
    180   {
    181     case Qt::LinearGradientPattern:
    182     {
    183       QLinearGradient gradient(getBoundingRect().center().x(), getBoundingRect().center().y(),
    184                                getBoundingRect().center().x(), getBoundingRect().y());
    185       gradient.setColorAt(0.0, this->mFillColor);
    186       gradient.setColorAt(1.0, this->mLineColor);
    187       gradient.setSpread(QGradient::ReflectSpread);
    188       painter->setBrush(gradient);
    189       break;
    190     }
    191     case Qt::Dense1Pattern:
    192     {
    193       QLinearGradient gradient(getBoundingRect().center().x(), getBoundingRect().center().y(),
    194                                getBoundingRect().x(), getBoundingRect().center().y());
    195       gradient.setColorAt(0.0, this->mFillColor);
    196       gradient.setColorAt(1.0, this->mLineColor);
    197       gradient.setSpread(QGradient::ReflectSpread);
    198       painter->setBrush(gradient);
    199       break;
    200     }
    201     case Qt::RadialGradientPattern:
    202     {
    203       QRadialGradient gradient(getBoundingRect().center().x(), getBoundingRect().center().y(),
    204                                getBoundingRect().width());
    205       gradient.setColorAt(0.0, this->mFillColor);
    206       gradient.setColorAt(1.0, this->mLineColor);
    207       gradient.setSpread(QGradient::ReflectSpread);
    208       painter->setBrush(gradient);
    209       break;
    210     }
    211     default:
    212       painter->setBrush(QBrush(this->mFillColor, mFillPattern));
    213       break;
    214   }
    215 
    216   // make the pen width upper rounded if rectangle is rounded
    217   qreal thickness;
    218   // if (mCornerRadius > 0) // this is commented intentionally so that we dont need path stroker. Also helps in svg rendering
    219   thickness = ceil(mThickness);
    220 
    221   QPen pen(mLineColor, thickness, mLinePattern);
    222   pen.setCosmetic(true);
    223   painter->setPen(pen);
    224 
    225   path.addRoundedRect(getBoundingRect(), mCornerRadius, mCornerRadius);
    226   painter->drawPath(path);
    227 }
    228 
    229 void RectangleAnnotation::addPoint(QPointF point)
    230 {
    231   mExtent.append(point);
    232 }
    233 
    234 void RectangleAnnotation::updateEndPoint(QPointF point)
    235 {
    236   mExtent.back() = point;
    237 }
    238 
    239 void RectangleAnnotation::drawRectangleCornerItems()
    240 {
    241   mIsFinishedCreatingShape = true;
    242   for (int i = 0 ; i < this->mExtent.size() ; i++)
    243   {
    244     QPointF point = this->mExtent.at(i);
    245     RectangleCornerItem *rectangleCornerItem = new RectangleCornerItem(point.x(), point.y(), i, this);
    246     mRectangleCornerItemsList.append(rectangleCornerItem);
    247   }
    248   emit updateShapeAnnotation();
    249 }
    250 
    251 QString RectangleAnnotation::getShapeAnnotation()
    252 {
    253   QString annotationString;
    254   annotationString.append("Rectangle(");
    255 
    256   if (!mVisible)
    257   {
    258     annotationString.append("visible=false,");
    259   }
    260 
    261   annotationString.append("rotation=").append(QString::number(this->rotation())).append(",");
    262 
    263   annotationString.append("lineColor={");
    264   annotationString.append(QString::number(mLineColor.red())).append(",");
    265   annotationString.append(QString::number(mLineColor.green())).append(",");
    266   annotationString.append(QString::number(mLineColor.blue()));
    267   annotationString.append("},");
    268 
    269   annotationString.append("fillColor={");
    270   annotationString.append(QString::number(mFillColor.red())).append(",");
    271   annotationString.append(QString::number(mFillColor.green())).append(",");
    272   annotationString.append(QString::number(mFillColor.blue()));
    273   annotationString.append("},");
    274 
    275   QMap<QString, Qt::PenStyle>::iterator it;
    276   for (it = this->mLinePatternsMap.begin(); it != this->mLinePatternsMap.end(); ++it)
    277   {
    278     if (it.value() == mLinePattern)
    279     {
    280       annotationString.append("pattern=LinePattern.").append(it.key()).append(",");
    281       break;
    282     }
    283   }
    284 
    285   QMap<QString, Qt::BrushStyle>::iterator fill_it;
    286   for (fill_it = this->mFillPatternsMap.begin(); fill_it != this->mFillPatternsMap.end(); ++fill_it)
    287   {
    288     if (fill_it.value() == mFillPattern)
    289     {
    290       annotationString.append("fillPattern=FillPattern.").append(fill_it.key()).append(",");
    291       break;
    292     }
    293   }
    294 
    295   annotationString.append("lineThickness=").append(QString::number(mThickness)).append(",");
    296   annotationString.append("extent={{");
    297   annotationString.append(QString::number(mapToScene(mExtent.at(0)).x())).append(",");
    298   annotationString.append(QString::number(mapToScene(mExtent.at(0)).y())).append("},{");
    299   annotationString.append(QString::number(mapToScene(mExtent.at(1)).x())).append(",");
    300   annotationString.append(QString::number(mapToScene(mExtent.at(1)).y()));
    301 
    302   annotationString.append("}}");
    303 
    304   annotationString.append(")");
    305   return annotationString;
    306 }
    307 
    308 void RectangleAnnotation::updatePoint(int index, QPointF point)
    309 {
    310 
    311   mExtent.replace(index, point);
    312 }
    313 
    314 void RectangleAnnotation::parseShapeAnnotation(QString shape, OMCProxy *omc)
    315 {
    316   // Remove { } from shape
    317 
    318   shape = shape.replace("{", "");
    319   shape = shape.replace("}", "");
    320 
    321   // parse the shape to get the list of attributes of Rectangle.
    322   QStringList list = StringHandler::getStrings(shape);
    323   if (list.size() < 16)
    324   {
    325     return;
    326   }
    327 
    328   // if first item of list is true then the Rectangle should be visible.
    329   this->mVisible = static_cast<QString>(list.at(0)).contains("true");
    330 
    331   int index = 0;
    332   mOrigin.setX(static_cast<QString>(list.at(1)).toFloat());
    333   mOrigin.setY(static_cast<QString>(list.at(2)).toFloat());
    334   mRotation = static_cast<QString>(list.at(3)).toFloat();
    335   index = 3;
    336   // 2,3,4 items of list contains the line color.
    337   index = index + 1;
    338   int red, green, blue;
    339 
    340   red = static_cast<QString>(list.at(index)).toInt();
    341   index = index + 1;
    342   green = static_cast<QString>(list.at(index)).toInt();
    343   index = index + 1;
    344   blue = static_cast<QString>(list.at(index)).toInt();
    345   this->mLineColor = QColor (red, green, blue);
    346 
    347   // 5,6,7 items of list contains the fill color.
    348   index = index + 1;
    349   red = static_cast<QString>(list.at(index)).toInt();
    350   index = index + 1;
    351   green = static_cast<QString>(list.at(index)).toInt();
    352   index = index + 1;
    353   blue = static_cast<QString>(list.at(index)).toInt();
    354   this->mFillColor = QColor (red, green, blue);
    355 
    356   // 8 item of the list contains the line pattern.
    357   index = index + 1;
    358   QString linePattern = StringHandler::getLastWordAfterDot(list.at(index));
    359   QMap<QString, Qt::PenStyle>::iterator it;
    360   for (it = this->mLinePatternsMap.begin(); it != this->mLinePatternsMap.end(); ++it)
    361   {
    362     if (it.key().compare(linePattern) == 0)
    363     {
    364       this->mLinePattern = it.value();
    365       break;
    366     }
    367   }
    368 
    369   // 9 item of the list contains the fill pattern.
    370   index = index + 1;
    371   QString fillPattern = StringHandler::getLastWordAfterDot(list.at(index));
    372   QMap<QString, Qt::BrushStyle>::iterator fill_it;
    373   for (fill_it = this->mFillPatternsMap.begin(); fill_it != this->mFillPatternsMap.end(); ++fill_it)
    374   {
    375     if (fill_it.key().compare(fillPattern) == 0)
    376     {
    377       this->mFillPattern = fill_it.value();
    378       break;
    379     }
    380   }
    381 
    382   // 10 item of the list contains the thickness.
    383   index = index + 1;
    384   this->mThickness = static_cast<QString>(list.at(index)).toFloat();
    385 
    386   // 11 item of the list contains the border pattern.
    387   index = index + 1;
    388   QString borderPattern = StringHandler::getLastWordAfterDot(list.at(index));
    389   QMap<QString, Qt::BrushStyle>::iterator border_it;
    390   for (border_it = this->mBorderPatternsMap.begin(); border_it != this->mBorderPatternsMap.end(); ++border_it)
    391   {
    392     if (border_it.key() == borderPattern)
    393     {
    394       this->mBorderPattern = border_it.value();
    395       break;
    396     }
    397   }
    398 
    399   // 12, 13, 14, 15 items of the list contains the extent points of rectangle.
    400   index = index + 1;
    401   qreal x = static_cast<QString>(list.at(index)).toFloat();
    402   index = index + 1;
    403   qreal y = static_cast<QString>(list.at(index)).toFloat();
    404   QPointF p1 (x, y);
    405   index = index + 1;
    406   x = static_cast<QString>(list.at(index)).toFloat();
    407   index = index + 1;
    408   y = static_cast<QString>(list.at(index)).toFloat();
    409   QPointF p2 (x, y);
    410 
    411   this->mExtent.append(p1);
    412   this->mExtent.append(p2);
    413 
    414   // 16 item of the list contains the corner radius.
    415   index = index + 1;
    416   this->mCornerRadius = static_cast<QString>(list.at(index)).toFloat();
    417 }
Note: See TracChangeset for help on using the changeset viewer.