Create, query and edit a specific server version using service geodatabase.

Use case
Workflows often progress in discrete stages, with each stage requiring the allocation of a different set of resources and business rules. Typically, each stage in the overall process represents a single unit of work, such as a work order or job. To manage these, you can create a separate, isolated version and modify it. Once this work is complete, you can integrate the changes into the default version.
How to use the sample
Once loaded, the map will zoom to the extent of the feature layer. The current version is indicated at the top of the map. Click “Create Version” to open a dialog to specify the version information (name, access, and description). See the Additional information section for restrictions on the version name.
Click “Create” to create the version with the information that you specified. Select a feature to edit an attribute and/or click a second time to relocate the point.
Click the button in the top left corner to switch back and forth between the version you created and the default version. Edits will automatically be applied to your version when switching to the default version.
How it works
- Create and load a
ServiceGeodatabasewith a feature service URL that has enabled Version Management. - Get the
ServiceFeatureTablefrom the service geodatabase. - Create a
FeatureLayerfrom the service feature table. - Create
ServiceVersionParameterswith a unique name,VersionAccess, and description.- Note - See the additional information section for more restrictions on the version name.
- Create a new version calling
ServiceGeodatabase::createVersionAsyncpassing in the service version parameters. - Obtain the
ServiceVersionInfoof the version created in your future async handler. - Switch to the version you have just created using
ServiceGeodatabase::switchVersionAsync, passing in the version name obtained from the service version info from step 6. - Select a
Featurefrom the map to edit its “TYPDAMAGE” attribute and location. - Apply these edits to your version by calling
ServiceGeodatabase::applyEditsAsync. - Switch back and forth between your version and the default version to see how the two versions differ.
Relevant API
- FeatureLayer
- ServiceFeatureTable
- ServiceGeodatabase
- ServiceGeodatabase::applyEditsAsync
- ServiceGeodatabase::createVersionAsync
- ServiceGeodatabase::switchVersionAsync
- ServiceVersionInfo
- ServiceVersionParameters
- VersionAccess
About the data
The feature layer used in this sample is Damage to commercial buildings located in Naperville, Illinois.
Additional information
Credentials:
- Username: editor01
- Password: S7#i2LWmYH75
The name of the version must meet the following criteria:
- Must not exceed 62 characters
- Must not include: Period (.), Semicolon (;), Single quotation mark (’), Double quotation mark (”)
- Must not include a space for the first character
- Note - the version name will have the username and a period (.) prepended to it. E.g “editor01.MyNewUniqueVersionName”
Branch versioning access permission:
- VersionAccess::Public - Any portal user can view and edit the version.
- VersionAccess::Protected - Any portal user can view, but only the version owner, feature layer owner, and portal administrator can edit the version.
- VersionAccess::Private - Only the version owner, feature layer owner, and portal administrator can view and edit the version.
Tags
branch versioning, edit, version control, version management server
Sample Code
// [WriteFile Name=EditWithBranchVersioning, Category=EditData]// [Legal]// Copyright 2020 Esri.//// Licensed under the Apache License, Version 2.0 (the "License");// you may not use this file except in compliance with the License.// You may obtain a copy of the License at// http://www.apache.org/licenses/LICENSE-2.0//// Unless required by applicable law or agreed to in writing, software// distributed under the License is distributed on an "AS IS" BASIS,// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.// See the License for the specific language governing permissions and// limitations under the License.// [Legal]
#ifdef PCH_BUILD#include "pch.hpp"#endif // PCH_BUILD
// sample headers#include "EditWithBranchVersioning.h"
// ArcGIS Maps SDK headers#include "ArcGISRuntimeEnvironment.h"#include "Authentication/AuthenticationManager.h"#include "Authentication/ArcGISAuthenticationChallenge.h"#include "Authentication/TokenCredential.h"#include "ArcGISFeature.h"#include "AttributeListModel.h"#include "CalloutData.h"#include "Envelope.h"#include "ErrorException.h"#include "FeatureEditResult.h"#include "FeatureLayer.h"#include "FeatureTableEditResult.h"#include "IdentifyLayerResult.h"#include "Layer.h"#include "LayerListModel.h"#include "Map.h"#include "MapQuickView.h"#include "MapTypes.h"#include "Point.h"#include "Polyline.h"#include "ServiceFeatureTable.h"#include "ServiceGeodatabase.h"#include "ServiceTypes.h"#include "ServiceVersionInfo.h"#include "ServiceVersionParameters.h"#include "Viewpoint.h"
// Qt headers#include <QFuture>
using namespace Esri::ArcGISRuntime;using namespace Esri::ArcGISRuntime::Authentication;
namespace{ // Convenience RAII struct that deletes all pointers in given container. struct FeatureTableEditResultsScopedCleanup { FeatureTableEditResultsScopedCleanup(const QList<FeatureTableEditResult*>& list) : results(list) { } ~FeatureTableEditResultsScopedCleanup() { qDeleteAll(results); } const QList<FeatureTableEditResult*>& results; };}
EditWithBranchVersioning::EditWithBranchVersioning(QObject* parent /* = nullptr */): ArcGISAuthenticationChallengeHandler(parent), m_map(new Map(BasemapStyle::ArcGISStreets, this)){ ArcGISRuntimeEnvironment::authenticationManager()->setArcGISAuthenticationChallengeHandler(this);}
EditWithBranchVersioning::~EditWithBranchVersioning() = default;
void EditWithBranchVersioning::init(){ // Register the map view for QML qmlRegisterType<MapQuickView>("Esri.Samples", 1, 0, "MapView"); qmlRegisterType<EditWithBranchVersioning>("Esri.Samples", 1, 0, "EditWithBranchVersioningSample");}
MapQuickView* EditWithBranchVersioning::mapView() const{ return m_mapView;}
// Set the view (created in QML)void EditWithBranchVersioning::setMapView(MapQuickView* mapView){ if (!mapView || mapView == m_mapView) return;
m_mapView = mapView; m_mapView->setMap(m_map);
m_busy = true; emit busyChanged();
// When map is done loading set up service geodatabse signals and map signals connect(m_map, &Map::doneLoading, this, &EditWithBranchVersioning::onMapDoneLoading_);
emit mapViewChanged();}
void EditWithBranchVersioning::onMapDoneLoading_(const Error& error){ if (!error.isEmpty()) return;
// connect all needed service geodatabase signals connectSgdbSignals();
connect(m_mapView, &MapQuickView::mouseClicked, this, [this](QMouseEvent& mouseEvent) { m_busy = true; emit busyChanged(); // first clear the selection m_featureLayer->clearSelection();
emit hideWindow();
// if feature is already selected, then move to new location if (m_selectedFeature) { if (m_serviceGeodatabase->versionName() == m_serviceGeodatabase->defaultVersionName()) { clearSelectedFeature(); m_busy = false; emit busyChanged(); return; } const Point clickedPoint = m_mapView->screenToLocation(mouseEvent.position().x(), mouseEvent.position().y()); moveFeature(clickedPoint); } else { // call identify on the map view m_mapView->identifyLayerAsync(m_featureLayer, mouseEvent.position(), 5, false, 1).then(this, [this](IdentifyLayerResult* identifyResult) { onIdentifyLayerCompleted_(identifyResult); }); } });
connect(m_mapView, &MapQuickView::viewpointChanged, this, [this]() { if (!m_featureLayer) return;
m_featureLayer->clearSelection(); clearSelectedFeature(); emit hideWindow(); });}
void EditWithBranchVersioning::connectSgdbSignals(){ m_serviceGeodatabase = new ServiceGeodatabase(QUrl("https://sampleserver7.arcgisonline.com/server/rest/services/DamageAssessment/FeatureServer"), this); m_busy = true; emit busyChanged();
connect(m_serviceGeodatabase, &ServiceGeodatabase::doneLoading, this, &EditWithBranchVersioning::onSgdbDoneLoadingCompleted_);
m_serviceGeodatabase->load();}
void EditWithBranchVersioning::onSwitchVersionCompleted_(){ m_busy = false; emit busyChanged(); // set the current version name for the UI m_sgdbCurrentVersionName = m_serviceGeodatabase->versionName(); // if the current version is the default, prevent editing m_sgdbVersionIsDefault = m_sgdbCurrentVersionName == m_serviceGeodatabase->defaultVersionName() ? true : false; clearSelectedFeature(); emit sgdbVersionIsDefaultChanged(); emit sgdbCurrentVersionChanged();}
void EditWithBranchVersioning::onSgdbDoneLoadingCompleted_(const Error& error){ if (!error.isEmpty()) return;
// created service feature table from the table contained in the service geodatabase m_featureTable = m_serviceGeodatabase->table(0);
connect(m_featureTable, &ServiceFeatureTable::doneLoading, this, [this](const Error& error) { if (!error.isEmpty()) return;
// once the service feature table is loaded set the mapview extent to the full extent of the feature layer m_mapView->setViewpointAsync(m_featureLayer->fullExtent());
m_busy = false; emit busyChanged(); });
// create a feature layer from the service feature table m_featureLayer = new FeatureLayer(m_featureTable, this);
// add the feature layer to the map m_map->operationalLayers()->append(m_featureLayer);
// update current version for UI m_sgdbCurrentVersionName = m_serviceGeodatabase->versionName(); emit sgdbCurrentVersionChanged();}
void EditWithBranchVersioning::onCreateVersionCompleted_(ServiceVersionInfo* serviceVersionInfo){ // check for local edits before switching versions if (m_serviceGeodatabase->hasLocalEdits()) return;
// ensure the created version was succesful if (!serviceVersionInfo) return;
m_busy = false; emit busyChanged(); emit createVersionSuccess();
// store create version name for easy switching between default and created version m_createdVersionName = serviceVersionInfo->name();
// switch to the version you just created m_serviceGeodatabase->switchVersionAsync(m_createdVersionName).then(this, [this]() { onSwitchVersionCompleted_(); }).onFailed(this, [this](const ErrorException& e) { onTaskFailed_(e); });}
void EditWithBranchVersioning::applyEdits(){ m_busy = true; emit busyChanged();
if (m_serviceGeodatabase->hasLocalEdits()) { emit applyingEdits(); m_serviceGeodatabase->applyEditsAsync().then(this, [this](const QList<FeatureTableEditResult*>& featureTableEditResults) { onApplyEditsCompleted_(featureTableEditResults); }); } else switchVersion();}
void EditWithBranchVersioning::switchVersion(){ // if the current version is our created version switch to the default const QString versionName = m_serviceGeodatabase->versionName() == m_serviceGeodatabase->defaultVersionName() ? m_createdVersionName : m_serviceGeodatabase->defaultVersionName();
m_serviceGeodatabase->switchVersionAsync(versionName).then(this, [this]() { onSwitchVersionCompleted_(); }).onFailed(this, [this](const ErrorException& e) { onTaskFailed_(e); });}
void EditWithBranchVersioning::updateAttribute(const QString& attributeValue){ m_busy = true; emit busyChanged(); if (!m_selectedFeature) return;
if (sgdbVerionIsDefault()) { clearSelectedFeature(); return; }
// update the attirbute with the selection from the combo box m_selectedFeature->attributes()->replaceAttribute("TYPDAMAGE", attributeValue); m_selectedFeature->featureTable()->updateFeatureAsync(m_selectedFeature).then(this, [this]() { m_busy = false; emit busyChanged(); });}
void EditWithBranchVersioning::createVersion(const QString& versionName, const QString& versionAccess, const QString& description){ m_busy = true; emit busyChanged(); // create parameters for version from the inputed fields from the UI ServiceVersionParameters* params = new ServiceVersionParameters(this); params->setName(versionName); params->setDescription(description);
if (versionAccess == "Private") params->setAccess(VersionAccess::Private); else if (versionAccess == "Protected") params->setAccess(VersionAccess::Protected); else params->setAccess(VersionAccess::Public);
m_serviceGeodatabase->createVersionAsync(params).then(this, [this](ServiceVersionInfo* serviceVersionInfo) { onCreateVersionCompleted_(serviceVersionInfo); }).onFailed(this, [this](const ErrorException& e) { onTaskFailed_(e); });}
void EditWithBranchVersioning::moveFeature(const Point& mapPoint){ if (sgdbVerionIsDefault()) { clearSelectedFeature(); return; } const Polyline geom = geometry_cast<Polyline>(m_selectedFeature->geometry()); m_selectedFeature->setGeometry(mapPoint);
// update the selected feature with the new geometry m_selectedFeature->featureTable()->updateFeatureAsync(m_selectedFeature).then(this, [this]() { m_busy = false; emit busyChanged(); }); clearSelectedFeature();}
void EditWithBranchVersioning::clearSelection(){ // helper function to clear feature layer selection if (m_featureLayer) m_featureLayer->clearSelection();}
bool EditWithBranchVersioning::sgdbVerionIsDefault() const{ // helper function to check if the current version is the default version return m_serviceGeodatabase->versionName() == m_serviceGeodatabase->defaultVersionName() ? true : false;}
void EditWithBranchVersioning::clearSelectedFeature(){ // helper function to clean up the selected feature when invalidated delete m_selectedFeature; m_selectedFeature = nullptr; clearSelection();}
void EditWithBranchVersioning::onIdentifyLayerCompleted_(IdentifyLayerResult* identifyResult){ if (!identifyResult) { clearSelectedFeature(); return; } if (!identifyResult->geoElements().empty()) { m_selectedFeature = static_cast<ArcGISFeature*>(identifyResult->geoElements().at(0)); // select the item in the result m_featureLayer->selectFeature(m_selectedFeature);
// Obtain placename attribute for the callout title const QString featureName = m_selectedFeature->attributes()->attributeValue("PLACENAME").toString(); m_mapView->calloutData()->setTitle(QString("<br><font size=\"+2\">%1</font>").arg(featureName)); m_mapView->calloutData()->setLocation(m_selectedFeature->geometry().extent().center());
m_currentTypeDamage = m_selectedFeature->attributes()->attributeValue("TYPDAMAGE").toString(); emit currentTypeDamageChanged(); emit featureSelected(); } m_busy = false; emit busyChanged();}
void EditWithBranchVersioning::onApplyEditsCompleted_(const QList<FeatureTableEditResult*>& featureTableEditResults){ // A convenience wrapper that deletes the contents of featureEditResults when we leave scope. FeatureTableEditResultsScopedCleanup featureTableEditResultsCleanup(featureTableEditResults);
for (FeatureTableEditResult* featureTableEditResult : featureTableEditResults) { const QList<FeatureEditResult*> results = featureTableEditResult->editResults(); for (FeatureEditResult* featureEditResult : results) { if (!featureEditResult->error().isEmpty()) { m_errorMessage = featureEditResult->error().message() + " - " + featureEditResult->error().additionalMessage(); emit errorMessageChanged(); m_busy = false; emit busyChanged(); return; } } } emit applyingEditsCompleted(); switchVersion();}
void EditWithBranchVersioning::onTaskFailed_(const ErrorException& taskException){ m_errorMessage = taskException.error().message() + " - " + taskException.error().additionalMessage(); emit errorMessageChanged(); m_busy = false; emit busyChanged();}
void EditWithBranchVersioning::handleArcGISAuthenticationChallenge(ArcGISAuthenticationChallenge* challenge){ TokenCredential::createWithChallengeAsync(challenge, "editor01", "S7#i2LWmYH75", {}, this).then(this, [challenge](TokenCredential* tokenCredential) { challenge->continueWithCredential(tokenCredential); }).onFailed(this, [challenge](const ErrorException& e) { challenge->continueWithError(e.error()); });}// [WriteFile Name=EditWithBranchVersioning, Category=EditData]// [Legal]// Copyright 2020 Esri.//// Licensed under the Apache License, Version 2.0 (the "License");// you may not use this file except in compliance with the License.// You may obtain a copy of the License at// http://www.apache.org/licenses/LICENSE-2.0//// Unless required by applicable law or agreed to in writing, software// distributed under the License is distributed on an "AS IS" BASIS,// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.// See the License for the specific language governing permissions and// limitations under the License.// [Legal]
#ifndef EDITWITHBRANCHVERSIONING_H#define EDITWITHBRANCHVERSIONING_H
// ArcGIS Maps SDK headers#include "Authentication/ArcGISAuthenticationChallengeHandler.h"#include "Error.h"
// Qt headers#include <QUrl>#include <QUuid>
namespace Esri::ArcGISRuntime{class ServiceVersionParameters;class Map;class MapQuickView;class ServiceGeodatabase;class FeatureLayer;class ServiceFeatureTable;class ServiceVersionInfo;class ArcGISFeature;class Point;class IdentifyLayerResult;class ErrorException;class FeatureTableEditResult;}
namespace Esri::ArcGISRuntime::Authentication{ class ArcGISAuthenticationChallenge;}
Q_MOC_INCLUDE("MapQuickView.h")
class EditWithBranchVersioning : public Esri::ArcGISRuntime::Authentication::ArcGISAuthenticationChallengeHandler{ Q_OBJECT
Q_PROPERTY(Esri::ArcGISRuntime::MapQuickView* mapView READ mapView WRITE setMapView NOTIFY mapViewChanged) Q_PROPERTY(QString sgdbCurrentVersion MEMBER m_sgdbCurrentVersionName NOTIFY sgdbCurrentVersionChanged) Q_PROPERTY(QString currentTypeDamage MEMBER m_currentTypeDamage NOTIFY currentTypeDamageChanged) Q_PROPERTY(QString errorMessage MEMBER m_errorMessage NOTIFY errorMessageChanged) Q_PROPERTY(bool busy MEMBER m_busy NOTIFY busyChanged) Q_PROPERTY(bool sgdbVersionIsDefault MEMBER m_sgdbVersionIsDefault NOTIFY sgdbVersionIsDefaultChanged)
public: explicit EditWithBranchVersioning(QObject* parent = nullptr); ~EditWithBranchVersioning();
static void init();
Esri::ArcGISRuntime::ServiceVersionParameters* createParams(); void clearSelection(); void moveFeature(const Esri::ArcGISRuntime::Point& mapPoint); Q_INVOKABLE void applyEdits(); Q_INVOKABLE void clearSelectedFeature(); Q_INVOKABLE void createVersion(const QString& versionName, const QString& versionAccess, const QString& description); Q_INVOKABLE void switchVersion(); Q_INVOKABLE void updateAttribute(const QString& attributeValue);
signals: void applyingEdits(); void applyingEditsCompleted(); void busyChanged(); void createVersionSuccess(); void currentTypeDamageChanged(); void errorMessageChanged(); void featureSelected(); void hideWindow(); void mapViewChanged(); void sgdbCurrentVersionChanged(); void sgdbVersionIsDefaultChanged();
private: void onCreateVersionCompleted_(Esri::ArcGISRuntime::ServiceVersionInfo* serviceVersionInfo); void onMapDoneLoading_(const Esri::ArcGISRuntime::Error& error); void onSgdbDoneLoadingCompleted_(const Esri::ArcGISRuntime::Error& error); void onIdentifyLayerCompleted_(Esri::ArcGISRuntime::IdentifyLayerResult* identifyResult); void onSwitchVersionCompleted_(); void onApplyEditsCompleted_(const QList<Esri::ArcGISRuntime::FeatureTableEditResult*>& featureTableEditResults); void onTaskFailed_(const Esri::ArcGISRuntime::ErrorException& taskException);
Esri::ArcGISRuntime::MapQuickView* mapView() const; void setMapView(Esri::ArcGISRuntime::MapQuickView* mapView); void connectSgdbSignals(); bool sgdbVerionIsDefault() const;
void handleArcGISAuthenticationChallenge(Esri::ArcGISRuntime::Authentication::ArcGISAuthenticationChallenge* challenge) override;
Esri::ArcGISRuntime::ArcGISFeature* m_selectedFeature = nullptr; Esri::ArcGISRuntime::FeatureLayer* m_featureLayer = nullptr; Esri::ArcGISRuntime::Map* m_map = nullptr; Esri::ArcGISRuntime::MapQuickView* m_mapView = nullptr; Esri::ArcGISRuntime::ServiceFeatureTable* m_featureTable = nullptr; Esri::ArcGISRuntime::ServiceGeodatabase* m_serviceGeodatabase = nullptr;
bool m_busy = false; bool m_sgdbVersionIsDefault = true; QString m_createdVersionName; QString m_currentTypeDamage; QString m_errorMessage; QString m_sgdbCurrentVersionName; QString m_sgdbVersionAccess; QString m_sgdbVersionDescription;};
#endif // EDITWITHBRANCHVERSIONING_H// [WriteFile Name=EditWithBranchVersioning, Category=EditData]// [Legal]// Copyright 2020 Esri.//// Licensed under the Apache License, Version 2.0 (the "License");// you may not use this file except in compliance with the License.// You may obtain a copy of the License at// http://www.apache.org/licenses/LICENSE-2.0//// Unless required by applicable law or agreed to in writing, software// distributed under the License is distributed on an "AS IS" BASIS,// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.// See the License for the specific language governing permissions and// limitations under the License.// [Legal]
import QtQuickimport QtQuick.Controlsimport QtQuick.Layoutsimport Esri.Samplesimport Esri.ArcGISRuntime.Toolkit
Item {
readonly property var featAttributes: ["Affected", "Destroyed", "Inaccessible", "Minor", "Major"] readonly property var versionAccessModel: ["Public", "Protected", "Private"]
// add a mapView component MapView { id: view anchors.fill: parent
Component.onCompleted: { // Set the focus on MapView to initially enable keyboard navigation forceActiveFocus(); }
Callout { id: callout background: Rectangle { border.color: "lightgrey" border.width: 1 } calloutData: model.mapView.calloutData leaderPosition: Callout.LeaderPosition.Automatic onAccessoryButtonClicked: { for (let i=0; i < featAttributes.length; i++) { if (model.currentTypeDamage === featAttributes[i]) { typeDmgCombo.currentIndex = i; break; } } updateWindow.visible = true; } }
Button { id: createVersionBtn text: qsTr("Create Version") anchors { left: parent.left top: parent.top margins: 3 } enabled: !busyIndicator.visible
onClicked: { if (text === qsTr("Create Version")) { createVersionWindow.visible = true; callout.dismiss(); updateWindow.visible = false; } else if (text === qsTr("Switch to default version")) { text = qsTr("Switch to created version") model.applyEdits(); callout.dismiss(); updateWindow.visible = false; } else if (text === qsTr("Switch to created version")) { text = qsTr("Switch to default version") model.switchVersion(); callout.dismiss(); updateWindow.visible = false; } } }
Rectangle { id: currentVersionRect anchors{ top: parent.top horizontalCenter: parent.horizontalCenter margins: 3 } width: childrenRect.width; height: childrenRect.height; color: "#000000" visible: currentVersionText.text !== "" ? true : false
ColumnLayout { spacing: 3 Text { text: qsTr("Current version:") Layout.alignment: Qt.AlignHCenter color: "white" }
Text { id: currentVersionText Layout.alignment: Qt.AlignHCenter text: model.sgdbCurrentVersion color: "white" } } } }
Rectangle { id: createVersionWindow anchors.centerIn: parent width: childrenRect.width height: childrenRect.height radius: 10 visible: false
MouseArea { anchors.fill: parent onClicked: mouse => mouse.accepted = true; onWheel: wheel => wheel.accepted = true; }
ColumnLayout { anchors.margins: 5
TextField { id: versionNameTextField placeholderText: qsTr("Name must be unique") Layout.alignment: Qt.AlignHCenter Layout.margins: 5 validator: RegularExpressionValidator { regularExpression: /\w{0,50}/ } }
ComboBox { id: accessComboBox model: versionAccessModel Layout.fillWidth: true Layout.alignment: Qt.AlignHCenter Layout.margins: 5 }
TextField { id: descriptionTextField placeholderText: qsTr("Enter description") Layout.alignment: Qt.AlignHCenter Layout.margins: 5 }
Row { Layout.alignment: Qt.AlignRight Layout.margins: 5 height: childrenRect.height spacing: 5
Button { Layout.margins: 5 Layout.alignment: Qt.AlignRight text: qsTr("Create") onClicked: { model.createVersion(versionNameTextField.text, accessComboBox.currentValue, descriptionTextField.text); resetCreateVersionWindow(); } }
Button { Layout.alignment: Qt.AlignRight Layout.margins: 5 text: qsTr("Cancel") onClicked: { resetCreateVersionWindow(); } } } } }
// Update Window Rectangle { id: updateWindow anchors.centerIn: parent width: childrenRect.width height: childrenRect.height radius: 10 visible: false
MouseArea { anchors.fill: parent onClicked: mouse => mouse.accepted = true; onWheel: wheel => wheel.accepted = true; }
GridLayout { columns: 2 anchors.margins: 5
Text { Layout.columnSpan: 2 Layout.margins: 5 Layout.alignment: Qt.AlignHCenter text: qsTr("Update Attributes") font.pixelSize: 16 }
Text { text: "TYPDAMAGE:" Layout.margins: 5 }
ComboBox { id: typeDmgCombo property int modelWidth: 0 Layout.minimumWidth: modelWidth + leftPadding + rightPadding + 20 Layout.margins: 5 Layout.fillWidth: true enabled: !model.sgdbVersionIsDefault model: featAttributes }
Row { Layout.alignment: Qt.AlignRight Layout.columnSpan: 2 height: childrenRect.height spacing: 5
Button { Layout.margins: 5 Layout.alignment: Qt.AlignRight text: qsTr("Update") enabled: !model.sgdbVersionIsDefault // once the update button is clicked, hide the windows, and fetch the currently selected features onClicked: { print("Update Attribute " + typeDmgCombo.currentValue); model.updateAttribute(typeDmgCombo.currentValue); updateWindow.visible = false; callout.dismiss(); } }
Button { Layout.alignment: Qt.AlignRight Layout.margins: 5 text: qsTr("Cancel") // once the cancel button is clicked, hide the window onClicked: { model.clearSelectedFeature(); updateWindow.visible = false; callout.dismiss(); } } } } }
function resetCreateVersionWindow() { createVersionWindow.visible = false; versionNameTextField.text = ""; descriptionTextField.text = ""; accessComboBox.currentIndex = 0; }
// Declare the C++ instance which creates the map etc. and supply the view EditWithBranchVersioningSample { id: model mapView: view
onFeatureSelected: { callout.showCallout(); }
onHideWindow: { // hide the callout if (callout.visible) callout.dismiss(); // hide the update window updateWindow.visible = false; }
onCreateVersionSuccess: { createVersionBtn.text = qsTr("Switch to default version"); }
onErrorMessageChanged: { errorDialog.visible = true; }
onApplyingEdits: { applyEditsDialog.visible = true; }
onApplyingEditsCompleted: { applyEditsDialog.visible = false; } }
Dialog { id: errorDialog anchors.centerIn: parent standardButtons: Dialog.Ok
Text { id: errorText text: model.errorMessage; } }
Dialog { id: applyEditsDialog x: Math.round(parent.width - width) / 2 y: Math.round(parent.height - height) - view.attributionRect.height;
Text { id: applyEditsText text: qsTr("Applying Edits") } }
BusyIndicator { id: busyIndicator anchors.centerIn: parent visible: model.busy }}// [Legal]// Copyright 2020 Esri.//// Licensed under the Apache License, Version 2.0 (the "License");// you may not use this file except in compliance with the License.// You may obtain a copy of the License at// http://www.apache.org/licenses/LICENSE-2.0//// Unless required by applicable law or agreed to in writing, software// distributed under the License is distributed on an "AS IS" BASIS,// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.// See the License for the specific language governing permissions and// limitations under the License.// [Legal]
// sample headers#include "EditWithBranchVersioning.h"
// ArcGIS Maps SDK headers#include "ArcGISRuntimeEnvironment.h"
// Qt headers#include <QDir>#include <QGuiApplication>#include <QQmlApplicationEngine>
// Platform specific headers#ifdef Q_OS_WIN#include <Windows.h>#endif
#ifdef QT_WEBVIEW_WEBENGINE_BACKEND#include <QtWebEngineQuick>#endif // QT_WEBVIEW_WEBENGINE_BACKEND
#include "Esri/ArcGISRuntime/Toolkit/register.h"
int main(int argc, char *argv[]){ Esri::ArcGISRuntime::ArcGISRuntimeEnvironment::setUseLegacyAuthentication(false); QGuiApplication app(argc, argv); app.setApplicationName(QString("EditWithBranchVersioning"));
#ifdef QT_WEBVIEW_WEBENGINE_BACKEND QtWebEngineQuick::initialize();#endif // QT_WEBVIEW_WEBENGINE_BACKEND
// Use of ArcGIS location services, such as basemap styles, geocoding, and routing services, // requires an access token. For more information see // https://links.esri.com/arcgis-runtime-security-auth.
// The following methods grant an access token:
// 1. User authentication: Grants a temporary access token associated with a user's ArcGIS account. // To generate a token, a user logs in to the app with an ArcGIS account that is part of an // organization in ArcGIS Online or ArcGIS Enterprise.
// 2. API key authentication: Get a long-lived access token that gives your application access to // ArcGIS location services. Go to the tutorial at https://links.esri.com/create-an-api-key. // Copy the API Key access token.
const QString accessToken = QString("");
if (accessToken.isEmpty()) { qWarning() << "Use of ArcGIS location services, such as the basemap styles service, requires" << "you to authenticate with an ArcGIS account or set the API Key property."; } else { Esri::ArcGISRuntime::ArcGISRuntimeEnvironment::setApiKey(accessToken); }
// Initialize the sample EditWithBranchVersioning::init();
// Initialize application view QQmlApplicationEngine engine; // Add the import Path engine.addImportPath(QDir(QCoreApplication::applicationDirPath()).filePath("qml"));
#ifdef ARCGIS_RUNTIME_IMPORT_PATH_2 engine.addImportPath(ARCGIS_RUNTIME_IMPORT_PATH_2);#endif
Esri::ArcGISRuntime::Toolkit::registerComponents(engine);
// Set the source engine.load(QUrl("qrc:/Samples/EditData/EditWithBranchVersioning/main.qml"));
return app.exec();}// Copyright 2020 Esri.
// Licensed under the Apache License, Version 2.0 (the "License");// you may not use this file except in compliance with the License.// You may obtain a copy of the License at// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software// distributed under the License is distributed on an "AS IS" BASIS,// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.// See the License for the specific language governing permissions and// limitations under the License.
import QtQuick.Controlsimport Esri.Samples
ApplicationWindow { visible: true width: 800 height: 600
EditWithBranchVersioning { anchors.fill: parent }}