desktop-widget: remove SettingsObjectWrapper and update qPref calls

remove use of SettingsObjectWrapper::
remove include of SettingsObjectWrapper.h
use qPrefFoo:: for setters and getters
replace prefs.foo with qPrefXYZ::foo() where feasible
(this expands to the same code, but gives us more control
over the variable).

Signed-off-by: Jan Iversen <jani@apache.org>
This commit is contained in:
jan Iversen 2018-08-15 11:56:17 +02:00 committed by Dirk Hohndel
parent c6998ee926
commit 0f68e0cc2e
6 changed files with 80 additions and 91 deletions

View file

@ -3,7 +3,7 @@
#include "core/display.h"
#include "core/qthelper.h"
#include "core/subsurface-qt/SettingsObjectWrapper.h"
#include "core/settings/qPrefDiveComputer.h"
#include "desktop-widgets/mainwindow.h"
// For fill_computer_list, descriptorLookup
#include "core/downloadfromdcthread.h"
@ -132,9 +132,8 @@ ConfigureDiveComputerDialog::ConfigureDiveComputerDialog(QWidget *parent) : QDia
memset(&device_data, 0, sizeof(device_data));
fill_computer_list();
auto dc = SettingsObjectWrapper::instance()->dive_computer_settings;
if (!dc->device().isEmpty())
ui.device->setEditText(dc->device());
if (!qPrefDiveComputer::device().isEmpty())
ui.device->setEditText(qPrefDiveComputer::device());
ui.DiveComputerList->setCurrentRow(0);
on_DiveComputerList_currentRowChanged(0);
@ -912,11 +911,10 @@ void ConfigureDiveComputerDialog::getDeviceData()
device_data.descriptor = descriptorLookup.value(selected_vendor + selected_product);
device_data.deviceid = device_data.diveid = 0;
auto dc = SettingsObjectWrapper::instance()->dive_computer_settings;
dc->set_device(device_data.devname);
qPrefDiveComputer::set_device(device_data.devname);
#ifdef BT_SUPPORT
if (ui.bluetoothMode && btDeviceSelectionDialog)
dc->set_device_name(btDeviceSelectionDialog->getSelectedDeviceName());
qPrefDiveComputer::set_device_name(btDeviceSelectionDialog->getSelectedDeviceName());
#endif
}

View file

@ -4,7 +4,7 @@
#include "desktop-widgets/mainwindow.h"
#include "core/planner.h"
#include "core/qthelper.h"
#include "core/subsurface-qt/SettingsObjectWrapper.h"
#include "core/settings/qPrefDivePlanner.h"
#include "core/gettextfromc.h"
#include "qt-models/cylindermodel.h"

View file

@ -2,7 +2,7 @@
#include "desktop-widgets/downloadfromdivecomputer.h"
#include "core/display.h"
#include "core/qthelper.h"
#include "core/subsurface-qt/SettingsObjectWrapper.h"
#include "core/settings/qPrefDiveComputer.h"
#include "core/subsurface-string.h"
#include "core/uemis.h"
#include "desktop-widgets/divelistview.h"
@ -71,12 +71,11 @@ DownloadFromDCWidget::DownloadFromDCWidget(QWidget *parent, Qt::WindowFlags f) :
MainWindow *w = MainWindow::instance();
connect(&thread, SIGNAL(finished()), w, SLOT(refreshDisplay()));
auto dc = SettingsObjectWrapper::instance()->dive_computer_settings;
if (!dc->vendor().isEmpty()) {
ui.vendor->setCurrentIndex(ui.vendor->findText(dc->vendor()));
productModel.setStringList(productList[dc->vendor()]);
if (!dc->product().isEmpty())
ui.product->setCurrentIndex(ui.product->findText(dc->product()));
if (!qPrefDiveComputer::vendor().isEmpty()) {
ui.vendor->setCurrentIndex(ui.vendor->findText(qPrefDiveComputer::vendor()));
productModel.setStringList(productList[qPrefDiveComputer::vendor()]);
if (!qPrefDiveComputer::product().isEmpty())
ui.product->setCurrentIndex(ui.product->findText(qPrefDiveComputer::product()));
}
updateState(INITIAL);
@ -84,16 +83,16 @@ DownloadFromDCWidget::DownloadFromDCWidget(QWidget *parent, Qt::WindowFlags f) :
ui.downloadCancelRetryButton->setEnabled(true);
ui.downloadCancelRetryButton->setText(tr("Download"));
QString deviceText = dc->device();
QString deviceText = qPrefDiveComputer::device();
#if defined(BT_SUPPORT)
ui.bluetoothMode->setText(tr("Choose Bluetooth download mode"));
ui.bluetoothMode->setChecked(dc->download_mode() == DC_TRANSPORT_BLUETOOTH);
ui.bluetoothMode->setChecked(qPrefDiveComputer::download_mode() == DC_TRANSPORT_BLUETOOTH);
btDeviceSelectionDialog = 0;
connect(ui.bluetoothMode, SIGNAL(stateChanged(int)), this, SLOT(enableBluetoothMode(int)));
connect(ui.chooseBluetoothDevice, SIGNAL(clicked()), this, SLOT(selectRemoteBluetoothDevice()));
ui.chooseBluetoothDevice->setEnabled(ui.bluetoothMode->isChecked());
if (ui.bluetoothMode->isChecked())
deviceText = BtDeviceSelectionDialog::formatDeviceText(dc->device(), dc->device_name());
deviceText = BtDeviceSelectionDialog::formatDeviceText(qPrefDiveComputer::device(), qPrefDiveComputer::device_name());
#else
ui.bluetoothMode->hide();
ui.chooseBluetoothDevice->hide();
@ -288,9 +287,8 @@ void DownloadFromDCWidget::on_downloadCancelRetryButton_clicked()
data->setDevName(btDeviceSelectionDialog->getSelectedDeviceAddress());
data->setDevBluetoothName(btDeviceSelectionDialog->getSelectedDeviceName());
} else {
auto dc = SettingsObjectWrapper::instance()->dive_computer_settings;
data->setDevName(dc->device());
data->setDevBluetoothName(dc->device_name());
data->setDevName(qPrefDiveComputer::device());
data->setDevBluetoothName(qPrefDiveComputer::device_name());
}
} else
// this breaks an "else if" across lines... not happy...
@ -313,13 +311,12 @@ void DownloadFromDCWidget::on_downloadCancelRetryButton_clicked()
data->setSaveLog(ui.logToFile->isChecked());
data->setSaveDump(ui.dumpToFile->isChecked());
auto dc = SettingsObjectWrapper::instance()->dive_computer_settings;
dc->set_vendor(data->vendor());
dc->set_product(data->product());
dc->set_device(data->devName());
qPrefDiveComputer::set_vendor(data->vendor());
qPrefDiveComputer::set_product(data->product());
qPrefDiveComputer::set_device(data->devName());
#if defined(BT_SUPPORT)
dc->set_download_mode(ui.bluetoothMode->isChecked() ? DC_TRANSPORT_BLUETOOTH : DC_TRANSPORT_SERIAL);
qPrefDiveComputer::set_download_mode(ui.bluetoothMode->isChecked() ? DC_TRANSPORT_BLUETOOTH : DC_TRANSPORT_SERIAL);
#endif
// before we start, remember where the dive_table ended

View file

@ -61,7 +61,6 @@
#include "core/color.h"
#include "core/isocialnetworkintegration.h"
#include "core/pluginmanager.h"
#include "core/subsurface-qt/SettingsObjectWrapper.h"
#if defined(FBSUPPORT)
#include "plugins/facebook/facebook_integration.h"
@ -284,21 +283,21 @@ MainWindow::MainWindow() : QMainWindow(),
set_error_cb(&showErrorFromC);
// Toolbar Connections related to the Profile Update
SettingsObjectWrapper *sWrapper = SettingsObjectWrapper::instance();
connect(ui.profCalcAllTissues, &QAction::triggered, sWrapper->techDetails, &qPrefTechnicalDetails::set_calcalltissues);
connect(ui.profCalcCeiling, &QAction::triggered, sWrapper->techDetails, &qPrefTechnicalDetails::set_calcceiling);
connect(ui.profDcCeiling, &QAction::triggered, sWrapper->techDetails, &qPrefTechnicalDetails::set_dcceiling);
connect(ui.profEad, &QAction::triggered, sWrapper->techDetails, &qPrefTechnicalDetails::set_ead);
connect(ui.profIncrement3m, &QAction::triggered, sWrapper->techDetails, &qPrefTechnicalDetails::set_calcceiling3m);
connect(ui.profMod, &QAction::triggered, sWrapper->techDetails, &qPrefTechnicalDetails::set_mod);
connect(ui.profNdl_tts, &QAction::triggered, sWrapper->techDetails, &qPrefTechnicalDetails::set_calcndltts);
connect(ui.profHR, &QAction::triggered, sWrapper->techDetails, &qPrefTechnicalDetails::set_hrgraph);
connect(ui.profRuler, &QAction::triggered, sWrapper->techDetails, &qPrefTechnicalDetails::set_rulergraph);
connect(ui.profSAC, &QAction::triggered, sWrapper->techDetails, &qPrefTechnicalDetails::set_show_sac);
connect(ui.profScaled, &QAction::triggered, sWrapper->techDetails, &qPrefTechnicalDetails::set_zoomed_plot);
connect(ui.profTogglePicture, &QAction::triggered, sWrapper->techDetails, &qPrefTechnicalDetails::set_show_pictures_in_profile);
connect(ui.profTankbar, &QAction::triggered, sWrapper->techDetails, &qPrefTechnicalDetails::set_tankbar);
connect(ui.profTissues, &QAction::triggered, sWrapper->techDetails, &qPrefTechnicalDetails::set_percentagegraph);
auto tec = qPrefTechnicalDetails::instance();
connect(ui.profCalcAllTissues, &QAction::triggered, tec, &qPrefTechnicalDetails::set_calcalltissues);
connect(ui.profCalcCeiling, &QAction::triggered, tec, &qPrefTechnicalDetails::set_calcceiling);
connect(ui.profDcCeiling, &QAction::triggered, tec, &qPrefTechnicalDetails::set_dcceiling);
connect(ui.profEad, &QAction::triggered, tec, &qPrefTechnicalDetails::set_ead);
connect(ui.profIncrement3m, &QAction::triggered, tec, &qPrefTechnicalDetails::set_calcceiling3m);
connect(ui.profMod, &QAction::triggered, tec, &qPrefTechnicalDetails::set_mod);
connect(ui.profNdl_tts, &QAction::triggered, tec, &qPrefTechnicalDetails::set_calcndltts);
connect(ui.profHR, &QAction::triggered, tec, &qPrefTechnicalDetails::set_hrgraph);
connect(ui.profRuler, &QAction::triggered, tec, &qPrefTechnicalDetails::set_rulergraph);
connect(ui.profSAC, &QAction::triggered, tec, &qPrefTechnicalDetails::set_show_sac);
connect(ui.profScaled, &QAction::triggered, tec, &qPrefTechnicalDetails::set_zoomed_plot);
connect(ui.profTogglePicture, &QAction::triggered, tec, &qPrefTechnicalDetails::set_show_pictures_in_profile);
connect(ui.profTankbar, &QAction::triggered, tec, &qPrefTechnicalDetails::set_tankbar);
connect(ui.profTissues, &QAction::triggered, tec, &qPrefTechnicalDetails::set_percentagegraph);
connect(ui.profTissues, &QAction::triggered, this, &MainWindow::unsetProfHR);
connect(ui.profHR, &QAction::triggered, this, &MainWindow::unsetProfTissues);
@ -308,24 +307,24 @@ MainWindow::MainWindow() : QMainWindow(),
connect(ui.profPn2, &QAction::triggered, pp_gas, &qPrefPartialPressureGas::set_pn2);
connect(ui.profPO2, &QAction::triggered, pp_gas, &qPrefPartialPressureGas::set_po2);
connect(sWrapper->techDetails, &qPrefTechnicalDetails::calcalltissues_changed , graphics(), &ProfileWidget2::actionRequestedReplot);
connect(sWrapper->techDetails, &qPrefTechnicalDetails::calcceiling_changed , graphics(), &ProfileWidget2::actionRequestedReplot);
connect(sWrapper->techDetails, &qPrefTechnicalDetails::dcceiling_changed , graphics(), &ProfileWidget2::actionRequestedReplot);
connect(sWrapper->techDetails, &qPrefTechnicalDetails::ead_changed , graphics(), &ProfileWidget2::actionRequestedReplot);
connect(sWrapper->techDetails, &qPrefTechnicalDetails::calcceiling3m_changed , graphics(), &ProfileWidget2::actionRequestedReplot);
connect(sWrapper->techDetails, &qPrefTechnicalDetails::mod_changed , graphics(), &ProfileWidget2::actionRequestedReplot);
connect(sWrapper->techDetails, &qPrefTechnicalDetails::calcndltts_changed , graphics(), &ProfileWidget2::actionRequestedReplot);
connect(sWrapper->techDetails, &qPrefTechnicalDetails::hrgraph_changed , graphics(), &ProfileWidget2::actionRequestedReplot);
connect(sWrapper->techDetails, &qPrefTechnicalDetails::rulergraph_changed , graphics(), &ProfileWidget2::actionRequestedReplot);
connect(sWrapper->techDetails, &qPrefTechnicalDetails::show_sac_changed , graphics(), &ProfileWidget2::actionRequestedReplot);
connect(sWrapper->techDetails, &qPrefTechnicalDetails::zoomed_plot_changed , graphics(), &ProfileWidget2::actionRequestedReplot);
connect(sWrapper->techDetails, &qPrefTechnicalDetails::show_pictures_in_profile_changed , graphics(), &ProfileWidget2::actionRequestedReplot);
connect(sWrapper->techDetails, &qPrefTechnicalDetails::tankbar_changed , graphics(), &ProfileWidget2::actionRequestedReplot);
connect(sWrapper->techDetails, &qPrefTechnicalDetails::percentagegraph_changed , graphics(), &ProfileWidget2::actionRequestedReplot);
connect(tec, &qPrefTechnicalDetails::calcalltissues_changed , graphics(), &ProfileWidget2::actionRequestedReplot);
connect(tec, &qPrefTechnicalDetails::calcceiling_changed , graphics(), &ProfileWidget2::actionRequestedReplot);
connect(tec, &qPrefTechnicalDetails::dcceiling_changed , graphics(), &ProfileWidget2::actionRequestedReplot);
connect(tec, &qPrefTechnicalDetails::ead_changed , graphics(), &ProfileWidget2::actionRequestedReplot);
connect(tec, &qPrefTechnicalDetails::calcceiling3m_changed , graphics(), &ProfileWidget2::actionRequestedReplot);
connect(tec, &qPrefTechnicalDetails::mod_changed , graphics(), &ProfileWidget2::actionRequestedReplot);
connect(tec, &qPrefTechnicalDetails::calcndltts_changed , graphics(), &ProfileWidget2::actionRequestedReplot);
connect(tec, &qPrefTechnicalDetails::hrgraph_changed , graphics(), &ProfileWidget2::actionRequestedReplot);
connect(tec, &qPrefTechnicalDetails::rulergraph_changed , graphics(), &ProfileWidget2::actionRequestedReplot);
connect(tec, &qPrefTechnicalDetails::show_sac_changed , graphics(), &ProfileWidget2::actionRequestedReplot);
connect(tec, &qPrefTechnicalDetails::zoomed_plot_changed , graphics(), &ProfileWidget2::actionRequestedReplot);
connect(tec, &qPrefTechnicalDetails::show_pictures_in_profile_changed , graphics(), &ProfileWidget2::actionRequestedReplot);
connect(tec, &qPrefTechnicalDetails::tankbar_changed , graphics(), &ProfileWidget2::actionRequestedReplot);
connect(tec, &qPrefTechnicalDetails::percentagegraph_changed , graphics(), &ProfileWidget2::actionRequestedReplot);
connect(sWrapper->pp_gas, &qPrefPartialPressureGas::phe_changed, graphics(), &ProfileWidget2::actionRequestedReplot);
connect(sWrapper->pp_gas, &qPrefPartialPressureGas::pn2_changed, graphics(), &ProfileWidget2::actionRequestedReplot);
connect(sWrapper->pp_gas, &qPrefPartialPressureGas::po2_changed, graphics(), &ProfileWidget2::actionRequestedReplot);
connect(pp_gas, &qPrefPartialPressureGas::phe_changed, graphics(), &ProfileWidget2::actionRequestedReplot);
connect(pp_gas, &qPrefPartialPressureGas::pn2_changed, graphics(), &ProfileWidget2::actionRequestedReplot);
connect(pp_gas, &qPrefPartialPressureGas::po2_changed, graphics(), &ProfileWidget2::actionRequestedReplot);
// now let's set up some connections
connect(graphics(), &ProfileWidget2::enableToolbar ,this, &MainWindow::setEnabledToolbar);
@ -337,23 +336,23 @@ MainWindow::MainWindow() : QMainWindow(),
connect(PreferencesDialog::instance(), SIGNAL(settingsChanged()), graphics(), SLOT(settingsChanged()));
ui.profCalcAllTissues->setChecked(sWrapper->techDetails->calcalltissues());
ui.profCalcCeiling->setChecked(sWrapper->techDetails->calcceiling());
ui.profDcCeiling->setChecked(sWrapper->techDetails->dcceiling());
ui.profEad->setChecked(sWrapper->techDetails->ead());
ui.profIncrement3m->setChecked(sWrapper->techDetails->calcceiling3m());
ui.profMod->setChecked(sWrapper->techDetails->mod());
ui.profNdl_tts->setChecked(sWrapper->techDetails->calcndltts());
ui.profCalcAllTissues->setChecked(qPrefTechnicalDetails::calcalltissues());
ui.profCalcCeiling->setChecked(qPrefTechnicalDetails::calcceiling());
ui.profDcCeiling->setChecked(qPrefTechnicalDetails::dcceiling());
ui.profEad->setChecked(qPrefTechnicalDetails::ead());
ui.profIncrement3m->setChecked(qPrefTechnicalDetails::calcceiling3m());
ui.profMod->setChecked(qPrefTechnicalDetails::mod());
ui.profNdl_tts->setChecked(qPrefTechnicalDetails::calcndltts());
ui.profPhe->setChecked(pp_gas->phe());
ui.profPn2->setChecked(pp_gas->pn2());
ui.profPO2->setChecked(pp_gas->po2());
ui.profHR->setChecked(sWrapper->techDetails->hrgraph());
ui.profRuler->setChecked(sWrapper->techDetails->rulergraph());
ui.profSAC->setChecked(sWrapper->techDetails->show_sac());
ui.profTogglePicture->setChecked(sWrapper->techDetails->show_pictures_in_profile());
ui.profTankbar->setChecked(sWrapper->techDetails->tankbar());
ui.profTissues->setChecked(sWrapper->techDetails->percentagegraph());
ui.profScaled->setChecked(sWrapper->techDetails->zoomed_plot());
ui.profHR->setChecked(qPrefTechnicalDetails::hrgraph());
ui.profRuler->setChecked(qPrefTechnicalDetails::rulergraph());
ui.profSAC->setChecked(qPrefTechnicalDetails::show_sac());
ui.profTogglePicture->setChecked(qPrefTechnicalDetails::show_pictures_in_profile());
ui.profTankbar->setChecked(qPrefTechnicalDetails::tankbar());
ui.profTissues->setChecked(qPrefTechnicalDetails::percentagegraph());
ui.profScaled->setChecked(qPrefTechnicalDetails::zoomed_plot());
// full screen support is buggy on Windows and Ubuntu.
// require the FULLSCREEN_SUPPORT macro to enable it!
@ -1911,7 +1910,7 @@ void MainWindow::editCurrentDive()
void MainWindow::turnOffNdlTts()
{
SettingsObjectWrapper::instance()->techDetails->set_calcndltts(false);
qPrefTechnicalDetails::set_calcndltts(false);
}
#undef TOOLBOX_PREF_PROFILE
@ -2047,16 +2046,12 @@ void MainWindow::hideProgressBar()
void MainWindow::unsetProfHR()
{
SettingsObjectWrapper *sWrapper = SettingsObjectWrapper::instance();
ui.profHR->setChecked(false);
sWrapper->techDetails->set_hrgraph(false);
qPrefTechnicalDetails::set_hrgraph(false);
}
void MainWindow::unsetProfTissues()
{
SettingsObjectWrapper *sWrapper = SettingsObjectWrapper::instance();
ui.profTissues->setChecked(false);
sWrapper->techDetails->set_percentagegraph(false);
qPrefTechnicalDetails::set_percentagegraph(false);
}

View file

@ -3,6 +3,7 @@
#include "templatelayout.h"
#include "core/statistics.h"
#include "core/qthelper.h"
#include "core/settings/qPrefAnimations.h"
#include <algorithm>
#include <QPainter>
@ -135,7 +136,7 @@ void Printer::render(int Pages = 0)
// keep original preferences
QPointer<ProfileWidget2> profile = MainWindow::instance()->graphics();
int profileFrameStyle = profile->frameStyle();
int animationOriginal = prefs.animation_speed;
int animationOriginal = qPrefAnimations::animation_speed();
double fontScale = profile->getFontPrintScale();
double printFontScale = 1.0;
@ -143,7 +144,7 @@ void Printer::render(int Pages = 0)
profile->setFrameStyle(QFrame::NoFrame);
profile->setPrintMode(true, !printOptions->color_selected);
profile->setToolTipVisibile(false);
prefs.animation_speed = 0;
qPrefAnimations::set_animation_speed(0);
// render the Qwebview
QPainter painter;
@ -201,7 +202,7 @@ void Printer::render(int Pages = 0)
#else
profile->resize(originalSize);
#endif
prefs.animation_speed = animationOriginal;
qPrefAnimations::set_animation_speed(animationOriginal);
//replot the dive after returning the settings
profile->plotDive(0, true, true);

View file

@ -8,23 +8,21 @@
#include "core/version.h"
#include "desktop-widgets/mainwindow.h"
#include "core/cloudstorage.h"
#include "core/subsurface-qt/SettingsObjectWrapper.h"
#include "core/settings/qPrefUpdateManager.h"
UpdateManager::UpdateManager(QObject *parent) :
QObject(parent),
isAutomaticCheck(false)
{
auto update_settings = qPrefUpdateManager::instance();
if (update_settings->dont_check_for_updates())
if (qPrefUpdateManager::dont_check_for_updates())
return;
if (update_settings->last_version_used() == subsurface_git_version() &&
update_settings->next_check() > QDate::currentDate())
if (qPrefUpdateManager::last_version_used() == subsurface_git_version() &&
qPrefUpdateManager::next_check() > QDate::currentDate())
return;
update_settings->set_last_version_used(subsurface_git_version());
update_settings->set_next_check(QDate::currentDate().addDays(14));
qPrefUpdateManager::set_last_version_used(subsurface_git_version());
qPrefUpdateManager::set_next_check(QDate::currentDate().addDays(14));
checkForUpdates(true);
}