More two.
On Wed, Jan 22, 2014 at 5:27 PM, Tomaz Canabrava <[email protected]> wrote: > slow day today. > >
From 044e9a81a8c118136042b1499b7e66c672d0d28e Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava <[email protected]> Date: Wed, 22 Jan 2014 17:54:24 -0200 Subject: [PATCH 4/5] Simplify the code for the Reported Ceiling. The item of the reported ceiling now behaves better by not being deleted / recreated, instead it uses the same object and connects to the model to know when to regenerate it's plot. Signed-off-by: Tomaz Canabrava <[email protected]> --- qt-ui/profile/diveprofileitem.cpp | 10 +++++----- qt-ui/profile/profilewidget2.cpp | 21 +++++++++------------ 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/qt-ui/profile/diveprofileitem.cpp b/qt-ui/profile/diveprofileitem.cpp index 8314fae..8d4531e 100644 --- a/qt-ui/profile/diveprofileitem.cpp +++ b/qt-ui/profile/diveprofileitem.cpp @@ -15,6 +15,7 @@ #include <QDebug> #include <QApplication> #include <QGraphicsItem> +#include <QSettings> AbstractProfilePolygonItem::AbstractProfilePolygonItem(): QObject(), QGraphicsPolygonItem(), hAxis(NULL), vAxis(NULL), dataModel(NULL), hDataColumn(-1), vDataColumn(-1) @@ -42,6 +43,7 @@ void AbstractProfilePolygonItem::setModel(DivePlotDataModel* model) { dataModel = model; connect(dataModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelDataChanged())); + connect(dataModel, SIGNAL(rowsInserted(QModelIndex,int,int)), this, SLOT(modelDataChanged())); modelDataChanged(); } @@ -413,11 +415,9 @@ void DiveReportedCeiling::modelDataChanged() void DiveReportedCeiling::preferencesChanged() { - if (prefs.profile_dc_ceiling) { - setVisible(prefs.profile_red_ceiling); - } else { - setVisible(false); - } + QSettings s; + s.beginGroup("TecDetails"); + setVisible(s.value("redceiling").toBool()); } void DiveReportedCeiling::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) diff --git a/qt-ui/profile/profilewidget2.cpp b/qt-ui/profile/profilewidget2.cpp index e6a60da..95c43a7 100644 --- a/qt-ui/profile/profilewidget2.cpp +++ b/qt-ui/profile/profilewidget2.cpp @@ -107,6 +107,15 @@ ProfileWidget2::ProfileWidget2(QWidget *parent) : scene()->addItem(item); } + reportedCeiling = new DiveReportedCeiling(); + reportedCeiling->setHorizontalAxis(timeAxis); + reportedCeiling->setVerticalAxis(profileYAxis); + reportedCeiling->setModel(dataModel); + reportedCeiling->setVerticalDataColumn(DivePlotDataModel::CEILING); + reportedCeiling->setHorizontalDataColumn(DivePlotDataModel::TIME); + reportedCeiling->setZValue(1); + scene()->addItem(reportedCeiling); + background->setFlag(QGraphicsItem::ItemIgnoresTransformations); //enum State{ EMPTY, PROFILE, EDIT, ADD, PLAN, INVALID }; @@ -394,18 +403,6 @@ void ProfileWidget2::plotDives(QList<dive*> dives) scene()->addItem(tissueItem); } - if(reportedCeiling){ - scene()->removeItem(reportedCeiling); - delete reportedCeiling; - } - reportedCeiling = new DiveReportedCeiling(); - reportedCeiling->setHorizontalAxis(timeAxis); - reportedCeiling->setVerticalAxis(profileYAxis); - reportedCeiling->setModel(dataModel); - reportedCeiling->setVerticalDataColumn(DivePlotDataModel::CEILING); - reportedCeiling->setHorizontalDataColumn(DivePlotDataModel::TIME); - reportedCeiling->setZValue(1); - scene()->addItem(reportedCeiling); emit startProfileState(); } -- 1.8.5.3
From bfd7c9d571c5a5a4a250520e50dd6fc7df3f597d Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava <[email protected]> Date: Wed, 22 Jan 2014 18:25:35 -0200 Subject: [PATCH 5/5] Do not delete / new object that can be cached. Do not new / delete object that can be used as cache. this way we will always have this object on screen, and as soon as the model changes, it's contents will change. Signed-off-by: Tomaz Canabrava <[email protected]> --- qt-ui/profile/diveprofileitem.cpp | 2 ++ qt-ui/profile/diveprofileitem.h | 2 +- qt-ui/profile/profilewidget2.cpp | 22 +++++++++------------- 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/qt-ui/profile/diveprofileitem.cpp b/qt-ui/profile/diveprofileitem.cpp index 8d4531e..03eab1a 100644 --- a/qt-ui/profile/diveprofileitem.cpp +++ b/qt-ui/profile/diveprofileitem.cpp @@ -367,6 +367,8 @@ void DiveCalculatedCeiling::modelDataChanged() AbstractProfilePolygonItem::modelDataChanged(); // Add 2 points to close the polygon. QPolygonF poly = polygon(); + if(poly.isEmpty()) + return; QPointF p1 = poly.first(); QPointF p2 = poly.last(); diff --git a/qt-ui/profile/diveprofileitem.h b/qt-ui/profile/diveprofileitem.h index 792f08a..1891df7 100644 --- a/qt-ui/profile/diveprofileitem.h +++ b/qt-ui/profile/diveprofileitem.h @@ -114,4 +114,4 @@ private: DiveTextItem *leftText; DiveTextItem *rightText; }; -#endif \ No newline at end of file +#endif diff --git a/qt-ui/profile/profilewidget2.cpp b/qt-ui/profile/profilewidget2.cpp index 95c43a7..d293798 100644 --- a/qt-ui/profile/profilewidget2.cpp +++ b/qt-ui/profile/profilewidget2.cpp @@ -116,6 +116,15 @@ ProfileWidget2::ProfileWidget2(QWidget *parent) : reportedCeiling->setZValue(1); scene()->addItem(reportedCeiling); + diveCeiling = new DiveCalculatedCeiling(); + diveCeiling->setHorizontalAxis(timeAxis); + diveCeiling->setVerticalAxis(profileYAxis); + diveCeiling->setModel(dataModel); + diveCeiling->setVerticalDataColumn(DivePlotDataModel::CEILING); + diveCeiling->setHorizontalDataColumn(DivePlotDataModel::TIME); + diveCeiling->setZValue(1); + scene()->addItem(diveCeiling); + background->setFlag(QGraphicsItem::ItemIgnoresTransformations); //enum State{ EMPTY, PROFILE, EDIT, ADD, PLAN, INVALID }; @@ -373,19 +382,6 @@ void ProfileWidget2::plotDives(QList<dive*> dives) gasPressureItem->setZValue(1); scene()->addItem(gasPressureItem); - if(diveCeiling){ - scene()->removeItem(diveCeiling); - delete diveCeiling; - } - diveCeiling = new DiveCalculatedCeiling(); - diveCeiling->setHorizontalAxis(timeAxis); - diveCeiling->setVerticalAxis(profileYAxis); - diveCeiling->setModel(dataModel); - diveCeiling->setVerticalDataColumn(DivePlotDataModel::CEILING); - diveCeiling->setHorizontalDataColumn(DivePlotDataModel::TIME); - diveCeiling->setZValue(1); - scene()->addItem(diveCeiling); - diveComputerText->setText(currentdc->model); diveComputerText->animateMoveTo(1 , sceneRect().height()); -- 1.8.5.3
_______________________________________________ subsurface mailing list [email protected] http://lists.hohndel.org/cgi-bin/mailman/listinfo/subsurface
