diff --git a/scwx-qt/source/scwx/qt/map/map_widget.cpp b/scwx-qt/source/scwx/qt/map/map_widget.cpp index b4882345..ebea2b21 100644 --- a/scwx-qt/source/scwx/qt/map/map_widget.cpp +++ b/scwx-qt/source/scwx/qt/map/map_widget.cpp @@ -185,8 +185,6 @@ public: bool UpdateStoredMapParameters(); void CheckLevel3Availability(); - std::string FindMapSymbologyLayer(); - common::Level2Product GetLevel2ProductOrDefault(const std::string& productName) const; @@ -1146,43 +1144,6 @@ void MapWidget::DumpLayerList() const logger_->info("Layers: {}", p->map_->layerIds().join(", ").toStdString()); } -std::string MapWidgetImpl::FindMapSymbologyLayer() -{ - std::string before = "ferry"; - - for (const QString& qlayer : styleLayers_) - { - const std::string layer = qlayer.toStdString(); - - // Draw below layers defined in map style - auto it = std::find_if(currentStyle_->drawBelow_.cbegin(), - currentStyle_->drawBelow_.cend(), - [&layer](const std::string& styleLayer) -> bool - { - // Perform case-insensitive matching - RE2 re {"(?i)" + styleLayer}; - if (re.ok()) - { - return RE2::FullMatch(layer, re); - } - else - { - // Fall back to basic comparison if RE - // doesn't compile - return layer == styleLayer; - } - }); - - if (it != currentStyle_->drawBelow_.cend()) - { - before = layer; - break; - } - } - - return before; -} - void MapWidgetImpl::AddLayers() { if (styleLayers_.isEmpty()) @@ -1218,7 +1179,8 @@ void MapWidgetImpl::AddLayers() { // Subsequent layers are drawn underneath the map symbology layer case types::MapLayer::MapUnderlay: - before = FindMapSymbologyLayer(); + before = util::maplibre::FindMapSymbologyLayer( + styleLayers_, currentStyle_->drawBelow_); break; // Subsequent layers are drawn after all style-defined layers diff --git a/scwx-qt/source/scwx/qt/ui/custom_layer_dialog.cpp b/scwx-qt/source/scwx/qt/ui/custom_layer_dialog.cpp index 0bea7ffc..b297ab22 100644 --- a/scwx-qt/source/scwx/qt/ui/custom_layer_dialog.cpp +++ b/scwx-qt/source/scwx/qt/ui/custom_layer_dialog.cpp @@ -1,10 +1,11 @@ #include "custom_layer_dialog.hpp" #include "ui_custom_layer_dialog.h" -#include #include +#include #include #include + #include namespace scwx::qt::ui @@ -36,43 +37,26 @@ public: std::shared_ptr map_; }; -// TODO Duplicated form map_widget, Should probably be moved. -static bool match_layer(const std::string& pattern, const std::string& layer) -{ - // Perform case-insensitive matching - const RE2 re {"(?i)" + pattern}; - if (re.ok()) - { - return RE2::FullMatch(layer, re); - } - else - { - // Fall back to basic comparison if RE - // doesn't compile - return layer == pattern; - } -} - void CustomLayerDialogImpl::handle_mapChanged(QMapLibre::Map::MapChange change) { if (change == QMapLibre::Map::MapChange::MapChangeDidFinishLoadingStyle) { auto& generalSettings = settings::GeneralSettings::Instance(); const std::string& customStyleDrawLayer = - generalSettings.custom_style_draw_layer().GetValue(); + generalSettings.custom_style_draw_layer().GetStagedOrValue(); const QStringList layerIds = map_->layerIds(); self_->ui->layerListWidget->clear(); self_->ui->layerListWidget->addItems(layerIds); - for (int i = 0; i < self_->ui->layerListWidget->count(); i++) - { - auto* item = self_->ui->layerListWidget->item(i); + std::string symbologyLayer = util::maplibre::FindMapSymbologyLayer( + layerIds, {customStyleDrawLayer}); - if (match_layer(customStyleDrawLayer, item->text().toStdString())) - { - self_->ui->layerListWidget->setCurrentItem(item); - } + const auto& symbologyItems = self_->ui->layerListWidget->findItems( + symbologyLayer.c_str(), Qt::MatchExactly); + if (!symbologyItems.isEmpty()) + { + self_->ui->layerListWidget->setCurrentItem(symbologyItems.first()); } } } diff --git a/scwx-qt/source/scwx/qt/util/maplibre.cpp b/scwx-qt/source/scwx/qt/util/maplibre.cpp index 63f5112e..88ae4cce 100644 --- a/scwx-qt/source/scwx/qt/util/maplibre.cpp +++ b/scwx-qt/source/scwx/qt/util/maplibre.cpp @@ -1,7 +1,9 @@ #include #include +#include #include +#include namespace scwx { @@ -120,6 +122,44 @@ void SetMapStyleUrl(const std::shared_ptr& mapContext, } } +std::string FindMapSymbologyLayer(const QStringList& styleLayers, + const std::vector& drawBelow) +{ + std::string before = "ferry"; + + for (const QString& qlayer : styleLayers) + { + const std::string layer = qlayer.toStdString(); + + // Draw below layers defined in map style + auto it = + std::ranges::find_if(drawBelow, + [&layer](const std::string& styleLayer) -> bool + { + // Perform case-insensitive matching + RE2 re {"(?i)" + styleLayer}; + if (re.ok()) + { + return RE2::FullMatch(layer, re); + } + else + { + // Fall back to basic comparison if RE + // doesn't compile + return layer == styleLayer; + } + }); + + if (it != drawBelow.cend()) + { + before = layer; + break; + } + } + + return before; +} + } // namespace maplibre } // namespace util } // namespace qt diff --git a/scwx-qt/source/scwx/qt/util/maplibre.hpp b/scwx-qt/source/scwx/qt/util/maplibre.hpp index 7c2eb58b..c03be113 100644 --- a/scwx-qt/source/scwx/qt/util/maplibre.hpp +++ b/scwx-qt/source/scwx/qt/util/maplibre.hpp @@ -37,6 +37,18 @@ glm::vec2 LatLongToScreenCoordinate(const QMapLibre::Coordinate& coordinate); void SetMapStyleUrl(const std::shared_ptr& mapContext, const std::string& url); +/** + * @brief Find the first layer which should be drawn above the radar products + * + * @param [in] styleLayers The layers of the style + * @param [in] drawBelow A list of RE2 compatible regex's describing the layers + * to draw below + * + * @return The first layer to be drawn above the radar products + */ +std::string FindMapSymbologyLayer(const QStringList& styleLayers, + const std::vector& drawBelow); + } // namespace maplibre } // namespace util } // namespace qt