daily update
This commit is contained in:
@@ -8,17 +8,27 @@
|
||||
#include <qcolor.h>
|
||||
#include <qcolormap.h>
|
||||
#include <qcontainerfwd.h>
|
||||
#include <qdebug.h>
|
||||
#include <qnamespace.h>
|
||||
#include <qobject.h> #include <qsize.h>
|
||||
#include <qobject.h>
|
||||
#include <qsize.h>
|
||||
|
||||
BasicPlot::BasicPlot() : pimpl{std::make_unique<Impl>(*this)} {}
|
||||
BasicPlot::BasicPlot() : pimpl{std::make_unique<Impl>(*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<PointData> 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<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)) {
|
||||
if (cpmp->data()->alpha(item.x, item.y)) {
|
||||
cpmp->data()->setCell(item.x, item.y, item.z);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
replot();
|
||||
}
|
||||
|
||||
void BasicPlot::update_dynamic_heatmap(QVector<PointData>& map) {
|
||||
auto *cpmp = static_cast<QCPColorMap*>(this->plottable(0));
|
||||
|
||||
@@ -92,3 +127,8 @@ void BasicPlot::update_dynamic_heatmap(QVector<PointData>& map) {
|
||||
|
||||
replot();
|
||||
}
|
||||
|
||||
using namespace creeper;
|
||||
auto HeatMapPlot::paintEvent(QPaintEvent* event) -> void {
|
||||
QCustomPlot::paintEvent(event);
|
||||
}
|
||||
|
||||
@@ -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 <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 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<Impl> 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<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);
|
||||
}>;
|
||||
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} {}
|
||||
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 <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;
|
||||
};
|
||||
}; // namespace plot_widget::pro
|
||||
} // namespace creeper
|
||||
|
||||
}
|
||||
#endif // TOUCHSENSOR_HEATMAP_H
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user