Arcgis Runtime SDK for Qt: Building Apps Lucas Danzinger & Koushik Hajra Agenda
Total Page:16
File Type:pdf, Size:1020Kb
ArcGIS Runtime SDK for Qt: Building Apps Lucas Danzinger & Koushik Hajra Agenda • What is Qt • ArcGIS Runtime SDK for Qt capabilities • Getting started • Fundamental development patterns • How Esri uses Qt • Where to go from here What is Qt? What is the Qt Framework? • Write once, run anywhere Portable • Builds as native C++ Approach- • Cross-platform libraries able • High-level abstractions • Pre-built some platforms Open • Source code available Qt Framework - Cross platform libraries for native app development - Business logic in C++. - UI in QML (JavaScript-based) - Write once, deploy everywhere - Linux, Windows, Mac, iOS, Android - Platform nuances are abstracted - Abstraction APIs for common native workflows - HTTP, local data storage, sensors, Bluetooth, etc How does it work? Your App ComboBox, Button, Qt GUI (and other) Libraries Charts, QImage QNetworkManager, QFile, etc Qt Abstracted API Language Java Objective C Objective C C++ C++ Native platform Android iOS macOS APIs (http, file i/o, Linux Windows (via JNI & NDK) (via cocoa) (via cocoa) sensors etc) C++ Compiler clang/gcc clang clang gcc MSVC Platform Which platforms can I build for? • Windows – x86, x64 • Linux – x64, arm 64 (beta) • macOS – x64 • Android – armv7, armv8, x86 • iOS – arm64, sim ArcGIS Runtime SDK for Qt capabilities Offline Routing Offline Geocoding Offline Geometry Offline Maps/Scenes Symbols & Renderers (with customizations) Data Collection and editing ArcGIS Runtime SDK for Qt Geoprocessing Augmented Reality Search/Identify/ Query/Popups Navigation ArcGIS Platform Utility Network & Identity ArcGIS Runtime SDK for Qt Capabilities Koushik Hajra Getting started Setup • Setup Qt: - Create account - Commercial license / open-source? - Install kits for target platforms • Setup ArcGIS Runtime SDK for Qt - Create developer account - https://developers.arcgis.com/qt/latest/ • Install compiler / SDK dependencies - macOS/iOS: Xcode compiler - Windows: Visual Studio compiler, debugging tools - Linux: GCC compiler - Android: Android NDK and SDK • IDE - Qt Creator App development patterns Runs on Linux, Ideal place to macOS & Runs on iOS & App Pattern API to use start for Windows Android QML with Qt Quick QML Web Developer Yes Yes C++ with Qt Quick C++ C++ Developer Yes Yes C++ with Qt Widgets C++ C++ Developer Yes No Commonly-used pattern https://developers.arcgis.com/qt/latest/qml/guide/qt-sdk-best-practices.htm The QML API • QML is a declarative language from The Qt Company - Declare components similarly to writing JSON or CSS • Write procedural code as JavaScript functions • Create UI rapidly with Qt Quick, with animation and prebuilt controls • The QML API extends QML with new types that expose ArcGIS Runtime functionality • Used by AppStudio The C++ API • Flexible: Create your UI with Qt Quick (targets any platforms) or Qt Widgets (targets desktop platforms) - Most common design pattern: QML UI, C++ business logic • Works with Local Server (QML API doesn’t) Need help choosing between C++ and QML APIs? See https://developers.arcgis.com/qt/latest/qml/guide/qt-sdk-best-practices.htm Building your first ArcGIS Runtime Qt app Koushik Hajra Runtime fundamental patterns + Qt Asynchronous API • The Runtime API is a modern, asynchronous API • Tasks - RouteTask, LocatorTask, OfflineMapTask, GeoprocessingTask, Map.save … - All follow the same pattern - All are Loadable - All have async functions to execute their tasks - TaskWatchers are returned for keep track of concurrent tasks • Signals & Slots - Signal == “event” - Slot == “event handler” - *Slots can be defined as standalone methods or inline lambda functions Asynchronous API – example LocatorTask Asynchronous API – example LocatorTask Asynchronous API – example LocatorTask (QML) Asynchronous coding with Qt Koushik Hajra Memory management • C++ is not a managed language • Memory is not automatically handled for you - Pros - Close to the metal - Fine tuned performance - Fast - Can run on memory constrained devices - Cons - A little extra work for you Memory management – Qt Parent/Child • When you create a new object, you pass in a parent object. • When the parent object is deleted, so are the children • Can be any QObject – often you will see “this” • Any object you create on the heap, it is up to you to manage • Any object we return always has a parent (but you can re-set) Memory management – Clean up when you are done • Apps with lots of temporary graphics added and removed - You don’t want memory allocated for the lifetime of the app • Signals passing through pointers - The parent object is set by our API - No leaks, but memory will grow each time it emits • Use RAII – Resource Acquisition is Initialization - e.g. C++11 “smart pointers” – std::shared_ptr, std::unique_ptr - Other methods… Memory management – QML C++ memory management Koushik Hajra ListModels • Qt’s way of doing MVC/MVVM • Mutable lists exposed as list models in Runtime API - LayerListModel, GraphicListModel, etc • List Models can be displayed with - ListViews - TableViews - GridViews • Model – the data • View – what is displayed • Delegate – access the model’s “roles” ListModels – Map Layer Documentation ListModels – Map Layer List Example List Models Koushik Hajra Wrap up How is Esri using Qt? Runtime Core (for testing) How to get started using the SDK • Create a developer account - https://developers.arcgis.com/sign-up • Download Qt Framework and ArcGIS Runtime SDK for Qt - https://developers.arcgis.com/qt/latest/cpp/guide/install-and-set-up-on-windows.htm et al • Read the guide’s fundamental topics - https://developers.arcgis.com/qt/latest/qml/guide/arcgis-runtime-sdk-for-qt.htm • Study and modify the samples - https://github.com/Esri/arcgis-runtime-samples-qt • Use the Forum and join the community discussion - https://geonet.esri.com/community/developers/native-app-developers/arcgis-runtime-sdk-for-qt/ .