Skip to content

Commit

Permalink
adc: fix plot change autoscale and yctrl bug
Browse files Browse the repository at this point in the history
Signed-off-by: Adrian Suciu <adrian.suciu@analog.com>
  • Loading branch information
adisuciu committed Jul 11, 2024
1 parent c028175 commit 6d25d55
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 25 deletions.
4 changes: 4 additions & 0 deletions gui/include/gui/widgets/menuplotaxisrangecontrol.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,13 @@ public Q_SLOTS:
void setMin(double);
void setMax(double);

void addAxis(PlotAxis *ax);
void removeAxis(PlotAxis *ax);
private:
PositionSpinButton *m_min;
PositionSpinButton *m_max;

QMap<PlotAxis*, QList<QMetaObject::Connection>> connections;
};
} // namespace scopy::gui

Expand Down
33 changes: 25 additions & 8 deletions gui/src/widgets/menuplotaxisrangecontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,28 +29,45 @@ MenuPlotAxisRangeControl::MenuPlotAxisRangeControl(PlotAxis *m_plotAxis, QWidget
},
"Max", -DBL_MAX, DBL_MAX, false, false, this);

addAxis(m_plotAxis);
minMaxLayout->addWidget(m_min);
minMaxLayout->addWidget(m_max);

}


void MenuPlotAxisRangeControl::addAxis(PlotAxis *ax) {
// Connects
connect(m_min, &PositionSpinButton::valueChanged, m_plotAxis, &PlotAxis::setMin);
connect(m_min, &PositionSpinButton::valueChanged, this,

if(connections.contains(ax))
return;

connections[ax] << connect(m_min, &PositionSpinButton::valueChanged, ax, &PlotAxis::setMin);
connections[ax] << connect(m_min, &PositionSpinButton::valueChanged, this,
[=](double) { Q_EMIT intervalChanged(m_min->value(), m_max->value()); });
connect(m_plotAxis, &PlotAxis::minChanged, this, [=]() {
connections[ax] << connect(ax, &PlotAxis::minChanged, this, [=]() {
QSignalBlocker b(m_min);
m_min->setValue(m_plotAxis->min());
m_min->setValue(ax->min());
Q_EMIT intervalChanged(m_min->value(), m_max->value());
});

connect(m_max, &PositionSpinButton::valueChanged, m_plotAxis, &PlotAxis::setMax);
connect(m_max, &PositionSpinButton::valueChanged, this,
connections[ax] << connect(m_max, &PositionSpinButton::valueChanged, ax, &PlotAxis::setMax);
connections[ax] << connect(m_max, &PositionSpinButton::valueChanged, this,
[=](double) { Q_EMIT intervalChanged(m_min->value(), m_max->value()); });
connect(m_plotAxis, &PlotAxis::maxChanged, this, [=]() {
connections[ax] << connect(ax, &PlotAxis::maxChanged, this, [=]() {
QSignalBlocker b(m_max);
m_max->setValue(m_plotAxis->max());
m_max->setValue(ax->max());
Q_EMIT intervalChanged(m_min->value(), m_max->value());
});
}

void MenuPlotAxisRangeControl::removeAxis(PlotAxis *ax) {
for(const QMetaObject::Connection &c : qAsConst(connections[ax])) {
QObject::disconnect(c);
}
connections.remove(ax);
}

MenuPlotAxisRangeControl::~MenuPlotAxisRangeControl() {}

double MenuPlotAxisRangeControl::min() { return m_min->value(); }
Expand Down
16 changes: 0 additions & 16 deletions plugins/adc/src/adcinstrumentcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,22 +340,6 @@ void ADCInstrumentController::removeChannel(AcqTreeNode *node)
m_plotComponentManager->replot();
}

/*void ADCInstrumentController::createSnapshotChannel(SnapshotProvider::SnapshotRecipe rec)
{
// proxy->getChannelAddons().append(new ch)
qInfo() << "Creating snapshot from recipe" << rec.name;
int idx = chIdP->next();
ImportChannelAddon *ch = new ImportChannelAddon("REF-" + rec.name + "-" + QString::number(idx), plotAddon,
chidp->pen(idx), this);
proxy->addChannelAddon(ch);
ch->setData(rec.x, rec.y);
auto btn = addChannel(ch, vcm);
vcm->add(btn);
ch->onInit();
btn->animateClick(1);
}*/

void ADCInstrumentController::setupChannelMeasurement(PlotManager *c, ChannelComponent *ch)
{
auto chMeasureableChannel = dynamic_cast<MeasurementProvider *>(ch);
Expand Down
14 changes: 13 additions & 1 deletion plugins/adc/src/importchannelcomponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ QWidget *ImportChannelComponent::createMenu(QWidget *parent)
QWidget *ImportChannelComponent::createYAxisMenu(QWidget *parent)
{
MenuSectionCollapseWidget *section =
new MenuSectionCollapseWidget("Y-AXIS", MenuCollapseSection::MHCW_NONE, parent);
new MenuSectionCollapseWidget("Y-AXIS", MenuCollapseSection::MHCW_ONOFF, parent);

m_yCtrl = new MenuPlotAxisRangeControl(m_timePlotChannelComponent->m_timePlotYAxis, section);
m_autoscaleBtn = new QPushButton(tr("AUTOSCALE"), section);
Expand Down Expand Up @@ -103,6 +103,18 @@ QWidget *ImportChannelComponent::createCurveMenu(QWidget *parent)
return section;
}

void ImportChannelComponent::addChannelToPlot()
{
m_yCtrl->addAxis(m_timePlotChannelComponent->m_timePlotYAxis);
m_autoscaler->addChannels(m_timePlotChannelComponent->m_timePlotCh);
}

void ImportChannelComponent::removeChannelFromPlot()
{
m_yCtrl->removeAxis(m_timePlotChannelComponent->m_timePlotYAxis);
m_autoscaler->removeChannels(m_timePlotChannelComponent->m_timePlotCh);
}

void ImportChannelComponent::forgetChannel()
{
AcqTreeNode *treeRoot = m_node->treeRoot();
Expand Down
6 changes: 6 additions & 0 deletions plugins/adc/src/importchannelcomponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class SCOPY_ADC_EXPORT ImportChannelComponent : public ChannelComponent
~ImportChannelComponent();

virtual void onInit() override;

public Q_SLOTS:
void forgetChannel();

Expand All @@ -33,6 +34,11 @@ public Q_SLOTS:
QWidget *createMenu(QWidget *parent = nullptr);
QWidget *createYAxisMenu(QWidget *parent);
QWidget *createCurveMenu(QWidget *parent);

// ChannelComponent interface
public:
void addChannelToPlot() override;
void removeChannelFromPlot() override;
};
} // namespace adc
} // namespace scopy
Expand Down
4 changes: 4 additions & 0 deletions plugins/adc/src/time/grtimechannelcomponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,14 +299,18 @@ void GRTimeChannelComponent::setYModeHelper(YMode mode)

void GRTimeChannelComponent::addChannelToPlot()
{
m_yCtrl->addAxis(m_timePlotComponentChannel->m_timePlotYAxis);
m_curvemenu->addChannels(m_timePlotComponentChannel->m_timePlotCh);
m_curvemenu->addChannels(m_timePlotComponentChannel->m_xyPlotCh);
m_autoscaler->addChannels(m_timePlotComponentChannel->m_timePlotCh);
}

void GRTimeChannelComponent::removeChannelFromPlot()
{
m_yCtrl->removeAxis(m_timePlotComponentChannel->m_timePlotYAxis);
m_curvemenu->removeChannels(m_timePlotComponentChannel->m_timePlotCh);
m_curvemenu->removeChannels(m_timePlotComponentChannel->m_xyPlotCh);
m_autoscaler->removeChannels(m_timePlotComponentChannel->m_timePlotCh);
}

IIOUnit GRTimeChannelComponent::unit() const
Expand Down

0 comments on commit 6d25d55

Please sign in to comment.