From de4b22c3eff361b5f936f382000ace366914e8f4 Mon Sep 17 00:00:00 2001 From: lcjh <120989324@qq.com> Date: Tue, 14 Dec 2021 23:45:39 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=86=E6=94=AF=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 赋值代替if-else,去除不必要分支 Signed-off-by: lcjh <120989324@qq.com> --- chart_plugin/src/curve/curve_data.cpp | 5 +--- chart_plugin/src/curve_display.cpp | 8 ++---- chart_plugin/src/slt_space_display.cpp | 19 +++++--------- chart_plugin/src/st_space_display.cpp | 34 ++++++++------------------ 4 files changed, 19 insertions(+), 47 deletions(-) diff --git a/chart_plugin/src/curve/curve_data.cpp b/chart_plugin/src/curve/curve_data.cpp index 050728b..665672c 100755 --- a/chart_plugin/src/curve/curve_data.cpp +++ b/chart_plugin/src/curve/curve_data.cpp @@ -84,9 +84,6 @@ bool CurveData::Add(const custom::PlotData::ConstPtr &msg) const auto &firstCurve = msg->firstCurve; const auto &secondCurve = msg->secondCurve; SetMeanSquareDiffData(msg->meanSquareDifference); - if (SetCurveData(firstCurve, firstCurvePolyonF) && SetCurveData(secondCurve, secondCurvePolyonF)) { - return true; - } - return false; + return SetCurveData(firstCurve, firstCurvePolyonF) && SetCurveData(secondCurve, secondCurvePolyonF); } } // namespace chart_plugin diff --git a/chart_plugin/src/curve_display.cpp b/chart_plugin/src/curve_display.cpp index eea1c79..74f0c03 100755 --- a/chart_plugin/src/curve_display.cpp +++ b/chart_plugin/src/curve_display.cpp @@ -228,12 +228,8 @@ void CurveDisplay::UpdateCurveTitle() void CurveDisplay::UpdateCurveChoice() { - bool isUseFirstStTrackCurve = true; - bool isUseSecondStTrackCurve = false; - if (curveProperty->getOptionInt() == SECOND_CURVE) { - isUseFirstStTrackCurve = false; - isUseSecondStTrackCurve = true; - } + bool isUseFirstStTrackCurve = curveProperty->getOptionInt() == FIRST_CURVE; + bool isUseSecondStTrackCurve = !isUseFirstStTrackCurve; firstCurveTitleProperty->setHidden(!isUseFirstStTrackCurve); firstCurveColorProperty->setHidden(!isUseFirstStTrackCurve); diff --git a/chart_plugin/src/slt_space_display.cpp b/chart_plugin/src/slt_space_display.cpp index a695a7c..9cb4ba7 100755 --- a/chart_plugin/src/slt_space_display.cpp +++ b/chart_plugin/src/slt_space_display.cpp @@ -165,10 +165,7 @@ void SltSpaceDisplay::InitProperty() void SltSpaceDisplay::UpdateOptimizedCurveChoice() { - bool isOptimizedStTrackCurve = false; - if (curveProperty->getOptionInt() == OPTIMIZED_TRACK_CURVE) { - isOptimizedStTrackCurve = true; - } + bool isOptimizedStTrackCurve = curveProperty->getOptionInt() == OPTIMIZED_TRACK_CURVE; optimizedCurveTitleProperty->setHidden(!isOptimizedStTrackCurve); optimizedCurveColorProperty->setHidden(!isOptimizedStTrackCurve); @@ -176,11 +173,7 @@ void SltSpaceDisplay::UpdateOptimizedCurveChoice() void SltSpaceDisplay::UpdateStSpeedCurveChoice() { - bool isStSpeedLimitCurve = false; - - if (curveProperty->getOptionInt() == SPEED_LIMIT_CURVE) { - isStSpeedLimitCurve = true; - } + bool isStSpeedLimitCurve = curveProperty->getOptionInt() == SPEED_LIMIT_CURVE; speedLimitCurveTitleProperty->setHidden(!isStSpeedLimitCurve); speedLimitCurveColorProperty->setHidden(!isStSpeedLimitCurve); @@ -203,10 +196,10 @@ void SltSpaceDisplay::CreateObjectsTypeProperty(int32_t type) if (objectsTypeProperty == nullptr) { objectsTypeProperty = new (std::nothrow) EnumProperty("Objects Type", typeName, "Slt Objects Type setting selection.", this, SLOT(UpdateObjectsTypeChoice())); - } - if (objectsTypeProperty == nullptr) { - ROS_ERROR("Failed to create the objectsTypeProperty."); - return; + if (objectsTypeProperty == nullptr) { + ROS_ERROR("Failed to create the objectsTypeProperty."); + return; + } } objectsTypeProperty->addOption(typeName, type); } diff --git a/chart_plugin/src/st_space_display.cpp b/chart_plugin/src/st_space_display.cpp index a7fbdd7..de1a6b4 100755 --- a/chart_plugin/src/st_space_display.cpp +++ b/chart_plugin/src/st_space_display.cpp @@ -304,11 +304,7 @@ void StSpaceDisplay::UpdateObjectCurveTitle() void StSpaceDisplay::UpdateFirstCurveChoice() { - bool useFirstStTrackCurve = false; - - if (curveProperty->getOptionInt() == FIRST_ST_TRACK_CURVE) { - useFirstStTrackCurve = true; - } + bool useFirstStTrackCurve = curveProperty->getOptionInt() == FIRST_ST_TRACK_CURVE; firstCurveTitleProperty->setHidden(!useFirstStTrackCurve); firstCurveColorProperty->setHidden(!useFirstStTrackCurve); @@ -317,11 +313,7 @@ void StSpaceDisplay::UpdateFirstCurveChoice() void StSpaceDisplay::UpdateOptimizedCurveChoice() { - bool useOptimizedStTrackCurve = false; - - if (curveProperty->getOptionInt() == OPTIMIZED_ST_TRACK_CURVE) { - useOptimizedStTrackCurve = true; - } + bool useOptimizedStTrackCurve = curveProperty->getOptionInt() == OPTIMIZED_ST_TRACK_CURVE; optimizedCurveTitleProperty->setHidden(!useOptimizedStTrackCurve); optimizedCurveColorProperty->setHidden(!useOptimizedStTrackCurve); @@ -330,11 +322,7 @@ void StSpaceDisplay::UpdateOptimizedCurveChoice() void StSpaceDisplay::UpdateStSpeedCurveChoice() { - bool useStSpeedLimitCurve = false; - - if (curveProperty->getOptionInt() == ST_SPEED_LIMIT_CURVE) { - useStSpeedLimitCurve = true; - } + bool useStSpeedLimitCurve = curveProperty->getOptionInt() == ST_SPEED_LIMIT_CURVE; speedLimitCurveTitleProperty->setHidden(!useStSpeedLimitCurve); speedLimitCurveColorProperty->setHidden(!useStSpeedLimitCurve); @@ -417,18 +405,16 @@ void StSpaceDisplay::InitQwtPlotStyle() return; } - if (legend != nullptr) { - legend->setStyleSheet(LEGEND_STYLE_SHEET); + legend->setStyleSheet(LEGEND_STYLE_SHEET); - // 图例可以选择,Checkable - legend->setDefaultItemMode(QwtLegendData::Checkable); + // 图例可以选择,Checkable + legend->setDefaultItemMode(QwtLegendData::Checkable); - // 设置图例的位置 - ui.qwtPlot->insertLegend(legend, QwtPlot::BottomLegend); + // 设置图例的位置 + ui.qwtPlot->insertLegend(legend, QwtPlot::BottomLegend); - // 连接槽,处理选择事件 - connect(legend, SIGNAL(checked(const QVariant &, bool, int)), SLOT(LegendChecked(const QVariant &, bool))); - } + // 连接槽,处理选择事件 + connect(legend, SIGNAL(checked(const QVariant &, bool, int)), SLOT(LegendChecked(const QVariant &, bool))); // 绘制网格 // 设置画笔 -- Gitee