summaryrefslogtreecommitdiffstats
path: root/qt-ui/models.cpp
diff options
context:
space:
mode:
authorGravatar Tomaz Canabrava <tcanabrava@kde.org>2013-05-22 11:00:20 -0300
committerGravatar Tomaz Canabrava <tcanabrava@kde.org>2013-05-22 11:00:20 -0300
commit0b30c821ae5b8cb9f5e3e8d49152d56f215aeec4 (patch)
tree5d4a6c9ca607465f4a67dd31f3b94129cc81ee80 /qt-ui/models.cpp
parent94ba79c0fedc92113df22da27a4ff2cf01b26f94 (diff)
downloadsubsurface-0b30c821ae5b8cb9f5e3e8d49152d56f215aeec4.tar.gz
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>
Diffstat (limited to 'qt-ui/models.cpp')
-rw-r--r--qt-ui/models.cpp48
1 files changed, 46 insertions, 2 deletions
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;