コード例 #1
0
void DiagramScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent)
{
    if (line != 0 && myMode == InsertLine)
    {
        QList<QGraphicsItem *> startItems = items(line->line().p1());
        if (startItems.count() && startItems.first() == line)
            startItems.removeFirst();
        QList<QGraphicsItem *> endItems = items(line->line().p2());
        if (endItems.count() && endItems.first() == line)
            endItems.removeFirst();

        removeItem(line);
        delete line;

        if (startItems.count() > 0 && endItems.count() > 0 &&
                startItems.first()->type() == Connector::Type &&
                endItems.first()->type() == Connector::Type &&
                startItems.first() != endItems.first())
        {
            Connector *startItem =
                    qgraphicsitem_cast<Connector *>(startItems.first());
            Connector *endItem =
                    qgraphicsitem_cast<Connector *>(endItems.first());
            QDomNode arrowXml =  createArrowXml(startItem,endItem);
            Arrow *arrow = new Arrow(startItem, endItem,arrowXml);

            arrowList.append(arrow);
            arrow->setColor(myLineColor);
            startItem->addArrow(arrow);
            endItem->addArrow(arrow);
            arrow->setZValue(-1000.0);
            addItem(arrow);
            arrow->updatePosition();

        }
    }

    line = 0;
    QGraphicsScene::mouseReleaseEvent(mouseEvent);
    if(myMode == MoveItem)
    {
        DiagramItem* item =(DiagramItem*)itemAt(mouseEvent->scenePos());
        if(item == 0)
            return;
        if(item->type() == DiagramItem::Type)
            {
                item->updatePoz();
                ((DiagramWindow*)parent())->updateXml();
            }
    }
}
コード例 #2
0
void DiagramScene::loadDiagram()
{
    QDomNodeList lst = projXml->elementsByTagName("item");

    for(int i=0;i<lst.count();i++)
    {
        QDomNode xmlNode = lst.at(i);
        QDomNamedNodeMap attr = xmlNode.attributes();
        int type = attr.namedItem("type").nodeValue().toInt();
        int id = attr.namedItem("id").nodeValue().toInt();
        int diagId = attr.namedItem("diagId").nodeValue().toInt();

        qreal x = attr.namedItem("x").nodeValue().toDouble();
        qreal y = attr.namedItem("y").nodeValue().toDouble();

        DiagramNode nod = ((DiagramWindow*)parent())->searchById(type,id);

        DiagramItem* item = new DiagramItem(((DiagramItem::DiagramType)type),
                                            myItemMenu,
                                            nod.name,
                                            xmlNode,
                                            diagId,
                                            nod.inputs);

        item->setPos(x,y);

        diagItems.append(item);
        addItem(item);
    }

    QDomNodeList lst2 = projXml->elementsByTagName("arrow");

    for(int i=0;i<lst2.count();i++)
    {
        QDomNamedNodeMap attr = lst2.at(i).attributes();

        DiagramItem* startParent =
                getItemById(attr.namedItem("parentInId").nodeValue().toInt());

        DiagramItem* endParent =
                getItemById(attr.namedItem("parentOutId").nodeValue().toInt());

        Connector* start =
                startParent->childAt(attr.namedItem("connectorInId").nodeValue().toInt());

        Connector* end =
                endParent->childAt(attr.namedItem("connectorOutId").nodeValue().toInt());

        Arrow *arrow = new Arrow(start, end,lst2.at(i));
        arrowList.append(arrow);

        arrow->setColor(myLineColor);
        start->addArrow(arrow);
        end->addArrow(arrow);
        addItem(arrow);
        arrow->setZValue(-1000.0);
        arrow->updatePosition();
    }

    for(int i=0;i<diagItems.count();i++)
    {
        diagItems.at(i)->updateId(itemCount);
        itemCount++;
    }
}