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:
Tomaz Canabrava 2013-05-22 11:00:20 -03:00
parent 94ba79c0fe
commit 0b30c821ae
4 changed files with 63 additions and 4 deletions

View file

@ -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;