summaryrefslogtreecommitdiffstats
path: root/qt-ui/profile/profilewidget2.cpp
diff options
context:
space:
mode:
authorGravatar Tomaz Canabrava <tcanabrava@kde.org>2014-01-27 15:14:42 -0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2014-01-27 09:15:28 -0800
commitc99089e1fa3b7eaccf3a49ea35bae0dacad04060 (patch)
tree49b6491b19ca1bd2feb9dbb245cc4269626add0a /qt-ui/profile/profilewidget2.cpp
parenta57f950b302cdd54e9a71736aaa9e761070ece41 (diff)
downloadsubsurface-c99089e1fa3b7eaccf3a49ea35bae0dacad04060.tar.gz
Add settings awareness for the PP graph
This commit is rather big, and I forgot to cut it in pieces. The first part creates a new 'calculate_gas_information' that will not fill the profile_info->maxpp member ( that should be removed from it as soon as the new dialog is finished ). The reason for that is that all of the profile data will be calculated and the graph needs to update dynamically, so whenever the settings changes, I ask for the model which is the biggest graph and replot only the ones we need. The second part adds a new animation function 'animdelete' to fade-out and delete the item when it's done. the old function 'hide' did just that but a hide shouldn't delete anything. The third part is preferenes awareness for the PP graphs. I created two new functions that receive the settings key for visibility and use the QSettings to show / hide them. This also works quite well for the axis; if no graph is visible, the axis will also hide itself. The fourth part is colors. The pp graphs now have the correct colors. And a bit of code cleanup too. Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui/profile/profilewidget2.cpp')
-rw-r--r--qt-ui/profile/profilewidget2.cpp62
1 files changed, 24 insertions, 38 deletions
diff --git a/qt-ui/profile/profilewidget2.cpp b/qt-ui/profile/profilewidget2.cpp
index a39dbadd7..007ca8a68 100644
--- a/qt-ui/profile/profilewidget2.cpp
+++ b/qt-ui/profile/profilewidget2.cpp
@@ -27,7 +27,7 @@ ProfileWidget2::ProfileWidget2(QWidget *parent) :
stateMachine(new QStateMachine(this)),
background (new DivePixmapItem()),
profileYAxis(new DepthAxis()),
- gasYAxis(new DiveCartesianAxis()),
+ gasYAxis(new PartialGasPressureAxis()),
temperatureAxis(new TemperatureAxis()),
timeAxis(new TimeAxis()),
depthController(new DiveRectItem()),
@@ -72,6 +72,8 @@ ProfileWidget2::ProfileWidget2(QWidget *parent) :
gasYAxis->setTickInterval(1);
gasYAxis->setTickSize(2);
gasYAxis->setY(70);
+ gasYAxis->setMinimum(0);
+ gasYAxis->setModel(dataModel);
scene()->addItem(gasYAxis);
temperatureAxis->setOrientation(DiveCartesianAxis::BottomToTop);
@@ -89,6 +91,7 @@ ProfileWidget2::ProfileWidget2(QWidget *parent) :
timeAxis->setLine(0,0,96,0);
timeAxis->setX(3);
timeAxis->setTickSize(1);
+
depthController->setRect(0, 0, 10, 5);
timeController->setRect(0, 0, 10, 5);
timeController->setX(sceneRect().width() - timeController->boundingRect().width()); // Position it on the right spot.
@@ -170,35 +173,24 @@ ProfileWidget2::ProfileWidget2(QWidget *parent) :
diveProfileItem->setZValue(0);
scene()->addItem(diveProfileItem);
- pn2GasItem = new PartialPressureGasItem();
- pn2GasItem->setHorizontalAxis(timeAxis);
- pn2GasItem->setVerticalAxis(gasYAxis);
- pn2GasItem->setModel(dataModel);
- pn2GasItem->setVerticalDataColumn(DivePlotDataModel::PN2);
- pn2GasItem->setHorizontalDataColumn(DivePlotDataModel::TIME);
- pn2GasItem->setZValue(0);
- pn2GasItem->setThreshouldSettingsKey("pn2threshold");
- scene()->addItem(pn2GasItem);
-
- pheGasItem = new PartialPressureGasItem();
- pheGasItem->setHorizontalAxis(timeAxis);
- pheGasItem->setVerticalAxis(gasYAxis);
- pheGasItem->setModel(dataModel);
- pheGasItem->setVerticalDataColumn(DivePlotDataModel::PHE);
- pheGasItem->setHorizontalDataColumn(DivePlotDataModel::TIME);
- pheGasItem->setZValue(0);
- pheGasItem->setThreshouldSettingsKey("phethreshold");
- scene()->addItem(pheGasItem);
-
- pheGasItem = new PartialPressureGasItem();
- pheGasItem->setHorizontalAxis(timeAxis);
- pheGasItem->setVerticalAxis(gasYAxis);
- pheGasItem->setModel(dataModel);
- pheGasItem->setVerticalDataColumn(DivePlotDataModel::PO2);
- pheGasItem->setHorizontalDataColumn(DivePlotDataModel::TIME);
- pheGasItem->setZValue(0);
- pheGasItem->setThreshouldSettingsKey("po2threshold");
- scene()->addItem(pheGasItem);
+#define CREATE_PP_GAS( ITEM, VERTICAL_COLUMN, COLOR, COLOR_ALERT, THRESHOULD_SETTINGS, VISIBILITY_SETTINGS ) \
+ ITEM = new PartialPressureGasItem(); \
+ ITEM->setHorizontalAxis(timeAxis); \
+ ITEM->setVerticalAxis(gasYAxis); \
+ ITEM->setModel(dataModel); \
+ ITEM->setVerticalDataColumn(DivePlotDataModel::VERTICAL_COLUMN); \
+ ITEM->setHorizontalDataColumn(DivePlotDataModel::TIME); \
+ ITEM->setZValue(0); \
+ ITEM->setThreshouldSettingsKey(THRESHOULD_SETTINGS); \
+ ITEM->setVisibilitySettingsKey(VISIBILITY_SETTINGS); \
+ ITEM->setColors(getColor(COLOR), getColor(COLOR_ALERT)); \
+ ITEM->preferencesChanged(); \
+ scene()->addItem(ITEM);
+
+ CREATE_PP_GAS( pn2GasItem, PN2, PN2, PN2_ALERT, "pn2threshold", "pn2graph");
+ CREATE_PP_GAS( pheGasItem, PHE, PHE, PHE_ALERT, "phethreshold", "phegraph");
+ CREATE_PP_GAS( po2GasItem, PO2, PO2, PO2_ALERT, "po2threshold", "po2graph");
+#undef CREATE_PP_GAS
background->setFlag(QGraphicsItem::ItemIgnoresTransformations);
@@ -387,6 +379,7 @@ void ProfileWidget2::plotDives(QList<dive*> dives)
int maxtime = get_maxtime(&pInfo);
int maxdepth = get_maxdepth(&pInfo);
+ dataModel->setDive(current_dive, pInfo);
// It seems that I'll have a lot of boilerplate setting the model / axis for
// each item, I'll mostly like to fix this in the future, but I'll keep at this for now.
profileYAxis->setMaximum(maxdepth);
@@ -400,14 +393,7 @@ void ProfileWidget2::plotDives(QList<dive*> dives)
meanDepth->setMeanDepth(pInfo.meandepth);
meanDepth->animateMoveTo(3, profileYAxis->posAtValue(pInfo.meandepth));
- qreal pp = floor(pInfo.maxpp * 10.0) / 10.0 + 0.2;
- gasYAxis->setMaximum(pp);
- gasYAxis->setMinimum(0);
- gasYAxis->setTickInterval(pp > 4 ? 0.5 : 0.25);
- gasYAxis->updateTicks();
-
- dataModel->setDive(current_dive, pInfo);
-
+ dataModel->emitDataChanged();
// The event items are a bit special since we don't know how many events are going to
// exist on a dive, so I cant create cache items for that. that's why they are here
// while all other items are up there on the constructor.