summaryrefslogtreecommitdiffstats
path: root/qt-ui/diveplanner.cpp
diff options
context:
space:
mode:
authorGravatar Lakshman Anumolu <acrlakshman@gmail.com>2014-03-31 23:24:33 -0500
committerGravatar Dirk Hohndel <dirk@hohndel.org>2014-03-31 22:01:16 -0700
commit18ec989ef51b5357d76db85d467626141d5e2429 (patch)
treed2c2429919250a16654cde5ab4b4f6afd2b23787 /qt-ui/diveplanner.cpp
parent30bdfc8160100a296af7115a1f1dff5e4eeb710c (diff)
downloadsubsurface-18ec989ef51b5357d76db85d467626141d5e2429.tar.gz
Diveplan with entered and computed waypoints to UI
Recently Robert Helling provided a patch "Distinguish between entered and calculated waypoints" in an attempt to distinguish between entered and calculated stops. This patch is an independent (content wise) extension of the above patch and is built relative to it which adds new table to display computed waypoints in plan mode. Currently table includes only two columns "Comp. Depth" and "Comp. Duration", which can extended to show further information. This is only a start to the UI interaction in PLAN mode. In addition to this there are many TODO things that diveplan feature demands TODO: 1. Show more details through "Computed Waypoints" table. 2. Remove tooltip from "Computed Waypoints" table widget. 3. Make contents in "Computed Waypoints" table widget non-editable. 4. Fix error when trying to save dive plan without using cylinder data. 5. Make dive plan editable after saving it. 6. Improvise dive planner graphics window. Signed-off-by: Lakshman Anumolu <acrlakshman@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui/diveplanner.cpp')
-rw-r--r--qt-ui/diveplanner.cpp128
1 files changed, 127 insertions, 1 deletions
diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp
index 03b1a2043..ad950f262 100644
--- a/qt-ui/diveplanner.cpp
+++ b/qt-ui/diveplanner.cpp
@@ -42,6 +42,124 @@ QString dpGasToStr(const divedatapoint &p)
return gasToStr(p.o2, p.he);
}
+static DivePlannerDisplay *plannerDisplay = DivePlannerDisplay::instance();
+
+DivePlannerDisplay::DivePlannerDisplay(QObject *parent) : QAbstractTableModel(parent)
+{
+}
+
+DivePlannerDisplay *DivePlannerDisplay::instance()
+{
+ static QScopedPointer<DivePlannerDisplay> self(new DivePlannerDisplay());
+ return self.data();
+}
+
+int DivePlannerDisplay::size()
+{
+ return computedPoints.size();
+}
+
+int DivePlannerDisplay::columnCount(const QModelIndex &parent) const
+{
+ return COLUMNS;
+}
+
+QVariant DivePlannerDisplay::data(const QModelIndex &index, int role) const
+{
+ if (role == Qt::DisplayRole) {
+ computedPoint p = computedPoints.at(index.row());
+ switch (index.column()) {
+ case COMPUTED_DEPTH:
+ return rint(get_depth_units(p.computedDepth, NULL, NULL));
+ case COMPUTED_DURATION:
+ return p.computedTime / 60;
+ }
+ } else if (role == Qt::DecorationRole) {
+ switch (index.column()) {
+ }
+ } else if (role == Qt::FontRole) {
+ return defaultModelFont();
+ }
+ return QVariant();
+}
+
+bool DivePlannerDisplay::setData(const QModelIndex &index, const QVariant &value, int role)
+{
+ if (role == Qt::EditRole) {
+ computedPoint &p = computedPoints[index.row()];
+ switch (index.column()) {
+ case COMPUTED_DEPTH:
+ p.computedDepth = units_to_depth(value.toInt());
+ break;
+ case COMPUTED_DURATION:
+ p.computedTime = value.toInt() * 60;
+ break;
+ }
+ }
+ return QAbstractItemModel::setData(index, value, role);
+}
+
+QVariant DivePlannerDisplay::headerData(int section, Qt::Orientation orientation, int role) const
+{
+ if (role == Qt::DisplayRole && orientation == Qt::Horizontal) {
+ switch (section) {
+ case COMPUTED_DEPTH:
+ return tr("Comp. Depth");
+ case COMPUTED_DURATION:
+ return tr("Comp. Duration");
+ }
+ } else if (role == Qt::FontRole) {
+ return defaultModelFont();
+ }
+ return QVariant();
+}
+
+Qt::ItemFlags DivePlannerDisplay::flags(const QModelIndex &index) const
+{
+ return QAbstractItemModel::flags(index) | Qt::ItemIsEditable;
+}
+
+int DivePlannerDisplay::rowCount(const QModelIndex &parent) const
+{
+ return computedPoints.size();
+}
+
+struct computedPoint DivePlannerDisplay::at(int row)
+{
+ return computedPoints.at(row);
+}
+
+void DivePlannerDisplay::clear()
+{
+ if (rowCount() > 0) {
+ beginRemoveRows(QModelIndex(), 0, rowCount() - 1);
+ computedPoints.clear();
+ endRemoveRows();
+ }
+}
+
+void DivePlannerDisplay::removeStops()
+{
+ if (rowCount() > 0) {
+ beginRemoveRows(QModelIndex(), 0, rowCount() - 1);
+ endRemoveRows();
+ }
+}
+
+void DivePlannerDisplay::addStops()
+{
+ int rows = computedPoints.size();
+ if (rows > 0) {
+ beginInsertRows(QModelIndex(), 0, rows - 1);
+ endInsertRows();
+ }
+}
+
+void DivePlannerDisplay::insertPoint(const struct computedPoint &p)
+{
+ computedPoints.append(p);
+}
+
static DivePlannerPointsModel *plannerModel = DivePlannerPointsModel::instance();
DivePlannerGraphics::DivePlannerGraphics(QWidget *parent) : QGraphicsView(parent),
@@ -511,6 +629,7 @@ void DivePlannerGraphics::drawProfile()
QPolygonF poly;
poly.append(QPointF(lastx, lasty));
+ plannerDisplay->clear();
for (dp = diveplan.dp; dp != NULL; dp = dp->next) {
if (dp->time == 0) // magic entry for available tank
continue;
@@ -521,8 +640,11 @@ void DivePlannerGraphics::drawProfile()
item->setPen(QPen(QBrush(Qt::red), 0));
scene()->addItem(item);
lines << item;
- if (dp->depth)
+ if (dp->depth) {
qDebug() << "Time: " << dp->time / 60 << " depth: " << dp->depth / 1000;
+ computedPoint p(dp->time, dp->depth);
+ plannerDisplay->insertPoint(p);
+ }
}
lastx = xpos;
lasty = ypos;
@@ -530,6 +652,7 @@ void DivePlannerGraphics::drawProfile()
}
qDebug() << " ";
+ plannerDisplay->addStops();
diveBg->setPolygon(poly);
QRectF b = poly.boundingRect();
@@ -937,6 +1060,8 @@ DivePlannerWidget::DivePlannerWidget(QWidget *parent, Qt::WindowFlags f) : QWidg
ui.tableWidget->setTitle(tr("Dive Planner Points"));
ui.tableWidget->setModel(DivePlannerPointsModel::instance());
ui.tableWidget->view()->setItemDelegateForColumn(DivePlannerPointsModel::GAS, new AirTypesDelegate(this));
+ ui.tableWidgetComp->setTitle(tr("Computed Waypoints"));
+ ui.tableWidgetComp->setModel(DivePlannerDisplay::instance());
ui.cylinderTableWidget->setTitle(tr("Available Gases"));
ui.cylinderTableWidget->setModel(CylindersModel::instance());
QTableView *view = ui.cylinderTableWidget->view();
@@ -956,6 +1081,7 @@ DivePlannerWidget::DivePlannerWidget(QWidget *parent, Qt::WindowFlags f) : QWidg
GasSelectionModel::instance(), SLOT(repopulate()));
ui.tableWidget->setBtnToolTip(tr("add dive data point"));
+ ui.tableWidgetComp->setBtnToolTip(tr("This does nothing, and should be removed"));
connect(ui.startTime, SIGNAL(timeChanged(QTime)), plannerModel, SLOT(setStartTime(QTime)));
connect(ui.ATMPressure, SIGNAL(textChanged(QString)), this, SLOT(atmPressureChanged(QString)));
connect(ui.bottomSAC, SIGNAL(textChanged(QString)), this, SLOT(bottomSacChanged(QString)));