summaryrefslogtreecommitdiffstats
path: root/qt-ui
diff options
context:
space:
mode:
authorGravatar Tomaz Canabrava <tcanabrava@kde.org>2013-08-30 07:14:30 -0300
committerGravatar Tomaz Canabrava <tcanabrava@kde.org>2013-08-30 07:14:30 -0300
commit69903903d213e45fe16f3b5a6acb52278eee9291 (patch)
treed6d67ff1771196962bc5e47da076ea0fd31654ca /qt-ui
parent6c56f0795923453f2502637d6f7ddda59190bc2d (diff)
downloadsubsurface-69903903d213e45fe16f3b5a6acb52278eee9291.tar.gz
Started the work of Editable Model for the Planner
This commit is the start of the Editable Model work for the planner, it creates a new delegate and shares the code for the model that creates the gas types, so we only need to change in one place to add new gases. The table is already edition-enabled, but the outcome is still undone, next commit - put all together. Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
Diffstat (limited to 'qt-ui')
-rw-r--r--qt-ui/diveplanner.cpp23
-rw-r--r--qt-ui/diveplanner.h5
-rw-r--r--qt-ui/modeldelegates.cpp14
-rw-r--r--qt-ui/modeldelegates.h9
4 files changed, 47 insertions, 4 deletions
diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp
index 9fadd53c0..63b8229ad 100644
--- a/qt-ui/diveplanner.cpp
+++ b/qt-ui/diveplanner.cpp
@@ -1,10 +1,12 @@
#include "diveplanner.h"
#include "graphicsview-common.h"
#include "models.h"
+#include "modeldelegates.h"
#include "../dive.h"
#include "../divelist.h"
+
#include <cmath>
#include <QMouseEvent>
#include <QDebug>
@@ -27,6 +29,11 @@
#define MAX_DEEPNESS 150
#define MIN_DEEPNESS 40
+QStringListModel *airTypes(){
+ static QStringListModel *self = new QStringListModel(QStringList() << QObject::tr("AIR") << QObject::tr("EAN32") << QObject::tr("EAN36"));
+ return self;
+}
+
static DivePlannerPointsModel *plannerModel = DivePlannerPointsModel::instance();
DivePlannerGraphics::DivePlannerGraphics(QWidget* parent): QGraphicsView(parent), activeDraggedHandler(0)
@@ -135,10 +142,9 @@ DivePlannerGraphics::DivePlannerGraphics(QWidget* parent): QGraphicsView(parent)
#undef ADD_ACTION
// Prepare the stuff for the gas-choices.
- gasChoices = new QStringListModel(QStringList() << tr("AIR") << tr("EAN32") << tr("EAN36"));
gasListView = new QListView();
gasListView->setWindowFlags(Qt::Popup);
- gasListView->setModel(gasChoices);
+ gasListView->setModel(airTypes());
gasListView->hide();
connect(gasListView, SIGNAL(activated(QModelIndex)), this, SLOT(selectGas(QModelIndex)));
@@ -394,8 +400,6 @@ void DivePlannerGraphics::createDecoStops()
{
qDeleteAll(lines);
lines.clear();
- //TODO: fix.
- //qSort(handles.begin(), handles.end(), handlerLessThenMinutes);
// This needs to be done in the following steps:
// Get the user-input and calculate the dive info
@@ -807,6 +811,7 @@ DivePlannerWidget::DivePlannerWidget(QWidget* parent, Qt::WindowFlags f): QWidge
{
ui->setupUi(this);
ui->tablePoints->setModel(DivePlannerPointsModel::instance());
+ ui->tablePoints->setItemDelegateForColumn(DivePlannerPointsModel::GAS, new AirTypesDelegate(this));
connect(ui->startTime, SIGNAL(timeChanged(QTime)), this, SLOT(startTimeChanged(QTime)));
connect(ui->ATMPressure, SIGNAL(textChanged(QString)), this, SLOT(atmPressureChanged(QString)));
connect(ui->bottomSAC, SIGNAL(textChanged(QString)), this, SLOT(bottomSacChanged(QString)));
@@ -914,6 +919,11 @@ QVariant DivePlannerPointsModel::data(const QModelIndex& index, int role) const
return QVariant();
}
+bool DivePlannerPointsModel::setData(const QModelIndex& index, const QVariant& value, int role)
+{
+ return QAbstractItemModel::setData(index, value, role);
+}
+
QVariant DivePlannerPointsModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if (role == Qt::DisplayRole && orientation == Qt::Horizontal){
@@ -927,6 +937,11 @@ QVariant DivePlannerPointsModel::headerData(int section, Qt::Orientation orienta
return QVariant();
}
+Qt::ItemFlags DivePlannerPointsModel::flags(const QModelIndex& index) const
+{
+ return QAbstractItemModel::flags(index) | Qt::ItemIsEditable;
+}
+
int DivePlannerPointsModel::rowCount(const QModelIndex& parent) const
{
return divepoints.count();
diff --git a/qt-ui/diveplanner.h b/qt-ui/diveplanner.h
index 719aca853..afa9c0fca 100644
--- a/qt-ui/diveplanner.h
+++ b/qt-ui/diveplanner.h
@@ -17,6 +17,9 @@ class QListView;
class QStringListModel;
class QModelIndex;
+// Return a Model containing the air types.
+QStringListModel *airTypes();
+
class DivePlannerPointsModel : public QAbstractTableModel{
Q_OBJECT
public:
@@ -26,6 +29,8 @@ public:
virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
virtual int rowCount(const QModelIndex& parent = QModelIndex()) const;
virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
+ virtual bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole);
+ virtual Qt::ItemFlags flags(const QModelIndex& index) const;
/**
* @return the row number.
diff --git a/qt-ui/modeldelegates.cpp b/qt-ui/modeldelegates.cpp
index 998c246b8..31267810c 100644
--- a/qt-ui/modeldelegates.cpp
+++ b/qt-ui/modeldelegates.cpp
@@ -3,6 +3,7 @@
#include "../divelist.h"
#include "starwidget.h"
#include "models.h"
+#include "diveplanner.h"
#include <QtDebug>
#include <QPainter>
@@ -14,6 +15,7 @@
#include <QLineEdit>
#include <QKeyEvent>
#include <QAbstractItemView>
+#include <QStringListModel>
// Gets the index of the model in the currentRow and column.
// currCombo is defined below.
@@ -253,3 +255,15 @@ QWidget* WSInfoDelegate::createEditor(QWidget* parent, const QStyleOptionViewIte
currWeigth.weigth = ws->weight.grams;
return editor;
}
+
+void AirTypesDelegate::revertModelData(QWidget* widget, QAbstractItemDelegate::EndEditHint hint)
+{
+}
+
+void AirTypesDelegate::setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const
+{
+}
+
+AirTypesDelegate::AirTypesDelegate(QObject* parent) : ComboBoxDelegate(airTypes(), parent)
+{
+}
diff --git a/qt-ui/modeldelegates.h b/qt-ui/modeldelegates.h
index 9603d5dce..29d4f3717 100644
--- a/qt-ui/modeldelegates.h
+++ b/qt-ui/modeldelegates.h
@@ -49,4 +49,13 @@ public slots:
void revertModelData(QWidget* widget, QAbstractItemDelegate::EndEditHint hint);
};
+class AirTypesDelegate : public ComboBoxDelegate{
+ Q_OBJECT
+public:
+ explicit AirTypesDelegate(QObject* parent = 0);
+ virtual void setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const;
+public slots:
+ void revertModelData(QWidget* widget, QAbstractItemDelegate::EndEditHint hint);
+};
+
#endif