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 <tcanabrava@kde.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Tomaz Canabrava 2014-02-10 14:41:59 -02:00 committed by Dirk Hohndel
parent 2f2c9e371c
commit cafc7e4b13
5 changed files with 23 additions and 0 deletions

View file

@ -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, QFlags<Qt::Alignment
void DiveGasPressureItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
{
if(polygon().isEmpty())
return;
QPen pen;
pen.setCosmetic(true);
pen.setWidth(2);
@ -427,6 +441,8 @@ void DiveCalculatedCeiling::modelDataChanged(const QModelIndex& topLeft, const Q
void DiveCalculatedCeiling::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
{
if(polygon().isEmpty())
return;
QGraphicsPolygonItem::paint(painter, option, widget);
}
@ -492,6 +508,8 @@ void DiveReportedCeiling::preferencesChanged()
void DiveReportedCeiling::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
{
if(polygon().isEmpty())
return;
QGraphicsPolygonItem::paint(painter, option, widget);
}