Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#983 & #984 Add option for custom line widths #989

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions plotjuggler_app/plotwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");

Expand Down
11 changes: 11 additions & 0 deletions plotjuggler_app/plotwidget_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<double>::of(&QDoubleSpinBox::valueChanged),
this, &PlotwidgetEditor::on_widthSpinBox_changed);

// ui->listWidget->widget_background_disabled("QListView::item:selected { background:
// #ddeeff; }");

Expand Down Expand Up @@ -205,6 +209,7 @@ void PlotwidgetEditor::disableWidgets()

ui->frameLimits->setEnabled(false);
ui->frameStyle->setEnabled(false);
ui->frameWidth->setEnabled(false);
}

void PlotwidgetEditor::setupTable()
Expand Down Expand Up @@ -454,6 +459,7 @@ void PlotwidgetEditor::on_listWidget_itemSelectionChanged()
}

ui->widgetColor->setEnabled(true);
ui->widthSpinBox->setValue(_plotwidget->curvesWidth());

if (selected.size() != 1)
{
Expand All @@ -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);
}
1 change: 1 addition & 0 deletions plotjuggler_app/plotwidget_editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ private slots:
void updateLimits();
void onDeleteRow(QWidget* w);
void disableWidgets();
void on_widthSpinBox_changed(double width);

std::unordered_map<std::string, std::shared_ptr<TransformFunction>> _transforms;
};
Expand Down
90 changes: 59 additions & 31 deletions plotjuggler_app/plotwidget_editor.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>955</width>
<height>657</height>
<height>777</height>
</rect>
</property>
<property name="minimumSize">
Expand Down Expand Up @@ -242,22 +242,7 @@
<height>16777215</height>
</size>
</property>
<layout class="QVBoxLayout" name="verticalLayout_4">
<property name="spacing">
<number>10</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="label">
<property name="font">
Expand Down Expand Up @@ -341,7 +326,7 @@
</property>
</widget>
</item>
<item>
<item>
<widget class="QRadioButton" name="radioSteps">
<property name="text">
<string>Steps (pre)</string>
Expand All @@ -358,6 +343,62 @@
</layout>
</widget>
</item>
<item>
<widget class="QLabel" name="label_3">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Line Width:</string>
</property>
</widget>
</item>
<item>
<widget class="QFrame" name="frameWidth">
<property name="minimumSize">
<size>
<width>100</width>
<height>25</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>200</height>
</size>
</property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<widget class="QDoubleSpinBox" name="widthSpinBox">
<property name="decimals">
<number>1</number>
</property>
<property name="minimum">
<double>0.100000000000000</double>
</property>
<property name="maximum">
<double>10.000000000000000</double>
</property>
<property name="singleStep">
<double>0.100000000000000</double>
</property>
<property name="value">
<double>1.300000000000000</double>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QLabel" name="label_2">
<property name="font">
Expand Down Expand Up @@ -482,19 +523,6 @@
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
Expand Down
5 changes: 5 additions & 0 deletions plotjuggler_base/include/PlotJuggler/plotwidget_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ class PlotWidgetBase : public QWidget

void changeCurvesStyle(CurveStyle style);

void changeCurvesWidth(double width);

bool isXYPlot() const;

QRectF currentBoundingRect() const;
Expand All @@ -93,6 +95,8 @@ class PlotWidgetBase : public QWidget

CurveStyle curveStyle() const;

double curvesWidth() const;

bool keepRatioXY() const;

void setKeepRatioXY(bool active);
Expand Down Expand Up @@ -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;
Expand Down
24 changes: 22 additions & 2 deletions plotjuggler_base/src/plotwidget_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ class PlotWidgetBase::QwtPlotPimpl : public QwtPlot
std::list<CurveInfo> curve_list;

CurveStyle curve_style = LINES;
double curve_width = 1.3;

bool zoom_enabled = true;

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -697,8 +704,6 @@ std::map<QString, QColor> 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:
Expand All @@ -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;
Expand All @@ -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)
Expand Down
Loading