diff --git a/Software/PC_Application/Traces/tracemarker.cpp b/Software/PC_Application/Traces/tracemarker.cpp index bc9a5d3..8cde9f6 100644 --- a/Software/PC_Application/Traces/tracemarker.cpp +++ b/Software/PC_Application/Traces/tracemarker.cpp @@ -475,68 +475,67 @@ void TraceMarker::deltaDeleted() void TraceMarker::updateContextmenu() { if(parent) { - parent->updateContextmenu(); - contextmenu = parent->contextmenu; - } else { - if(contextmenu) { - // check if the contextmenu or one of its submenus is currently open - auto *activeWidget = QApplication::activePopupWidget(); - while (activeWidget) { - if(activeWidget == contextmenu) { - // contextmenu currently open, do not update - return; - } - activeWidget = activeWidget->parentWidget(); - } - delete contextmenu; - } - contextmenu = new QMenu(); - auto typemenu = contextmenu->addMenu("Type"); - auto typegroup = new QActionGroup(contextmenu); - for(auto t : getSupportedTypes()) { - auto setTypeAction = new QAction(typeToString(t)); - setTypeAction->setCheckable(true); - if(t == type) { - setTypeAction->setChecked(true); - } - connect(setTypeAction, &QAction::triggered, [=](){ - setType(t); - }); - typegroup->addAction(setTypeAction); - typemenu->addAction(setTypeAction); + // do nothing, using contextmenu from parent anyway + return; + } + // check if the contextmenu or one of its submenus is currently open + auto *activeWidget = QApplication::activePopupWidget(); + while (activeWidget) { + if(activeWidget == &contextmenu) { + // contextmenu currently open, do not update + qDebug() << "Contextmenu open, skipping update"; + return; } + activeWidget = activeWidget->parentWidget(); + } - auto table = contextmenu->addMenu("Data Format in Table"); - auto tablegroup = new QActionGroup(contextmenu); - for(auto f : applicableFormats()) { - auto setFormatAction = new QAction(formatToString(f)); - setFormatAction->setCheckable(true); - if(f == formatTable) { - setFormatAction->setChecked(true); - } - connect(setFormatAction, &QAction::triggered, [=](){ - setTableFormat(f); - }); - tablegroup->addAction(setFormatAction); - table->addAction(setFormatAction); - } + contextmenu.clear(); - auto graph = contextmenu->addMenu("Show on Graph"); - for(auto f : applicableFormats()) { - auto setFormatAction = new QAction(formatToString(f)); - setFormatAction->setCheckable(true); - if(formatGraph.count(f)) { - setFormatAction->setChecked(true); - } - connect(setFormatAction, &QAction::triggered, [=](bool checked){ - if(checked) { - formatGraph.insert(f); - } else { - formatGraph.erase(f); - } - }); - graph->addAction(setFormatAction); + auto typemenu = contextmenu.addMenu("Type"); + auto typegroup = new QActionGroup(&contextmenu); + for(auto t : getSupportedTypes()) { + auto setTypeAction = new QAction(typeToString(t)); + setTypeAction->setCheckable(true); + if(t == type) { + setTypeAction->setChecked(true); } + connect(setTypeAction, &QAction::triggered, [=](){ + setType(t); + }); + typegroup->addAction(setTypeAction); + typemenu->addAction(setTypeAction); + } + + auto table = contextmenu.addMenu("Data Format in Table"); + auto tablegroup = new QActionGroup(&contextmenu); + for(auto f : applicableFormats()) { + auto setFormatAction = new QAction(formatToString(f)); + setFormatAction->setCheckable(true); + if(f == formatTable) { + setFormatAction->setChecked(true); + } + connect(setFormatAction, &QAction::triggered, [=](){ + setTableFormat(f); + }); + tablegroup->addAction(setFormatAction); + table->addAction(setFormatAction); + } + + auto graph = contextmenu.addMenu("Show on Graph"); + for(auto f : applicableFormats()) { + auto setFormatAction = new QAction(formatToString(f)); + setFormatAction->setCheckable(true); + if(formatGraph.count(f)) { + setFormatAction->setChecked(true); + } + connect(setFormatAction, &QAction::triggered, [=](bool checked){ + if(checked) { + formatGraph.insert(f); + } else { + formatGraph.erase(f); + } + }); + graph->addAction(setFormatAction); } } @@ -749,7 +748,6 @@ void TraceMarker::setTableFormat(TraceMarker::Format f) } formatTable = f; - updateContextmenu(); emit dataChanged(this); } @@ -1050,6 +1048,14 @@ void TraceMarker::adjustSettings(double value) update(); } +QMenu *TraceMarker::getContextMenu() { + if(parent) { + return parent->getContextMenu(); + } else { + return &contextmenu; + } +} + void TraceMarker::update() { if(!parentTrace->size()) { diff --git a/Software/PC_Application/Traces/tracemarker.h b/Software/PC_Application/Traces/tracemarker.h index a6fd670..34f6f1d 100644 --- a/Software/PC_Application/Traces/tracemarker.h +++ b/Software/PC_Application/Traces/tracemarker.h @@ -4,6 +4,7 @@ #include #include #include "trace.h" +#include #include #include "CustomWidgets/siunitedit.h" #include "savable.h" @@ -82,7 +83,7 @@ public: SIUnitEdit* getSettingsEditor(); void adjustSettings(double value); - QMenu *getContextMenu() { return contextmenu;} + QMenu *getContextMenu(); // Updates marker position and data on automatic markers. Should be called whenever the tracedata is complete void update(); @@ -163,7 +164,7 @@ private: QString suffix; QString description; - QMenu *contextmenu; + QMenu contextmenu; TraceMarker *delta; std::vector helperMarkers;