mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-28 05:00:20 +00:00
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>
This commit is contained in:
parent
64753e0682
commit
a9ba98942c
3 changed files with 22 additions and 4 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue