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/LineAnnotation.cpp

    r13405 r13537  
    3636#include "LineAnnotation.h"
    3737
    38 LineAnnotation_OMC::LineAnnotation_OMC(QString annotation, Component_OMC *pParent)
    39   : ShapeAnnotation_OMC(pParent)
     38LineAnnotation::LineAnnotation(QString annotation, Component *pParent)
     39  : ShapeAnnotation(pParent)
    4040{
    4141  parseShapeAnnotation(annotation);
    4242}
    4343
    44 LineAnnotation_OMC::LineAnnotation_OMC(Component_OMC *pStartComponent, GraphicsView *pGraphicsView)
    45   : ShapeAnnotation_OMC(0)
     44LineAnnotation::LineAnnotation(Component *pStartComponent, GraphicsView *pGraphicsView)
     45  : ShapeAnnotation(0)
    4646{
    4747  setZValue(-1.0);
     
    6262}
    6363
    64 void LineAnnotation_OMC::parseShapeAnnotation(QString annotation)
     64void LineAnnotation::parseShapeAnnotation(QString annotation)
    6565{
    6666  GraphicItem::parseShapeAnnotation(annotation);
     
    103103}
    104104
    105 QPainterPath LineAnnotation_OMC::getShape() const
     105QPainterPath LineAnnotation::getShape() const
    106106{
    107107  QPainterPath path;
     
    154154}
    155155
    156 QRectF LineAnnotation_OMC::boundingRect() const
     156QRectF LineAnnotation::boundingRect() const
    157157{
    158158  return shape().boundingRect();
    159159}
    160160
    161 QPainterPath LineAnnotation_OMC::shape() const
     161QPainterPath LineAnnotation::shape() const
    162162{
    163163  QPainterPath path = getShape();
     
    165165}
    166166
    167 void LineAnnotation_OMC::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
     167void LineAnnotation::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
    168168{
    169169  Q_UNUSED(option);
     
    176176}
    177177
    178 void LineAnnotation_OMC::drawLineAnnotaion(QPainter *painter)
     178void LineAnnotation::drawLineAnnotaion(QPainter *painter)
    179179{
    180180  applyLinePattern(painter);
     
    202202}
    203203
    204 QPolygonF LineAnnotation_OMC::drawArrow(QPointF startPos, QPointF endPos, qreal size, int arrowType) const
     204QPolygonF LineAnnotation::drawArrow(QPointF startPos, QPointF endPos, qreal size, int arrowType) const
    205205{
    206206  double xA = size / 2;
     
    257257}
    258258
    259 QString LineAnnotation_OMC::getShapeAnnotation()
     259QString LineAnnotation::getShapeAnnotation()
    260260{
    261261  QString annotationString;
     
    294294}
    295295
    296 void LineAnnotation_OMC::setStartComponent(Component_OMC *pStartComponent)
     296void LineAnnotation::setStartComponent(Component *pStartComponent)
    297297{
    298298  mpStartComponent = pStartComponent;
    299299}
    300300
    301 Component_OMC* LineAnnotation_OMC::getStartComponent()
     301Component* LineAnnotation::getStartComponent()
    302302{
    303303  return mpStartComponent;
    304304}
    305305
    306 void LineAnnotation_OMC::setEndComponent(Component_OMC *pEndComponent)
     306void LineAnnotation::setEndComponent(Component *pEndComponent)
    307307{
    308308  mpEndComponent = pEndComponent;
    309309}
    310310
    311 Component_OMC* LineAnnotation_OMC::getEndComponent()
     311Component* LineAnnotation::getEndComponent()
    312312{
    313313  return mpEndComponent;
    314314}
    315315
    316 void LineAnnotation_OMC::addPoint(QPointF point)
     316void LineAnnotation::addPoint(QPointF point)
    317317{
    318318  //! @todo make it better
     
    320320  if(mPoints.size() <= 2 && (fabs(mpStartComponent->getTransformation()->getRotateAngle()) >= 0 && fabs(mpStartComponent->getTransformation()->getRotateAngle()) < 90))
    321321  {
    322     mGeometries.push_back(LineAnnotation_OMC::HORIZONTAL);
     322    mGeometries.push_back(LineAnnotation::HORIZONTAL);
    323323  }
    324324  else if(mPoints.size() <= 2 && (fabs(mpStartComponent->getTransformation()->getRotateAngle()) >= 90 && fabs(mpStartComponent->getTransformation()->getRotateAngle()) < 180))
    325325  {
    326     mGeometries.push_back(LineAnnotation_OMC::VERTICAL);
     326    mGeometries.push_back(LineAnnotation::VERTICAL);
    327327  }
    328328  else if(mPoints.size() <= 2 && (fabs(mpStartComponent->getTransformation()->getRotateAngle()) >= 180 && fabs(mpStartComponent->getTransformation()->getRotateAngle()) < 270))
    329329  {
    330     mGeometries.push_back(LineAnnotation_OMC::HORIZONTAL);
     330    mGeometries.push_back(LineAnnotation::HORIZONTAL);
    331331  }
    332332  else if(mPoints.size() <= 2 && (fabs(mpStartComponent->getTransformation()->getRotateAngle()) >= 270 && fabs(mpStartComponent->getTransformation()->getRotateAngle()) < 360))
    333333  {
    334     mGeometries.push_back(LineAnnotation_OMC::VERTICAL);
     334    mGeometries.push_back(LineAnnotation::VERTICAL);
    335335  }
    336336  else if (mPoints.size() <= 2)
    337337  {
    338     mGeometries.push_back(LineAnnotation_OMC::HORIZONTAL);
    339   }
    340   else if(mPoints.size() > 2 && mGeometries.back() == LineAnnotation_OMC::HORIZONTAL)
    341   {
    342     mGeometries.push_back(LineAnnotation_OMC::VERTICAL);
    343   }
    344   else if(mPoints.size() > 2 && mGeometries.back() == LineAnnotation_OMC::VERTICAL)
    345   {
    346     mGeometries.push_back(LineAnnotation_OMC::HORIZONTAL);
    347   }
    348   else if(mPoints.size() > 2 && mGeometries.back() == LineAnnotation_OMC::DIAGONAL)
    349   {
    350     mGeometries.push_back(LineAnnotation_OMC::DIAGONAL);
     338    mGeometries.push_back(LineAnnotation::HORIZONTAL);
     339  }
     340  else if(mPoints.size() > 2 && mGeometries.back() == LineAnnotation::HORIZONTAL)
     341  {
     342    mGeometries.push_back(LineAnnotation::VERTICAL);
     343  }
     344  else if(mPoints.size() > 2 && mGeometries.back() == LineAnnotation::VERTICAL)
     345  {
     346    mGeometries.push_back(LineAnnotation::HORIZONTAL);
     347  }
     348  else if(mPoints.size() > 2 && mGeometries.back() == LineAnnotation::DIAGONAL)
     349  {
     350    mGeometries.push_back(LineAnnotation::DIAGONAL);
    351351    //Give new line correct angle!
    352352  }
     
    356356//! @param point is the new start point.
    357357//! @see updateEndPoint(QPointF point)
    358 void LineAnnotation_OMC::updateStartPoint(QPointF point)
     358void LineAnnotation::updateStartPoint(QPointF point)
    359359{
    360360  if (mPoints.size() == 0)
     
    364364  if (mPoints.size() != 1)
    365365  {
    366     if (mGeometries[0] == LineAnnotation_OMC::HORIZONTAL)
     366    if (mGeometries[0] == LineAnnotation::HORIZONTAL)
    367367      mPoints[1] = QPointF(mPoints[1].x(),mPoints[0].y());
    368     else if (mGeometries[0] == LineAnnotation_OMC::VERTICAL)
     368    else if (mGeometries[0] == LineAnnotation::VERTICAL)
    369369      mPoints[1] = QPointF(mPoints[0].x(),mPoints[1].y());
    370370  }
    371371}
    372372
    373 void LineAnnotation_OMC::updateEndPoint(QPointF point)
     373void LineAnnotation::updateEndPoint(QPointF point)
    374374{
    375375  mPoints.back() = point;
    376   if (mGeometries.back() == LineAnnotation_OMC::HORIZONTAL)
     376  if (mGeometries.back() == LineAnnotation::HORIZONTAL)
    377377    mPoints[mPoints.size()-2] = QPointF(mPoints[mPoints.size()-2].x(),point.y());
    378   else if (mGeometries.back() == LineAnnotation_OMC::VERTICAL)
     378  else if (mGeometries.back() == LineAnnotation::VERTICAL)
    379379    mPoints[mPoints.size()-2] = QPointF(point.x(),mPoints[mPoints.size()-2].y());
    380380}
    381381
    382 void LineAnnotation_OMC::moveAllPoints(qreal offsetX, qreal offsetY)
     382void LineAnnotation::moveAllPoints(qreal offsetX, qreal offsetY)
    383383{
    384384  for(int i=0; i != mPoints.size(); ++i)
     
    388388}
    389389
    390 void LineAnnotation_OMC::handleComponentMoved()
     390void LineAnnotation::setStartComponentName(QString name)
     391{
     392  mStartComponentName = name;
     393}
     394
     395QString LineAnnotation::getStartComponentName()
     396{
     397  return mStartComponentName;
     398}
     399
     400void LineAnnotation::setEndComponentName(QString name)
     401{
     402  mEndComponentName = name;
     403}
     404
     405QString LineAnnotation::getEndComponentName()
     406{
     407  return mEndComponentName;
     408}
     409
     410void LineAnnotation::handleComponentMoved()
    391411{
    392412  if (mPoints.size() < 2)
     
    406426}
    407427
    408 void LineAnnotation_OMC::updateConnectionAnnotation()
     428void LineAnnotation::updateConnectionAnnotation()
    409429{
    410430  // get the connection line annotation.
    411431  QString annotationString = QString("annotate=").append(getShapeAnnotation());
    412   // get the connected components names.
    413   QString startComponentName, endComponentName;
    414   if (mpStartComponent->getParentComponent())
    415     startComponentName = QString(mpStartComponent->getParentComponent()->getName()).append(".").append(mpStartComponent->getComponentInfo()->getName());
    416   else
    417     startComponentName = mpStartComponent->getName();
    418   if (mpEndComponent->getParentComponent())
    419     endComponentName = QString(mpEndComponent->getParentComponent()->getName()).append(".").append(mpEndComponent->getComponentInfo()->getName());
    420   else
    421     endComponentName = mpEndComponent->getName();
    422432  // update the connection
    423433  OMCProxy *pOMCProxy = mpGraphicsView->getModelWidget()->getModelWidgetContainer()->getMainWindow()->getOMCProxy();
    424   pOMCProxy->updateConnection(startComponentName, endComponentName, mpGraphicsView->getModelWidget()->getLibraryTreeNode()->getNameStructure(), annotationString);
    425 }
    426 
    427 
    428 
    429 LineAnnotation::LineAnnotation(QString shape, Component *pParent)
    430   : ShapeAnnotation(pParent), mpComponent(pParent)
    431 {
    432   // initialize all fields with default values
    433   initializeFields();
    434   parseShapeAnnotation(shape);
    435 }
    436 
    437 LineAnnotation::LineAnnotation(GraphicsView *graphicsView, QGraphicsItem *pParent)
    438   : ShapeAnnotation(graphicsView, pParent)
    439 {
    440   // initialize all fields with default values
    441   initializeFields();
    442   mIsCustomShape = true;
    443   setAcceptHoverEvents(true);
    444   connect(this, SIGNAL(updateShapeAnnotation()), mpGraphicsView, SLOT(addClassAnnotation()));
    445 }
    446 
    447 LineAnnotation::LineAnnotation(QString shape, GraphicsView *graphicsView, QGraphicsItem *pParent)
    448   : ShapeAnnotation(graphicsView, pParent)
    449 {
    450   // initialize all fields with default values
    451   initializeFields();
    452   parseShapeAnnotation(shape);
    453   mIsCustomShape = true;
    454   setAcceptHoverEvents(true);
    455   connect(this, SIGNAL(updateShapeAnnotation()), mpGraphicsView, SLOT(addClassAnnotation()));
    456 }
    457 
    458 QPainterPath LineAnnotation::getShape() const
    459 {
    460   QPainterPath path;
    461 
    462   if (this->mPoints.size() > 0)
    463   {
    464     if (mSmooth)
     434  pOMCProxy->updateConnection(getStartComponentName(), getEndComponentName(),
     435                              mpGraphicsView->getModelWidget()->getLibraryTreeNode()->getNameStructure(), annotationString);
     436}
     437
     438ConnectionArray::ConnectionArray(GraphicsView *pGraphicsView, LineAnnotation *pConnectionLineAnnotation, QWidget *pParent)
     439  : QDialog(pParent, Qt::WindowTitleHint), mpGraphicsView(pGraphicsView), mpConnectionLineAnnotation(pConnectionLineAnnotation)
     440{
     441  setWindowTitle(QString(Helper::applicationName).append(" - ").append(Helper::connectArray));
     442  setAttribute(Qt::WA_DeleteOnClose);
     443  setMinimumSize(375, 140);
     444  setModal(true);
     445  // heading
     446  mpHeading = new Label(Helper::connectArray);
     447  mpHeading->setFont(QFont("", Helper::headingFontSize));
     448  mpHeading->setAlignment(Qt::AlignTop);
     449  // horizontal line
     450  mpHorizontalLine = new QFrame();
     451  mpHorizontalLine->setFrameShape(QFrame::HLine);
     452  mpHorizontalLine->setFrameShadow(QFrame::Sunken);
     453  // Description text
     454  QString startComponentDescription = QString("<b>").append(pConnectionLineAnnotation->getStartComponent()->getParentComponent()->getName())
     455      .append(".").append(pConnectionLineAnnotation->getStartComponent()->getName()).append("</b>");
     456  if (pConnectionLineAnnotation->getStartComponent()->getComponentInfo()->isArray())
     457    startComponentDescription.append("<b>[index]</b>");
     458  QString endComponentDescription = QString("<b>").append(pConnectionLineAnnotation->getEndComponent()->getParentComponent()->getName())
     459      .append(".").append(pConnectionLineAnnotation->getEndComponent()->getName()).append("</b>");
     460  if (pConnectionLineAnnotation->getEndComponent()->getComponentInfo()->isArray())
     461    endComponentDescription.append("<b>[index]</b>");
     462  mpDescriptionLabel = new Label(QString("Connect ").append(startComponentDescription).append(" with ").append(endComponentDescription));
     463  // start component
     464  QIntValidator *pIntValidator = new QIntValidator(this);
     465  pIntValidator->setBottom(0);
     466  mpStartComponentLabel = new Label(tr("Enter <b>index</b> value for <b>").append(pConnectionLineAnnotation->getStartComponent()->getParentComponent()->getName())
     467                                    .append(".").append(pConnectionLineAnnotation->getStartComponent()->getName()).append("<b>"));
     468  mpStartComponentTextBox = new QLineEdit;
     469  mpStartComponentTextBox->setValidator(pIntValidator);
     470  // start component
     471  mpEndComponentLabel = new Label(tr("Enter <b>index</b> value for <b>").append(pConnectionLineAnnotation->getEndComponent()->getParentComponent()->getName())
     472                                  .append(".").append(pConnectionLineAnnotation->getEndComponent()->getComponentInfo()->getName()).append("</b>"));
     473  mpEndComponentTextBox = new QLineEdit;
     474  mpEndComponentTextBox->setValidator(pIntValidator);
     475  // Create the buttons
     476  mpOkButton = new QPushButton(Helper::ok);
     477  mpOkButton->setAutoDefault(true);
     478  connect(mpOkButton, SIGNAL(clicked()), SLOT(saveArrayIndex()));
     479  mpCancelButton = new QPushButton(Helper::cancel);
     480  mpCancelButton->setAutoDefault(false);
     481  connect(mpCancelButton, SIGNAL(clicked()), SLOT(cancelArrayIndex()));
     482  // add buttons
     483  mpButtonBox = new QDialogButtonBox(Qt::Horizontal);
     484  mpButtonBox->addButton(mpOkButton, QDialogButtonBox::ActionRole);
     485  mpButtonBox->addButton(mpCancelButton, QDialogButtonBox::ActionRole);
     486  // Create a layout
     487  QGridLayout *mainLayout = new QGridLayout;
     488  mainLayout->addWidget(mpHeading, 0, 0);
     489  mainLayout->addWidget(mpHorizontalLine, 1, 0);
     490  mainLayout->addWidget(mpDescriptionLabel, 2, 0);
     491  int i = 3;
     492  if (pConnectionLineAnnotation->getStartComponent()->getComponentInfo()->isArray())
     493  {
     494    mainLayout->addWidget(mpStartComponentLabel, i, 0);
     495    mainLayout->addWidget(mpStartComponentTextBox, i+1, 0);
     496    i = i + 2;
     497  }
     498  if (pConnectionLineAnnotation->getEndComponent()->getComponentInfo()->isArray())
     499  {
     500    mainLayout->addWidget(mpEndComponentLabel, i, 0);
     501    mainLayout->addWidget(mpEndComponentTextBox, i+1, 0);
     502    i = i + 2;
     503  }
     504  mainLayout->addWidget(mpButtonBox, i, 0);
     505  setLayout(mainLayout);
     506}
     507
     508void ConnectionArray::saveArrayIndex()
     509{
     510  QString startComponentName, endComponentName;
     511  // set start component name
     512  if (mpConnectionLineAnnotation->getStartComponent()->getComponentInfo()->isArray())
     513  {
     514    startComponentName = QString(mpConnectionLineAnnotation->getStartComponent()->getParentComponent()->getName()).append(".")
     515        .append(mpConnectionLineAnnotation->getStartComponent()->getName());
     516    if (mpStartComponentTextBox->text().isEmpty())
    465517    {
    466       for (int i = 0 ; i < this->mPoints.size() ; i++)
    467       {
    468         QPointF point3 = this->mPoints.at(i);
    469         if (i == 0)
    470           path.moveTo(point3);
    471         else
    472         {
    473           // if points are only two then spline acts as simple line
    474           if (i < 2)
    475           {
    476             if (mPoints.size() < 3)
    477               path.lineTo(point3);
    478           }
    479           else
    480           {
    481             // calculate middle points for bezier curves
    482             QPointF point2 = this->mPoints.at(i - 1);
    483             QPointF point1 = this->mPoints.at(i - 2);
    484             QPointF point12((point1.x() + point2.x())/2, (point1.y() + point2.y())/2);
    485             QPointF point23((point2.x() + point3.x())/2, (point2.y() + point3.y())/2);
    486 
    487             path.lineTo(point12);
    488             path.cubicTo(point12, point2, point23);
    489             // if its the last point
    490             if (i == mPoints.size() - 1)
    491               path.lineTo(point3);
    492           }
    493         }
    494       }
    495     }
    496     else
    497     {
    498       for (int i = 0 ; i < this->mPoints.size() ; i++)
    499       {
    500         QPointF point1 = this->mPoints.at(i);
    501         if (i == 0)
    502           path.moveTo(point1);
    503         else
    504           path.lineTo(point1);
    505       }
    506     }
    507   }
    508   return path;
    509 }
    510 
    511 QRectF LineAnnotation::boundingRect() const
    512 {
    513   return shape().boundingRect();
    514 }
    515 
    516 QPainterPath LineAnnotation::shape() const
    517 {
    518   QPainterPath path = getShape();
    519   return addPathStroker(path);
    520 }
    521 
    522 void LineAnnotation::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
    523 {
    524   Q_UNUSED(option);
    525   Q_UNUSED(widget);
    526 
    527   if (transformOriginPoint() != boundingRect().center())
    528   {
    529     setTransformOriginPoint(boundingRect().center());
    530   }
    531   drawLineAnnotaion(painter);
    532 }
    533 
    534 void LineAnnotation::drawLineAnnotaion(QPainter *painter)
    535 {
    536   qreal thickness;
    537 
    538   // make the pen width upper rounded for spline, otherwise spline is distorted
    539   thickness = ceil(mThickness);
    540   // this is commented intentionally so that we dont need path stroker. Also helps in svg rendering
    541   //    if (mSmooth)
    542   //        thickness = ceil(mThickness);
    543   //    else
    544   //        thickness = mThickness;
    545 
    546   QPen pen(this->mLineColor, thickness, this->mLinePattern);
    547   pen.setCosmetic(true);
    548   painter->setPen(pen);
    549   // draw start arrow
    550   if (mStartArrow == ShapeAnnotation::Filled)
    551   {
    552     painter->save();
    553     painter->setBrush(QBrush(mLineColor, Qt::SolidPattern));
    554     painter->drawPolygon(drawArrow(mPoints.at(0), mPoints.at(1), mArrowSize * 2, mStartArrow));
    555     painter->restore();
    556   }
    557   else
    558     painter->drawPolygon(drawArrow(mPoints.at(0), mPoints.at(1), mArrowSize * 2, mStartArrow));
    559 
    560   painter->drawPath(getShape());
    561 
    562   // draw end arrow
    563   if (mEndArrow == ShapeAnnotation::Filled)
    564   {
    565     painter->save();
    566     painter->setBrush(QBrush(mLineColor, Qt::SolidPattern));
    567     painter->drawPolygon(drawArrow(mPoints.at(mPoints.size() - 1), mPoints.at(mPoints.size() - 2),
    568                                    mArrowSize * 2, mEndArrow));
    569     painter->restore();
    570   }
    571   else
    572     painter->drawPolygon(drawArrow(mPoints.at(mPoints.size() - 1), mPoints.at(mPoints.size() - 2),
    573                                    mArrowSize * 2, mEndArrow));
    574 }
    575 
    576 void LineAnnotation::addPoint(QPointF point)
    577 {
    578   mPoints.append(point);
    579 }
    580 
    581 void LineAnnotation::updateEndPoint(QPointF point)
    582 {
    583   mPoints.back() = point;
    584 }
    585 
    586 void LineAnnotation::drawRectangleCornerItems()
    587 {
    588   mIsFinishedCreatingShape = true;
    589   // remove the last point since mouse double click event has added an extra point to it.....
    590   mPoints.remove(mPoints.size() - 1);
    591   for (int i = 0 ; i < this->mPoints.size() ; i++)
    592   {
    593     QPointF point = this->mPoints.at(i);
    594     RectangleCornerItem *rectangleCornerItem = new RectangleCornerItem(point.x(), point.y(), i, this);
    595     mRectangleCornerItemsList.append(rectangleCornerItem);
    596   }
    597   emit updateShapeAnnotation();
    598 }
    599 
    600 QString LineAnnotation::getShapeAnnotation()
    601 {
    602   QString annotationString;
    603   annotationString.append("Line(");
    604 
    605   if (!mVisible)
    606   {
    607     annotationString.append("visible=false,");
    608   }
    609 
    610   annotationString.append("points={");
    611   for (int i = 0 ; i < mPoints.size() ; i++)
    612   {
    613     annotationString.append("{").append(QString::number(mapToScene(mPoints[i]).x())).append(",");
    614     annotationString.append(QString::number(mapToScene(mPoints[i]).y())).append("}");
    615     if (i < mPoints.size() - 1)
    616       annotationString.append(",");
    617   }
    618   annotationString.append("},");
    619 
    620   annotationString.append("rotation=").append(QString::number(this->rotation())).append(",");
    621 
    622   annotationString.append("color={");
    623   annotationString.append(QString::number(mLineColor.red())).append(",");
    624   annotationString.append(QString::number(mLineColor.green())).append(",");
    625   annotationString.append(QString::number(mLineColor.blue()));
    626   annotationString.append("},");
    627 
    628   QMap<QString, Qt::PenStyle>::iterator it;
    629   for (it = this->mLinePatternsMap.begin(); it != this->mLinePatternsMap.end(); ++it)
    630   {
    631     if (it.value() == mLinePattern)
    632     {
    633       annotationString.append("pattern=LinePattern.").append(it.key()).append(",");
    634       break;
    635     }
    636   }
    637 
    638   annotationString.append("thickness=").append(QString::number(mThickness));
    639   if (mSmooth)
    640   {
    641     annotationString.append(",smooth=Smooth.Bezier");
    642   }
    643 
    644   annotationString.append(")");
    645   return annotationString;
    646 }
    647 
    648 void LineAnnotation::updatePoint(int index, QPointF point)
    649 {
    650   mPoints.replace(index, point);
    651 }
    652 
    653 void LineAnnotation::parseShapeAnnotation(QString shape)
    654 {
    655   // parse the shape to get the list of attributes of Line.
    656   QStringList list = StringHandler::getStrings(shape);
    657   if (list.size() < 8)
    658   {
    659     return;
    660   }
    661 
    662   // if first item of list is true then the Line should be visible.
    663   this->mVisible = static_cast<QString>(list.at(0)).contains("true");
    664 
    665   int index = 0;
    666   QStringList originList = StringHandler::getStrings(StringHandler::removeFirstLastCurlBrackets(list.at(1)));
    667   mOrigin.setX(static_cast<QString>(originList.at(0)).toFloat());
    668   mOrigin.setY(static_cast<QString>(originList.at(1)).toFloat());
    669   mRotation = static_cast<QString>(list.at(2)).toFloat();
    670   index = 2;
    671   // second item of list contains the points.
    672   index = index + 1;
    673   QStringList pointsList = StringHandler::getStrings(StringHandler::removeFirstLastCurlBrackets(list.at(index)));
    674 
    675   foreach (QString point, pointsList)
    676   {
    677     QStringList linePoints = StringHandler::getStrings(StringHandler::removeFirstLastCurlBrackets(point));
    678     if (linePoints.size() < 2)
    679     {
     518      QMessageBox::critical(mpGraphicsView->getModelWidget()->getModelWidgetContainer()->getMainWindow(),
     519                            QString(Helper::applicationName).append(" - ").append(Helper::error),
     520                            GUIMessages::getMessage(GUIMessages::ENTER_VALID_INTEGER).arg(startComponentName), Helper::ok);
    680521      return;
    681522    }
    682 
    683     qreal x = static_cast<QString>(linePoints.at(0)).toFloat();
    684     qreal y = static_cast<QString>(linePoints.at(1)).toFloat();
    685     QPointF p (x, y);
    686     this->mPoints.append(p);
    687   }
    688 
    689   // third item of list contains the color.
    690   index = index + 1;
    691   QStringList colorList = StringHandler::getStrings(StringHandler::removeFirstLastCurlBrackets(list.at(index)));
    692   if (colorList.size() < 3)
    693   {
    694     return;
    695   }
    696 
    697   int red = static_cast<QString>(colorList.at(0)).toInt();
    698   int green = static_cast<QString>(colorList.at(1)).toInt();
    699   int blue = static_cast<QString>(colorList.at(2)).toInt();
    700 
    701   this->mLineColor = QColor (red, green, blue);
    702 
    703   // fourth item of list contains the Line Pattern.
    704   index = index + 1;
    705   QString linePattern = StringHandler::getLastWordAfterDot(list.at(index));
    706   QMap<QString, Qt::PenStyle>::iterator it;
    707   for (it = this->mLinePatternsMap.begin(); it != this->mLinePatternsMap.end(); ++it)
    708   {
    709     if (it.key().compare(linePattern) == 0)
     523    startComponentName = QString(startComponentName).append("[").append(mpStartComponentTextBox->text()).append("]");
     524  }
     525  else
     526  {
     527    startComponentName = QString(mpConnectionLineAnnotation->getStartComponent()->getParentComponent()->getName()).append(".")
     528        .append(mpConnectionLineAnnotation->getStartComponent()->getName());
     529  }
     530  // set end component name
     531  if (mpConnectionLineAnnotation->getEndComponent()->getComponentInfo()->isArray())
     532  {
     533    endComponentName = QString(mpConnectionLineAnnotation->getEndComponent()->getParentComponent()->getName()).append(".")
     534        .append(mpConnectionLineAnnotation->getEndComponent()->getName());
     535    if (mpEndComponentTextBox->text().isEmpty())
    710536    {
    711       this->mLinePattern = it.value();
    712       break;
     537      QMessageBox::critical(mpGraphicsView->getModelWidget()->getModelWidgetContainer()->getMainWindow(),
     538                            QString(Helper::applicationName).append(" - ").append(Helper::error),
     539                            GUIMessages::getMessage(GUIMessages::ENTER_VALID_INTEGER).arg(endComponentName), Helper::ok);
     540      return;
    713541    }
    714   }
    715 
    716   // fifth item of list contains the Line thickness.
    717   index = index + 1;
    718   this->mThickness = static_cast<QString>(list.at(index)).toFloat();
    719 
    720   // sixth item of list contains the Line Arrows.
    721   index = index + 1;
    722   QStringList arrowList = StringHandler::getStrings(StringHandler::removeFirstLastCurlBrackets(list.at(index)));
    723   if (arrowList.size() < 2)
    724     return;
    725 
    726   QMap<QString, ArrowType>::iterator arrow_it;
    727   for (arrow_it = mArrowsMap.begin(); arrow_it != mArrowsMap.end(); ++arrow_it)
    728   {
    729     if (arrow_it.key().compare(StringHandler::getLastWordAfterDot(arrowList.at(0))) == 0)
    730       mStartArrow = arrow_it.value();
    731     if (arrow_it.key().compare(StringHandler::getLastWordAfterDot(arrowList.at(1))) == 0)
    732       mEndArrow = arrow_it.value();
    733   }
    734 
    735   // seventh item of list contains the Line Arrow Size.
    736   index = index + 1;
    737   mArrowSize = static_cast<QString>(list.at(index)).toFloat();
    738 
    739   // eighth item of list contains the smooth.
    740   index = index + 1;
    741   this->mSmooth = static_cast<QString>(list.at(index)).toLower().contains("smooth.bezier");
    742 }
    743 
    744 QPolygonF LineAnnotation::drawArrow(QPointF startPos, QPointF endPos, qreal size, int arrowType) const
    745 {
    746   double xA = size / 2;
    747   double yA = size * sqrt(3) / 2;
    748 
    749   double xB = -xA;
    750   double yB = yA;
    751 
    752   switch (arrowType)
    753   {
    754     case ShapeAnnotation::Filled:
    755       break;
    756     case ShapeAnnotation::Half:
    757       xB = 0;
    758       break;
    759     case ShapeAnnotation::None:
    760       return QPolygonF();
    761     case ShapeAnnotation::Open:
    762       break;
    763   }
    764 
    765   double angle = 0.0f;
    766   if (endPos.x() - startPos.x() == 0)
    767   {
    768     if (endPos.y() - startPos.y() >= 0)
    769       angle = 0;
    770     else
    771       angle = M_PI;
    772   }
    773   else
    774   {
    775     angle = -(M_PI / 2 - (atan((endPos.y() - startPos.y())/(endPos.x() - startPos.x()))));
    776     if(startPos.x() > endPos.x())
    777       angle += M_PI;
    778   }
    779 
    780   qreal m11, m12, m13, m21, m22, m23, m31, m32, m33;
    781 
    782   m11 = cos(angle);
    783   m12 = -sin(angle);
    784   m13 = startPos.x();
    785   m21 = sin(angle);
    786   m22 = cos(angle);
    787   m23 = startPos.y();
    788   m31 = 0;
    789   m32 = 0;
    790   m33 = 1;
    791 
    792   QTransform t1(m11, m12, m13, m21, m22, m23, m31, m32, m33);
    793   QTransform t2(xA, 1, 1, yA, 1, 1, 1, 1, 1);
    794   QTransform t3 = t1 * t2;
    795 
    796   QPolygonF polygon;
    797   polygon << startPos;
    798   polygon << QPointF(t3.m11(), t3.m21());
    799 
    800   t2.setMatrix(xB, 1, 1, yB, 1, 1, 1, 1, 1);
    801   t3 = t1 * t2;
    802 
    803   polygon << QPointF(t3.m11(), t3.m21());
    804   polygon << startPos;
    805 
    806   return polygon;
    807 }
     542    endComponentName = QString(endComponentName).append("[").append(mpEndComponentTextBox->text()).append("]");
     543  }
     544  else
     545  {
     546    endComponentName = QString(mpConnectionLineAnnotation->getEndComponent()->getParentComponent()->getName()).append(".")
     547        .append(mpConnectionLineAnnotation->getEndComponent()->getName());
     548  }
     549  mpGraphicsView->createConnection(startComponentName, endComponentName);
     550  accept();
     551}
     552
     553void ConnectionArray::cancelArrayIndex()
     554{
     555  mpGraphicsView->removeConnection();
     556  reject();
     557}
Note: See TracChangeset for help on using the changeset viewer.