From e844b8dcadda8a9e4d79b4030d3f1d8587638c9c Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Mon, 31 May 2021 21:44:37 +0200 Subject: [PATCH] profile: move creation of mobile profile-widget into function The current way of handling the "print scale factor" is complex: The text fields are added and later resized via signals. Things could be simplified by just redoing the chart when changing the scale factor. Moreover, in the future we will want to adapt the size of the axes depending on the size of the texts. As a first step, factor out the creation of the profile-widget. This can then be used to recreate the profile when changing the scale factor. Signed-off-by: Berthold Stoeger --- profile-widget/qmlprofile.cpp | 15 ++++++++++----- profile-widget/qmlprofile.h | 1 + 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/profile-widget/qmlprofile.cpp b/profile-widget/qmlprofile.cpp index a0f68f0db..35ab82ba1 100644 --- a/profile-widget/qmlprofile.cpp +++ b/profile-widget/qmlprofile.cpp @@ -15,20 +15,25 @@ QMLProfile::QMLProfile(QQuickItem *parent) : m_devicePixelRatio(1.0), m_margin(0), m_xOffset(0.0), - m_yOffset(0.0), - m_profileWidget(new ProfileWidget2(nullptr, nullptr)) + m_yOffset(0.0) { + createProfileView(); setAntialiasing(true); setFlags(QQuickItem::ItemClipsChildrenToShape | QQuickItem::ItemHasContents ); - m_profileWidget->setProfileState(nullptr, 0); - m_profileWidget->setPrintMode(true); - m_profileWidget->setFontPrintScale(fontScale); connect(QMLManager::instance(), &QMLManager::sendScreenChanged, this, &QMLProfile::screenChanged); connect(this, &QMLProfile::scaleChanged, this, &QMLProfile::triggerUpdate); connect(&diveListNotifier, &DiveListNotifier::divesChanged, this, &QMLProfile::divesChanged); setDevicePixelRatio(QMLManager::instance()->lastDevicePixelRatio()); } +void QMLProfile::createProfileView() +{ + m_profileWidget.reset(new ProfileWidget2(nullptr, nullptr)); + m_profileWidget->setProfileState(nullptr, 0); + m_profileWidget->setPrintMode(true); + m_profileWidget->setFontPrintScale(fontScale * m_devicePixelRatio); +} + // we need this so we can connect update() to the scaleChanged() signal - which the connect above cannot do // directly as it chokes on the default parameter for update(). // If the scale changes we may need to change our offsets to ensure that we still only show a subset of diff --git a/profile-widget/qmlprofile.h b/profile-widget/qmlprofile.h index a67bc8c2f..4762c6d9c 100644 --- a/profile-widget/qmlprofile.h +++ b/profile-widget/qmlprofile.h @@ -38,6 +38,7 @@ private: qreal m_xOffset, m_yOffset; QScopedPointer m_profileWidget; void updateProfile(); + void createProfileView(); private slots: void divesChanged(const QVector &dives, DiveField);