mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-30 22:20:21 +00:00
profile: merge plotDive() into draw() call
Rendering resets the size, which now recalculates the axes. Therefore, plotDive() must be called. The callers were doing the opposite: call plotDive() first, then draw(). To make it easier for the callers, present a single interface that handles these subtleties. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
d0beae59f9
commit
8046a05e95
7 changed files with 22 additions and 39 deletions
|
@ -41,11 +41,10 @@ static constexpr int profileHeight = 600 * profileScale;
|
||||||
|
|
||||||
static void exportProfile(ProfileScene *profile, const struct dive *dive, const QString &filename)
|
static void exportProfile(ProfileScene *profile, const struct dive *dive, const QString &filename)
|
||||||
{
|
{
|
||||||
profile->plotDive(dive, 0, nullptr, false, true);
|
|
||||||
QImage image = QImage(QSize(profileWidth, profileHeight), QImage::Format_RGB32);
|
QImage image = QImage(QSize(profileWidth, profileHeight), QImage::Format_RGB32);
|
||||||
QPainter paint;
|
QPainter paint;
|
||||||
paint.begin(&image);
|
paint.begin(&image);
|
||||||
profile->draw(&paint, QRect(0, 0, profileWidth, profileHeight));
|
profile->draw(&paint, QRect(0, 0, profileWidth, profileHeight), dive, 0, nullptr, false);
|
||||||
image.save(filename);
|
image.save(filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -610,8 +610,7 @@ void PlannerWidgets::printDecoPlan()
|
||||||
painter.setRenderHint(QPainter::SmoothPixmapTransform);
|
painter.setRenderHint(QPainter::SmoothPixmapTransform);
|
||||||
|
|
||||||
auto profile = std::make_unique<ProfileScene>(1.0, true, false);
|
auto profile = std::make_unique<ProfileScene>(1.0, true, false);
|
||||||
profile->plotDive(&displayed_dive, 0, DivePlannerPointsModel::instance(), true, true);
|
profile->draw(&painter, QRect(0, 0, pixmap.width(), pixmap.height()), &displayed_dive, 0, DivePlannerPointsModel::instance(), true);
|
||||||
profile->draw(&painter, QRect(0, 0, pixmap.width(), pixmap.height()));
|
|
||||||
|
|
||||||
QByteArray byteArray;
|
QByteArray byteArray;
|
||||||
QBuffer buffer(&byteArray);
|
QBuffer buffer(&byteArray);
|
||||||
|
|
|
@ -38,8 +38,7 @@ void Printer::putProfileImage(const QRect &profilePlaceholder, const QRect &view
|
||||||
// use the placeHolder and the viewPort position to calculate the relative position of the dive profile.
|
// use the placeHolder and the viewPort position to calculate the relative position of the dive profile.
|
||||||
QRect pos(x, y, profilePlaceholder.width(), profilePlaceholder.height());
|
QRect pos(x, y, profilePlaceholder.width(), profilePlaceholder.height());
|
||||||
|
|
||||||
profile->plotDive(dive, 0, nullptr, true);
|
profile->draw(painter, pos, dive, 0, nullptr, false);
|
||||||
profile->draw(painter, pos);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Printer::flowRender()
|
void Printer::flowRender()
|
||||||
|
|
|
@ -530,19 +530,21 @@ void ProfileScene::plotDive(const struct dive *dIn, int dcIn, DivePlannerPointsM
|
||||||
diveComputerText->set(dcText, getColor(TIME_TEXT, isGrayscale));
|
diveComputerText->set(dcText, getColor(TIME_TEXT, isGrayscale));
|
||||||
}
|
}
|
||||||
|
|
||||||
QImage ProfileScene::toImage(QSize size)
|
void ProfileScene::draw(QPainter *painter, const QRect &pos,
|
||||||
|
const struct dive *d, int dc,
|
||||||
|
DivePlannerPointsModel *plannerModel, bool inPlanner)
|
||||||
{
|
{
|
||||||
// The size of chart with respect to the scene is fixed - by convention - to 100.0.
|
QSize size = pos.size();
|
||||||
// We add 2% to the height so that the dive computer name is not cut off.
|
resize(QSizeF(size));
|
||||||
QRectF sceneRect(0.0, 0.0, 100.0, 102.0);
|
plotDive(d, dc, plannerModel, inPlanner, true, true);
|
||||||
|
|
||||||
QImage image(size, QImage::Format_ARGB32);
|
QImage image(pos.size(), QImage::Format_ARGB32);
|
||||||
image.fill(getColor(::BACKGROUND, isGrayscale));
|
image.fill(getColor(::BACKGROUND, isGrayscale));
|
||||||
|
|
||||||
QPainter imgPainter(&image);
|
QPainter imgPainter(&image);
|
||||||
imgPainter.setRenderHint(QPainter::Antialiasing);
|
imgPainter.setRenderHint(QPainter::Antialiasing);
|
||||||
imgPainter.setRenderHint(QPainter::SmoothPixmapTransform);
|
imgPainter.setRenderHint(QPainter::SmoothPixmapTransform);
|
||||||
render(&imgPainter, QRect(QPoint(), size), sceneRect, Qt::IgnoreAspectRatio);
|
render(&imgPainter, QRect(QPoint(), size), sceneRect(), Qt::IgnoreAspectRatio);
|
||||||
imgPainter.end();
|
imgPainter.end();
|
||||||
|
|
||||||
if (isGrayscale) {
|
if (isGrayscale) {
|
||||||
|
@ -556,12 +558,5 @@ QImage ProfileScene::toImage(QSize size)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
painter->drawImage(pos, image);
|
||||||
return image;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ProfileScene::draw(QPainter *painter, const QRect &pos)
|
|
||||||
{
|
|
||||||
QImage img = toImage(pos.size());
|
|
||||||
painter->drawImage(pos, img);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,8 +48,9 @@ public:
|
||||||
void plotDive(const struct dive *d, int dc, DivePlannerPointsModel *plannerModel = nullptr, bool inPlanner = false,
|
void plotDive(const struct dive *d, int dc, DivePlannerPointsModel *plannerModel = nullptr, bool inPlanner = false,
|
||||||
bool instant = false, bool calcMax = true);
|
bool instant = false, bool calcMax = true);
|
||||||
|
|
||||||
void draw(QPainter *painter, const QRect &pos);
|
void draw(QPainter *painter, const QRect &pos,
|
||||||
QImage toImage(QSize size);
|
const struct dive *d, int dc,
|
||||||
|
DivePlannerPointsModel *plannerModel = nullptr, bool inPlanner = false);
|
||||||
|
|
||||||
const struct dive *d;
|
const struct dive *d;
|
||||||
int dc;
|
int dc;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// SPDX-License-Identifier: GPL-2.0
|
// SPDX-License-Identifier: GPL-2.
|
||||||
#include "qmlprofile.h"
|
#include "qmlprofile.h"
|
||||||
#include "profilescene.h"
|
#include "profilescene.h"
|
||||||
#include "mobile-widgets/qmlmanager.h"
|
#include "mobile-widgets/qmlmanager.h"
|
||||||
|
@ -54,7 +54,12 @@ void QMLProfile::paint(QPainter *painter)
|
||||||
|
|
||||||
// let's look at the intended size of the content and scale our scene accordingly
|
// let's look at the intended size of the content and scale our scene accordingly
|
||||||
QRect painterRect = painter->viewport();
|
QRect painterRect = painter->viewport();
|
||||||
m_profileWidget->draw(painter, painterRect);
|
if (m_diveId < 0)
|
||||||
|
return;
|
||||||
|
struct dive *d = get_dive_by_uniq_id(m_diveId);
|
||||||
|
if (!d)
|
||||||
|
return;
|
||||||
|
m_profileWidget->draw(painter, painterRect, d, dc_number, nullptr, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void QMLProfile::setMargin(int margin)
|
void QMLProfile::setMargin(int margin)
|
||||||
|
@ -67,22 +72,9 @@ int QMLProfile::diveId() const
|
||||||
return m_diveId;
|
return m_diveId;
|
||||||
}
|
}
|
||||||
|
|
||||||
void QMLProfile::updateProfile()
|
|
||||||
{
|
|
||||||
struct dive *d = get_dive_by_uniq_id(m_diveId);
|
|
||||||
if (!d)
|
|
||||||
return;
|
|
||||||
if (verbose)
|
|
||||||
qDebug() << "update profile for dive #" << d->number << "offeset" << QString::number(m_xOffset, 'f', 1) << "/" << QString::number(m_yOffset, 'f', 1);
|
|
||||||
m_profileWidget->plotDive(d, dc_number);
|
|
||||||
}
|
|
||||||
|
|
||||||
void QMLProfile::setDiveId(int diveId)
|
void QMLProfile::setDiveId(int diveId)
|
||||||
{
|
{
|
||||||
m_diveId = diveId;
|
m_diveId = diveId;
|
||||||
if (m_diveId < 0)
|
|
||||||
return;
|
|
||||||
updateProfile();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
qreal QMLProfile::devicePixelRatio() const
|
qreal QMLProfile::devicePixelRatio() const
|
||||||
|
@ -129,7 +121,6 @@ void QMLProfile::divesChanged(const QVector<dive *> &dives, DiveField)
|
||||||
for (struct dive *d: dives) {
|
for (struct dive *d: dives) {
|
||||||
if (d->id == m_diveId) {
|
if (d->id == m_diveId) {
|
||||||
qDebug() << "dive #" << d->number << "changed, trigger profile update";
|
qDebug() << "dive #" << d->number << "changed, trigger profile update";
|
||||||
m_profileWidget->plotDive(d, dc_number);
|
|
||||||
triggerUpdate();
|
triggerUpdate();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,7 +40,6 @@ private:
|
||||||
int m_margin;
|
int m_margin;
|
||||||
qreal m_xOffset, m_yOffset;
|
qreal m_xOffset, m_yOffset;
|
||||||
std::unique_ptr<ProfileScene> m_profileWidget;
|
std::unique_ptr<ProfileScene> m_profileWidget;
|
||||||
void updateProfile();
|
|
||||||
void createProfileView();
|
void createProfileView();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
|
Loading…
Reference in a new issue