Skip to content

Commit

Permalink
pqm: Add DockWidgets to RMS and Waveforms instruments
Browse files Browse the repository at this point in the history
Signed-off-by: Andrei-Fabian-Pop <[email protected]>
  • Loading branch information
Andrei-Fabian-Pop committed Dec 13, 2024
1 parent abb8f71 commit 0893e1d
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 20 deletions.
9 changes: 8 additions & 1 deletion plugins/pqm/include/pqm/rmsinstrument.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@
#ifndef RMSINSTRUMENT_H
#define RMSINSTRUMENT_H
#include <QWidget>
#include <gui/widgets/measurementlabel.h>
#include <measurementpanel.h>
#include <pqmdatalogger.h>
#include <scopy-pqm_export.h>
#include <gui/polarplotwidget.h>
#include <gui/widgets/menucontrolbutton.h>
#include <gui/widgets/toolbuttons.h>
#include <gui/widgets/measurementlabel.h>
#include <gui/docking/dockwrapperinterface.h>
#include <gui/docking/dockableareainterface.h>
#include <pluginbase/resourcemanager.h>
#include <pluginbase/toolmenuentry.h>

Expand All @@ -46,6 +48,7 @@ class SCOPY_PQM_EXPORT RmsInstrument : public QWidget, public ResourceUser
void pqEvent();
void enableTool(bool en, QString toolName = "rms");
void logData(PqmDataLogger::ActiveInstrument instr, const QString &filePath);

public Q_SLOTS:
void stop() override;
void toggleRms(bool en);
Expand All @@ -63,6 +66,10 @@ public Q_SLOTS:
QPushButton *createPQEventsBtn(QWidget *parent);
void browseFile(QLineEdit *lineEditPath);

DockableAreaInterface *m_dockableArea;
DockWrapperInterface *m_voltageDockWrapper;
DockWrapperInterface *m_currentDockWrapper;

QString m_uri;
ToolMenuEntry *m_tme;
bool m_running;
Expand Down
6 changes: 6 additions & 0 deletions plugins/pqm/include/pqm/waveforminstrument.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
#include <gui/tooltemplate.h>
#include <gui/widgets/menucontrolbutton.h>
#include <gui/widgets/toolbuttons.h>
#include <gui/docking/dockableareainterface.h>
#include <gui/docking/dockwrapperinterface.h>
#include <pluginbase/resourcemanager.h>
#include <pluginbase/toolmenuentry.h>

Expand Down Expand Up @@ -84,6 +86,10 @@ private Q_SLOTS:
gui::MenuSpinbox *m_timespanSpin;
MenuCombo *m_triggeredBy;

DockableAreaInterface *m_dockableArea;
DockWrapperInterface *m_voltageDockWrapper;
DockWrapperInterface *m_currentDockWrapper;

QMap<QString, PlotChannel *> m_plotChnls;
QVector<double> m_xTime;
PlottingStrategy *m_plottingStrategy = nullptr;
Expand Down
29 changes: 15 additions & 14 deletions plugins/pqm/src/rmsinstrument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
*/

#include "rmsinstrument.h"
#include "dockablearea.h"
#include "dockableareainterface.h"
#include "dockwrapper.h"
#include "measurementlabel.h"

#include <stylehelper.h>
Expand Down Expand Up @@ -52,6 +55,8 @@ RmsInstrument::RmsInstrument(ToolMenuEntry *tme, QString uri, QWidget *parent)
setLayout(instrumentLayout);
instrumentLayout->setMargin(0);

m_dockableArea = createDockableArea(this);

ToolTemplate *tool = new ToolTemplate(this);
tool->topContainer()->setVisible(true);
tool->centralContainer()->setVisible(true);
Expand All @@ -66,13 +71,11 @@ RmsInstrument::RmsInstrument(ToolMenuEntry *tme, QString uri, QWidget *parent)
QDesktopServices::openUrl(QUrl("https://analogdevicesinc.github.io/scopy/plugins/pqm/rms.html"));
});

QWidget *central = new QWidget(this);
QHBoxLayout *centralLayout = new QHBoxLayout();
central->setLayout(centralLayout);
centralLayout->setSpacing(8);
centralLayout->setContentsMargins(0, 0, 0, 0);
QWidget *dockableAreaWidget = dynamic_cast<QWidget *>(m_dockableArea);
tool->addWidgetToCentralContainerHelper(dockableAreaWidget);

QWidget *voltageWidget = new QWidget(central);
m_voltageDockWrapper = createDockWrapper("Voltage Plot");
QWidget *voltageWidget = new QWidget(dockableAreaWidget);
voltageWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
QVBoxLayout *voltageLayout = new QVBoxLayout();
voltageWidget->setLayout(voltageLayout);
Expand All @@ -90,8 +93,11 @@ RmsInstrument::RmsInstrument(ToolMenuEntry *tme, QString uri, QWidget *parent)
initPlot(m_voltagePlot);
setupPlotChannels(m_voltagePlot, m_chnls["voltage"]);
voltageLayout->addWidget(m_voltagePlot);
m_voltageDockWrapper->setInnerWidget(voltageWidget);
m_dockableArea->addDockWrapper(m_voltageDockWrapper, DockableAreaInterface::Direction_LEFT);

QWidget *currentWidget = new QWidget(central);
m_currentDockWrapper = createDockWrapper("Current Plot");
QWidget *currentWidget = new QWidget(dockableAreaWidget);
currentWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
QVBoxLayout *currentLayout = new QVBoxLayout();
currentWidget->setLayout(currentLayout);
Expand All @@ -108,13 +114,8 @@ RmsInstrument::RmsInstrument(ToolMenuEntry *tme, QString uri, QWidget *parent)
initPlot(m_currentPlot);
setupPlotChannels(m_currentPlot, m_chnls["current"]);
currentLayout->addWidget(m_currentPlot);

centralLayout->addWidget(voltageWidget);
centralLayout->setStretchFactor(voltageWidget, 1);
centralLayout->addWidget(currentWidget);
centralLayout->setStretchFactor(currentWidget, 1);

tool->addWidgetToCentralContainerHelper(central);
m_currentDockWrapper->setInnerWidget(currentWidget);
m_dockableArea->addDockWrapper(m_currentDockWrapper, DockableAreaInterface::Direction_RIGHT);

GearBtn *settingsBtn = new GearBtn(this);
settingsBtn->setChecked(true);
Expand Down
21 changes: 16 additions & 5 deletions plugins/pqm/src/waveforminstrument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
#include <gui/widgets/menucollapsesection.h>
#include <gui/widgets/menusectionwidget.h>
#include <gui/widgets/menuheader.h>
#include <gui/docking/dockablearea.h>
#include <gui/docking/dockwrapper.h>

using namespace scopy::pqm;

Expand All @@ -53,6 +55,8 @@ WaveformInstrument::WaveformInstrument(ToolMenuEntry *tme, QString uri, QWidget
setLayout(layout);
layout->setMargin(0);

m_dockableArea = createDockableArea(this);

m_plottingStrategy = PlottingStrategyBuilder::build("trigger", m_plotSampleRate);
ToolTemplate *tool = new ToolTemplate(this);
tool->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
Expand All @@ -69,15 +73,22 @@ WaveformInstrument::WaveformInstrument(ToolMenuEntry *tme, QString uri, QWidget
QDesktopServices::openUrl(QUrl("https://analogdevicesinc.github.io/scopy/plugins/pqm/waveform.html"));
});

m_voltagePlot = new PlotWidget(this);
QWidget *dockableAreaWidget = dynamic_cast<QWidget *>(m_dockableArea);
tool->addWidgetToCentralContainerHelper(dockableAreaWidget);

m_voltageDockWrapper = createDockWrapper("Voltage Plot");
m_voltagePlot = new PlotWidget(dockableAreaWidget);
initPlot(m_voltagePlot, "V", -400, 400);
setupChannels(m_voltagePlot, m_chnls["voltage"]);
tool->addWidgetToCentralContainerHelper(m_voltagePlot);
m_voltageDockWrapper->setInnerWidget(m_voltagePlot);
m_dockableArea->addDockWrapper(m_voltageDockWrapper);

m_currentPlot = new PlotWidget(this);
m_currentDockWrapper = createDockWrapper("Current Plot");
m_currentPlot = new PlotWidget(dockableAreaWidget);
initPlot(m_currentPlot, "A", -20, 20);
setupChannels(m_currentPlot, m_chnls["current"]);
tool->addWidgetToCentralContainerHelper(m_currentPlot);
m_currentDockWrapper->setInnerWidget(m_currentPlot);
m_dockableArea->addDockWrapper(m_currentDockWrapper);

PlotNavigator::syncPlotNavigators(m_voltagePlot->navigator(), m_currentPlot->navigator(),
new QSet<QwtAxisId>{m_voltagePlot->xAxis()->axisId()});
Expand Down Expand Up @@ -144,7 +155,7 @@ void WaveformInstrument::setupChannels(PlotWidget *plot, QMap<QString, QString>
int chnlIdx = 0;
for(const QString &chnlId : chnls) {
QPen chPen = QPen(QColor(StyleHelper::getChannelColor(chnlIdx)), 1);
PlotChannel *plotCh = new PlotChannel(chnls.key(chnlId), chPen, plot->xAxis(), plot->yAxis(), this);
PlotChannel *plotCh = new PlotChannel(chnls.key(chnlId), chPen, plot->xAxis(), plot->yAxis(), plot);
plot->addPlotChannel(plotCh);
plotCh->setEnabled(true);
m_plotChnls[chnlId] = plotCh;
Expand Down

0 comments on commit 0893e1d

Please sign in to comment.