From 453ed9e505431efd474d70a208c9d725064bc800 Mon Sep 17 00:00:00 2001 From: lenn Date: Mon, 20 Oct 2025 17:23:28 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E7=83=AD=E5=8A=9B=E5=9B=BE?= =?UTF-8?q?=EF=BC=8C=E7=AD=89=E5=BE=85=E6=B5=8B=E8=AF=95=E5=90=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .clang-format | 14 +++++ components/charts/heatmap.cc | 88 +++++++++++++++++++++++++++++-- components/charts/heatmap.hh | 70 ++++++++++++++---------- components/charts/heatmap.impl.hh | 33 +++++++++--- 4 files changed, 169 insertions(+), 36 deletions(-) create mode 100644 .clang-format diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..000543b --- /dev/null +++ b/.clang-format @@ -0,0 +1,14 @@ +BasedOnStyle: LLVM +IndentWidth: 4 + +Language: Cpp + +DerivePointerAlignment: false +PointerAlignment: Left + + +CompileFlags: + Add: [] + Remove: [-mno-direct-extern-access, -mdirect-extern-access] + + diff --git a/components/charts/heatmap.cc b/components/charts/heatmap.cc index 4e91f4a..6b66d11 100644 --- a/components/charts/heatmap.cc +++ b/components/charts/heatmap.cc @@ -4,9 +4,91 @@ #include "heatmap.hh" #include "heatmap.impl.hh" +#include "qcustomplot/qcustomplot.h" +#include +#include +#include +#include +#include #include -BasicPlot::BasicPlot() - : pimpl {std::make_unique(*this)} {} +BasicPlot::BasicPlot() : pimpl{std::make_unique(*this)} {} -void BasicPlot::set_matrix_size(const QSize &) { +void BasicPlot::set_matrix_size(const QSize& size) { + pimpl->set_matrix_size(size); +} + +void BasicPlot::set_matrix_size(const int& w, const int& h) { + QSize size(w, h); + pimpl->set_matrix_size(size); +} + +void BasicPlot::set_xlabel_text(const QString& text) { + pimpl->set_xlabel_text(text); +} + +void BasicPlot::set_ylabel_text(const QString& text) { + pimpl->set_ylabel_text(text); +} + +void BasicPlot::load_theme_manager(ThemeManager& mgr) { + +} + +QSize BasicPlot::get_matrix_size() { + return matrix_size; +} +void BasicPlot::init_plot() { + QCPColorMap* cpmp = new QCPColorMap(xAxis, yAxis); + 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()); + // cpmp ->setRange(QCPRange(0.5, matrix_size.width() - 0.5), QCPRange(0.5, matrix_size.height() - 0.5)); + QSharedPointer xticker(new QCPAxisTickerText); + QSharedPointer yticker(new QCPAxisTickerText); + xticker->setSubTickCount(1); + xticker->setSubTickCount(1); + xAxis->setTicker(xticker); + yAxis->setTicker(yticker); + xAxis->grid()->setPen(Qt::NoPen); + yAxis->grid()->setPen(Qt::NoPen); + xAxis->grid()->setSubGridVisible(true); + yAxis->grid()->setSubGridVisible(true); + xAxis->setSubTicks(true); + yAxis->setSubTicks(true); + xAxis->setTickLength(0); + yAxis->setTickLength(0); + xAxis->setSubTickLength(6); + yAxis->setSubTickLength(6); + xAxis->setRange(0, matrix_size.width()); + yAxis->setRange(0, matrix_size.height()); + + QCPColorScale* color_scale = new QCPColorScale(this); + color_scale->setType(QCPAxis::atBottom); + this->plotLayout()->addElement(1, 0, color_scale); + cpmp->setColorScale(color_scale); + QCPColorGradient gradient; + gradient.setColorStopAt(0.0, QColor("#F6EFA6")); + gradient.setColorStopAt(1.0, QColor("#BF444C")); + cpmp->setGradient(gradient); + + cpmp->setDataRange(QCPRange(0, 10)); + cpmp->setInterpolate(false); + + QCPMarginGroup *margin_group = new QCPMarginGroup(this); + axisRect()->setMarginGroup(QCP::msLeft | QCP::msRight, margin_group); + color_scale->setMarginGroup(QCP::msLeft | QCP::msRight, margin_group); +} + +void BasicPlot::update_dynamic_heatmap(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)) { + cpmp->data()->setCell(item.x, item.y, item.z); + } + } + + replot(); } diff --git a/components/charts/heatmap.hh b/components/charts/heatmap.hh index 96e9be7..ef1ece1 100644 --- a/components/charts/heatmap.hh +++ b/components/charts/heatmap.hh @@ -8,50 +8,66 @@ #include "modern-qt/utility/theme/theme.hh" #include "modern-qt/utility/wrapper/pimpl.hh" #include "qcustomplot/qcustomplot.h" +#include +struct point_data { + double x; + double y; + double z; +}; +using PointData = struct point_data; namespace creeper { -class heatmap; +class heatmap; namespace plot_widget::internal { - class BasicPlot : public QCustomPlot { - CREEPER_PIMPL_DEFINITION(BasicPlot); - friend heatmap; +class BasicPlot : public QCustomPlot { + CREEPER_PIMPL_DEFINITION(BasicPlot); + friend heatmap; - public: - struct ColorSpace { + public: + struct ColorSpace {}; - }; + void init_plot(); - void load_theme_manager(ThemeManager&); + void load_theme_manager(ThemeManager&); - void set_xlabel_text(const QString&); + void set_xlabel_text(const QString&); - void set_ylabel_text(const QString&); + void set_ylabel_text(const QString&); - void set_matrix_size(const QSize&); + void set_matrix_size(const QSize&); - private: - friend class Impl; - }; -} + void set_matrix_size(const int& w, const int& h); + +public slots: + void update_dynamic_heatmap(QVector& map); +private: + QSize get_matrix_size(); + private: + friend class Impl; + QSize matrix_size; +}; +} // namespace plot_widget::internal namespace plot_widget::pro { - using Token = common::Token; - using XLabelText = common::pro::String; +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 { - - } +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()); } -} -} +}; +}; // namespace plot_widget::pro +} // namespace creeper -#endif //TOUCHSENSOR_HEATMAP_H \ No newline at end of file +#endif // TOUCHSENSOR_HEATMAP_H diff --git a/components/charts/heatmap.impl.hh b/components/charts/heatmap.impl.hh index 8d9975c..cc33435 100644 --- a/components/charts/heatmap.impl.hh +++ b/components/charts/heatmap.impl.hh @@ -6,17 +6,38 @@ #define TOUCHSENSOR_HEATMAP_IMPL_HH #include "heatmap.hh" - +#include "modern-qt/utility/theme/theme.hh" +#include "modern-qt/widget/sliders.hh" +#include using namespace creeper::plot_widget::internal; struct BasicPlot::Impl { - explicit Impl(BasicSelect& self) noexcept - : self{self} { + explicit Impl(BasicPlot& self) noexcept : self{self} {} + + public: + auto set_xlabel_text(const QString& text) -> void { xlabel = text; } + + auto set_ylabel_text(const QString& text) -> void { ylabel = text; } + + auto set_matrix_size(const QSize& size) { + matrix_size.setWidth(size.width()); + matrix_size.setHeight(size.height()); + } + + auto load_theme_manager(ThemeManager& mgr) { + mgr.append_handler(&self, [this](const ThemeManager& mgr){ + set_color_scheme(mgr.color_scheme()); + }); + } + + auto set_color_scheme(slider::pro::Measurements measurements) { } -private: - + private: + QString xlabel; + QString ylabel; + QSize matrix_size; BasicPlot& self; }; -#endif //TOUCHSENSOR_HEATMAP_IMPL_HH \ No newline at end of file +#endif // TOUCHSENSOR_HEATMAP_IMPL_HH