mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-31 20:53:23 +00:00
Added a 'trash' icon on the Cylinders and Weigthsystem models
So, the Cylinders and Weigthsystems got a new Trash icon, and the interface already intercepts the clicks ( on all columns ) and send this to the 'remove' method on boch models. On the model I'm just filtering the indexes that are not 'DELETE' and creating a stub method to be filled later. Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
This commit is contained in:
parent
94ba79c0fe
commit
0b30c821ae
4 changed files with 63 additions and 4 deletions
|
@ -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.
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -3,5 +3,6 @@
|
|||
<file alias="star">star.svg</file>
|
||||
<file alias="subsurface-icon">subsurface-icon.png</file>
|
||||
<file alias="plus">plus.png</file>
|
||||
<file alias="trash">trash.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
|
Loading…
Add table
Reference in a new issue