summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Tomaz Canabrava <tomaz.canabrava@gmail.com>2015-06-01 22:16:07 -0300
committerGravatar Dirk Hohndel <dirk@hohndel.org>2015-06-01 21:31:16 -0700
commita9ba98942ccdacda37fa038fef46c478271aca22 (patch)
tree992f603753a72262bad8d79dbe3cbc651bfeff28
parent64753e0682d1fd008d9cdf573e78fe5ea862dcef (diff)
downloadsubsurface-a9ba98942ccdacda37fa038fef46c478271aca22.tar.gz
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 <tomaz.canabrava@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--qt-models/divelocationmodel.cpp15
-rw-r--r--qt-models/divelocationmodel.h2
-rw-r--r--qt-ui/locationinformation.cpp9
3 files changed, 22 insertions, 4 deletions
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:
diff --git a/qt-ui/locationinformation.cpp b/qt-ui/locationinformation.cpp
index b6c4f7fa9..25d3ddecb 100644
--- a/qt-ui/locationinformation.cpp
+++ b/qt-ui/locationinformation.cpp
@@ -202,9 +202,12 @@ void LocationInformationWidget::on_diveSiteDescription_textChanged(const QString
void LocationInformationWidget::on_diveSiteName_textChanged(const QString& text)
{
- if (!currentDs || !same_string(qPrintable(text), currentDs->name)) {
- free(displayed_dive_site.name);
- displayed_dive_site.name = copy_string(qPrintable(text));
+ if (currentDs && text != currentDs->name) {
+ // This needs to be changed directly into the model so that
+ // the changes are replyed on the ComboBox with the current selection.
+
+ QModelIndex idx = ui.currentLocation->model()->index(ui.currentLocation->currentIndex(),0);
+ LocationInformationModel::instance()->setData(idx, text, Qt::EditRole);
markChangedWidget(ui.diveSiteName);
emit coordinatesChanged();
}