完成热力图,等待测试吧

This commit is contained in:
2025-10-20 17:23:28 +08:00
parent 6ad03fc44f
commit 453ed9e505
4 changed files with 169 additions and 36 deletions

View File

@@ -4,9 +4,91 @@
#include "heatmap.hh"
#include "heatmap.impl.hh"
#include "qcustomplot/qcustomplot.h"
#include <qcolor.h>
#include <qcolormap.h>
#include <qcontainerfwd.h>
#include <qnamespace.h>
#include <qobject.h> #include <qsize.h>
BasicPlot::BasicPlot()
: pimpl {std::make_unique<Impl>(*this)} {}
BasicPlot::BasicPlot() : pimpl{std::make_unique<Impl>(*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<QCPAxisTickerText> xticker(new QCPAxisTickerText);
QSharedPointer<QCPAxisTickerText> 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<PointData>& map) {
auto *cpmp = static_cast<QCPColorMap*>(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();
}

View File

@@ -8,50 +8,66 @@
#include "modern-qt/utility/theme/theme.hh"
#include "modern-qt/utility/wrapper/pimpl.hh"
#include "qcustomplot/qcustomplot.h"
#include <qcontainerfwd.h>
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<PointData>& 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<internal::BasicPlot>;
using XLabelText = common::pro::String<Token, [](auto& self, const auto& string) {
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) {
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} {}
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
#endif // TOUCHSENSOR_HEATMAP_H

View File

@@ -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 <memory>
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
#endif // TOUCHSENSOR_HEATMAP_IMPL_HH