Speed up the grid: don't repaint when uneeded.

Added a flag to only recalculate the axis when needed.

Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Tomaz Canabrava 2014-05-26 18:01:38 -03:00 committed by Dirk Hohndel
parent addec6b69f
commit 4c9dd0e698
2 changed files with 10 additions and 2 deletions

View file

@ -34,6 +34,7 @@ double DiveCartesianAxis::tickSize() const
void DiveCartesianAxis::setFontLabelScale(qreal scale) void DiveCartesianAxis::setFontLabelScale(qreal scale)
{ {
labelScale = scale; labelScale = scale;
changed = true;
} }
void DiveCartesianAxis::setMaximum(double maximum) void DiveCartesianAxis::setMaximum(double maximum)
@ -41,6 +42,7 @@ void DiveCartesianAxis::setMaximum(double maximum)
if (IS_FP_SAME(max, maximum)) if (IS_FP_SAME(max, maximum))
return; return;
max = maximum; max = maximum;
changed = true;
emit maxChanged(); emit maxChanged();
} }
@ -49,6 +51,7 @@ void DiveCartesianAxis::setMinimum(double minimum)
if (IS_FP_SAME(min, minimum)) if (IS_FP_SAME(min, minimum))
return; return;
min = minimum; min = minimum;
changed = true;
} }
void DiveCartesianAxis::setTextColor(const QColor &color) void DiveCartesianAxis::setTextColor(const QColor &color)
@ -67,7 +70,8 @@ DiveCartesianAxis::DiveCartesianAxis() : QObject(),
textVisibility(true), textVisibility(true),
lineVisibility(true), lineVisibility(true),
labelScale(1.0), labelScale(1.0),
line_size(1) line_size(1),
changed(true)
{ {
setPen(gridPen()); setPen(gridPen());
} }
@ -79,11 +83,13 @@ DiveCartesianAxis::~DiveCartesianAxis()
void DiveCartesianAxis::setLineSize(qreal lineSize) void DiveCartesianAxis::setLineSize(qreal lineSize)
{ {
line_size = lineSize; line_size = lineSize;
changed = true;
} }
void DiveCartesianAxis::setOrientation(Orientation o) void DiveCartesianAxis::setOrientation(Orientation o)
{ {
orientation = o; orientation = o;
changed = true;
} }
QColor DiveCartesianAxis::colorForValue(double value) QColor DiveCartesianAxis::colorForValue(double value)
@ -126,7 +132,7 @@ void emptyList(QList<T *> &list, double steps)
void DiveCartesianAxis::updateTicks(color_indice_t color) void DiveCartesianAxis::updateTicks(color_indice_t color)
{ {
if (!scene()) if (!scene() || !changed)
return; return;
QLineF m = line(); QLineF m = line();
// unused so far: // unused so far:
@ -241,6 +247,7 @@ void DiveCartesianAxis::updateTicks(color_indice_t color)
item->setVisible(textVisibility); item->setVisible(textVisibility);
Q_FOREACH (DiveLineItem *item, lines) Q_FOREACH (DiveLineItem *item, lines)
item->setVisible(lineVisibility); item->setVisible(lineVisibility);
changed = false;
} }
void DiveCartesianAxis::animateChangeLine(const QLineF &newLine) void DiveCartesianAxis::animateChangeLine(const QLineF &newLine)

View file

@ -69,6 +69,7 @@ protected:
bool lineVisibility; bool lineVisibility;
double labelScale; double labelScale;
qreal line_size; qreal line_size;
bool changed;
}; };
class DepthAxis : public DiveCartesianAxis { class DepthAxis : public DiveCartesianAxis {