Simplify the code for the reported ceiling.

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 its plot.

Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Tomaz Canabrava 2014-01-22 17:54:24 -02:00 committed by Dirk Hohndel
parent bc7b221498
commit 629a1ea0f9
2 changed files with 14 additions and 17 deletions

View file

@ -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)

View file

@ -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();
}