profile: pass fontPrintScale at construction time

Instead of intializing the text fields and then changing the
font scale via signal-rigmarole, pass down the font-scale
at construction time.

Since the fontPrintScale is only set in print mode, we also
can access it directly instead of testing for printMode.

Since the DiveTextItem is not updated using signals anymore,
the connected flag can be removed.

The commit is larger than I had hoped for, but this makes
things ultimately less brittle.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2021-06-03 17:19:38 +02:00 committed by Dirk Hohndel
parent 7744fec0bf
commit 01983c65c3
9 changed files with 88 additions and 98 deletions

View file

@ -8,13 +8,12 @@
#include <QDebug>
#include <QApplication>
DiveTextItem::DiveTextItem(QGraphicsItem *parent) : QGraphicsItemGroup(parent),
DiveTextItem::DiveTextItem(double printScale, QGraphicsItem *parent) : QGraphicsItemGroup(parent),
internalAlignFlags(Qt::AlignHCenter | Qt::AlignVCenter),
textBackgroundItem(new QGraphicsPathItem(this)),
textItem(new QGraphicsPathItem(this)),
printScale(1.0),
scale(1.0),
connected(false)
printScale(printScale),
scale(1.0)
{
setFlag(ItemIgnoresTransformations);
textBackgroundItem->setBrush(QBrush(getColor(TEXT_BACKGROUND)));
@ -28,11 +27,6 @@ void DiveTextItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *opti
QGraphicsItemGroup::paint(painter, option, widget);
}
void DiveTextItem::fontPrintScaleUpdate(double scale)
{
printScale = scale;
}
void DiveTextItem::setAlignment(int alignFlags)
{
if (alignFlags != internalAlignFlags) {
@ -55,19 +49,6 @@ void DiveTextItem::setScale(double newscale)
void DiveTextItem::setText(const QString &t)
{
if (internalText != t) {
if (!connected) {
if (scene()) {
// by now we should be on a scene. grab the profile widget from it and setup our printScale
// and connect to the signal that makes sure we keep track if that changes
ProfileWidget2 *profile = qobject_cast<ProfileWidget2 *>(scene()->views().first());
connect(profile, SIGNAL(fontPrintScaleChanged(double)), this, SLOT(fontPrintScaleUpdate(double)), Qt::UniqueConnection);
fontPrintScaleUpdate(profile->getFontPrintScale());
connected = true;
} else {
if (verbose)
qDebug() << "called before scene was set up" << t;
}
}
internalText = t;
updateText();
}