I didn't cleared the model when closing the file ( because I never closed the file, sigh. ) now it works :)
Tomaz
From 87f71fe3bdeaff8b2233c1424ed25d3c5533b17b Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava <tcanabr...@kde.org> Date: Mon, 10 Feb 2014 15:04:27 -0200 Subject: [PATCH 3/3] Do not add the items to the scene twice. Those items have parent(), wich means that when the parent have a scene, they are automatically added and removed from the scene. Signed-off-by: Tomaz Canabrava <tcanabr...@kde.org> --- qt-ui/profile/divecartesianaxis.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/qt-ui/profile/divecartesianaxis.cpp b/qt-ui/profile/divecartesianaxis.cpp index 5bb0d94..143b0f9 100644 --- a/qt-ui/profile/divecartesianaxis.cpp +++ b/qt-ui/profile/divecartesianaxis.cpp @@ -397,7 +397,6 @@ void DiveCartesianPlane::setup() line->setZValue(-1); line->setPen(gridPen()); horizontalLines.push_back(line); - scene()->addItem(line); } for (int i = bottomAxis->minimum(), max = bottomAxis->maximum(); i < max; i += 600) { // increments by 10 minutes. @@ -407,7 +406,6 @@ void DiveCartesianPlane::setup() line->setZValue(-1); line->setPen(gridPen()); verticalLines.push_back(line); - scene()->addItem(line); } } -- 1.8.5.4
From 1ce59402830d7d57176ecf48d62815d22b6feda7 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava <tcanabr...@kde.org> Date: Mon, 10 Feb 2014 15:01:04 -0200 Subject: [PATCH 2/3] Fixed item visibility on emptyState after being on profileState. Background was not correctly back to it's original position and a few other items kept their visibility when it shouldn't. Signed-off-by: Tomaz Canabrava <tcanabr...@kde.org> --- qt-ui/profile/divecartesianaxis.cpp | 8 ++++---- qt-ui/profile/profilewidget2.cpp | 4 +++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/qt-ui/profile/divecartesianaxis.cpp b/qt-ui/profile/divecartesianaxis.cpp index c455468..5bb0d94 100644 --- a/qt-ui/profile/divecartesianaxis.cpp +++ b/qt-ui/profile/divecartesianaxis.cpp @@ -391,9 +391,9 @@ void DiveCartesianPlane::setup() // DEPTH is M_OR_FEET(10,30), Minutes are 600, per line. for (int i = leftAxis->minimum(), max = leftAxis->maximum(); i < max; i += M_OR_FT(10,30)) { - DiveLineItem *line = new DiveLineItem(); + DiveLineItem *line = new DiveLineItem(this); line->setLine(0, 0, horizontalSize, 0); - line->setPos(left,leftAxis->posAtValue(i)); + line->setPos(0,leftAxis->posAtValue(i)-top); line->setZValue(-1); line->setPen(gridPen()); horizontalLines.push_back(line); @@ -401,9 +401,9 @@ void DiveCartesianPlane::setup() } for (int i = bottomAxis->minimum(), max = bottomAxis->maximum(); i < max; i += 600) { // increments by 10 minutes. - DiveLineItem *line = new DiveLineItem(); + DiveLineItem *line = new DiveLineItem(this); line->setLine(0, 0, 0, verticalSize); - line->setPos(bottomAxis->posAtValue(i), top); + line->setPos(bottomAxis->posAtValue(i)-left, 0); line->setZValue(-1); line->setPen(gridPen()); verticalLines.push_back(line); diff --git a/qt-ui/profile/profilewidget2.cpp b/qt-ui/profile/profilewidget2.cpp index 55fdc51..0fb925f 100644 --- a/qt-ui/profile/profilewidget2.cpp +++ b/qt-ui/profile/profilewidget2.cpp @@ -147,6 +147,7 @@ void ProfileWidget2::setupItemOnScene() cartesianPlane->setBottomAxis(timeAxis); cartesianPlane->setLeftAxis(profileYAxis); + cartesianPlane->setZValue(-1); diveComputerText->setAlignment(Qt::AlignRight | Qt::AlignBottom); diveComputerText->setBrush(getColor(TIME_TEXT)); @@ -441,14 +442,15 @@ void ProfileWidget2::setEmptyState() gasYAxis->setPos(itemPos.partialgas.pos.off); timeAxis->setPos(itemPos.time.pos.off); background->setY( itemPos.background.on.y()); + background->setVisible(true); toolTipItem->setVisible(false); temperatureAxis->setPos(itemPos.temperature.pos.off); cylinderPressureAxis->setPos(itemPos.cylinder.pos.off); - cartesianPlane->setVisible(false); meanDepth->setVisible(false); diveComputerText->setVisible(false); diveCeiling->setVisible(false); reportedCeiling->setVisible(false); + cartesianPlane->setVisible(false); Q_FOREACH(DiveCalculatedTissue *tissue, allTissues){ tissue->setVisible(false); } -- 1.8.5.4
From 2d2860103f413cadab8a5be480b727c0b469cf0a Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava <tcanabr...@kde.org> Date: Mon, 10 Feb 2014 14:41:59 -0200 Subject: [PATCH 1/3] 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 doesn't folloes the rules can clean themseves up. Signed-off-by: Tomaz Canabrava <tcanabr...@kde.org> --- qt-ui/mainwindow.cpp | 1 + qt-ui/profile/diveplotdatamodel.cpp | 1 + qt-ui/profile/diveprofileitem.cpp | 18 ++++++++++++++++++ qt-ui/profile/diveprofileitem.h | 2 ++ qt-ui/profile/profilewidget2.cpp | 1 + 5 files changed, 23 insertions(+) diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp index d93de4d..b0de017 100644 --- a/qt-ui/mainwindow.cpp +++ b/qt-ui/mainwindow.cpp @@ -167,6 +167,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 cb3b07c..ee4e13e 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 214fd1e..249fa47 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); @@ -425,6 +439,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); } @@ -490,6 +506,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 80c8407..b47cbd5 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 0f38e5f..55fdc51 100644 --- a/qt-ui/profile/profilewidget2.cpp +++ b/qt-ui/profile/profilewidget2.cpp @@ -433,6 +433,7 @@ void ProfileWidget2::setEmptyState() if (currentState == EMPTY) return; + dataModel->clear(); backgroundFile = QString(":poster%1").arg( rand()%3 +1); currentState = EMPTY; fixBackgroundPos(); -- 1.8.5.4
_______________________________________________ subsurface mailing list subsurface@hohndel.org http://lists.hohndel.org/cgi-bin/mailman/listinfo/subsurface