@@ -238,98 +238,97 @@ MainWindow::MainWindow(QWidget *parent)
// init demo
QObject::connect(ui->actionDemoMode, &QAction::toggled,
this, &MainWindow::enableDemo);
plotMan, &PlotManager::showDemoIndicator);
// load default settings
QSettings settings("serialplot", "serialplot");
loadAllSettings(&settings);
// ensure command panel has 1 command if none loaded
if (!commandPanel.numOfCommands())
{
commandPanel.newCommandAction()->trigger();
}
// Important: This should be after newCommandAction is triggered
// (above) we don't want user to be greeted with command panel on
// the very first run.
connect(commandPanel.newCommandAction(), &QAction::triggered, [this]()
this->ui->tabWidget->setCurrentWidget(&commandPanel);
this->ui->tabWidget->showTabs();
});
MainWindow::~MainWindow()
if (serialPort.isOpen())
serialPort.close();
delete plotMan;
delete ui;
ui = NULL; // we check if ui is deleted in messageHandler
void MainWindow::closeEvent(QCloseEvent * event)
// save snapshots
if (!snapshotMan.isAllSaved())
auto clickedButton = QMessageBox::warning(
this, "Closing SerialPlot",
"There are un-saved snapshots. If you close you will loose the data.",
QMessageBox::Discard | QMessageBox::Discard,
QMessageBox::Cancel);
QMessageBox::Discard, QMessageBox::Cancel);
if (clickedButton == QMessageBox::Cancel)
event->ignore();
return;
// save settings
saveAllSettings(&settings);
settings.sync();
if (settings.status() != QSettings::NoError)
QString errorText;
if (settings.status() == QSettings::AccessError)
QString file = settings.fileName();
errorText = QString("Serialplot cannot save settings due to access error. \
This happens if you have run serialplot as root (with sudo for ex.) previously. \
Try fixing the permissions of file: %1, or just delete it.").arg(file);
else
errorText = QString("Serialplot cannot save settings due to unknown error: %1").\
arg(settings.status());
auto button = QMessageBox::critical(
NULL,
"Failed to save settings!", errorText,
QMessageBox::Cancel | QMessageBox::Ok);
if (button == QMessageBox::Cancel)
QMainWindow::closeEvent(event);
void MainWindow::setupAboutDialog()
Ui_AboutDialog uiAboutDialog;
uiAboutDialog.setupUi(&aboutDialog);
Status change: