mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
profile: unify formating of axis labels
Instead of a host of virtual functions, let the base class (DiveCartesianAxis) do the formatting of the axis labels. To do so, it needs to know how to convert the internal representation (e.g. mm) into the displayed value (e.g. feet). Moreover, this transformation has to be adapted when changing the locale-setting, therefore do it for every plot() call. The transformation itself cannot be a simple linear translation, because we have non-absolute display units, namely °C and °F. Thankfully affine transformations are enough though. Only one custom formatter remains: the time axis. It might be a good idea to remove the virtual function and do this via a flag. This is all done not so much for code simplification, but because for a general layout of the axis labels, the axis has to understand the values of the labels and not only handle them as opaque texts. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
0e9eee0a7f
commit
177df72d33
3 changed files with 63 additions and 18 deletions
|
@ -22,6 +22,7 @@ DiveCartesianAxis::DiveCartesianAxis(Position position, int integralDigits, int
|
|||
double labelScale, bool printMode, bool isGrayscale, ProfileScene &scene) :
|
||||
printMode(printMode),
|
||||
position(position),
|
||||
fractionalDigits(fractionalDigits),
|
||||
gridColor(gridColor),
|
||||
scene(scene),
|
||||
orientation(LeftToRight),
|
||||
|
@ -32,7 +33,8 @@ DiveCartesianAxis::DiveCartesianAxis(Position position, int integralDigits, int
|
|||
lineVisibility(true),
|
||||
labelScale(labelScale),
|
||||
changed(true),
|
||||
dpr(dpr)
|
||||
dpr(dpr),
|
||||
transform({1.0, 0.0})
|
||||
{
|
||||
QPen pen;
|
||||
pen.setColor(getColor(TIME_GRID, isGrayscale));
|
||||
|
@ -77,6 +79,13 @@ void DiveCartesianAxis::setOrientation(Orientation o)
|
|||
changed = true;
|
||||
}
|
||||
|
||||
void DiveCartesianAxis::setTransform(double a, double b)
|
||||
{
|
||||
transform.a = a;
|
||||
transform.b = b;
|
||||
changed = true;
|
||||
}
|
||||
|
||||
QColor DiveCartesianAxis::colorForValue(double) const
|
||||
{
|
||||
return QColor(Qt::black);
|
||||
|
@ -282,9 +291,19 @@ void DiveCartesianAxis::animateChangeLine(const QRectF &rectIn, int animSpeed)
|
|||
sizeChanged();
|
||||
}
|
||||
|
||||
double DiveCartesianAxis::Transform::to(double x) const
|
||||
{
|
||||
return a*x + b;
|
||||
}
|
||||
|
||||
double DiveCartesianAxis::Transform::from(double y) const
|
||||
{
|
||||
return (y - b) / a;
|
||||
}
|
||||
|
||||
QString DiveCartesianAxis::textForValue(double value) const
|
||||
{
|
||||
return QString("%L1").arg(value, 0, 'g', 4);
|
||||
return QStringLiteral("%L1").arg(transform.to(value), 0, 'f', fractionalDigits);
|
||||
}
|
||||
|
||||
void DiveCartesianAxis::setTickInterval(double i)
|
||||
|
@ -353,13 +372,6 @@ std::pair<double, double> DiveCartesianAxis::screenMinMax() const
|
|||
: std::make_pair(rect.top(), rect.bottom());
|
||||
}
|
||||
|
||||
QString DepthAxis::textForValue(double value) const
|
||||
{
|
||||
if (value == 0)
|
||||
return QString();
|
||||
return get_depth_string(lrint(value), false, false);
|
||||
}
|
||||
|
||||
QColor DepthAxis::colorForValue(double) const
|
||||
{
|
||||
return QColor(Qt::red);
|
||||
|
@ -389,11 +401,6 @@ void TimeAxis::updateTicks(int animSpeed)
|
|||
}
|
||||
}
|
||||
|
||||
QString TemperatureAxis::textForValue(double value) const
|
||||
{
|
||||
return QString::number(mkelvin_to_C((int)value));
|
||||
}
|
||||
|
||||
PartialGasPressureAxis::PartialGasPressureAxis(const DivePlotDataModel &model, Position position, int integralDigits, int fractionalDigits,
|
||||
color_index_t gridColor, double dpr, double labelScale, bool printMode, bool isGrayscale,
|
||||
ProfileScene &scene) :
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue