aboutsummaryrefslogtreecommitdiffstats
path: root/qt-ui/profile
diff options
context:
space:
mode:
Diffstat (limited to 'qt-ui/profile')
-rw-r--r--qt-ui/profile/diveplotdatamodel.cpp33
-rw-r--r--qt-ui/profile/diveplotdatamodel.h10
-rw-r--r--qt-ui/profile/diveprofileitem.cpp73
-rw-r--r--qt-ui/profile/diveprofileitem.h26
4 files changed, 94 insertions, 48 deletions
diff --git a/qt-ui/profile/diveplotdatamodel.cpp b/qt-ui/profile/diveplotdatamodel.cpp
index 362eb018b..31941fef7 100644
--- a/qt-ui/profile/diveplotdatamodel.cpp
+++ b/qt-ui/profile/diveplotdatamodel.cpp
@@ -5,11 +5,12 @@
#include "graphicsview-common.h"
#include "dive.h"
#include "display.h"
+#include "divelist.h"
#include <QDebug>
-DivePlotDataModel::DivePlotDataModel(QObject* parent): QAbstractTableModel(parent), sampleCount(0), plotData(NULL)
+DivePlotDataModel::DivePlotDataModel(QObject* parent): QAbstractTableModel(parent)
{
-
+ pInfo.nr = 0;
}
int DivePlotDataModel::columnCount(const QModelIndex& parent) const
@@ -22,7 +23,7 @@ QVariant DivePlotDataModel::data(const QModelIndex& index, int role) const
if (!index.isValid())
return QVariant();
- plot_data item = plotData[index.row()];
+ plot_data item = pInfo.entry[index.row()];
if (role == Qt::DisplayRole) {
switch (index.column()) {
case DEPTH: return item.depth;
@@ -54,14 +55,14 @@ QVariant DivePlotDataModel::data(const QModelIndex& index, int role) const
return QVariant();
}
-plot_data* DivePlotDataModel::data()
+const plot_info& DivePlotDataModel::data() const
{
- return plotData;
+ return pInfo;
}
int DivePlotDataModel::rowCount(const QModelIndex& parent) const
{
- return sampleCount;
+ return pInfo.nr;
}
QVariant DivePlotDataModel::headerData(int section, Qt::Orientation orientation, int role) const
@@ -102,7 +103,7 @@ void DivePlotDataModel::clear()
}
}
-void DivePlotDataModel::setDive(dive* d,const plot_info& pInfo)
+void DivePlotDataModel::setDive(dive* d, const plot_info& info)
{
// We need a way to find out if the dive setted is the same old dive, but pointers change,
// and there's no UUID, for now, just repopulate everything.
@@ -112,9 +113,8 @@ void DivePlotDataModel::setDive(dive* d,const plot_info& pInfo)
if (d)
dc = select_dc(&d->dc);
diveId = d->id;
- plotData = pInfo.entry;
- sampleCount = pInfo.nr;
- beginInsertRows(QModelIndex(), 0, sampleCount-1);
+ pInfo = info;
+ beginInsertRows(QModelIndex(), 0, pInfo.nr-1);
endInsertRows();
}
@@ -128,8 +128,8 @@ double DivePlotDataModel::GASFUNC() \
{ \
double ret = -1; \
for(int i = 0, count = rowCount(); i < count; i++){ \
- if (plotData[i].GAS > ret) \
- ret = plotData[i].GAS; \
+ if (pInfo.entry[i].GAS > ret) \
+ ret = pInfo.entry[i].GAS; \
} \
return ret; \
}
@@ -142,3 +142,12 @@ void DivePlotDataModel::emitDataChanged()
{
emit dataChanged(QModelIndex(), QModelIndex());
}
+
+void DivePlotDataModel::calculateDecompression()
+{
+ struct dive *d = getDiveById(id());
+ struct divecomputer *dc = select_dc(&d->dc);
+ init_decompression(d);
+ calculate_deco_information(d, dc, &pInfo, FALSE);
+ dataChanged(index(0, CEILING), index(pInfo.nr-1, TISSUE_16));
+}
diff --git a/qt-ui/profile/diveplotdatamodel.h b/qt-ui/profile/diveplotdatamodel.h
index 6f4929bb2..e84645b40 100644
--- a/qt-ui/profile/diveplotdatamodel.h
+++ b/qt-ui/profile/diveplotdatamodel.h
@@ -3,6 +3,8 @@
#include <QAbstractTableModel>
+#include "display.h"
+
struct dive;
struct plot_data;
struct plot_info;
@@ -19,16 +21,16 @@ public:
virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
virtual int rowCount(const QModelIndex& parent = QModelIndex()) const;
void clear();
- void setDive(struct dive *d, const plot_info& pInfo);
- plot_data* data();
+ void setDive(struct dive *d, const plot_info& pInfo);
+ const plot_info& data() const;
int id() const;
double pheMax();
double pn2Max();
double po2Max();
void emitDataChanged();
+ void calculateDecompression();
private:
- int sampleCount;
- plot_data *plotData;
+ plot_info pInfo;
int diveId;
};
diff --git a/qt-ui/profile/diveprofileitem.cpp b/qt-ui/profile/diveprofileitem.cpp
index 335d5ecf6..05791eed5 100644
--- a/qt-ui/profile/diveprofileitem.cpp
+++ b/qt-ui/profile/diveprofileitem.cpp
@@ -43,7 +43,7 @@ void AbstractProfilePolygonItem::setHorizontalDataColumn(int column)
void AbstractProfilePolygonItem::setModel(DivePlotDataModel* model)
{
dataModel = model;
- connect(dataModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelDataChanged()));
+ connect(dataModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelDataChanged(QModelIndex, QModelIndex)));
modelDataChanged();
}
@@ -61,11 +61,26 @@ void AbstractProfilePolygonItem::setVerticalDataColumn(int column)
modelDataChanged();
}
-void AbstractProfilePolygonItem::modelDataChanged()
+bool AbstractProfilePolygonItem::shouldCalculateStuff(const QModelIndex& topLeft, const QModelIndex& bottomRight)
+{
+ if (!hAxis || !vAxis)
+ return false;
+ if (!dataModel || dataModel->rowCount() == 0)
+ return false;
+ if (hDataColumn == -1 || vDataColumn == -1)
+ return false;
+ if ( topLeft.isValid() && bottomRight.isValid()){
+ if ((topLeft.column() >= vDataColumn || topLeft.column() >= hDataColumn ) &&
+ (bottomRight.column() <= vDataColumn || topLeft.column() <= hDataColumn )){
+ return true;
+ }
+ }
+ return true;
+}
+
+void AbstractProfilePolygonItem::modelDataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight)
{
// We don't have enougth data to calculate things, quit.
- if (!hAxis || !vAxis || !dataModel || hDataColumn == -1 || vDataColumn == -1)
- return;
// Calculate the polygon. This is the polygon that will be painted on screen
// on the ::paint method. Here we calculate the correct position of the points
@@ -107,12 +122,12 @@ void DiveProfileItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* o
}
}
-void DiveProfileItem::modelDataChanged()
+void DiveProfileItem::modelDataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight)
{
- if (!hAxis || !vAxis || !dataModel || hDataColumn == -1 || vDataColumn == -1 || dataModel->rowCount() == 0)
+ if(!shouldCalculateStuff(topLeft, bottomRight))
return;
- AbstractProfilePolygonItem::modelDataChanged();
+ AbstractProfilePolygonItem::modelDataChanged(topLeft, bottomRight);
if (polygon().isEmpty())
return;
@@ -122,7 +137,7 @@ void DiveProfileItem::modelDataChanged()
/* Show any ceiling we may have encountered */
if (prefs.profile_dc_ceiling && !prefs.profile_red_ceiling) {
QPolygonF p = polygon();
- plot_data *entry = dataModel->data() + dataModel->rowCount()-1;
+ plot_data *entry = dataModel->data().entry + dataModel->rowCount()-1;
for (int i = dataModel->rowCount() - 1; i >= 0; i--, entry--) {
if (!entry->in_deco) {
/* not in deco implies this is a safety stop, no ceiling */
@@ -146,7 +161,7 @@ void DiveProfileItem::modelDataChanged()
int last = -1;
for (int i = 0, count = dataModel->rowCount(); i < count; i++) {
- struct plot_data *entry = dataModel->data()+i;
+ struct plot_data *entry = dataModel->data().entry+i;
if (entry->depth < 2000)
continue;
@@ -194,10 +209,10 @@ DiveTemperatureItem::DiveTemperatureItem()
setPen(pen);
}
-void DiveTemperatureItem::modelDataChanged()
+void DiveTemperatureItem::modelDataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight)
{
// We don't have enougth data to calculate things, quit.
- if (!hAxis || !vAxis || !dataModel || hDataColumn == -1 || vDataColumn == -1 || dataModel->rowCount() == 0)
+ if (!shouldCalculateStuff(topLeft, bottomRight))
return;
qDeleteAll(texts);
@@ -260,10 +275,10 @@ void DiveTemperatureItem::paint(QPainter* painter, const QStyleOptionGraphicsIte
painter->drawPolyline(polygon());
}
-void DiveGasPressureItem::modelDataChanged()
+void DiveGasPressureItem::modelDataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight)
{
// We don't have enougth data to calculate things, quit.
- if (!hAxis || !vAxis || !dataModel || hDataColumn == -1 || vDataColumn == -1 || dataModel->rowCount() == 0)
+ if (!shouldCalculateStuff(topLeft, bottomRight))
return;
int last_index = -1;
int lift_pen = false;
@@ -272,7 +287,7 @@ void DiveGasPressureItem::modelDataChanged()
polygons.clear();
for (int i = 0, count = dataModel->rowCount(); i < count; i++) {
- plot_data* entry = dataModel->data() + i;
+ plot_data* entry = dataModel->data().entry + i;
int mbar = GET_PRESSURE(entry);
if (entry->cylinderindex != last_index) {
@@ -300,7 +315,7 @@ void DiveGasPressureItem::modelDataChanged()
cyl = -1;
for (int i = 0, count = dataModel->rowCount(); i < count; i++) {
- entry = dataModel->data() + i;
+ entry = dataModel->data().entry + i;
mbar = GET_PRESSURE(entry);
if (!mbar)
@@ -357,7 +372,7 @@ void DiveGasPressureItem::paint(QPainter* painter, const QStyleOptionGraphicsIte
pen.setCosmetic(true);
pen.setWidth(2);
struct dive *d = getDiveById(dataModel->id());
- struct plot_data *entry = dataModel->data();
+ struct plot_data *entry = dataModel->data().entry;
Q_FOREACH(const QPolygonF& poly, polygons) {
for (int i = 1, count = poly.count(); i < count; i++, entry++) {
pen.setBrush(getSacColor(entry->sac, d->sac));
@@ -376,12 +391,12 @@ DiveCalculatedCeiling::DiveCalculatedCeiling()
preferencesChanged();
}
-void DiveCalculatedCeiling::modelDataChanged()
+void DiveCalculatedCeiling::modelDataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight)
{
// We don't have enougth data to calculate things, quit.
- if (!hAxis || !vAxis || !dataModel || hDataColumn == -1 || vDataColumn == -1)
+ if (!shouldCalculateStuff(topLeft, bottomRight))
return;
- AbstractProfilePolygonItem::modelDataChanged();
+ AbstractProfilePolygonItem::modelDataChanged(topLeft, bottomRight);
// Add 2 points to close the polygon.
QPolygonF poly = polygon();
if (poly.isEmpty())
@@ -420,14 +435,14 @@ void DiveCalculatedTissue::preferencesChanged()
setVisible(s.value("calcalltissues").toBool());
}
-void DiveReportedCeiling::modelDataChanged()
+void DiveReportedCeiling::modelDataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight)
{
- if (!hAxis || !vAxis || !dataModel || hDataColumn == -1 || vDataColumn == -1)
+ if(!shouldCalculateStuff(topLeft, bottomRight))
return;
QPolygonF p;
p.append(QPointF(hAxis->posAtValue(0), vAxis->posAtValue(0)));
- plot_data *entry = dataModel->data();
+ plot_data *entry = dataModel->data().entry;
for (int i = 0, count = dataModel->rowCount(); i < count; i++, entry++) {
if (entry->in_deco && entry->stopdepth) {
if (entry->stopdepth < entry->depth) {
@@ -451,6 +466,14 @@ void DiveCalculatedCeiling::preferencesChanged()
{
QSettings s;
s.beginGroup("TecDetails");
+
+ bool shouldShow3mIncrement = s.value("calcceiling3m").toBool();
+ if ( dataModel && is3mIncrement != shouldShow3mIncrement){
+ // recalculate that part.
+ dataModel->calculateDecompression();
+ is3mIncrement = shouldShow3mIncrement;
+ }
+
setVisible(s.value("calcceiling").toBool());
}
@@ -491,13 +514,13 @@ void MeanDepthLine::setMeanDepth(int value)
rightText->setText(get_depth_string(value, false, false));
}
-void PartialPressureGasItem::modelDataChanged()
+void PartialPressureGasItem::modelDataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight)
{
//AbstractProfilePolygonItem::modelDataChanged();
- if (!hAxis || !vAxis || !dataModel || hDataColumn == -1 || vDataColumn == -1 || dataModel->rowCount() == 0)
+ if (!shouldCalculateStuff(topLeft, bottomRight))
return;
- plot_data *entry = dataModel->data();
+ plot_data *entry = dataModel->data().entry;
QPolygonF poly;
alertPoly.clear();
QSettings s;
diff --git a/qt-ui/profile/diveprofileitem.h b/qt-ui/profile/diveprofileitem.h
index 980b99213..4dd32b9fa 100644
--- a/qt-ui/profile/diveprofileitem.h
+++ b/qt-ui/profile/diveprofileitem.h
@@ -3,6 +3,8 @@
#include <QObject>
#include <QGraphicsPolygonItem>
+#include <QModelIndex>
+
#include "graphicsview-common.h"
#include "divelineitem.h"
@@ -41,8 +43,17 @@ public:
virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0) = 0;
public slots:
virtual void preferencesChanged();
- virtual void modelDataChanged();
+ virtual void modelDataChanged(const QModelIndex& topLeft = QModelIndex(), const QModelIndex& bottomRight = QModelIndex());
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'
+ * the data for Ceiling and tissues will be changed, and only those. so, the topLeft will be the CEILING
+ * column and the bottomRight will have the TISSUE_16 column. this method takes the vDataColumn and hDataColumn
+ * into consideration when returning 'true' for "yes, continue the calculation', and 'false' for
+ * 'do not recalculate, we already have the right data.
+ */
+ bool shouldCalculateStuff(const QModelIndex& topLeft, const QModelIndex& bottomRight);
+
DiveCartesianAxis *hAxis;
DiveCartesianAxis *vAxis;
DivePlotDataModel *dataModel;
@@ -56,7 +67,7 @@ class DiveProfileItem : public AbstractProfilePolygonItem{
public:
virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0);
- virtual void modelDataChanged();
+ virtual void modelDataChanged(const QModelIndex& topLeft = QModelIndex(), const QModelIndex& bottomRight = QModelIndex());
virtual void preferencesChanged();
void plot_depth_sample(struct plot_data *entry,QFlags<Qt::AlignmentFlag> flags,const QColor& color);
private:
@@ -68,7 +79,7 @@ class DiveTemperatureItem : public AbstractProfilePolygonItem{
Q_OBJECT
public:
DiveTemperatureItem();
- virtual void modelDataChanged();
+ virtual void modelDataChanged(const QModelIndex& topLeft = QModelIndex(), const QModelIndex& bottomRight = QModelIndex());
virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0);
private:
void createTextItem(int seconds, int mkelvin);
@@ -78,7 +89,7 @@ class DiveGasPressureItem : public AbstractProfilePolygonItem{
Q_OBJECT
public:
- virtual void modelDataChanged();
+ virtual void modelDataChanged(const QModelIndex& topLeft = QModelIndex(), const QModelIndex& bottomRight = QModelIndex());
virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0);
private:
void plot_pressure_value(int mbar, int sec, QFlags<Qt::AlignmentFlag> align);
@@ -91,10 +102,11 @@ class DiveCalculatedCeiling : public AbstractProfilePolygonItem{
public:
DiveCalculatedCeiling();
- virtual void modelDataChanged();
+ virtual void modelDataChanged(const QModelIndex& topLeft = QModelIndex(), const QModelIndex& bottomRight = QModelIndex());
virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0);
virtual void preferencesChanged();
private:
+ bool is3mIncrement;
DiveTextItem *gradientFactor;
};
@@ -102,7 +114,7 @@ class DiveReportedCeiling : public AbstractProfilePolygonItem{
Q_OBJECT
public:
- virtual void modelDataChanged();
+ virtual void modelDataChanged(const QModelIndex& topLeft = QModelIndex(), const QModelIndex& bottomRight = QModelIndex());
virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0);
virtual void preferencesChanged();
};
@@ -131,7 +143,7 @@ class PartialPressureGasItem : public AbstractProfilePolygonItem{
public:
PartialPressureGasItem();
virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0);
- virtual void modelDataChanged();
+ virtual void modelDataChanged(const QModelIndex& topLeft = QModelIndex(), const QModelIndex& bottomRight = QModelIndex());
virtual void preferencesChanged();
void setThreshouldSettingsKey(const QString& threshouldSettingsKey);
void setVisibilitySettingsKey(const QString& setVisibilitySettingsKey);