aboutsummaryrefslogtreecommitdiffstats
path: root/qt-ui
diff options
context:
space:
mode:
Diffstat (limited to 'qt-ui')
-rw-r--r--qt-ui/maintab.cpp8
-rw-r--r--qt-ui/models.cpp48
-rw-r--r--qt-ui/models.h10
3 files changed, 62 insertions, 4 deletions
diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp
index 0a8710e09..a52058816 100644
--- a/qt-ui/maintab.cpp
+++ b/qt-ui/maintab.cpp
@@ -75,6 +75,14 @@ MainTab::MainTab(QWidget *parent) : QTabWidget(parent),
addWeight->setToolTip(tr("Add Weight System"));
connect(addWeight, SIGNAL(clicked(bool)), this, SLOT(addWeight_clicked()));
addWeight->setEnabled(false);
+
+ connect(ui->cylinders, SIGNAL(clicked(QModelIndex)), ui->cylinders->model(), SLOT(remove(QModelIndex)));
+ connect(ui->weights, SIGNAL(clicked(QModelIndex)), ui->weights->model(), SLOT(remove(QModelIndex)));
+
+ ui->cylinders->setColumnWidth( CylindersModel::REMOVE, 24);
+ ui->cylinders->horizontalHeader()->setResizeMode (CylindersModel::REMOVE , QHeaderView::Fixed);
+ ui->weights->setColumnWidth( WeightModel::REMOVE, 24);
+ ui->cylinders->horizontalHeader()->setResizeMode (WeightModel::REMOVE , QHeaderView::Fixed);
}
// We need to manually position the 'plus' on cylinder and weight.
diff --git a/qt-ui/models.cpp b/qt-ui/models.cpp
index 466dcd2f9..82c125df6 100644
--- a/qt-ui/models.cpp
+++ b/qt-ui/models.cpp
@@ -11,6 +11,7 @@
#include <QColor>
#include <QBrush>
#include <QFont>
+#include <QIcon>
extern struct tank_info tank_info[100];
@@ -54,7 +55,7 @@ QVariant CylindersModel::headerData(int section, Qt::Orientation orientation, in
int CylindersModel::columnCount(const QModelIndex& parent) const
{
- return 7;
+ return COLUMNS;
}
QVariant CylindersModel::data(const QModelIndex& index, int role) const
@@ -102,6 +103,13 @@ QVariant CylindersModel::data(const QModelIndex& index, int role) const
break;
}
}
+
+ else if (role == Qt::DecorationRole){
+ if (index.column() == REMOVE){
+ ret = QIcon(":trash");
+ }
+ }
+
return ret;
}
@@ -164,6 +172,29 @@ void CylindersModel::setDive(dive* d)
endInsertRows();
}
+Qt::ItemFlags CylindersModel::flags(const QModelIndex& index) const
+{
+ if (index.column() == REMOVE)
+ return Qt::ItemIsEnabled;
+ return QAbstractItemModel::flags(index);
+}
+
+void CylindersModel::remove(const QModelIndex& index)
+{
+ if (index.column() != REMOVE){
+ return;
+ }
+ // Remove code should be here.
+}
+
+void WeightModel::remove(const QModelIndex& index)
+{
+ if (index.column() != REMOVE){
+ return;
+ }
+ // Remove code should be here.
+}
+
void WeightModel::clear()
{
if (rows > 0) {
@@ -174,7 +205,7 @@ void WeightModel::clear()
int WeightModel::columnCount(const QModelIndex& parent) const
{
- return 2;
+ return COLUMNS;
}
QVariant WeightModel::data(const QModelIndex& index, int role) const
@@ -195,9 +226,22 @@ QVariant WeightModel::data(const QModelIndex& index, int role) const
break;
}
}
+
+ else if (role == Qt::DecorationRole){
+ if (index.column() == REMOVE){
+ ret = QIcon(":trash");
+ }
+ }
return ret;
}
+Qt::ItemFlags WeightModel::flags(const QModelIndex& index) const
+{
+ if (index.column() == REMOVE)
+ return Qt::ItemIsEnabled;
+ return QAbstractItemModel::flags(index);
+}
+
int WeightModel::rowCount(const QModelIndex& parent) const
{
return rows;
diff --git a/qt-ui/models.h b/qt-ui/models.h
index 62ae3913c..98f955bf6 100644
--- a/qt-ui/models.h
+++ b/qt-ui/models.h
@@ -38,18 +38,21 @@ private:
class CylindersModel : public QAbstractTableModel {
Q_OBJECT
public:
- enum Column {TYPE, SIZE, MAXPRESS, START, END, O2, HE};
+ enum Column {REMOVE, TYPE, SIZE, MAXPRESS, START, END, O2, HE, COLUMNS};
explicit CylindersModel(QObject* parent = 0);
/*reimp*/ QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
/*reimp*/ int columnCount(const QModelIndex& parent = QModelIndex()) const;
/*reimp*/ QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
/*reimp*/ int rowCount(const QModelIndex& parent = QModelIndex()) const;
+ /*reimp*/ Qt::ItemFlags flags(const QModelIndex& index) const;
void add(cylinder_t *cyl);
void clear();
void update();
void setDive(struct dive *d);
+public slots:
+ void remove(const QModelIndex& index);
private:
struct dive *current;
@@ -61,16 +64,19 @@ private:
class WeightModel : public QAbstractTableModel {
Q_OBJECT
public:
- enum Column {TYPE, WEIGHT};
+ enum Column {REMOVE, TYPE, WEIGHT, COLUMNS};
/*reimp*/ QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
/*reimp*/ int columnCount(const QModelIndex& parent = QModelIndex()) const;
/*reimp*/ QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
/*reimp*/ int rowCount(const QModelIndex& parent = QModelIndex()) const;
+ /*reimp*/ Qt::ItemFlags flags(const QModelIndex& index) const;
void add(weightsystem_t *weight);
void clear();
void update();
void setDive(struct dive *d);
+public slots:
+ void remove(const QModelIndex& index);
private:
struct dive *current;