diff --git a/include/BusStrategyBase.h b/include/BusStrategyBase.h index c375947..df3fa78 100644 --- a/include/BusStrategyBase.h +++ b/include/BusStrategyBase.h @@ -21,6 +21,7 @@ public: BusModel *bus_model; int bus_tick; + int strategy; BusStrategyBase(); diff --git a/src/BusStrategyBase.cpp b/src/BusStrategyBase.cpp index dd9d9ef..10519fd 100644 --- a/src/BusStrategyBase.cpp +++ b/src/BusStrategyBase.cpp @@ -11,6 +11,7 @@ BusStrategyBase::BusStrategyBase() bus_model = new BusModel; bus_tick = 0; + strategy = -1; SetConnection(); } @@ -112,12 +113,21 @@ void BusStrategyBase::HandleQuery() query_model->DeleteQuery(bus_model->target_query); bus_model->target_query = GetTargetQuery(); } + + // 需要停一tick处理请求 + emit BusRunningSignal(BUS_STOP, 1000); } else { // 没有到站就进行顺便处理 bus_query_t *query = HandleBTWQuery(); + if(query != nullptr) + { + // 需要停一tick处理请求 + emit BusRunningSignal(BUS_STOP, 1000); + } + while(query != nullptr) { emit DeleteQuerySignal(query->type, query->node->id); diff --git a/src/PosPair.cpp b/src/PosPair.cpp index 58f4f28..615867b 100644 --- a/src/PosPair.cpp +++ b/src/PosPair.cpp @@ -61,8 +61,9 @@ int PosPair::GetBusPosX() const } else if(pos_x >= stop_begin_x + stop_rail_width) { - // 最下面一行得加上站点图片的高度 - result = pos_x + stop_bus_distance + 100; + // 最右边一行得加上站点图片的宽度 + // 实际测试貌似不加就可以 + result = pos_x + stop_bus_distance; } else { @@ -80,10 +81,10 @@ int PosPair::GetBusPosY() const { result = stop_begin_y - stop_bus_distance; } - else if(pos_y >= stop_begin_y + stop_rail_width) + else if(pos_y >= stop_begin_y + stop_rail_height) { - // 最右边一行得加上站点图片的宽度 - result = pos_y + stop_bus_distance + 30; + // 最下面一行得加上站点图片的高度 + result = pos_y + stop_bus_distance + 25; } else { diff --git a/src/StrategyFactory.cpp b/src/StrategyFactory.cpp index 5c33efe..dee32f8 100644 --- a/src/StrategyFactory.cpp +++ b/src/StrategyFactory.cpp @@ -139,6 +139,7 @@ BusStrategyBase *StrategyFactory::GetStrategy(const QString& file_name) if(controller != nullptr) { controller->rails_model->CreateRails(distance, total_station); + controller->strategy = chosen_strategy; } return controller; } diff --git a/src/centralwidget.cpp b/src/centralwidget.cpp index 1808748..65faf1b 100644 --- a/src/centralwidget.cpp +++ b/src/centralwidget.cpp @@ -34,6 +34,28 @@ void CentralWidget::SetController(BusStrategyBase *c) SetRailsScene(controller->rails_model->node_num); } +void CentralWidget::SetStrategyLabel(int strategy) +{ + QString name; + + switch (strategy) + { + case BUS_FCFS: + name = QString("先来先服务"); + break; + case BUS_SSTF: + name = QString("最短寻找时间"); + break; + case BUS_SCAN: + name = QString("顺便服务"); + break; + default: + break; + } + + ui->strategy_label->setText(name); +} + void CentralWidget::SetControlConnection() { // 设置添加请求事件的连接 diff --git a/src/form/centralwidget.ui b/src/form/centralwidget.ui index d6ae526..a08adeb 100644 --- a/src/form/centralwidget.ui +++ b/src/form/centralwidget.ui @@ -39,24 +39,11 @@ - - - - 0 - 400 - 900 - 10 - - - - Qt::Horizontal - - - 770 - 160 + 780 + 100 121 231 @@ -127,10 +114,10 @@ - 600 - 170 + 610 + 70 161 - 221 + 331 @@ -151,6 +138,42 @@ + + + + 630 + 20 + 241 + 31 + + + + + + + + 12 + + + + 当前策略 + + + + + + + + 12 + + + + 无配置文件 + + + + + diff --git a/src/header/centralwidget.h b/src/header/centralwidget.h index 3a5350c..d11f4f0 100644 --- a/src/header/centralwidget.h +++ b/src/header/centralwidget.h @@ -38,6 +38,12 @@ public: */ void SetController(BusStrategyBase *c); + /** + * 设置显示当前策略的标签 + * @param strategy 当前选择的策略 + */ + void SetStrategyLabel(int strategy); + signals: /** * 添加一个请求的信号 diff --git a/src/header/mainwindow.h b/src/header/mainwindow.h index 5078487..7f05470 100644 --- a/src/header/mainwindow.h +++ b/src/header/mainwindow.h @@ -79,7 +79,7 @@ public slots: */ void OneTickSlot(); - void BeginBusTimerSlot(int direction, int duration); + void BeginBusTimerSlot([[maybe_unused]] int direction, int duration); private: /** diff --git a/src/mainScene.cpp b/src/mainScene.cpp index a5b3f72..e6888f2 100644 --- a/src/mainScene.cpp +++ b/src/mainScene.cpp @@ -21,13 +21,10 @@ SceneManager::SceneManager() SceneManager::~SceneManager() { - // 清除站点图像 - ClearStopScene(); - - // 清除公交车图像 - scene->removeItem(bus->item); + delete []name_items; + delete []pixmap_items; + delete []stop_pos_pairs; delete bus; - delete scene; } diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 708e2fe..89657d6 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -120,6 +120,8 @@ void MainWindow::ReadConfigFileButtonClicked() central_widget->SetController(controller); // 重设公交车的状态 controller->bus_model->ResetBus(controller->rails_model->rails); + // 设置策略的标签 + central_widget->SetStrategyLabel(controller->strategy); } } @@ -160,7 +162,7 @@ void MainWindow::EndTickTimerSlot() tick_timer->stop(); } -void MainWindow::BeginBusTimerSlot(int direction, int duration) +void MainWindow::BeginBusTimerSlot([[maybe_unused]] int direction, int duration) { // 这里得多计上一段时间 // 执行动画需要消耗时间