diff --git a/Software/PC_Application/Traces/traceplot.cpp b/Software/PC_Application/Traces/traceplot.cpp index 1caf87f..b11c46c 100644 --- a/Software/PC_Application/Traces/traceplot.cpp +++ b/Software/PC_Application/Traces/traceplot.cpp @@ -122,6 +122,18 @@ std::vector TracePlot::activeTraces() return ret; } +std::vector TracePlot::orderedTraces() +{ + std::vector ordered; + for(auto t : traces) { + ordered.push_back(t.first); + } + sort(ordered.begin(), ordered.end(), [](Trace *l, Trace *r) -> bool { + return l->name() < r->name(); + }); + return ordered; +} + void TracePlot::contextMenuEvent(QContextMenuEvent *event) { auto m = markerAtPosition(event->pos()); diff --git a/Software/PC_Application/Traces/traceplot.h b/Software/PC_Application/Traces/traceplot.h index 4330a48..da4a3f5 100644 --- a/Software/PC_Application/Traces/traceplot.h +++ b/Software/PC_Application/Traces/traceplot.h @@ -50,6 +50,8 @@ protected: // need to be called in derived class constructor void initializeTraceInfo(); std::vector activeTraces(); + // returns a list of all traces in alphabetical order + std::vector orderedTraces(); // changes the graph settings to make it possible to display a specific trace. The trace is not aded yet virtual bool configureForTrace(Trace *t) { Q_UNUSED(t) return false; } // default implementation fails for all traces void contextMenuEvent(QContextMenuEvent *event) override; diff --git a/Software/PC_Application/Traces/tracesmithchart.cpp b/Software/PC_Application/Traces/tracesmithchart.cpp index 9f8cf4e..e690320 100644 --- a/Software/PC_Application/Traces/tracesmithchart.cpp +++ b/Software/PC_Application/Traces/tracesmithchart.cpp @@ -513,17 +513,17 @@ void TraceSmithChart::updateContextMenu() contextmenu->addSection("Traces"); // Populate context menu - for(auto t : traces) { - if(!supported(t.first)) { + for(auto t : orderedTraces()) { + if(!supported(t)) { continue; } - auto action = new QAction(t.first->name(), contextmenu); + auto action = new QAction(t->name(), contextmenu); action->setCheckable(true); - if(t.second) { + if(traces[t]) { action->setChecked(true); } connect(action, &QAction::toggled, [=](bool active) { - enableTrace(t.first, active); + enableTrace(t, active); }); contextmenu->addAction(action); } diff --git a/Software/PC_Application/Traces/tracewaterfall.cpp b/Software/PC_Application/Traces/tracewaterfall.cpp index fba3e73..64b59e1 100644 --- a/Software/PC_Application/Traces/tracewaterfall.cpp +++ b/Software/PC_Application/Traces/tracewaterfall.cpp @@ -196,17 +196,17 @@ void TraceWaterfall::updateContextMenu() contextmenu->addSection("Traces"); // Populate context menu - for(auto t : traces) { - if(!supported(t.first)) { + for(auto t : orderedTraces()) { + if(!supported(t)) { continue; } - auto action = new QAction(t.first->name(), contextmenu); + auto action = new QAction(t->name(), contextmenu); action->setCheckable(true); - if(t.second) { + if(traces[t]) { action->setChecked(true); } connect(action, &QAction::toggled, [=](bool active) { - enableTrace(t.first, active); + enableTrace(t, active); }); contextmenu->addAction(action); } diff --git a/Software/PC_Application/Traces/tracexyplot.cpp b/Software/PC_Application/Traces/tracexyplot.cpp index 4d0a58d..74433e3 100644 --- a/Software/PC_Application/Traces/tracexyplot.cpp +++ b/Software/PC_Application/Traces/tracexyplot.cpp @@ -304,19 +304,19 @@ void TraceXYPlot::updateContextMenu() } else { contextmenu->addSection("Secondary Traces"); } - for(auto t : traces) { + for(auto t : orderedTraces()) { // Skip traces that are not applicable for the selected axis type - if(!supported(t.first, yAxis[axis].getType())) { + if(!supported(t, yAxis[axis].getType())) { continue; } - auto action = new QAction(t.first->name(), contextmenu); + auto action = new QAction(t->name(), contextmenu); action->setCheckable(true); - if(tracesAxis[axis].find(t.first) != tracesAxis[axis].end()) { + if(tracesAxis[axis].find(t) != tracesAxis[axis].end()) { action->setChecked(true); } connect(action, &QAction::toggled, [=](bool active) { - enableTraceAxis(t.first, axis, active); + enableTraceAxis(t, axis, active); }); contextmenu->addAction(action); }