2017-04-27 18:26:36 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2016-04-05 05:02:03 +00:00
|
|
|
#include "profile-widget/divecartesianaxis.h"
|
|
|
|
#include "profile-widget/divetextitem.h"
|
2018-06-03 20:15:19 +00:00
|
|
|
#include "core/qthelper.h"
|
2018-05-11 15:25:41 +00:00
|
|
|
#include "core/subsurface-string.h"
|
2016-04-05 05:02:03 +00:00
|
|
|
#include "qt-models/diveplotdatamodel.h"
|
|
|
|
#include "profile-widget/animationfunctions.h"
|
|
|
|
#include "profile-widget/divelineitem.h"
|
2021-06-28 18:29:46 +00:00
|
|
|
#include "profile-widget/profilescene.h"
|
2014-01-14 18:20:15 +00:00
|
|
|
|
2021-08-28 12:25:04 +00:00
|
|
|
static const double labelSpaceHorizontal = 2.0; // space between label and ticks
|
|
|
|
static const double labelSpaceVertical = 2.0; // space between label and ticks
|
2021-08-11 08:57:42 +00:00
|
|
|
|
2021-09-11 19:57:49 +00:00
|
|
|
void DiveCartesianAxis::setBounds(double minimum, double maximum)
|
2014-01-14 18:20:15 +00:00
|
|
|
{
|
2021-09-11 19:57:49 +00:00
|
|
|
changed = !IS_FP_SAME(max, maximum) || !IS_FP_SAME(min, minimum);
|
2014-01-14 18:20:15 +00:00
|
|
|
min = minimum;
|
2021-09-11 19:57:49 +00:00
|
|
|
max = maximum;
|
2014-01-14 18:20:15 +00:00
|
|
|
}
|
|
|
|
|
2021-09-01 19:18:38 +00:00
|
|
|
DiveCartesianAxis::DiveCartesianAxis(Position position, color_index_t gridColor, double dpr,
|
2021-09-11 20:14:45 +00:00
|
|
|
double labelScale, bool printMode, bool isGrayscale, ProfileScene &scene) :
|
2021-08-03 13:39:25 +00:00
|
|
|
printMode(printMode),
|
2021-08-28 18:12:36 +00:00
|
|
|
position(position),
|
|
|
|
gridColor(gridColor),
|
2021-06-28 18:29:46 +00:00
|
|
|
scene(scene),
|
2014-02-09 17:37:40 +00:00
|
|
|
orientation(LeftToRight),
|
|
|
|
min(0),
|
|
|
|
max(0),
|
|
|
|
interval(1),
|
2014-02-15 23:55:31 +00:00
|
|
|
textVisibility(true),
|
2014-02-17 22:39:03 +00:00
|
|
|
lineVisibility(true),
|
2021-09-11 20:14:45 +00:00
|
|
|
labelScale(labelScale),
|
2021-06-03 15:19:38 +00:00
|
|
|
changed(true),
|
2021-08-09 14:48:08 +00:00
|
|
|
dpr(dpr)
|
2014-01-14 18:20:15 +00:00
|
|
|
{
|
2021-09-01 19:18:38 +00:00
|
|
|
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;
|
2014-01-14 18:20:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DiveCartesianAxis::~DiveCartesianAxis()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-01-16 21:28:33 +00:00
|
|
|
void DiveCartesianAxis::setOrientation(Orientation o)
|
2014-01-14 18:20:15 +00:00
|
|
|
{
|
|
|
|
orientation = o;
|
2014-05-26 21:01:38 +00:00
|
|
|
changed = true;
|
2014-01-14 18:20:15 +00:00
|
|
|
}
|
|
|
|
|
2020-12-20 12:01:21 +00:00
|
|
|
QColor DiveCartesianAxis::colorForValue(double) const
|
2014-01-19 22:14:48 +00:00
|
|
|
{
|
|
|
|
return QColor(Qt::black);
|
|
|
|
}
|
|
|
|
|
2014-02-12 16:24:19 +00:00
|
|
|
void DiveCartesianAxis::setTextVisible(bool arg1)
|
|
|
|
{
|
2014-02-28 04:09:57 +00:00
|
|
|
if (textVisibility == arg1) {
|
2014-02-12 16:24:19 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
textVisibility = arg1;
|
2014-05-22 18:40:22 +00:00
|
|
|
Q_FOREACH (DiveTextItem *item, labels) {
|
2014-02-12 16:24:19 +00:00
|
|
|
item->setVisible(textVisibility);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-16 00:54:41 +00:00
|
|
|
void DiveCartesianAxis::setLinesVisible(bool arg1)
|
|
|
|
{
|
2014-02-28 04:09:57 +00:00
|
|
|
if (lineVisibility == arg1) {
|
2014-02-16 00:54:41 +00:00
|
|
|
return;
|
|
|
|
}
|
2014-02-28 04:09:57 +00:00
|
|
|
lineVisibility = arg1;
|
2014-05-22 18:40:22 +00:00
|
|
|
Q_FOREACH (DiveLineItem *item, lines) {
|
2014-02-28 04:09:57 +00:00
|
|
|
item->setVisible(lineVisibility);
|
2014-02-16 00:54:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
template <typename T>
|
2019-07-10 20:40:06 +00:00
|
|
|
void emptyList(QList<T *> &list, int steps, int speed)
|
2014-02-28 04:09:57 +00:00
|
|
|
{
|
2018-05-19 05:37:58 +00:00
|
|
|
while (list.size() > steps) {
|
|
|
|
T *removedItem = list.takeLast();
|
2019-07-10 20:40:06 +00:00
|
|
|
Animations::animDelete(removedItem, speed);
|
2014-02-15 23:55:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-11 08:57:42 +00:00
|
|
|
double DiveCartesianAxis::textWidth(const QString &s) const
|
|
|
|
{
|
|
|
|
QFont fnt = DiveTextItem::getFont(dpr, labelScale);
|
|
|
|
QFontMetrics fm(fnt);
|
2021-08-28 12:25:04 +00:00
|
|
|
return fm.size(Qt::TextSingleLine, s).width() + labelSpaceHorizontal * dpr;
|
2021-08-11 08:57:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
double DiveCartesianAxis::width() const
|
|
|
|
{
|
|
|
|
return textWidth("999");
|
|
|
|
}
|
|
|
|
|
2021-08-28 12:25:04 +00:00
|
|
|
double DiveCartesianAxis::height() const
|
|
|
|
{
|
|
|
|
QFont fnt = DiveTextItem::getFont(dpr, labelScale);
|
|
|
|
QFontMetrics fm(fnt);
|
|
|
|
return fm.height() + labelSpaceVertical * dpr;
|
|
|
|
}
|
|
|
|
|
2021-08-28 18:15:57 +00:00
|
|
|
void DiveCartesianAxis::updateTicks(int animSpeed)
|
2014-01-14 18:20:15 +00:00
|
|
|
{
|
2021-06-28 18:29:46 +00:00
|
|
|
if (!changed && !printMode)
|
2014-01-25 15:25:03 +00:00
|
|
|
return;
|
2014-01-14 18:20:15 +00:00
|
|
|
QLineF m = line();
|
2018-05-19 05:37:58 +00:00
|
|
|
double stepsInRange = (max - min) / interval;
|
|
|
|
int steps = (int)stepsInRange;
|
2014-02-16 00:15:45 +00:00
|
|
|
double currValueText = min;
|
|
|
|
double currValueLine = min;
|
2014-01-14 18:20:15 +00:00
|
|
|
|
2014-01-27 17:14:42 +00:00
|
|
|
if (steps < 1)
|
|
|
|
return;
|
2014-01-27 19:09:08 +00:00
|
|
|
|
2021-08-03 08:32:08 +00:00
|
|
|
emptyList(labels, steps, animSpeed);
|
|
|
|
emptyList(lines, steps, animSpeed);
|
2014-02-15 23:55:31 +00:00
|
|
|
|
2021-08-28 21:36:09 +00:00
|
|
|
// Move the remaining grid lines / labels to their correct positions
|
2018-05-19 05:37:58 +00:00
|
|
|
// regarding the possible new values for the axis
|
2014-01-16 21:28:33 +00:00
|
|
|
qreal begin, stepSize;
|
|
|
|
if (orientation == TopToBottom) {
|
|
|
|
begin = m.y1();
|
|
|
|
stepSize = (m.y2() - m.y1());
|
|
|
|
} else if (orientation == BottomToTop) {
|
|
|
|
begin = m.y2();
|
|
|
|
stepSize = (m.y2() - m.y1());
|
2014-02-28 04:09:57 +00:00
|
|
|
} else if (orientation == LeftToRight) {
|
2014-01-16 21:28:33 +00:00
|
|
|
begin = m.x1();
|
|
|
|
stepSize = (m.x2() - m.x1());
|
2014-06-11 16:37:12 +00:00
|
|
|
} else /* if (orientation == RightToLeft) */ {
|
2014-01-16 21:28:33 +00:00
|
|
|
begin = m.x2();
|
|
|
|
stepSize = (m.x2() - m.x1());
|
|
|
|
}
|
2018-05-19 05:37:58 +00:00
|
|
|
stepSize /= stepsInRange;
|
2014-01-16 21:28:33 +00:00
|
|
|
|
2014-02-16 00:15:45 +00:00
|
|
|
for (int i = 0, count = labels.size(); i < count; i++, currValueText += interval) {
|
2021-08-28 21:36:09 +00:00
|
|
|
double childPos = (orientation == TopToBottom || orientation == LeftToRight) ?
|
2014-05-22 18:40:22 +00:00
|
|
|
begin + i * stepSize :
|
|
|
|
begin - i * stepSize;
|
2014-01-27 19:09:08 +00:00
|
|
|
|
2021-08-13 07:56:46 +00:00
|
|
|
labels[i]->set(textForValue(currValueText), colorForValue(currValueText));
|
2021-08-28 21:36:09 +00:00
|
|
|
switch (position) {
|
|
|
|
default:
|
|
|
|
case Position::Bottom:
|
|
|
|
Animations::moveTo(labels[i], animSpeed, childPos, rect.bottom() + labelSpaceVertical * dpr);
|
|
|
|
break;
|
|
|
|
case Position::Left:
|
|
|
|
Animations::moveTo(labels[i], animSpeed, rect.left() - labelSpaceHorizontal * dpr, childPos);
|
|
|
|
break;
|
|
|
|
case Position::Right:
|
|
|
|
Animations::moveTo(labels[i], animSpeed, rect.right() + labelSpaceHorizontal * dpr, childPos);
|
|
|
|
break;
|
2014-01-14 18:24:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-16 00:15:45 +00:00
|
|
|
for (int i = 0, count = lines.size(); i < count; i++, currValueLine += interval) {
|
2021-08-28 21:36:09 +00:00
|
|
|
double childPos = (orientation == TopToBottom || orientation == LeftToRight) ?
|
2014-05-22 18:40:22 +00:00
|
|
|
begin + i * stepSize :
|
|
|
|
begin - i * stepSize;
|
2014-02-16 00:15:45 +00:00
|
|
|
|
2021-08-28 21:36:09 +00:00
|
|
|
if (position == Position::Bottom) {
|
|
|
|
// Fix size in case the scene changed
|
|
|
|
QLineF old = lines[i]->line();
|
|
|
|
lines[i]->setLine(old.x1(), old.y1(), old.x1(), old.y1() + rect.height());
|
|
|
|
Animations::moveTo(lines[i], animSpeed, childPos, rect.top());
|
2014-02-16 00:15:45 +00:00
|
|
|
} else {
|
2021-08-28 21:36:09 +00:00
|
|
|
// Fix size in case the scene changed
|
|
|
|
QLineF old = lines[i]->line();
|
|
|
|
lines[i]->setLine(old.x1(), old.y1(), old.x1() + rect.width(), old.y1());
|
|
|
|
Animations::moveTo(lines[i], animSpeed, rect.left(), childPos);
|
2014-02-16 00:15:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-28 21:36:09 +00:00
|
|
|
// Add the rest of the needed labels.
|
2014-02-28 04:09:57 +00:00
|
|
|
for (int i = labels.size(); i < steps; i++, currValueText += interval) {
|
2021-08-28 21:36:09 +00:00
|
|
|
double childPos;
|
2014-01-16 21:28:33 +00:00
|
|
|
if (orientation == TopToBottom || orientation == LeftToRight) {
|
2014-02-28 04:09:57 +00:00
|
|
|
childPos = begin + i * stepSize;
|
2014-01-16 21:28:33 +00:00
|
|
|
} else {
|
|
|
|
childPos = begin - i * stepSize;
|
|
|
|
}
|
2021-08-28 21:36:09 +00:00
|
|
|
int alignFlags = position == Position::Bottom ? Qt::AlignTop | Qt::AlignHCenter :
|
|
|
|
position == Position::Left ? Qt::AlignVCenter | Qt::AlignLeft:
|
|
|
|
Qt::AlignVCenter | Qt::AlignRight;
|
2021-08-12 20:57:57 +00:00
|
|
|
DiveTextItem *label = new DiveTextItem(dpr, labelScale, alignFlags, this);
|
2021-08-13 07:56:46 +00:00
|
|
|
label->set(textForValue(currValueText), colorForValue(currValueText));
|
2014-02-16 00:49:30 +00:00
|
|
|
label->setZValue(1);
|
2014-02-07 20:08:29 +00:00
|
|
|
labels.push_back(label);
|
2021-08-28 21:36:09 +00:00
|
|
|
switch (position) {
|
|
|
|
default:
|
|
|
|
case Position::Bottom:
|
|
|
|
label->setPos(scene.sceneRect().width() + 10, rect.bottom() + labelSpaceVertical * dpr); // position it outside of the scene;
|
|
|
|
Animations::moveTo(labels[i], animSpeed, childPos, rect.bottom() + labelSpaceVertical * dpr);
|
|
|
|
break;
|
|
|
|
case Position::Left:
|
|
|
|
label->setPos(rect.left() - labelSpaceHorizontal * dpr, scene.sceneRect().height() + 10);
|
|
|
|
Animations::moveTo(labels[i], animSpeed, rect.left() - labelSpaceHorizontal * dpr, childPos);
|
|
|
|
break;
|
|
|
|
case Position::Right:
|
|
|
|
label->setPos(rect.right() + labelSpaceHorizontal * dpr, scene.sceneRect().height() + 10);
|
|
|
|
Animations::moveTo(labels[i], animSpeed, rect.right() + labelSpaceHorizontal * dpr, childPos);
|
|
|
|
break;
|
2014-01-14 18:28:07 +00:00
|
|
|
}
|
|
|
|
}
|
2014-02-12 16:24:19 +00:00
|
|
|
|
2021-08-28 21:36:09 +00:00
|
|
|
// Add the rest of the needed grid lines.
|
2014-02-28 04:09:57 +00:00
|
|
|
for (int i = lines.size(); i < steps; i++, currValueText += interval) {
|
2021-08-28 21:36:09 +00:00
|
|
|
double childPos;
|
2014-02-16 00:43:27 +00:00
|
|
|
if (orientation == TopToBottom || orientation == LeftToRight) {
|
2014-02-28 04:09:57 +00:00
|
|
|
childPos = begin + i * stepSize;
|
2014-02-16 00:43:27 +00:00
|
|
|
} else {
|
|
|
|
childPos = begin - i * stepSize;
|
|
|
|
}
|
|
|
|
DiveLineItem *line = new DiveLineItem(this);
|
2021-09-01 19:18:38 +00:00
|
|
|
line->setPen(gridPen);
|
2014-02-16 00:49:30 +00:00
|
|
|
line->setZValue(0);
|
2014-02-16 00:43:27 +00:00
|
|
|
lines.push_back(line);
|
2021-08-28 21:36:09 +00:00
|
|
|
if (position == Position::Bottom) {
|
|
|
|
line->setLine(0.0, 0.0, 0.0, rect.height());
|
|
|
|
line->setPos(scene.sceneRect().width() + 10, rect.top()); // position it outside of the scene);
|
|
|
|
Animations::moveTo(line, animSpeed, childPos, rect.top());
|
2014-02-16 00:43:27 +00:00
|
|
|
} else {
|
2021-08-28 21:36:09 +00:00
|
|
|
line->setLine(0.0, 0.0, rect.width(), 0.0);
|
|
|
|
line->setPos(rect.left(), scene.sceneRect().height() + 10);
|
|
|
|
Animations::moveTo(line, animSpeed, rect.left(), childPos);
|
2014-02-16 00:43:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-22 18:40:22 +00:00
|
|
|
Q_FOREACH (DiveTextItem *item, labels)
|
2014-03-03 21:25:55 +00:00
|
|
|
item->setVisible(textVisibility);
|
2014-05-22 18:40:22 +00:00
|
|
|
Q_FOREACH (DiveLineItem *item, lines)
|
2014-03-03 21:25:55 +00:00
|
|
|
item->setVisible(lineVisibility);
|
2014-05-26 21:01:38 +00:00
|
|
|
changed = false;
|
2014-01-14 18:20:15 +00:00
|
|
|
}
|
|
|
|
|
2014-07-29 21:48:17 +00:00
|
|
|
void DiveCartesianAxis::setLine(const QLineF &line)
|
|
|
|
{
|
|
|
|
QGraphicsLineItem::setLine(line);
|
|
|
|
changed = true;
|
|
|
|
}
|
|
|
|
|
2021-08-28 21:36:09 +00:00
|
|
|
void DiveCartesianAxis::animateChangeLine(const QRectF &rectIn, int animSpeed)
|
|
|
|
{
|
|
|
|
rect = rectIn;
|
|
|
|
switch (position) {
|
|
|
|
case Position::Left:
|
|
|
|
setLine(QLineF(rect.topLeft(), rect.bottomLeft()));
|
|
|
|
break;
|
|
|
|
case Position::Right:
|
|
|
|
setLine(QLineF(rect.topRight(), rect.bottomRight()));
|
|
|
|
break;
|
|
|
|
case Position::Bottom:
|
|
|
|
default:
|
|
|
|
setLine(QLineF(rect.bottomLeft(), rect.bottomRight()));
|
|
|
|
break;
|
|
|
|
}
|
2021-08-03 08:32:08 +00:00
|
|
|
updateTicks(animSpeed);
|
2014-01-22 19:10:18 +00:00
|
|
|
sizeChanged();
|
|
|
|
}
|
|
|
|
|
2020-12-20 12:01:21 +00:00
|
|
|
QString DiveCartesianAxis::textForValue(double value) const
|
2014-01-14 18:20:15 +00:00
|
|
|
{
|
2018-02-19 20:55:18 +00:00
|
|
|
return QString("%L1").arg(value, 0, 'g', 4);
|
2014-01-14 18:20:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DiveCartesianAxis::setTickInterval(double i)
|
|
|
|
{
|
|
|
|
interval = i;
|
|
|
|
}
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
qreal DiveCartesianAxis::valueAt(const QPointF &p) const
|
2014-01-14 18:20:15 +00:00
|
|
|
{
|
2019-08-08 09:30:41 +00:00
|
|
|
double fraction;
|
2014-01-14 18:20:15 +00:00
|
|
|
QLineF m = line();
|
2014-02-11 20:05:33 +00:00
|
|
|
QPointF relativePosition = p;
|
|
|
|
relativePosition -= pos(); // normalize p based on the axis' offset on screen
|
|
|
|
|
2019-08-08 09:30:41 +00:00
|
|
|
if (orientation == LeftToRight || orientation == RightToLeft)
|
|
|
|
fraction = (relativePosition.x() - m.x1()) / (m.x2() - m.x1());
|
|
|
|
else
|
|
|
|
fraction = (relativePosition.y() - m.y1()) / (m.y2() - m.y1());
|
|
|
|
|
|
|
|
if (orientation == RightToLeft || orientation == BottomToTop)
|
|
|
|
fraction = 1 - fraction;
|
|
|
|
return fraction * (max - min) + min;
|
2014-01-14 18:20:15 +00:00
|
|
|
}
|
|
|
|
|
2020-12-20 12:01:21 +00:00
|
|
|
qreal DiveCartesianAxis::posAtValue(qreal value) const
|
2014-01-14 18:20:15 +00:00
|
|
|
{
|
|
|
|
QLineF m = line();
|
|
|
|
QPointF p = pos();
|
|
|
|
|
|
|
|
double size = max - min;
|
2014-01-16 23:30:47 +00:00
|
|
|
// unused for now:
|
|
|
|
// double distanceFromOrigin = value - min;
|
2014-02-28 04:09:57 +00:00
|
|
|
double percent = IS_FP_SAME(min, max) ? 0.0 : (value - min) / size;
|
2014-01-21 20:43:07 +00:00
|
|
|
|
2014-01-16 21:28:33 +00:00
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
double realSize = orientation == LeftToRight || orientation == RightToLeft ?
|
2014-05-22 18:40:22 +00:00
|
|
|
m.x2() - m.x1() :
|
|
|
|
m.y2() - m.y1();
|
2014-01-16 21:28:33 +00:00
|
|
|
|
|
|
|
// Inverted axis, just invert the percentage.
|
2014-01-16 23:30:47 +00:00
|
|
|
if (orientation == RightToLeft || orientation == BottomToTop)
|
2014-01-16 21:28:33 +00:00
|
|
|
percent = 1 - percent;
|
|
|
|
|
2014-01-14 18:20:15 +00:00
|
|
|
double retValue = realSize * percent;
|
2014-01-16 21:28:33 +00:00
|
|
|
double adjusted =
|
2014-05-22 18:40:22 +00:00
|
|
|
orientation == LeftToRight ? retValue + m.x1() + p.x() :
|
2014-07-29 19:34:57 +00:00
|
|
|
orientation == RightToLeft ? retValue + m.x1() + p.x() :
|
|
|
|
orientation == TopToBottom ? retValue + m.y1() + p.y() :
|
|
|
|
/* entation == BottomToTop */ retValue + m.y1() + p.y();
|
2014-01-16 20:39:13 +00:00
|
|
|
return adjusted;
|
2014-01-14 18:20:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
double DiveCartesianAxis::maximum() const
|
|
|
|
{
|
|
|
|
return max;
|
|
|
|
}
|
|
|
|
|
|
|
|
double DiveCartesianAxis::minimum() const
|
|
|
|
{
|
|
|
|
return min;
|
|
|
|
}
|
|
|
|
|
2021-08-29 20:13:26 +00:00
|
|
|
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());
|
|
|
|
}
|
|
|
|
|
2020-12-20 12:01:21 +00:00
|
|
|
QString DepthAxis::textForValue(double value) const
|
2014-01-15 12:54:33 +00:00
|
|
|
{
|
2014-02-15 22:48:58 +00:00
|
|
|
if (value == 0)
|
|
|
|
return QString();
|
2017-03-23 01:13:49 +00:00
|
|
|
return get_depth_string(lrint(value), false, false);
|
2014-01-15 12:54:33 +00:00
|
|
|
}
|
2014-01-15 13:08:31 +00:00
|
|
|
|
2020-12-20 12:01:21 +00:00
|
|
|
QColor DepthAxis::colorForValue(double) const
|
2014-01-19 22:14:48 +00:00
|
|
|
{
|
|
|
|
return QColor(Qt::red);
|
|
|
|
}
|
|
|
|
|
2020-12-20 12:01:21 +00:00
|
|
|
QColor TimeAxis::colorForValue(double) const
|
2014-01-19 22:14:48 +00:00
|
|
|
{
|
|
|
|
return QColor(Qt::blue);
|
|
|
|
}
|
|
|
|
|
2020-12-20 12:01:21 +00:00
|
|
|
QString TimeAxis::textForValue(double value) const
|
2014-01-15 13:08:31 +00:00
|
|
|
{
|
2017-03-23 01:13:49 +00:00
|
|
|
int nr = lrint(value) / 60;
|
2014-02-28 04:09:57 +00:00
|
|
|
if (maximum() < 600)
|
|
|
|
return QString("%1:%2").arg(nr).arg((int)value % 60, 2, 10, QChar('0'));
|
|
|
|
return QString::number(nr);
|
2014-01-16 04:50:56 +00:00
|
|
|
}
|
2014-01-16 14:32:45 +00:00
|
|
|
|
2021-08-28 21:36:09 +00:00
|
|
|
// TODO: replace by real dynamic axis - this is just weird.
|
2021-08-28 18:15:57 +00:00
|
|
|
void TimeAxis::updateTicks(int animSpeed)
|
2014-01-27 19:18:35 +00:00
|
|
|
{
|
2021-08-28 18:15:57 +00:00
|
|
|
DiveCartesianAxis::updateTicks(animSpeed);
|
2014-02-28 04:09:57 +00:00
|
|
|
if (maximum() > 600) {
|
|
|
|
for (int i = 0; i < labels.count(); i++) {
|
2014-01-27 19:18:35 +00:00
|
|
|
labels[i]->setVisible(i % 2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-20 12:01:21 +00:00
|
|
|
QString TemperatureAxis::textForValue(double value) const
|
2014-01-16 20:39:13 +00:00
|
|
|
{
|
2014-02-28 04:09:57 +00:00
|
|
|
return QString::number(mkelvin_to_C((int)value));
|
2014-01-16 20:39:13 +00:00
|
|
|
}
|
|
|
|
|
2021-08-28 18:12:36 +00:00
|
|
|
PartialGasPressureAxis::PartialGasPressureAxis(const DivePlotDataModel &model, Position position, color_index_t gridColor,
|
2021-09-11 20:14:45 +00:00
|
|
|
double dpr, double labelScale, bool printMode, bool isGrayscale, ProfileScene &scene) :
|
|
|
|
DiveCartesianAxis(position, gridColor, dpr, labelScale, printMode, isGrayscale, scene),
|
2020-12-29 21:49:40 +00:00
|
|
|
model(model)
|
2014-01-27 17:14:42 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-08-03 08:32:08 +00:00
|
|
|
void PartialGasPressureAxis::update(int animSpeed)
|
2014-01-27 17:14:42 +00:00
|
|
|
{
|
2014-04-16 20:03:44 +00:00
|
|
|
bool showPhe = prefs.pp_graphs.phe;
|
|
|
|
bool showPn2 = prefs.pp_graphs.pn2;
|
|
|
|
bool showPo2 = prefs.pp_graphs.po2;
|
2014-01-27 17:14:42 +00:00
|
|
|
setVisible(showPhe || showPn2 || showPo2);
|
2020-12-29 21:49:40 +00:00
|
|
|
if (!model.rowCount())
|
2014-01-27 17:14:42 +00:00
|
|
|
return;
|
|
|
|
|
2020-12-29 21:49:40 +00:00
|
|
|
double max = showPhe ? model.pheMax() : -1;
|
|
|
|
if (showPn2 && model.pn2Max() > max)
|
|
|
|
max = model.pn2Max();
|
|
|
|
if (showPo2 && model.po2Max() > max)
|
|
|
|
max = model.po2Max();
|
2014-01-27 17:14:42 +00:00
|
|
|
|
|
|
|
qreal pp = floor(max * 10.0) / 10.0 + 0.2;
|
2014-02-11 04:43:21 +00:00
|
|
|
if (IS_FP_SAME(maximum(), pp))
|
2014-02-04 21:21:57 +00:00
|
|
|
return;
|
|
|
|
|
2021-09-11 19:57:49 +00:00
|
|
|
setBounds(0.0, pp);
|
2014-02-28 04:09:57 +00:00
|
|
|
setTickInterval(pp > 4 ? 0.5 : 0.25);
|
2021-08-03 08:32:08 +00:00
|
|
|
updateTicks(animSpeed);
|
2014-01-27 17:14:42 +00:00
|
|
|
}
|
2021-08-11 08:57:42 +00:00
|
|
|
|
|
|
|
double PartialGasPressureAxis::width() const
|
|
|
|
{
|
|
|
|
return textWidth(textForValue(0.99));
|
|
|
|
}
|