void OutputCalibrationPage::setupVehicleItems()
{
    m_vehicleItems.clear();
    m_vehicleBoundsItem = new QGraphicsSvgItem();
    m_vehicleBoundsItem->setSharedRenderer(m_vehicleRenderer);
    m_vehicleBoundsItem->setElementId(m_vehicleElementIds[0]);
    m_vehicleBoundsItem->setZValue(-1);
    m_vehicleBoundsItem->setOpacity(0);
    m_vehicleScene->addItem(m_vehicleBoundsItem);

    QRectF parentBounds = m_vehicleRenderer->boundsOnElement(m_vehicleElementIds[0]);

    for (int i = 1; i < m_vehicleElementIds.size(); i++) {
        QGraphicsSvgItem *item = new QGraphicsSvgItem();
        item->setSharedRenderer(m_vehicleRenderer);
        item->setElementId(m_vehicleElementIds[i]);
        item->setZValue(i);
        item->setOpacity(1.0);

        QRectF itemBounds = m_vehicleRenderer->boundsOnElement(m_vehicleElementIds[i]);
        item->setPos(itemBounds.x() - parentBounds.x(), itemBounds.y() - parentBounds.y());

        m_vehicleScene->addItem(item);
        m_vehicleItems << item;
    }
}
void ConnectionDiagram::setupGraphicsSceneItems(QList<QString> elementsToShow)
{
    qreal z = 0;
    QRectF backgBounds = m_renderer->boundsOnElement("background");

    foreach(QString elementId, elementsToShow) {
        if (m_renderer->elementExists(elementId)) {
            QGraphicsSvgItem *element = new QGraphicsSvgItem();
            element->setSharedRenderer(m_renderer);
            element->setElementId(elementId);
            element->setZValue(z++);
            element->setOpacity(1.0);

            QMatrix matrix = m_renderer->matrixForElement(elementId);
            QRectF orig    = matrix.mapRect(m_renderer->boundsOnElement(elementId));
            element->setPos(orig.x(), orig.y());

            // QRectF orig = m_renderer->boundsOnElement(elementId);
            // element->setPos(orig.x() - backgBounds.x(), orig.y() - backgBounds.y());

            m_scene->addItem(element);
            qDebug() << "Adding " << elementId << " to scene at " << element->pos();
        } else {
            qDebug() << "Element with id: " << elementId << " not found.";
        }
    }
}
Exemple #3
0
void ScriptWidget::loadSvgFile(const QString & file) 
{
  
  if (!file.isEmpty())
  {
      clearSvgItems();
      qDebug("Loading file %s",qPrintable(file)); 
      m_renderer = new QSvgRenderer(file);
      int zBuffer = 0; 
      foreach (QString itemName, m_items)
      {
        QGraphicsSvgItem * g = new QGraphicsSvgItem();
        Item * item = new Item(g,this);  
        item->setObjectName(itemName); 
        g->setElementId(itemName); 
        g->setSharedRenderer(m_renderer); 
        g->setZValue(zBuffer++); 
        m_scene->addItem(g); 
        qDebug("item %s",qPrintable(itemName));
      }
QGraphicsSvgItem* GraphicsWorkflow::addAllSvgItems( const QString& name,  const QMap<int,QString>& cmds) {


     QGraphicsSvgItem *myitem = NULL;

     if ( myitem == NULL  ) {

         QByteArray myxml = SafetYAWL::readStringFromFile(name);
          QMap<QString,QPair<QPointF,QString> > ids = getXmlIds(myxml);

          QString curtitle = SafetYAWL::getConf()["GeneralOptions/currentflowtitle"];
         // qDebug(".......curtitle: |%s|", qPrintable(curtitle));
          QGraphicsTextItem* titleitem = NULL;
          QString includetitle = SafetYAWL::getConf()["GeneralOptions/currentflowtitle.include"];
          qDebug("includetitle: %s", qPrintable(includetitle));

          if ( includetitle.compare("on") == 0 ) {
            titleitem = NULL;
            addInfoGraphText(ids,curtitle,titleitem);
            if ( titleitem ) {
                _items.append(titleitem);
            }

          }
          QString includedate = SafetYAWL::getConf()["Graphs/infotext.include"];

          if ( includedate.compare("on") == 0 ) {
              SYD << tr("QGraphicsTextItem* myitem = addInfoGraphDateText(ids);");
              QGraphicsTextItem* myitem = addInfoGraphDateText(ids);
              if ( myitem) {
                  _items.append(myitem);
              }

          }


          QMap<QString,QString>  svgs = extractSvgElements(myxml);
            for(int i =0; i < svgs.keys().count(); i++) {
                QString key = svgs.keys().at(i);
                QString svg = svgs[ key];
                GraphicsSvgItemLive localitem(svg);
                myitem = localitem.loadSvgItem();
                if ( MainWindow::configurator->getWorkflow() != NULL ) {
                    QString info = MainWindow::configurator->getWorkflow()->infoModeMap()[ids[key].second];
                    if (key.startsWith("node")) {
                        myitem->setToolTip(tr("%1").arg(info));
                    }
                }
                myitem->setFlags(QGraphicsItem::ItemClipsToShape| QGraphicsItem::ItemIsMovable);
                myitem->setCacheMode(QGraphicsItem::NoCache);
                myitem->setZValue(0);                

                scene()->addItem(myitem);

                myitem->setPos(ids[key].first);
                _items.append(myitem);
            }

      }
     else {
          //QSvgRenderer *renderer = new QSvgRenderer(name);
     }
     qDebug("...addAllSvgItems..........(6)...");
     SafetYAWL::streamlog << SafetLog::Action
             << tr("Gráfico de \"Flujo de Trabajo\" generado correctamente...ok!");
     doGroup();
     SafetYAWL::streamlog << SafetLog::Action
             << tr("Agrupando Nodos...ok!");

     return myitem;
}
void OutputCalibrationPage::setupVehicleItems()
{
    m_vehicleItems.clear();
    m_arrowsItems.clear();
    m_vehicleBoundsItem = new QGraphicsSvgItem();
    m_vehicleBoundsItem->setSharedRenderer(m_vehicleRenderer);
    m_vehicleBoundsItem->setElementId(m_vehicleElementIds[0]);
    m_vehicleBoundsItem->setZValue(-1);
    m_vehicleBoundsItem->setOpacity(0);
    m_vehicleScene->addItem(m_vehicleBoundsItem);

    QRectF parentBounds = m_vehicleRenderer->boundsOnElement(m_vehicleElementIds[0]);

    for (int i = 1; i < m_vehicleElementIds.size(); i++) {
        QGraphicsSvgItem *item = new QGraphicsSvgItem();
        item->setSharedRenderer(m_vehicleRenderer);
        item->setElementId(m_vehicleElementIds[i]);
        item->setZValue(i);
        item->setOpacity(1.0);

        QRectF itemBounds = m_vehicleRenderer->boundsOnElement(m_vehicleElementIds[i]);
        item->setPos(itemBounds.x() - parentBounds.x(), itemBounds.y() - parentBounds.y());

        m_vehicleScene->addItem(item);
        m_vehicleItems << item;

        bool addArrows = false;

        if ((m_vehicleElementIds[i].contains("left")) || (m_vehicleElementIds[i].contains("right"))
            || (m_vehicleElementIds[i].contains("elevator")) || (m_vehicleElementIds[i].contains("rudder"))
            || (m_vehicleElementIds[i].contains("steering")) || (m_vehicleElementIds[i] == "singleaileron-aileron")) {
            addArrows = true;
        }

        if (addArrows) {
            QString arrowUp   = "-up"; // right if rudder / steering
            QString arrowDown = "-down"; // left

            QGraphicsSvgItem *itemUp = new QGraphicsSvgItem();

            itemUp->setSharedRenderer(m_vehicleRenderer);
            QString elementUp = m_vehicleElementIds[i] + arrowUp;
            itemUp->setElementId(elementUp);
            itemUp->setZValue(i + 10);
            itemUp->setOpacity(0);

            QRectF itemBounds = m_vehicleRenderer->boundsOnElement(elementUp);
            itemUp->setPos(itemBounds.x() - parentBounds.x(), itemBounds.y() - parentBounds.y());
            m_vehicleScene->addItem(itemUp);

            m_arrowsItems << itemUp;

            QGraphicsSvgItem *itemDown = new QGraphicsSvgItem();
            itemDown->setSharedRenderer(m_vehicleRenderer);
            QString elementDown = m_vehicleElementIds[i] + arrowDown;
            itemDown->setElementId(elementDown);
            itemDown->setZValue(i + 10);
            itemDown->setOpacity(0);

            itemBounds = m_vehicleRenderer->boundsOnElement(elementDown);
            itemDown->setPos(itemBounds.x() - parentBounds.x(), itemBounds.y() - parentBounds.y());
            m_vehicleScene->addItem(itemDown);

            m_arrowsItems << itemDown;
        }
    }
}