summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--profile.c61
-rw-r--r--profile.h3
-rw-r--r--qt-ui/profile/profilewidget2.cpp41
3 files changed, 104 insertions, 1 deletions
diff --git a/profile.c b/profile.c
index c43bd083b..528818760 100644
--- a/profile.c
+++ b/profile.c
@@ -717,6 +717,67 @@ static void check_gas_change_events(struct dive *dive, struct divecomputer *dc,
set_cylinder_index(pi, i, cylinderindex, ~0u);
}
+
+struct plot_info calculate_max_limits_new(struct dive *dive, struct divecomputer *dc)
+{
+ struct plot_info pi;
+ int maxdepth = dive->maxdepth.mm;
+ int maxtime = 0;
+ int maxpressure = 0, minpressure = INT_MAX;
+ int mintemp = dive->mintemp.mkelvin;
+ int maxtemp = dive->maxtemp.mkelvin;
+ int cyl;
+
+ /* Get the per-cylinder maximum pressure if they are manual */
+ for (cyl = 0; cyl < MAX_CYLINDERS; cyl++) {
+ unsigned int mbar = dive->cylinder[cyl].start.mbar;
+ if (mbar > maxpressure)
+ maxpressure = mbar;
+ }
+
+ /* Then do all the samples from all the dive computers */
+ do {
+ int i = dc->samples;
+ int lastdepth = 0;
+ struct sample *s = dc->sample;
+
+ while (--i >= 0) {
+ int depth = s->depth.mm;
+ int pressure = s->cylinderpressure.mbar;
+ int temperature = s->temperature.mkelvin;
+
+ if (!mintemp && temperature < mintemp)
+ mintemp = temperature;
+ if (temperature > maxtemp)
+ maxtemp = temperature;
+
+ if (pressure && pressure < minpressure)
+ minpressure = pressure;
+ if (pressure > maxpressure)
+ maxpressure = pressure;
+
+ if (depth > maxdepth)
+ maxdepth = s->depth.mm;
+ if ((depth > SURFACE_THRESHOLD || lastdepth > SURFACE_THRESHOLD) &&
+ s->time.seconds > maxtime)
+ maxtime = s->time.seconds;
+ lastdepth = depth;
+ s++;
+ }
+ } while ((dc = dc->next) != NULL);
+
+ if (minpressure > maxpressure)
+ minpressure = 0;
+
+ pi.maxdepth = maxdepth;
+ pi.maxtime = maxtime;
+ pi.maxpressure = maxpressure;
+ pi.minpressure = minpressure;
+ pi.mintemp = mintemp;
+ pi.maxtemp = maxtemp;
+ return pi;
+}
+
void calculate_max_limits(struct dive *dive, struct divecomputer *dc, struct graphics_context *gc)
{
struct plot_info *pi;
diff --git a/profile.h b/profile.h
index a7a48b51e..daf402d52 100644
--- a/profile.h
+++ b/profile.h
@@ -43,8 +43,9 @@ struct plot_data {
int stopdepth_calc;
int pressure_time;
};
-
+//TODO: remove the calculatE_max_limits as soon as the new profile is done.
void calculate_max_limits(struct dive *dive, struct divecomputer *dc, struct graphics_context *gc);
+struct plot_info calculate_max_limits_new(struct dive *dive, struct divecomputer *dc);
struct plot_info *create_plot_info(struct dive *dive, struct divecomputer *dc, struct graphics_context *gc, bool print_mode);
int setup_temperature_limits(struct graphics_context *gc);
int get_cylinder_pressure_range(struct graphics_context *gc);
diff --git a/qt-ui/profile/profilewidget2.cpp b/qt-ui/profile/profilewidget2.cpp
index 067fc97fb..68b42f1b9 100644
--- a/qt-ui/profile/profilewidget2.cpp
+++ b/qt-ui/profile/profilewidget2.cpp
@@ -5,6 +5,7 @@
#include "divecartesianaxis.h"
#include "diveprofileitem.h"
#include "helpers.h"
+#include "profile.h"
#include <QStateMachine>
#include <QSignalTransition>
@@ -228,7 +229,47 @@ ProfileWidget2::ProfileWidget2(QWidget *parent) :
// Currently just one dive, but the plan is to enable All of the selected dives.
void ProfileWidget2::plotDives(QList<dive*> dives)
{
+ // I Know that it's a list, but currently we are
+ // using just the first.
+ struct dive *d = dives.first();
+ if(!d)
+ return;
+ // Here we need to probe for the limits of the dive.
+ // There's already a function that does exactly that,
+ // but it's using the graphics context, and I need to
+ // replace that.
+ struct divecomputer *currentdc = select_dc(&d->dc);
+ Q_ASSERT(currentdc);
+
+ /* This struct holds all the data that's about to be plotted.
+ * I'm not sure this is the best approach ( but since we are
+ * interpolating some points of the Dive, maybe it is... )
+ * The Calculation of the points should be done per graph,
+ * so I'll *not* calculate everything if something is not being
+ * shown.
+ */
+ struct plot_info pInfo = calculate_max_limits_new(d, currentdc);
+
+ profileYAxis->setMaximum(pInfo.maxdepth);
+ profileYAxis->updateTicks();
+ timeAxis->setMaximum(pInfo.maxtime);
+ timeAxis->updateTicks();
+ dataModel->setDive(current_dive, pInfo);
+
+ if(diveProfileItem){
+ //diveProfileItem->animateDelete();
+ scene()->removeItem(diveProfileItem);
+ delete diveProfileItem;
+ }
+ diveProfileItem = new DiveProfileItem();
+ diveProfileItem->setHorizontalAxis(timeAxis);
+ diveProfileItem->setVerticalAxis(profileYAxis);
+ diveProfileItem->setModel(dataModel);
+ diveProfileItem->setVerticalDataColumn(DivePlotDataModel::DEPTH);
+ diveProfileItem->setHorizontalDataColumn(DivePlotDataModel::TIME);
+ scene()->addItem(diveProfileItem);
+ emit startProfileState();
}
void ProfileWidget2::settingsChanged()