mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Remove only the Uneeded Ticks / Labels when a update is requested.
This patch makes the updateTicks method not remove / readd everything when it's triggered, but to only remove the ticks / labels that are no longer needed on the current display. Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
49f4052c67
commit
ca979044d0
1 changed files with 8 additions and 38 deletions
|
@ -44,48 +44,18 @@ void DiveCartesianAxis::setOrientation(Qt::Orientation o)
|
||||||
|
|
||||||
void DiveCartesianAxis::updateTicks()
|
void DiveCartesianAxis::updateTicks()
|
||||||
{
|
{
|
||||||
qDeleteAll(ticks);
|
|
||||||
ticks.clear();
|
|
||||||
qDeleteAll(labels);
|
|
||||||
labels.clear();
|
|
||||||
|
|
||||||
QLineF m = line();
|
QLineF m = line();
|
||||||
DiveLineItem *item = NULL;
|
QGraphicsView *view = scene()->views().first();
|
||||||
DiveTextItem *label = NULL;
|
|
||||||
|
|
||||||
double steps = (max - min) / interval;
|
double steps = (max - min) / interval;
|
||||||
qreal pos;
|
|
||||||
double currValue = min;
|
double currValue = min;
|
||||||
|
|
||||||
if (orientation == Qt::Horizontal) {
|
// Remove the uneeded Ticks / Texts.
|
||||||
double stepSize = (m.x2() - m.x1()) / steps;
|
if (ticks.size() > steps){
|
||||||
for (pos = m.x1(); pos <= m.x2(); pos += stepSize, currValue += interval) {
|
while (ticks.size() > steps){
|
||||||
item = new DiveLineItem(this);
|
DiveLineItem *removedLine = ticks.takeLast();
|
||||||
item->setLine(pos, m.y1(), pos, m.y1() + tickSize);
|
removedLine->animatedHide();
|
||||||
item->setPen(pen());
|
DiveTextItem *removedText = labels.takeLast();
|
||||||
ticks.push_back(item);
|
removedText->animatedHide();
|
||||||
|
|
||||||
label = new DiveTextItem(this);
|
|
||||||
label->setText(QString::number(currValue));
|
|
||||||
label->setBrush(QBrush(textColor));
|
|
||||||
label->setFlag(ItemIgnoresTransformations);
|
|
||||||
label->setPos(pos - label->boundingRect().width()/2, m.y1() + tickSize + 5);
|
|
||||||
labels.push_back(label);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
double stepSize = (m.y2() - m.y1()) / steps;
|
|
||||||
for (pos = m.y1(); pos <= m.y2(); pos += stepSize, currValue += interval) {
|
|
||||||
item = new DiveLineItem(this);
|
|
||||||
item->setLine(m.x1(), pos, m.x1() - tickSize, pos);
|
|
||||||
item->setPen(pen());
|
|
||||||
ticks.push_back(item);
|
|
||||||
|
|
||||||
label = new DiveTextItem(this);
|
|
||||||
label->setText(get_depth_string(currValue, false, false));
|
|
||||||
label->setBrush(QBrush(textColor));
|
|
||||||
label->setFlag(ItemIgnoresTransformations);
|
|
||||||
label->setPos(m.x2() - 80, pos);
|
|
||||||
labels.push_back(label);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue