Automatically adjust domain of graph to dropped trace
This commit is contained in:
parent
20b0b336bb
commit
f6cc46781e
@ -213,7 +213,7 @@ void TracePlot::dragEnterEvent(QDragEnterEvent *event)
|
|||||||
quintptr dropPtr;
|
quintptr dropPtr;
|
||||||
stream >> dropPtr;
|
stream >> dropPtr;
|
||||||
auto trace = (Trace*) dropPtr;
|
auto trace = (Trace*) dropPtr;
|
||||||
if(supported(trace)) {
|
if(dropSupported(trace)) {
|
||||||
event->acceptProposedAction();
|
event->acceptProposedAction();
|
||||||
dropPending = true;
|
dropPending = true;
|
||||||
dropTrace = trace;
|
dropTrace = trace;
|
||||||
|
@ -39,9 +39,9 @@ protected:
|
|||||||
void contextMenuEvent(QContextMenuEvent *event) override;
|
void contextMenuEvent(QContextMenuEvent *event) override;
|
||||||
void paintEvent(QPaintEvent *event) override;
|
void paintEvent(QPaintEvent *event) override;
|
||||||
virtual void updateContextMenu(){};
|
virtual void updateContextMenu(){};
|
||||||
virtual bool supported(Trace *t) = 0;
|
|
||||||
virtual void replot(){update();};
|
virtual void replot(){update();};
|
||||||
virtual void draw(QPainter& p) = 0;
|
virtual void draw(QPainter& p) = 0;
|
||||||
|
virtual bool supported(Trace *t) = 0;
|
||||||
std::map<Trace*, bool> traces;
|
std::map<Trace*, bool> traces;
|
||||||
QMenu *contextmenu;
|
QMenu *contextmenu;
|
||||||
QTime lastUpdate;
|
QTime lastUpdate;
|
||||||
@ -56,6 +56,7 @@ protected:
|
|||||||
void leaveEvent(QEvent *event) override;
|
void leaveEvent(QEvent *event) override;
|
||||||
|
|
||||||
// handle trace drops
|
// handle trace drops
|
||||||
|
virtual bool dropSupported(Trace *t) = 0;
|
||||||
void dragEnterEvent(QDragEnterEvent *event) override;
|
void dragEnterEvent(QDragEnterEvent *event) override;
|
||||||
void dropEvent(QDropEvent *event) override;
|
void dropEvent(QDropEvent *event) override;
|
||||||
void dragLeaveEvent(QDragLeaveEvent *event) override;
|
void dragLeaveEvent(QDragLeaveEvent *event) override;
|
||||||
|
@ -299,6 +299,11 @@ void TraceSmithChart::updateContextMenu()
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool TraceSmithChart::supported(Trace *t)
|
bool TraceSmithChart::supported(Trace *t)
|
||||||
|
{
|
||||||
|
return dropSupported(t);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool TraceSmithChart::dropSupported(Trace *t)
|
||||||
{
|
{
|
||||||
if(t->outputType() == Trace::DataType::Frequency && t->isReflection()) {
|
if(t->outputType() == Trace::DataType::Frequency && t->isReflection()) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -31,6 +31,7 @@ protected:
|
|||||||
//void paintEvent(QPaintEvent *event) override;
|
//void paintEvent(QPaintEvent *event) override;
|
||||||
virtual void updateContextMenu() override;
|
virtual void updateContextMenu() override;
|
||||||
bool supported(Trace *t) override;
|
bool supported(Trace *t) override;
|
||||||
|
bool dropSupported(Trace *t) override;
|
||||||
virtual void draw(QPainter& painter) override;
|
virtual void draw(QPainter& painter) override;
|
||||||
virtual void traceDropped(Trace *t, QPoint position) override;
|
virtual void traceDropped(Trace *t, QPoint position) override;
|
||||||
QString mouseText(QPoint pos) override;
|
QString mouseText(QPoint pos) override;
|
||||||
|
@ -36,6 +36,8 @@ void TraceWidget::on_add_clicked()
|
|||||||
auto t = new Trace("Trace #"+QString::number(createCount), Qt::darkYellow, defaultParameter());
|
auto t = new Trace("Trace #"+QString::number(createCount), Qt::darkYellow, defaultParameter());
|
||||||
t->setColor(QColor::fromHsl((createCount * 50) % 360, 250, 128));
|
t->setColor(QColor::fromHsl((createCount * 50) % 360, 250, 128));
|
||||||
model.addTrace(t);
|
model.addTrace(t);
|
||||||
|
ui->view->selectRow(model.getTraces().size() - 1);
|
||||||
|
on_edit_clicked();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TraceWidget::on_remove_clicked()
|
void TraceWidget::on_remove_clicked()
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
#include "Util/util.h"
|
#include "Util/util.h"
|
||||||
#include "unit.h"
|
#include "unit.h"
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include "CustomWidgets/informationbox.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
@ -218,7 +219,7 @@ bool TraceXYPlot::isTDRtype(TraceXYPlot::YAxisType type)
|
|||||||
void TraceXYPlot::axisSetupDialog()
|
void TraceXYPlot::axisSetupDialog()
|
||||||
{
|
{
|
||||||
auto setup = new XYplotAxisDialog(this);
|
auto setup = new XYplotAxisDialog(this);
|
||||||
setup->show();
|
setup->exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TraceXYPlot::updateContextMenu()
|
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)
|
bool TraceXYPlot::supported(Trace *t)
|
||||||
{
|
{
|
||||||
// potentially possible to add every kind of trace (depends on axis)
|
// 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)
|
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) {
|
if(axis == 0) {
|
||||||
TracePlot::enableTrace(t, enabled);
|
TracePlot::enableTrace(t, enabled);
|
||||||
}
|
}
|
||||||
@ -904,6 +916,23 @@ double TraceXYPlot::nearestTracePoint(Trace *t, QPoint pixel)
|
|||||||
|
|
||||||
void TraceXYPlot::traceDropped(Trace *t, QPoint position)
|
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) {
|
if(YAxis[0].type == YAxisType::Disabled && YAxis[1].type == YAxisType::Disabled) {
|
||||||
// no Y axis enabled, unable to drop
|
// no Y axis enabled, unable to drop
|
||||||
return;
|
return;
|
||||||
|
@ -55,7 +55,7 @@ public slots:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void updateContextMenu() override;
|
virtual void updateContextMenu() override;
|
||||||
virtual bool supported(Trace *t) override;
|
virtual bool dropSupported(Trace *t) override;
|
||||||
virtual void draw(QPainter &p) override;
|
virtual void draw(QPainter &p) override;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
@ -69,6 +69,7 @@ private:
|
|||||||
YAxisType YAxisTypeFromName(QString name);
|
YAxisType YAxisTypeFromName(QString name);
|
||||||
XAxisMode AxisModeFromName(QString name);
|
XAxisMode AxisModeFromName(QString name);
|
||||||
void enableTraceAxis(Trace *t, int axis, bool enabled);
|
void enableTraceAxis(Trace *t, int axis, bool enabled);
|
||||||
|
bool supported(Trace *t) override;
|
||||||
bool supported(Trace *t, YAxisType type);
|
bool supported(Trace *t, YAxisType type);
|
||||||
void removeUnsupportedTraces();
|
void removeUnsupportedTraces();
|
||||||
QPointF traceToCoordinate(Trace *t, unsigned int sample, YAxisType type);
|
QPointF traceToCoordinate(Trace *t, unsigned int sample, YAxisType type);
|
||||||
|
Loading…
Reference in New Issue
Block a user