示例#1
0
void GraphViewer::onValueEdited()
{
    bool ok=false;
    int newvalue = _valueEditor.text().toInt(&ok);
    if (ok)
    {

        if (qgraphicsitem_cast<QGraphicsSimpleTextItem*>(_editedItem))
        {
            QGraphicsSimpleTextItem* text = qgraphicsitem_cast<QGraphicsSimpleTextItem*>(_editedItem);
            text->setText(QString("%1").arg(newvalue));
            QGraphicsItem* parent = text->parentItem();
            if (parent)
            {
                parent->setData(KEY_EDGE_WEIGHT, newvalue);
            }
            _valueEditor.hide();
        }

    }
}
示例#2
0
void GraphViewer::onSceneMouseDoubleClick(QGraphicsSceneMouseEvent *mouseEvent)
{
    QGraphicsItem * item = _scene.itemAt(mouseEvent->scenePos(), QTransform());
    QGraphicsSimpleTextItem* text = qgraphicsitem_cast<QGraphicsSimpleTextItem*>(item);

    // Modify edge weight
    if (text)
    {
        QGraphicsLineItem* edge = qgraphicsitem_cast<QGraphicsLineItem*>(text->parentItem());
        if (edge)
        { // text is edge weight

            _editedItem = text;

            int weight = edge->data(KEY_EDGE_WEIGHT).toInt();
            _valueEditor.setText(QString("%1").arg(weight));
            _valueEditor.show();
            _valueEditor.resize(20,_valueEditor.height());
            _valueEditor.move(mouseEvent->screenPos());

        }

    }
}