读取配置文件后重绘站点图重设下拉栏
修复了释放轨道链表内存空间时未判断指针是否为空的问题 修复了绘制站点图部分站点位置计算错误的问题
This commit is contained in:
parent
48cd806197
commit
54c4521fb2
|
@ -45,9 +45,15 @@ public:
|
|||
* 构造函数,同时生成站点
|
||||
* @param stop_node_number 站点的数量
|
||||
*/
|
||||
explicit SceneManager(int stop_node_number);
|
||||
explicit SceneManager();
|
||||
~SceneManager();
|
||||
|
||||
/**
|
||||
* 生成站点画面
|
||||
* @param node_number
|
||||
*/
|
||||
void SetStopScene(int node_number);
|
||||
|
||||
private:
|
||||
/**
|
||||
* 显示站点的像素图对象
|
||||
|
@ -58,7 +64,21 @@ private:
|
|||
*/
|
||||
PosPair *stop_pos_pairs;
|
||||
|
||||
/**
|
||||
* 总共的站点数量
|
||||
*/
|
||||
int stop_node_number;
|
||||
|
||||
/**
|
||||
* 一个矩形的边框
|
||||
* 使无论中间存在多少站点,这个scene都能在view的中心
|
||||
*/
|
||||
QGraphicsRectItem *rect_item;
|
||||
|
||||
/**
|
||||
* 清除画面
|
||||
*/
|
||||
void ClearScene();
|
||||
};
|
||||
|
||||
#endif //AUTO_BUS_GUI_MAIN_SCENE_H
|
||||
|
|
|
@ -304,11 +304,11 @@ void BusControllerModel::ReadConfigFile(const std::string& file_name)
|
|||
chosen_strategy = BUS_FCFS;
|
||||
}
|
||||
|
||||
qDebug() << node_space_length << total_station;
|
||||
// 得到轨道的总长度
|
||||
total_distance = node_space_length * total_station;
|
||||
rail_manager->CreateRails(node_space_length, total_station);
|
||||
|
||||
// 发射信号说明创建完毕
|
||||
emit RailsCreated(total_station);
|
||||
}
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
CentralWidget::CentralWidget(QWidget *parent, BusControllerModel *bus_controller) : QWidget(parent), ui(new Ui::CentralWidget)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
scene_manager = new SceneManager(20);
|
||||
scene_manager = new SceneManager;
|
||||
|
||||
ui->main_canva->setScene(scene_manager->scene);
|
||||
|
||||
|
@ -32,7 +32,9 @@ CentralWidget::~CentralWidget()
|
|||
|
||||
void CentralWidget::SetControlConnection()
|
||||
{
|
||||
|
||||
// 处理轨道重新设置事件
|
||||
QObject::connect(controller, &BusControllerModel::RailsCreated,
|
||||
this, &CentralWidget::SetRailsScene);
|
||||
}
|
||||
|
||||
void CentralWidget::SetWidgetConnection()
|
||||
|
@ -97,3 +99,20 @@ void CentralWidget::AddQueryButtonClicked()
|
|||
{
|
||||
|
||||
}
|
||||
|
||||
void CentralWidget::SetRailsScene(int node_num)
|
||||
{
|
||||
scene_manager->SetStopScene(node_num);
|
||||
SetRailsComboBox(node_num);
|
||||
}
|
||||
|
||||
void CentralWidget::SetRailsComboBox(int node_num)
|
||||
{
|
||||
ui->query_node_combo->clear();
|
||||
|
||||
for(int i = 1; i <= node_num; i++)
|
||||
{
|
||||
QString node_str = QString::asprintf("第%d站", i);
|
||||
ui->query_node_combo->addItem(node_str);
|
||||
}
|
||||
}
|
|
@ -49,6 +49,14 @@ public slots:
|
|||
*/
|
||||
void AddQueryButtonClicked();
|
||||
|
||||
/**
|
||||
* 处理轨道重新生成的槽函数
|
||||
* 重绘轨道画面
|
||||
* 重新设置站点选择下拉栏
|
||||
* @param node_num
|
||||
*/
|
||||
void SetRailsScene(int node_num);
|
||||
|
||||
private:
|
||||
/**
|
||||
* UI控件
|
||||
|
@ -90,6 +98,11 @@ private:
|
|||
* 清除展示对象占用的内存空间
|
||||
*/
|
||||
void DeleteQueryList();
|
||||
|
||||
/**
|
||||
* 设置站点选择下拉栏
|
||||
*/
|
||||
void SetRailsComboBox(int node_num);
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -4,12 +4,33 @@
|
|||
|
||||
#include "mainScene.h"
|
||||
|
||||
SceneManager::SceneManager(int stop_node_number)
|
||||
SceneManager::SceneManager()
|
||||
{
|
||||
scene = new QGraphicsScene;
|
||||
stop_node_number = 0;
|
||||
pixmap_items = nullptr;
|
||||
stop_pos_pairs = nullptr;
|
||||
rect_item = new QGraphicsRectItem;
|
||||
|
||||
// 画一个描边的矩形框
|
||||
rect_item->setRect(0, 0, 595, 395);
|
||||
scene->addItem(rect_item);
|
||||
}
|
||||
|
||||
SceneManager::~SceneManager()
|
||||
{
|
||||
ClearScene();
|
||||
delete scene;
|
||||
}
|
||||
|
||||
void SceneManager::SetStopScene(int node_number)
|
||||
{
|
||||
// 先清除以下屏幕
|
||||
ClearScene();
|
||||
|
||||
stop_node_number = node_number;
|
||||
pixmap_items = new QGraphicsPixmapItem[stop_node_number];
|
||||
stop_pos_pairs = new PosPair[stop_node_number];
|
||||
rect_item = new QGraphicsRectItem;
|
||||
|
||||
int stop_space_length = stop_pos_pairs->GetStopSpaceLength(stop_node_number);
|
||||
double stop_scale = 0.15;
|
||||
|
@ -36,17 +57,18 @@ SceneManager::SceneManager(int stop_node_number)
|
|||
}
|
||||
pixmap_items[i].setPos(stop_pos_pairs[i].pos_x, stop_pos_pairs[i].pos_y);
|
||||
}
|
||||
|
||||
// 画一个描边的矩形框
|
||||
rect_item->setRect(0, 0, 595, 395);
|
||||
scene->addItem(rect_item);
|
||||
}
|
||||
|
||||
SceneManager::~SceneManager()
|
||||
void SceneManager::ClearScene()
|
||||
{
|
||||
delete []stop_pos_pairs;
|
||||
// 从画布中移除所有的站点图片
|
||||
for(int i = 0; i < stop_node_number; i++)
|
||||
{
|
||||
scene->removeItem(&pixmap_items[i]);
|
||||
}
|
||||
|
||||
delete []pixmap_items;
|
||||
delete scene;
|
||||
delete []stop_pos_pairs;
|
||||
}
|
||||
|
||||
PosPair::PosPair()
|
||||
|
@ -85,7 +107,7 @@ void PosPair::AddLength(int length)
|
|||
// 站点在右轨道
|
||||
|
||||
pos_x = stop_begin_x + stop_rail_width;
|
||||
pos_y = stop_begin_y + stop_rail_width + stop_rail_height - distance;
|
||||
pos_y = stop_begin_y + distance - stop_rail_width;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -12,7 +12,10 @@ RailsModel::RailsModel()
|
|||
|
||||
RailsModel::~RailsModel()
|
||||
{
|
||||
if(rails != nullptr)
|
||||
{
|
||||
FreeRails();
|
||||
}
|
||||
}
|
||||
|
||||
rail_node_t *RailsModel::FindNode(int node_num) const
|
||||
|
|
Loading…
Reference in New Issue
Block a user