From 563c39b8221ac2e3730c9f51a0e890b42af8ca78 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Thu, 23 Jan 2014 15:44:12 -0200 Subject: 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 Signed-off-by: Dirk Hohndel --- qt-ui/profile/diveprofileitem.cpp | 2 +- qt-ui/profile/profilewidget2.cpp | 22 +++++++++------------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/qt-ui/profile/diveprofileitem.cpp b/qt-ui/profile/diveprofileitem.cpp index 25d6a8415..f00fff688 100644 --- a/qt-ui/profile/diveprofileitem.cpp +++ b/qt-ui/profile/diveprofileitem.cpp @@ -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); diff --git a/qt-ui/profile/profilewidget2.cpp b/qt-ui/profile/profilewidget2.cpp index e21af21bd..2f607590b 100644 --- a/qt-ui/profile/profilewidget2.cpp +++ b/qt-ui/profile/profilewidget2.cpp @@ -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 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(); -- cgit v1.2.3-70-g09d2