From cafc7e4b1338156c9a3294a8f1037b5a31fffdbb Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Mon, 10 Feb 2014 14:41:59 -0200 Subject: Clear the data when the model resets. This patch does a few things: 1 - reset the model when user closes the dive file 2 - connects the 'rowsAboutToBeRemoved' in a way that the graphics can remove their polygons too 3 - adds a 'clear' virtual method so items that don't follow the rules can clean themseves up. Signed-off-by: Tomaz Canabrava Signed-off-by: Dirk Hohndel --- qt-ui/profile/diveplotdatamodel.cpp | 1 + qt-ui/profile/diveprofileitem.cpp | 18 ++++++++++++++++++ qt-ui/profile/diveprofileitem.h | 2 ++ qt-ui/profile/profilewidget2.cpp | 1 + 4 files changed, 22 insertions(+) (limited to 'qt-ui/profile') diff --git a/qt-ui/profile/diveplotdatamodel.cpp b/qt-ui/profile/diveplotdatamodel.cpp index 2f81999c2..3c89e81e7 100644 --- a/qt-ui/profile/diveplotdatamodel.cpp +++ b/qt-ui/profile/diveplotdatamodel.cpp @@ -99,6 +99,7 @@ void DivePlotDataModel::clear() { if (rowCount() != 0) { beginRemoveRows(QModelIndex(), 0, rowCount() - 1); + pInfo.nr = 0; endRemoveRows(); } } diff --git a/qt-ui/profile/diveprofileitem.cpp b/qt-ui/profile/diveprofileitem.cpp index 96947bd02..f60760881 100644 --- a/qt-ui/profile/diveprofileitem.cpp +++ b/qt-ui/profile/diveprofileitem.cpp @@ -44,9 +44,17 @@ void AbstractProfilePolygonItem::setModel(DivePlotDataModel* model) { dataModel = model; connect(dataModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelDataChanged(QModelIndex, QModelIndex))); + connect(dataModel, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)), this, SLOT(modelDataRemoved(QModelIndex, int, int))); modelDataChanged(); } +void AbstractProfilePolygonItem::modelDataRemoved(const QModelIndex& parent, int from, int to) +{ + setPolygon(QPolygonF()); + qDeleteAll(texts); + texts.clear(); +} + void AbstractProfilePolygonItem::setVerticalAxis(DiveCartesianAxis* vertical) { vAxis = vertical; @@ -107,6 +115,8 @@ DiveProfileItem::DiveProfileItem() : show_reported_ceiling(0), reported_ceiling_ void DiveProfileItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) { Q_UNUSED(widget); + if(polygon().isEmpty()) + return; // This paints the Polygon + Background. I'm setting the pen to QPen() so we don't get a black line here, // after all we need to plot the correct velocities colors later. @@ -277,6 +287,8 @@ void DiveTemperatureItem::createTextItem(int sec, int mkelvin) void DiveTemperatureItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) { + if(polygon().isEmpty()) + return; painter->setPen(pen()); painter->drawPolyline(polygon()); } @@ -374,6 +386,8 @@ void DiveGasPressureItem::plot_gas_value(int mbar, int sec, QFlagsclear(); backgroundFile = QString(":poster%1").arg( rand()%3 +1); currentState = EMPTY; fixBackgroundPos(); -- cgit v1.2.3-70-g09d2