diff --git a/src/app/panels/chart/IDatasetChartStrategy.hpp b/src/app/panels/chart/IDatasetChartStrategy.hpp new file mode 100644 index 0000000..7fdc240 --- /dev/null +++ b/src/app/panels/chart/IDatasetChartStrategy.hpp @@ -0,0 +1,29 @@ +#pragma once +#include +#include +#include +namespace geopro::app { + +class DatasetDetailPage; // 前置 + +// dd 类型驱动的图表策略:决定某 ddCode 的详情页如何加载/渲染。 +struct IDatasetChartStrategy { + virtual ~IDatasetChartStrategy() = default; + virtual std::string ddCode() const = 0; +}; + +class ChartStrategyRegistry { +public: + void add(std::unique_ptr s) { + const std::string code = s->ddCode(); + map_[code] = std::move(s); + } + IDatasetChartStrategy* find(const std::string& ddCode) const { + auto it = map_.find(ddCode); + return it == map_.end() ? nullptr : it->second.get(); + } + bool supports(const std::string& ddCode) const { return map_.count(ddCode) > 0; } +private: + std::map> map_; +}; +} // namespace geopro::app diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 6e60a4e..8db9c60 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -80,4 +80,7 @@ target_sources(geopro_tests PRIVATE render/test_terrain.cpp) target_link_libraries(geopro_tests PRIVATE geopro_render ${VTK_LIBRARIES}) vtk_module_autoinit(TARGETS geopro_tests MODULES ${VTK_LIBRARIES}) +target_include_directories(geopro_tests PRIVATE ${CMAKE_SOURCE_DIR}/src/app) +target_sources(geopro_tests PRIVATE app/test_chart_strategy_registry.cpp) + add_subdirectory(spike) # spike S3: banded contour 渲染验证 diff --git a/tests/app/test_chart_strategy_registry.cpp b/tests/app/test_chart_strategy_registry.cpp new file mode 100644 index 0000000..ad6da01 --- /dev/null +++ b/tests/app/test_chart_strategy_registry.cpp @@ -0,0 +1,14 @@ +#include +#include "panels/chart/IDatasetChartStrategy.hpp" +using namespace geopro::app; +namespace { +struct Fake : IDatasetChartStrategy { std::string ddCode() const override { return "dd_inversion_data"; } }; +} +TEST(ChartStrategyRegistry, FindsRegisteredAndDegradesUnknown) { + ChartStrategyRegistry reg; + reg.add(std::make_unique()); + EXPECT_TRUE(reg.supports("dd_inversion_data")); + EXPECT_NE(reg.find("dd_inversion_data"), nullptr); + EXPECT_FALSE(reg.supports("dd_unknown")); + EXPECT_EQ(reg.find("dd_unknown"), nullptr); +}