将PosPair类独立出来
添加了公交车显示类
This commit is contained in:
29
include/BusWidget.h
Normal file
29
include/BusWidget.h
Normal file
@@ -0,0 +1,29 @@
|
||||
//
|
||||
// Created by ricardo on 2022/6/28.
|
||||
//
|
||||
|
||||
#ifndef AUTO_BUS_GUI_BUS_WIDGET_H
|
||||
#define AUTO_BUS_GUI_BUS_WIDGET_H
|
||||
#include "QGraphicsPixmapItem"
|
||||
#include "QTransform"
|
||||
|
||||
#include "PosPair.h"
|
||||
|
||||
class BusWidget
|
||||
{
|
||||
public:
|
||||
QGraphicsPixmapItem *item;
|
||||
|
||||
|
||||
explicit BusWidget();
|
||||
|
||||
~BusWidget();
|
||||
|
||||
void ResetBusPos(PosPair *s);
|
||||
|
||||
private:
|
||||
PosPair *pos_pairs = nullptr;
|
||||
};
|
||||
|
||||
|
||||
#endif //AUTO_BUS_GUI_BUS_WIDGET_H
|
59
include/PosPair.h
Normal file
59
include/PosPair.h
Normal file
@@ -0,0 +1,59 @@
|
||||
//
|
||||
// Created by ricardo on 2022/6/28.
|
||||
//
|
||||
|
||||
#ifndef AUTO_BUS_GUI_POSPAIR_H
|
||||
#define AUTO_BUS_GUI_POSPAIR_H
|
||||
|
||||
/**
|
||||
* 储存每个站点位置的类
|
||||
*/
|
||||
class PosPair{
|
||||
|
||||
public:
|
||||
/*
|
||||
* 站点位置的x坐标
|
||||
*/
|
||||
int pos_x;
|
||||
/**
|
||||
* 站点位置的y坐标
|
||||
*/
|
||||
int pos_y;
|
||||
|
||||
PosPair();
|
||||
/**
|
||||
* 获取两个站点之间的距离
|
||||
* @param stop_number 站点的数量
|
||||
* @return 站点之间的距离
|
||||
*/
|
||||
int GetStopSpaceLength(int stop_number) const;
|
||||
|
||||
/**
|
||||
* 加上一定的距离
|
||||
* @param length 需要加上的距离
|
||||
*/
|
||||
void AddLength(int length);
|
||||
|
||||
/**
|
||||
* 获得该站点公交车停车的位置x坐标
|
||||
* @return
|
||||
*/
|
||||
int GetBusPosX() const;
|
||||
|
||||
/**
|
||||
* 获得该站点公交车停车位置的y坐标
|
||||
* @return
|
||||
*/
|
||||
int GetBusPosY() const;
|
||||
|
||||
private:
|
||||
const int stop_begin_x = 100;
|
||||
const int stop_begin_y = 80;
|
||||
const int stop_rail_width = 300;
|
||||
const int stop_rail_height = 200;
|
||||
const int stop_bus_distance = 30;
|
||||
|
||||
int distance = 0;
|
||||
};
|
||||
|
||||
#endif //AUTO_BUS_GUI_POSPAIR_H
|
@@ -8,56 +8,8 @@
|
||||
#include "QGraphicsScene"
|
||||
#include "QGraphicsPixmapItem"
|
||||
|
||||
/**
|
||||
* 储存每个站点位置的类
|
||||
*/
|
||||
class PosPair{
|
||||
|
||||
public:
|
||||
/*
|
||||
* 站点位置的x坐标
|
||||
*/
|
||||
int pos_x;
|
||||
/**
|
||||
* 站点位置的y坐标
|
||||
*/
|
||||
int pos_y;
|
||||
|
||||
PosPair();
|
||||
/**
|
||||
* 获取两个站点之间的距离
|
||||
* @param stop_number 站点的数量
|
||||
* @return 站点之间的距离
|
||||
*/
|
||||
int GetStopSpaceLength(int stop_number) const;
|
||||
|
||||
/**
|
||||
* 加上一定的距离
|
||||
* @param length 需要加上的距离
|
||||
*/
|
||||
void AddLength(int length);
|
||||
|
||||
/**
|
||||
* 获得该站点公交车停车的位置x坐标
|
||||
* @return
|
||||
*/
|
||||
int GetBusPosX() const;
|
||||
|
||||
/**
|
||||
* 获得该站点公交车停车位置的y坐标
|
||||
* @return
|
||||
*/
|
||||
int GetBusPosY() const;
|
||||
|
||||
private:
|
||||
const int stop_begin_x = 100;
|
||||
const int stop_begin_y = 80;
|
||||
const int stop_rail_width = 300;
|
||||
const int stop_rail_height = 200;
|
||||
const int stop_bus_distance = 20;
|
||||
|
||||
int distance = 0;
|
||||
};
|
||||
#include "PosPair.h"
|
||||
#include "BusWidget.h"
|
||||
|
||||
class SceneManager
|
||||
{
|
||||
@@ -82,11 +34,17 @@ private:
|
||||
* 显示站点的像素图对象
|
||||
*/
|
||||
QGraphicsPixmapItem *pixmap_items;
|
||||
|
||||
/**
|
||||
* 每个站点的所在位置
|
||||
*/
|
||||
PosPair *stop_pos_pairs;
|
||||
|
||||
/**
|
||||
* 公交车对象
|
||||
*/
|
||||
BusWidget *bus;
|
||||
|
||||
/**
|
||||
* 总共的站点数量
|
||||
*/
|
||||
@@ -101,7 +59,7 @@ private:
|
||||
/**
|
||||
* 清除画面
|
||||
*/
|
||||
void ClearScene();
|
||||
void ClearStopScene();
|
||||
};
|
||||
|
||||
#endif //AUTO_BUS_GUI_MAIN_SCENE_H
|
||||
|
Reference in New Issue
Block a user