Lubomir, I used a method of yours on the new profile ( the zoom checking. ) can you take a look on why it's not correctly moving the scene around the mouse? I bet it's because the scene().width() is always 100, and scene().height() is also always 100.
Tomaz
From 713264c5a0a901596effd507db716a46ad7dd8e9 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava <[email protected]> Date: Tue, 4 Feb 2014 17:34:16 -0200 Subject: [PATCH 1/4] Created a method to check if calculations should take place. Created a method to check if calculations should take place taking into consideration what changed on the model. if the model changes *everything*, them, all calculations should be done, but if just some of the columns of the model are changed, only those columns should trigger an visual update on the items. In theory this patch looks right, but something is wrong ( calculations are not being made. ), so I'll commit this any how, and fix on the next commit. Signed-off-by: Tomaz Canabrava <[email protected]> --- profile.c | 2 +- profile.h | 1 + qt-ui/profile/diveplotdatamodel.cpp | 33 +++++++++++------ qt-ui/profile/diveplotdatamodel.h | 10 +++-- qt-ui/profile/diveprofileitem.cpp | 73 ++++++++++++++++++++++++------------- qt-ui/profile/diveprofileitem.h | 26 +++++++++---- 6 files changed, 96 insertions(+), 49 deletions(-) diff --git a/profile.c b/profile.c index 66e7a13..6a20dce 100644 --- a/profile.c +++ b/profile.c @@ -1151,7 +1151,7 @@ static void calculate_ndl_tts(double tissue_tolerance, struct plot_data *entry, /* Let's try to do some deco calculations. * Needs to be run before calculate_gas_information so we know that if we have a po2, where in ccr-mode. */ -static void calculate_deco_information(struct dive *dive, struct divecomputer *dc, struct plot_info *pi, bool print_mode) +void calculate_deco_information(struct dive *dive, struct divecomputer *dc, struct plot_info *pi, bool print_mode) { int i; double surface_pressure = (dc->surface_pressure.mbar ? dc->surface_pressure.mbar : get_surface_pressure_in_mbar(dive, true)) / 1000.0; diff --git a/profile.h b/profile.h index 94b32a3..7270eda 100644 --- a/profile.h +++ b/profile.h @@ -53,6 +53,7 @@ void compare_samples(struct plot_data *e1, struct plot_data *e2, char *buf, int struct plot_data *populate_plot_entries(struct dive *dive, struct divecomputer *dc, struct plot_info *pi); struct plot_info *analyze_plot_info(struct plot_info *pi); void create_plot_info_new(struct dive *dive, struct divecomputer *dc, struct plot_info *pi); +void calculate_deco_information(struct dive *dive, struct divecomputer *dc, struct plot_info *pi, bool print_mode); struct ev_select { char *ev_name; diff --git a/qt-ui/profile/diveplotdatamodel.cpp b/qt-ui/profile/diveplotdatamodel.cpp index 362eb01..31941fe 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 6f4929b..e84645b 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 335d5ec..05791ee 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 980b992..4dd32b9 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); -- 1.8.5.3
From 3776da8dc01277dff2e5a5a7c79b41e2c59022a5 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava <[email protected]> Date: Tue, 4 Feb 2014 19:21:57 -0200 Subject: [PATCH 2/4] Optimizations and fixes on the new profile. This patch optimizes a few items when hitting the 'save preferences' dialog, since when a preference is modified, all the items try to reload their visual based on wether a preference changed or not, the correct code for 'hey, my pref changed, let's update' needed to be done. now the axis will only set a new maximum if it's different from the old one ( and thus, going to a new dive with the same maxdepth or maxtime as the old one will not touch their axis, not triggering gratuitous animations. ) also, the 'incr by 3m' was not being called - it seems that our 'syncsettings' method is not storing things on the 'prefs' global var. I added just for the incr by 3m case, but it's something that we need to check later. Signed-off-by: Tomaz Canabrava <[email protected]> --- qt-ui/preferences.cpp | 1 + qt-ui/profile/divecartesianaxis.cpp | 14 +++++++++++++- qt-ui/profile/divecartesianaxis.h | 2 ++ qt-ui/profile/diveprofileitem.cpp | 3 +-- qt-ui/profile/diveprofileitem.h | 2 +- 5 files changed, 18 insertions(+), 4 deletions(-) diff --git a/qt-ui/preferences.cpp b/qt-ui/preferences.cpp index fdee356..34a165c 100644 --- a/qt-ui/preferences.cpp +++ b/qt-ui/preferences.cpp @@ -157,6 +157,7 @@ void PreferencesDialog::syncSettings() SB("redceiling", ui.red_ceiling); SB("calcceiling", ui.calculated_ceiling); SB("calcceiling3m", ui.increment_3m); + prefs.calc_ceiling_3m_incr = ui.increment_3m->isChecked() ? 1 : 0; SB("calcndltts", ui.calc_ndl_tts); SB("calcalltissues", ui.all_tissues); s.setValue("gflow", ui.gflow->value()); diff --git a/qt-ui/profile/divecartesianaxis.cpp b/qt-ui/profile/divecartesianaxis.cpp index 7c91281..c6567d4 100644 --- a/qt-ui/profile/divecartesianaxis.cpp +++ b/qt-ui/profile/divecartesianaxis.cpp @@ -21,12 +21,16 @@ static QPen gridPen(){ } void DiveCartesianAxis::setMaximum(double maximum) { + if (max == maximum) + return; max = maximum; emit maxChanged(); } void DiveCartesianAxis::setMinimum(double minimum) { + if (min == minimum) + return; min = minimum; } @@ -255,7 +259,7 @@ QColor DepthAxis::colorForValue(double value) return QColor(Qt::red); } -DepthAxis::DepthAxis() +DepthAxis::DepthAxis() : showWithPPGraph(false) { connect(PreferencesDialog::instance(), SIGNAL(settingsChanged()), this, SLOT(settingsChanged())); settingsChanged(); // force the correct size of the line. @@ -267,11 +271,16 @@ void DepthAxis::settingsChanged() s.beginGroup("TecDetails"); bool ppGraph = s.value("phegraph").toBool() || s.value("po2graph").toBool() || s.value("pn2graph").toBool(); + if ( ppGraph == showWithPPGraph){ + return; + } + if (ppGraph) { animateChangeLine(QLineF(0,2,0,60)); } else { animateChangeLine(QLineF(0,2,0,98)); } + showWithPPGraph = ppGraph; } QColor TimeAxis::colorForValue(double value) @@ -419,6 +428,9 @@ void PartialGasPressureAxis::preferencesChanged() max = model->po2Max(); qreal pp = floor(max * 10.0) / 10.0 + 0.2; + if (maximum() == pp) + return; + setMaximum(pp); setTickInterval( pp > 4 ? 0.5 : 0.25 ); updateTicks(); diff --git a/qt-ui/profile/divecartesianaxis.h b/qt-ui/profile/divecartesianaxis.h index 3f18fe8..f321983 100644 --- a/qt-ui/profile/divecartesianaxis.h +++ b/qt-ui/profile/divecartesianaxis.h @@ -63,6 +63,8 @@ protected: QColor colorForValue(double value); private slots: void settingsChanged(); +private: + bool showWithPPGraph; }; class TimeAxis : public DiveCartesianAxis { diff --git a/qt-ui/profile/diveprofileitem.cpp b/qt-ui/profile/diveprofileitem.cpp index 05791ee..11d80e9 100644 --- a/qt-ui/profile/diveprofileitem.cpp +++ b/qt-ui/profile/diveprofileitem.cpp @@ -471,9 +471,8 @@ void DiveCalculatedCeiling::preferencesChanged() if ( dataModel && is3mIncrement != shouldShow3mIncrement){ // recalculate that part. dataModel->calculateDecompression(); - is3mIncrement = shouldShow3mIncrement; } - + is3mIncrement = shouldShow3mIncrement; setVisible(s.value("calcceiling").toBool()); } diff --git a/qt-ui/profile/diveprofileitem.h b/qt-ui/profile/diveprofileitem.h index 4dd32b9..1f9fa26 100644 --- a/qt-ui/profile/diveprofileitem.h +++ b/qt-ui/profile/diveprofileitem.h @@ -123,7 +123,7 @@ class DiveCalculatedTissue : public DiveCalculatedCeiling { Q_OBJECT public: DiveCalculatedTissue(); - void preferencesChanged(); + virtual void preferencesChanged(); }; class MeanDepthLine : public DiveLineItem { -- 1.8.5.3
From da5908ceb3295223f704fcad4a8af2cef1df4358 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava <[email protected]> Date: Tue, 4 Feb 2014 21:24:08 -0200 Subject: [PATCH 3/4] Fix hiding the tissues when user set 'show ceiling' to false. Signed-off-by: Tomaz Canabrava <[email protected]> --- qt-ui/profile/diveprofileitem.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qt-ui/profile/diveprofileitem.cpp b/qt-ui/profile/diveprofileitem.cpp index 11d80e9..e7cf7cf 100644 --- a/qt-ui/profile/diveprofileitem.cpp +++ b/qt-ui/profile/diveprofileitem.cpp @@ -432,7 +432,7 @@ void DiveCalculatedTissue::preferencesChanged() { QSettings s; s.beginGroup("TecDetails"); - setVisible(s.value("calcalltissues").toBool()); + setVisible(s.value("calcalltissues").toBool() && s.value("calcceiling").toBool()); } void DiveReportedCeiling::modelDataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight) -- 1.8.5.3
From faf26ed7c61af6a2c8fd06699d5a636c0cbbf0b5 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava <[email protected]> Date: Tue, 4 Feb 2014 21:47:50 -0200 Subject: [PATCH 4/4] Added Mouse based Zoom / Movement. This patch uses the same code that lubomir used on the old profile. It strangely didn't worked - most probably because the scene has a fixed width() and height() of 100. the zoom works, and the movement works, but only on the 100 first pixels of the profile. Signed-off-by: Tomaz Canabrava <[email protected]> --- qt-ui/profile/profilewidget2.cpp | 73 +++++++++++++++++++++++++++++++++++++++- qt-ui/profile/profilewidget2.h | 5 ++- 2 files changed, 76 insertions(+), 2 deletions(-) diff --git a/qt-ui/profile/profilewidget2.cpp b/qt-ui/profile/profilewidget2.cpp index 3a65fdd..0de1196 100644 --- a/qt-ui/profile/profilewidget2.cpp +++ b/qt-ui/profile/profilewidget2.cpp @@ -14,6 +14,7 @@ #include <QMenu> #include <QContextMenuEvent> #include <QDebug> +#include <QScrollBar> #ifndef QT_NO_DEBUG #include <QTableView> @@ -24,6 +25,7 @@ ProfileWidget2::ProfileWidget2(QWidget *parent) : QGraphicsView(parent), dataModel(new DivePlotDataModel(this)), currentState(INVALID), + zoomLevel(0), stateMachine(new QStateMachine(this)), background (new DivePixmapItem()), profileYAxis(new DepthAxis()), @@ -50,7 +52,7 @@ ProfileWidget2::ProfileWidget2(QWidget *parent) : setOptimizationFlags(QGraphicsView::DontSavePainterState); setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate); setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform); - + setMouseTracking(true); // Creating the needed items. // ORDER: {BACKGROUND, PROFILE_Y_AXIS, GAS_Y_AXIS, TIME_AXIS, DEPTH_CONTROLLER, TIME_CONTROLLER, COLUMNS}; profileYAxis->setOrientation(DiveCartesianAxis::TopToBottom); @@ -476,3 +478,72 @@ void ProfileWidget2::fixBackgroundPos() bg->setPixmap(p); bg->setX(mapToScene(x, 0).x()); } + +void ProfileWidget2::wheelEvent(QWheelEvent* event) +{ +// if (!toolTip) +// return; + + // doesn't seem to work for Qt 4.8.1 + // setTransformationAnchor(QGraphicsView::AnchorUnderMouse); + + // Scale the view / do the zoom +// QPoint toolTipPos = mapFromScene(toolTip->pos()); + + double scaleFactor = 1.15; + if (event->delta() > 0 && zoomLevel < 20) { + scale(scaleFactor, scaleFactor); + zoomLevel++; + } else if (event->delta() < 0 && zoomLevel > 0) { + // Zooming out + scale(1.0 / scaleFactor, 1.0 / scaleFactor); + zoomLevel--; + } + + scrollViewTo(event->pos()); +// toolTip->setPos(mapToScene(toolTipPos)); +// toolBarProxy->setPos(mapToScene(TOOLBAR_POS)); +// if (zoomLevel != 0) { +// toolBarProxy->hide(); +// } else { +// toolBarProxy->show(); +// } +} + +void ProfileWidget2::scrollViewTo(const QPoint& pos) +{ +/* since we cannot use translate() directly on the scene we hack on + * the scroll bars (hidden) functionality */ + if (!zoomLevel) + return; + QScrollBar *vs = verticalScrollBar(); + QScrollBar *hs = horizontalScrollBar(); + const qreal yRat = pos.y() / sceneRect().height(); + const qreal xRat = pos.x() / sceneRect().width(); + const int vMax = vs->maximum(); + const int hMax = hs->maximum(); + const int vMin = vs->minimum(); + const int hMin = hs->minimum(); + /* QScrollBar receives crazy negative values for minimum */ + vs->setValue(yRat * (vMax - vMin) + vMin * 0.9); + hs->setValue(xRat * (hMax - hMin) + hMin * 0.9); +} + +void ProfileWidget2::mouseMoveEvent(QMouseEvent* event) +{ +// if (!toolTip) +// return; +// +// toolTip->refresh(&gc, mapToScene(event->pos())); +// QPoint toolTipPos = mapFromScene(toolTip->pos()); + + + if (zoomLevel == 0) { + QGraphicsView::mouseMoveEvent(event); + } else {/* + toolTip->setPos(mapToScene(toolTipPos)); + toolBarProxy->setPos(mapToScene(TOOLBAR_POS));*/ + scrollViewTo(event->pos()); + } +} + diff --git a/qt-ui/profile/profilewidget2.h b/qt-ui/profile/profilewidget2.h index df4a844..a89cef7 100644 --- a/qt-ui/profile/profilewidget2.h +++ b/qt-ui/profile/profilewidget2.h @@ -43,6 +43,7 @@ struct PartialGasPressureAxis; class ProfileWidget2 : public QGraphicsView { Q_OBJECT void fixBackgroundPos(); + void scrollViewTo(const QPoint& pos); public: enum State{ EMPTY, PROFILE, EDIT, ADD, PLAN, INVALID }; enum Items{BACKGROUND, PROFILE_Y_AXIS, GAS_Y_AXIS, TIME_AXIS, DEPTH_CONTROLLER, TIME_CONTROLLER, COLUMNS}; @@ -55,6 +56,8 @@ public slots: // Necessary to call from QAction's signals. protected: virtual void contextMenuEvent(QContextMenuEvent* event); virtual void resizeEvent(QResizeEvent* event); + virtual void wheelEvent(QWheelEvent* event); + virtual void mouseMoveEvent(QMouseEvent* event); signals: void startProfileState(); @@ -70,7 +73,7 @@ private: DivePlotDataModel *dataModel; State currentState; QStateMachine *stateMachine; - + int zoomLevel; DivePixmapItem *background ; // All those here should probably be merged into one structure, // So it's esyer to replicate for more dives later. -- 1.8.5.3
_______________________________________________ subsurface mailing list [email protected] http://lists.hohndel.org/cgi-bin/mailman/listinfo/subsurface
