Ask to save calibration when closing the app
This commit is contained in:
parent
15c7492bec
commit
753dd3d261
@ -20,6 +20,32 @@ void InformationBox::ShowMessage(QString title, QString message, QString message
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool InformationBox::AskQuestion(QString title, QString question, bool defaultAnswer, QString messageID)
|
||||||
|
{
|
||||||
|
// check if the user still wants to see this message
|
||||||
|
unsigned int hash;
|
||||||
|
if(messageID.isEmpty()) {
|
||||||
|
hash = qHash(question);
|
||||||
|
} else {
|
||||||
|
hash = qHash(messageID);
|
||||||
|
}
|
||||||
|
|
||||||
|
QSettings s;
|
||||||
|
if(!s.contains(hashToSettingsKey(hash))) {
|
||||||
|
auto box = new InformationBox(title, question, hash, nullptr);
|
||||||
|
box->setStandardButtons(QMessageBox::Yes | QMessageBox::No);
|
||||||
|
int ret = box->exec();
|
||||||
|
if(ret == QMessageBox::Yes) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// don't show this question anymore
|
||||||
|
return defaultAnswer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
InformationBox::InformationBox(QString title, QString message, unsigned int hash, QWidget *parent)
|
InformationBox::InformationBox(QString title, QString message, unsigned int hash, QWidget *parent)
|
||||||
: QMessageBox(parent),
|
: QMessageBox(parent),
|
||||||
hash(hash)
|
hash(hash)
|
||||||
|
@ -8,6 +8,8 @@ class InformationBox : public QMessageBox
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
static void ShowMessage(QString title, QString message, QString messageID = QString());
|
static void ShowMessage(QString title, QString message, QString messageID = QString());
|
||||||
|
// Display a dialog with yes/no buttons. Returns true if yes is clicked, false otherwise. If the user has selected to never see this message again, defaultAnswer is returned instead
|
||||||
|
static bool AskQuestion(QString title, QString question, bool defaultAnswer, QString messageID = QString());
|
||||||
private:
|
private:
|
||||||
InformationBox(QString title, QString message, unsigned int hash, QWidget *parent);
|
InformationBox(QString title, QString message, unsigned int hash, QWidget *parent);
|
||||||
~InformationBox();
|
~InformationBox();
|
||||||
|
@ -153,9 +153,9 @@ void TraceXYPlot::fromJSON(nlohmann::json j)
|
|||||||
auto xtype = jX.value("type", XAxisType::Frequency);
|
auto xtype = jX.value("type", XAxisType::Frequency);
|
||||||
auto xmode = jX.value("mode", XAxisMode::UseSpan);
|
auto xmode = jX.value("mode", XAxisMode::UseSpan);
|
||||||
// auto xlog = jX.value("log", false);
|
// auto xlog = jX.value("log", false);
|
||||||
auto xmin = jX.value("min", 0);
|
auto xmin = jX.value("min", 0.0);
|
||||||
auto xmax = jX.value("max", 6000000000);
|
auto xmax = jX.value("max", 6000000000.0);
|
||||||
auto xdiv = jX.value("div", 600000000);
|
auto xdiv = jX.value("div", 600000000.0);
|
||||||
setXAxis(xtype, xmode, xmin, xmax, xdiv);
|
setXAxis(xtype, xmode, xmin, xmax, xdiv);
|
||||||
nlohmann::json jY[2] = {j["YPrimary"], j["YSecondary"]};
|
nlohmann::json jY[2] = {j["YPrimary"], j["YSecondary"]};
|
||||||
for(unsigned int i=0;i<2;i++) {
|
for(unsigned int i=0;i<2;i++) {
|
||||||
|
@ -53,6 +53,7 @@ VNA::VNA(AppWindow *window)
|
|||||||
calValid = false;
|
calValid = false;
|
||||||
calMeasuring = false;
|
calMeasuring = false;
|
||||||
calDialog.reset();
|
calDialog.reset();
|
||||||
|
calEdited = false;
|
||||||
|
|
||||||
// Create default traces
|
// Create default traces
|
||||||
auto tS11 = new Trace("S11", Qt::yellow);
|
auto tS11 = new Trace("S11", Qt::yellow);
|
||||||
@ -104,10 +105,13 @@ VNA::VNA(AppWindow *window)
|
|||||||
} else {
|
} else {
|
||||||
ApplyCalibration(cal.getType());
|
ApplyCalibration(cal.getType());
|
||||||
}
|
}
|
||||||
|
calEdited = false;
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(saveCal, &QAction::triggered, [=](){
|
connect(saveCal, &QAction::triggered, [=](){
|
||||||
cal.saveToFile();
|
if(cal.saveToFile()) {
|
||||||
|
calEdited = false;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
auto calDisable = calMenu->addAction("Disabled");
|
auto calDisable = calMenu->addAction("Disabled");
|
||||||
@ -508,6 +512,16 @@ void VNA::deviceDisconnected()
|
|||||||
defaultCalMenu->setEnabled(false);
|
defaultCalMenu->setEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void VNA::shutdown()
|
||||||
|
{
|
||||||
|
if(calEdited && calValid) {
|
||||||
|
auto save = InformationBox::AskQuestion("Save calibration?", "The calibration contains data that has not been saved yet. Do you want to save it before exiting?", false);
|
||||||
|
if(save) {
|
||||||
|
cal.saveToFile();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
nlohmann::json VNA::toJSON()
|
nlohmann::json VNA::toJSON()
|
||||||
{
|
{
|
||||||
nlohmann::json j;
|
nlohmann::json j;
|
||||||
@ -798,6 +812,7 @@ void VNA::StartCalibrationMeasurement(Calibration::Measurement m)
|
|||||||
// enable calibration measurement only in transmission callback (prevents accidental sampling of data which was still being processed)
|
// enable calibration measurement only in transmission callback (prevents accidental sampling of data which was still being processed)
|
||||||
calMeasuring = true;
|
calMeasuring = true;
|
||||||
});
|
});
|
||||||
|
calEdited = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void VNA::ConstrainAndUpdateFrequencies()
|
void VNA::ConstrainAndUpdateFrequencies()
|
||||||
|
@ -19,6 +19,7 @@ public:
|
|||||||
void deactivate() override;
|
void deactivate() override;
|
||||||
void initializeDevice() override;
|
void initializeDevice() override;
|
||||||
void deviceDisconnected() override;
|
void deviceDisconnected() override;
|
||||||
|
void shutdown() override;
|
||||||
|
|
||||||
// Only save/load user changeable stuff, no need to save the widgets/mode name etc.
|
// Only save/load user changeable stuff, no need to save the widgets/mode name etc.
|
||||||
virtual nlohmann::json toJSON() override;
|
virtual nlohmann::json toJSON() override;
|
||||||
@ -67,6 +68,7 @@ private:
|
|||||||
// Calibration
|
// Calibration
|
||||||
Calibration cal;
|
Calibration cal;
|
||||||
bool calValid;
|
bool calValid;
|
||||||
|
bool calEdited;
|
||||||
Calibration::Measurement calMeasurement;
|
Calibration::Measurement calMeasurement;
|
||||||
bool calMeasuring;
|
bool calMeasuring;
|
||||||
bool calWaitFirst;
|
bool calWaitFirst;
|
||||||
|
@ -184,6 +184,9 @@ AppWindow::~AppWindow()
|
|||||||
|
|
||||||
void AppWindow::closeEvent(QCloseEvent *event)
|
void AppWindow::closeEvent(QCloseEvent *event)
|
||||||
{
|
{
|
||||||
|
vna->shutdown();
|
||||||
|
generator->shutdown();
|
||||||
|
spectrumAnalyzer->shutdown();
|
||||||
delete device;
|
delete device;
|
||||||
QSettings settings;
|
QSettings settings;
|
||||||
settings.setValue("geometry", saveGeometry());
|
settings.setValue("geometry", saveGeometry());
|
||||||
|
@ -17,6 +17,7 @@ public:
|
|||||||
|
|
||||||
virtual void activate(); // derived classes must call Mode::activate before doing anything
|
virtual void activate(); // derived classes must call Mode::activate before doing anything
|
||||||
virtual void deactivate(); // derived classes must call Mode::deactivate before returning
|
virtual void deactivate(); // derived classes must call Mode::deactivate before returning
|
||||||
|
virtual void shutdown(){}; // called when the application is about to exit
|
||||||
QString getName() const;
|
QString getName() const;
|
||||||
static Mode *getActiveMode();
|
static Mode *getActiveMode();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user