默认暗色模式,添加值显示开关

This commit is contained in:
2025-12-16 19:18:21 +08:00
parent a1f7f337c2
commit 5b319cb76d
14 changed files with 372 additions and 75 deletions

View File

@@ -171,11 +171,14 @@ class SensorStreamController: public QObject {
std::shared_ptr<MutableValue<QVector<PointData>>> heatmap_data,
std::shared_ptr<MutableValue<QSize>> matrix_context,
std::shared_ptr<MutableValue<QVector<QPointF>>> line_series,
std::shared_ptr<MutableValue<QVector<QPointF>>> line_series_max,
int line_capacity = 240,
QObject* parent = nullptr): QObject(parent), heatmap_data_(std::move(heatmap_data)),
matrix_context_(std::move(matrix_context)),
line_series_(std::move(line_series)),
line_series_capacity_(std::max(1, line_capacity)) {
line_series_max_(std::move(line_series_max)),
line_series_capacity_(std::max(1, line_capacity)),
line_series_half_capacity_(std::max(1, line_capacity / 2)) {
std::call_once(codec_registration_flag(),
[] {
ffmsep::tactile::register_tactile_codec();
@@ -197,6 +200,9 @@ class SensorStreamController: public QObject {
if (line_series_) {
line_series_->set(QVector<QPointF>{});
}
if (line_series_max_) {
line_series_max_->set(QVector<QPointF>{});
}
const auto ports = ffmsep::CPStreamCore::list_available_ports();
std::string port_utf8;
@@ -335,6 +341,9 @@ class SensorStreamController: public QObject {
if (line_series_) {
line_series_->set(QVector<QPointF>{});
}
if (line_series_max_) {
line_series_max_->set(QVector<QPointF>{});
}
sample_counter_ = 0;
}
@@ -444,8 +453,13 @@ class SensorStreamController: public QObject {
}
double total = 0.0;
double max_v = 0.0;
for (const auto value: pressures) {
total += static_cast<double>(value);
const double v = static_cast<double>(value);
total += v;
if (v > max_v) {
max_v = v;
}
}
if (line_series_) {
@@ -456,9 +470,19 @@ class SensorStreamController: public QObject {
const int start = series.size() - line_series_capacity_;
series = series.mid(start);
}
++sample_counter_;
line_series_->set(std::move(series));
}
if (line_series_max_) {
auto series = line_series_max_->get();
series.append(QPointF(static_cast<double>(sample_counter_), max_v));
const int cap = std::max(1, line_series_half_capacity_);
if (series.size() > cap) {
const int start = series.size() - cap;
series = series.mid(start);
}
line_series_max_->set(std::move(series));
}
++sample_counter_;
QVector<PointData> points;
points.reserve(matrix.width() * matrix.height());
@@ -546,11 +570,13 @@ class SensorStreamController: public QObject {
std::shared_ptr<MutableValue<QVector<PointData>>> heatmap_data_;
std::shared_ptr<MutableValue<QSize>> matrix_context_;
std::shared_ptr<MutableValue<QVector<QPointF>>> line_series_;
std::shared_ptr<MutableValue<QVector<QPointF>>> line_series_max_;
std::unique_ptr<ffmsep::CPStreamCore> core_;
QString active_port_;
QString last_error_;
std::uint64_t sample_counter_ = 0;
int line_series_capacity_ = 240;
int line_series_half_capacity_ = 120;
bool connected_ = false;
static std::future<ffmsep::persist::WriteResult>
@@ -573,8 +599,12 @@ struct SensorUiState {
std::make_shared<MutableValue<QSize>>();
std::shared_ptr<MutableValue<QPair<int, int>>> heatmap_range =
std::make_shared<MutableValue<QPair<int, int>>>(QPair<int, int>{ 0, 300 });
std::shared_ptr<MutableValue<bool>> heatmap_show_numbers =
std::make_shared<MutableValue<bool>>(false);
std::shared_ptr<MutableValue<QVector<QPointF>>> line_series =
std::make_shared<MutableValue<QVector<QPointF>>>();
std::shared_ptr<MutableValue<QVector<QPointF>>> line_series_max =
std::make_shared<MutableValue<QVector<QPointF>>>();
int line_series_capacity = 240;
std::shared_ptr<MutableValue<QStringList>> port_items =
std::make_shared<MutableValue<QStringList>>();
@@ -631,7 +661,7 @@ struct SensorUiState {
controller =
std::make_unique<SensorStreamController>(
heatmap_data, heatmap_matrix, line_series, line_series_capacity);
heatmap_data, heatmap_matrix, line_series, line_series_max, line_series_capacity);
}
};
@@ -674,6 +704,10 @@ class PortHoverRefreshFilter final: public QObject {
} // namespace
std::shared_ptr<MutableValue<bool>> HeatmapNumberVisibilityContext() {
return sensor_state().heatmap_show_numbers;
}
void RefreshProfilesForView() {
auto& sensor = sensor_state();
@@ -912,9 +946,10 @@ int /*index*/ = 0) noexcept {
auto& sensor = sensor_state();
const auto row = new Row{
lnpro::Item<HeatMapPlot>{
plot_widget::pro::SizePolicy{
QSizePolicy::Expanding,
},
widget::pro::FixedSize {600, 600},
// plot_widget::pro::SizePolicy{
// // QSizePolicy::Fixed,
// },
plot_widget::pro::ThemeManager{ manager },
MutableForward{
plot_widget::pro::PlotData{},
@@ -933,6 +968,10 @@ int /*index*/ = 0) noexcept {
widget.set_color_gradient_range(min, max);
},
sensor.heatmap_range },
MutableTransform{ [](auto& widget, bool show_numbers) {
widget.set_labels_visible(show_numbers);
},
sensor.heatmap_show_numbers },
},
};
return new Widget{
@@ -966,21 +1005,29 @@ static auto DisplayVectorComponent(ThemeManager& manager) noexcept {
static auto DisplayLineComponent(ThemeManager& manager) noexcept {
auto& sensor = sensor_state();
const auto row = new Row{
const int half_cap = std::max(1, sensor.line_series_capacity / 2);
const auto col = new Col{
lnpro::Item<SumLinePlot>{
lcpro::SizePolicy{
QSizePolicy::Expanding,
},
lcpro::SizePolicy{ QSizePolicy::Expanding },
lcpro::ThemeManager{ manager },
lcpro::MaxPoints{ sensor.line_series_capacity },
lcpro::MaxPoints{ half_cap },
MutableForward{
lcpro::PlotData{},
sensor.line_series,
},
},
lnpro::Item<SumLinePlot>{
lcpro::SizePolicy{ QSizePolicy::Expanding },
lcpro::ThemeManager{ manager },
lcpro::MaxPoints{ half_cap },
MutableForward{
lcpro::PlotData{},
sensor.line_series_max,
},
},
};
return new Widget{
widget::pro::Layout{ row },
widget::pro::Layout{ col },
};
}