diff --git a/chart_plugin/src/slt_space/slt_space_draw.cpp b/chart_plugin/src/slt_space/slt_space_draw.cpp index 83efdc82d18c777dee038df015a8a8590102aba1..4d372ef0c8ffa6a211feeb4850f7294851a3527c 100755 --- a/chart_plugin/src/slt_space/slt_space_draw.cpp +++ b/chart_plugin/src/slt_space/slt_space_draw.cpp @@ -1,5 +1,5 @@ /* -Copyright (c) 2020-2021, Huawei Technologies Co., Ltd +Copyright (c) 2020-2022, Huawei Technologies Co., Ltd All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the @@ -108,13 +108,15 @@ void SltSpaceDraw::DrawObjects(mglGraph *mglGraphPtr) const const auto sltObjectsMap = spaceDataPtr->GetObjectsMap(); const auto objectsIdType = spaceDataPtr->GetObjectsIdTypeMap(); - for (auto iter = sltObjectsMap.begin(); iter != sltObjectsMap.end(); iter++) { - vector objectData = iter.value(); + QList listType = objectsIdType.values(); + qSort(listType.begin(), listType.end()); + + for (auto type : listType) { + vector objectData = sltObjectsMap.value(objectsIdType.key(type)); if (objectData.size() != OBJECT_DATA_NUM_SIZE) { continue; } - QString objectId = iter.key(); - int32_t type = objectsIdType.value(objectId); + QString objectId = objectsIdType.key(type); spaceDisplayPtr->SetObjectProperty(type); auto objectIdLegendIter = (spaceDisplayPtr->GetObjectsIdLegendMap()).find(objectId); if (objectIdLegendIter != (spaceDisplayPtr->GetObjectsIdLegendMap()).end() && diff --git a/chart_plugin/src/slt_space_display.cpp b/chart_plugin/src/slt_space_display.cpp index 6b3b2c96e7164691239049a16de4ba3eb281ddd0..ee930e5515ffe8016a3340c1ff1d9d19269c587a 100755 --- a/chart_plugin/src/slt_space_display.cpp +++ b/chart_plugin/src/slt_space_display.cpp @@ -1,5 +1,5 @@ /* -Copyright (c) 2020-2021, Huawei Technologies Co., Ltd +Copyright (c) 2020-2022, Huawei Technologies Co., Ltd All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the @@ -75,36 +75,20 @@ void SltSpaceDisplay::ClearData() void SltSpaceDisplay::InitTitleProperty() { - plotTitleProperty = new (std::nothrow) + plotTitleProperty = new StringProperty("Chart Title", "SLT", "Chart title name property.", this, SLOT(UpdateMathglDraw()), this); - if (plotTitleProperty == nullptr) { - ROS_ERROR("Failed to create the plotTitleProperty."); - return; - } plotTitleProperty->setReadOnly(true); - xAxisTitleProperty = new (std::nothrow) + xAxisTitleProperty = new StringProperty("X Axis Title", "S[m]", "X Axis title name property.", this, SLOT(UpdateMathglDraw()), this); - if (xAxisTitleProperty == nullptr) { - ROS_ERROR("Failed to create the xAxisTitleProperty."); - return; - } xAxisTitleProperty->setReadOnly(true); - yAxisTitleProperty = new (std::nothrow) + yAxisTitleProperty = new StringProperty("Y Axis Title", "L[m]", "Y Axis title name property.", this, SLOT(UpdateMathglDraw()), this); - if (yAxisTitleProperty == nullptr) { - ROS_ERROR("Failed to create the yAxisTitleProperty."); - return; - } yAxisTitleProperty->setReadOnly(true); - zAxisTitleProperty = new (std::nothrow) + zAxisTitleProperty = new StringProperty("Z Axis Title", "T[s]", "Z Axis title name property.", this, SLOT(UpdateMathglDraw()), this); - if (zAxisTitleProperty == nullptr) { - ROS_ERROR("Failed to create the zAxisTitleProperty."); - return; - } zAxisTitleProperty->setReadOnly(true); } @@ -117,44 +101,24 @@ void SltSpaceDisplay::InitCurveProperty() const int32_t speedLimitCurveColorG = 0xFF; const int32_t speedLimitCurveColorB = 0xC1; - curveProperty = new (std::nothrow) + curveProperty = new EnumProperty("Curve", "Optimized Track", "Curve type setting selection.", this, SLOT(UpdateCurveChoice())); - if (curveProperty == nullptr) { - ROS_ERROR("Failed to create the curveProperty."); - return; - } curveProperty->addOption("Optimized Track", OPTIMIZED_TRACK_CURVE); curveProperty->addOption("Speed Limit", SPEED_LIMIT_CURVE); - optimizedCurveTitleProperty = new (std::nothrow) StringProperty("Optimized Title", "Optimized Track", + optimizedCurveTitleProperty = new StringProperty("Optimized Title", "Optimized Track", "Optimized curve title property setting.", curveProperty, SLOT(UpdateOptimizedCurveTitle()), this); - if (optimizedCurveTitleProperty == nullptr) { - ROS_ERROR("Failed to create the optimizedCurveTitleProperty."); - return; - } - optimizedCurveColorProperty = new (std::nothrow) + optimizedCurveColorProperty = new ColorProperty("Optimized Color", QColor(optimizedCurveColorR, optimizedCurveColorG, optimizedCurveColorB), "Color of the Optimized Slt Track Curve.", curveProperty, SLOT(UpdateOptimizedCurveColor()), this); - if (optimizedCurveColorProperty == nullptr) { - ROS_ERROR("Failed to create the optimizedCurveColorProperty."); - return; - } - speedLimitCurveTitleProperty = new (std::nothrow) StringProperty("Speed Title", "Speed Limit", + speedLimitCurveTitleProperty = new StringProperty("Speed Title", "Speed Limit", "Slt Speed Limit curve title property setting.", curveProperty, SLOT(UpdateSpeedLimitCurveTitle()), this); - if (speedLimitCurveTitleProperty == nullptr) { - ROS_ERROR("Failed to create the speedLimitCurveTitleProperty."); - return; - } - speedLimitCurveColorProperty = new (std::nothrow) + speedLimitCurveColorProperty = new ColorProperty("Speed Color", QColor(speedLimitCurveColorR, speedLimitCurveColorG, speedLimitCurveColorB), "Color of the Slt Speed Limit Curve.", curveProperty, SLOT(UpdateSpeedLimitCurveColor()), this); - if (speedLimitCurveColorProperty == nullptr) { - ROS_ERROR("Failed to create the speedLimitCurveColorProperty."); - return; - } } void SltSpaceDisplay::InitProperty() @@ -201,13 +165,9 @@ void SltSpaceDisplay::CreateObjectsTypeProperty(int32_t type) objectsTypeTotalVector.append(type); if (objectsTypeProperty == nullptr) { - objectsTypeProperty = new (std::nothrow) EnumProperty("Objects Type", typeName, + objectsTypeProperty = new EnumProperty("Objects Type", typeName, "Slt Objects Type setting selection.", this, SLOT(UpdateObjectsTypeChoice())); } - if (objectsTypeProperty == nullptr) { - ROS_ERROR("Failed to create the objectsTypeProperty."); - return; - } objectsTypeProperty->addOption(typeName, type); } @@ -269,12 +229,8 @@ void SltSpaceDisplay::CreateObjectProperty(const QString &propertyKey, const QSt int32_t green = colorChannelValue[1].toInt(); int32_t blue = colorChannelValue[2].toInt(); // 取colorChannelValue中第2个元素 QColor color = QColor(red, green, blue); - ColorProperty *objectsTypeColorPropertyPtr = new (std::nothrow) ColorProperty(propertyKey, color, + ColorProperty *objectsTypeColorPropertyPtr = new ColorProperty(propertyKey, color, "Objects type color setting.", objectsTypeProperty, SLOT(UpdateObjectsTypeColor()), this); - if (objectsTypeColorPropertyPtr == nullptr) { - ROS_ERROR("Failed to Create the objectsTypeColorPropertyPtr of ColorProperty."); - return; - } SetObjectsTypeColor(type, red, green, blue); objectsTypeColorPropertyMap.insert(type, objectsTypeColorPropertyPtr); @@ -282,12 +238,8 @@ void SltSpaceDisplay::CreateObjectProperty(const QString &propertyKey, const QSt } if (keyList.contains("Title")) { - StringProperty *objectsTypeTitlePropertyPtr = new (std::nothrow) StringProperty(propertyKey, propertyValue, + StringProperty *objectsTypeTitlePropertyPtr = new StringProperty(propertyKey, propertyValue, "Objects type title setting.", objectsTypeProperty, SLOT(UpdateObjectsTypeTitle()), this); - if (objectsTypeTitlePropertyPtr == nullptr) { - ROS_ERROR("Failed to Create the objectsTypeTitlePropertyPtr of StringProperty."); - return; - } objectsTypeTitlePropertyMap.insert(type, objectsTypeTitlePropertyPtr); } @@ -313,11 +265,7 @@ void SltSpaceDisplay::load(const rviz::Config &config) void SltSpaceDisplay::CreateOptimizedLegend() { if (optimizedCurveLegend == nullptr) { - optimizedCurveLegend = new (std::nothrow) QPushButton(ui.GetScrollAreaWidgetContents()); - if (optimizedCurveLegend == nullptr) { - ROS_ERROR("Failed to Create the optimizedCurveLegend of QPushButton."); - return; - } + optimizedCurveLegend = new QPushButton(ui.GetScrollAreaWidgetContents()); QObject::connect(optimizedCurveLegend, SIGNAL(toggled(bool)), this, SLOT(UpdateMathglDraw())); } @@ -333,11 +281,7 @@ void SltSpaceDisplay::CreateOptimizedLegend() void SltSpaceDisplay::CreateSpeedLegend() { if (speedLimitCurveLegend == nullptr) { - speedLimitCurveLegend = new (std::nothrow) QPushButton(ui.GetScrollAreaWidgetContents()); - if (speedLimitCurveLegend == nullptr) { - ROS_ERROR("Failed to Create the speedLimitCurveLegend of QPushButton."); - return; - } + speedLimitCurveLegend = new QPushButton(ui.GetScrollAreaWidgetContents()); QObject::connect(speedLimitCurveLegend, SIGNAL(toggled(bool)), this, SLOT(UpdateMathglDraw())); } @@ -489,7 +433,11 @@ void SltSpaceDisplay::UpdateGridLayoutItem() ui.GetGridLayout()->addItem(horizontalSpacerRight, 1, column - 1, 1, 1); const auto &objectsIdTypeMap = sltSpaceData.GetObjectsIdTypeMap(); - auto iter = objectsIdTypeMap.cbegin(); + + QList listType = objectsIdTypeMap.values(); + qSort(listType.begin(), listType.end()); + + int32_t k = 0; // 从第1行第1列位置开始放置图例按钮,遍历网格图例按钮放置区域(row - 2)行乘(column - 2)列个放置空间 for (int32_t i = 1; i <= row - 2; i++) { // 共有(column - 2)列是安置图例按钮的 @@ -502,15 +450,15 @@ void SltSpaceDisplay::UpdateGridLayoutItem() ui.GetGridLayout()->addWidget(speedLimitCurveLegend, i, j, 1, 1); speedLimitCurveLegend->show(); // 只有当整个障碍物图例按钮都还没有遍历安置完毕,网格布局器才安置图例按钮 - } else if (iter != objectsIdTypeMap.cend()) { - auto objectIdLegendIter = objectsIdLegendMap.find(iter.key()); + } else if (k < listType.count()) { + auto objectIdLegendIter = objectsIdLegendMap.find(objectsIdTypeMap.key(listType.at(k))); if ((objectIdLegendIter == objectsIdLegendMap.end()) || (objectIdLegendIter->second == nullptr)) { - iter++; + k++; continue; } - ui.GetGridLayout()->addWidget(objectsIdLegendMap[iter.key()].get(), i, j, 1, 1); - objectsIdLegendMap[iter.key()]->show(); - iter++; + ui.GetGridLayout()->addWidget(objectsIdLegendMap[objectsIdTypeMap.key(listType.at(k))].get(), i, j, 1, 1); + objectsIdLegendMap[objectsIdTypeMap.key(listType.at(k))]->show(); + k++; } } } @@ -531,36 +479,20 @@ void SltSpaceDisplay::InitLegendSpacerItem() const int32_t horizontalHeight = 20; verticalSpacerTop = - new (std::nothrow) QSpacerItem(verticalWidth, verticalHeightTop, QSizePolicy::Minimum, QSizePolicy::Expanding); - if (verticalSpacerTop == nullptr) { - ROS_ERROR("Failed to Create the verticalSpacerTop of QSpacerItem."); - return; - } + new QSpacerItem(verticalWidth, verticalHeightTop, QSizePolicy::Minimum, QSizePolicy::Expanding); ui.GetGridLayout()->addItem(verticalSpacerTop, 0, 1, 1, 1); - verticalSpacerBottom = new (std::nothrow) + verticalSpacerBottom = new QSpacerItem(verticalWidth, verticalHeightBottom, QSizePolicy::Minimum, QSizePolicy::Expanding); - if (verticalSpacerBottom == nullptr) { - ROS_ERROR("Failed to Create the verticalSpacerBottom of QSpacerItem."); - return; - } // 底部垂直弹簧放置第2行第1列,占据1行1列 ui.GetGridLayout()->addItem(verticalSpacerBottom, 2, 1, 1, 1); horizontalSpacerLeft = - new (std::nothrow) QSpacerItem(horizontalWidth, horizontalHeight, QSizePolicy::Expanding, QSizePolicy::Minimum); - if (horizontalSpacerLeft == nullptr) { - ROS_ERROR("Failed to Create the horizontalSpacerLeft of QSpacerItem."); - return; - } + new QSpacerItem(horizontalWidth, horizontalHeight, QSizePolicy::Expanding, QSizePolicy::Minimum); ui.GetGridLayout()->addItem(horizontalSpacerLeft, 1, 0, 1, 1); horizontalSpacerRight = - new (std::nothrow) QSpacerItem(horizontalWidth, horizontalHeight, QSizePolicy::Expanding, QSizePolicy::Minimum); - if (horizontalSpacerRight == nullptr) { - ROS_ERROR("Failed to Create the horizontalSpacerRight of QSpacerItem."); - return; - } + new QSpacerItem(horizontalWidth, horizontalHeight, QSizePolicy::Expanding, QSizePolicy::Minimum); // 默认安装位置为第1行第3列,占据1行1列 ui.GetGridLayout()->addItem(horizontalSpacerRight, 1, 3, 1, 1); @@ -603,11 +535,7 @@ void SltSpaceDisplay::onInitialize() graph.Clf(mglGraphColorR, mglGraphColorG, mglGraphColorB); ui.GetQMathGl()->setGraph(&graph); - SltSpaceDraw *spaceDraw = new (std::nothrow) SltSpaceDraw(this, &sltSpaceData); - if (spaceDraw == nullptr) { - ROS_ERROR("Failed to Create the spaceDraw of SltSpaceDraw."); - return; - } + SltSpaceDraw *spaceDraw = new SltSpaceDraw(this, &sltSpaceData); ui.GetQMathGl()->setDraw(spaceDraw); ui.GetQMathGl()->setDotsPreview(false); @@ -734,32 +662,20 @@ void SltSpaceDisplay::SetObjectProperty(int32_t objectType) objectsTypeTotalVector.append(objectType); if (objectsTypeProperty == nullptr) { - objectsTypeProperty = new (std::nothrow) EnumProperty("Object Type", QString("Type %1").arg(objectType), + objectsTypeProperty = new EnumProperty("Object Type", QString("Type %1").arg(objectType), "Slt Objects Type setting selection.", this, SLOT(UpdateObjectsTypeChoice())); - if (objectsTypeProperty == nullptr) { - ROS_ERROR("Failed to Create the objectsTypeProperty of EnumProperty."); - return; - } } QString typeName = QString("Type %1").arg(objectType); objectsTypeProperty->addOption(typeName, objectType); StringProperty *objectsTypeTitlePropertyPtr = - new (std::nothrow) StringProperty(QString("Type %1 Title").arg(objectType), QString("Type %1").arg(objectType), + new StringProperty(QString("Type %1 Title").arg(objectType), QString("Type %1").arg(objectType), "Objects type title setting.", objectsTypeProperty, SLOT(UpdateObjectsTypeTitle()), this); - if (objectsTypeTitlePropertyPtr == nullptr) { - ROS_ERROR("Failed to Create the objectsTypeTitlePropertyPtr of StringProperty."); - return; - } QColor color = GetObjectsTypeColor(objectType); ColorProperty *objectsTypeColorPropertyPtr = - new (std::nothrow) ColorProperty(QString("Type %1 Color").arg(objectType), color, "Objects type color setting.", + new ColorProperty(QString("Type %1 Color").arg(objectType), color, "Objects type color setting.", objectsTypeProperty, SLOT(UpdateObjectsTypeColor()), this); - if (objectsTypeColorPropertyPtr == nullptr) { - ROS_ERROR("Failed to Create the objectsTypeColorPropertyPtr of ColorProperty."); - return; - } objectsTypeTitlePropertyMap.insert(objectType, objectsTypeTitlePropertyPtr); objectsTypeColorPropertyMap.insert(objectType, objectsTypeColorPropertyPtr); diff --git a/chart_plugin/src/st_space_display.cpp b/chart_plugin/src/st_space_display.cpp index a70738241e4ee62af2d719fbde5e17c2615dd255..0aec9380374534694d5233509aa18e62a7bd3e54 100755 --- a/chart_plugin/src/st_space_display.cpp +++ b/chart_plugin/src/st_space_display.cpp @@ -700,20 +700,11 @@ void StSpaceDisplay::ShowObjectsCurve(const QMap &objectsIdTyp stObjectsCurveMap.clear(); } - QStringList typeNames = stObjectsMap.keys(); - for (int32_t i = 0; i < typeNames.count() - 1; i++) { - for (int32_t j = i + 1; j < typeNames.count(); j++) { - if (objectsIdType.value(typeNames.at(i)) > objectsIdType.value(typeNames.at(j))) { - QString typeName = typeNames.at(i); - typeNames[i] = typeNames.at(j); - typeNames[j] = typeName; - } - } - } + QList listType = objectsIdType.values(); + qSort(listType.begin(), listType.end()); - for (auto typeName : typeNames) { - QString objectId = typeName; - int32_t type = objectsIdType.value(objectId); + for (auto type : listType) { + QString objectId = objectsIdType.key(type); SetObjectProperty(type); if (!objectsTypeTitleProperty.contains(type) || objectsTypeTitleProperty[type] == nullptr) { continue;