profile: set textColor in constructor of DiveCartesianAxis

There were virtual functions to calculate the label colors
based on the value of the label. However, these functions
only returned constant values. Therefore, just set these
in the constructors.

Thuse, a few virtual functions and derived classes can be
removed.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2021-10-03 22:10:00 +02:00 committed by Dirk Hohndel
parent ea59e5cf7a
commit 3a79f3e78a
4 changed files with 16 additions and 57 deletions

View file

@ -19,11 +19,12 @@ void DiveCartesianAxis::setBounds(double minimum, double maximum)
}
DiveCartesianAxis::DiveCartesianAxis(Position position, int integralDigits, int fractionalDigits, color_index_t gridColor,
bool textVisible, bool linesVisible,
QColor textColor, bool textVisible, bool linesVisible,
double dpr, double labelScale, bool printMode, bool isGrayscale, ProfileScene &scene) :
printMode(printMode),
position(position),
fractionalDigits(fractionalDigits),
textColor(textColor),
scene(scene),
orientation(LeftToRight),
min(0),
@ -85,11 +86,6 @@ void DiveCartesianAxis::setTransform(double a, double b)
changed = true;
}
QColor DiveCartesianAxis::colorForValue(double) const
{
return QColor(Qt::black);
}
template <typename T>
void emptyList(QList<T *> &list, int steps, int speed)
{
@ -218,7 +214,7 @@ void DiveCartesianAxis::updateLabels(int numTicks, double firstPosScreen, double
firstPosScreen + i * stepScreen :
firstPosScreen - i * stepScreen;
labels[i]->set(textForValue(firstValue), colorForValue(firstValue));
labels[i]->set(textForValue(firstValue), textColor);
switch (position) {
default:
case Position::Bottom:
@ -245,7 +241,7 @@ void DiveCartesianAxis::updateLabels(int numTicks, double firstPosScreen, double
position == Position::Left ? Qt::AlignVCenter | Qt::AlignLeft:
Qt::AlignVCenter | Qt::AlignRight;
DiveTextItem *label = new DiveTextItem(dpr, labelScale, alignFlags, this);
label->set(textForValue(firstValue), colorForValue(firstValue));
label->set(textForValue(firstValue), textColor);
label->setZValue(1);
labels.push_back(label);
switch (position) {
@ -411,13 +407,3 @@ std::pair<double, double> DiveCartesianAxis::screenMinMax() const
return position == Position::Bottom ? std::make_pair(rect.left(), rect.right())
: std::make_pair(rect.top(), rect.bottom());
}
QColor DepthAxis::colorForValue(double) const
{
return QColor(Qt::red);
}
QColor TimeAxis::colorForValue(double) const
{
return QColor(Qt::blue);
}

View file

@ -34,7 +34,7 @@ public:
};
DiveCartesianAxis(Position position, int integralDigits, int fractionalDigits, color_index_t gridColor,
bool textVisible, bool linesVisible,
QColor textColor, bool textVisible, bool linesVisible,
double dpr, double labelScale, bool printMode, bool isGrayscale, ProfileScene &scene);
~DiveCartesianAxis();
void setBounds(double min, double max);
@ -57,9 +57,9 @@ private:
int fractionalDigits;
QRectF rect; // Rectangle to fill with grid lines
QPen gridPen;
QColor textColor;
ProfileScene &scene;
QString textForValue(double value) const;
virtual QColor colorForValue(double value) const;
Orientation orientation;
QList<DiveTextItem *> labels;
QList<DiveLineItem *> lines;
@ -86,26 +86,4 @@ private:
void updateLines(int numTicks, double firstPosScreen, double stepScreen, int animSpeed);
};
class DepthAxis : public DiveCartesianAxis {
Q_OBJECT
public:
using DiveCartesianAxis::DiveCartesianAxis;
private:
QColor colorForValue(double value) const override;
};
class TimeAxis : public DiveCartesianAxis {
Q_OBJECT
public:
using DiveCartesianAxis::DiveCartesianAxis;
private:
QColor colorForValue(double value) const override;
};
class TemperatureAxis : public DiveCartesianAxis {
Q_OBJECT
public:
using DiveCartesianAxis::DiveCartesianAxis;
};
#endif // DIVECARTESIANAXIS_H

View file

@ -47,19 +47,19 @@ ProfileScene::ProfileScene(double dpr, bool printMode, bool isGrayscale) :
maxtime(-1),
maxdepth(-1),
dataModel(new DivePlotDataModel(this)),
profileYAxis(new DepthAxis(DiveCartesianAxis::Position::Left, 3, 0, TIME_GRID, true, true,
profileYAxis(new DiveCartesianAxis(DiveCartesianAxis::Position::Left, 3, 0, TIME_GRID, Qt::red, true, true,
dpr, 1.0, printMode, isGrayscale, *this)),
gasYAxis(new DiveCartesianAxis(DiveCartesianAxis::Position::Right, 1, 2, TIME_GRID, true, true,
gasYAxis(new DiveCartesianAxis(DiveCartesianAxis::Position::Right, 1, 2, TIME_GRID, Qt::black, true, true,
dpr, 0.7, printMode, isGrayscale, *this)),
temperatureAxis(new TemperatureAxis(DiveCartesianAxis::Position::Right, 3, 0, TIME_GRID, false, false,
temperatureAxis(new DiveCartesianAxis(DiveCartesianAxis::Position::Right, 3, 0, TIME_GRID, Qt::black, false, false,
dpr, 1.0, printMode, isGrayscale, *this)),
timeAxis(new TimeAxis(DiveCartesianAxis::Position::Bottom, 2, 2, TIME_GRID, true, true,
timeAxis(new DiveCartesianAxis(DiveCartesianAxis::Position::Bottom, 2, 2, TIME_GRID, Qt::blue, true, true,
dpr, 1.0, printMode, isGrayscale, *this)),
cylinderPressureAxis(new DiveCartesianAxis(DiveCartesianAxis::Position::Right, 4, 0, TIME_GRID, false, false,
cylinderPressureAxis(new DiveCartesianAxis(DiveCartesianAxis::Position::Right, 4, 0, TIME_GRID, Qt::black, false, false,
dpr, 1.0, printMode, isGrayscale, *this)),
heartBeatAxis(new DiveCartesianAxis(DiveCartesianAxis::Position::Left, 3, 0, HR_AXIS, true, true,
heartBeatAxis(new DiveCartesianAxis(DiveCartesianAxis::Position::Left, 3, 0, HR_AXIS, Qt::black, true, true,
dpr, 0.7, printMode, isGrayscale, *this)),
percentageAxis(new DiveCartesianAxis(DiveCartesianAxis::Position::Right, 2, 0, TIME_GRID, false, false,
percentageAxis(new DiveCartesianAxis(DiveCartesianAxis::Position::Right, 2, 0, TIME_GRID, Qt::black, false, false,
dpr, 0.7, printMode, isGrayscale, *this)),
diveProfileItem(createItem<DiveProfileItem>(*profileYAxis, DivePlotDataModel::DEPTH, 0, dpr)),
temperatureItem(createItem<DiveTemperatureItem>(*temperatureAxis, DivePlotDataModel::TEMPERATURE, 1, dpr)),

View file

@ -15,8 +15,6 @@ class DivePlannerPointsModel;
class DivePlotDataModel;
class AbstractProfilePolygonItem;
class DepthAxis;
class DiveCartesianAxis;
class DiveCalculatedCeiling;
class DiveCalculatedTissue;
class DiveCartesianAxis;
@ -30,11 +28,8 @@ class DiveProfileItem;
class DiveReportedCeiling;
class DiveTemperatureItem;
class DiveTextItem;
class PartialGasPressureAxis;
class PartialPressureGasItem;
class TankItem;
class TemperatureAxis;
class TimeAxis;
class ProfileScene : public QGraphicsScene {
public:
@ -71,10 +66,10 @@ private:
DivePlotDataModel *dataModel;
struct plot_info plotInfo;
DepthAxis *profileYAxis;
DiveCartesianAxis *profileYAxis;
DiveCartesianAxis *gasYAxis;
TemperatureAxis *temperatureAxis;
TimeAxis *timeAxis;
DiveCartesianAxis *temperatureAxis;
DiveCartesianAxis *timeAxis;
DiveCartesianAxis *cylinderPressureAxis;
DiveCartesianAxis *heartBeatAxis;
DiveCartesianAxis *percentageAxis;