From 84ebd1d67ab90b043cf256fd407489d0e68e2f0e Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Tue, 3 Aug 2021 15:39:25 +0200 Subject: [PATCH] profile: pass print-mode add construction of ProfileScene Setting the profile and grayscale mode of the profile via functions is from a time when the same profile widget was used for printing and the UI. It is simpler to set the mode when constructing the object and not deal with changes. To prepare for this scenario, take the flag at construction time. This still keeps the callers as-is. These will be adapted later. Logically, then the printFlag also has to be set in DiveCartesianAxis at construction time. Signed-off-by: Berthold Stoeger --- profile-widget/divecartesianaxis.cpp | 23 +++++------------------ profile-widget/divecartesianaxis.h | 7 +++---- profile-widget/profilescene.cpp | 20 ++++++++++---------- profile-widget/profilescene.h | 8 ++++---- profile-widget/profilewidget2.cpp | 10 +--------- 5 files changed, 23 insertions(+), 45 deletions(-) diff --git a/profile-widget/divecartesianaxis.cpp b/profile-widget/divecartesianaxis.cpp index bbc0f1d26..231e8f56d 100644 --- a/profile-widget/divecartesianaxis.cpp +++ b/profile-widget/divecartesianaxis.cpp @@ -26,18 +26,6 @@ void DiveCartesianAxis::setFontLabelScale(qreal scale) changed = true; } -void DiveCartesianAxis::setPrintMode() -{ - printMode = true; - // update the QPen of all lines depending on printMode - QPen newPen = gridPen(); - QColor oldColor = pen().brush().color(); - newPen.setBrush(oldColor); - setPen(newPen); - Q_FOREACH (DiveLineItem *item, lines) - item->setPen(pen()); -} - void DiveCartesianAxis::setMaximum(double maximum) { if (IS_FP_SAME(max, maximum)) @@ -59,9 +47,8 @@ void DiveCartesianAxis::setTextColor(const QColor &color) textColor = color; } -DiveCartesianAxis::DiveCartesianAxis(double fontPrintScale, ProfileScene &scene) : QObject(), - QGraphicsLineItem(), - printMode(false), +DiveCartesianAxis::DiveCartesianAxis(double fontPrintScale, bool printMode, ProfileScene &scene) : + printMode(printMode), scene(scene), orientation(LeftToRight), min(0), @@ -352,7 +339,7 @@ QColor DepthAxis::colorForValue(double) const return QColor(Qt::red); } -DepthAxis::DepthAxis(double fontPrintScale, ProfileScene &scene) : DiveCartesianAxis(fontPrintScale, scene) +DepthAxis::DepthAxis(double fontPrintScale, bool printMode, ProfileScene &scene) : DiveCartesianAxis(fontPrintScale, printMode, scene) { changed = true; } @@ -385,8 +372,8 @@ QString TemperatureAxis::textForValue(double value) const return QString::number(mkelvin_to_C((int)value)); } -PartialGasPressureAxis::PartialGasPressureAxis(const DivePlotDataModel &model, double fontPrintScale, ProfileScene &scene) : - DiveCartesianAxis(fontPrintScale, scene), +PartialGasPressureAxis::PartialGasPressureAxis(const DivePlotDataModel &model, double fontPrintScale, bool printMode, ProfileScene &scene) : + DiveCartesianAxis(fontPrintScale, printMode, scene), model(model) { } diff --git a/profile-widget/divecartesianaxis.h b/profile-widget/divecartesianaxis.h index 72b8f98ed..5834964f4 100644 --- a/profile-widget/divecartesianaxis.h +++ b/profile-widget/divecartesianaxis.h @@ -29,9 +29,8 @@ public: LeftToRight, RightToLeft }; - DiveCartesianAxis(double fontPrintScale, ProfileScene &scene); + DiveCartesianAxis(double fontPrintScale, bool printMode, ProfileScene &scene); ~DiveCartesianAxis(); - void setPrintMode(); void setMinimum(double minimum); void setMaximum(double maximum); void setTickInterval(double interval); @@ -77,7 +76,7 @@ protected: class DepthAxis : public DiveCartesianAxis { Q_OBJECT public: - DepthAxis(double fontPrintScale, ProfileScene &scene); + DepthAxis(double fontPrintScale, bool printMode, ProfileScene &scene); private: QString textForValue(double value) const override; QColor colorForValue(double value) const override; @@ -104,7 +103,7 @@ private: class PartialGasPressureAxis : public DiveCartesianAxis { Q_OBJECT public: - PartialGasPressureAxis(const DivePlotDataModel &model, double fontPrintScale, ProfileScene &scene); + PartialGasPressureAxis(const DivePlotDataModel &model, double fontPrintScale, bool printMode, ProfileScene &scene); void update(int animSpeed); private: const DivePlotDataModel &model; diff --git a/profile-widget/profilescene.cpp b/profile-widget/profilescene.cpp index f5658e95a..cc556dffa 100644 --- a/profile-widget/profilescene.cpp +++ b/profile-widget/profilescene.cpp @@ -61,22 +61,22 @@ PartialPressureGasItem *ProfileScene::createPPGas(int column, color_index_t colo return item; } -ProfileScene::ProfileScene(double fontPrintScale) : +ProfileScene::ProfileScene(double fontPrintScale, bool printMode, bool isGrayscale) : d(nullptr), dc(-1), fontPrintScale(fontPrintScale), - printMode(false), - isGrayscale(false), + printMode(printMode), + isGrayscale(isGrayscale), maxtime(-1), maxdepth(-1), dataModel(new DivePlotDataModel(this)), - profileYAxis(new DepthAxis(fontPrintScale, *this)), - gasYAxis(new PartialGasPressureAxis(*dataModel, fontPrintScale, *this)), - temperatureAxis(new TemperatureAxis(fontPrintScale, *this)), - timeAxis(new TimeAxis(fontPrintScale, *this)), - cylinderPressureAxis(new DiveCartesianAxis(fontPrintScale, *this)), - heartBeatAxis(new DiveCartesianAxis(fontPrintScale, *this)), - percentageAxis(new DiveCartesianAxis(fontPrintScale, *this)), + profileYAxis(new DepthAxis(fontPrintScale, printMode, *this)), + gasYAxis(new PartialGasPressureAxis(*dataModel, fontPrintScale, printMode, *this)), + temperatureAxis(new TemperatureAxis(fontPrintScale, printMode, *this)), + timeAxis(new TimeAxis(fontPrintScale, printMode, *this)), + cylinderPressureAxis(new DiveCartesianAxis(fontPrintScale, printMode, *this)), + heartBeatAxis(new DiveCartesianAxis(fontPrintScale, printMode, *this)), + percentageAxis(new DiveCartesianAxis(fontPrintScale, printMode, *this)), diveProfileItem(createItem(*profileYAxis, DivePlotDataModel::DEPTH, 0, fontPrintScale)), temperatureItem(createItem(*temperatureAxis, DivePlotDataModel::TEMPERATURE, 1, fontPrintScale)), meanDepthItem(createItem(*profileYAxis, DivePlotDataModel::INSTANT_MEANDEPTH, 1, fontPrintScale)), diff --git a/profile-widget/profilescene.h b/profile-widget/profilescene.h index 2da45c851..665bb56d0 100644 --- a/profile-widget/profilescene.h +++ b/profile-widget/profilescene.h @@ -1,6 +1,6 @@ - // SPDX-License-Identifier: GPL-2.0 - // Displays the dive profile. Used by the interactive profile widget - // and the printing/exporting code. +// SPDX-License-Identifier: GPL-2.0 +// Displays the dive profile. Used by the interactive profile widget +// and the printing/exporting code. #ifndef PROFILESCENE_H #define PROFILESCENE_H @@ -35,7 +35,7 @@ class TimeAxis; class ProfileScene : public QGraphicsScene { public: - ProfileScene(double fontPrintScale); + ProfileScene(double fontPrintScale, bool printMode, bool isGrayscale); ~ProfileScene(); void updateAxes(bool instant); // Update axes according to preferences diff --git a/profile-widget/profilewidget2.cpp b/profile-widget/profilewidget2.cpp index 26ee354b9..391dcbb6c 100644 --- a/profile-widget/profilewidget2.cpp +++ b/profile-widget/profilewidget2.cpp @@ -46,7 +46,7 @@ static const double thumbnailBaseZValue = 100.0; #endif ProfileWidget2::ProfileWidget2(DivePlannerPointsModel *plannerModelIn, double fontPrintScale, QWidget *parent) : QGraphicsView(parent), - profileScene(new ProfileScene(fontPrintScale)), + profileScene(new ProfileScene(fontPrintScale, false, false)), currentState(INIT), plannerModel(plannerModelIn), zoomLevel(0), @@ -821,16 +821,8 @@ void ProfileWidget2::setPrintMode(bool grayscale) resetZoom(); // set printMode for axes - profileScene->profileYAxis->setPrintMode(); - profileScene->gasYAxis->setPrintMode(); - profileScene->temperatureAxis->setPrintMode(); - profileScene->timeAxis->setPrintMode(); - profileScene->cylinderPressureAxis->setPrintMode(); profileScene->isGrayscale = grayscale; #ifndef SUBSURFACE_MOBILE - profileScene->heartBeatAxis->setPrintMode(); - profileScene->percentageAxis->setPrintMode(); - mouseFollowerHorizontal->setVisible(false); mouseFollowerVertical->setVisible(false); toolTipItem->setVisible(false);