From 5347562b36a8a4d9cf9ff1887293cb08e1d37466 Mon Sep 17 00:00:00 2001 From: lenn Date: Tue, 21 Oct 2025 17:00:45 +0800 Subject: [PATCH] daily update --- CMakeLists.txt | 6 ++- components/charts/heatmap.cc | 44 ++++++++++++++++- components/charts/heatmap.hh | 78 +++++++++++++++++++++---------- components/charts/heatmap.impl.hh | 12 ++--- components/view.cc | 26 +++++++++-- main.cc | 2 +- 6 files changed, 129 insertions(+), 39 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9fd048e..0fc39d0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,7 +14,7 @@ set(CMAKE_AUTORCC ON) add_compile_options(-Os -O3) set(QT_VERSION Qt6) -find_package(${QT_VERSION} REQUIRED COMPONENTS Widgets Network) +find_package(${QT_VERSION} REQUIRED COMPONENTS Widgets Network PrintSupport) find_package(Eigen3 REQUIRED) # For #include "..." @@ -60,6 +60,7 @@ target_link_libraries( qcustomplot PUBLIC ${QT_VERSION}::Core ${QT_VERSION}::Gui + ${QT_VERSION}::PrintSupport ) qt_standard_project_setup() @@ -85,4 +86,5 @@ target_link_libraries( ${QT_VERSION}::Widgets ${QT_VERSION}::Network modern-qt -) \ No newline at end of file + qcustomplot +) diff --git a/components/charts/heatmap.cc b/components/charts/heatmap.cc index 6b66d11..19fabda 100644 --- a/components/charts/heatmap.cc +++ b/components/charts/heatmap.cc @@ -8,17 +8,27 @@ #include #include #include +#include #include -#include #include +#include +#include -BasicPlot::BasicPlot() : pimpl{std::make_unique(*this)} {} +BasicPlot::BasicPlot() : pimpl{std::make_unique(*this)} { + init_plot(); +} + +BasicPlot::~BasicPlot() {} void BasicPlot::set_matrix_size(const QSize& size) { + qDebug() << "set matrix size" << size; + matrix_size = size; pimpl->set_matrix_size(size); } void BasicPlot::set_matrix_size(const int& w, const int& h) { QSize size(w, h); + qDebug() << "set matrix size" << size; + matrix_size = size; pimpl->set_matrix_size(size); } @@ -38,7 +48,12 @@ QSize BasicPlot::get_matrix_size() { return matrix_size; } void BasicPlot::init_plot() { + QVector origin_data = {PointData{0, 0, 5}, PointData{0, 1, 3}, PointData{0, 2, 0}, + PointData{1, 0, 5}, PointData{1, 1, 3}, PointData{1, 2, 9}, + PointData{2, 0, 5}, PointData{2, 1, 3}, PointData{2, 2, 3}, + PointData{3, 0, 5}, PointData{3, 1, 3}, PointData{3, 2, 8}}; QCPColorMap* cpmp = new QCPColorMap(xAxis, yAxis); + qDebug() << "cpmp->data()->setSize():" << matrix_size; cpmp->data()->setSize(matrix_size.width(), matrix_size.height()); cpmp->data()->setRange(QCPRange(0.5, matrix_size.width()), (QCPRange(0.5, matrix_size.height()))); // cpmp ->setSize(matrix_size.width(), matrix_size.height()); @@ -62,6 +77,10 @@ void BasicPlot::init_plot() { xAxis->setRange(0, matrix_size.width()); yAxis->setRange(0, matrix_size.height()); + for (const auto& item : origin_data) { + cpmp->data()->setCell(item.x, item.y, item.z); + } + QCPColorScale* color_scale = new QCPColorScale(this); color_scale->setType(QCPAxis::atBottom); this->plotLayout()->addElement(1, 0, color_scale); @@ -79,6 +98,22 @@ void BasicPlot::init_plot() { color_scale->setMarginGroup(QCP::msLeft | QCP::msRight, margin_group); } +void BasicPlot::dataChanged(QVector& map) { + auto *cpmp = static_cast(this->plottable(0)); + + size_t key_size = cpmp->data()->keySize(); + size_t value_size = cpmp->data()->valueSize(); + for (auto& item : map) { + if (cpmp->data()->alpha(item.x, item.y)) { + if (cpmp->data()->alpha(item.x, item.y)) { + cpmp->data()->setCell(item.x, item.y, item.z); + } + } + } + + replot(); +} + void BasicPlot::update_dynamic_heatmap(QVector& map) { auto *cpmp = static_cast(this->plottable(0)); @@ -92,3 +127,8 @@ void BasicPlot::update_dynamic_heatmap(QVector& map) { replot(); } + +using namespace creeper; +auto HeatMapPlot::paintEvent(QPaintEvent* event) -> void { + QCustomPlot::paintEvent(event); +} diff --git a/components/charts/heatmap.hh b/components/charts/heatmap.hh index ef1ece1..574aae9 100644 --- a/components/charts/heatmap.hh +++ b/components/charts/heatmap.hh @@ -6,33 +6,42 @@ #define TOUCHSENSOR_HEATMAP_H #include "modern-qt/utility/theme/theme.hh" +#include "modern-qt/utility/wrapper/common.hh" #include "modern-qt/utility/wrapper/pimpl.hh" +#include "modern-qt/utility/wrapper/property.hh" #include "qcustomplot/qcustomplot.h" +#include "modern-qt/utility/wrapper/widget.hh" +#include #include struct point_data { double x; double y; double z; + explicit point_data(double x, double y, double z) : x{x}, y{y}, z{z} {} }; using PointData = struct point_data; namespace creeper { -class heatmap; +class HeatMapPlot; namespace plot_widget::internal { class BasicPlot : public QCustomPlot { - CREEPER_PIMPL_DEFINITION(BasicPlot); - friend heatmap; +public: + // CREEPER_PIMPL_DEFINITION(BasicPlot); + BasicPlot(); + ~BasicPlot(); + BasicPlot(const BasicPlot&) = delete; + BasicPlot& operator=(const BasicPlot&) = delete; private: struct Impl; + std::unique_ptr pimpl; + + friend HeatMapPlot; public: struct ColorSpace {}; void init_plot(); - void load_theme_manager(ThemeManager&); - - void set_xlabel_text(const QString&); - + void load_theme_manager(ThemeManager&); void set_xlabel_text(const QString&); void set_ylabel_text(const QString&); void set_matrix_size(const QSize&); @@ -41,33 +50,52 @@ class BasicPlot : public QCustomPlot { public slots: void update_dynamic_heatmap(QVector& map); + void dataChanged(QVector& map); private: QSize get_matrix_size(); private: friend class Impl; + // QSize matrix_size = {3, 4}; QSize matrix_size; }; } // namespace plot_widget::internal namespace plot_widget::pro { -using Token = common::Token; -using XLabelText = - common::pro::String; -using YLabelText = - common::pro::String; + using Token = common::Token; + using XLabelText = + common::pro::String; + using YLabelText = + common::pro::String; -struct MatrixSize : Token { - QSize size; - explicit MatrixSize(const int& w, const int& h) : size{w, h} {} - void apply(auto& self) const { - self.set_matrix_size(size.width(), size.height()); - } + struct MatrixSize : Token { + QSize size; + explicit MatrixSize(const int& w, const int& h) : size{w, h} {} + explicit MatrixSize(const QSize& s) : size{s} {} + void apply(auto& self) const { + self.set_matrix_size(size.width(), size.height()); + } + }; + + template + using OnDataChanged = + common::pro::SignalInjection; + + template + concept trait = std::derived_from; + + CREEPER_DEFINE_CHECKER(trait); + using namespace widget::pro; + using namespace theme::pro; +} +struct HeatMapPlot + : public Declarative> { + using Declarative::Declarative; + void paintEvent(QPaintEvent*) override; }; -}; // namespace plot_widget::pro -} // namespace creeper - +} #endif // TOUCHSENSOR_HEATMAP_H diff --git a/components/charts/heatmap.impl.hh b/components/charts/heatmap.impl.hh index cc33435..6d62bdf 100644 --- a/components/charts/heatmap.impl.hh +++ b/components/charts/heatmap.impl.hh @@ -25,14 +25,14 @@ struct BasicPlot::Impl { } auto load_theme_manager(ThemeManager& mgr) { - mgr.append_handler(&self, [this](const ThemeManager& mgr){ - set_color_scheme(mgr.color_scheme()); - }); + // mgr.append_handler(&self, [this](const ThemeManager& mgr){ + // set_color_scheme(mgr.color_scheme()); + // }); } - auto set_color_scheme(slider::pro::Measurements measurements) { - - } + // auto set_color_scheme(slider::pro::Measurements measurements) { + // + // } private: QString xlabel; QString ylabel; diff --git a/components/view.cc b/components/view.cc index 964ddc6..26b404d 100644 --- a/components/view.cc +++ b/components/view.cc @@ -2,10 +2,14 @@ // Created by Lenn on 2025/10/14. // +#include #include #include "component.hh" - +#include "modern-qt/utility/theme/theme.hh" +#include "modern-qt/utility/wrapper/layout.hh" +#include "modern-qt/utility/wrapper/widget.hh" +#include "components/charts/heatmap.hh" #include #include #include @@ -27,12 +31,12 @@ namespace lnpro = linear::pro; namespace impro = image::pro; namespace ibpro = icon_button::pro; namespace slpro = select_widget::pro; +namespace pwpro = plot_widget::pro; static auto ComConfigComponent(ThemeManager& manager, auto&& callback) { auto slogen_context = std::make_shared>(); slogen_context->set_silent("BanG Bream! It's MyGo!!!"); - // 创建一个MutableValue来存储MatSelect的选项 auto select_com_context = std::make_shared>(); select_com_context->set_silent(QStringList {}); @@ -138,6 +142,18 @@ static auto ComConfigComponent(ThemeManager& manager, auto&& callback) { }; } +static auto DisplayComponent(ThemeManager& manager, int index = 0) noexcept { + const auto row = new Row{ + lnpro::Item { + pwpro::MatrixSize { + QSize{3, 4} + }, + }, + }; + return new Widget { + widget::pro::Layout{row}, + }; +} auto ViewComponent(ViewComponentState& state) noexcept -> raw_pointer { const auto texts = std::array { std::make_shared>("0.500"), @@ -173,6 +189,10 @@ auto ViewComponent(ViewComponentState& state) noexcept -> raw_pointer { } }), }, + + lnpro::Item { + DisplayComponent(state.manager), + }, }, }; -} \ No newline at end of file +} diff --git a/main.cc b/main.cc index 8a39435..48e8aab 100644 --- a/main.cc +++ b/main.cc @@ -84,4 +84,4 @@ auto main(int argc, char *argv[]) -> int { }); return app::exec(); -} \ No newline at end of file +}