73 lines
2.3 KiB
C++
73 lines
2.3 KiB
C++
#pragma once
|
|
|
|
#include <QObject>
|
|
#include <QString>
|
|
#include <vector>
|
|
#include <memory>
|
|
#include <unordered_map>
|
|
|
|
class MapLayer;
|
|
class RasterImageLayer;
|
|
class QWidget;
|
|
|
|
class MapLayerStore : public QObject
|
|
{
|
|
Q_OBJECT
|
|
|
|
struct ImageLayerEntry {
|
|
std::unique_ptr<RasterImageLayer> imageLayer;
|
|
QWidget* widget;
|
|
};
|
|
|
|
struct LayerEntry {
|
|
std::unique_ptr<MapLayer> mapLayer;
|
|
std::vector<ImageLayerEntry> imageLayers;
|
|
};
|
|
|
|
public:
|
|
explicit MapLayerStore(QObject* parent = nullptr);
|
|
~MapLayerStore() override = default;
|
|
|
|
// Layer management
|
|
void addLayer(MapLayer* layer);
|
|
void removeLayer(MapLayer* layer);
|
|
void removeLayerByName(const QString& name);
|
|
bool containsLayer(const QString& url, bool isAbsolutePath = true) const;
|
|
|
|
MapLayer* getLayer(const QString& name) const;
|
|
MapLayer* getLayerByAbsolutePath(const QString& absolutePath) const;
|
|
MapLayer* getLayerAt(int index) const;
|
|
int layerCount() const;
|
|
|
|
// ImageLayer management
|
|
void addImageLayer(MapLayer* mapLayer, RasterImageLayer* imageLayer, QWidget* widget);
|
|
void removeImageLayer(RasterImageLayer* imageLayer);
|
|
RasterImageLayer* getImageLayer(MapLayer* mapLayer, int index) const;
|
|
int imageLayerCount(MapLayer* mapLayer) const;
|
|
std::vector<RasterImageLayer*> getAllImageLayers() const;
|
|
|
|
// Widget queries
|
|
QWidget* widgetForImageLayer(RasterImageLayer* imageLayer) const;
|
|
QWidget* widgetForLayer(MapLayer* layer) const;
|
|
QWidget* widgetForLayer(const QString& absolutePath) const;
|
|
std::vector<QWidget*> widgetsForMapLayer(MapLayer* mapLayer) const;
|
|
|
|
// Reverse lookups
|
|
MapLayer* mapLayerForImageLayer(RasterImageLayer* imageLayer) const;
|
|
MapLayer* mapLayerForWidget(QWidget* widget) const;
|
|
RasterImageLayer* imageLayerForWidget(QWidget* widget) const;
|
|
|
|
signals:
|
|
void layerAdded(MapLayer* layer);
|
|
void layerAboutToBeRemoved(MapLayer* layer);
|
|
void imageLayerAdded(RasterImageLayer* imageLayer);
|
|
void imageLayerAboutToBeRemoved(RasterImageLayer* imageLayer);
|
|
|
|
private:
|
|
LayerEntry* findLayerEntry(MapLayer* mapLayer);
|
|
const LayerEntry* findLayerEntry(MapLayer* mapLayer) const;
|
|
|
|
std::vector<LayerEntry> m_layers;
|
|
std::unordered_map<MapLayer*, int> m_mapLayerIndex;
|
|
};
|