current position:Home>Why is it not displayed in graphicsview

Why is it not displayed in graphicsview

2022-02-02 14:33:23 CSDN Q & A

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
  
  
  
  
    ui->setupUi(this);
    myView = new Graphics_view_zoom(ui->graphicsView);
    myView->set_modifiers(Qt::NoModifier);
    ui->graphicsView->setRenderHint(QPainter::Antialiasing);
 
    scene=new QGraphicsScene;
    scene->setSceneRect(-LINE_INFO_WIDTH,0,SCENE_WIDTH,SCENE_HEIGHT);
    ui->graphicsView->setScene(scene);
    ui->graphicsView->setDragMode(QGraphicsView::ScrollHandDrag);
 
    busGraph=new BusGraph;
    busGraph->readFileData(":/data/data/outline.txt");
 
    myConnect();
    initBusLine();
    on_actionLineMap_triggered();
}
// Draw the edges of the network diagram 
void MainWindow::drawEdges(myvector<edge>& edgesList)
{
  
  
  
  
    for(int i=0; i<edgesList.getlength(); ++i)
    {
  
  
  
  
        int s1=edgesList[i].s1;
        int s2=edgesList[i].s2;
 
        myvector<int> linesList=busGraph->getCommonLines(s1, s2);
        QColor color=getLinesColor(linesList);
        QString tip=" Via : "+busGraph->getStationName(s1)+"--"+busGraph->getStationName(s2)+"\n line :";
        tip+=getLinesName(linesList);
        QPointF s1Pos=transferCoord(busGraph->getStationCoord(s1));
        QPointF s2Pos=transferCoord(busGraph->getStationCoord(s2));
 
        QGraphicsLineItem* edgeItem=new QGraphicsLineItem;
        edgeItem->setPen(QPen(color, EDGE_PEN_WIDTH));
        edgeItem->setCursor(Qt::PointingHandCursor);
        edgeItem->setToolTip(tip);
        edgeItem->setPos(s1Pos);
        edgeItem->setLine(0, 0, s2Pos.x()-s1Pos.x(), s2Pos.y()-s1Pos.y());
        scene->addItem(edgeItem);
    }
}
 
// The site node that draws the network diagram 
void MainWindow::drawStations (myvector<int>& stationsList)
{
  
  
  
  
    for (int i=0; i<stationsList.getlength(); ++i)
    {
  
  
  
  
        int s=stationsList[i];
        QString name=busGraph->getStationName(s);
        myvector<int> linesList=busGraph->getStationLinesInfo(s);
        QColor color=getLinesColor(linesList);
        QPointF longiLati=busGraph->getStationCoord(s);
        QPointF coord=transferCoord(longiLati);
        QString tip=" Station name :  "+name+"\n"+
                " longitude :  "+QString::number(longiLati.x(),'f',7)+"\n"+
                " latitude :  "+QString::number(longiLati.y(),'f',7)+"\n"+
                " line :"+getLinesName(linesList);
 
        QGraphicsEllipseItem* stationItem=new QGraphicsEllipseItem;
        stationItem->setRect(-NODE_HALF_WIDTH, -NODE_HALF_WIDTH, NODE_HALF_WIDTH<<1, NODE_HALF_WIDTH<<1);
        stationItem->setPos(coord);
        stationItem->setPen(color);
        stationItem->setCursor(Qt::PointingHandCursor);
        stationItem->setToolTip(tip);
 
        if(linesList.getlength()<=1)
        {
  
  
  
  
            stationItem->setBrush(QColor(QRgb(0xffffff)));
        }
        scene->addItem(stationItem);
 
        QGraphicsTextItem* textItem=new QGraphicsTextItem;
        textItem->setPlainText(name);
        textItem->setFont(QFont("consolas",4,1));
        textItem->setPos(coord.x(),coord.y()-NODE_HALF_WIDTH*2);
        scene->addItem(textItem);
        qDebug()<<""<<textItem;
    }
}
// Action view all circuit diagram slot functions 
void MainWindow::on_actionLineMap_triggered()
{
  
  
  
  
    scene->clear();
    myvector<int> stationsList;
    myvector<edge> edgesList;
    busGraph->getGraph(stationsList,edgesList);
    drawEdges(edgesList);
    drawStations(stationsList);
}
 

copyright notice
author[CSDN Q & A],Please bring the original link to reprint, thank you.
https://en.primo.wiki/2022/02/202202021433207280.html

Random recommended