80 lines
2.0 KiB
C++
80 lines
2.0 KiB
C++
//
|
|
// Created by Codex on 2025/12/10.
|
|
//
|
|
|
|
#pragma once
|
|
|
|
#include "creeper-qt/utility/theme/theme.hh"
|
|
#include "creeper-qt/utility/wrapper/common.hh"
|
|
#include "creeper-qt/utility/wrapper/property.hh"
|
|
#include "creeper-qt/utility/wrapper/widget.hh"
|
|
#include "qcustomplot/qcustomplot.h"
|
|
#include <QPaintEvent>
|
|
#include <QPointF>
|
|
#include <concepts>
|
|
#include <optional>
|
|
#include <qsize.h>
|
|
#include <qvector.h>
|
|
|
|
namespace creeper {
|
|
class SumLinePlot;
|
|
|
|
namespace line_widget::internal {
|
|
class LinePlot: public QCustomPlot {
|
|
public:
|
|
LinePlot();
|
|
~LinePlot() override;
|
|
|
|
void load_theme_manager(ThemeManager& mgr);
|
|
void set_data(const QVector<QPointF>& points);
|
|
void set_max_points(int count);
|
|
|
|
protected:
|
|
void paintEvent(QPaintEvent* event) override;
|
|
|
|
private:
|
|
void initialize_plot();
|
|
void update_graph();
|
|
void apply_theme();
|
|
void reset_graph_range();
|
|
void trim_points();
|
|
|
|
QVector<QPointF> points_;
|
|
bool initialized_ = false;
|
|
std::optional<ColorScheme> scheme_;
|
|
QCPGraph* graph_ = nullptr;
|
|
int max_points_ = 240;
|
|
double default_y_range_ = 100.0;
|
|
};
|
|
} // namespace line_widget::internal
|
|
|
|
namespace line_widget::pro {
|
|
using Token = common::Token<internal::LinePlot>;
|
|
|
|
struct MaxPoints: Token {
|
|
int count;
|
|
explicit MaxPoints(int c): count{ c } { }
|
|
void apply(auto& self) const { self.set_max_points(count); }
|
|
};
|
|
|
|
using PlotData = DerivedProp<Token, QVector<QPointF>, [](auto& self, const auto& vec) {
|
|
self.set_data(vec);
|
|
}>;
|
|
|
|
template<class PlotWidget>
|
|
concept trait = std::derived_from<PlotWidget, Token>;
|
|
|
|
CREEPER_DEFINE_CHECKER(trait);
|
|
|
|
using namespace widget::pro;
|
|
using namespace theme::pro;
|
|
} // namespace line_widget::pro
|
|
|
|
struct SumLinePlot
|
|
: public Declarative<line_widget::internal::LinePlot,
|
|
CheckerOr<line_widget::pro::checker, widget::pro::checker, theme::pro::checker>> {
|
|
using Declarative::Declarative;
|
|
void paintEvent(QPaintEvent* event) override;
|
|
};
|
|
} // namespace creeper
|