Skip to content

Commit

Permalink
gui: PlotWidget: plot grid can be disabled from prefrences
Browse files Browse the repository at this point in the history
- this also disables HDivInfo

Signed-off-by: Andrei Popa <[email protected]>
  • Loading branch information
andrei47w committed May 14, 2024
1 parent edd73ab commit 635e7c7
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
1 change: 1 addition & 0 deletions core/src/scopymainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ void ScopyMainWindow::initPreferences()
p->init("general_use_animations", true);
p->init("general_theme", "default");
p->init("general_language", "en");
p->init("show_grid", true);
p->init("general_plot_target_fps", "60");
p->init("general_show_plot_fps", true);
p->init("general_use_native_dialogs", true);
Expand Down
2 changes: 2 additions & 0 deletions core/src/scopypreferencespage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,8 @@ QWidget *ScopyPreferencesPage::buildGeneralPreferencesPage()
generalSection->contentLayout()->addWidget(PreferencesHelper::addPreferenceCheckBox(
p, "general_show_status_bar", "Enable the status bar for displaying important messages.",
generalSection));
generalSection->contentLayout()->addWidget(
PreferencesHelper::addPreferenceCheckBox(p, "show_grid", "Show Grid", generalSection));
generalSection->contentLayout()->addWidget(PreferencesHelper::addPreferenceCombo(
p, "general_theme", "Theme", {"default", "light"}, generalSection));
generalSection->contentLayout()->addWidget(PreferencesHelper::addPreferenceCombo(
Expand Down
29 changes: 27 additions & 2 deletions gui/src/plotwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,20 @@ PlotWidget::PlotWidget(QWidget *parent)
EdgelessPlotGrid *d_grid = new EdgelessPlotGrid();
QColor majorPenColor(gridpen.color());
d_grid->setMajorPen(majorPenColor, 1.0, Qt::DashLine);
d_grid->attach(m_plot);
if(Preferences::GetInstance()->get("show_grid").toBool()) {
d_grid->attach(m_plot);
}
connect(Preferences::GetInstance(), &Preferences::preferenceChanged, this,
[=](QString preference, QVariant value) {
if(preference == "show_grid") {
if(value.toBool()) {
d_grid->attach(m_plot);
} else {
d_grid->detach();
}
m_plot->replot();
}
});

// QwtPlotMarker *d_origin = new QwtPlotMarker();
// d_origin->setLineStyle( QwtPlotMarker::Cross );
Expand Down Expand Up @@ -264,8 +277,20 @@ void PlotWidget::hideDefaultAxis()
void PlotWidget::setupPlotInfo()
{
m_plotInfo = new PlotInfo(m_plot->canvas());
m_plotInfo->addCustomInfo(new HDivInfo(this), InfoPosition::IP_LEFT);
m_plotInfo->addCustomInfo(new FPSInfo(this), InfoPosition::IP_LEFT);

HDivInfo *hDivInfo = new HDivInfo(this);
m_plotInfo->addCustomInfo(hDivInfo, InfoPosition::IP_LEFT);

if(!Preferences::GetInstance()->get("show_grid").toBool()) {
hDivInfo->hide();
}
connect(Preferences::GetInstance(), &Preferences::preferenceChanged, this,
[=](QString preference, QVariant value) {
if(preference == "show_grid") {
hDivInfo->setVisible(value.toBool());
}
});
}

bool PlotWidget::showYAxisLabels() const { return m_showYAxisLabels; }
Expand Down

0 comments on commit 635e7c7

Please sign in to comment.