Skip to content

Commit

Permalink
Split apart connection logic from permission requests logic (#1764)
Browse files Browse the repository at this point in the history
  • Loading branch information
bri12415 authored Nov 7, 2024
1 parent 349ca35 commit 483fe8c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 24 deletions.
40 changes: 17 additions & 23 deletions CppSamples/Search/FindPlace/FindPlace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,26 +101,13 @@ void FindPlace::componentComplete()
m_mapView->calloutData()->setVisible(false);
m_calloutData = m_mapView->calloutData();

// connect mapview signals
#ifdef PERMISSIONS_PLATFORM
startLocationPermission();
#else
connectSignals();
#endif

initiateLocation();
}

void FindPlace::connectSignals()
{
connect(m_mapView, &MapQuickView::drawStatusChanged, this, [this](DrawStatus drawStatus)
{
if (drawStatus != DrawStatus::Completed || m_mapView->locationDisplay()->isStarted())
return;

// turn on the location display
m_mapView->locationDisplay()->setAutoPanMode(LocationDisplayAutoPanMode::Recenter);
m_mapView->locationDisplay()->start();
});

connect(m_mapView, &MapQuickView::mousePressed, this, [this](QMouseEvent& /*event*/)
{
emit hideSuggestionView();
Expand Down Expand Up @@ -152,22 +139,29 @@ void FindPlace::connectSignals()
});
}

void FindPlace::startLocationPermission()
void FindPlace::initiateLocation()
{
#ifdef PERMISSIONS_PLATFORM
QLocationPermission locationPermission{};
locationPermission.setAccuracy(QLocationPermission::Accuracy::Precise);
locationPermission.setAvailability(QLocationPermission::Availability::WhenInUse);

qApp->requestPermission(locationPermission, [this, locationPermission](const QPermission& permission)
switch (qApp->checkPermission(locationPermission))
{
Q_UNUSED(permission)
if (qApp->checkPermission(locationPermission) == Qt::PermissionStatus::Denied)
{
case Qt::PermissionStatus::Undetermined:
qApp->requestPermission(locationPermission, this, &FindPlace::initiateLocation);
return;
case Qt::PermissionStatus::Denied:
emit locationPermissionDenied();
}
connectSignals();
});
return;
case Qt::PermissionStatus::Granted:
m_mapView->locationDisplay()->setAutoPanMode(LocationDisplayAutoPanMode::Recenter);
m_mapView->locationDisplay()->start();
return;
}
#else
m_mapView->locationDisplay()->setAutoPanMode(LocationDisplayAutoPanMode::Recenter);
m_mapView->locationDisplay()->start();
#endif
}

Expand Down
2 changes: 1 addition & 1 deletion CppSamples/Search/FindPlace/FindPlace.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class FindPlace : public QQuickItem
void setPoiTextHasFocus(bool hasFocus);
Esri::ArcGISRuntime::GeocodeParameters createParameters();
void onGeocodingCompleted_(const QList<Esri::ArcGISRuntime::GeocodeResult>& results);
void startLocationPermission();
void initiateLocation();

private:
Esri::ArcGISRuntime::Map* m_map = nullptr;
Expand Down

0 comments on commit 483fe8c

Please sign in to comment.