aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Tomaz Canabrava <tcanabrava@kde.org>2014-02-10 14:41:59 -0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2014-02-10 09:57:04 -0800
commitcafc7e4b1338156c9a3294a8f1037b5a31fffdbb (patch)
tree5a543404a6ec221b0450865409801584ec1ce7f5
parent2f2c9e371ceeba4cf45575b5a30815bcd562f853 (diff)
downloadsubsurface-cafc7e4b1338156c9a3294a8f1037b5a31fffdbb.tar.gz
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>
-rw-r--r--qt-ui/mainwindow.cpp1
-rw-r--r--qt-ui/profile/diveplotdatamodel.cpp1
-rw-r--r--qt-ui/profile/diveprofileitem.cpp18
-rw-r--r--qt-ui/profile/diveprofileitem.h2
-rw-r--r--qt-ui/profile/profilewidget2.cpp1
5 files changed, 23 insertions, 0 deletions
diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp
index df6e13163..4f2fd9642 100644
--- a/qt-ui/mainwindow.cpp
+++ b/qt-ui/mainwindow.cpp
@@ -171,6 +171,7 @@ void MainWindow::on_actionClose_triggered()
if (unsaved_changes() && (askSaveChanges() == false))
return;
+ ui.graphicsView->setEmptyState();
/* free the dives and trips */
while (dive_table.nr)
delete_single_dive(0);
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, 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);
}
diff --git a/qt-ui/profile/diveprofileitem.h b/qt-ui/profile/diveprofileitem.h
index 80c840736..b47cbd513 100644
--- a/qt-ui/profile/diveprofileitem.h
+++ b/qt-ui/profile/diveprofileitem.h
@@ -41,9 +41,11 @@ public:
void setHorizontalDataColumn(int column);
void setVerticalDataColumn(int column);
virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0) = 0;
+ virtual void clear(){};
public slots:
virtual void preferencesChanged();
virtual void modelDataChanged(const QModelIndex& topLeft = QModelIndex(), const QModelIndex& bottomRight = QModelIndex());
+ virtual void modelDataRemoved(const QModelIndex& parent, int from, int to);
protected:
/* when the model emits a 'datachanged' signal, this method below should be used to check if the
* modified data affects this particular item ( for example, when setting the '3m increment'
diff --git a/qt-ui/profile/profilewidget2.cpp b/qt-ui/profile/profilewidget2.cpp
index 7db90886e..69ec8b9e2 100644
--- a/qt-ui/profile/profilewidget2.cpp
+++ b/qt-ui/profile/profilewidget2.cpp
@@ -432,6 +432,7 @@ void ProfileWidget2::setEmptyState()
if (currentState == EMPTY)
return;
+ dataModel->clear();
backgroundFile = QString(":poster%1").arg( rand()%3 +1);
currentState = EMPTY;
fixBackgroundPos();