From 797bf49129769842b5ca872e5efe40b4a575d1d5 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Thu, 8 Jan 2015 10:55:38 -0200 Subject: [PATCH] Dive d/l selection UI: Add the setData method Signed-off-by: Tomaz Canabrava Signed-off-by: Dirk Hohndel --- qt-ui/downloadfromdivecomputer.cpp | 15 +++++++++++++++ qt-ui/downloadfromdivecomputer.h | 1 + 2 files changed, 16 insertions(+) diff --git a/qt-ui/downloadfromdivecomputer.cpp b/qt-ui/downloadfromdivecomputer.cpp index 91e38ae36..a7363c4ed 100644 --- a/qt-ui/downloadfromdivecomputer.cpp +++ b/qt-ui/downloadfromdivecomputer.cpp @@ -539,6 +539,21 @@ QVariant DiveImportedModel::data(const QModelIndex& index, int role) const return QVariant(); } +bool DiveImportedModel::setData(const QModelIndex &index, const QVariant &value, int role) +{ + if (!index.isValid()) + return false; + + if (index.row() + firstIndex > lastIndex) + return false; + + if (role != Qt::CheckStateRole) + return false; + + checkStates[index.row() + firstIndex ] = value.toBool(); + dataChanged(index, index, QVector() << Qt::CheckStateRole); +} + void DiveImportedModel::setImportedDivesIndexes(int first, int last) { beginRemoveRows(QModelIndex(), 0, lastIndex - firstIndex); diff --git a/qt-ui/downloadfromdivecomputer.h b/qt-ui/downloadfromdivecomputer.h index c49ad9a40..028f7dda2 100644 --- a/qt-ui/downloadfromdivecomputer.h +++ b/qt-ui/downloadfromdivecomputer.h @@ -33,6 +33,7 @@ public: int columnCount(const QModelIndex& index = QModelIndex()) const; int rowCount(const QModelIndex& index = QModelIndex()) const; QVariant data(const QModelIndex& index, int role) const; + bool setData(const QModelIndex &index, const QVariant &value, int role); void setImportedDivesIndexes(int first, int last); private: int firstIndex;