数据结构实验7:校园地图导航(QT版)

要求

地图不低于五个点
可以在代码里设置好点名,路径,路径权重
程序运行,输入两个点,输出最短距离及最短路径
加分项:可视化地图 QT

项目地址

https://github.com/adventurer-w/OUCmap

代码

mainwindow.h

#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QVector>
#include "wangziyi.h"
#include <QMap>
#include <QRadioButton>

QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    int c=4;
    int distance[25];
    int distance1[25][25];
    QString display;
    QString colors[25][25];
    QRadioButton *mpb[25];
    MainWindow(QWidget *parent = nullptr);
    void place_onclick(QRadioButton *btn);
    void init();
    void floyd_print(int dis[25][25],int i,int j);
    ~MainWindow();

protected:
   void paintEvent(QPaintEvent *);

private slots:
   void on_btn_dijkstra_clicked();
   void on_btn_floyd_clicked();
   void on_btn_clean_clicked();
    void on_btn_cailiao_clicked();
    void on_btn_dongcao_clicked();
    void on_btn_beichan_clicked();
    void on_btn_sijiao_clicked();
    void on_btn_wujiao_clicked();
    void on_btn_beicao_clicked();
    void on_btn_diyuan_clicked();
    void on_btn_gongyuan_clicked();
    void on_btn_huayuan_clicked();
    void on_btn_xinbei_clicked();
    void on_btn_xinnan_clicked();
    void on_btn_houqin_clicked();
    void on_btn_wuziding_clicked();
    void on_btn_wenxin_clicked();
    void on_btn_haiyang_clicked();
    void on_btn_haike_clicked();
    void on_btn_tiyuguan_clicked();
    void on_btn_liujiao_clicked();
    void on_btn_tushuguan_clicked();
    void on_btn_xinzilou_clicked();
    void on_btn_shuyuan_clicked();
    void on_btn_zhengfa_clicked();

private:
    Ui::MainWindow *ui;
    wangziyi *shortes;
};
#endif // MAINWINDOW_H

wangziyi.h

#ifndef WANGZIYI_H
#define WANGZIYI_H
#include <QString>
#include <QVector>
#include <QMap>

typedef struct Arccell
{
    int path;
} Matrix[25][25];

typedef struct
{
    QString places[25];
    Matrix arcs;
    int vexnum, arcnum;
}Graph;

class wangziyi
{
public:
    wangziyi();
    Graph G;
    QVector<QPair<int,QPair<int,int> > > List;
    QMap<QString,int> mp;


    QString starcity;
    QString overcity;
    int st;
    int ed;
};

#endif // WANGZIYI_H

main.cpp

#include "mainwindow.h"

#include <QApplication>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow w;
    w.show();
    return a.exec();
}

mainwindow.cpp

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include<QString>
#include <QPainter>
#include<QTime>

void sleep(unsigned int msec)
{
    QTime dieTime = QTime::currentTime().addMSecs(msec);
    while( QTime::currentTime() < dieTime )
        QCoreApplication::processEvents(QEventLoop::AllEvents, 100);
}

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    this->shortes=new wangziyi;
    for(int i=0;i<25;i++)
    {
        for(int j=0;j<25;j++)
        {
            colors[i][j]="lightGray";
        }
    }

    mpb[0]= ui->btn_beicao;
    mpb[1]= ui->btn_tiyuguan;
    mpb[2]=ui->btn_beichan;
    mpb[3]=ui->btn_haike;
    mpb[4]=ui->btn_sijiao;
    mpb[5]=ui->btn_dongcao;
    mpb[6]=ui->btn_wujiao;
    mpb[7]=ui->btn_liujiao;
    mpb[8]=ui->btn_gongyuan;
    mpb[9]=ui->btn_haiyang;
    mpb[10]=ui->btn_wuziding;
    mpb[11]=ui->btn_huayuan;
    mpb[12]=ui->btn_xinbei;
    mpb[13]=ui->btn_cailiao;
    mpb[14]=ui->btn_xinnan;
    mpb[15]=ui->btn_diyuan;
    mpb[16]=ui->btn_xinzilou;
    mpb[17]=ui->btn_tushuguan;
    mpb[18]=ui->btn_zhengfa;
    mpb[19]=ui->btn_houqin;
    mpb[20]=ui->btn_shuyuan;
    mpb[21]=ui->btn_wenxin;

}
void MainWindow::init(){

    for(auto x:this->shortes->List){
        int nw=x.first,nx=x.second.first,dis=x.second.second;
        QPen pen;
        QPainter painter(this);
        pen.setWidth(5);
        pen.setColor(colors[nw][nx]);
        painter.setRenderHint(QPainter::Antialiasing, true); // 反走样
        painter.setPen(pen);
        painter.drawLine(QPointF(mpb[nw]->x()+7,mpb[nw]->y()+7), QPointF(mpb[nx]->x()+7, mpb[nx]->y()+7));// 绘制直线

        pen.setColor("Purple");
        painter.setPen(pen);
        painter.drawText(QPointF((mpb[nw]->x()+mpb[nx]->x())/2,(mpb[nw]->y()+mpb[nx]->y())/2),QString::number(dis));
    }
}
void MainWindow::paintEvent(QPaintEvent *)
{
    QPainter pbk(this);
//    pbk.drawPixmap(30,10,881,701,QPixmap("mymap.jpg"));
    init();
}
MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::floyd_print(int pre[25][25],int i,int j){
    if(i==j) return;
    if(pre[i][j]==0){
        colors[i][j]=colors[j][i]="Blue";
    }else{
        floyd_print(pre,i,pre[i][j]);
        floyd_print(pre,pre[i][j],j);
    }
}
void MainWindow::on_btn_floyd_clicked()
{
    if(this->shortes->starcity == ""||this->shortes->overcity== "") return;
    this->c=1;
    this->ui->btn_floyd->setStyleSheet("background-color: rgb(189, 240, 255);");
    this->ui->btn_dijkstra->setStyleSheet("color: rgb(0, 0, 0);");


    for(int i=0;i<25;i++)
    {
        for(int j=0;j<25;j++)
        {
            colors[i][j]="lightGray";
        }
    }
    update();

    int dis[25][25],pre[25][25];
    memset(pre,0,sizeof (pre));
    for(int i=0;i<=21;i++){
        for(int j=0;j<=21;j++){
            dis[i][j]=this->shortes->G.arcs[i][j].path;
        }
    }

    for(int k=0;k<=21;k++){
        for(int i=0;i<=21;i++){
            for(int j=0;j<=21;j++){
                if(dis[i][j]>dis[i][k]+dis[k][j]){
                    dis[i][j]=dis[i][k]+dis[k][j];
                    pre[i][j]=k;
                }
            }
        }
    }
    floyd_print(pre,this->shortes->st,this->shortes->ed);
    this->ui->label_display->setText("最短距离是:"+QString::number(dis[this->shortes->st][this->shortes->ed]));
}

void MainWindow::on_btn_dijkstra_clicked()
{
    if(this->shortes->starcity == ""||this->shortes->overcity== "") return;
    this->c=0;
    this->ui->btn_dijkstra->setStyleSheet("background-color: rgb(189, 240, 255);");
    this->ui->btn_floyd->setStyleSheet("color: rgb(0, 0, 0);");


    for(int i=0;i<25;i++)
    {
        for(int j=0;j<25;j++)
        {
            colors[i][j]="lightGray";
        }
    }
    update();


    int dis[25],n=22,pre[25];
    bool st[25];
    memset(st,false,sizeof (st));
    memset(dis,0x3f,sizeof (dis));
    memset(pre,0x3f,sizeof (pre));
    dis[this->shortes->st]=0;

    for(int i=0;i<n;i++){
        int t=-1;
        for(int j=0;j<n;j++){
            if(!st[j]&&(t==-1||dis[t]>dis[j]))
                t=j;
        }
        st[t]=true;
        if(pre[t]!=0x3f3f3f3f) colors[t][pre[t]]=colors[pre[t]][t]="lightBlue";
        update();
        sleep(200);

        for(auto x:this->shortes->List){
            int nw=x.first,j=x.second.first,tt=x.second.second;
            if(j==t){
               j^=nw;nw^=j;j^=nw;
            }
            if(nw==t){
                if(dis[j]>=dis[t]+tt){
                    dis[j]=dis[t]+tt;
                    pre[j]=t;
                }
            }
        }
        if(t==this->shortes->ed) break;
    }
    int zd =this->shortes->ed,qd=this->shortes->st;
    while(zd!=qd){
        colors[zd][pre[zd]]=colors[pre[zd]][zd]="Blue";
        zd=pre[zd];
    }
    update();
    this->ui->label_display->setText("最短距离是:"+QString::number(dis[this->shortes->ed]));
}

void MainWindow::on_btn_clean_clicked()
{
    this->c=-1;
    this->ui->btn_floyd->setStyleSheet("color: rgb(0, 0, 0);");
    this->ui->btn_dijkstra->setStyleSheet("color: rgb(0, 0, 0);");
    for(int i=0;i<25;i++)
    {
        for(int j=0;j<25;j++)
        {
            colors[i][j]="lightGray";
        }
    }
    this->ui->label_start->setText("");
    this->ui->label_over->setText("");
    this->ui->label_display->setText("");
    this->shortes->starcity="";
    this->shortes->overcity="";
    update();
}

void MainWindow::place_onclick(QRadioButton *btn){
    int v;
    for(int i=0;i<=23;i++){
        if(mpb[i]==btn){
            v=i;
            break;
        }
    }
    if(this->shortes->starcity==""){
        for(int i=0;i<25;i++)
        {
            for(int j=0;j<25;j++)
            {
                colors[i][j]="lightGray";
            }
        }
        update();
        this->ui->label_start->setText(btn->text());
        this->shortes->starcity=btn->text();
        this->ui->label_over->setText("");
        this->ui->label_display->setText("");
        this->shortes->st=v;
    }else if(this->shortes->starcity==btn->text()||this->shortes->overcity==btn->text()){
        this->ui->label_start->setText("");
        this->shortes->starcity="";

        this->ui->label_over->setText("");
        this->shortes->overcity="";

        this->ui->label_display->setText("");
    }else{
        for(int i=0;i<25;i++)
        {
            for(int j=0;j<25;j++)
            {
                colors[i][j]="lightGray";
            }
        }
        update();
        this->ui->label_over->setText(btn->text());
        this->shortes->overcity=btn->text();
        this->ui->label_display->setText("");
        this->shortes->ed=v;
    }
    btn->setAutoExclusive(false);
    btn->setChecked(false);
}

void MainWindow::on_btn_cailiao_clicked(){
    place_onclick(ui->btn_cailiao);
}
void MainWindow::on_btn_dongcao_clicked(){
place_onclick(ui->btn_dongcao);
}
void MainWindow::on_btn_beichan_clicked(){
place_onclick(ui->btn_beichan);
}
void MainWindow::on_btn_sijiao_clicked(){
place_onclick(ui->btn_sijiao);
}
void MainWindow::on_btn_wujiao_clicked(){
    place_onclick(ui->btn_wujiao);
}
void MainWindow::on_btn_beicao_clicked(){
place_onclick(ui->btn_beicao);
}
void MainWindow::on_btn_diyuan_clicked(){
place_onclick(ui->btn_diyuan);
}
void MainWindow::on_btn_gongyuan_clicked(){
place_onclick(ui->btn_gongyuan);
}
void MainWindow::on_btn_huayuan_clicked(){
place_onclick(ui->btn_huayuan);
}
void MainWindow::on_btn_xinbei_clicked(){
place_onclick(ui->btn_xinbei);
}
void MainWindow::on_btn_xinnan_clicked(){
place_onclick(ui->btn_xinnan);
}
void MainWindow::on_btn_houqin_clicked(){
place_onclick(ui->btn_houqin);
}
void MainWindow::on_btn_wuziding_clicked(){
place_onclick(ui->btn_wuziding);
}
void MainWindow::on_btn_wenxin_clicked(){
place_onclick(ui->btn_wenxin);
}
void MainWindow::on_btn_haiyang_clicked(){
place_onclick(ui->btn_haiyang);
}
void MainWindow::on_btn_haike_clicked(){
place_onclick(ui->btn_haike);
}
void MainWindow::on_btn_tiyuguan_clicked(){
place_onclick(ui->btn_tiyuguan);
}
void MainWindow::on_btn_liujiao_clicked(){
place_onclick(ui->btn_liujiao);
}
void MainWindow::on_btn_tushuguan_clicked(){
place_onclick(ui->btn_tushuguan);
}
void MainWindow::on_btn_xinzilou_clicked(){
place_onclick(ui->btn_xinzilou);
}
void MainWindow::on_btn_shuyuan_clicked(){
place_onclick(ui->btn_shuyuan);
}
void MainWindow::on_btn_zhengfa_clicked(){
place_onclick(ui->btn_zhengfa);
}




wangziyi.cpp

#include "wangziyi.h"
#include "cstring"

wangziyi::wangziyi()
{
    starcity="";
    overcity="";
    G.arcnum = 20;
    G.vexnum = 22;

    G.places[0]="beichan";mp["beichan"]=0;
    G.places[1]="tiyuguan";mp["tiyuguan"]=1;
    G.places[2]="beichan";mp["beichan"]=2;
    G.places[3]="haike";mp["haike"]=3;
    G.places[4]="sijiao";mp["sijiao"]=4;
    G.places[5]="dongcao";mp["dongcao"]=5;
    G.places[6]="wujiao";mp["wujiao"]=6;
    G.places[7]="liujiao";mp["liujiao"]=7;
    G.places[8]="gongyuan";mp["gongyuan"]=8;
    G.places[9]="haiyang";mp["haiyang"]=9;
    G.places[10]="wuziding";mp["wuziding"]=10;
    G.places[11]="huayuan";mp["huayuan"]=11;
    G.places[12]="xinbei";mp["xinbei"]=12;
    G.places[13]="cailiao";mp["cailiao"]=13;
    G.places[14]="xinnan";mp["xinnan"]=14;
    G.places[15]="diyuan";mp["diyuan"]=15;
    G.places[16]="xinzilou";mp["xinzilou"]=16;
    G.places[17]="tushuguan";mp["tushuguan"]=17;
    G.places[18]="zhengfa";mp["zhengfa"]=18;
    G.places[19]="houqin";mp["houqin"]=19;
    G.places[20]="shuyuan";mp["shuyuan"]=20;
    G.places[21]="wenxin";mp["wenxin"]=21;

    List.push_back({0,{1,81}});List.push_back({0,{2,192}});
    List.push_back({1,{3,108}});List.push_back({1,{4,168}});
    List.push_back({2,{5,211}});List.push_back({3,{4,120}});
    List.push_back({4,{6,89}});List.push_back({2,{4,213}});
    List.push_back({5,{10,295}});List.push_back({6,{7,92}});
    List.push_back({18,{14,323}});List.push_back({7,{12,180}});
    List.push_back({7,{10,360}});List.push_back({7,{9,178}});
    List.push_back({8,{11,123}});List.push_back({8,{9,70}});
    List.push_back({9,{12,80}});List.push_back({9,{13,138}});
    List.push_back({10,{12,330}});List.push_back({11,{13,72}});
    List.push_back({12,{13,136}});List.push_back({12,{14,79}});
    List.push_back({13,{15,128}});List.push_back({14,{17,284}});
    List.push_back({14,{16,395}});List.push_back({16,{17,320}});
    List.push_back({17,{20,210}});List.push_back({17,{18,220}});
    List.push_back({18,{19,188}});List.push_back({19,{21,180}});

    for(int i=0;i<=21;i++){
        for(int j=0;j<=21;j++){
            G.arcs[i][j].path=999999;
        }
    }
    for(auto x:List){
        int nw=x.first,nx=x.second.first,dis=x.second.second;
        G.arcs[nw][nx].path=G.arcs[nx][nw].path=dis;
    }

}

mainwindow.ui

<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
 <class>MainWindow</class>
 <widget class="QMainWindow" name="MainWindow">
  <property name="geometry">
   <rect>
    <x>0</x>
    <y>0</y>
    <width>1251</width>
    <height>915</height>
   </rect>
  </property>
  <property name="windowTitle">
   <string>OUCmap</string>
  </property>
  <property name="windowIcon">
   <iconset>
    <normaloff>../Shortestpath/timg.jpg</normaloff>../Shortestpath/timg.jpg</iconset>
  </property>
  <property name="styleSheet">
   <string notr="true"/>
  </property>
  <widget class="QWidget" name="centralWidget">
   <widget class="QRadioButton" name="btn_cailiao">
    <property name="geometry">
     <rect>
      <x>280</x>
      <y>440</y>
      <width>121</width>
      <height>31</height>
     </rect>
    </property>
    <property name="font">
     <font>
      <pointsize>11</pointsize>
     </font>
    </property>
    <property name="cursor">
     <cursorShape>CrossCursor</cursorShape>
    </property>
    <property name="text">
     <string>材料学院</string>
    </property>
   </widget>
   <widget class="QRadioButton" name="btn_dongcao">
    <property name="geometry">
     <rect>
      <x>830</x>
      <y>215</y>
      <width>71</width>
      <height>31</height>
     </rect>
    </property>
    <property name="font">
     <font>
      <pointsize>11</pointsize>
     </font>
    </property>
    <property name="cursor">
     <cursorShape>CrossCursor</cursorShape>
    </property>
    <property name="text">
     <string>东操</string>
    </property>
   </widget>
   <widget class="QRadioButton" name="btn_beichan">
    <property name="geometry">
     <rect>
      <x>650</x>
      <y>135</y>
      <width>71</width>
      <height>31</height>
     </rect>
    </property>
    <property name="font">
     <font>
      <pointsize>11</pointsize>
     </font>
    </property>
    <property name="cursor">
     <cursorShape>CrossCursor</cursorShape>
    </property>
    <property name="text">
     <string>北餐</string>
    </property>
   </widget>
   <widget class="QRadioButton" name="btn_sijiao">
    <property name="geometry">
     <rect>
      <x>500</x>
      <y>200</y>
      <width>101</width>
      <height>31</height>
     </rect>
    </property>
    <property name="font">
     <font>
      <pointsize>11</pointsize>
     </font>
    </property>
    <property name="cursor">
     <cursorShape>CrossCursor</cursorShape>
    </property>
    <property name="text">
     <string>四教</string>
    </property>
   </widget>
   <widget class="QRadioButton" name="btn_wujiao">
    <property name="geometry">
     <rect>
      <x>390</x>
      <y>225</y>
      <width>81</width>
      <height>31</height>
     </rect>
    </property>
    <property name="font">
     <font>
      <pointsize>11</pointsize>
     </font>
    </property>
    <property name="cursor">
     <cursorShape>CrossCursor</cursorShape>
    </property>
    <property name="text">
     <string>五教</string>
    </property>
   </widget>
   <widget class="QRadioButton" name="btn_beicao">
    <property name="geometry">
     <rect>
      <x>480</x>
      <y>45</y>
      <width>81</width>
      <height>21</height>
     </rect>
    </property>
    <property name="font">
     <font>
      <pointsize>11</pointsize>
     </font>
    </property>
    <property name="cursor">
     <cursorShape>CrossCursor</cursorShape>
    </property>
    <property name="text">
     <string>北操</string>
    </property>
   </widget>
   <widget class="QRadioButton" name="btn_diyuan">
    <property name="geometry">
     <rect>
      <x>250</x>
      <y>495</y>
      <width>131</width>
      <height>31</height>
     </rect>
    </property>
    <property name="font">
     <font>
      <pointsize>11</pointsize>
     </font>
    </property>
    <property name="cursor">
     <cursorShape>CrossCursor</cursorShape>
    </property>
    <property name="styleSheet">
     <string notr="true"/>
    </property>
    <property name="text">
     <string>地球学院</string>
    </property>
   </widget>
   <widget class="QRadioButton" name="btn_gongyuan">
    <property name="geometry">
     <rect>
      <x>170</x>
      <y>325</y>
      <width>111</width>
      <height>21</height>
     </rect>
    </property>
    <property name="font">
     <font>
      <pointsize>11</pointsize>
     </font>
    </property>
    <property name="cursor">
     <cursorShape>CrossCursor</cursorShape>
    </property>
    <property name="text">
     <string>工院</string>
    </property>
   </widget>
   <widget class="QRadioButton" name="btn_huayuan">
    <property name="geometry">
     <rect>
      <x>170</x>
      <y>425</y>
      <width>81</width>
      <height>21</height>
     </rect>
    </property>
    <property name="font">
     <font>
      <pointsize>11</pointsize>
     </font>
    </property>
    <property name="cursor">
     <cursorShape>CrossCursor</cursorShape>
    </property>
    <property name="text">
     <string>化院</string>
    </property>
   </widget>
   <widget class="QRadioButton" name="btn_xinbei">
    <property name="geometry">
     <rect>
      <x>420</x>
      <y>425</y>
      <width>91</width>
      <height>21</height>
     </rect>
    </property>
    <property name="font">
     <font>
      <pointsize>11</pointsize>
     </font>
    </property>
    <property name="cursor">
     <cursorShape>CrossCursor</cursorShape>
    </property>
    <property name="text">
     <string>信北</string>
    </property>
   </widget>
   <widget class="QRadioButton" name="btn_xinnan">
    <property name="geometry">
     <rect>
      <x>400</x>
      <y>495</y>
      <width>81</width>
      <height>21</height>
     </rect>
    </property>
    <property name="font">
     <font>
      <pointsize>11</pointsize>
     </font>
    </property>
    <property name="cursor">
     <cursorShape>CrossCursor</cursorShape>
    </property>
    <property name="text">
     <string>信南</string>
    </property>
   </widget>
   <widget class="QRadioButton" name="btn_houqin">
    <property name="geometry">
     <rect>
      <x>670</x>
      <y>735</y>
      <width>121</width>
      <height>31</height>
     </rect>
    </property>
    <property name="font">
     <font>
      <pointsize>11</pointsize>
     </font>
    </property>
    <property name="cursor">
     <cursorShape>CrossCursor</cursorShape>
    </property>
    <property name="text">
     <string>后勤宿舍</string>
    </property>
   </widget>
   <widget class="QRadioButton" name="btn_wuziding">
    <property name="geometry">
     <rect>
      <x>630</x>
      <y>365</y>
      <width>131</width>
      <height>31</height>
     </rect>
    </property>
    <property name="font">
     <font>
      <pointsize>11</pointsize>
     </font>
    </property>
    <property name="cursor">
     <cursorShape>CrossCursor</cursorShape>
    </property>
    <property name="text">
     <string>五子顶</string>
    </property>
   </widget>
   <widget class="QRadioButton" name="btn_wenxin">
    <property name="geometry">
     <rect>
      <x>530</x>
      <y>805</y>
      <width>91</width>
      <height>21</height>
     </rect>
    </property>
    <property name="font">
     <font>
      <pointsize>11</pointsize>
     </font>
    </property>
    <property name="cursor">
     <cursorShape>CrossCursor</cursorShape>
    </property>
    <property name="text">
     <string>文新</string>
    </property>
   </widget>
   <widget class="QRadioButton" name="btn_haiyang">
    <property name="geometry">
     <rect>
      <x>280</x>
      <y>365</y>
      <width>171</width>
      <height>31</height>
     </rect>
    </property>
    <property name="font">
     <font>
      <pointsize>11</pointsize>
     </font>
    </property>
    <property name="cursor">
     <cursorShape>CrossCursor</cursorShape>
    </property>
    <property name="text">
     <string>海洋学院</string>
    </property>
   </widget>
   <widget class="QRadioButton" name="btn_haike">
    <property name="geometry">
     <rect>
      <x>300</x>
      <y>175</y>
      <width>121</width>
      <height>31</height>
     </rect>
    </property>
    <property name="font">
     <font>
      <pointsize>11</pointsize>
     </font>
    </property>
    <property name="cursor">
     <cursorShape>CrossCursor</cursorShape>
    </property>
    <property name="text">
     <string>海科楼</string>
    </property>
   </widget>
   <widget class="QRadioButton" name="btn_tiyuguan">
    <property name="geometry">
     <rect>
      <x>390</x>
      <y>105</y>
      <width>121</width>
      <height>31</height>
     </rect>
    </property>
    <property name="font">
     <font>
      <pointsize>11</pointsize>
     </font>
    </property>
    <property name="cursor">
     <cursorShape>CrossCursor</cursorShape>
    </property>
    <property name="text">
     <string>体育馆</string>
    </property>
   </widget>
   <widget class="QRadioButton" name="btn_liujiao">
    <property name="geometry">
     <rect>
      <x>440</x>
      <y>295</y>
      <width>91</width>
      <height>21</height>
     </rect>
    </property>
    <property name="font">
     <font>
      <pointsize>11</pointsize>
     </font>
    </property>
    <property name="cursor">
     <cursorShape>CrossCursor</cursorShape>
    </property>
    <property name="text">
     <string>六教</string>
    </property>
   </widget>
   <widget class="QRadioButton" name="btn_tushuguan">
    <property name="geometry">
     <rect>
      <x>380</x>
      <y>645</y>
      <width>141</width>
      <height>21</height>
     </rect>
    </property>
    <property name="font">
     <font>
      <pointsize>11</pointsize>
     </font>
    </property>
    <property name="cursor">
     <cursorShape>CrossCursor</cursorShape>
    </property>
    <property name="text">
     <string>图书馆</string>
    </property>
   </widget>
   <widget class="QRadioButton" name="btn_xinzilou">
    <property name="geometry">
     <rect>
      <x>100</x>
      <y>590</y>
      <width>131</width>
      <height>31</height>
     </rect>
    </property>
    <property name="font">
     <font>
      <pointsize>11</pointsize>
     </font>
    </property>
    <property name="cursor">
     <cursorShape>CrossCursor</cursorShape>
    </property>
    <property name="text">
     <string>行知楼</string>
    </property>
   </widget>
   <widget class="QRadioButton" name="btn_shuyuan">
    <property name="geometry">
     <rect>
      <x>370</x>
      <y>755</y>
      <width>111</width>
      <height>21</height>
     </rect>
    </property>
    <property name="font">
     <font>
      <pointsize>11</pointsize>
     </font>
    </property>
    <property name="cursor">
     <cursorShape>CrossCursor</cursorShape>
    </property>
    <property name="text">
     <string>数院</string>
    </property>
   </widget>
   <widget class="QRadioButton" name="btn_zhengfa">
    <property name="geometry">
     <rect>
      <x>530</x>
      <y>685</y>
      <width>101</width>
      <height>31</height>
     </rect>
    </property>
    <property name="font">
     <font>
      <pointsize>11</pointsize>
     </font>
    </property>
    <property name="cursor">
     <cursorShape>CrossCursor</cursorShape>
    </property>
    <property name="styleSheet">
     <string notr="true"/>
    </property>
    <property name="text">
     <string>政法楼</string>
    </property>
   </widget>
   <widget class="QWidget" name="layoutWidget">
    <property name="geometry">
     <rect>
      <x>930</x>
      <y>166</y>
      <width>291</width>
      <height>661</height>
     </rect>
    </property>
    <layout class="QVBoxLayout" name="_2" stretch="0,0,0,1,2,2,0">
     <item>
      <widget class="QPushButton" name="btn_dijkstra">
       <property name="sizePolicy">
        <sizepolicy hsizetype="Ignored" vsizetype="Ignored">
         <horstretch>2</horstretch>
         <verstretch>2</verstretch>
        </sizepolicy>
       </property>
       <property name="font">
        <font>
         <pointsize>18</pointsize>
         <weight>75</weight>
         <bold>true</bold>
        </font>
       </property>
       <property name="cursor">
        <cursorShape>OpenHandCursor</cursorShape>
       </property>
       <property name="styleSheet">
        <string notr="true">color: rgb(0, 0, 0);</string>
       </property>
       <property name="text">
        <string>Dijkstra</string>
       </property>
      </widget>
     </item>
     <item>
      <widget class="QPushButton" name="btn_floyd">
       <property name="sizePolicy">
        <sizepolicy hsizetype="Ignored" vsizetype="Ignored">
         <horstretch>2</horstretch>
         <verstretch>2</verstretch>
        </sizepolicy>
       </property>
       <property name="font">
        <font>
         <family>SimSun-ExtB</family>
         <pointsize>18</pointsize>
         <weight>75</weight>
         <bold>true</bold>
        </font>
       </property>
       <property name="cursor">
        <cursorShape>OpenHandCursor</cursorShape>
       </property>
       <property name="styleSheet">
        <string notr="true">color: rgb(0, 0, 0);</string>
       </property>
       <property name="text">
        <string>Floyd</string>
       </property>
      </widget>
     </item>
     <item>
      <widget class="QPushButton" name="btn_clean">
       <property name="font">
        <font>
         <pointsize>18</pointsize>
         <weight>75</weight>
         <bold>true</bold>
        </font>
       </property>
       <property name="text">
        <string>Clean</string>
       </property>
      </widget>
     </item>
     <item>
      <spacer name="verticalSpacer_2">
       <property name="orientation">
        <enum>Qt::Vertical</enum>
       </property>
       <property name="sizeHint" stdset="0">
        <size>
         <width>20</width>
         <height>40</height>
        </size>
       </property>
      </spacer>
     </item>
     <item>
      <layout class="QHBoxLayout" name="horizontalLayout" stretch="2,3">
       <item>
        <widget class="QLabel" name="label_2">
         <property name="font">
          <font>
           <family>Arial Black</family>
           <pointsize>18</pointsize>
           <weight>10</weight>
           <italic>false</italic>
           <bold>false</bold>
          </font>
         </property>
         <property name="styleSheet">
          <string notr="true">font: 87 18pt &quot;Arial Black&quot;;
color: rgb(0, 0, 0);</string>
         </property>
         <property name="text">
          <string>   start:</string>
         </property>
        </widget>
       </item>
       <item>
        <widget class="QLabel" name="label_start">
         <property name="font">
          <font>
           <family>Arial</family>
           <pointsize>20</pointsize>
           <weight>50</weight>
           <italic>false</italic>
           <bold>false</bold>
          </font>
         </property>
         <property name="styleSheet">
          <string notr="true">font: 20pt &quot;Arial&quot;;
color: rgb(85, 170, 255);</string>
         </property>
         <property name="text">
          <string/>
         </property>
        </widget>
       </item>
      </layout>
     </item>
     <item>
      <layout class="QHBoxLayout" name="horizontalLayout_2" stretch="0,3">
       <item>
        <widget class="QLabel" name="label_3">
         <property name="styleSheet">
          <string notr="true">font: 87 18pt &quot;Arial Black&quot;;
color: rgb(0, 0, 0);</string>
         </property>
         <property name="text">
          <string>   end:</string>
         </property>
        </widget>
       </item>
       <item>
        <widget class="QLabel" name="label_over">
         <property name="font">
          <font>
           <family>Arial</family>
           <pointsize>20</pointsize>
           <weight>50</weight>
           <italic>false</italic>
           <bold>false</bold>
          </font>
         </property>
         <property name="styleSheet">
          <string notr="true">font: 20pt &quot;Arial&quot;;
color: rgb(85, 170, 255);</string>
         </property>
         <property name="text">
          <string/>
         </property>
        </widget>
       </item>
      </layout>
     </item>
     <item>
      <widget class="QLabel" name="label_display">
       <property name="styleSheet">
        <string notr="true">font: 18pt &quot;Arial&quot;;
color: rgb(105, 158, 255);</string>
       </property>
       <property name="text">
        <string/>
       </property>
      </widget>
     </item>
    </layout>
   </widget>
   <widget class="QLabel" name="label_4">
    <property name="geometry">
     <rect>
      <x>410</x>
      <y>400</y>
      <width>31</width>
      <height>16</height>
     </rect>
    </property>
    <property name="text">
     <string/>
    </property>
   </widget>
   <widget class="QLabel" name="label_5">
    <property name="geometry">
     <rect>
      <x>930</x>
      <y>0</y>
      <width>249</width>
      <height>161</height>
     </rect>
    </property>
    <property name="font">
     <font>
      <pointsize>12</pointsize>
     </font>
    </property>
    <property name="text">
     <string>使用方法:
先依次点击起点和终点
再选择下方的算法

点击Clean重置</string>
    </property>
   </widget>
  </widget>
  <widget class="QMenuBar" name="menuBar">
   <property name="geometry">
    <rect>
     <x>0</x>
     <y>0</y>
     <width>1251</width>
     <height>26</height>
    </rect>
   </property>
  </widget>
  <widget class="QStatusBar" name="statusBar"/>
 </widget>
 <layoutdefault spacing="6" margin="11"/>
 <resources/>
 <connections/>
</ui>

  • 7
    点赞
  • 65
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
c++/qt写的项目,项目都经测试过,真实可靠,可供自己学习c++/qtQt是一个用标准C++编写的跨平台开发类库,它对标准C++进行了扩展,引入了元对象系统、信号与槽、属性等特性,使应用程序的开发变得更高效。 Qt类库中大量的类以模块形式分类组织的,包括基本模块和扩展模块等。一个模块通常就是一个编程主题,如数据库、图表、网络等。 一、Qt核心特点 1.1.概述 Qt本身并不是一种编程语言,它本质上是一个跨平台的C++开发类库,是用标准C++编写的类库,它为开发GUI应用程序和非GUI应用程序提供了各种类。 Qt对标准C++进行了扩展,引入了一些新概念和功能,例如信号和槽、对象属性等。Qt的元对象编译器(Meta-Object Compiler,MOC)是一个预处理器,在源程序被编译前先将这些Qt特性的程序转换为标准C++兼容的形式,然后再由标准C++编译器进行编译。这就是为什么在使用信号与槽机制的类里,必须添加一个Q_OBJECT宏的原因,只有添加了这个宏,moc才能对类里的信号与槽的代码进行预处理。 Qt Core模块是Qt类库的核心,所有其他模块都依赖于此模块,如果使用qmake来构建项目,Qt Core模块则是被自动加入的。 QtC++语言增加的特性就是在Qt Core模块里实现的,这些扩展特性由Qt的元对象系统实现,包括信号与槽机制、属性系统、动态类型转换等。 1.2.元对象系统 Qt的元对象系统(Meta-Object-System)提供了对象之间通信的信号与槽机制、运行时类型信息和动态属性系统。 元对象系统由以下三个基础组成: 1.QObject类是所有使用元对象系统的类的基类; 2.在一个类的private部分声明Q_OBJECT宏,使得类可以使用元对象的特性,如动态属性、信号与槽。 3.MOC(元对象编译器)为每个QObject的子类提供必要的代码来实现元对象系统的特征。 构建项目时,MOC工具读取C++源文件,当它发现类的定义里有Q_OBJECT宏时,它就会为这个类生成另外一个包含有元对象支持代码的C++源文件,这个生成的源文件连同类的实现文件一起被编译和连接。 除了信号和槽机制外,元对象还提供如下一些功能。 1.QObject::metaObject()函数返回类关联的元对象,元对象类QMetaObject包含了访问元对象的一些接口函数,例如QMetaObject::className()函数可在运行时返回类的名称字符串。 QObject obj=new QPushButton; obj->metaObject()->className(); 2.QMetaObject::newInstance()函数创建类的一个新的实例。 3.QObject::inherits(const charclassName)函数判断一个对象实例是否是名称为className的类或QObject的子类的实例。 1.3.属性系统 1.属性定义 Qt提供一个Q_PROPERTY()宏可以定义属性,它也是属于元对象系统实现的。Qt的属性系统与C++编译器无关,可以用任何标准的C++编译器编译定义了属性的Qt C++程序。 2.属性的使用 不管是否用READ和WRITE定义了接口函数,只要知道属性名称,就可以通过QObject::property()读取属性值,并通过QObject::setProperty()设置属性值。 3.动态属性 QObject::setProperty()函数可以在运行时为类定义一个新的属性,称之为动态属性。动态属性是针对类的实例定义的。 动态属性可以使用QObject::property()查询,就如在类定义里用Q_PROPERTY宏定义的属性一样。 例如,在数据表编辑界面上,一些字段是必填字段,就可以在初始化界面时为这些字段的关联显示组件定义一个新的required属性,并设置值为“true"。 4.类的附加信息 属性系统还有一个宏Q_CLASSINFO(),可以为类的元对象定义”名称——值“信息。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值