Show traces in alphabetical order in plot context menus

This commit is contained in:
Jan Käberich 2022-07-10 12:41:41 +02:00
parent a6df8c8c8b
commit e36783bc9f
5 changed files with 29 additions and 15 deletions

View File

@ -122,6 +122,18 @@ std::vector<Trace *> TracePlot::activeTraces()
return ret;
}
std::vector<Trace *> TracePlot::orderedTraces()
{
std::vector<Trace*> 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());

View File

@ -50,6 +50,8 @@ protected:
// need to be called in derived class constructor
void initializeTraceInfo();
std::vector<Trace*> activeTraces();
// returns a list of all traces in alphabetical order
std::vector<Trace*> 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;

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}