maplocationmodel: make setSelectedUuid() accept "fromClick" flag

The idea of this flag is to be able to only to emit the
selectedLocationChanged() signal when the user clicked on the map
(fromClick == true).

MapWidgetHelper::selectedLocationChanged() listens for this signal
and only then it will select nearby dives based on a "small-cicle".

If "fromClick" is false, it's the backend or the dive list that
updated the selection and MapWidgetHelper::selectedLocationChanged()
should no be called.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
This commit is contained in:
Lubomir I. Ivanov 2017-07-24 17:00:06 +03:00 committed by Dirk Hohndel
parent 747f3d8cab
commit 5ea702199b
3 changed files with 11 additions and 15 deletions

View file

@ -60,7 +60,7 @@ Item {
MouseArea { MouseArea {
anchors.fill: parent anchors.fill: parent
onClicked: { onClicked: {
mapHelper.model.selectedUuid = model.uuid mapHelper.model.setSelectedUuid(model.uuid, true)
mapItemImageAnimation.restart() mapItemImageAnimation.restart()
} }
} }
@ -106,12 +106,12 @@ Item {
} }
function centerOnMapLocation(mapLocation) { function centerOnMapLocation(mapLocation) {
mapHelper.model.selectedUuid = mapLocation.uuid mapHelper.model.setSelectedUuid(mapLocation.uuid, false)
animateMapZoomIn(mapLocation.coordinate) animateMapZoomIn(mapLocation.coordinate)
} }
function deselectMapLocation() { function deselectMapLocation() {
mapHelper.model.selectedUuid = 0 mapHelper.model.setSelectedUuid(0, false)
animateMapZoomOut() animateMapZoomOut()
} }
} }

View file

@ -93,15 +93,12 @@ void MapLocationModel::clear()
endRemoveRows(); endRemoveRows();
} }
quint32 MapLocationModel::selectedUuid() void MapLocationModel::setSelectedUuid(QVariant uuid, QVariant fromClick)
{ {
return m_selectedUuid; m_selectedUuid = qvariant_cast<quint32>(uuid);
} const bool fromClickBool = qvariant_cast<bool>(fromClick);
if (fromClickBool)
void MapLocationModel::setSelectedUuid(quint32 uuid) emit selectedLocationChanged(getMapLocationForUuid(m_selectedUuid));
{
m_selectedUuid = uuid;
emit selectedLocationChanged(getMapLocationForUuid(uuid));
} }
MapLocation *MapLocationModel::getMapLocationForUuid(quint32 uuid) MapLocation *MapLocationModel::getMapLocationForUuid(quint32 uuid)

View file

@ -38,7 +38,7 @@ class MapLocationModel : public QAbstractListModel
{ {
Q_OBJECT Q_OBJECT
Q_PROPERTY(int count READ count NOTIFY countChanged) Q_PROPERTY(int count READ count NOTIFY countChanged)
Q_PROPERTY(quint32 selectedUuid READ selectedUuid WRITE setSelectedUuid NOTIFY selectedLocationChanged) Q_PROPERTY(quint32 selectedUuid MEMBER m_selectedUuid NOTIFY selectedLocationChanged)
public: public:
MapLocationModel(QObject *parent = NULL); MapLocationModel(QObject *parent = NULL);
@ -57,9 +57,8 @@ public:
protected: protected:
QHash<int, QByteArray> roleNames() const; QHash<int, QByteArray> roleNames() const;
private: public:
quint32 selectedUuid(); Q_INVOKABLE void setSelectedUuid(QVariant uuid, QVariant fromClick = true);
void setSelectedUuid(quint32);
QVector<MapLocation *> m_mapLocations; QVector<MapLocation *> m_mapLocations;
QHash<int, QByteArray> m_roles; QHash<int, QByteArray> m_roles;