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

ADC plugin fixes #1691

Merged
merged 13 commits into from
Sep 16, 2024
Merged
10 changes: 8 additions & 2 deletions gui/include/gui/cursorcontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ class SCOPY_GUI_EXPORT CursorController : public QObject
PlotCursors *getPlotCursors();
void connectSignals(CursorSettings *cursorSettings);

void static syncXCursorControllers(CursorController *ctrl1, CursorController *ctrl2);
void static unsyncXCursorControllers(CursorController *ctrl1, CursorController *ctrl2);
bool isVisible();

public Q_SLOTS:
void setVisible(bool visible);
void readoutsSetVisible(bool visible);
Expand All @@ -32,6 +36,9 @@ public Q_SLOTS:
void onRemovedChannel(PlotChannel *ch);
void updateTracking();

Q_SIGNALS:
void visibilityChanged(bool visible);

private:
PlotWidget *m_plot;
PlotCursors *plotCursors;
Expand All @@ -47,10 +54,9 @@ public Q_SLOTS:
bool xEn, xLock, xTrack;
bool yEn, yLock;
bool readoutDragsEn;
bool m_visible;

void initUI();

// void initSession();
};
} // namespace scopy
#endif // CURSORCONTROLLER_H
4 changes: 4 additions & 0 deletions gui/include/gui/mapstackedwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ class SCOPY_GUI_EXPORT MapStackedWidget : public QStackedWidget
virtual QString getKey(QWidget *w);
virtual bool contains(QString key);
virtual QWidget *get(QString key);

QSize sizeHint() const override;
QSize minimumSizeHint() const override;

public Q_SLOTS:
virtual bool show(QString key);

Expand Down
2 changes: 1 addition & 1 deletion gui/include/gui/plotcursors.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class SCOPY_GUI_EXPORT PlotCursors : public QObject
{
Q_OBJECT
public:
PlotCursors(PlotWidget *plot);
PlotCursors(PlotWidget *plot, QObject *parent = nullptr);
~PlotCursors();

void displayIntersection();
Expand Down
3 changes: 3 additions & 0 deletions gui/include/gui/plotmagnifier.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ class SCOPY_GUI_EXPORT PlotMagnifier : public QObject
bool isXAxisEn() const;
bool isYAxisEn() const;

static double scaleToFactor(double scale, QwtAxisId axisId, QwtPlot *plot);
static double factorToScale(double factor, QwtAxisId axisId, QwtPlot *plot);

Q_SIGNALS:
void reset();
void zoomed(double factor, QPointF cursorPos = QPointF());
Expand Down
9 changes: 8 additions & 1 deletion gui/include/gui/plotnavigator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ class SCOPY_GUI_EXPORT PlotNavigator : public QObject
void removeChannel(PlotChannel *channel);

bool isZoomed();
void forcePan(QwtAxisId axisId, double factor);
void forceMagnify(QwtAxisId axisId, double factor, QPointF cursorPos);
void forceZoom(QwtAxisId axisId, const QRectF &rect);

void setZoomerXAxesEn(bool en);
void setZoomerYAxesEn(bool en);
Expand Down Expand Up @@ -95,12 +98,14 @@ class SCOPY_GUI_EXPORT PlotNavigator : public QObject
Qt::KeyboardModifier getZoomerXYModifier();

static void syncPlotNavigators(PlotNavigator *pNav1, PlotNavigator *pNav2, QSet<QwtAxisId> *axes);
static void syncPlotNavigators(PlotNavigator *pNav1, PlotNavigator *pNav2);
void setResetButtonEn(bool en);

Q_SIGNALS:
void reset();
void undo();
void rectChanged(const QRectF &rect, navigationType type);
void addedNavigator(Navigator *nav);

protected:
virtual bool eventFilter(QObject *object, QEvent *event) QWT_OVERRIDE;
Expand All @@ -115,11 +120,13 @@ class SCOPY_GUI_EXPORT PlotNavigator : public QObject
PlotMagnifier *createMagnifier(QwtAxisId axisId);
PlotZoomer *createZoomer(QwtAxisId axisId);
void addNavigators(QwtAxisId axisId);
void removeNavigators(QwtAxisId axisId);
void removeNavigators(QwtAxisId axisId, PlotChannel *channel);
void addRectToHistory(Navigator *nav, const QRectF &rect, navigationType type);
void onUndo();
void onReset();
static void syncNavigators(PlotNavigator *pNav1, Navigator *nav1, PlotNavigator *pNav2, Navigator *nav2);
static void syncPlotNavigatorSignals(PlotNavigator *pNav1, PlotNavigator *pNav2);
static void syncPlotNavigatorAxes(PlotNavigator *pNav1, PlotNavigator *pNav2, QSet<QwtAxisId> *axes);

private:
bool m_en;
Expand Down
6 changes: 6 additions & 0 deletions gui/include/gui/widgets/cursorsettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ class SCOPY_GUI_EXPORT CursorSettings : public QWidget
QAbstractButton *getYLock();
QAbstractButton *getReadoutsDrag();

void updateSession();

Q_SIGNALS:
void sessionUpdated();

protected:
void initSession();

private:
Expand Down
6 changes: 3 additions & 3 deletions gui/include/gui/widgets/plotbufferpreviewer.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class SCOPY_GUI_EXPORT PlotBufferPreviewer : public QWidget
explicit PlotBufferPreviewer(PlotWidget *p, BufferPreviewer *b, QWidget *parent = nullptr);
~PlotBufferPreviewer();

void updateDataLimits();
void setManualDataLimits(bool enabled);
void updateDataLimits(double min, double max);

public Q_SLOTS:
Expand All @@ -24,12 +24,12 @@ public Q_SLOTS:
private:
double m_bufferDataLimitMin;
double m_bufferDataLimitMax;
double m_bufferPrevInitMin;
double m_bufferPrevInitMax;
bool m_manualDataLimits;

void setupBufferPreviewer();
PlotWidget *m_plot;
BufferPreviewer *m_bufferPreviewer;
double m_lastMin;
};

} // namespace scopy
Expand Down
4 changes: 4 additions & 0 deletions gui/include/gui/widgets/verticalchannelmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <scopy-gui_export.h>
#include <compositewidget.h>

class QScrollArea;
namespace scopy {
class SCOPY_GUI_EXPORT VerticalChannelManager : public QWidget, public CompositeWidget
{
Expand All @@ -21,6 +22,9 @@ class SCOPY_GUI_EXPORT VerticalChannelManager : public QWidget, public Composite
private:
QSpacerItem *spacer;
QVBoxLayout *lay;
QVBoxLayout *m_contLayout;
QScrollArea *m_scrollArea;
QWidget *m_container;
};
} // namespace scopy

Expand Down
65 changes: 55 additions & 10 deletions gui/src/cursorcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ CursorController::CursorController(PlotWidget *plot, QObject *parent)
, yEn(true)
, yLock(false)
, readoutDragsEn(false)
, m_visible(false)
{
initUI();

Expand All @@ -27,7 +28,7 @@ CursorController::~CursorController() {}

void CursorController::initUI()
{
plotCursors = new PlotCursors(m_plot);
plotCursors = new PlotCursors(m_plot, this);
plotCursors->setVisible(false);

plotCursorReadouts = new PlotCursorReadouts(m_plot);
Expand All @@ -39,9 +40,9 @@ void CursorController::initUI()
plotCursorReadouts->setYUnits(ch->yAxis()->getUnits());
}
hoverReadouts = new HoverWidget(plotCursorReadouts, m_plot->plot()->canvas(), m_plot);
hoverReadouts->setAnchorPos(HoverPosition::HP_TOPLEFT);
hoverReadouts->setContentPos(HoverPosition::HP_BOTTOMRIGHT);
hoverReadouts->setAnchorOffset(QPoint(10, 10));
hoverReadouts->setAnchorPos(HoverPosition::HP_BOTTOMRIGHT);
hoverReadouts->setContentPos(HoverPosition::HP_TOPLEFT);
hoverReadouts->setAnchorOffset(QPoint(-10, -10));
hoverReadouts->setRelative(true);
}

Expand All @@ -60,12 +61,9 @@ void CursorController::connectSignals(CursorSettings *cursorSettings)
connect(cursorSettings->getReadoutsDrag(), &QAbstractButton::toggled, this,
&CursorController::readoutsDragToggled);

cursorSettings->initSession();

getPlotCursors()->getX1Cursor()->setPosition(0);
getPlotCursors()->getX2Cursor()->setPosition(0);
getPlotCursors()->getY1Cursor()->setPosition(0);
getPlotCursors()->getY2Cursor()->setPosition(0);
// update session in case the settings are conncted to multiple controllers
connect(cursorSettings, &CursorSettings::sessionUpdated, this, [=]() { setVisible(isVisible()); });
cursorSettings->updateSession();

// cursor movement
connect(y1Cursor, &PlotAxisHandle::scalePosChanged, this, [=](double pos) {
Expand Down Expand Up @@ -178,10 +176,57 @@ void CursorController::updateTracking()
}
}

void CursorController::syncXCursorControllers(CursorController *ctrl1, CursorController *ctrl2)
{
ctrl2->setVisible(ctrl1->isVisible());
ctrl2->x1Cursor->setPosition(ctrl1->x1Cursor->getPosition());
ctrl2->x2Cursor->setPosition(ctrl1->x2Cursor->getPosition());

// connect ctrl1 to ctrl2
connect(ctrl1->x1Cursor, &PlotAxisHandle::scalePosChanged, ctrl2->x1Cursor, [=](double pos) {
ctrl1->x1Cursor->blockSignals(true);
ctrl2->x1Cursor->setPosition(pos);
ctrl1->x1Cursor->blockSignals(false);
ctrl2->m_plot->repaint();
});
connect(ctrl1->x2Cursor, &PlotAxisHandle::scalePosChanged, ctrl2->x2Cursor, [=](double pos) {
ctrl1->x2Cursor->blockSignals(true);
ctrl2->x2Cursor->setPosition(pos);
ctrl1->x2Cursor->blockSignals(false);
ctrl2->m_plot->repaint();
});

// connect ctrl2 to ctrl1
connect(ctrl2->x1Cursor, &PlotAxisHandle::scalePosChanged, ctrl1->x1Cursor, [=](double pos) {
ctrl2->x1Cursor->blockSignals(true);
ctrl1->x1Cursor->setPosition(pos);
ctrl2->x1Cursor->blockSignals(false);
ctrl1->m_plot->repaint();
});
connect(ctrl2->x2Cursor, &PlotAxisHandle::scalePosChanged, ctrl1->x2Cursor, [=](double pos) {
ctrl2->x2Cursor->blockSignals(true);
ctrl1->x2Cursor->setPosition(pos);
ctrl2->x2Cursor->blockSignals(false);
ctrl1->m_plot->repaint();
});
}

void CursorController::unsyncXCursorControllers(CursorController *ctrl1, CursorController *ctrl2)
{
disconnect(ctrl1->x1Cursor, &PlotAxisHandle::scalePosChanged, ctrl2->x1Cursor, nullptr);
disconnect(ctrl1->x2Cursor, &PlotAxisHandle::scalePosChanged, ctrl2->x2Cursor, nullptr);
disconnect(ctrl2->x1Cursor, &PlotAxisHandle::scalePosChanged, ctrl1->x1Cursor, nullptr);
disconnect(ctrl2->x2Cursor, &PlotAxisHandle::scalePosChanged, ctrl1->x2Cursor, nullptr);
}

bool CursorController::isVisible() { return m_visible; }

void CursorController::setVisible(bool visible)
{
m_visible = visible;
readoutsSetVisible(visible);
cursorsSetVisible(visible);
Q_EMIT visibilityChanged(visible);
}

void CursorController::readoutsSetVisible(bool visible) { hoverReadouts->setVisible(visible && (xEn || yEn)); }
Expand Down
16 changes: 16 additions & 0 deletions gui/src/mapstackedwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,22 @@ QWidget *MapStackedWidget::get(QString key)
return nullptr;
}

QSize MapStackedWidget::sizeHint() const
{
if(currentWidget()) {
return currentWidget()->sizeHint();
}
return QStackedWidget::sizeHint();
}

QSize MapStackedWidget::minimumSizeHint() const
{
if(currentWidget()) {
return currentWidget()->minimumSizeHint();
}
return QStackedWidget::minimumSizeHint();
}

bool MapStackedWidget::show(QString key)
{
QWidget *w = map[key];
Expand Down
9 changes: 7 additions & 2 deletions gui/src/plotcursors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@

using namespace scopy;

PlotCursors::PlotCursors(PlotWidget *plot)
: m_plot(plot)
PlotCursors::PlotCursors(PlotWidget *plot, QObject *parent)
: QObject(parent)
, m_plot(plot)
, m_tracking(false)
{
initUI();
Expand All @@ -19,6 +20,10 @@ void PlotCursors::initUI()
m_yCursors.second = new PlotAxisHandle(m_plot, m_plot->yAxis());
m_xCursors.first = new PlotAxisHandle(m_plot, m_plot->xAxis());
m_xCursors.second = new PlotAxisHandle(m_plot, m_plot->xAxis());
m_xCursors.first->setPosition(0);
m_xCursors.second->setPosition(0);
m_yCursors.first->setPosition(0);
m_yCursors.second->setPosition(0);

plotMarker1 = new QwtPlotMarker();
plotMarker2 = new QwtPlotMarker();
Expand Down
16 changes: 15 additions & 1 deletion gui/src/plotmagnifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,20 @@ bool PlotMagnifier::eventFilter(QObject *object, QEvent *event)
return QObject::eventFilter(object, event);
}

double PlotMagnifier::scaleToFactor(double scale, QwtAxisId axisId, QwtPlot *plot)
{
double v1 = plot->axisInterval(axisId).minValue();
double v2 = plot->axisInterval(axisId).maxValue();
return (scale / 0.5 - (v2 - v1)) / (v1 - v2);
}

double PlotMagnifier::factorToScale(double factor, QwtAxisId axisId, QwtPlot *plot)
{
double v1 = plot->axisInterval(axisId).minValue();
double v2 = plot->axisInterval(axisId).maxValue();
return ((v2 - v1) - (v2 - v1) * factor) * 0.5;
}

void PlotMagnifier::panRescale(double factor)
{
if(isXAxisEn()) {
Expand All @@ -190,7 +204,7 @@ void PlotMagnifier::panRescale(double factor)

double v1 = plot()->axisInterval(axisId).minValue();
double v2 = plot()->axisInterval(axisId).maxValue();
double pan_amount = (((v2 - v1) - (v2 - v1) * factor) * 0.5);
double pan_amount = factorToScale(factor, axisId, plot());
bool isInverted = v1 > v2;

if(isInverted) {
Expand Down
Loading
Loading