コード例 #1
0
void RaceViewer::cutLaps(void)
{
    this->mLaps.clear();

    QList<QGraphicsItem*> items = marker->collidingItems(Qt::IntersectsItemShape);
    QList<QGraphicsLineItem*> segments;

    foreach(QGraphicsItem* item, items)
    {
        QGraphicsLineItem* segment = qgraphicsitem_cast<QGraphicsLineItem*>(item);

        if (segment != NULL)
        {
            QList<QGraphicsLineItem*>::iterator it = segments.begin();
            bool found(false);

            while (it != segments.end() && ! found)
            {
                if ((*it)->data(0).toInt() >= segment->data(0).toInt())
                    found = true;
                else
                    it++;
            }

            segments.insert(it, segment);
        }
    }
コード例 #2
0
ファイル: GraphViewer.cpp プロジェクト: vfdev-5/GraphToolsApp
bool GraphViewer::setupGraph(GT::Graph * graph)
{
    if (!graph)
        return false;

    graph->vertices.resize(_vertices.size());
    for (int i=0;i<graph->vertices.size();i++)
    {
        graph->vertices[i].id = _vertices[i]->data(KEY_VERTEX_ID).toInt();
    }

    // Factor 2 due to the undirected visual graph representation
    QVector<GT::Edge> edges(2*_edges.size());
    for (int i=0; i< _edges.size(); i++)
    {
        QGraphicsLineItem * edge = _edges[i];
        int vertexIndex1 = edge->data(KEY_EDGE_VERTEX1).toInt();
        int vertexIndex2 = edge->data(KEY_EDGE_VERTEX2).toInt();
        int weight = edge->data(KEY_EDGE_WEIGHT).toInt();

        if (weight < 0)
        {
            std::cerr << "Weights should not negative for undirected graphs" << std::endl;
            return false;
        }

        edges[2*i].a = &graph->vertices[vertexIndex1];
        edges[2*i].b = &graph->vertices[vertexIndex2];
        edges[2*i].weight = weight;

        edges[2*i+1].a = &graph->vertices[vertexIndex2];
        edges[2*i+1].b = &graph->vertices[vertexIndex1];
        edges[2*i+1].weight = weight;

    }


    graph->setEdges(edges);

    if (graph->vertices.isEmpty())
        return false;

    return true;
}
コード例 #3
0
ファイル: GraphViewer.cpp プロジェクト: vfdev-5/GraphToolsApp
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());

        }

    }
}