mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 02:10:05 +00:00 
			
		
		
		
	Merge pull request #321 from AdenKoperczak/location_markers_part2
Location Markers Part 2
This commit is contained in:
		
						commit
						60b4833eb2
					
				
					 37 changed files with 1234 additions and 218 deletions
				
			
		|  | @ -9,10 +9,10 @@ | |||
| #include <scwx/qt/map/layer_wrapper.hpp> | ||||
| #include <scwx/qt/map/map_provider.hpp> | ||||
| #include <scwx/qt/map/map_settings.hpp> | ||||
| #include <scwx/qt/map/marker_layer.hpp> | ||||
| #include <scwx/qt/map/overlay_layer.hpp> | ||||
| #include <scwx/qt/map/overlay_product_layer.hpp> | ||||
| #include <scwx/qt/map/placefile_layer.hpp> | ||||
| #include <scwx/qt/map/marker_layer.hpp> | ||||
| #include <scwx/qt/map/radar_product_layer.hpp> | ||||
| #include <scwx/qt/map/radar_range_layer.hpp> | ||||
| #include <scwx/qt/map/radar_site_layer.hpp> | ||||
|  | @ -21,6 +21,7 @@ | |||
| #include <scwx/qt/settings/general_settings.hpp> | ||||
| #include <scwx/qt/settings/map_settings.hpp> | ||||
| #include <scwx/qt/settings/palette_settings.hpp> | ||||
| #include <scwx/qt/ui/edit_marker_dialog.hpp> | ||||
| #include <scwx/qt/util/file.hpp> | ||||
| #include <scwx/qt/util/maplibre.hpp> | ||||
| #include <scwx/qt/util/tooltip.hpp> | ||||
|  | @ -127,8 +128,6 @@ public: | |||
|       ImGui_ImplQt_Init(); | ||||
| 
 | ||||
|       InitializeCustomStyles(); | ||||
| 
 | ||||
|       ConnectSignals(); | ||||
|    } | ||||
| 
 | ||||
|    ~MapWidgetImpl() | ||||
|  | @ -219,6 +218,8 @@ public: | |||
|    std::shared_ptr<model::LayerModel> layerModel_ { | ||||
|       model::LayerModel::Instance()}; | ||||
| 
 | ||||
|    ui::EditMarkerDialog* editMarkerDialog_ {nullptr}; | ||||
| 
 | ||||
|    std::shared_ptr<manager::HotkeyManager> hotkeyManager_ { | ||||
|       manager::HotkeyManager::Instance()}; | ||||
|    std::shared_ptr<manager::PlacefileManager> placefileManager_ { | ||||
|  | @ -283,6 +284,12 @@ MapWidget::MapWidget(std::size_t id, const QMapLibre::Settings& settings) : | |||
|    setFocusPolicy(Qt::StrongFocus); | ||||
| 
 | ||||
|    ImGui_ImplQt_RegisterWidget(this); | ||||
| 
 | ||||
|    // Qt parent deals with memory management
 | ||||
|    // NOLINTNEXTLINE(cppcoreguidelines-owning-memory)
 | ||||
|    p->editMarkerDialog_ = new ui::EditMarkerDialog(this); | ||||
| 
 | ||||
|    p->ConnectSignals(); | ||||
| } | ||||
| 
 | ||||
| MapWidget::~MapWidget() | ||||
|  | @ -429,6 +436,16 @@ void MapWidgetImpl::HandleHotkeyPressed(types::Hotkey hotkey, bool isAutoRepeat) | |||
| 
 | ||||
|    switch (hotkey) | ||||
|    { | ||||
|    case types::Hotkey::AddLocationMarker: | ||||
|       if (hasMouse_) | ||||
|       { | ||||
|          auto coordinate = map_->coordinateForPixel(lastPos_); | ||||
| 
 | ||||
|          editMarkerDialog_->setup(coordinate.first, coordinate.second); | ||||
|          editMarkerDialog_->show(); | ||||
|       } | ||||
|       break; | ||||
| 
 | ||||
|    case types::Hotkey::ChangeMapStyle: | ||||
|       if (context_->settings().isActive_) | ||||
|       { | ||||
|  |  | |||
|  | @ -1,9 +1,14 @@ | |||
| #include <scwx/qt/map/marker_layer.hpp> | ||||
| #include <scwx/qt/manager/marker_manager.hpp> | ||||
| #include <scwx/util/logger.hpp> | ||||
| #include <scwx/qt/types/marker_types.hpp> | ||||
| #include <scwx/qt/types/texture_types.hpp> | ||||
| #include <scwx/qt/gl/draw/geo_icons.hpp> | ||||
| #include <scwx/qt/types/marker_types.hpp> | ||||
| #include <scwx/qt/ui/edit_marker_dialog.hpp> | ||||
| 
 | ||||
| #include <QGeoPositionInfo> | ||||
| #include <QMouseEvent> | ||||
| 
 | ||||
| #include <string> | ||||
| 
 | ||||
| namespace scwx | ||||
| { | ||||
|  | @ -19,48 +24,104 @@ class MarkerLayer::Impl | |||
| { | ||||
| public: | ||||
|    explicit Impl(MarkerLayer* self, std::shared_ptr<MapContext> context) : | ||||
|        self_ {self}, geoIcons_ {std::make_shared<gl::draw::GeoIcons>(context)} | ||||
|        self_ {self}, | ||||
|        geoIcons_ {std::make_shared<gl::draw::GeoIcons>(context)}, | ||||
|        editMarkerDialog_ {std::make_shared<ui::EditMarkerDialog>()} | ||||
|    { | ||||
|       ConnectSignals(); | ||||
|    } | ||||
|    ~Impl() {} | ||||
|    ~Impl() = default; | ||||
| 
 | ||||
|    void ReloadMarkers(); | ||||
|    void ConnectSignals(); | ||||
| 
 | ||||
|    std::shared_ptr<manager::MarkerManager> markerManager_ { | ||||
|       manager::MarkerManager::Instance()}; | ||||
| 
 | ||||
|    void set_icon_sheets(); | ||||
| 
 | ||||
|    MarkerLayer* self_; | ||||
|    const std::string& markerIconName_ { | ||||
|       types::GetTextureName(types::ImageTexture::LocationMarker)}; | ||||
| 
 | ||||
|    std::shared_ptr<gl::draw::GeoIcons> geoIcons_; | ||||
|    std::shared_ptr<ui::EditMarkerDialog> editMarkerDialog_; | ||||
| }; | ||||
| 
 | ||||
| void MarkerLayer::Impl::ConnectSignals() | ||||
| { | ||||
|    auto markerManager = manager::MarkerManager::Instance(); | ||||
| 
 | ||||
|    QObject::connect(markerManager.get(), | ||||
|          &manager::MarkerManager::MarkersUpdated, | ||||
|          self_, | ||||
|          [this]() | ||||
|          { | ||||
|             this->ReloadMarkers(); | ||||
|          }); | ||||
|    QObject::connect(markerManager_.get(), | ||||
|                     &manager::MarkerManager::MarkersUpdated, | ||||
|                     self_, | ||||
|                     [this]() { ReloadMarkers(); }); | ||||
|    QObject::connect(markerManager_.get(), | ||||
|                     &manager::MarkerManager::IconsReady, | ||||
|                     self_, | ||||
|                     [this]() { set_icon_sheets(); }); | ||||
|    QObject::connect(markerManager_.get(), | ||||
|                     &manager::MarkerManager::IconAdded, | ||||
|                     self_, | ||||
|                     [this]() { set_icon_sheets(); }); | ||||
| } | ||||
| 
 | ||||
| void MarkerLayer::Impl::ReloadMarkers() | ||||
| { | ||||
|    logger_->debug("ReloadMarkers()"); | ||||
|    auto markerManager = manager::MarkerManager::Instance(); | ||||
| 
 | ||||
|    geoIcons_->StartIcons(); | ||||
| 
 | ||||
|    markerManager->for_each( | ||||
|    markerManager_->for_each( | ||||
|       [this](const types::MarkerInfo& marker) | ||||
|       { | ||||
|          std::shared_ptr<gl::draw::GeoIconDrawItem> icon = geoIcons_->AddIcon(); | ||||
|          geoIcons_->SetIconTexture(icon, markerIconName_, 0); | ||||
|          // must use local ID, instead of reference to marker in event handler
 | ||||
|          // callback.
 | ||||
|          const types::MarkerId id = marker.id; | ||||
| 
 | ||||
|          const std::shared_ptr<gl::draw::GeoIconDrawItem> icon = | ||||
|             geoIcons_->AddIcon(); | ||||
| 
 | ||||
|          const std::string latitudeString = | ||||
|             common::GetLatitudeString(marker.latitude); | ||||
|          const std::string longitudeString = | ||||
|             common::GetLongitudeString(marker.longitude); | ||||
| 
 | ||||
|          const std::string hoverText = | ||||
|             marker.name != "" ? | ||||
|                fmt::format( | ||||
|                   "{}\n{}, {}", marker.name, latitudeString, longitudeString) : | ||||
|                fmt::format("{}, {}", latitudeString, longitudeString); | ||||
| 
 | ||||
|          auto iconInfo = markerManager_->get_icon(marker.iconName); | ||||
|          if (iconInfo) | ||||
|          { | ||||
|             geoIcons_->SetIconTexture(icon, iconInfo->name, 0); | ||||
|          } | ||||
|          else | ||||
|          { | ||||
|             geoIcons_->SetIconTexture(icon, marker.iconName, 0); | ||||
|          } | ||||
| 
 | ||||
|          geoIcons_->SetIconLocation(icon, marker.latitude, marker.longitude); | ||||
|          geoIcons_->SetIconHoverText(icon, hoverText); | ||||
|          geoIcons_->SetIconModulate(icon, marker.iconColor); | ||||
|          geoIcons_->RegisterEventHandler( | ||||
|             icon, | ||||
|             [this, id](QEvent* ev) | ||||
|             { | ||||
|                switch (ev->type()) | ||||
|                { | ||||
|                case QEvent::Type::MouseButtonPress: | ||||
|                { | ||||
|                   auto* mouseEvent = reinterpret_cast<QMouseEvent*>(ev); | ||||
|                   if (mouseEvent->buttons() == Qt::MouseButton::RightButton) | ||||
|                   { | ||||
|                      editMarkerDialog_->setup(id); | ||||
|                      editMarkerDialog_->show(); | ||||
|                   } | ||||
|                } | ||||
|                break; | ||||
| 
 | ||||
|                default: | ||||
|                   break; | ||||
|                } | ||||
|             }); | ||||
|       }); | ||||
| 
 | ||||
|    geoIcons_->FinishIcons(); | ||||
|  | @ -80,17 +141,28 @@ void MarkerLayer::Initialize() | |||
|    logger_->debug("Initialize()"); | ||||
|    DrawLayer::Initialize(); | ||||
| 
 | ||||
|    p->geoIcons_->StartIconSheets(); | ||||
|    p->geoIcons_->AddIconSheet(p->markerIconName_); | ||||
|    p->geoIcons_->FinishIconSheets(); | ||||
| 
 | ||||
|    p->set_icon_sheets(); | ||||
|    p->ReloadMarkers(); | ||||
| } | ||||
| 
 | ||||
| void MarkerLayer::Impl::set_icon_sheets() | ||||
| { | ||||
|    geoIcons_->StartIconSheets(); | ||||
|    for (auto& markerIcon : markerManager_->get_icons()) | ||||
|    { | ||||
|       geoIcons_->AddIconSheet(markerIcon.second.name, | ||||
|                               0, | ||||
|                               0, | ||||
|                               markerIcon.second.hotX, | ||||
|                               markerIcon.second.hotY); | ||||
|    } | ||||
|    geoIcons_->FinishIconSheets(); | ||||
| } | ||||
| 
 | ||||
| void MarkerLayer::Render(const QMapLibre::CustomLayerRenderParameters& params) | ||||
| { | ||||
|    // auto markerManager = manager::MarkerManager::Instance();
 | ||||
|    gl::OpenGLFunctions& gl = context()->gl(); | ||||
|    context()->set_render_parameters(params); | ||||
| 
 | ||||
|    DrawLayer::Render(params); | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Paulat
						Dan Paulat