summaryrefslogtreecommitdiffstats
path: root/qt-ui
diff options
context:
space:
mode:
authorGravatar Tomaz Canabrava <tcanabrava@kde.org>2013-06-07 12:57:35 -0300
committerGravatar Tomaz Canabrava <tcanabrava@kde.org>2013-06-07 12:57:35 -0300
commit24446f9c3ce3b48c59b2ceb212b7ac49eb6dbff7 (patch)
treeaf38eef1b92549ddb8479f2d18a5c0839a1d8d4c /qt-ui
parentebed836ee5d10659ae3d830704508f9c575181d3 (diff)
downloadsubsurface-24446f9c3ce3b48c59b2ceb212b7ac49eb6dbff7.tar.gz
Edit the name of the Dive Computer via dialog.
The GTK version seems to be bugged on this, since the dialog doesn't save the dive computer nickname that I setted, but the Qt version shows less dive-computers than the GTK one on the same dive. I want somebody to do a quick review of my code too. :) I also plan to remove the 'OK' and 'Cancel' buttom, they seem to be overrated on this dialog - fairly uneeded. Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
Diffstat (limited to 'qt-ui')
-rw-r--r--qt-ui/models.cpp23
-rw-r--r--qt-ui/models.h2
2 files changed, 22 insertions, 3 deletions
diff --git a/qt-ui/models.cpp b/qt-ui/models.cpp
index 1fc2515c6..787dbd8cf 100644
--- a/qt-ui/models.cpp
+++ b/qt-ui/models.cpp
@@ -1173,18 +1173,35 @@ void DiveComputerModel::update()
nnl = nnl->next;
count++;
}
- qDebug() << "Numero de Devices" << count;
-
+
if(numRows){
beginRemoveRows(QModelIndex(), 0, numRows-1);
numRows = 0;
endRemoveRows();
}
-
+
if (count){
beginInsertRows(QModelIndex(), 0, count-1);
numRows = count;
endInsertRows();
}
+}
+
+Qt::ItemFlags DiveComputerModel::flags(const QModelIndex& index) const
+{
+ Qt::ItemFlags flags = QAbstractItemModel::flags(index);
+ if (index.column() == NICKNAME)
+ flags |= Qt::ItemIsEditable;
+ return flags;
+}
+
+bool DiveComputerModel::setData(const QModelIndex& index, const QVariant& value, int role)
+{
+ struct device_info *nnl = head_of_device_info_list();
+ for(int i = 0; i < index.row(); i++){
+ nnl = nnl->next;
+ }
+ QByteArray v = value.toByteArray();
+ nnl->nickname = strdup(v.data()); // how should I free this before setting a new one?
}
diff --git a/qt-ui/models.h b/qt-ui/models.h
index c0625325f..7a32998ce 100644
--- a/qt-ui/models.h
+++ b/qt-ui/models.h
@@ -177,6 +177,8 @@ public:
virtual int columnCount(const QModelIndex& parent = QModelIndex()) const;
virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
virtual int rowCount(const QModelIndex& parent = QModelIndex()) const;
+ virtual Qt::ItemFlags flags(const QModelIndex& index) const;
+ virtual bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole);
void update();
private:
int numRows;