profile-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:52:50 +02:00 committed by Dirk Hohndel
parent 50c58b4065
commit 1cc7c05170
6 changed files with 35 additions and 33 deletions

View file

@ -1,13 +1,14 @@
// SPDX-License-Identifier: GPL-2.0 // SPDX-License-Identifier: GPL-2.0
#include "profile-widget/animationfunctions.h" #include "profile-widget/animationfunctions.h"
#include "core/pref.h" #include "core/pref.h"
#include "core/settings/qPrefAnimations.h"
#include <QPropertyAnimation> #include <QPropertyAnimation>
namespace Animations { namespace Animations {
void hide(QObject *obj) void hide(QObject *obj)
{ {
if (prefs.animation_speed != 0) { if (qPrefAnimations::animation_speed() != 0) {
QPropertyAnimation *animation = new QPropertyAnimation(obj, "opacity"); QPropertyAnimation *animation = new QPropertyAnimation(obj, "opacity");
animation->setStartValue(1); animation->setStartValue(1);
animation->setEndValue(0); animation->setEndValue(0);
@ -19,7 +20,7 @@ namespace Animations {
void show(QObject *obj) void show(QObject *obj)
{ {
if (prefs.animation_speed != 0) { if (qPrefAnimations::animation_speed() != 0) {
QPropertyAnimation *animation = new QPropertyAnimation(obj, "opacity"); QPropertyAnimation *animation = new QPropertyAnimation(obj, "opacity");
animation->setStartValue(0); animation->setStartValue(0);
animation->setEndValue(1); animation->setEndValue(1);
@ -31,7 +32,7 @@ namespace Animations {
void animDelete(QObject *obj) void animDelete(QObject *obj)
{ {
if (prefs.animation_speed != 0) { if (qPrefAnimations::animation_speed() != 0) {
QPropertyAnimation *animation = new QPropertyAnimation(obj, "opacity"); QPropertyAnimation *animation = new QPropertyAnimation(obj, "opacity");
obj->connect(animation, &QPropertyAnimation::finished, &QObject::deleteLater); obj->connect(animation, &QPropertyAnimation::finished, &QObject::deleteLater);
animation->setStartValue(1); animation->setStartValue(1);
@ -44,7 +45,7 @@ namespace Animations {
void moveTo(QObject *obj, qreal x, qreal y) void moveTo(QObject *obj, qreal x, qreal y)
{ {
if (prefs.animation_speed != 0) { if (qPrefAnimations::animation_speed() != 0) {
QPropertyAnimation *animation = new QPropertyAnimation(obj, "pos"); QPropertyAnimation *animation = new QPropertyAnimation(obj, "pos");
animation->setDuration(prefs.animation_speed); animation->setDuration(prefs.animation_speed);
animation->setStartValue(obj->property("pos").toPointF()); animation->setStartValue(obj->property("pos").toPointF());
@ -57,7 +58,7 @@ namespace Animations {
void scaleTo(QObject *obj, qreal scale) void scaleTo(QObject *obj, qreal scale)
{ {
if (prefs.animation_speed != 0) { if (qPrefAnimations::animation_speed() != 0) {
QPropertyAnimation *animation = new QPropertyAnimation(obj, "scale"); QPropertyAnimation *animation = new QPropertyAnimation(obj, "scale");
animation->setDuration(prefs.animation_speed); animation->setDuration(prefs.animation_speed);
animation->setStartValue(obj->property("scale").toReal()); animation->setStartValue(obj->property("scale").toReal());

View file

@ -3,7 +3,6 @@
#include "profile-widget/divetextitem.h" #include "profile-widget/divetextitem.h"
#include "core/qthelper.h" #include "core/qthelper.h"
#include "core/subsurface-string.h" #include "core/subsurface-string.h"
#include "core/subsurface-qt/SettingsObjectWrapper.h"
#ifndef SUBSURFACE_MOBILE #ifndef SUBSURFACE_MOBILE
#include "desktop-widgets/preferences/preferencesdialog.h" #include "desktop-widgets/preferences/preferencesdialog.h"
#endif #endif

View file

@ -10,7 +10,7 @@
#endif #endif
#include "qt-models/diveplannermodel.h" #include "qt-models/diveplannermodel.h"
#include "core/qthelper.h" #include "core/qthelper.h"
#include "core/subsurface-qt/SettingsObjectWrapper.h" #include "core/settings/qPrefTechnicalDetails.h"
#include "libdivecomputer/parser.h" #include "libdivecomputer/parser.h"
#include "profile-widget/profilewidget2.h" #include "profile-widget/profilewidget2.h"
@ -112,8 +112,8 @@ void AbstractProfilePolygonItem::modelDataChanged(const QModelIndex&, const QMod
DiveProfileItem::DiveProfileItem() : show_reported_ceiling(0), reported_ceiling_in_red(0) DiveProfileItem::DiveProfileItem() : show_reported_ceiling(0), reported_ceiling_in_red(0)
{ {
connect(SettingsObjectWrapper::instance()->techDetails, &qPrefTechnicalDetails::dcceiling_changed, this, &DiveProfileItem::settingsToggled); connect(qPrefTechnicalDetails::instance(), &qPrefTechnicalDetails::dcceiling_changed, this, &DiveProfileItem::settingsToggled);
connect(SettingsObjectWrapper::instance()->techDetails, &qPrefTechnicalDetails::redceiling_changed, this, &DiveProfileItem::settingsToggled); connect(qPrefTechnicalDetails::instance(), &qPrefTechnicalDetails::redceiling_changed, this, &DiveProfileItem::settingsToggled);
} }
void DiveProfileItem::settingsToggled(bool) void DiveProfileItem::settingsToggled(bool)
@ -267,7 +267,7 @@ DiveHeartrateItem::DiveHeartrateItem()
pen.setCosmetic(true); pen.setCosmetic(true);
pen.setWidth(1); pen.setWidth(1);
setPen(pen); setPen(pen);
connect(SettingsObjectWrapper::instance()->techDetails, &qPrefTechnicalDetails::hrgraph_changed, this, &DiveHeartrateItem::setVisible); connect(qPrefTechnicalDetails::instance(), &qPrefTechnicalDetails::hrgraph_changed, this, &DiveHeartrateItem::setVisible);
} }
void DiveHeartrateItem::modelDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight) void DiveHeartrateItem::modelDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
@ -348,7 +348,7 @@ void DiveHeartrateItem::paint(QPainter *painter, const QStyleOptionGraphicsItem*
DivePercentageItem::DivePercentageItem(int i) DivePercentageItem::DivePercentageItem(int i)
{ {
connect(SettingsObjectWrapper::instance()->techDetails, &qPrefTechnicalDetails::percentagegraph_changed, this, &DivePercentageItem::setVisible); connect(qPrefTechnicalDetails::instance(), &qPrefTechnicalDetails::percentagegraph_changed, this, &DivePercentageItem::setVisible);
tissueIndex = i; tissueIndex = i;
settingsChanged(); settingsChanged();
} }
@ -465,7 +465,7 @@ void DiveAmbPressureItem::paint(QPainter *painter, const QStyleOptionGraphicsIte
painter->setPen(pen()); painter->setPen(pen());
painter->drawPolyline(polygon()); painter->drawPolyline(polygon());
painter->restore(); painter->restore();
connect(SettingsObjectWrapper::instance()->techDetails, &qPrefTechnicalDetails::percentagegraph_changed, this, &DiveAmbPressureItem::setVisible); connect(qPrefTechnicalDetails::instance(), &qPrefTechnicalDetails::percentagegraph_changed, this, &DiveAmbPressureItem::setVisible);
} }
DiveGFLineItem::DiveGFLineItem() DiveGFLineItem::DiveGFLineItem()
@ -510,7 +510,7 @@ void DiveGFLineItem::paint(QPainter *painter, const QStyleOptionGraphicsItem*, Q
painter->setPen(pen()); painter->setPen(pen());
painter->drawPolyline(polygon()); painter->drawPolyline(polygon());
painter->restore(); painter->restore();
connect(SettingsObjectWrapper::instance()->techDetails, &qPrefTechnicalDetails::percentagegraph_changed, this, &DiveAmbPressureItem::setVisible); connect(qPrefTechnicalDetails::instance(), &qPrefTechnicalDetails::percentagegraph_changed, this, &DiveAmbPressureItem::setVisible);
} }
DiveTemperatureItem::DiveTemperatureItem() DiveTemperatureItem::DiveTemperatureItem()
@ -635,7 +635,7 @@ void DiveMeanDepthItem::paint(QPainter *painter, const QStyleOptionGraphicsItem*
painter->setPen(pen()); painter->setPen(pen());
painter->drawPolyline(polygon()); painter->drawPolyline(polygon());
painter->restore(); painter->restore();
connect(SettingsObjectWrapper::instance()->techDetails, &qPrefTechnicalDetails::show_average_depth_changed, this, &DiveAmbPressureItem::setVisible); connect(qPrefTechnicalDetails::instance(), &qPrefTechnicalDetails::show_average_depth_changed, this, &DiveAmbPressureItem::setVisible);
} }
void DiveMeanDepthItem::createTextItem() { void DiveMeanDepthItem::createTextItem() {
@ -821,7 +821,7 @@ DiveCalculatedCeiling::DiveCalculatedCeiling(ProfileWidget2 *widget) :
profileWidget(widget), profileWidget(widget),
is3mIncrement(false) is3mIncrement(false)
{ {
connect(SettingsObjectWrapper::instance()->techDetails, &qPrefTechnicalDetails::calcceiling_changed, this, &DiveCalculatedCeiling::setVisible); connect(qPrefTechnicalDetails::instance(), &qPrefTechnicalDetails::calcceiling_changed, this, &DiveCalculatedCeiling::setVisible);
setVisible(prefs.calcceiling); setVisible(prefs.calcceiling);
settingsChanged(); settingsChanged();
} }
@ -862,8 +862,8 @@ void DiveCalculatedCeiling::paint(QPainter *painter, const QStyleOptionGraphicsI
DiveCalculatedTissue::DiveCalculatedTissue(ProfileWidget2 *widget) : DiveCalculatedCeiling(widget) DiveCalculatedTissue::DiveCalculatedTissue(ProfileWidget2 *widget) : DiveCalculatedCeiling(widget)
{ {
settingsChanged(); settingsChanged();
connect(SettingsObjectWrapper::instance()->techDetails, &qPrefTechnicalDetails::calcalltissues_changed, this, &DiveCalculatedTissue::setVisible); connect(qPrefTechnicalDetails::instance(), &qPrefTechnicalDetails::calcalltissues_changed, this, &DiveCalculatedTissue::setVisible);
connect(SettingsObjectWrapper::instance()->techDetails, &qPrefTechnicalDetails::calcceiling_changed, this, &DiveCalculatedTissue::setVisible); connect(qPrefTechnicalDetails::instance(), &qPrefTechnicalDetails::calcceiling_changed, this, &DiveCalculatedTissue::setVisible);
} }
void DiveCalculatedTissue::setVisible(bool) void DiveCalculatedTissue::setVisible(bool)
@ -878,7 +878,7 @@ void DiveCalculatedTissue::settingsChanged()
DiveReportedCeiling::DiveReportedCeiling() DiveReportedCeiling::DiveReportedCeiling()
{ {
connect(SettingsObjectWrapper::instance()->techDetails, &qPrefTechnicalDetails::dcceiling_changed, this, &DiveReportedCeiling::setVisible); connect(qPrefTechnicalDetails::instance(), &qPrefTechnicalDetails::dcceiling_changed, this, &DiveReportedCeiling::setVisible);
setVisible(prefs.dcceiling); setVisible(prefs.dcceiling);
settingsChanged(); settingsChanged();
} }

View file

@ -4,6 +4,7 @@
#include "core/profile.h" #include "core/profile.h"
#include "core/membuffer.h" #include "core/membuffer.h"
#include "core/metrics.h" #include "core/metrics.h"
#include "core/settings/qPrefAnimations.h"
#include <QPropertyAnimation> #include <QPropertyAnimation>
#include <QSettings> #include <QSettings>
#include <QGraphicsView> #include <QGraphicsView>
@ -61,7 +62,7 @@ void ToolTipItem::collapse()
{ {
int dim = defaultIconMetrics().sz_small; int dim = defaultIconMetrics().sz_small;
if (prefs.animation_speed) { if (qPrefAnimations::animation_speed()) {
QPropertyAnimation *animation = new QPropertyAnimation(this, "rect"); QPropertyAnimation *animation = new QPropertyAnimation(this, "rect");
animation->setDuration(100); animation->setDuration(100);
animation->setStartValue(nextRectangle); animation->setStartValue(nextRectangle);
@ -119,7 +120,7 @@ void ToolTipItem::expand()
nextRectangle.setHeight(height); nextRectangle.setHeight(height);
if (nextRectangle != rect()) { if (nextRectangle != rect()) {
if (prefs.animation_speed) { if (qPrefAnimations::animation_speed()) {
QPropertyAnimation *animation = new QPropertyAnimation(this, "rect", this); QPropertyAnimation *animation = new QPropertyAnimation(this, "rect", this);
animation->setDuration(prefs.animation_speed); animation->setDuration(prefs.animation_speed);
animation->setStartValue(rect()); animation->setStartValue(rect());

View file

@ -4,6 +4,9 @@
#include "core/subsurface-string.h" #include "core/subsurface-string.h"
#include "core/qthelper.h" #include "core/qthelper.h"
#include "core/profile.h" #include "core/profile.h"
#include "core/settings/qPrefAnimations.h"
#include "core/settings/qPrefTechnicalDetails.h"
#include "core/settings/qPrefPartialPressureGas.h"
#include "profile-widget/diveeventitem.h" #include "profile-widget/diveeventitem.h"
#include "profile-widget/divetextitem.h" #include "profile-widget/divetextitem.h"
#include "profile-widget/divetooltipitem.h" #include "profile-widget/divetooltipitem.h"
@ -16,7 +19,6 @@
#include "qt-models/models.h" #include "qt-models/models.h"
#include "qt-models/divepicturemodel.h" #include "qt-models/divepicturemodel.h"
#include "core/divelist.h" #include "core/divelist.h"
#include "core/subsurface-qt/SettingsObjectWrapper.h"
#ifndef SUBSURFACE_MOBILE #ifndef SUBSURFACE_MOBILE
#include "desktop-widgets/diveplanner.h" #include "desktop-widgets/diveplanner.h"
#include "desktop-widgets/simplewidgets.h" #include "desktop-widgets/simplewidgets.h"
@ -345,13 +347,12 @@ void ProfileWidget2::setupItemOnScene()
connect(qPrefPartialPressureGas::instance(), &qPrefPartialPressureGas::po2_changed, po2GasItem, &PartialPressureGasItem::setVisible); connect(qPrefPartialPressureGas::instance(), &qPrefPartialPressureGas::po2_changed, po2GasItem, &PartialPressureGasItem::setVisible);
connect(qPrefPartialPressureGas::instance(), &qPrefPartialPressureGas::pn2_changed, pn2GasItem, &PartialPressureGasItem::setVisible); connect(qPrefPartialPressureGas::instance(), &qPrefPartialPressureGas::pn2_changed, pn2GasItem, &PartialPressureGasItem::setVisible);
//WARNING: The old code was broken, I'm not sure what should trigger the visibility of those graphs, since the old code didn't triggered them
// because it was using a wrong settings. // because it was using a wrong settings.
connect(SettingsObjectWrapper::instance()->techDetails, &qPrefTechnicalDetails::show_ccr_setpoint_changed, o2SetpointGasItem, &PartialPressureGasItem::setVisible); connect(qPrefTechnicalDetails::instance(), &qPrefTechnicalDetails::show_ccr_setpoint_changed, o2SetpointGasItem, &PartialPressureGasItem::setVisible);
connect(SettingsObjectWrapper::instance()->techDetails, &qPrefTechnicalDetails::show_scr_ocpo2_changed, ocpo2GasItem, &PartialPressureGasItem::setVisible); connect(qPrefTechnicalDetails::instance(), &qPrefTechnicalDetails::show_scr_ocpo2_changed, ocpo2GasItem, &PartialPressureGasItem::setVisible);
connect(SettingsObjectWrapper::instance()->techDetails, &qPrefTechnicalDetails::show_ccr_sensors_changed, ccrsensor1GasItem, &PartialPressureGasItem::setVisible); connect(qPrefTechnicalDetails::instance(), &qPrefTechnicalDetails::show_ccr_sensors_changed, ccrsensor1GasItem, &PartialPressureGasItem::setVisible);
connect(SettingsObjectWrapper::instance()->techDetails, &qPrefTechnicalDetails::show_ccr_sensors_changed, ccrsensor2GasItem, &PartialPressureGasItem::setVisible); connect(qPrefTechnicalDetails::instance(), &qPrefTechnicalDetails::show_ccr_sensors_changed, ccrsensor2GasItem, &PartialPressureGasItem::setVisible);
connect(SettingsObjectWrapper::instance()->techDetails, &qPrefTechnicalDetails::show_ccr_sensors_changed, ccrsensor3GasItem, &PartialPressureGasItem::setVisible); connect(qPrefTechnicalDetails::instance(), &qPrefTechnicalDetails::show_ccr_sensors_changed, ccrsensor3GasItem, &PartialPressureGasItem::setVisible);
heartBeatAxis->setTextVisible(true); heartBeatAxis->setTextVisible(true);
heartBeatAxis->setLinesVisible(true); heartBeatAxis->setLinesVisible(true);
@ -595,8 +596,8 @@ void ProfileWidget2::plotDive(struct dive *d, bool force, bool doClearPictures)
// special handling for the first time we display things // special handling for the first time we display things
int animSpeedBackup = 0; int animSpeedBackup = 0;
if (firstCall && haveFilesOnCommandLine()) { if (firstCall && haveFilesOnCommandLine()) {
animSpeedBackup = prefs.animation_speed; animSpeedBackup = qPrefAnimations::animation_speed();
prefs.animation_speed = 0; qPrefAnimations::set_animation_speed(0);
firstCall = false; firstCall = false;
} }
@ -806,7 +807,7 @@ void ProfileWidget2::plotDive(struct dive *d, bool force, bool doClearPictures)
#endif #endif
diveComputerText->setText(dcText); diveComputerText->setText(dcText);
if (haveFilesOnCommandLine() && animSpeedBackup != 0) { if (haveFilesOnCommandLine() && animSpeedBackup != 0) {
prefs.animation_speed = animSpeedBackup; qPrefAnimations::set_animation_speed(animSpeedBackup);
} }
#ifndef SUBSURFACE_MOBILE #ifndef SUBSURFACE_MOBILE
@ -825,7 +826,7 @@ void ProfileWidget2::plotDive(struct dive *d, bool force, bool doClearPictures)
// so if we are calculation TTS / NDL then let's force that off. // so if we are calculation TTS / NDL then let's force that off.
#ifndef SUBSURFACE_MOBILE #ifndef SUBSURFACE_MOBILE
if (measureDuration.elapsed() > 1000 && prefs.calcndltts) { if (measureDuration.elapsed() > 1000 && prefs.calcndltts) {
SettingsObjectWrapper::instance()->techDetails->set_calcndltts(false); qPrefTechnicalDetails::set_calcndltts(false);
report_error(qPrintable(tr("Show NDL / TTS was disabled because of excessive processing time"))); report_error(qPrintable(tr("Show NDL / TTS was disabled because of excessive processing time")));
} }
#endif #endif

View file

@ -5,7 +5,7 @@
#endif #endif
#include "profile-widget/profilewidget2.h" #include "profile-widget/profilewidget2.h"
#include "core/display.h" #include "core/display.h"
#include "core/subsurface-qt/SettingsObjectWrapper.h" #include "core/settings/qPrefTechnicalDetails.h"
#include <qgraphicssceneevent.h> #include <qgraphicssceneevent.h>
@ -83,7 +83,7 @@ RulerItem2::RulerItem2() : source(new RulerNodeItem2()),
textItemBack->setFlag(QGraphicsItem::ItemIgnoresTransformations); textItemBack->setFlag(QGraphicsItem::ItemIgnoresTransformations);
setPen(QPen(QColor(Qt::black), 0.0)); setPen(QPen(QColor(Qt::black), 0.0));
#ifndef SUBSURFACE_MOBILE #ifndef SUBSURFACE_MOBILE
connect(SettingsObjectWrapper::instance()->techDetails, &qPrefTechnicalDetails::rulergraph_changed, this, &RulerItem2::settingsChanged); connect(qPrefTechnicalDetails::instance(), &qPrefTechnicalDetails::rulergraph_changed, this, &RulerItem2::settingsChanged);
#endif #endif
} }