diff --git a/Software/PC_Application/Generator/generator.cpp b/Software/PC_Application/Generator/generator.cpp index efecde8..6a52878 100644 --- a/Software/PC_Application/Generator/generator.cpp +++ b/Software/PC_Application/Generator/generator.cpp @@ -1,5 +1,4 @@ #include "generator.h" -#include "modehandler.h" #include @@ -56,7 +55,7 @@ void Generator::fromJSON(nlohmann::json j) void Generator::updateDevice() { - if(!window->getDevice() || window->getModeHandler()->getActiveMode() != this) { + if(!window->getDevice() || isActive != true) { // can't update if not connected return; } diff --git a/Software/PC_Application/SpectrumAnalyzer/spectrumanalyzer.cpp b/Software/PC_Application/SpectrumAnalyzer/spectrumanalyzer.cpp index cc2cf6d..12d8d94 100644 --- a/Software/PC_Application/SpectrumAnalyzer/spectrumanalyzer.cpp +++ b/Software/PC_Application/SpectrumAnalyzer/spectrumanalyzer.cpp @@ -17,7 +17,6 @@ #include "Device/firmwareupdatedialog.h" #include "preferences.h" #include "Generator/signalgenwidget.h" -#include "modehandler.h" #include #include @@ -434,7 +433,7 @@ using namespace std; void SpectrumAnalyzer::NewDatapoint(Protocol::SpectrumAnalyzerResult d) { - if(window->getModeHandler()->getActiveMode() != this) { + if(isActive != true) { return; } @@ -571,7 +570,7 @@ void SpectrumAnalyzer::SettingsChanged() } } - if(window->getDevice() && window->getModeHandler()->getActiveMode() == this) { + if(window->getDevice() && isActive) { window->getDevice()->Configure(settings, [=](Device::TransmissionResult res){ // device received command changingSettings = false; diff --git a/Software/PC_Application/VNA/vna.cpp b/Software/PC_Application/VNA/vna.cpp index b176d78..aa65a67 100644 --- a/Software/PC_Application/VNA/vna.cpp +++ b/Software/PC_Application/VNA/vna.cpp @@ -22,7 +22,6 @@ #include "Calibration/manualcalibrationdialog.h" #include "Util/util.h" #include "Tools/parameters.h" -#include "modehandler.h" #include #include @@ -802,7 +801,7 @@ using namespace std; void VNA::NewDatapoint(Protocol::Datapoint d) { - if(window->getModeHandler()->getActiveMode() != this) { + if(isActive != true) { // ignore return; } @@ -973,7 +972,7 @@ void VNA::SettingsChanged(bool resetTraces, std::functiongetDevice() && window->getModeHandler()->getActiveMode() == this) { + if(window->getDevice() && isActive) { if(s.excitePort1 == 0 && s.excitePort2 == 0) { // no signal at either port, just set the device to idle window->getDevice()->SetIdle(); @@ -1487,7 +1486,7 @@ void VNA::SetupSCPI() return ret; })); scpi_cal->add(new SCPICommand("MEASure", [=](QStringList params) -> QString { - if(params.size() != 1 || CalibrationMeasurementActive() || !window->getDevice() || window->getModeHandler()->getActiveMode() != this) { + if(params.size() != 1 || CalibrationMeasurementActive() || !window->getDevice() || isActive != true) { // no measurement specified, still busy or invalid mode return SCPI::getResultName(SCPI::Result::Error); } else { diff --git a/Software/PC_Application/mode.cpp b/Software/PC_Application/mode.cpp index b5eb493..ec31fb1 100644 --- a/Software/PC_Application/mode.cpp +++ b/Software/PC_Application/mode.cpp @@ -19,6 +19,7 @@ Mode::Mode(AppWindow *window, QString name, QString SCPIname) : QObject(window), SCPINode(SCPIname), window(window), + isActive(false), name(name), central(nullptr) { @@ -40,6 +41,7 @@ Mode::~Mode() void Mode::activate() { + isActive = true; qDebug() << "Activating mode" << name; // show all mode specific GUI elements for(auto t : toolbars) { @@ -86,6 +88,7 @@ void Mode::activate() void Mode::deactivate() { + isActive = false; QSettings settings; // save dock/toolbar visibility for(auto d : docks) { @@ -110,6 +113,7 @@ void Mode::deactivate() } qDebug() << "Deactivated mode" << name; + if(window->getDevice()) { window->getDevice()->SetIdle(); } diff --git a/Software/PC_Application/mode.h b/Software/PC_Application/mode.h index e554776..9742e87 100644 --- a/Software/PC_Application/mode.h +++ b/Software/PC_Application/mode.h @@ -47,6 +47,7 @@ protected: virtual void activate(); // derived classes must call Mode::activate before doing anything virtual void deactivate(); // derived classes must call Mode::deactivate before returning + bool isActive; void setStatusbarMessage(QString msg); // call once the derived class is fully initialized