默认暗色模式,添加值显示开关
This commit is contained in:
@@ -19,7 +19,13 @@
|
||||
using namespace creeper::plot_widget::internal;
|
||||
|
||||
struct BasicPlot::Impl {
|
||||
explicit Impl(BasicPlot& self) noexcept : self{self}, initialized(false), matrix_size(QSize{3, 4}) {}
|
||||
explicit Impl(BasicPlot& self) noexcept
|
||||
: matrix_size(QSize{3, 4})
|
||||
, color_min(0.0)
|
||||
, color_max(800.0)
|
||||
, show_labels(false)
|
||||
, initialized(false)
|
||||
, self{self} { }
|
||||
|
||||
public:
|
||||
std::optional<creeper::ColorScheme> scheme;
|
||||
@@ -41,10 +47,15 @@ public:
|
||||
|
||||
auto set_matrix_size(const QSize& size) -> void {
|
||||
matrix_size = size;
|
||||
const int expected = std::max(0, matrix_size.width() * matrix_size.height());
|
||||
last_values.assign(static_cast<std::size_t>(expected), 0.0);
|
||||
if (initialized) {
|
||||
reset_plot();
|
||||
if (!data_points.isEmpty()) {
|
||||
set_data(data_points);
|
||||
} else if (show_labels) {
|
||||
sync_labels(last_values);
|
||||
self.replot();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -75,6 +86,18 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
auto set_labels_visible(bool visible) -> void {
|
||||
show_labels = visible;
|
||||
if (initialized) {
|
||||
sync_labels(last_values);
|
||||
self.replot();
|
||||
}
|
||||
}
|
||||
|
||||
auto labels_visible() const -> bool {
|
||||
return show_labels;
|
||||
}
|
||||
|
||||
auto initialize_plot() -> void {
|
||||
if (initialized) return;
|
||||
|
||||
@@ -149,12 +172,12 @@ public:
|
||||
|
||||
auto reset_plot() -> void {
|
||||
// 清除所有绘图元素
|
||||
clear_labels();
|
||||
self.clearPlottables();
|
||||
self.clearGraphs();
|
||||
self.clearItems();
|
||||
self.clearFocus();
|
||||
color_map = nullptr;
|
||||
cell_labels.clear();
|
||||
|
||||
// 重新初始化
|
||||
initialized = false;
|
||||
@@ -163,7 +186,7 @@ public:
|
||||
auto update_plot_data() -> void {
|
||||
if (!initialized || !color_map) return;
|
||||
|
||||
ensure_labels();
|
||||
// ensure_labels();
|
||||
|
||||
const int width = matrix_size.width();
|
||||
const int height = matrix_size.height();
|
||||
@@ -182,7 +205,8 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
update_label_values(values);
|
||||
last_values = values;
|
||||
sync_labels(last_values);
|
||||
|
||||
// 重绘
|
||||
self.replot();
|
||||
@@ -201,8 +225,10 @@ private:
|
||||
QString ylabel;
|
||||
QSize matrix_size;
|
||||
QVector<PointData> data_points;
|
||||
std::vector<double> last_values;
|
||||
double color_min = 0.0;
|
||||
double color_max = 800.0;
|
||||
bool show_labels = false;
|
||||
bool initialized;
|
||||
BasicPlot& self;
|
||||
QCPColorScale* color_scale = nullptr;
|
||||
@@ -217,7 +243,7 @@ private:
|
||||
text_color = scheme->on_surface;
|
||||
}
|
||||
}
|
||||
label_text_color = QColor(0, 0, 0); // 固定黑色
|
||||
label_text_color = text_color;
|
||||
|
||||
const auto pen = QPen(text_color);
|
||||
|
||||
@@ -293,7 +319,6 @@ private:
|
||||
void update_label_values(const std::vector<double>& values) {
|
||||
const int width = matrix_size.width();
|
||||
const int height = matrix_size.height();
|
||||
const double range = std::max(color_max - color_min, 1.0);
|
||||
const int expected = width * height;
|
||||
for (int idx = 0; idx < expected && idx < cell_labels.size(); ++idx) {
|
||||
auto* label = cell_labels[idx];
|
||||
@@ -309,6 +334,18 @@ private:
|
||||
label->position->setCoords(x + 0.5, y + 0.5);
|
||||
}
|
||||
}
|
||||
|
||||
void sync_labels(const std::vector<double>& values) {
|
||||
if (!initialized) {
|
||||
return;
|
||||
}
|
||||
if (show_labels) {
|
||||
ensure_labels();
|
||||
update_label_values(values);
|
||||
} else if (!cell_labels.isEmpty()) {
|
||||
clear_labels();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
#endif // TOUCHSENSOR_HEATMAP_IMPL_HH
|
||||
|
||||
Reference in New Issue
Block a user