Files
HPPA/HPPA/MapLayerStore.h
2026-03-03 17:22:03 +08:00

49 lines
1.5 KiB
C++

#pragma once
#include <QObject>
#include <QString>
#include <vector>
#include <memory>
#include <unordered_map>
class MapLayer;
class QWidget;
class MapLayerStore : public QObject
{
Q_OBJECT
public:
explicit MapLayerStore(QObject* parent = nullptr);
~MapLayerStore() override = default;
// Take ownership of the layer (store will own and manage its lifetime)
// Now also accept the associated QWidget so UI widget can be retrieved by layer pointer
void addLayer(MapLayer* layer, QWidget* widget = nullptr);
// Remove by pointer or by name. Destruction happens when removed from store.
public slots:
void removeLayer(MapLayer* layer);
void removeLayerByName(const QString& name);
// Queries
MapLayer* getLayer(const QString& name) const;
MapLayer* getLayerAt(int index) const;
int layerCount() const;
// Get associated widget for a layer (or nullptr if none)
QWidget* widgetForLayer(MapLayer* layer) const;
// Get associated widget by layer absolute data path
QWidget* widgetForLayer(const QString& absolutePath) const;
signals:
void layerAdded(MapLayer* layer);
// Emitted just before the layer is destroyed/removed from store
void layerAboutToBeRemoved(MapLayer* layer);
private:
// store shared ownership so other parts can keep raw pointers safely (or use QPointer)
std::vector<std::shared_ptr<MapLayer>> m_layers;
// mapping from raw MapLayer pointer to associated QWidget*
std::unordered_map<MapLayer*, QWidget*> m_layerWidgets;
};