#include "MapLayerStore.h" #include "MapLayer.h" MapLayerStore::MapLayerStore(QObject* parent) : QObject(parent) { int a = 1; } void MapLayerStore::addLayer(MapLayer* layer, QWidget* widget) { if (!layer) return; MapLayer* raw = layer; m_layers.emplace_back(std::shared_ptr(layer)); if (widget) m_layerWidgets[raw] = widget; emit layerAdded(raw); } void MapLayerStore::removeLayer(MapLayer* layer) { if (!layer) return; for (auto it = m_layers.begin(); it != m_layers.end(); ++it) { if (it->get() == layer) { emit layerAboutToBeRemoved(layer); m_layers.erase(it); m_layerWidgets.erase(layer); return; } } } void MapLayerStore::removeLayerByName(const QString& name) { for (auto it = m_layers.begin(); it != m_layers.end(); ++it) { if ((*it)->name() == name) { MapLayer* raw = it->get(); emit layerAboutToBeRemoved(raw); m_layers.erase(it); m_layerWidgets.erase(raw); return; } } } MapLayer* MapLayerStore::getLayer(const QString& name) const { for (const auto& l : m_layers) { if (l->name() == name) return l.get(); } return nullptr; } MapLayer* MapLayerStore::getLayerAt(int index) const { if (index < 0 || index >= (int)m_layers.size()) return nullptr; return m_layers[index].get(); } int MapLayerStore::layerCount() const { return (int)m_layers.size(); } QWidget* MapLayerStore::widgetForLayer(MapLayer* layer) const { auto it = m_layerWidgets.find(layer); if (it == m_layerWidgets.end()) return nullptr; return it->second; } QWidget* MapLayerStore::widgetForLayer(const QString& absolutePath) const { for (const auto& sp : m_layers) { if (sp && sp->dataPath() == absolutePath) { MapLayer* raw = sp.get(); auto it = m_layerWidgets.find(raw); if (it != m_layerWidgets.end()) return it->second; return nullptr; } } return nullptr; }