Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion plugins/oscilloscope/oscilloscope.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ void Oscilloscope::Panel::updateChannelPen(IO::endpoint endpoint)
this->scopeWindow->setChannelPen(endpoint, pen);
}

void Oscilloscope::Panel::updateChannelCurveStyle(IO::endpoint endpoint)
{
auto curveStyle = this->curveStylesList->currentData().value<QwtPlotCurve::CurveStyle>();
this->scopeWindow->setChannelCurveStyle(endpoint, curveStyle);
}

void Oscilloscope::Panel::updateChannelLabel(IO::endpoint probe_info)
{
const QString chanlabel = QString::number(probe_info.block->getID()) + " "
Expand Down Expand Up @@ -135,6 +141,7 @@ void Oscilloscope::Panel::enableChannel()
this->updateChannelOffset(endpoint);
this->updateChannelScale(endpoint);
this->updateChannelPen(endpoint);
this->updateChannelCurveStyle(endpoint);
}

void Oscilloscope::Panel::disableChannel()
Expand Down Expand Up @@ -166,6 +173,7 @@ void Oscilloscope::Panel::activateChannel(bool active)
colorsList->setEnabled(enable);
widthsList->setEnabled(enable);
stylesList->setEnabled(enable);
curveStylesList->setEnabled(enable);
this->activateButton->setChecked(enable);
}

Expand Down Expand Up @@ -254,6 +262,7 @@ void Oscilloscope::Panel::applyChannelTab()
this->updateChannelScale(probeInfo);
this->updateChannelOffset(probeInfo);
this->updateChannelPen(probeInfo);
this->updateChannelCurveStyle(probeInfo);
this->updateChannelLabel(probeInfo);
}
scopeWindow->replot();
Expand Down Expand Up @@ -431,7 +440,7 @@ QWidget* Oscilloscope::Panel::createChannelTab(QWidget* parent)
}

// Create styles list
auto* styleLabel = new QLabel(tr("Style:"), page);
auto* styleLabel = new QLabel(tr("Line Style:"), page);
row2Layout->addWidget(styleLabel);
stylesList = new QComboBox(page);
stylesList->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
Expand All @@ -451,6 +460,25 @@ QWidget* Oscilloscope::Panel::createChannelTab(QWidget* parent)
QVariant::fromValue(Oscilloscope::penStyles.at(i)));
}

// Create curve styles list
auto* curveStyleLabel = new QLabel(tr("Curve Style:"), page);
row2Layout->addWidget(curveStyleLabel);
curveStylesList = new QComboBox(page);
curveStylesList->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
curveStylesList->setSizeAdjustPolicy(QComboBox::AdjustToContents);
row2Layout->addWidget(curveStylesList);
for (size_t i = 0; i < Oscilloscope::curveStyles.size(); i++) {
temp_name = Oscilloscope::curvestyles2string.at(i);
tmp.fill(Qt::white);
painter.setPen(
QPen(Oscilloscope::penColors.at(Oscilloscope::ColorID::Black),
3));
(i == 0) ? painter.drawLine(0, 12, 25, 12) : painter.drawPoint(12, 12);
curveStylesList->addItem(tmp,
QString(temp_name.c_str()),
QVariant::fromValue(Oscilloscope::curveStyles.at(i)));
}

// Activate button
row2Layout->addSpacerItem(
new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum));
Expand Down Expand Up @@ -910,6 +938,8 @@ void Oscilloscope::Panel::syncChannelProperties()
widthsList->setCurrentIndex(widthsList->findData(width));
const Qt::PenStyle style = scopeWindow->getChannelStyle(probe_info);
stylesList->setCurrentIndex(stylesList->findData(QVariant::fromValue(style)));
const QwtPlotCurve::CurveStyle curveStyle = scopeWindow->getChannelCurveStyle(probe_info);
curveStylesList->setCurrentIndex(curveStylesList->findData(QVariant::fromValue(curveStyle)));
double offset = scopeWindow->getChannelOffset(probe_info);
const double scale = scopeWindow->getChannelScale(probe_info);
scalesList->setCurrentIndex(
Expand Down
2 changes: 2 additions & 0 deletions plugins/oscilloscope/oscilloscope.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ private slots:
void updateChannelScale(IO::endpoint probe_info);
void updateChannelOffset(IO::endpoint probe_info);
void updateChannelPen(IO::endpoint endpoint);
void updateChannelCurveStyle(IO::endpoint endpoint);
void updateWindowTimeDiv();

// Tab Widget
Expand Down Expand Up @@ -170,6 +171,7 @@ private slots:
QComboBox* offsetsList = nullptr;
QComboBox* scalesList = nullptr;
QComboBox* stylesList = nullptr;
QComboBox* curveStylesList = nullptr;
QComboBox* widthsList = nullptr;
QLineEdit* offsetsEdit = nullptr;

Expand Down
26 changes: 26 additions & 0 deletions plugins/oscilloscope/scope.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ void Oscilloscope::Scope::createChannel(IO::endpoint probeInfo,
pen.setStyle(Oscilloscope::penStyles[0]);
chan.fifo = fifo;
chan.curve->setPen(pen);
chan.curve->setStyle(Oscilloscope::curveStyles[0]);
chan.curve->attach(this);
this->channels.push_back(chan);
}
Expand Down Expand Up @@ -420,6 +421,19 @@ Qt::PenStyle Oscilloscope::Scope::getChannelStyle(IO::endpoint endpoint)
return chan_loc->curve->pen().style();
}

QwtPlotCurve::CurveStyle Oscilloscope::Scope::getChannelCurveStyle(IO::endpoint endpoint)
{
const std::shared_lock<std::shared_mutex> lock(this->m_channel_mutex);
auto chan_loc = std::find_if(this->channels.begin(),
this->channels.end(),
[&](const Oscilloscope::scope_channel& chann)
{ return chann.endpoint == endpoint; });
if (chan_loc == channels.end()) {
return curveStyles[Oscilloscope::CurveStyleID::Line];
}
return chan_loc->curve->style();
}

int Oscilloscope::Scope::getChannelWidth(IO::endpoint endpoint)
{
const std::shared_lock<std::shared_mutex> lock(this->m_channel_mutex);
Expand All @@ -445,6 +459,18 @@ void Oscilloscope::Scope::setChannelPen(IO::endpoint endpoint, const QPen& pen)
}
}

void Oscilloscope::Scope::setChannelCurveStyle(IO::endpoint endpoint, const QwtPlotCurve::CurveStyle& curveStyle)
{
const std::shared_lock<std::shared_mutex> lock(this->m_channel_mutex);
auto chan_loc = std::find_if(this->channels.begin(),
this->channels.end(),
[&](const Oscilloscope::scope_channel& chann)
{ return chann.endpoint == endpoint; });
if (chan_loc != channels.end()) {
chan_loc->curve->setStyle(curveStyle);
}
}

void Oscilloscope::Scope::setTriggerThreshold(double threshold)
{
this->m_trigger_info.threshold = threshold;
Expand Down
19 changes: 19 additions & 0 deletions plugins/oscilloscope/scope.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include <shared_mutex>
#include <vector>

#include <qwt_plot_curve.h>
#include <qwt_plot_canvas.h>
#include <qwt_plot_legenditem.h>
#include <qwt_plot.h>
Expand Down Expand Up @@ -143,6 +144,21 @@ enum penstyle_id : size_t
};
} // namespace PenStyleID

constexpr std::array<QwtPlotCurve::CurveStyle, 2> curveStyles = {QwtPlotCurve::Lines, QwtPlotCurve::Dots};

constexpr std::array<std::string_view, 2> curvestyles2string {
"Lines", "Dots"};

namespace CurveStyleID
{
enum curvestyle_id : size_t
{
Line = 0,
Dot,
};
} // namespace CurveStyleID


class LegendItem : public QwtPlotLegendItem
{
public:
Expand Down Expand Up @@ -198,7 +214,9 @@ class Scope : public QwtPlot
void setChannelLabel(IO::endpoint endpoint, const QString& label);
QColor getChannelColor(IO::endpoint endpoint);
Qt::PenStyle getChannelStyle(IO::endpoint endpoint);
QwtPlotCurve::CurveStyle getChannelCurveStyle(IO::endpoint endpoint);
void setChannelPen(IO::endpoint endpoint, const QPen& pen);
void setChannelCurveStyle(IO::endpoint endpoint, const QwtPlotCurve::CurveStyle& curveStyle);
int getChannelWidth(IO::endpoint endpoint);
double getTriggerThreshold() const;
void setTriggerThreshold(double threshold);
Expand Down Expand Up @@ -252,4 +270,5 @@ public slots:

} // namespace Oscilloscope

Q_DECLARE_METATYPE(QwtPlotCurve::CurveStyle)
#endif // SCOPE_H