From 21af2c031119a6a5842bd8c09fc96ddc08199b99 Mon Sep 17 00:00:00 2001 From: jackfiled Date: Fri, 1 Jul 2022 16:38:07 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=86tick=E7=9A=84=E6=8C=81=E7=BB=AD?= =?UTF-8?q?=E6=97=B6=E9=97=B4=E8=AE=BE=E7=BD=AE=E4=BA=86=E5=85=A8=E5=B1=80?= =?UTF-8?q?=E5=B8=B8=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/BusStrategyBase.h | 1 + include/Settings.h | 13 +++++++++++++ src/BusStrategyBase.cpp | 6 +++--- src/header/mainwindow.h | 6 +----- src/mainwindow.cpp | 2 +- 5 files changed, 19 insertions(+), 9 deletions(-) create mode 100644 include/Settings.h diff --git a/include/BusStrategyBase.h b/include/BusStrategyBase.h index 2057e2f..dbf8f1d 100644 --- a/include/BusStrategyBase.h +++ b/include/BusStrategyBase.h @@ -11,6 +11,7 @@ #include "railsModel.h" #include "queryModel.h" #include "busModel.h" +#include "Settings.h" class BusStrategyBase : public QObject { diff --git a/include/Settings.h b/include/Settings.h new file mode 100644 index 0000000..e3b0093 --- /dev/null +++ b/include/Settings.h @@ -0,0 +1,13 @@ +// +// Created by ricardo on 2022/7/1. +// + +#ifndef AUTO_BUS_GUI_SETTINGS_H +#define AUTO_BUS_GUI_SETTINGS_H + +class Settings +{ +public: + const static int tick = 2000; +}; +#endif //AUTO_BUS_GUI_SETTINGS_H diff --git a/src/BusStrategyBase.cpp b/src/BusStrategyBase.cpp index adfd2b8..6e32c67 100644 --- a/src/BusStrategyBase.cpp +++ b/src/BusStrategyBase.cpp @@ -86,13 +86,13 @@ void BusStrategyBase::GetBusDirectionSlot() switch (bus_model->direction) { case BUS_CLOCK_WISE: - duration = bus_model->rail_pos->next_node_distance / bus_model->velocity * 1000; + duration = bus_model->rail_pos->next_node_distance / bus_model->velocity * Settings::tick; break; case BUS_COUNTER_CLOCK_WISE: - duration = bus_model->rail_pos->last_node_distance / bus_model->velocity * 1000; + duration = bus_model->rail_pos->last_node_distance / bus_model->velocity * Settings::tick; break; case BUS_STOP: - duration = 1000; + duration = Settings::tick; break; } diff --git a/src/header/mainwindow.h b/src/header/mainwindow.h index 43b93af..d8e461d 100644 --- a/src/header/mainwindow.h +++ b/src/header/mainwindow.h @@ -13,7 +13,7 @@ #include "centralwidget.h" #include "BusStrategyBase.h" #include "StrategyFactory.h" - +#include "Settings.h" QT_BEGIN_NAMESPACE namespace Ui @@ -87,10 +87,6 @@ public slots: void BeginBusTimerSlot([[maybe_unused]] int direction, int duration); private: - /** - * 设置一时刻的长度,单位毫秒 - */ - const int tick = 1000; /** * UI控件 diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 1e35e37..4903b63 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -153,7 +153,7 @@ void MainWindow::BeginThread() void MainWindow::BeginTickTimerSlot() { - tick_timer->setInterval(tick); + tick_timer->setInterval(Settings::tick); tick_timer->start(); }