Catch exception when importing files and display error message
This commit is contained in:
parent
2fac430381
commit
3d4d3c9468
@ -15,11 +15,17 @@ void InformationBox::ShowMessage(QString title, QString message, QString message
|
|||||||
|
|
||||||
QSettings s;
|
QSettings s;
|
||||||
if(!s.contains(hashToSettingsKey(hash))) {
|
if(!s.contains(hashToSettingsKey(hash))) {
|
||||||
auto box = new InformationBox(title, message, hash, nullptr);
|
auto box = new InformationBox(title, message, QMessageBox::Information, hash, nullptr);
|
||||||
box->show();
|
box->show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void InformationBox::ShowError(QString title, QString message)
|
||||||
|
{
|
||||||
|
auto box = new InformationBox(title, message, QMessageBox::Information, 0, nullptr);
|
||||||
|
box->show();
|
||||||
|
}
|
||||||
|
|
||||||
bool InformationBox::AskQuestion(QString title, QString question, bool defaultAnswer, QString messageID)
|
bool InformationBox::AskQuestion(QString title, QString question, bool defaultAnswer, QString messageID)
|
||||||
{
|
{
|
||||||
// check if the user still wants to see this message
|
// check if the user still wants to see this message
|
||||||
@ -32,7 +38,7 @@ bool InformationBox::AskQuestion(QString title, QString question, bool defaultAn
|
|||||||
|
|
||||||
QSettings s;
|
QSettings s;
|
||||||
if(!s.contains(hashToSettingsKey(hash))) {
|
if(!s.contains(hashToSettingsKey(hash))) {
|
||||||
auto box = new InformationBox(title, question, hash, nullptr);
|
auto box = new InformationBox(title, question, QMessageBox::Question, hash, nullptr);
|
||||||
box->setStandardButtons(QMessageBox::Yes | QMessageBox::No);
|
box->setStandardButtons(QMessageBox::Yes | QMessageBox::No);
|
||||||
int ret = box->exec();
|
int ret = box->exec();
|
||||||
if(ret == QMessageBox::Yes) {
|
if(ret == QMessageBox::Yes) {
|
||||||
@ -46,17 +52,21 @@ bool InformationBox::AskQuestion(QString title, QString question, bool defaultAn
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
InformationBox::InformationBox(QString title, QString message, unsigned int hash, QWidget *parent)
|
InformationBox::InformationBox(QString title, QString message, Icon icon, unsigned int hash, QWidget *parent)
|
||||||
: QMessageBox(parent),
|
: QMessageBox(parent),
|
||||||
hash(hash)
|
hash(hash)
|
||||||
{
|
{
|
||||||
setWindowTitle(title);
|
setWindowTitle(title);
|
||||||
setText(message);
|
setText(message);
|
||||||
setAttribute(Qt::WA_DeleteOnClose, true);
|
setAttribute(Qt::WA_DeleteOnClose, true);
|
||||||
setIcon(QMessageBox::Information);
|
setIcon(icon);
|
||||||
|
|
||||||
auto cb = new QCheckBox("Do not show this message again");
|
auto cb = new QCheckBox("Do not show this message again");
|
||||||
setCheckBox(cb);
|
setCheckBox(cb);
|
||||||
|
|
||||||
|
if(hash == 0) {
|
||||||
|
cb->setVisible(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
InformationBox::~InformationBox()
|
InformationBox::~InformationBox()
|
||||||
|
@ -8,10 +8,11 @@ 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());
|
||||||
|
static void ShowError(QString title, QString message);
|
||||||
// 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
|
// 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());
|
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, QMessageBox::Icon icon, unsigned int hash, QWidget *parent);
|
||||||
~InformationBox();
|
~InformationBox();
|
||||||
static QString hashToSettingsKey(unsigned int hash);
|
static QString hashToSettingsKey(unsigned int hash);
|
||||||
unsigned int hash;
|
unsigned int hash;
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
#include "Traces/tracecsvexport.h"
|
#include "Traces/tracecsvexport.h"
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
#include "Traces/traceimportdialog.h"
|
#include "Traces/traceimportdialog.h"
|
||||||
|
#include "CustomWidgets/informationbox.h"
|
||||||
|
|
||||||
TraceWidgetSA::TraceWidgetSA(TraceModel &model, QWidget *parent)
|
TraceWidgetSA::TraceWidgetSA(TraceModel &model, QWidget *parent)
|
||||||
: TraceWidget(model, parent)
|
: TraceWidget(model, parent)
|
||||||
@ -19,6 +20,7 @@ void TraceWidgetSA::importDialog()
|
|||||||
{
|
{
|
||||||
auto filename = QFileDialog::getOpenFileName(nullptr, "Open measurement file", "", "CSV files (*.csv)", nullptr, QFileDialog::DontUseNativeDialog);
|
auto filename = QFileDialog::getOpenFileName(nullptr, "Open measurement file", "", "CSV files (*.csv)", nullptr, QFileDialog::DontUseNativeDialog);
|
||||||
if (!filename.isEmpty()) {
|
if (!filename.isEmpty()) {
|
||||||
|
try {
|
||||||
std::vector<Trace*> traces;
|
std::vector<Trace*> traces;
|
||||||
QString prefix = QString();
|
QString prefix = QString();
|
||||||
auto csv = CSV::fromFile(filename);
|
auto csv = CSV::fromFile(filename);
|
||||||
@ -35,5 +37,8 @@ void TraceWidgetSA::importDialog()
|
|||||||
prefix.append("_");
|
prefix.append("_");
|
||||||
auto i = new TraceImportDialog(model, traces, prefix);
|
auto i = new TraceImportDialog(model, traces, prefix);
|
||||||
i->show();
|
i->show();
|
||||||
|
} catch(const std::exception e) {
|
||||||
|
InformationBox::ShowError("Failed to import file", QString("Attempt to import file ended with error: \"") + e.what()+"\"");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
#include "Traces/tracecsvexport.h"
|
#include "Traces/tracecsvexport.h"
|
||||||
#include "ui_tracewidget.h"
|
#include "ui_tracewidget.h"
|
||||||
#include "ui_s2pImportOptions.h"
|
#include "ui_s2pImportOptions.h"
|
||||||
|
#include "CustomWidgets/informationbox.h"
|
||||||
|
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
|
|
||||||
@ -47,6 +48,7 @@ void TraceWidgetVNA::importDialog()
|
|||||||
{
|
{
|
||||||
auto filename = QFileDialog::getOpenFileName(nullptr, "Open measurement file", "", "Touchstone files (*.s1p *.s2p *.s3p *.s4p);;CSV files (*.csv)", nullptr, QFileDialog::DontUseNativeDialog);
|
auto filename = QFileDialog::getOpenFileName(nullptr, "Open measurement file", "", "Touchstone files (*.s1p *.s2p *.s3p *.s4p);;CSV files (*.csv)", nullptr, QFileDialog::DontUseNativeDialog);
|
||||||
if (!filename.isEmpty()) {
|
if (!filename.isEmpty()) {
|
||||||
|
try {
|
||||||
std::vector<Trace*> traces;
|
std::vector<Trace*> traces;
|
||||||
QString prefix = QString();
|
QString prefix = QString();
|
||||||
if(filename.endsWith(".csv")) {
|
if(filename.endsWith(".csv")) {
|
||||||
@ -102,5 +104,8 @@ void TraceWidgetVNA::importDialog()
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
} catch(const std::exception& e) {
|
||||||
|
InformationBox::ShowError("Failed to import file", QString("Attempt to import file ended with error: \"") + e.what()+"\"");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user