computer configuration: pass current filename to dialog

Instead of accessing a global variable, pass the filename
from the MainWindow to the dialog. This is supposed to cut
down on the global variable mess.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2024-03-16 09:53:22 +01:00 committed by bstoeger
parent 2e067c89dd
commit 981352646c
3 changed files with 8 additions and 10 deletions

View file

@ -117,10 +117,11 @@ static const DiveComputerEntry supportedDiveComputers[] = {
{ "Suunto", "Vyper", DC_TRANSPORT_SERIAL, false, false }, { "Suunto", "Vyper", DC_TRANSPORT_SERIAL, false, false },
}; };
ConfigureDiveComputerDialog::ConfigureDiveComputerDialog(QWidget *parent) : QDialog(parent), ConfigureDiveComputerDialog::ConfigureDiveComputerDialog(const QString &filename, QWidget *parent) : QDialog(parent),
config(0), filename(filename),
config(0)
#ifdef BT_SUPPORT #ifdef BT_SUPPORT
btDeviceSelectionDialog(0) , btDeviceSelectionDialog(0)
#endif #endif
{ {
ui.setupUi(this); ui.setupUi(this);
@ -1399,7 +1400,6 @@ void ConfigureDiveComputerDialog::reloadValuesOSTC4()
void ConfigureDiveComputerDialog::on_backupButton_clicked() void ConfigureDiveComputerDialog::on_backupButton_clicked()
{ {
QString filename = existing_filename ?: prefs.default_filename;
QFileInfo fi(filename); QFileInfo fi(filename);
filename = fi.absolutePath().append(QDir::separator()).append("Backup.xml"); filename = fi.absolutePath().append(QDir::separator()).append("Backup.xml");
QString backupPath = QFileDialog::getSaveFileName(this, tr("Backup dive computer settings"), QString backupPath = QFileDialog::getSaveFileName(this, tr("Backup dive computer settings"),
@ -1420,7 +1420,6 @@ void ConfigureDiveComputerDialog::on_backupButton_clicked()
void ConfigureDiveComputerDialog::on_restoreBackupButton_clicked() void ConfigureDiveComputerDialog::on_restoreBackupButton_clicked()
{ {
QString filename = existing_filename ?: prefs.default_filename;
QFileInfo fi(filename); QFileInfo fi(filename);
filename = fi.absolutePath().append(QDir::separator()).append("Backup.xml"); filename = fi.absolutePath().append(QDir::separator()).append("Backup.xml");
QString restorePath = QFileDialog::getOpenFileName(this, tr("Restore dive computer settings"), QString restorePath = QFileDialog::getOpenFileName(this, tr("Restore dive computer settings"),
@ -1443,7 +1442,6 @@ void ConfigureDiveComputerDialog::on_restoreBackupButton_clicked()
void ConfigureDiveComputerDialog::on_updateFirmwareButton_clicked() void ConfigureDiveComputerDialog::on_updateFirmwareButton_clicked()
{ {
QString filename = existing_filename ?: prefs.default_filename;
QFileInfo fi(filename); QFileInfo fi(filename);
filename = fi.absolutePath(); filename = fi.absolutePath();
QString firmwarePath = QFileDialog::getOpenFileName(this, tr("Select firmware file"), QString firmwarePath = QFileDialog::getOpenFileName(this, tr("Select firmware file"),
@ -1480,7 +1478,6 @@ void ConfigureDiveComputerDialog::checkLogFile(int state)
void ConfigureDiveComputerDialog::pickLogFile() void ConfigureDiveComputerDialog::pickLogFile()
{ {
QString filename = existing_filename ?: prefs.default_filename;
QFileInfo fi(filename); QFileInfo fi(filename);
filename = fi.absolutePath().append(QDir::separator()).append("subsurface.log"); filename = fi.absolutePath().append(QDir::separator()).append("subsurface.log");
logFile = QFileDialog::getSaveFileName(this, tr("Choose file for dive computer download logfile"), logFile = QFileDialog::getSaveFileName(this, tr("Choose file for dive computer download logfile"),

View file

@ -58,7 +58,7 @@ class ConfigureDiveComputerDialog : public QDialog {
Q_OBJECT Q_OBJECT
public: public:
explicit ConfigureDiveComputerDialog(QWidget *parent = 0); explicit ConfigureDiveComputerDialog(const QString &filename, QWidget *parent = 0);
~ConfigureDiveComputerDialog(); ~ConfigureDiveComputerDialog();
private private
@ -77,7 +77,6 @@ slots:
void on_restoreBackupButton_clicked(); void on_restoreBackupButton_clicked();
void on_updateFirmwareButton_clicked(); void on_updateFirmwareButton_clicked();
void on_DiveComputerList_currentRowChanged(int currentRow); void on_DiveComputerList_currentRowChanged(int currentRow);
@ -94,6 +93,7 @@ private:
Ui::ConfigureDiveComputerDialog ui; Ui::ConfigureDiveComputerDialog ui;
QString logFile; QString logFile;
QString filename;
void closeEvent(QCloseEvent *event); void closeEvent(QCloseEvent *event);

View file

@ -1395,7 +1395,8 @@ void MainWindow::on_actionExport_triggered()
void MainWindow::on_actionConfigure_Dive_Computer_triggered() void MainWindow::on_actionConfigure_Dive_Computer_triggered()
{ {
ConfigureDiveComputerDialog *dcConfig = new ConfigureDiveComputerDialog(this); QString filename = existing_filename ?: prefs.default_filename;
ConfigureDiveComputerDialog *dcConfig = new ConfigureDiveComputerDialog(filename, this);
dcConfig->show(); dcConfig->show();
} }