mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
profile: set text and brush of DiveTextItem concurrently
The text and the brush are the two properties of text items that change dynamically. To avoid complexities concerning redrawing, set them concurrently instead of in two separate calls. Since setting one of the properties requires a full redraw, there is no performance advantage in setting them individually. This fixes a theoretical bug: the colors of axis labels were not updated appropriately. However, it seems like value-dependent labels weren't used anyway. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
2ebe6e3684
commit
04e0d96bae
6 changed files with 18 additions and 35 deletions
|
@ -170,7 +170,7 @@ void DiveCartesianAxis::updateTicks(int animSpeed, color_index_t color)
|
|||
begin + i * stepSize :
|
||||
begin - i * stepSize;
|
||||
|
||||
labels[i]->setText(textForValue(currValueText));
|
||||
labels[i]->set(textForValue(currValueText), colorForValue(currValueText));
|
||||
if (orientation == LeftToRight || orientation == RightToLeft) {
|
||||
Animations::moveTo(labels[i], animSpeed, childPos, m.y1() + tick_size);
|
||||
} else {
|
||||
|
@ -201,8 +201,7 @@ void DiveCartesianAxis::updateTicks(int animSpeed, color_index_t color)
|
|||
int alignFlags = orientation == RightToLeft || orientation == LeftToRight ? Qt::AlignBottom | Qt::AlignHCenter :
|
||||
Qt::AlignVCenter | Qt::AlignLeft;
|
||||
DiveTextItem *label = new DiveTextItem(dpr, labelScale, alignFlags, this);
|
||||
label->setText(textForValue(currValueText));
|
||||
label->setBrush(colorForValue(currValueText));
|
||||
label->set(textForValue(currValueText), colorForValue(currValueText));
|
||||
label->setZValue(1);
|
||||
labels.push_back(label);
|
||||
if (orientation == RightToLeft || orientation == LeftToRight) {
|
||||
|
|
|
@ -143,9 +143,8 @@ void DiveProfileItem::replot(const dive *d, bool in_planner)
|
|||
void DiveProfileItem::plot_depth_sample(struct plot_data *entry, QFlags<Qt::AlignmentFlag> flags, const QColor &color)
|
||||
{
|
||||
DiveTextItem *item = new DiveTextItem(dpr, 1.0, flags, this);
|
||||
item->set(get_depth_string(entry->depth, true), color);
|
||||
item->setPos(hAxis.posAtValue(entry->sec), vAxis.posAtValue(entry->depth));
|
||||
item->setText(get_depth_string(entry->depth, true));
|
||||
item->setBrush(color);
|
||||
texts.append(item);
|
||||
}
|
||||
|
||||
|
@ -219,9 +218,8 @@ void DiveHeartrateItem::createTextItem(int sec, int hr, bool last)
|
|||
int flags = last ? Qt::AlignLeft | Qt::AlignBottom :
|
||||
Qt::AlignRight | Qt::AlignBottom;
|
||||
DiveTextItem *text = new DiveTextItem(dpr, 0.7, flags, this);
|
||||
text->setBrush(getColor(HR_TEXT));
|
||||
text->set(QString("%1").arg(hr), getColor(HR_TEXT));
|
||||
text->setPos(QPointF(hAxis.posAtValue(sec), vAxis.posAtValue(hr)));
|
||||
text->setText(QString("%1").arg(hr));
|
||||
texts.append(text);
|
||||
}
|
||||
|
||||
|
@ -369,9 +367,8 @@ void DiveTemperatureItem::createTextItem(int sec, int mkelvin, bool last)
|
|||
int flags = last ? Qt::AlignLeft | Qt::AlignBottom :
|
||||
Qt::AlignRight | Qt::AlignBottom;
|
||||
DiveTextItem *text = new DiveTextItem(dpr, 0.8, flags, this);
|
||||
text->setBrush(getColor(TEMP_TEXT));
|
||||
text->set(get_temperature_string(temp, true), getColor(TEMP_TEXT));
|
||||
text->setPos(QPointF(hAxis.posAtValue(sec), vAxis.posAtValue(mkelvin)));
|
||||
text->setText(get_temperature_string(temp, true));
|
||||
texts.append(text);
|
||||
}
|
||||
|
||||
|
@ -435,9 +432,8 @@ void DiveMeanDepthItem::createTextItem()
|
|||
qDeleteAll(texts);
|
||||
texts.clear();
|
||||
DiveTextItem *text = new DiveTextItem(dpr, 0.8, Qt::AlignRight | Qt::AlignTop, this);
|
||||
text->setBrush(getColor(TEMP_TEXT));
|
||||
text->set(get_depth_string(lrint(lastRunningSum), true), getColor(TEMP_TEXT));
|
||||
text->setPos(QPointF(hAxis.posAtValue(sec) + 1, vAxis.posAtValue(lastRunningSum)));
|
||||
text->setText(get_depth_string(lrint(lastRunningSum), true));
|
||||
texts.append(text);
|
||||
}
|
||||
|
||||
|
@ -571,9 +567,8 @@ void DiveGasPressureItem::plotPressureValue(int mbar, int sec, QFlags<Qt::Alignm
|
|||
const char *unit;
|
||||
int pressure = get_pressure_units(mbar, &unit);
|
||||
DiveTextItem *text = new DiveTextItem(dpr, 1.0, align, this);
|
||||
text->set(QString("%1%2").arg(pressure).arg(unit), getColor(PRESSURE_TEXT));
|
||||
text->setPos(hAxis.posAtValue(sec), vAxis.posAtValue(mbar) + pressure_offset );
|
||||
text->setText(QString("%1%2").arg(pressure).arg(unit));
|
||||
text->setBrush(getColor(PRESSURE_TEXT));
|
||||
texts.push_back(text);
|
||||
}
|
||||
|
||||
|
@ -581,9 +576,8 @@ void DiveGasPressureItem::plotGasValue(int mbar, int sec, struct gasmix gasmix,
|
|||
{
|
||||
QString gas = get_gas_string(gasmix);
|
||||
DiveTextItem *text = new DiveTextItem(dpr, 1.0, align, this);
|
||||
text->set(gas, getColor(PRESSURE_TEXT));
|
||||
text->setPos(hAxis.posAtValue(sec), vAxis.posAtValue(mbar) + gasname_offset );
|
||||
text->setText(gas);
|
||||
text->setBrush(getColor(PRESSURE_TEXT));
|
||||
texts.push_back(text);
|
||||
}
|
||||
|
||||
|
|
|
@ -27,17 +27,11 @@ void DiveTextItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *opti
|
|||
QGraphicsItemGroup::paint(painter, option, widget);
|
||||
}
|
||||
|
||||
void DiveTextItem::setBrush(const QBrush &b)
|
||||
void DiveTextItem::set(const QString &t, const QBrush &b)
|
||||
{
|
||||
textItem->setBrush(b);
|
||||
}
|
||||
|
||||
void DiveTextItem::setText(const QString &t)
|
||||
{
|
||||
if (internalText != t) {
|
||||
internalText = t;
|
||||
updateText();
|
||||
}
|
||||
internalText = t;
|
||||
updateText();
|
||||
}
|
||||
|
||||
const QString &DiveTextItem::text()
|
||||
|
|
|
@ -15,8 +15,7 @@ class DiveTextItem : public QObject, public QGraphicsItemGroup {
|
|||
Q_PROPERTY(qreal opacity READ opacity WRITE setOpacity)
|
||||
public:
|
||||
DiveTextItem(double dpr, double scale, int alignFlags, QGraphicsItem *parent);
|
||||
void setText(const QString &text);
|
||||
void setBrush(const QBrush &brush);
|
||||
void set(const QString &text, const QBrush &brush);
|
||||
const QString &text();
|
||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
||||
static QFont getFont(double dpr, double scale);
|
||||
|
|
|
@ -157,9 +157,7 @@ ProfileScene::ProfileScene(double dpr, bool printMode, bool isGrayscale) :
|
|||
// show the deco model parameters at the top in the center
|
||||
decoModelParameters->setY(0);
|
||||
decoModelParameters->setX(50);
|
||||
decoModelParameters->setBrush(getColor(PRESSURE_TEXT));
|
||||
|
||||
diveComputerText->setBrush(getColor(TIME_TEXT, isGrayscale));
|
||||
diveComputerText->setPos(itemPos.dcLabel.on);
|
||||
|
||||
tankItem->setPos(itemPos.tankBar.on);
|
||||
|
@ -450,15 +448,15 @@ void ProfileScene::plotDive(const struct dive *dIn, int dcIn, DivePlannerPointsM
|
|||
|
||||
if (!plannerModel) {
|
||||
if (decoMode(false) == VPMB)
|
||||
decoModelParameters->setText(QString("VPM-B +%1").arg(prefs.vpmb_conservatism));
|
||||
decoModelParameters->set(QString("VPM-B +%1").arg(prefs.vpmb_conservatism), getColor(PRESSURE_TEXT));
|
||||
else
|
||||
decoModelParameters->setText(QString("GF %1/%2").arg(prefs.gflow).arg(prefs.gfhigh));
|
||||
decoModelParameters->set(QString("GF %1/%2").arg(prefs.gflow).arg(prefs.gfhigh), getColor(PRESSURE_TEXT));
|
||||
} else {
|
||||
struct diveplan &diveplan = plannerModel->getDiveplan();
|
||||
if (decoMode(inPlanner) == VPMB)
|
||||
decoModelParameters->setText(QString("VPM-B +%1").arg(diveplan.vpmb_conservatism));
|
||||
decoModelParameters->set(QString("VPM-B +%1").arg(diveplan.vpmb_conservatism), getColor(PRESSURE_TEXT));
|
||||
else
|
||||
decoModelParameters->setText(QString("GF %1/%2").arg(diveplan.gflow).arg(diveplan.gfhigh));
|
||||
decoModelParameters->set(QString("GF %1/%2").arg(diveplan.gflow).arg(diveplan.gfhigh), getColor(PRESSURE_TEXT));
|
||||
}
|
||||
|
||||
const struct divecomputer *currentdc = get_dive_dc_const(d, dc);
|
||||
|
@ -660,7 +658,7 @@ void ProfileScene::plotDive(const struct dive *dIn, int dcIn, DivePlannerPointsM
|
|||
if ((nr = number_of_computers(d)) > 1)
|
||||
dcText += tr(" (#%1 of %2)").arg(dc + 1).arg(nr);
|
||||
#endif
|
||||
diveComputerText->setText(dcText);
|
||||
diveComputerText->set(dcText, getColor(TIME_TEXT, isGrayscale));
|
||||
}
|
||||
|
||||
QImage ProfileScene::toImage(QSize size)
|
||||
|
|
|
@ -52,8 +52,7 @@ void TankItem::createBar(int startTime, int stopTime, struct gasmix gas)
|
|||
rect->setPen(QPen(QBrush(), 0.0)); // get rid of the thick line around the rectangle
|
||||
rects.push_back(rect);
|
||||
DiveTextItem *label = new DiveTextItem(dpr, 1.0, Qt::AlignBottom | Qt::AlignRight, rect);
|
||||
label->setText(gasname(gas));
|
||||
label->setBrush(Qt::black);
|
||||
label->set(gasname(gas), Qt::black);
|
||||
label->setPos(x + 1, 0);
|
||||
#ifdef SUBSURFACE_MOBILE
|
||||
label->setPos(x + 1, -2.5);
|
||||
|
|
Loading…
Add table
Reference in a new issue