From a9ba98942ccdacda37fa038fef46c478271aca22 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Mon, 1 Jun 2015 22:16:07 -0300 Subject: Correctly change the dive_site name Correctly change and update the dive_site, updating the name on the combobox or other attached views. Signed-off-by: Tomaz Canabrava Signed-off-by: Dirk Hohndel --- qt-models/divelocationmodel.cpp | 15 +++++++++++++++ qt-models/divelocationmodel.h | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) (limited to 'qt-models') diff --git a/qt-models/divelocationmodel.cpp b/qt-models/divelocationmodel.cpp index 05d68c27d..d45df349c 100644 --- a/qt-models/divelocationmodel.cpp +++ b/qt-models/divelocationmodel.cpp @@ -60,3 +60,18 @@ int32_t LocationInformationModel::addDiveSite(const QString& name, int lon, int update(); return uuid; } + +bool LocationInformationModel::setData(const QModelIndex &index, const QVariant &value, int role) +{ + if (!index.isValid()) + return false; + + if (role != Qt::EditRole) + return false; + + struct dive_site *ds = get_dive_site(index.row()); + free(ds->name); + ds->name = copy_string(qPrintable(value.toString())); + emit dataChanged(index, index); + return true; +} diff --git a/qt-models/divelocationmodel.h b/qt-models/divelocationmodel.h index c9dd5cee5..7ca0c926a 100644 --- a/qt-models/divelocationmodel.h +++ b/qt-models/divelocationmodel.h @@ -12,7 +12,7 @@ public: int rowCount(const QModelIndex &parent = QModelIndex()) const; QVariant data(const QModelIndex &index = QModelIndex(), int role = Qt::DisplayRole) const; int32_t addDiveSite(const QString& name, int lat = 0, int lon = 0); - + bool setData(const QModelIndex &index, const QVariant &value, int role); public slots: void update(); private: -- cgit v1.2.3-70-g09d2