Map: export isSelected as attribute from MapLocationModel

Recently we changed the MapLocationModel-items to store whether
they are selected. Thus, we can directly export an isSelected
flag instead of calling a function taking a dive-site argument.

1) This makes the QML easier to read.
2) This avoids passing pointers through QML which has caused
   us lots of pain.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2019-08-31 23:24:21 +02:00 committed by Dirk Hohndel
parent 9322092e41
commit 1d01fff006
3 changed files with 8 additions and 4 deletions

View file

@ -66,7 +66,7 @@ Item {
PropertyAnimation { target: mapItemImage; property: "scale"; from: 0.7; to: 1.0; duration: 80 }
}
MouseArea {
drag.target: (mapHelper.editMode && mapHelper.model.isSelected(model.divesite)) ? mapItem : undefined
drag.target: (mapHelper.editMode && model.isSelected) ? mapItem : undefined
anchors.fill: parent
onClicked: {
if (!mapHelper.editMode && model.divesite)
@ -74,7 +74,7 @@ Item {
}
onDoubleClicked: map.doubleClickHandler(mapItem.coordinate)
onReleased: {
if (mapHelper.editMode && mapHelper.model.isSelected(model.divesite)) {
if (mapHelper.editMode && model.isSelected) {
mapHelper.updateCurrentDiveSiteCoordinatesFromMap(model.divesite, mapItem.coordinate)
}
}
@ -94,7 +94,7 @@ Item {
id: mapItemText
text: model.name
font.pointSize: 11.0
color: mapHelper.model.isSelected(model.divesite) ? "white" : "lightgrey"
color: model.isSelected ? "white" : "lightgrey"
}
}
}

View file

@ -48,6 +48,8 @@ QVariant MapLocation::getRole(int role) const
QString("qrc:///dive-location-marker-icon");
case Roles::RoleZ:
return m_selected ? 1 : 0;
case Roles::RoleIsSelected:
return QVariant::fromValue(m_selected);
default:
return QVariant();
}
@ -105,6 +107,7 @@ QHash<int, QByteArray> MapLocationModel::roleNames() const
roles[MapLocation::Roles::RoleName] = "name";
roles[MapLocation::Roles::RolePixmap] = "pixmap";
roles[MapLocation::Roles::RoleZ] = "z";
roles[MapLocation::Roles::RoleIsSelected] = "isSelected";
return roles;
}

View file

@ -33,7 +33,8 @@ public:
RoleCoordinate,
RoleName,
RolePixmap,
RoleZ
RoleZ,
RoleIsSelected
};
private: