diff --git a/backend-shared/exportfuncs.cpp b/backend-shared/exportfuncs.cpp index f5a1c9ccb..6afaff742 100644 --- a/backend-shared/exportfuncs.cpp +++ b/backend-shared/exportfuncs.cpp @@ -41,11 +41,10 @@ static constexpr int profileHeight = 600 * profileScale; 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); QPainter paint; 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); } diff --git a/desktop-widgets/diveplanner.cpp b/desktop-widgets/diveplanner.cpp index e3d267945..5f0930b5b 100644 --- a/desktop-widgets/diveplanner.cpp +++ b/desktop-widgets/diveplanner.cpp @@ -610,8 +610,7 @@ void PlannerWidgets::printDecoPlan() painter.setRenderHint(QPainter::SmoothPixmapTransform); auto profile = std::make_unique(1.0, true, false); - profile->plotDive(&displayed_dive, 0, DivePlannerPointsModel::instance(), true, true); - profile->draw(&painter, QRect(0, 0, pixmap.width(), pixmap.height())); + profile->draw(&painter, QRect(0, 0, pixmap.width(), pixmap.height()), &displayed_dive, 0, DivePlannerPointsModel::instance(), true); QByteArray byteArray; QBuffer buffer(&byteArray); diff --git a/desktop-widgets/printer.cpp b/desktop-widgets/printer.cpp index d476f4c55..529491fe4 100644 --- a/desktop-widgets/printer.cpp +++ b/desktop-widgets/printer.cpp @@ -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. QRect pos(x, y, profilePlaceholder.width(), profilePlaceholder.height()); - profile->plotDive(dive, 0, nullptr, true); - profile->draw(painter, pos); + profile->draw(painter, pos, dive, 0, nullptr, false); } void Printer::flowRender() diff --git a/profile-widget/profilescene.cpp b/profile-widget/profilescene.cpp index 305b20b5b..b8b9b4fe1 100644 --- a/profile-widget/profilescene.cpp +++ b/profile-widget/profilescene.cpp @@ -530,19 +530,21 @@ void ProfileScene::plotDive(const struct dive *dIn, int dcIn, DivePlannerPointsM 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. - // We add 2% to the height so that the dive computer name is not cut off. - QRectF sceneRect(0.0, 0.0, 100.0, 102.0); + QSize size = pos.size(); + resize(QSizeF(size)); + 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)); QPainter imgPainter(&image); imgPainter.setRenderHint(QPainter::Antialiasing); imgPainter.setRenderHint(QPainter::SmoothPixmapTransform); - render(&imgPainter, QRect(QPoint(), size), sceneRect, Qt::IgnoreAspectRatio); + render(&imgPainter, QRect(QPoint(), size), sceneRect(), Qt::IgnoreAspectRatio); imgPainter.end(); if (isGrayscale) { @@ -556,12 +558,5 @@ QImage ProfileScene::toImage(QSize size) } } } - - return image; -} - -void ProfileScene::draw(QPainter *painter, const QRect &pos) -{ - QImage img = toImage(pos.size()); - painter->drawImage(pos, img); + painter->drawImage(pos, image); } diff --git a/profile-widget/profilescene.h b/profile-widget/profilescene.h index 6749183bd..7424d66f8 100644 --- a/profile-widget/profilescene.h +++ b/profile-widget/profilescene.h @@ -48,8 +48,9 @@ public: void plotDive(const struct dive *d, int dc, DivePlannerPointsModel *plannerModel = nullptr, bool inPlanner = false, bool instant = false, bool calcMax = true); - void draw(QPainter *painter, const QRect &pos); - QImage toImage(QSize size); + void draw(QPainter *painter, const QRect &pos, + const struct dive *d, int dc, + DivePlannerPointsModel *plannerModel = nullptr, bool inPlanner = false); const struct dive *d; int dc; diff --git a/profile-widget/qmlprofile.cpp b/profile-widget/qmlprofile.cpp index e52c69ab2..175db10f1 100644 --- a/profile-widget/qmlprofile.cpp +++ b/profile-widget/qmlprofile.cpp @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-2.0 +// SPDX-License-Identifier: GPL-2. #include "qmlprofile.h" #include "profilescene.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 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) @@ -67,22 +72,9 @@ int QMLProfile::diveId() const 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) { m_diveId = diveId; - if (m_diveId < 0) - return; - updateProfile(); } qreal QMLProfile::devicePixelRatio() const @@ -129,7 +121,6 @@ void QMLProfile::divesChanged(const QVector &dives, DiveField) for (struct dive *d: dives) { if (d->id == m_diveId) { qDebug() << "dive #" << d->number << "changed, trigger profile update"; - m_profileWidget->plotDive(d, dc_number); triggerUpdate(); return; } diff --git a/profile-widget/qmlprofile.h b/profile-widget/qmlprofile.h index 29e1291ea..dcbde0309 100644 --- a/profile-widget/qmlprofile.h +++ b/profile-widget/qmlprofile.h @@ -40,7 +40,6 @@ private: int m_margin; qreal m_xOffset, m_yOffset; std::unique_ptr m_profileWidget; - void updateProfile(); void createProfileView(); private slots: