mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-28 05:00:20 +00:00
profile: move calculations out of DivePercentageItem::paint()
The DivePercentageItem is a polygon-item with a custom paint() method. Calculation of the polygon is done once in replot(), but calculation of the corresponding colors is done in every paint() call. The problem is, we have no control over paint(). It is called whenever Qt feels like. Therefore using live dive data is a dangerous proposition if we ever want to get rid of the global displayed_dive. Do all the calculations in replot(). Store the colors in an additional array of the same size as the polygon. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
0146a0c892
commit
acee77e516
2 changed files with 14 additions and 15 deletions
|
@ -285,14 +285,20 @@ DivePercentageItem::DivePercentageItem(const DivePlotDataModel &model, const Div
|
|||
|
||||
void DivePercentageItem::replot()
|
||||
{
|
||||
int sec = 0;
|
||||
|
||||
// Ignore empty values. a heart rate of 0 would be a bad sign.
|
||||
QPolygonF poly;
|
||||
colors.clear();
|
||||
for (int i = 0, modelDataCount = dataModel.rowCount(); i < modelDataCount; i++) {
|
||||
sec = dataModel.index(i, hDataColumn).data().toInt();
|
||||
int sec = dataModel.index(i, hDataColumn).data().toInt();
|
||||
QPointF point(hAxis.posAtValue(sec), vAxis.posAtValue(64 - 4 * tissueIndex));
|
||||
poly.append(point);
|
||||
|
||||
double value = dataModel.index(i, vDataColumn).data().toDouble();
|
||||
struct gasmix gasmix = gasmix_air;
|
||||
const struct event *ev = NULL;
|
||||
gasmix = get_gasmix(&displayed_dive, displayed_dc, sec, &ev, gasmix);
|
||||
int inert = get_n2(gasmix) + get_he(gasmix);
|
||||
colors.push_back(ColorScale(value, inert));
|
||||
}
|
||||
setPolygon(poly);
|
||||
|
||||
|
@ -333,18 +339,10 @@ void DivePercentageItem::paint(QPainter *painter, const QStyleOptionGraphicsItem
|
|||
mypen.setCapStyle(Qt::FlatCap);
|
||||
mypen.setCosmetic(false);
|
||||
QPolygonF poly = polygon();
|
||||
for (int i = 1, modelDataCount = dataModel.rowCount(); i < modelDataCount; i++) {
|
||||
if (i < poly.count()) {
|
||||
double value = dataModel.index(i, vDataColumn).data().toDouble();
|
||||
struct gasmix gasmix = gasmix_air;
|
||||
const struct event *ev = NULL;
|
||||
int sec = dataModel.index(i, DivePlotDataModel::TIME).data().toInt();
|
||||
gasmix = get_gasmix(&displayed_dive, displayed_dc, sec, &ev, gasmix);
|
||||
int inert = get_n2(gasmix) + get_he(gasmix);
|
||||
mypen.setBrush(QBrush(ColorScale(value, inert)));
|
||||
painter->setPen(mypen);
|
||||
painter->drawLine(poly[i - 1], poly[i]);
|
||||
}
|
||||
for (int i = 1; i < poly.count(); i++) {
|
||||
mypen.setBrush(QBrush(colors[i]));
|
||||
painter->setPen(mypen);
|
||||
painter->drawLine(poly[i - 1], poly[i]);
|
||||
}
|
||||
painter->restore();
|
||||
}
|
||||
|
|
|
@ -122,6 +122,7 @@ public:
|
|||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
|
||||
|
||||
private:
|
||||
std::vector<QColor> colors; // Must have same number of elements as the polygon
|
||||
QString visibilityKey;
|
||||
int tissueIndex;
|
||||
QColor ColorScale(double value, int inert);
|
||||
|
|
Loading…
Reference in a new issue