Moved the temperature item as a 'Cache'

This patch moves the temperature item as a cache that will
be updated as the model updates, instead of deleting / recreating
it everytime the dive changes.

Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Tomaz Canabrava 2014-01-23 15:44:12 -02:00 committed by Dirk Hohndel
parent 555ca8245d
commit 563c39b822
2 changed files with 10 additions and 14 deletions

View file

@ -192,7 +192,7 @@ DiveTemperatureItem::DiveTemperatureItem()
void DiveTemperatureItem::modelDataChanged()
{
// We don't have enougth data to calculate things, quit.
if (!hAxis || !vAxis || !dataModel || hDataColumn == -1 || vDataColumn == -1)
if (!hAxis || !vAxis || !dataModel || hDataColumn == -1 || vDataColumn == -1 || dataModel->rowCount() == 0)
return;
qDeleteAll(texts);

View file

@ -146,6 +146,15 @@ ProfileWidget2::ProfileWidget2(QWidget *parent) :
gasPressureItem->setZValue(1);
scene()->addItem(gasPressureItem);
temperatureItem = new DiveTemperatureItem();
temperatureItem->setHorizontalAxis(timeAxis);
temperatureItem->setVerticalAxis(temperatureAxis);
temperatureItem->setModel(dataModel);
temperatureItem->setVerticalDataColumn(DivePlotDataModel::TEMPERATURE);
temperatureItem->setHorizontalDataColumn(DivePlotDataModel::TIME);
temperatureItem->setZValue(1);
scene()->addItem(temperatureItem);
background->setFlag(QGraphicsItem::ItemIgnoresTransformations);
//enum State{ EMPTY, PROFILE, EDIT, ADD, PLAN, INVALID };
@ -377,19 +386,6 @@ void ProfileWidget2::plotDives(QList<dive*> dives)
event = event->next;
}
if(temperatureItem){
scene()->removeItem(temperatureItem);
delete temperatureItem;
}
temperatureItem = new DiveTemperatureItem();
temperatureItem->setHorizontalAxis(timeAxis);
temperatureItem->setVerticalAxis(temperatureAxis);
temperatureItem->setModel(dataModel);
temperatureItem->setVerticalDataColumn(DivePlotDataModel::TEMPERATURE);
temperatureItem->setHorizontalDataColumn(DivePlotDataModel::TIME);
temperatureItem->setZValue(1);
scene()->addItem(temperatureItem);
diveComputerText->setText(currentdc->model);
diveComputerText->animateMoveTo(1 , sceneRect().height());
emit startProfileState();