profile: make DiveCartesian axis grayscale aware

I doubt that this is necessary, but since most of the rest
of the profile code passes "isGrayscale" to "getColor()",
do the same here for consistency.

To avoid storing the isGrayscale flag, just create the pens
at construction time and store those.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2021-09-01 21:18:38 +02:00 committed by Dirk Hohndel
parent 2615ba02bb
commit a031f3444c
3 changed files with 33 additions and 32 deletions

View file

@ -11,18 +11,6 @@
static const double labelSpaceHorizontal = 2.0; // space between label and ticks
static const double labelSpaceVertical = 2.0; // space between label and ticks
QPen DiveCartesianAxis::gridPen() const
{
QPen pen;
pen.setColor(getColor(TIME_GRID));
/* cosmetic width() == 0 for lines in printMode
* having setCosmetic(true) and width() > 0 does not work when
* printing on OSX and Linux */
pen.setWidth(DiveCartesianAxis::printMode ? 0 : 2);
pen.setCosmetic(true);
return pen;
}
void DiveCartesianAxis::setFontLabelScale(qreal scale)
{
labelScale = scale;
@ -45,7 +33,8 @@ void DiveCartesianAxis::setMinimum(double minimum)
changed = true;
}
DiveCartesianAxis::DiveCartesianAxis(Position position, color_index_t gridColor, double dpr, bool printMode, ProfileScene &scene) :
DiveCartesianAxis::DiveCartesianAxis(Position position, color_index_t gridColor, double dpr,
bool printMode, bool isGrayscale, ProfileScene &scene) :
printMode(printMode),
position(position),
gridColor(gridColor),
@ -60,7 +49,17 @@ DiveCartesianAxis::DiveCartesianAxis(Position position, color_index_t gridColor,
changed(true),
dpr(dpr)
{
setPen(gridPen());
QPen pen;
pen.setColor(getColor(TIME_GRID, isGrayscale));
/* cosmetic width() == 0 for lines in printMode
* having setCosmetic(true) and width() > 0 does not work when
* printing on OSX and Linux */
pen.setWidth(DiveCartesianAxis::printMode ? 0 : 2);
pen.setCosmetic(true);
setPen(pen);
pen.setBrush(getColor(gridColor, isGrayscale));
gridPen = pen;
}
DiveCartesianAxis::~DiveCartesianAxis()
@ -241,9 +240,7 @@ void DiveCartesianAxis::updateTicks(int animSpeed)
childPos = begin - i * stepSize;
}
DiveLineItem *line = new DiveLineItem(this);
QPen pen = gridPen();
pen.setBrush(getColor(gridColor));
line->setPen(pen);
line->setPen(gridPen);
line->setZValue(0);
lines.push_back(line);
if (position == Position::Bottom) {
@ -372,8 +369,9 @@ QColor DepthAxis::colorForValue(double) const
return QColor(Qt::red);
}
DepthAxis::DepthAxis(Position position, color_index_t gridColor, double dpr, bool printMode, ProfileScene &scene) :
DiveCartesianAxis(position, gridColor, dpr, printMode, scene)
DepthAxis::DepthAxis(Position position, color_index_t gridColor, double dpr,
bool printMode, bool isGrayscale, ProfileScene &scene) :
DiveCartesianAxis(position, gridColor, dpr, printMode, isGrayscale, scene)
{
changed = true;
}
@ -408,8 +406,8 @@ QString TemperatureAxis::textForValue(double value) const
}
PartialGasPressureAxis::PartialGasPressureAxis(const DivePlotDataModel &model, Position position, color_index_t gridColor,
double dpr, bool printMode, ProfileScene &scene) :
DiveCartesianAxis(position, gridColor, dpr, printMode, scene),
double dpr, bool printMode, bool isGrayscale, ProfileScene &scene) :
DiveCartesianAxis(position, gridColor, dpr, printMode, isGrayscale, scene),
model(model)
{
}

View file

@ -4,6 +4,7 @@
#include <QObject>
#include <QGraphicsLineItem>
#include <QPen>
#include "core/color.h"
#include "core/units.h"
@ -21,7 +22,6 @@ class DiveCartesianAxis : public QObject, public QGraphicsLineItem {
Q_PROPERTY(qreal y WRITE setY READ y)
private:
bool printMode;
QPen gridPen() const;
public:
enum Orientation {
TopToBottom,
@ -32,7 +32,8 @@ public:
enum class Position {
Left, Right, Bottom
};
DiveCartesianAxis(Position position, color_index_t gridColor, double dpr, bool printMode, ProfileScene &scene);
DiveCartesianAxis(Position position, color_index_t gridColor, double dpr,
bool printMode, bool isGrayscale, ProfileScene &scene);
~DiveCartesianAxis();
void setMinimum(double minimum);
void setMaximum(double maximum);
@ -58,6 +59,7 @@ signals:
protected:
Position position;
QRectF rect; // Rectangle to fill with grid lines
QPen gridPen;
color_index_t gridColor;
ProfileScene &scene;
virtual QString textForValue(double value) const;
@ -79,7 +81,8 @@ protected:
class DepthAxis : public DiveCartesianAxis {
Q_OBJECT
public:
DepthAxis(Position position, color_index_t gridColor, double dpr, bool printMode, ProfileScene &scene);
DepthAxis(Position position, color_index_t gridColor, double dpr,
bool printMode, bool isGrayscale, ProfileScene &scene);
private:
QString textForValue(double value) const override;
QColor colorForValue(double value) const override;
@ -107,7 +110,7 @@ class PartialGasPressureAxis : public DiveCartesianAxis {
Q_OBJECT
public:
PartialGasPressureAxis(const DivePlotDataModel &model, Position position, color_index_t gridColor,
double dpr, bool printMode, ProfileScene &scene);
double dpr, bool printMode, bool isGrayscale, ProfileScene &scene);
void update(int animSpeed);
double width() const;
private:

View file

@ -47,13 +47,13 @@ ProfileScene::ProfileScene(double dpr, bool printMode, bool isGrayscale) :
maxtime(-1),
maxdepth(-1),
dataModel(new DivePlotDataModel(this)),
profileYAxis(new DepthAxis(DiveCartesianAxis::Position::Left, TIME_GRID, dpr, printMode, *this)),
gasYAxis(new PartialGasPressureAxis(*dataModel, DiveCartesianAxis::Position::Right, TIME_GRID, dpr, printMode, *this)),
temperatureAxis(new TemperatureAxis(DiveCartesianAxis::Position::Right, TIME_GRID, dpr, printMode, *this)),
timeAxis(new TimeAxis(DiveCartesianAxis::Position::Bottom, TIME_GRID, dpr, printMode, *this)),
cylinderPressureAxis(new DiveCartesianAxis(DiveCartesianAxis::Position::Right, TIME_GRID, dpr, printMode, *this)),
heartBeatAxis(new DiveCartesianAxis(DiveCartesianAxis::Position::Left, HR_AXIS, dpr, printMode, *this)),
percentageAxis(new DiveCartesianAxis(DiveCartesianAxis::Position::Right, TIME_GRID, dpr, printMode, *this)),
profileYAxis(new DepthAxis(DiveCartesianAxis::Position::Left, TIME_GRID, dpr, printMode, isGrayscale, *this)),
gasYAxis(new PartialGasPressureAxis(*dataModel, DiveCartesianAxis::Position::Right, TIME_GRID, dpr, printMode, isGrayscale, *this)),
temperatureAxis(new TemperatureAxis(DiveCartesianAxis::Position::Right, TIME_GRID, dpr, printMode, isGrayscale, *this)),
timeAxis(new TimeAxis(DiveCartesianAxis::Position::Bottom, TIME_GRID, dpr, printMode, isGrayscale, *this)),
cylinderPressureAxis(new DiveCartesianAxis(DiveCartesianAxis::Position::Right, TIME_GRID, dpr, printMode, isGrayscale, *this)),
heartBeatAxis(new DiveCartesianAxis(DiveCartesianAxis::Position::Left, HR_AXIS, dpr, printMode, isGrayscale, *this)),
percentageAxis(new DiveCartesianAxis(DiveCartesianAxis::Position::Right, TIME_GRID, dpr, printMode, isGrayscale, *this)),
diveProfileItem(createItem<DiveProfileItem>(*profileYAxis, DivePlotDataModel::DEPTH, 0, dpr)),
temperatureItem(createItem<DiveTemperatureItem>(*temperatureAxis, DivePlotDataModel::TEMPERATURE, 1, dpr)),
meanDepthItem(createItem<DiveMeanDepthItem>(*profileYAxis, DivePlotDataModel::INSTANT_MEANDEPTH, 1, dpr)),