diff --git a/Software/PC_Application/Traces/traceplot.cpp b/Software/PC_Application/Traces/traceplot.cpp index 0af871e..08dd6b8 100644 --- a/Software/PC_Application/Traces/traceplot.cpp +++ b/Software/PC_Application/Traces/traceplot.cpp @@ -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; diff --git a/Software/PC_Application/Traces/traceplot.h b/Software/PC_Application/Traces/traceplot.h index caa1d63..28790e5 100644 --- a/Software/PC_Application/Traces/traceplot.h +++ b/Software/PC_Application/Traces/traceplot.h @@ -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 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; diff --git a/Software/PC_Application/Traces/tracesmithchart.cpp b/Software/PC_Application/Traces/tracesmithchart.cpp index 53e9fce..1082660 100644 --- a/Software/PC_Application/Traces/tracesmithchart.cpp +++ b/Software/PC_Application/Traces/tracesmithchart.cpp @@ -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; diff --git a/Software/PC_Application/Traces/tracesmithchart.h b/Software/PC_Application/Traces/tracesmithchart.h index e2c01f9..4fecfab 100644 --- a/Software/PC_Application/Traces/tracesmithchart.h +++ b/Software/PC_Application/Traces/tracesmithchart.h @@ -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; diff --git a/Software/PC_Application/Traces/tracewidget.cpp b/Software/PC_Application/Traces/tracewidget.cpp index 8252fe2..f712a20 100644 --- a/Software/PC_Application/Traces/tracewidget.cpp +++ b/Software/PC_Application/Traces/tracewidget.cpp @@ -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() diff --git a/Software/PC_Application/Traces/tracexyplot.cpp b/Software/PC_Application/Traces/tracexyplot.cpp index bcfc445..9bc2da8 100644 --- a/Software/PC_Application/Traces/tracexyplot.cpp +++ b/Software/PC_Application/Traces/tracexyplot.cpp @@ -10,6 +10,7 @@ #include "Util/util.h" #include "unit.h" #include +#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; diff --git a/Software/PC_Application/Traces/tracexyplot.h b/Software/PC_Application/Traces/tracexyplot.h index 3336aa2..bee6e50 100644 --- a/Software/PC_Application/Traces/tracexyplot.h +++ b/Software/PC_Application/Traces/tracexyplot.h @@ -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);