添加了显示当前策略的标签

调整了公交车的位置
This commit is contained in:
jackfiled 2022-06-29 11:33:43 +08:00
parent 3ab2edf65c
commit 1a0c65383b
10 changed files with 94 additions and 31 deletions

View File

@ -21,6 +21,7 @@ public:
BusModel *bus_model;
int bus_tick;
int strategy;
BusStrategyBase();

View File

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

View File

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

View File

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

View File

@ -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()
{
// 设置添加请求事件的连接

View File

@ -39,24 +39,11 @@
</rect>
</property>
</widget>
<widget class="Line" name="line">
<property name="geometry">
<rect>
<x>0</x>
<y>400</y>
<width>900</width>
<height>10</height>
</rect>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
<widget class="QWidget" name="layoutWidget">
<property name="geometry">
<rect>
<x>770</x>
<y>160</y>
<x>780</x>
<y>100</y>
<width>121</width>
<height>231</height>
</rect>
@ -127,10 +114,10 @@
<widget class="QWidget" name="layoutWidget">
<property name="geometry">
<rect>
<x>600</x>
<y>170</y>
<x>610</x>
<y>70</y>
<width>161</width>
<height>221</height>
<height>331</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
@ -151,6 +138,42 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="layoutWidget">
<property name="geometry">
<rect>
<x>630</x>
<y>20</y>
<width>241</width>
<height>31</height>
</rect>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label_5">
<property name="font">
<font>
<pointsize>12</pointsize>
</font>
</property>
<property name="text">
<string>当前策略</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="strategy_label">
<property name="font">
<font>
<pointsize>12</pointsize>
</font>
</property>
<property name="text">
<string>无配置文件</string>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
<resources/>
<connections/>

View File

@ -38,6 +38,12 @@ public:
*/
void SetController(BusStrategyBase *c);
/**
*
* @param strategy
*/
void SetStrategyLabel(int strategy);
signals:
/**
*

View File

@ -79,7 +79,7 @@ public slots:
*/
void OneTickSlot();
void BeginBusTimerSlot(int direction, int duration);
void BeginBusTimerSlot([[maybe_unused]] int direction, int duration);
private:
/**

View File

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

View File

@ -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)
{
// 这里得多计上一段时间
// 执行动画需要消耗时间