Files
ts-qt/components/charts/heatmap.hh
2025-10-21 17:00:45 +08:00

102 lines
2.8 KiB
C++

//
// Created by Lenn on 2025/10/17.
//
#ifndef TOUCHSENSOR_HEATMAP_H
#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 <concepts>
#include <qcontainerfwd.h>
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 HeatMapPlot;
namespace plot_widget::internal {
class BasicPlot : public QCustomPlot {
public:
// CREEPER_PIMPL_DEFINITION(BasicPlot);
BasicPlot();
~BasicPlot();
BasicPlot(const BasicPlot&) = delete;
BasicPlot& operator=(const BasicPlot&) = delete; private: struct Impl;
std::unique_ptr<Impl> pimpl;
friend HeatMapPlot;
public:
struct ColorSpace {};
void init_plot();
void load_theme_manager(ThemeManager&); void set_xlabel_text(const QString&);
void set_ylabel_text(const QString&);
void set_matrix_size(const QSize&);
void set_matrix_size(const int& w, const int& h);
public slots:
void update_dynamic_heatmap(QVector<PointData>& map);
void dataChanged(QVector<PointData>& 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<internal::BasicPlot>;
using XLabelText =
common::pro::String<Token, [](auto& self, const auto& string) {
self.set_xlabel_text(string);
}>;
using YLabelText =
common::pro::String<Token, [](auto& self, const auto& string) {
self.set_ylabel_text(string);
}>;
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 <typename F>
using OnDataChanged =
common::pro::SignalInjection<F, Token, &internal::BasicPlot::dataChanged>;
template<class PlotWidget>
concept trait = std::derived_from<PlotWidget, Token>;
CREEPER_DEFINE_CHECKER(trait);
using namespace widget::pro;
using namespace theme::pro;
}
struct HeatMapPlot
: public Declarative<plot_widget::internal::BasicPlot,
CheckerOr<plot_widget::pro::checker, widget::pro::checker, theme::pro::checker>> {
using Declarative::Declarative;
void paintEvent(QPaintEvent*) override;
};
}
#endif // TOUCHSENSOR_HEATMAP_H