Skip to content

Commit

Permalink
datamonitor: select menu style update
Browse files Browse the repository at this point in the history
Signed-off-by: Ionut Muthi <[email protected]>
  • Loading branch information
IonutMuthi committed Apr 25, 2024
1 parent 5e36fa7 commit 15d4471
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public Q_SLOTS:
bool m_isDeletable;
PositionSpinButton *m_ymin;
PositionSpinButton *m_ymax;
QPushButton *deleteMonitor;
QPushButton *deleteMonitor = nullptr;
QWidget *generateYAxisSettings(QWidget *parent);
QWidget *generateCurveStyleSettings(QWidget *parent);
QWidget *generatePlotUiSettings(QWidget *parent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,19 @@ class SCOPY_DATAMONITORPLUGIN_EXPORT MonitorPlot : public QWidget
void monitorCurveRemoved(PlotChannel *c);

private:
QVBoxLayout *layout;
QString dateTimeFormat;
PlotWidget *m_plot;
PlotBufferPreviewer *m_bufferPreviewer;
QwtDateScaleDraw *m_scaleDraw;
QMap<QString, MonitorPlotCurve *> *m_monitorCurves;
bool m_firstMonitor = true;

int m_currentCurveStyle = 0;
double m_currentCurveThickness = 1;
bool m_isRealTime = false;

void generateBufferPreviewer();
void setupXAxis();
void genereateScaleDraw(QString format, double offset);
QwtDateScaleEngine *scaleEngine;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class SCOPY_DATAMONITORPLUGIN_EXPORT MonitorPlotCurve : public QObject
Q_OBJECT
public:
explicit MonitorPlotCurve(DataMonitorModel *dataMonitorModel, PlotWidget *plot, QObject *parent = nullptr);
~MonitorPlotCurve();

void clearCurveData();
void refreshCurve();
Expand All @@ -24,6 +25,7 @@ class SCOPY_DATAMONITORPLUGIN_EXPORT MonitorPlotCurve : public QObject
double curveMaxVal();

private:
PlotWidget *m_plot;
PlotChannel *m_plotch;
PlotAxis *chPlotAxis;
DataMonitorModel *m_dataMonitorModel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <QButtonGroup>
#include <QWidget>
#include <menucollapsesection.h>
#include <semiexclusivebuttongroup.h>

namespace scopy {
namespace datamonitor {
Expand All @@ -20,8 +21,8 @@ class MonitorSelectionMenu : public QWidget
void addMonitor(DataMonitorModel *monitor);
void removeDevice(QString device);

QButtonGroup *monitorsGroup() const;
void setMonitorsGroup(QButtonGroup *newMonitorsGroup);
SemiExclusiveButtonGroup *monitorsGroup() const;
void setMonitorsGroup(SemiExclusiveButtonGroup *newMonitorsGroup);

Q_SIGNALS:
void monitorToggled(bool toggled, QString monitorName);
Expand All @@ -33,7 +34,7 @@ class MonitorSelectionMenu : public QWidget
QWidget *deviceChannelsWidget;
QWidget *importedChannelsWidget;
QVBoxLayout *layout;
QButtonGroup *m_monitorsGroup;
SemiExclusiveButtonGroup *m_monitorsGroup;
QMap<QString, MenuCollapseSection *> deviceMap;

void generateDeviceSection(QString device, bool import = false);
Expand Down
69 changes: 43 additions & 26 deletions plugins/datamonitorPlugin/src/datamonitor/monitorplot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <monitorplotcurve.hpp>
#include <plotinfo.h>
#include <timemanager.hpp>

#include <plotnavigator.hpp>
#include <pluginbase/preferences.h>

using namespace scopy;
Expand All @@ -17,7 +17,7 @@ using namespace datamonitor;
MonitorPlot::MonitorPlot(QWidget *parent)
: QWidget{parent}
{
QVBoxLayout *layout = new QVBoxLayout(this);
layout = new QVBoxLayout(this);
setLayout(layout);

Preferences *p = Preferences::GetInstance();
Expand All @@ -35,6 +35,8 @@ MonitorPlot::MonitorPlot(QWidget *parent)
m_plot->yAxis()->setInterval(DataMonitorUtils::getAxisDefaultMinValue(),
DataMonitorUtils::getAxisDefaultMaxValue());
m_plot->yAxis()->setVisible(true);
m_plot->setShowXAxisLabels(true);
m_plot->setShowYAxisLabels(true);

m_xAxisIntervalMin = DataMonitorUtils::getAxisDefaultMaxValue();
m_xAxisIntervalMax = DataMonitorUtils::getAxisDefaultMinValue();
Expand All @@ -50,13 +52,9 @@ MonitorPlot::MonitorPlot(QWidget *parent)
startTime->setAttribute(Qt::WA_TransparentForMouseEvents);

setStartTime();

setupXAxis();
generateBufferPreviewer();

AnalogBufferPreviewer *bufferPreviewer = new AnalogBufferPreviewer(this);
m_bufferPreviewer = new PlotBufferPreviewer(m_plot, bufferPreviewer, this);

layout->addWidget(m_bufferPreviewer);
layout->addWidget(m_plot);

m_monitorCurves = new QMap<QString, MonitorPlotCurve *>();
Expand Down Expand Up @@ -84,7 +82,6 @@ void MonitorPlot::removeMonitor(QString monitorName)
{
if(m_monitorCurves->contains(monitorName)) {
Q_EMIT monitorCurveRemoved(m_monitorCurves->value(monitorName)->plotch());
m_plot->removePlotChannel(m_monitorCurves->value(monitorName)->plotch());
m_monitorCurves->value(monitorName)->plotch()->curve()->detach();
m_monitorCurves->remove(monitorName);
delete m_monitorCurves->value(monitorName);
Expand Down Expand Up @@ -156,21 +153,22 @@ void MonitorPlot::setupXAxis()

void MonitorPlot::genereateScaleDraw(QString format, double offset)
{
QwtDateScaleDraw *scaleDraw = new QwtDateScaleDraw(Qt::OffsetFromUTC);
scaleDraw->enableComponent(QwtAbstractScaleDraw::Ticks, false);
scaleDraw->enableComponent(QwtAbstractScaleDraw::Backbone, false);
m_scaleDraw = new QwtDateScaleDraw(Qt::OffsetFromUTC);
m_scaleDraw->enableComponent(QwtAbstractScaleDraw::Ticks, false);
m_scaleDraw->enableComponent(QwtAbstractScaleDraw::Backbone, false);

// set time format for time interval types
scaleDraw->setDateFormat(QwtDate::IntervalType::Second, format);
scaleDraw->setDateFormat(QwtDate::IntervalType::Minute, format);
scaleDraw->setDateFormat(QwtDate::IntervalType::Hour, format);
scaleDraw->setDateFormat(QwtDate::IntervalType::Day, format);
scaleDraw->setDateFormat(QwtDate::IntervalType::Month, format);
scaleDraw->setDateFormat(QwtDate::IntervalType::Year, format);
scaleDraw->setUtcOffset(offset);
m_scaleDraw->setDateFormat(QwtDate::IntervalType::Millisecond, format);
m_scaleDraw->setDateFormat(QwtDate::IntervalType::Second, format);
m_scaleDraw->setDateFormat(QwtDate::IntervalType::Minute, format);
m_scaleDraw->setDateFormat(QwtDate::IntervalType::Hour, format);
m_scaleDraw->setDateFormat(QwtDate::IntervalType::Day, format);
m_scaleDraw->setDateFormat(QwtDate::IntervalType::Month, format);
m_scaleDraw->setDateFormat(QwtDate::IntervalType::Year, format);
m_scaleDraw->setUtcOffset(offset);

// apply scale draw to axis
m_plot->plot()->setAxisScaleDraw(m_plot->xAxis()->axisId(), scaleDraw);
m_plot->plot()->setAxisScaleDraw(m_plot->xAxis()->axisId(), m_scaleDraw);

// make label more readable
m_plot->plot()->setAxisLabelRotation(m_plot->xAxis()->axisId(), -50.0);
Expand All @@ -185,17 +183,17 @@ void MonitorPlot::setStartTime()
QString formattedTime = timeTracker->startTime().toString(dateTimeFormat);
QByteArray formattedTimeMsg = formattedTime.toLocal8Bit();
startTimeLabel->setText(QString("Start time: " + formattedTimeMsg));

genereateScaleDraw(dateTimeFormat, QDateTime::currentDateTime().offsetFromUtc());
updateAxisScaleDraw();
}

void MonitorPlot::updateAxisScaleDraw()
{
if(m_isRealTime) {
genereateScaleDraw(dateTimeFormat, QDateTime::currentDateTime().offsetFromUtc());
m_scaleDraw->setUtcOffset(QDateTime::currentDateTime().offsetFromUtc());
} else {
double offset = (-1) * m_startTime / 1000;
genereateScaleDraw(dateTimeFormat, offset);
m_scaleDraw->setUtcOffset(offset);
}

m_plot->replot();
Expand All @@ -205,23 +203,42 @@ void MonitorPlot::refreshXAxisInterval()
{
double time = QwtDate::toDouble(QDateTime::currentDateTime());
double delta = m_xAxisIntervalMin - m_xAxisIntervalMax;
if(m_plot->navigator()->isZoomed()) {
delta = std::abs(m_plot->xAxis()->visibleMax() - m_plot->xAxis()->visibleMin()) / 1000;
}
m_plot->xAxis()->setInterval(time - (delta * 1000), time);
m_plot->replot();
}

void MonitorPlot::updatePlotStartingPoint(double time, double delta)
{
if(m_plot->navigator()->isZoomed()) {
delta = std::abs(m_plot->xAxis()->visibleMax() - m_plot->xAxis()->visibleMin());
} else {
delta = delta * 1000;
}

if(m_isRealTime) {
m_plot->xAxis()->setInterval(time - (delta * 1000), time);
m_plot->xAxis()->setInterval(time - delta, time);
} else {
double offset = (-1) * m_startTime / 1000;
genereateScaleDraw(dateTimeFormat, offset);
m_scaleDraw->setUtcOffset(offset);

m_plot->xAxis()->setInterval(time - (delta * 1000), time);
m_plot->xAxis()->setInterval(time - delta, time);
}

m_bufferPreviewer->updateBufferPreviewer();
m_bufferPreviewer->updateDataLimits(m_startTime, time);
m_plot->replot();
}

void MonitorPlot::toggleBufferPreview(bool toggled) { m_bufferPreviewer->setVisible(toggled); }

void MonitorPlot::generateBufferPreviewer()
{

AnalogBufferPreviewer *bufferPreviewer = new AnalogBufferPreviewer(this);
m_bufferPreviewer = new PlotBufferPreviewer(m_plot, bufferPreviewer, this);

layout->addWidget(m_bufferPreviewer);
m_plot->navigator()->setResetOnNewBase(false);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ using namespace datamonitor;

MonitorPlotCurve::MonitorPlotCurve(DataMonitorModel *dataMonitorModel, PlotWidget *plot, QObject *parent)
: m_dataMonitorModel(dataMonitorModel)
, m_plot(plot)
{
QPen chpen = QPen(dataMonitorModel->getColor(), 1);

Expand All @@ -26,6 +27,8 @@ MonitorPlotCurve::MonitorPlotCurve(DataMonitorModel *dataMonitorModel, PlotWidge
});
}

MonitorPlotCurve::~MonitorPlotCurve() { m_plot->removePlotChannel(m_plotch); }

void MonitorPlotCurve::clearCurveData()
{
m_plotch->curve()->setRawSamples(m_dataMonitorModel->getXdata()->data(), m_dataMonitorModel->getYdata()->data(),
Expand Down
4 changes: 3 additions & 1 deletion plugins/datamonitorPlugin/src/datamonitorstylehelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ void DataMonitorStyleHelper::DataMonitorSettingsStyle(DataMonitorSettings *dataM

style.replace("&&backgroundColor&&", "transparent");

dataMonitorSettings->deleteMonitor->setStyleSheet(DataMonitorStyleHelper::RemoveButtonStyle());
if(dataMonitorSettings->deleteMonitor) {
dataMonitorSettings->deleteMonitor->setStyleSheet(DataMonitorStyleHelper::RemoveButtonStyle());
}
dataMonitorSettings->setStyleSheet(style);
}

Expand Down
12 changes: 8 additions & 4 deletions plugins/datamonitorPlugin/src/menus/monitorselectionmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ MonitorSelectionMenu::MonitorSelectionMenu(QMap<QString, DataMonitorModel *> *mo
importedChannelsWidgetLayout->setSpacing(10);
importedChannelsWidget->setLayout(importedChannelsWidgetLayout);

m_monitorsGroup = new QButtonGroup(this);
m_monitorsGroup = new SemiExclusiveButtonGroup(this);
m_monitorsGroup->setExclusive(true);

foreach(QString monitor, monitorList->keys()) {
Expand Down Expand Up @@ -110,7 +110,8 @@ void MonitorSelectionMenu::addMonitor(DataMonitorModel *monitor)
m_monitorsGroup->addButton(monitorChannel);

// apply hover to the buttons based on the color they have
monitorChannel->setStyleSheet(QString(":hover{ background-color: %1 ; }").arg(monitor->getColor().name()));
monitorChannel->setStyleSheet(monitorChannel->styleSheet() +
QString(":hover{ background-color: %1 ; }").arg(monitor->getColor().name()));

connect(monitorChannel, &MenuControlButton::clicked, this, [=, this]() {
if(!monitorChannel->checkBox()->isChecked()) {
Expand Down Expand Up @@ -138,6 +139,9 @@ void MonitorSelectionMenu::removeDevice(QString device)
}
}

QButtonGroup *MonitorSelectionMenu::monitorsGroup() const { return m_monitorsGroup; }
SemiExclusiveButtonGroup *MonitorSelectionMenu::monitorsGroup() const { return m_monitorsGroup; }

void MonitorSelectionMenu::setMonitorsGroup(QButtonGroup *newMonitorsGroup) { m_monitorsGroup = newMonitorsGroup; }
void MonitorSelectionMenu::setMonitorsGroup(SemiExclusiveButtonGroup *newMonitorsGroup)
{
m_monitorsGroup = newMonitorsGroup;
}

0 comments on commit 15d4471

Please sign in to comment.