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 <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2021-05-31 21:44:37 +02:00 committed by Dirk Hohndel
parent 23ab6b7a8c
commit e844b8dcad
2 changed files with 11 additions and 5 deletions

View file

@ -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

View file

@ -38,6 +38,7 @@ private:
qreal m_xOffset, m_yOffset;
QScopedPointer<ProfileWidget2> m_profileWidget;
void updateProfile();
void createProfileView();
private slots:
void divesChanged(const QVector<dive *> &dives, DiveField);