Skip to content

Commit ca2b5ad

Browse files
Merge pull request #600 from Esri/james/async_updates
James/async updates
2 parents 8a4f6c9 + 85f3ea3 commit ca2b5ad

18 files changed

+239
-230
lines changed

uitools/cpp/Esri/ArcGISRuntime/Toolkit/BasemapGalleryItem.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,11 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
******************************************************************************/
16-
#include "BasemapGalleryController.h"
16+
#include "BasemapGalleryItem.h"
1717

1818
// Toolkit headers
1919
#include "Internal/BasemapGalleryImageProvider.h"
2020
#include "Internal/DoOnLoad.h"
21-
#include "Internal/GeoViews.h"
2221

2322
// ArcGISRuntime headers
2423
#include <Basemap.h>
@@ -28,6 +27,7 @@
2827

2928
// Qt headers
3029
#include <QIcon>
30+
#include <QFuture>
3131

3232
#ifdef CPP_ARCGISRUNTIME_TOOLKIT
3333
// Qt headers
@@ -185,8 +185,17 @@ namespace Esri::ArcGISRuntime::Toolkit {
185185

186186
return;
187187
}
188-
connect(item, &Item::fetchThumbnailCompleted, this, &BasemapGalleryItem::basemapChanged);
189-
item->fetchThumbnail();
188+
189+
// fetchThumbnailAsync returns a single future, so don't keep attaching continuations
190+
// if it's already running
191+
auto future = item->fetchThumbnailAsync();
192+
if (!future.isRunning())
193+
{
194+
future.then(this, [this](const QImage&)
195+
{
196+
emit basemapChanged();
197+
});
198+
}
190199
});
191200
}
192201
emit basemapChanged();

uitools/cpp/Esri/ArcGISRuntime/Toolkit/BookmarksViewController.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
// Qt headers
2525
#include <QtGlobal>
26+
#include <QFuture>
2627

2728
// ArcGISRuntime headers
2829
#include <Bookmark.h>
@@ -255,11 +256,13 @@ namespace Esri::ArcGISRuntime::Toolkit {
255256

256257
if (auto sceneView = qobject_cast<SceneViewToolkit*>(m_geoView))
257258
{
258-
sceneView->setBookmark(bookmark->bookmark());
259+
auto future = sceneView->setBookmarkAsync(bookmark->bookmark());
260+
Q_UNUSED(future)
259261
}
260262
else if (auto mapView = qobject_cast<MapViewToolkit*>(m_geoView))
261263
{
262-
mapView->setBookmark(bookmark->bookmark());
264+
auto future = mapView->setBookmarkAsync(bookmark->bookmark());
265+
Q_UNUSED(future)
263266
}
264267
}
265268

uitools/cpp/Esri/ArcGISRuntime/Toolkit/CoordinateConversionController.cpp

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <QMouseEvent>
2525
#include <QtGlobal>
2626
#include <QUuid>
27+
#include <QPointF>
2728

2829
// ArcGISRuntime headers
2930
#include <Camera.h>
@@ -156,22 +157,17 @@ void CoordinateConversionController::setGeoView(QObject* geoView)
156157
connect(sceneView, &SceneViewToolkit::mouseClicked, this,
157158
[sceneView, this](QMouseEvent& event)
158159
{
159-
if (m_inPickingMode && (!m_screenToLocationTask.isValid() ||
160-
m_screenToLocationTask.isDone()))
160+
if (m_inPickingMode && !m_screenToLocationFuture.isRunning())
161161
{
162-
m_screenToLocationTask = sceneView->screenToLocation(event.pos().x(), event.pos().y());
162+
m_screenToLocationFuture = sceneView->screenToLocationAsync(event.pos().x(), event.pos().y());
163+
m_screenToLocationFuture.then(this, [this](const Point& point)
164+
{
165+
setCurrentPoint(point);
166+
});
167+
163168
event.accept();
164169
}
165170
});
166-
167-
connect(sceneView, &SceneViewToolkit::screenToLocationCompleted, this,
168-
[this](QUuid taskId, Point point)
169-
{
170-
if (taskId != m_screenToLocationTask.taskId())
171-
return;
172-
173-
setCurrentPoint(point);
174-
});
175171
}
176172
else if (auto mapView = qobject_cast<MapViewToolkit*>(m_geoView))
177173
{
@@ -341,13 +337,15 @@ void CoordinateConversionController::zoomToCurrentPoint()
341337
{
342338
const Camera currentCam = sceneView->currentViewpointCamera();
343339
const Camera newCam(m_currentPoint, m_zoomToDistance, currentCam.heading(), currentCam.pitch(), currentCam.roll());
344-
sceneView->setViewpointCamera(newCam, 1.0);
340+
auto future = sceneView->setViewpointCameraAsync(newCam, 1.0);
341+
Q_UNUSED(future)
345342
}
346343
else if (auto mapView = qobject_cast<MapView*>(m_geoView))
347344
{
348345
const Viewpoint currVP = mapView->currentViewpoint(ViewpointType::CenterAndScale);
349346
const Viewpoint newViewPoint(m_currentPoint, currVP.targetScale());
350-
mapView->setViewpoint(newViewPoint, 1.0);
347+
auto future = mapView->setViewpointAsync(newViewPoint, 1.0);
348+
Q_UNUSED(future)
351349
}
352350
}
353351

uitools/cpp/Esri/ArcGISRuntime/Toolkit/CoordinateConversionController.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,18 @@
2121
#include "Internal/GenericListModel.h"
2222

2323
// Qt headers
24+
#include <QFuture>
2425
#include <QObject>
2526
#include <QString>
26-
#include <QPointF>
2727

2828
// Qt forward declarations
2929
class QAbstractListModel;
3030

3131
// ArcGISRuntime headers
3232
#include <Point.h>
33-
#include <TaskWatcher.h>
33+
34+
Q_MOC_INCLUDE(<QPointF>)
35+
class QPointF;
3436

3537
namespace Esri::ArcGISRuntime {
3638

@@ -100,8 +102,8 @@ public slots:
100102
void removeCoordinateResultAtIndex(int index);
101103

102104
private:
105+
QFuture<Point> m_screenToLocationFuture;
103106
Point m_currentPoint;
104-
TaskWatcher m_screenToLocationTask;
105107
double m_zoomToDistance = 0.0;
106108
GenericListModel* m_coordinateFormats = nullptr;
107109
GenericListModel* m_conversionResults = nullptr;

uitools/cpp/Esri/ArcGISRuntime/Toolkit/FloorFilterController.cpp

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
******************************************************************************/
1616
#include "FloorFilterController.h"
1717

18+
#include <QFuture>
19+
1820
// ArcGISRuntime headers
1921
#include <Envelope.h>
2022
#include <EnvelopeBuilder.h>
@@ -36,7 +38,6 @@
3638
#include "Internal/DisconnectOnSignal.h"
3739
#include "Internal/DoOnLoad.h"
3840
#include "Internal/GeoViews.h"
39-
#include "Internal/SingleShotConnection.h"
4041

4142
// stl headers
4243
#include <cmath>
@@ -881,31 +882,25 @@ namespace Esri::ArcGISRuntime::Toolkit {
881882

882883
if (auto mapView = qobject_cast<MapViewToolkit*>(m_geoView))
883884
{
884-
auto c = std::make_shared<QMetaObject::Connection>();
885885
m_settingViewpoint = true;
886-
*c = connect(mapView, &MapViewToolkit::setViewpointCompleted, this, [this, c](bool success)
887-
{
888-
if (success)
889-
{
890-
m_settingViewpoint = false;
891-
disconnect(*c);
892-
}
893-
});
894-
mapView->setViewpoint(b.toEnvelope());
886+
mapView->setViewpointAsync(b.toEnvelope()).then(this, [this](bool success)
887+
{
888+
if (success)
889+
{
890+
m_settingViewpoint = false;
891+
}
892+
});
895893
}
896894
else if (auto sceneView = qobject_cast<SceneViewToolkit*>(m_geoView))
897895
{
898-
auto c = std::make_shared<QMetaObject::Connection>();
899896
m_settingViewpoint = true;
900-
*c = connect(sceneView, &SceneViewToolkit::setViewpointCompleted, this, [this, c](bool success)
901-
{
902-
if (success)
903-
{
904-
m_settingViewpoint = false;
905-
disconnect(*c);
906-
}
907-
});
908-
sceneView->setViewpoint(b.toEnvelope());
897+
sceneView->setViewpointAsync(b.toEnvelope()).then(this, [this](bool success)
898+
{
899+
if (success)
900+
{
901+
m_settingViewpoint = false;
902+
}
903+
});
909904
}
910905
}
911906

uitools/cpp/Esri/ArcGISRuntime/Toolkit/Internal/BasemapGalleryImageProvider.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <Item.h>
2424

2525
// Qt headers
26+
#include <QFuture>
2627
#include <QIcon>
2728

2829
namespace Esri::ArcGISRuntime::Toolkit {
@@ -102,8 +103,10 @@ namespace Esri::ArcGISRuntime::Toolkit {
102103
emit finished();
103104
return;
104105
}
105-
connect(item, &Item::fetchThumbnailCompleted, this, &BasemapGalleryImageResponse::finished);
106-
item->fetchThumbnail();
106+
item->fetchThumbnailAsync().then(this, [this](QImage)
107+
{
108+
emit finished();
109+
});
107110
});
108111
}
109112

uitools/cpp/Esri/ArcGISRuntime/Toolkit/LocatorSearchSource.cpp

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -116,21 +116,6 @@ namespace Esri::ArcGISRuntime::Toolkit {
116116
LocatorSearchSource::setMaximumResults(DEFAULT_MAXIMUM_RESULTS);
117117
LocatorSearchSource::setMaximumSuggestions(DEFAULT_MAXIMUM_SUGGESTIONS);
118118

119-
connect(m_locatorTask, &LocatorTask::geocodeCompleted, this, [this](QUuid taskId, const QList<Esri::ArcGISRuntime::GeocodeResult>& geocodeResults)
120-
{
121-
if (m_searchTask.taskId() != taskId)
122-
return;
123-
124-
QList<SearchResult*> results;
125-
126-
for (const auto& g : geocodeResults)
127-
{
128-
results << resultFromGeocodeResult(g, this);
129-
}
130-
131-
emit searchCompleted(std::move(results));
132-
});
133-
134119
doOnLoaded(locatorTask, this, [this]
135120
{
136121
const auto& info = m_locatorTask->locatorInfo();
@@ -261,23 +246,43 @@ namespace Esri::ArcGISRuntime::Toolkit {
261246
return m_locatorTask->suggestions();
262247
}
263248

249+
void LocatorSearchSource::onGeocodeCompleted_(const QList<GeocodeResult>& geocodeResults)
250+
{
251+
QList<SearchResult*> results;
252+
253+
for (const auto& g : geocodeResults)
254+
{
255+
results << resultFromGeocodeResult(g, this);
256+
}
257+
258+
emit searchCompleted(std::move(results));
259+
}
260+
264261
/*!
265262
\reimp
266263
*/
267264
void LocatorSearchSource::search(const SuggestResult& suggestion, Geometry area)
268265
{
269-
m_searchTask.cancel();
266+
m_geocodeFuture.cancel();
270267

271268
auto params = normalizeGeometryParams(m_geocodeParameters, area);
272-
m_searchTask = m_locatorTask->geocodeWithSuggestResultAndParameters(suggestion, params);
269+
m_geocodeFuture = m_locatorTask->geocodeWithSuggestResultAndParametersAsync(suggestion, params);
270+
m_geocodeFuture.then(this, [this](const QList<GeocodeResult>& geocodeResults)
271+
{
272+
onGeocodeCompleted_(geocodeResults);
273+
});
273274
}
274275

275276
void LocatorSearchSource::search(const QString& searchString, Geometry area)
276277
{
277-
m_searchTask.cancel();
278+
m_geocodeFuture.cancel();
278279

279280
auto params = normalizeGeometryParams(m_geocodeParameters, area);
280-
m_searchTask = m_locatorTask->geocodeWithParameters(searchString, params);
281+
m_geocodeFuture = m_locatorTask->geocodeWithParametersAsync(searchString, params);
282+
m_geocodeFuture.then(this, [this](const QList<GeocodeResult>& geocodeResults)
283+
{
284+
onGeocodeCompleted_(geocodeResults);
285+
});
281286
}
282287

283288
} // Esri::ArcGISRuntime::Toolkit

uitools/cpp/Esri/ArcGISRuntime/Toolkit/LocatorSearchSource.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@
2929
#include <QList>
3030
#include <QObject>
3131

32+
namespace Esri::ArcGISRuntime {
33+
class GeocodeResult;
34+
}
35+
3236
namespace Esri::ArcGISRuntime::Toolkit {
3337

3438
class LocatorSearchSource : public SearchSourceInterface
@@ -62,10 +66,11 @@ namespace Esri::ArcGISRuntime::Toolkit {
6266
void search(const QString& searchString, Geometry area = Geometry{}) override;
6367

6468
protected:
65-
TaskWatcher m_searchTask;
69+
virtual void onGeocodeCompleted_(const QList<GeocodeResult>& geocodeResults);
70+
QFuture<QList<GeocodeResult>> m_geocodeFuture;
6671

6772
private:
68-
LocatorTask* m_locatorTask;
73+
LocatorTask* m_locatorTask = nullptr;
6974
GeocodeParameters m_geocodeParameters;
7075

7176
};

uitools/cpp/Esri/ArcGISRuntime/Toolkit/NorthArrowController.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
#include "Internal/GeoViews.h"
1919

2020
#include "Camera.h"
21-
#include "TaskWatcher.h"
21+
22+
#include <QFuture>
2223

2324
// std headers
2425
#include <cmath>
@@ -62,13 +63,15 @@ namespace Esri::ArcGISRuntime::Toolkit {
6263
{
6364
if (auto mapView = qobject_cast<MapView*>(m_geoView))
6465
{
65-
mapView->setViewpointRotation(heading);
66+
auto future = mapView->setViewpointRotationAsync(heading);
67+
Q_UNUSED(future)
6668
}
6769
else if (auto sceneView = qobject_cast<SceneView*>(m_geoView))
6870
{
6971
Camera currentCamera = sceneView->currentViewpointCamera();
7072
Camera updatedCamera = currentCamera.rotateTo(heading, currentCamera.pitch(), currentCamera.roll());
71-
sceneView->setViewpointCamera(updatedCamera, 0.50);
73+
auto future = sceneView->setViewpointCameraAsync(updatedCamera, 0.50);
74+
Q_UNUSED(future)
7275
}
7376
}
7477
/*!

0 commit comments

Comments
 (0)