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"
|
2020-11-24 11:50:52 +00:00
|
|
|
#include "core/subsurface-qt/divelistnotifier.h"
|
2016-04-05 05:02:03 +00:00
|
|
|
#include "qt-models/diveplotdatamodel.h"
|
|
|
|
#include "profile-widget/animationfunctions.h"
|
|
|
|
#include "profile-widget/divelineitem.h"
|
|
|
|
#include "profile-widget/profilewidget2.h"
|
2014-01-14 18:20:15 +00:00
|
|
|
|
2020-12-20 12:01:21 +00:00
|
|
|
QPen DiveCartesianAxis::gridPen() const
|
2014-02-28 04:09:57 +00:00
|
|
|
{
|
2014-01-19 22:14:48 +00:00
|
|
|
QPen pen;
|
|
|
|
pen.setColor(getColor(TIME_GRID));
|
2015-10-11 11:21:14 +00:00
|
|
|
/* 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);
|
2014-01-19 22:14:48 +00:00
|
|
|
pen.setCosmetic(true);
|
|
|
|
return pen;
|
|
|
|
}
|
2014-02-07 16:59:58 +00:00
|
|
|
|
2014-02-15 19:15:57 +00:00
|
|
|
void DiveCartesianAxis::setFontLabelScale(qreal scale)
|
|
|
|
{
|
|
|
|
labelScale = scale;
|
2014-05-26 21:01:38 +00:00
|
|
|
changed = true;
|
2014-02-15 19:15:57 +00:00
|
|
|
}
|
|
|
|
|
2015-10-11 11:21:14 +00:00
|
|
|
void DiveCartesianAxis::setPrintMode(bool mode)
|
|
|
|
{
|
|
|
|
printMode = mode;
|
|
|
|
// 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());
|
|
|
|
}
|
|
|
|
|
2014-01-14 18:20:15 +00:00
|
|
|
void DiveCartesianAxis::setMaximum(double maximum)
|
|
|
|
{
|
2014-02-11 04:43:21 +00:00
|
|
|
if (IS_FP_SAME(max, maximum))
|
2014-02-04 21:21:57 +00:00
|
|
|
return;
|
2014-01-14 18:20:15 +00:00
|
|
|
max = maximum;
|
2014-05-26 21:01:38 +00:00
|
|
|
changed = true;
|
2014-01-14 18:20:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DiveCartesianAxis::setMinimum(double minimum)
|
|
|
|
{
|
2014-02-11 04:43:21 +00:00
|
|
|
if (IS_FP_SAME(min, minimum))
|
2014-02-04 21:21:57 +00:00
|
|
|
return;
|
2014-01-14 18:20:15 +00:00
|
|
|
min = minimum;
|
2014-05-26 21:01:38 +00:00
|
|
|
changed = true;
|
2014-01-14 18:20:15 +00:00
|
|
|
}
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
void DiveCartesianAxis::setTextColor(const QColor &color)
|
2014-01-14 18:20:15 +00:00
|
|
|
{
|
|
|
|
textColor = color;
|
|
|
|
}
|
|
|
|
|
2015-11-06 11:54:35 +00:00
|
|
|
DiveCartesianAxis::DiveCartesianAxis(ProfileWidget2 *widget) : QObject(),
|
2014-02-09 17:37:40 +00:00
|
|
|
QGraphicsLineItem(),
|
2015-10-11 11:21:14 +00:00
|
|
|
printMode(false),
|
2015-11-06 11:54:35 +00:00
|
|
|
profileWidget(widget),
|
2014-02-09 17:37:40 +00:00
|
|
|
orientation(LeftToRight),
|
|
|
|
min(0),
|
|
|
|
max(0),
|
|
|
|
interval(1),
|
2014-02-12 16:24:19 +00:00
|
|
|
tick_size(0),
|
2014-02-15 23:55:31 +00:00
|
|
|
textVisibility(true),
|
2014-02-17 22:39:03 +00:00
|
|
|
lineVisibility(true),
|
2014-03-10 11:43:43 +00:00
|
|
|
labelScale(1.0),
|
2014-05-26 21:01:38 +00:00
|
|
|
line_size(1),
|
|
|
|
changed(true)
|
2014-01-14 18:20:15 +00:00
|
|
|
{
|
2014-01-19 22:14:48 +00:00
|
|
|
setPen(gridPen());
|
2014-01-14 18:20:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DiveCartesianAxis::~DiveCartesianAxis()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-02-15 23:55:31 +00:00
|
|
|
void DiveCartesianAxis::setLineSize(qreal lineSize)
|
|
|
|
{
|
|
|
|
line_size = lineSize;
|
2014-05-26 21:01:38 +00:00
|
|
|
changed = true;
|
2014-02-15 23:55:31 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-10 16:33:20 +00:00
|
|
|
void DiveCartesianAxis::updateTicks(color_index_t color)
|
2014-01-14 18:20:15 +00:00
|
|
|
{
|
2021-06-04 13:15:37 +00:00
|
|
|
if (!scene() || (!changed && !printMode))
|
2014-01-25 15:25:03 +00:00
|
|
|
return;
|
2014-01-14 18:20:15 +00:00
|
|
|
QLineF m = line();
|
2014-01-16 05:44:18 +00:00
|
|
|
// unused so far:
|
|
|
|
// QGraphicsView *view = scene()->views().first();
|
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
|
|
|
|
2019-07-10 20:40:06 +00:00
|
|
|
emptyList(labels, steps, profileWidget->animSpeed);
|
|
|
|
emptyList(lines, steps, profileWidget->animSpeed);
|
2014-02-15 23:55:31 +00:00
|
|
|
|
2018-05-19 05:37:58 +00:00
|
|
|
// Move the remaining ticks / text to their correct positions
|
|
|
|
// 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) {
|
|
|
|
qreal 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
|
|
|
|
2014-02-16 00:15:45 +00:00
|
|
|
labels[i]->setText(textForValue(currValueText));
|
2014-02-28 04:09:57 +00:00
|
|
|
if (orientation == LeftToRight || orientation == RightToLeft) {
|
2019-07-10 20:40:06 +00:00
|
|
|
Animations::moveTo(labels[i], profileWidget->animSpeed, childPos, m.y1() + tick_size);
|
2014-01-16 04:50:56 +00:00
|
|
|
} else {
|
2019-07-10 20:40:06 +00:00
|
|
|
Animations::moveTo(labels[i], profileWidget->animSpeed ,m.x1() - tick_size, childPos);
|
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) {
|
|
|
|
qreal 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
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
if (orientation == LeftToRight || orientation == RightToLeft) {
|
2019-07-10 20:40:06 +00:00
|
|
|
Animations::moveTo(lines[i], profileWidget->animSpeed, childPos, m.y1());
|
2014-02-16 00:15:45 +00:00
|
|
|
} else {
|
2019-07-10 20:40:06 +00:00
|
|
|
Animations::moveTo(lines[i], profileWidget->animSpeed, m.x1(), childPos);
|
2014-02-16 00:15:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-14 18:28:07 +00:00
|
|
|
// Add's the rest of the needed Ticks / Text.
|
2014-02-28 04:09:57 +00:00
|
|
|
for (int i = labels.size(); i < steps; i++, currValueText += interval) {
|
2014-01-16 21:28:33 +00:00
|
|
|
qreal childPos;
|
|
|
|
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;
|
|
|
|
}
|
2014-02-07 20:08:29 +00:00
|
|
|
DiveTextItem *label = new DiveTextItem(this);
|
2014-02-16 00:15:45 +00:00
|
|
|
label->setText(textForValue(currValueText));
|
|
|
|
label->setBrush(colorForValue(currValueText));
|
2014-02-15 19:15:57 +00:00
|
|
|
label->setScale(fontLabelScale());
|
2014-02-16 00:49:30 +00:00
|
|
|
label->setZValue(1);
|
2014-02-07 20:08:29 +00:00
|
|
|
labels.push_back(label);
|
2014-01-16 21:28:33 +00:00
|
|
|
if (orientation == RightToLeft || orientation == LeftToRight) {
|
2014-02-07 20:08:29 +00:00
|
|
|
label->setAlignment(Qt::AlignBottom | Qt::AlignHCenter);
|
|
|
|
label->setPos(scene()->sceneRect().width() + 10, m.y1() + tick_size); // position it outside of the scene);
|
2019-07-10 20:40:06 +00:00
|
|
|
Animations::moveTo(label, profileWidget->animSpeed,childPos , m.y1() + tick_size);
|
2014-01-16 04:50:56 +00:00
|
|
|
} else {
|
2014-02-28 04:09:57 +00:00
|
|
|
label->setAlignment(Qt::AlignVCenter | Qt::AlignLeft);
|
2014-02-07 20:08:29 +00:00
|
|
|
label->setPos(m.x1() - tick_size, scene()->sceneRect().height() + 10);
|
2019-07-10 20:40:06 +00:00
|
|
|
Animations::moveTo(label, profileWidget->animSpeed, m.x1() - tick_size, childPos);
|
2014-01-14 18:28:07 +00:00
|
|
|
}
|
|
|
|
}
|
2014-02-12 16:24:19 +00:00
|
|
|
|
2014-02-16 00:43:27 +00:00
|
|
|
// Add's the rest of the needed Ticks / Text.
|
2014-02-28 04:09:57 +00:00
|
|
|
for (int i = lines.size(); i < steps; i++, currValueText += interval) {
|
2014-02-16 00:43:27 +00:00
|
|
|
qreal childPos;
|
|
|
|
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);
|
2015-10-11 11:21:14 +00:00
|
|
|
QPen pen = gridPen();
|
2014-04-28 19:45:42 +00:00
|
|
|
pen.setBrush(getColor(color));
|
2014-02-16 00:43:27 +00:00
|
|
|
line->setPen(pen);
|
2014-02-16 00:49:30 +00:00
|
|
|
line->setZValue(0);
|
2014-02-16 00:43:27 +00:00
|
|
|
lines.push_back(line);
|
|
|
|
if (orientation == RightToLeft || orientation == LeftToRight) {
|
2014-02-28 04:09:57 +00:00
|
|
|
line->setLine(0, -line_size, 0, 0);
|
2014-05-26 21:20:40 +00:00
|
|
|
line->setPos(scene()->sceneRect().width() + 10, m.y1()); // position it outside of the scene);
|
2019-07-10 20:40:06 +00:00
|
|
|
Animations::moveTo(line, profileWidget->animSpeed, childPos, m.y1());
|
2014-02-16 00:43:27 +00:00
|
|
|
} else {
|
|
|
|
QPointF p1 = mapFromScene(3, 0);
|
|
|
|
QPointF p2 = mapFromScene(line_size, 0);
|
|
|
|
line->setLine(p1.x(), 0, p2.x(), 0);
|
2014-05-26 21:20:40 +00:00
|
|
|
line->setPos(m.x1(), scene()->sceneRect().height() + 10);
|
2019-07-10 20:40:06 +00:00
|
|
|
Animations::moveTo(line, profileWidget->animSpeed, m.x1(), 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;
|
|
|
|
}
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
void DiveCartesianAxis::animateChangeLine(const QLineF &newLine)
|
2014-01-22 19:10:18 +00:00
|
|
|
{
|
|
|
|
setLine(newLine);
|
|
|
|
updateTicks();
|
|
|
|
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::setTickSize(qreal size)
|
|
|
|
{
|
2014-02-07 19:59:21 +00:00
|
|
|
tick_size = size;
|
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;
|
|
|
|
}
|
|
|
|
|
2014-02-15 19:15:57 +00:00
|
|
|
double DiveCartesianAxis::fontLabelScale() const
|
|
|
|
{
|
|
|
|
return labelScale;
|
|
|
|
}
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
void DiveCartesianAxis::setColor(const QColor &color)
|
2014-01-14 18:20:15 +00:00
|
|
|
{
|
2015-10-11 11:21:14 +00:00
|
|
|
QPen defaultPen = gridPen();
|
|
|
|
defaultPen.setColor(color);
|
2014-01-14 18:20:15 +00:00
|
|
|
defaultPen.setJoinStyle(Qt::RoundJoin);
|
|
|
|
defaultPen.setCapStyle(Qt::RoundCap);
|
|
|
|
setPen(defaultPen);
|
|
|
|
}
|
2014-01-15 12:54:33 +00:00
|
|
|
|
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-24 18:13:16 +00:00
|
|
|
DepthAxis::DepthAxis(ProfileWidget2 *widget) : DiveCartesianAxis(widget),
|
|
|
|
unitSystem(prefs.units.length)
|
2014-01-22 19:10:18 +00:00
|
|
|
{
|
2020-11-24 11:50:52 +00:00
|
|
|
connect(&diveListNotifier, &DiveListNotifier::settingsChanged, this, &DepthAxis::settingsChanged);
|
2014-07-29 19:34:57 +00:00
|
|
|
changed = true;
|
2014-01-22 19:10:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DepthAxis::settingsChanged()
|
|
|
|
{
|
2020-12-24 18:13:16 +00:00
|
|
|
if (unitSystem == prefs.units.length)
|
2014-07-29 19:34:57 +00:00
|
|
|
return;
|
|
|
|
changed = true;
|
|
|
|
updateTicks();
|
|
|
|
unitSystem = prefs.units.length;
|
2014-01-22 19:10:18 +00:00
|
|
|
}
|
|
|
|
|
2015-11-06 11:54:35 +00:00
|
|
|
TimeAxis::TimeAxis(ProfileWidget2 *widget) : DiveCartesianAxis(widget)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2018-01-10 16:33:20 +00:00
|
|
|
void TimeAxis::updateTicks(color_index_t color)
|
2014-01-27 19:18:35 +00:00
|
|
|
{
|
2016-03-08 05:22:10 +00:00
|
|
|
DiveCartesianAxis::updateTicks(color);
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-06 11:54:35 +00:00
|
|
|
TemperatureAxis::TemperatureAxis(ProfileWidget2 *widget) : DiveCartesianAxis(widget)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2020-12-29 21:49:40 +00:00
|
|
|
PartialGasPressureAxis::PartialGasPressureAxis(const DivePlotDataModel &model, ProfileWidget2 *widget) :
|
2015-11-06 11:54:35 +00:00
|
|
|
DiveCartesianAxis(widget),
|
2020-12-29 21:49:40 +00:00
|
|
|
model(model)
|
2014-01-27 17:14:42 +00:00
|
|
|
{
|
2020-12-29 21:49:40 +00:00
|
|
|
connect(&diveListNotifier, &DiveListNotifier::settingsChanged, this, &PartialGasPressureAxis::update);
|
2014-01-27 17:14:42 +00:00
|
|
|
}
|
|
|
|
|
2020-12-29 21:49:40 +00:00
|
|
|
void PartialGasPressureAxis::update()
|
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;
|
|
|
|
|
2014-01-27 17:14:42 +00:00
|
|
|
setMaximum(pp);
|
2014-02-28 04:09:57 +00:00
|
|
|
setTickInterval(pp > 4 ? 0.5 : 0.25);
|
2014-01-27 17:14:42 +00:00
|
|
|
updateTicks();
|
|
|
|
}
|