From 69fe833715682a1d199f9c2a464ac791f2532e70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20K=C3=A4berich?= Date: Sun, 30 Jul 2023 13:09:47 +0200 Subject: [PATCH] Fix calibration progress dialog --- .../PC_Application/LibreVNA-GUI/VNA/vna.cpp | 30 +++++++++++-------- .../PC_Application/LibreVNA-GUI/VNA/vna.h | 2 +- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/Software/PC_Application/LibreVNA-GUI/VNA/vna.cpp b/Software/PC_Application/LibreVNA-GUI/VNA/vna.cpp index 5755b9c..9915599 100644 --- a/Software/PC_Application/LibreVNA-GUI/VNA/vna.cpp +++ b/Software/PC_Application/LibreVNA-GUI/VNA/vna.cpp @@ -66,10 +66,8 @@ VNA::VNA(AppWindow *window, QString name) singleSweep = false; calMeasuring = false; calWaitFirst = false; - calDialog.reset(); - // A modal QProgressDialog calls processEvents() in setValue(). Needs to use a queued connection to update the progress - // value from within the NewDatapoint slot to prevent possible re-entrancy. - connect(this, &VNA::calibrationMeasurementPercentage, &calDialog, &QProgressDialog::setValue, Qt::QueuedConnection); + calDialog = nullptr; + changingSettings = false; settings.sweepType = SweepType::Frequency; settings.zerospan = false; @@ -891,7 +889,7 @@ void VNA::NewDatapoint(DeviceDriver::VNAMeasurement m) if(m_avg.pointNum == settings.npoints - 1) { calMeasuring = false; cal.measurementsComplete(); - calDialog.reset(); + delete calDialog; } } } @@ -1249,18 +1247,24 @@ void VNA::StartCalibrationMeasurements(std::set m } else { text.append("multiple calibration standards."); } - calDialog.setLabelText(text); - calDialog.setCancelButtonText("Abort"); - calDialog.setWindowTitle("Taking calibration measurement..."); - calDialog.setValue(0); - calDialog.setWindowModality(Qt::ApplicationModal); + calDialog = new QProgressDialog(); + calDialog->setLabelText(text); + calDialog->setCancelButtonText("Abort"); + calDialog->setWindowTitle("Taking calibration measurement..."); + calDialog->setValue(0); + calDialog->setWindowModality(Qt::ApplicationModal); // always show the dialog - calDialog.setMinimumDuration(0); - connect(&calDialog, &QProgressDialog::canceled, [=]() { + calDialog->setMinimumDuration(0); + // A modal QProgressDialog calls processEvents() in setValue(). Needs to use a queued connection to update the progress + // value from within the NewDatapoint slot to prevent possible re-entrancy. + connect(this, &VNA::calibrationMeasurementPercentage, calDialog, &QProgressDialog::setValue, Qt::QueuedConnection); + + connect(calDialog, &QProgressDialog::canceled, this, [=]() { // the user aborted the calibration measurement calMeasuring = false; cal.clearMeasurements(calMeasurements); - }); + delete calDialog; + }, Qt::UniqueConnection); // Trigger sweep to start from beginning running = true; ConfigureDevice(true, [=](bool){ diff --git a/Software/PC_Application/LibreVNA-GUI/VNA/vna.h b/Software/PC_Application/LibreVNA-GUI/VNA/vna.h index a80f028..374e73c 100644 --- a/Software/PC_Application/LibreVNA-GUI/VNA/vna.h +++ b/Software/PC_Application/LibreVNA-GUI/VNA/vna.h @@ -150,7 +150,7 @@ private: std::set calMeasurements; bool calMeasuring; bool calWaitFirst; - QProgressDialog calDialog; + QProgressDialog *calDialog; Calibration::InterpolationType getCalInterpolation(); QString getCalStyle(); QString getCalToolTip();