@@ -275,21 +275,24 @@ void ContextMenuController::clearOptions()
275275{
276276 m_options->setStringList (QStringList{});
277277
278- for (const auto & geoElements : std::as_const (m_contextGeoElements))
278+ for (const QList<GeoElement*> & geoElements : std::as_const (m_contextGeoElements))
279279 {
280280 if (geoElements.empty ())
281281 continue ;
282282
283- // DynamicEntity and DynamicEntityObservation objects should not be deleted
284- // They are owned by their MessageFeed
285- const GeoElement* ge = geoElements.first ();
286- if (const auto * de = dynamic_cast <const DynamicEntity*>(ge); de)
287- continue ;
288-
289- if (const auto * deo = dynamic_cast <const DynamicEntityObservation*>(ge); deo)
290- continue ;
283+ for (GeoElement* ge : geoElements)
284+ {
285+ if (!ge)
286+ continue ;
291287
292- qDeleteAll (geoElements);
288+ // anything that was previously identified from the view
289+ // that is owned by the controller should be deleted
290+ if (QObject* o = GeoElementUtils::toQObject (ge); o)
291+ {
292+ if (o->parent () == this )
293+ o->deleteLater ();
294+ }
295+ }
293296 }
294297 m_contextGeoElements.clear ();
295298}
@@ -363,14 +366,14 @@ void ContextMenuController::invokeIdentifyOnGeoView()
363366 auto idenfityLayers = geoView->identifyLayersAsync (m_contextScreenPosition, 5.0 , false , -1 , this );
364367 auto identifyGraphicsOverlays = geoView->identifyGraphicsOverlaysAsync (m_contextScreenPosition, 5.0 , false , -1 , this );
365368
366- QtFuture::whenAll (idenfityLayers, identifyGraphicsOverlays).then (this , [this ](const QList<IdentifyResultsVariant::FutureType> & identifyResults)
369+ QtFuture::whenAll (idenfityLayers, identifyGraphicsOverlays).then (this , [this ](const QList<IdentifyResultsVariant::FutureType>& identifyResults)
367370 {
368371 for (const IdentifyResultsVariant::FutureType& identifyResult : identifyResults)
369372 {
370373 if (identifyResult.index () == IdentifyResultsVariant::Types::LAYERS )
371374 {
372- LayerResultsManager resultsManager ( std::get<IdentifyResultsVariant::Types::LAYERS >(identifyResult).result () );
373- for (IdentifyLayerResult* result : std::as_const (resultsManager. m_results ) )
375+ const QList<Esri::ArcGISRuntime::IdentifyLayerResult*> results = std::get<IdentifyResultsVariant::Types::LAYERS >(identifyResult).result ();
376+ for (IdentifyLayerResult* result : results )
374377 {
375378 if (!result)
376379 continue ;
@@ -379,34 +382,42 @@ void ContextMenuController::invokeIdentifyOnGeoView()
379382 if (geoElementsAll.isEmpty ())
380383 continue ;
381384
385+ QList<GeoElement*> geoElementsToOwn{};
382386 QList<GeoElement*> geoElements{};
383- std::for_each ( std::begin (geoElementsAll), std::end (geoElementsAll), [&]( GeoElement* ge)
387+ for ( GeoElement* ge : geoElementsAll )
384388 {
389+ // any non-observations (Feature, etc) should be owned
385390 DynamicEntityObservation* deo = dynamic_cast <DynamicEntityObservation*>(ge);
386391 if (!deo)
387392 {
393+ geoElementsToOwn.append (ge);
388394 geoElements.append (ge);
389- return ;
395+ continue ;
390396 }
391397
392- // add any observations that are not the latest to the list to be preserved
398+ // observations other than the latest at the time of the click
399+ // should also be owned
393400 DynamicEntity* de = deo->dynamicEntity ();
394401 if (de->latestObservation ()->observationId () != deo->observationId ())
395402 {
403+ geoElementsToOwn.append (deo);
396404 geoElements.append (deo);
397- return ;
405+ continue ;
398406 }
399407
400- // for latest observations, add the entity itself and mark the observation as deleted
408+ // the remaining case is that the observation was itself the latest
409+ // so we add the dynamic entity instead of the observation element
410+ // and mark the observation as no longer needed
401411 geoElements.append (de);
402412 deo->deleteLater ();
403- });
413+ }
404414
405- // set the GeoElements to be managed by the tool
406- GeoElementUtils::setParent (geoElements , this );
415+ // set the observations and any other non-DynamicEntity GeoElements to be owned by the tool
416+ GeoElementUtils::setParent (geoElementsToOwn , this );
407417
408418 // add the geoElements to the context hash using the layer name as the key
409419 m_contextGeoElements.insert (result->layerContent ()->name (), geoElements);
420+ result->deleteLater ();
410421 }
411422 }
412423 else if (identifyResult.index () == IdentifyResultsVariant::Types::GRAPHICS )
@@ -492,7 +503,12 @@ void ContextMenuController::selectOption(const QString& option)
492503 if (!identifyTool)
493504 return ;
494505
506+ // transfer the geoelements to the identify controller which takes ownership of them
495507 identifyTool->showPopups (m_contextGeoElements);
508+
509+ // clear the list so that the elements will not be cleaned up by subsequent
510+ // long presses on the geoview
511+ m_contextGeoElements.clear ();
496512 }
497513 else if (option == OPTION_VIEWSHED )
498514 {
0 commit comments