读取配置文件后重绘站点图重设下拉栏

修复了释放轨道链表内存空间时未判断指针是否为空的问题
修复了绘制站点图部分站点位置计算错误的问题
This commit is contained in:
jackfiled 2022-06-26 15:02:43 +08:00
parent 48cd806197
commit 54c4521fb2
6 changed files with 92 additions and 15 deletions

View File

@ -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

View File

@ -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);
}

View File

@ -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()
@ -96,4 +98,21 @@ void CentralWidget::DeleteQueryItem(int query_id)
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);
}
}

View File

@ -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);
};

View File

@ -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
{

View File

@ -12,7 +12,10 @@ RailsModel::RailsModel()
RailsModel::~RailsModel()
{
FreeRails();
if(rails != nullptr)
{
FreeRails();
}
}
rail_node_t *RailsModel::FindNode(int node_num) const