Skip to content

Commit

Permalink
Add options for enabling/disabling autozoom in preferences (#704)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bartimaeus- authored Aug 5, 2022
1 parent 5166714 commit f8d45ef
Show file tree
Hide file tree
Showing 8 changed files with 151 additions and 9 deletions.
22 changes: 18 additions & 4 deletions plotjuggler_app/plotwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,8 @@ void PlotWidget::onDropEvent(QDropEvent*)
{
bool curves_changed = false;

bool noCurves = curveList().empty();

if (_dragging.mode == DragInfo::CURVES)
{
size_t scatter_count = 0;
Expand Down Expand Up @@ -603,7 +605,16 @@ void PlotWidget::onDropEvent(QDropEvent*)
{
emit curvesDropped();
emit curveListChanged();
zoomOut(true);

QSettings settings;
bool autozoom_curve_added = settings.value("Preferences::autozoom_curve_added",true).toBool();
if(autozoom_curve_added || noCurves)
{
zoomOut(autozoom_curve_added);
}
else{
replot();
}
}
_dragging.mode = DragInfo::NONE;
_dragging.curves.clear();
Expand Down Expand Up @@ -700,7 +711,7 @@ QDomElement PlotWidget::xmlSaveState(QDomDocument& doc) const
return plot_el;
}

bool PlotWidget::xmlLoadState(QDomElement& plot_widget)
bool PlotWidget::xmlLoadState(QDomElement& plot_widget, bool autozoom)
{
std::set<std::string> added_curve_names;

Expand Down Expand Up @@ -823,7 +834,7 @@ bool PlotWidget::xmlLoadState(QDomElement& plot_widget)

QDomElement rectangle = plot_widget.firstChildElement("range");

if (!rectangle.isNull())
if (!rectangle.isNull() && autozoom)
{
QRectF rect;
rect.setBottom(rectangle.attribute("bottom").toDouble());
Expand Down Expand Up @@ -888,7 +899,10 @@ bool PlotWidget::xmlLoadState(QDomElement& plot_widget)
}
}

updateMaximumZoomArea();
if(autozoom)
{
updateMaximumZoomArea();
}
replot();
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion plotjuggler_app/plotwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class PlotWidget : public PlotWidgetBase

QDomElement xmlSaveState(QDomDocument& doc) const;

bool xmlLoadState(QDomElement& element);
bool xmlLoadState(QDomElement& element, bool autozoom = true);

Range getVisualizationRangeY(Range range_X) const override;

Expand Down
10 changes: 8 additions & 2 deletions plotjuggler_app/plotwidget_transforms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,16 @@ void DialogTransformEditor::on_pushButtonSave_clicked()
{
on_lineEditAlias_editingFinished();

QSettings settings;
bool autozoom_filter_applied = settings.value("Preferences::autozoom_filter_applied",true).toBool();
QDomDocument doc;
auto elem = _plotwidget->xmlSaveState(doc);
_plotwidget_origin->xmlLoadState(elem);
_plotwidget_origin->zoomOut(false);
_plotwidget_origin->xmlLoadState(elem,autozoom_filter_applied);

if(autozoom_filter_applied)
{
_plotwidget_origin->zoomOut(false);
}

this->accept();
}
Expand Down
12 changes: 12 additions & 0 deletions plotjuggler_app/preferences_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ PreferencesDialog::PreferencesDialog(QWidget* parent)
bool use_opengl = settings.value("Preferences::use_opengl", true).toBool();
ui->checkBoxOpenGL->setChecked(use_opengl);

bool autozoom_visibility = settings.value("Preferences::autozoom_visibility",true).toBool();
ui->checkBoxAutoZoomVisibility->setChecked(autozoom_visibility);

bool autozoom_curve_added = settings.value("Preferences::autozoom_curve_added",true).toBool();
ui->checkBoxAutoZoomAdded->setChecked(autozoom_curve_added);

bool autozoom_filter_applied = settings.value("Preferences::autozoom_filter_applied",true).toBool();
ui->checkBoxAutoZoomFilter->setChecked(autozoom_filter_applied);

//---------------
auto custom_plugin_folders =
settings.value("Preferences::plugin_folders", true).toStringList();
Expand Down Expand Up @@ -82,6 +91,9 @@ void PreferencesDialog::on_buttonBox_accepted()
ui->radioLocalColorIndex->isChecked());
settings.setValue("Preferences::use_separator", ui->checkBoxSeparator->isChecked());
settings.setValue("Preferences::use_opengl", ui->checkBoxOpenGL->isChecked());
settings.setValue("Preferences::autozoom_visibility", ui->checkBoxAutoZoomVisibility->isChecked());
settings.setValue("Preferences::autozoom_curve_added", ui->checkBoxAutoZoomAdded->isChecked());
settings.setValue("Preferences::autozoom_filter_applied", ui->checkBoxAutoZoomFilter->isChecked());

QStringList plugin_folders;
for (int row = 0; row < ui->listWidgetCustom->count(); row++)
Expand Down
86 changes: 85 additions & 1 deletion plotjuggler_app/preferences_dialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<enum>Qt::NoFocus</enum>
</property>
<property name="currentIndex">
<number>0</number>
<number>1</number>
</property>
<widget class="QWidget" name="tab">
<attribute name="title">
Expand Down Expand Up @@ -254,6 +254,90 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="behaviorTab">
<attribute name="title">
<string>Behavior</string>
</attribute>
<layout class="QFormLayout" name="formLayout_2">
<item row="1" column="1">
<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>
<item row="0" column="1">
<widget class="QGroupBox" name="groupBoxAutoZoom">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>40</height>
</size>
</property>
<property name="title">
<string>Autozoom</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
<layout class="QFormLayout" name="formLayout_4">
<item row="1" column="0">
<widget class="QCheckBox" name="checkBoxAutoZoomVisibility">
<property name="text">
<string>Curve visibility toggled</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QCheckBox" name="checkBoxAutoZoomFilter">
<property name="toolTip">
<string/>
</property>
<property name="text">
<string>Filters applied to curves</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="labelAutoZoom">
<property name="text">
<string>Reset plot zoom after:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QCheckBox" name="checkBoxAutoZoomAdded">
<property name="text">
<string>Curve added to plot</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="tabPlugins">
<attribute name="title">
<string>Plugins</string>
Expand Down
10 changes: 10 additions & 0 deletions plotjuggler_app/resources/stylesheet_dark.qss
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,16 @@ QCheckBox::indicator:checked:pressed {

/* QGroupBox -------------------------------------------------------------- */

QGroupBox{
margin-top:10px;
}

QGroupBox::title {
subcontrol-origin: margin;
subcontrol-position: top left;
padding-bottom: 10px;
}

QGroupBox::indicator {
margin-left: 4px;
width: 16px;
Expand Down
10 changes: 10 additions & 0 deletions plotjuggler_app/resources/stylesheet_light.qss
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,16 @@ QCheckBox::indicator:checked:pressed {

/* QGroupBox -------------------------------------------------------------- */

QGroupBox{
margin-top:10px;
}

QGroupBox::title {
subcontrol-origin: margin;
subcontrol-position: top left;
padding-bottom: 10px;
}

QGroupBox::indicator {
margin-left: 4px;
width: 16px;
Expand Down
8 changes: 7 additions & 1 deletion plotjuggler_base/src/plotwidget_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,13 @@ bool PlotWidgetBase::eventFilter(QObject* obj, QEvent* event)
{
it.curve->setVisible(!it.curve->isVisible());
//_tracker->redraw();
resetZoom();

QSettings settings;
bool autozoom_visibility = settings.value("Preferences::autozoom_visibility",true).toBool();
if(autozoom_visibility)
{
resetZoom();
}
replot();
return true;
}
Expand Down

0 comments on commit f8d45ef

Please sign in to comment.