mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Inform LocationFilterModel of changed dive site name
Since commit 01d961086c
, the location filter
list is updated if a dive site is edited. The problem is that if the
name of a selected dive site is changed, the selection is lost.
Therefore, before repopulating, inform the location filter that a dive
site changed its name. The location filter then internally changes the
name and can properly transfer the old selection on repopulate. This is
performed via the new LocationInformationWidget::nameChanged signal,
which is connected to the new LocationFilterModel::changeName slot.
A special case to be handled is the following:
[ ] Site 1
[x] Site 2
and "Site 2" being renamed to "Site 1", i.e. both sites being merged.
Here, the merging is detected and "Site 1" will likewise be checked:
[x] Site 1
[x] Site 1
No merging is performed, as the list will be repopulated anyway.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
2a0520d57d
commit
f4bcdf46aa
4 changed files with 23 additions and 0 deletions
|
@ -36,6 +36,8 @@ LocationInformationWidget::LocationInformationWidget(QWidget *parent) : QGroupBo
|
|||
connect(this, SIGNAL(startFilterDiveSite(uint32_t)), MultiFilterSortModel::instance(), SLOT(startFilterDiveSite(uint32_t)));
|
||||
connect(this, SIGNAL(stopFilterDiveSite()), MultiFilterSortModel::instance(), SLOT(stopFilterDiveSite()));
|
||||
connect(ui.geoCodeButton, SIGNAL(clicked()), this, SLOT(reverseGeocode()));
|
||||
connect(this, SIGNAL(nameChanged(const QString &, const QString &)),
|
||||
LocationFilterModel::instance(), SLOT(changeName(const QString &, const QString &)));
|
||||
|
||||
SsrfSortFilterProxyModel *filter_model = new SsrfSortFilterProxyModel(this);
|
||||
filter_model->setSourceModel(LocationInformationModel::instance());
|
||||
|
@ -156,6 +158,7 @@ void LocationInformationWidget::acceptChanges()
|
|||
currentDs->latitude = displayed_dive_site.latitude;
|
||||
currentDs->longitude = displayed_dive_site.longitude;
|
||||
if (!same_string(uiString, currentDs->name)) {
|
||||
emit nameChanged(QString(currentDs->name), ui.diveSiteName->text());
|
||||
free(currentDs->name);
|
||||
currentDs->name = uiString;
|
||||
} else {
|
||||
|
|
|
@ -41,6 +41,7 @@ signals:
|
|||
void stopFilterDiveSite();
|
||||
void requestCoordinates();
|
||||
void endRequestCoordinates();
|
||||
void nameChanged(const QString &oldName, const QString &newName);
|
||||
|
||||
private:
|
||||
void clearLabels();
|
||||
|
|
|
@ -315,6 +315,24 @@ void LocationFilterModel::repopulate()
|
|||
updateList(list);
|
||||
}
|
||||
|
||||
void LocationFilterModel::changeName(const QString &oldName, const QString &newName)
|
||||
{
|
||||
if (oldName.isEmpty() || newName.isEmpty() || oldName == newName)
|
||||
return;
|
||||
QStringList list = stringList();
|
||||
int oldIndex = list.indexOf(oldName);
|
||||
if (oldIndex < 0)
|
||||
return;
|
||||
int newIndex = list.indexOf(newName);
|
||||
list[oldIndex] = newName;
|
||||
setStringList(list);
|
||||
|
||||
// If there was already an entry with the new name, we are merging entries.
|
||||
// Thus, if the old entry was selected, also select the new entry.
|
||||
if (newIndex >= 0 && checkState[oldIndex])
|
||||
checkState[newIndex] = true;
|
||||
}
|
||||
|
||||
MultiFilterSortModel::MultiFilterSortModel(QObject *parent) :
|
||||
QSortFilterProxyModel(parent),
|
||||
divesDisplayed(0),
|
||||
|
|
|
@ -68,6 +68,7 @@ public:
|
|||
public
|
||||
slots:
|
||||
void repopulate();
|
||||
void changeName(const QString &oldName, const QString &newName);
|
||||
|
||||
private:
|
||||
explicit LocationFilterModel(QObject *parent = 0);
|
||||
|
|
Loading…
Add table
Reference in a new issue