From fffafe7cac8881ee569752b5e8298ff5ccc23d78 Mon Sep 17 00:00:00 2001 From: Zach Davis Date: Thu, 4 Jul 2024 15:12:24 -0500 Subject: [PATCH] #983 & #984 Add option for custom line widths --- plotjuggler_app/plotwidget.cpp | 13 +++ plotjuggler_app/plotwidget_editor.cpp | 11 +++ plotjuggler_app/plotwidget_editor.h | 1 + plotjuggler_app/plotwidget_editor.ui | 90 ++++++++++++------- .../include/PlotJuggler/plotwidget_base.h | 5 ++ plotjuggler_base/src/plotwidget_base.cpp | 24 ++++- 6 files changed, 111 insertions(+), 33 deletions(-) diff --git a/plotjuggler_app/plotwidget.cpp b/plotjuggler_app/plotwidget.cpp index 9f06b59e8..5c5a37720 100644 --- a/plotjuggler_app/plotwidget.cpp +++ b/plotjuggler_app/plotwidget.cpp @@ -682,6 +682,8 @@ QDomElement PlotWidget::xmlSaveState(QDomDocument& doc) const plot_el.setAttribute("style", "StepsInv"); } + plot_el.setAttribute("curve_width", QString::number(curvesWidth())); + for (auto& it : curveList()) { auto& name = it.src_name; @@ -890,6 +892,17 @@ bool PlotWidget::xmlLoadState(QDomElement& plot_widget, bool autozoom) } } + if (plot_widget.hasAttribute("curve_width")) + { + double curve_width = plot_widget.attribute("curve_width").toDouble(); + if (curve_width <= 0.0) + { + curve_width = 1.3; + } + + changeCurvesWidth(curve_width); + } + QString bg_data = plot_widget.attribute("background_data"); QString bg_colormap = plot_widget.attribute("background_colormap"); diff --git a/plotjuggler_app/plotwidget_editor.cpp b/plotjuggler_app/plotwidget_editor.cpp index 117f34d63..f23730cd7 100644 --- a/plotjuggler_app/plotwidget_editor.cpp +++ b/plotjuggler_app/plotwidget_editor.cpp @@ -104,6 +104,10 @@ PlotwidgetEditor::PlotwidgetEditor(PlotWidget* plotwidget, QWidget* parent) ui->lineLimitMax->setText(QString::number(suggested_limits.max)); } + ui->widthSpinBox->setValue(_plotwidget->curvesWidth()); + connect(ui->widthSpinBox, QOverload::of(&QDoubleSpinBox::valueChanged), + this, &PlotwidgetEditor::on_widthSpinBox_changed); + // ui->listWidget->widget_background_disabled("QListView::item:selected { background: // #ddeeff; }"); @@ -205,6 +209,7 @@ void PlotwidgetEditor::disableWidgets() ui->frameLimits->setEnabled(false); ui->frameStyle->setEnabled(false); + ui->frameWidth->setEnabled(false); } void PlotwidgetEditor::setupTable() @@ -454,6 +459,7 @@ void PlotwidgetEditor::on_listWidget_itemSelectionChanged() } ui->widgetColor->setEnabled(true); + ui->widthSpinBox->setValue(_plotwidget->curvesWidth()); if (selected.size() != 1) { @@ -467,3 +473,8 @@ void PlotwidgetEditor::on_listWidget_itemSelectionChanged() ui->editColotText->setText(row_widget->color().name()); } } + +void PlotwidgetEditor::on_widthSpinBox_changed(double width) +{ + _plotwidget->changeCurvesWidth(width); +} diff --git a/plotjuggler_app/plotwidget_editor.h b/plotjuggler_app/plotwidget_editor.h index 6c1ac7cf2..80765de0a 100644 --- a/plotjuggler_app/plotwidget_editor.h +++ b/plotjuggler_app/plotwidget_editor.h @@ -104,6 +104,7 @@ private slots: void updateLimits(); void onDeleteRow(QWidget* w); void disableWidgets(); + void on_widthSpinBox_changed(double width); std::unordered_map> _transforms; }; diff --git a/plotjuggler_app/plotwidget_editor.ui b/plotjuggler_app/plotwidget_editor.ui index cc49f2c34..7e432a780 100644 --- a/plotjuggler_app/plotwidget_editor.ui +++ b/plotjuggler_app/plotwidget_editor.ui @@ -7,7 +7,7 @@ 0 0 955 - 657 + 777 @@ -242,22 +242,7 @@ 16777215 - - - 10 - - - 0 - - - 0 - - - 0 - - - 0 - + @@ -341,7 +326,7 @@ - + Steps (pre) @@ -358,6 +343,62 @@ + + + + + 75 + true + + + + Line Width: + + + + + + + + 100 + 25 + + + + + 16777215 + 200 + + + + QFrame::NoFrame + + + QFrame::Plain + + + + + + 1 + + + 0.100000000000000 + + + 10.000000000000000 + + + 0.100000000000000 + + + 1.300000000000000 + + + + + + @@ -482,19 +523,6 @@ - - - - Qt::Vertical - - - - 20 - 40 - - - - diff --git a/plotjuggler_base/include/PlotJuggler/plotwidget_base.h b/plotjuggler_base/include/PlotJuggler/plotwidget_base.h index 8b5b3fd88..1afdca06e 100644 --- a/plotjuggler_base/include/PlotJuggler/plotwidget_base.h +++ b/plotjuggler_base/include/PlotJuggler/plotwidget_base.h @@ -85,6 +85,8 @@ class PlotWidgetBase : public QWidget void changeCurvesStyle(CurveStyle style); + void changeCurvesWidth(double width); + bool isXYPlot() const; QRectF currentBoundingRect() const; @@ -93,6 +95,8 @@ class PlotWidgetBase : public QWidget CurveStyle curveStyle() const; + double curvesWidth() const; + bool keepRatioXY() const; void setKeepRatioXY(bool active); @@ -125,6 +129,7 @@ public slots: QwtPlotPimpl* p = nullptr; static void setStyle(QwtPlotCurve* curve, CurveStyle style); + static void setWidth(QwtPlotCurve* curve, double width); QwtPlot* qwtPlot(); const QwtPlot* qwtPlot() const; diff --git a/plotjuggler_base/src/plotwidget_base.cpp b/plotjuggler_base/src/plotwidget_base.cpp index 02a00dddf..cac7ac5d9 100644 --- a/plotjuggler_base/src/plotwidget_base.cpp +++ b/plotjuggler_base/src/plotwidget_base.cpp @@ -141,6 +141,7 @@ class PlotWidgetBase::QwtPlotPimpl : public QwtPlot std::list curve_list; CurveStyle curve_style = LINES; + double curve_width = 1.3; bool zoom_enabled = true; @@ -430,6 +431,7 @@ PlotWidgetBase::CurveInfo* PlotWidgetBase::addCurve(const std::string& name, curve->setPen(color); setStyle(curve, p->curve_style); + setWidth(curve, p->curve_width); curve->setRenderHint(QwtPlotItem::RenderAntialiased, true); @@ -501,6 +503,11 @@ PlotWidgetBase::CurveStyle PlotWidgetBase::curveStyle() const return p->curve_style; } +double PlotWidgetBase::curvesWidth() const +{ + return p->curve_width; +} + bool PlotWidgetBase::keepRatioXY() const { return _keep_aspect_ratio; @@ -697,8 +704,6 @@ std::map PlotWidgetBase::getCurveColors() const void PlotWidgetBase::setStyle(QwtPlotCurve* curve, CurveStyle style) { - curve->setPen(curve->pen().color(), (style == DOTS) ? 4.0 : 1.3); - switch (style) { case LINES: @@ -724,6 +729,11 @@ void PlotWidgetBase::setStyle(QwtPlotCurve* curve, CurveStyle style) } } +void PlotWidgetBase::setWidth(QwtPlotCurve* curve, double width) +{ + curve->setPen(curve->pen().color(), width); +} + void PlotWidgetBase::changeCurvesStyle(CurveStyle style) { p->curve_style = style; @@ -734,6 +744,16 @@ void PlotWidgetBase::changeCurvesStyle(CurveStyle style) replot(); } +void PlotWidgetBase::changeCurvesWidth(double width) +{ + p->curve_width = width; + for (auto& it : p->curve_list) + { + setWidth(it.curve, width); + } + replot(); +} + PlotWidgetBase::CurveInfo* PlotWidgetBase::curveFromTitle(const QString& title) { for (auto& info : p->curve_list)