Automatically adjust domain of graph to dropped trace

This commit is contained in:
Jan Käberich 2021-02-22 13:39:47 +01:00
parent 20b0b336bb
commit f6cc46781e
7 changed files with 43 additions and 4 deletions

View File

@ -213,7 +213,7 @@ void TracePlot::dragEnterEvent(QDragEnterEvent *event)
quintptr dropPtr;
stream >> dropPtr;
auto trace = (Trace*) dropPtr;
if(supported(trace)) {
if(dropSupported(trace)) {
event->acceptProposedAction();
dropPending = true;
dropTrace = trace;

View File

@ -39,9 +39,9 @@ protected:
void contextMenuEvent(QContextMenuEvent *event) override;
void paintEvent(QPaintEvent *event) override;
virtual void updateContextMenu(){};
virtual bool supported(Trace *t) = 0;
virtual void replot(){update();};
virtual void draw(QPainter& p) = 0;
virtual bool supported(Trace *t) = 0;
std::map<Trace*, bool> traces;
QMenu *contextmenu;
QTime lastUpdate;
@ -56,6 +56,7 @@ protected:
void leaveEvent(QEvent *event) override;
// handle trace drops
virtual bool dropSupported(Trace *t) = 0;
void dragEnterEvent(QDragEnterEvent *event) override;
void dropEvent(QDropEvent *event) override;
void dragLeaveEvent(QDragLeaveEvent *event) override;

View File

@ -299,6 +299,11 @@ void TraceSmithChart::updateContextMenu()
}
bool TraceSmithChart::supported(Trace *t)
{
return dropSupported(t);
}
bool TraceSmithChart::dropSupported(Trace *t)
{
if(t->outputType() == Trace::DataType::Frequency && t->isReflection()) {
return true;

View File

@ -31,6 +31,7 @@ protected:
//void paintEvent(QPaintEvent *event) override;
virtual void updateContextMenu() override;
bool supported(Trace *t) override;
bool dropSupported(Trace *t) override;
virtual void draw(QPainter& painter) override;
virtual void traceDropped(Trace *t, QPoint position) override;
QString mouseText(QPoint pos) override;

View File

@ -36,6 +36,8 @@ void TraceWidget::on_add_clicked()
auto t = new Trace("Trace #"+QString::number(createCount), Qt::darkYellow, defaultParameter());
t->setColor(QColor::fromHsl((createCount * 50) % 360, 250, 128));
model.addTrace(t);
ui->view->selectRow(model.getTraces().size() - 1);
on_edit_clicked();
}
void TraceWidget::on_remove_clicked()

View File

@ -10,6 +10,7 @@
#include "Util/util.h"
#include "unit.h"
#include <QDebug>
#include "CustomWidgets/informationbox.h"
using namespace std;
@ -218,7 +219,7 @@ bool TraceXYPlot::isTDRtype(TraceXYPlot::YAxisType type)
void TraceXYPlot::axisSetupDialog()
{
auto setup = new XYplotAxisDialog(this);
setup->show();
setup->exec();
}
void TraceXYPlot::updateContextMenu()
@ -261,6 +262,13 @@ void TraceXYPlot::updateContextMenu()
});
}
bool TraceXYPlot::dropSupported(Trace *t)
{
Q_UNUSED(t)
// all kind of traces can be dropped, the graph will be reconfigured to support the dropped trace if required
return true;
}
bool TraceXYPlot::supported(Trace *t)
{
// potentially possible to add every kind of trace (depends on axis)
@ -735,6 +743,10 @@ QString TraceXYPlot::AxisTypeToName(TraceXYPlot::YAxisType type)
void TraceXYPlot::enableTraceAxis(Trace *t, int axis, bool enabled)
{
if(enabled && !supported(t, YAxis[axis].type)) {
// unable to add trace to the requested axis
return;
}
if(axis == 0) {
TracePlot::enableTrace(t, enabled);
}
@ -904,6 +916,23 @@ double TraceXYPlot::nearestTracePoint(Trace *t, QPoint pixel)
void TraceXYPlot::traceDropped(Trace *t, QPoint position)
{
if(t->outputType() == Trace::DataType::Frequency && XAxis.type != XAxisType::Frequency) {
// needs to switch to frequency domain graph
InformationBox::ShowMessage("X Axis Domain Change", "You dropped a frequency domain trace but the graph is still set up for the time domain."
" All current traces will be removed and the graph changed to frequency domain.");
setXAxis(XAxisType::Frequency, XAxisMode::FitTraces, 0, 1, 0.1);
setYAxis(0, YAxisType::Magnitude, false, true, 0, 1, 1.0);
setYAxis(1, YAxisType::Phase, false, true, 0, 1, 1.0);
}
if(t->outputType() != Trace::DataType::Frequency && XAxis.type == XAxisType::Frequency) {
// needs to switch to time domain graph
InformationBox::ShowMessage("X Axis Domain Change", "You dropped a time domain trace but the graph is still set up for the frequency domain."
" All current traces will be removed and the graph changed to time domain.");
setXAxis(XAxisType::Time, XAxisMode::FitTraces, 0, 1, 0.1);
setYAxis(0, YAxisType::ImpulseReal, false, true, 0, 1, 1.0);
setYAxis(1, YAxisType::Disabled, false, true, 0, 1, 1.0);
}
if(YAxis[0].type == YAxisType::Disabled && YAxis[1].type == YAxisType::Disabled) {
// no Y axis enabled, unable to drop
return;

View File

@ -55,7 +55,7 @@ public slots:
protected:
virtual void updateContextMenu() override;
virtual bool supported(Trace *t) override;
virtual bool dropSupported(Trace *t) override;
virtual void draw(QPainter &p) override;
private slots:
@ -69,6 +69,7 @@ private:
YAxisType YAxisTypeFromName(QString name);
XAxisMode AxisModeFromName(QString name);
void enableTraceAxis(Trace *t, int axis, bool enabled);
bool supported(Trace *t) override;
bool supported(Trace *t, YAxisType type);
void removeUnsupportedTraces();
QPointF traceToCoordinate(Trace *t, unsigned int sample, YAxisType type);