diff options
Diffstat (limited to 'qt-ui/profile')
-rw-r--r-- | qt-ui/profile/divecartesianaxis.cpp | 2 | ||||
-rw-r--r-- | qt-ui/profile/diveeventitem.cpp | 4 | ||||
-rw-r--r-- | qt-ui/profile/diveprofileitem.cpp | 48 | ||||
-rw-r--r-- | qt-ui/profile/divetextitem.cpp | 1 | ||||
-rw-r--r-- | qt-ui/profile/profilewidget2.cpp | 43 | ||||
-rw-r--r-- | qt-ui/profile/ruleritem.cpp | 8 |
6 files changed, 69 insertions, 37 deletions
diff --git a/qt-ui/profile/divecartesianaxis.cpp b/qt-ui/profile/divecartesianaxis.cpp index 467a8b978..41d94a9a0 100644 --- a/qt-ui/profile/divecartesianaxis.cpp +++ b/qt-ui/profile/divecartesianaxis.cpp @@ -5,6 +5,8 @@ #include "diveplotdatamodel.h" #include "animationfunctions.h" #include "mainwindow.h" +#include "divelineitem.h" +#include "profilewidget2.h" static QPen gridPen() { diff --git a/qt-ui/profile/diveeventitem.cpp b/qt-ui/profile/diveeventitem.cpp index 700430007..0d81e7b45 100644 --- a/qt-ui/profile/diveeventitem.cpp +++ b/qt-ui/profile/diveeventitem.cpp @@ -135,7 +135,9 @@ bool DiveEventItem::shouldBeHidden() * Don't bother showing those */ struct sample *first_sample = &get_dive_dc(&displayed_dive, dc_number)->sample[0]; - if (!strcmp(event->name, "gaschange") && first_sample && event->time.seconds == first_sample->time.seconds) + if (!strcmp(event->name, "gaschange") && + (event->time.seconds == 0 || + (first_sample && event->time.seconds == first_sample->time.seconds))) return true; for (int i = 0; i < evn_used; i++) { diff --git a/qt-ui/profile/diveprofileitem.cpp b/qt-ui/profile/diveprofileitem.cpp index 3bc79832e..7d29d28b4 100644 --- a/qt-ui/profile/diveprofileitem.cpp +++ b/qt-ui/profile/diveprofileitem.cpp @@ -9,6 +9,9 @@ #include "helpers.h" #include "libdivecomputer/parser.h" #include "mainwindow.h" +#include "maintab.h" +#include "profile/profilewidget2.h" +#include "diveplanner.h" #include <QSettings> @@ -166,7 +169,7 @@ void DiveProfileItem::modelDataChanged(const QModelIndex &topLeft, const QModelI for (int i = 0; i < dataModel->rowCount(); i++, entry++) { int max = maxCeiling(i); // Don't scream if we violate the ceiling by a few cm - if (entry->depth < max - 100) { + if (entry->depth < max - 100 && entry->sec > 0) { profileColor = QColor(Qt::red); if (!eventAdded) { add_event(&displayed_dive.dc, entry->sec, SAMPLE_EVENT_CEILING, -1, max / 1000, "planned waypoint above ceiling"); @@ -682,8 +685,8 @@ void DiveGasPressureItem::modelDataChanged(const QModelIndex &topLeft, const QMo bool offsets_initialised = false; int o2cyl = -1, dilcyl = -1; - QFlags<Qt::AlignmentFlag> alignVar, align_dil = Qt::AlignBottom, align_o2 = Qt::AlignBottom; - double axisRange = (vAxis->maximum() - vAxis->minimum())/1000; + QFlags<Qt::AlignmentFlag> alignVar= Qt::AlignTop, align_dil = Qt::AlignBottom, align_o2 = Qt::AlignTop; + double axisRange = (vAxis->maximum() - vAxis->minimum())/1000; // Convert axis pressure range to bar double axisLog = log10(log10(axisRange)); for (int i = 0, count = dataModel->rowCount(); i < count; i++) { entry = dataModel->data().entry + i; @@ -691,23 +694,17 @@ void DiveGasPressureItem::modelDataChanged(const QModelIndex &topLeft, const QMo if (displayed_dive.dc.divemode == CCR && displayed_dive.oxygen_cylinder_index >= 0) o2mbar = GET_O2CYLINDER_PRESSURE(entry); - if (o2mbar) { + if (o2mbar) { // If there is an o2mbar value then this is a CCR dive. Then do: // The first time an o2 value is detected, see if the oxygen cyl pressure graph starts above or below the dil graph if (!offsets_initialised) { // Initialise the parameters for placing the text correctly near the graph line: o2cyl = displayed_dive.oxygen_cylinder_index; dilcyl = displayed_dive.diluent_cylinder_index; if ((o2mbar > mbar)) { // If above, write o2 start cyl pressure above graph and diluent pressure below graph: - print_y_offset[o2cyl][0] = -7 * axisLog; // y offset for oxygen gas lable (above) - print_y_offset[o2cyl][1] = -0.5; // y offset for oxygen start pressure value (above) + print_y_offset[o2cyl][0] = -7 * axisLog; // y offset for oxygen gas lable (above); pressure offsets=-0.5, already initialised print_y_offset[dilcyl][0] = 5 * axisLog; // y offset for diluent gas lable (below) - print_y_offset[dilcyl][1] = 0; // y offset for diluent start pressure value (below) - align_dil = Qt::AlignBottom; - align_o2 = Qt::AlignTop; - } else { // ... else write o2 start cyl pressure below graph: - print_y_offset[o2cyl][0] = 5 * axisLog; // o2 lable & pressure below graph, - print_y_offset[o2cyl][1] = 0; - print_y_offset[dilcyl][0] = -7 * axisLog; // and diluent lable above graph. - print_y_offset[dilcyl][1] = -0.5; // and diluent pressure above graph. + } else { // ... else write o2 start cyl pressure below graph: + print_y_offset[o2cyl][0] = 5 * axisLog; // o2 lable & pressure below graph; pressure offsets=-0.5, already initialised + print_y_offset[dilcyl][0] = -7.8 * axisLog; // and diluent lable above graph. align_dil = Qt::AlignTop; align_o2 = Qt::AlignBottom; } @@ -722,9 +719,6 @@ void DiveGasPressureItem::modelDataChanged(const QModelIndex &topLeft, const QMo last_pressure[displayed_dive.oxygen_cylinder_index] = o2mbar; last_time[displayed_dive.oxygen_cylinder_index] = entry->sec; alignVar = align_dil; - } else { - alignVar = Qt::AlignBottom; - align_dil = Qt::AlignTop; } if (!mbar) @@ -733,29 +727,19 @@ void DiveGasPressureItem::modelDataChanged(const QModelIndex &topLeft, const QMo if (cyl != entry->cylinderindex) { // Pressure value near the left hand edge of the profile - other cylinders: cyl = entry->cylinderindex; // For each other cylinder, write the gas lable and pressure if (!seen_cyl[cyl]) { - plotPressureValue(mbar, entry->sec, alignVar, print_y_offset[cyl][0]); - plotGasValue(mbar, entry->sec, displayed_dive.cylinder[cyl].gasmix, align_dil, print_y_offset[cyl][1]); + plotPressureValue(mbar, entry->sec, alignVar, print_y_offset[cyl][1]); + plotGasValue(mbar, entry->sec, displayed_dive.cylinder[cyl].gasmix, align_dil, print_y_offset[cyl][0]); seen_cyl[cyl] = true; } } last_pressure[cyl] = mbar; last_time[cyl] = entry->sec; } - // Now, for the cylinder pressure written near the right edge of the profile: - if ((o2cyl >= 0) && (dilcyl >= 0)) { // At first, skip uninitialised values of o2cyl and dilcyl - if (last_pressure[o2cyl] > last_pressure[dilcyl]) { // If oxygen cyl pressure graph ends above diluent graph: - align_dil = Qt::AlignTop; // initialise to write diluent cyl end pressure underneath the graph - align_o2 = Qt::AlignBottom; - } else { - align_dil = Qt::AlignBottom; // else initialise to write diluent cyl end pressure above the graph - align_o2 = Qt::AlignTop; - } - } for (cyl = 0; cyl < MAX_CYLINDERS; cyl++) { // For each cylinder, on right hand side of profile, write cylinder pressure alignVar = ((o2cyl >= 0) && (cyl == displayed_dive.oxygen_cylinder_index)) ? align_o2 : align_dil; if (last_time[cyl]) { - plotPressureValue(last_pressure[cyl], last_time[cyl], (alignVar | Qt::AlignLeft), print_y_offset[cyl][0]); + plotPressureValue(last_pressure[cyl], last_time[cyl], (alignVar | Qt::AlignLeft), print_y_offset[cyl][1]); } } } @@ -808,12 +792,14 @@ DiveCalculatedCeiling::DiveCalculatedCeiling() : is3mIncrement(false), gradientF gradientFactor->setY(0); gradientFactor->setBrush(getColor(PRESSURE_TEXT)); gradientFactor->setAlignment(Qt::AlignHCenter | Qt::AlignBottom); - connect(MainWindow::instance()->information(), SIGNAL(dateTimeChanged()), this, SLOT(recalc())); settingsChanged(); } void DiveCalculatedCeiling::modelDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight) { + if (MainWindow::instance()->information()) + connect(MainWindow::instance()->information(), SIGNAL(dateTimeChanged()), this, SLOT(recalc()), Qt::UniqueConnection); + // We don't have enougth data to calculate things, quit. if (!shouldCalculateStuff(topLeft, bottomRight)) return; diff --git a/qt-ui/profile/divetextitem.cpp b/qt-ui/profile/divetextitem.cpp index 85e046638..4c0137177 100644 --- a/qt-ui/profile/divetextitem.cpp +++ b/qt-ui/profile/divetextitem.cpp @@ -1,5 +1,6 @@ #include "divetextitem.h" #include "mainwindow.h" +#include "profilewidget2.h" DiveTextItem::DiveTextItem(QGraphicsItem *parent) : QGraphicsItemGroup(parent), internalAlignFlags(Qt::AlignHCenter | Qt::AlignVCenter), diff --git a/qt-ui/profile/profilewidget2.cpp b/qt-ui/profile/profilewidget2.cpp index f04d16b3f..a426ceef2 100644 --- a/qt-ui/profile/profilewidget2.cpp +++ b/qt-ui/profile/profilewidget2.cpp @@ -10,12 +10,18 @@ #include "ruleritem.h" #include "tankitem.h" #include "pref.h" +#include "divepicturewidget.h" +#include "models.h" +#include "maintab.h" +#include "diveplanner.h" + #include <libdivecomputer/parser.h> #include <QScrollBar> #include <QtCore/qmath.h> #include <QMessageBox> #include <QInputDialog> #include <QDebug> +#include <QWheelEvent> #ifndef QT_NO_DEBUG #include <QTableView> @@ -644,7 +650,7 @@ void ProfileWidget2::plotDive(struct dive *d, bool force) // so if we are calculation TTS / NDL then let's force that off. if (measureDuration.elapsed() > 1000 && prefs.calcndltts) { MainWindow::instance()->turnOffNdlTts(); - MainWindow::instance()->showError(tr("Show NDL / TTS was disabled because of excessive processing time")); + MainWindow::instance()->getNotificationWidget()->showNotification(tr("Show NDL / TTS was disabled because of excessive processing time"), KMessageWidget::Error); } } @@ -727,6 +733,8 @@ void ProfileWidget2::resizeEvent(QResizeEvent *event) void ProfileWidget2::mousePressEvent(QMouseEvent *event) { + if (zoomLevel) + return; QGraphicsView::mousePressEvent(event); if (currentState == PLAN) shouldCalculateMaxTime = false; @@ -734,18 +742,24 @@ void ProfileWidget2::mousePressEvent(QMouseEvent *event) void ProfileWidget2::divePlannerHandlerClicked() { + if (zoomLevel) + return; shouldCalculateMaxDepth = false; replot(); } void ProfileWidget2::divePlannerHandlerReleased() { + if (zoomLevel) + return; shouldCalculateMaxDepth = true; replot(); } void ProfileWidget2::mouseReleaseEvent(QMouseEvent *event) { + if (zoomLevel) + return; QGraphicsView::mouseReleaseEvent(event); if (currentState == PLAN) { shouldCalculateMaxTime = true; @@ -1039,6 +1053,7 @@ void ProfileWidget2::clearHandlers() if (handles.count()) { foreach (DiveHandler *handle, handles) { scene()->removeItem(handle); + delete handle; } handles.clear(); } @@ -1054,6 +1069,7 @@ void ProfileWidget2::setAddState() if (currentState == ADD) return; + clearHandlers(); setProfileState(); mouseFollowerHorizontal->setVisible(true); mouseFollowerVertical->setVisible(true); @@ -1206,6 +1222,10 @@ void ProfileWidget2::contextMenuEvent(QContextMenuEvent *event) setpointAction->setData(event->globalPos()); QAction *action = m.addAction(tr("Add bookmark"), this, SLOT(addBookmark())); action->setData(event->globalPos()); + + if (same_string(current_dc->model, "manually added dive")) + QAction *editProfileAction = m.addAction(tr("Edit the profile"), MainWindow::instance(), SLOT(editCurrentDive())); + if (DiveEventItem *item = dynamic_cast<DiveEventItem *>(sceneItem)) { action = new QAction(&m); action->setText(tr("Remove event")); @@ -1375,8 +1395,21 @@ void ProfileWidget2::changeGas() // backup the things on the dataModel, since we will clear that out. struct gasmix gasmix; - int seconds = timeAxis->valueAt(scenePos); + qreal sec_val = timeAxis->valueAt(scenePos); + + // no gas changes before the dive starts + unsigned int seconds = (sec_val < 0.0) ? 0 : (unsigned int)sec_val; + // if there is a gas change at this time stamp, remove it before adding the new one + struct event *gasChangeEvent = current_dc->events; + while ((gasChangeEvent = get_next_event(gasChangeEvent, "gaschange")) != NULL) { + if (gasChangeEvent->time.seconds == seconds) { + remove_event(gasChangeEvent); + gasChangeEvent = current_dc->events; + } else { + gasChangeEvent = gasChangeEvent->next; + } + } validate_gas(gas.toUtf8().constData(), &gasmix); QRegExp rx("\\(\\D*(\\d+)"); int tank; @@ -1504,6 +1537,7 @@ void ProfileWidget2::repositionDiveHandlers() { DivePlannerPointsModel *plannerModel = DivePlannerPointsModel::instance(); // Re-position the user generated dive handlers + struct gasmix mix, lastmix; for (int i = 0; i < plannerModel->rowCount(); i++) { struct divedatapoint datapoint = plannerModel->at(i); if (datapoint.time == 0) // those are the magic entries for tanks @@ -1528,8 +1562,9 @@ void ProfileWidget2::repositionDiveHandlers() QLineF line(p1, p2); QPointF pos = line.pointAt(0.5); gases[i]->setPos(pos); - gases[i]->setVisible(datapoint.entered); - gases[i]->setText(dpGasToStr(plannerModel->at(i))); + gases[i]->setText(dpGasToStr(datapoint)); + gases[i]->setVisible(datapoint.entered && + (i == 0 || gases[i]->text() != gases[i-1]->text())); } } diff --git a/qt-ui/profile/ruleritem.cpp b/qt-ui/profile/ruleritem.cpp index c88a3353d..d5742ef1d 100644 --- a/qt-ui/profile/ruleritem.cpp +++ b/qt-ui/profile/ruleritem.cpp @@ -1,6 +1,8 @@ #include "ruleritem.h" #include "preferences.h" #include "mainwindow.h" +#include "profilewidget2.h" +#include "display.h" #include <qgraphicssceneevent.h> @@ -81,7 +83,11 @@ void RulerItem2::settingsChanged() ProfileWidget2 *profWidget = NULL; if (scene() && scene()->views().count()) profWidget = qobject_cast<ProfileWidget2 *>(scene()->views().first()); - setVisible(profWidget->currentState == ProfileWidget2::PROFILE ? prefs.rulergraph : false); + + if (profWidget && profWidget->currentState == ProfileWidget2::PROFILE) + setVisible(prefs.rulergraph); + else + setVisible(false); } void RulerItem2::recalculate() |