Skip To Content ArcGIS for Developers Sign In Dashboard

PortalItem Class

(Esri::ArcGISRuntime::PortalItem)

An item in a portal. More...

Header: #include <PortalItem>
Since: Esri::ArcGISRuntime 100.0
Inherits: Item, Loadable, and JsonSerializable

Public Functions

PortalItem(Portal *portal, QObject *parent = nullptr)
PortalItem(const QString &itemId, QObject *parent = nullptr)
PortalItem(Portal *portal, const QString &itemId, QObject *parent = nullptr)
PortalItem(Portal *portal, PortalItemType portalItemType, QObject *parent = nullptr)
PortalItem(const QUrl &url, QObject *parent = nullptr)
~PortalItem()
PortalAccess access() const
void addComment(const QString &comment)
void addRating(float rating)
PortalGroupListModel *adminGroups() const
float averageRating() const
int commentCount() const
PortalItemCommentListModel *comments() const
QString culture() const
void fetchComments()
void fetchGroups()
QString folderId() const
bool isCommentsEnabled() const
PortalGroupListModel *memberGroups() const
PortalGroupListModel *otherGroups() const
QString owner() const
Portal *portal() const
int ratingCount() const
QUrl serviceUrl() const
void shareWith(bool everyone, bool organization)
void shareWithGroups(const QStringList &groupIds)
qint64 size() const
PortalItemType type() const
QString typeName() const
void unshare()
void unshareGroups(const QStringList &groupIds)
void updateDataWithJson(const QString &json)
void updateDataWithUrl(const QUrl &fromUrl, const QString &fileName = QString())
QUrl url() const
int viewCount() const

Reimplemented Public Functions

virtual void cancelLoad()
virtual void load()
virtual Error loadError() const
virtual LoadStatus loadStatus() const
virtual void retryLoad()
virtual QString toJson() const
virtual QJsonObject unknownJson() const
virtual QJsonObject unsupportedJson() const

Signals

void addCommentCompleted(bool success)
void addRatingCompleted(bool success)
void doneLoading(Esri::ArcGISRuntime::Error loadError)
void fetchCommentsCompleted(bool success)
void fetchDataProgressChanged(const Esri::ArcGISRuntime::NetworkRequestProgress &progress)
void fetchGroupsCompleted(bool success)
void loadStatusChanged(Esri::ArcGISRuntime::LoadStatus loadStatus)
void shareWithCompleted(bool success)
void shareWithGroupsCompleted(bool success, const QStringList &failedToShareGroupIds)
void unshareCompleted(bool success)
void unshareGroupsCompleted(bool success, const QStringList &failedToUnshareGroupIds)
void updateDataCompleted(bool success, const QString &itemId)

Static Public Members

PortalItem *fromJson(const QString &json, Portal *portal = nullptr, QObject *parent = nullptr)
  • 10 static public members inherited from QObject

Additional Inherited Members

  • 1 property inherited from QObject
  • 1 public slot inherited from QObject
  • 1 public variable inherited from QObject
  • 9 protected functions inherited from QObject
  • 2 protected variables inherited from QObject

Detailed Description

An item in a portal.

Contains information about an item of content within the portal. Each item has a unique identifier and a well-known URL that is independent of the user owning the item.

A new item can be created using PortalUser::addPortalItemWithJson or PortalUser::addPortalItemWithUrl; or an existing item can be loaded from an online portal using PortalItem::load.

An item may also have associated binary or textual data which can be downloaded separately.

Create a new portal item

To add a new item to a portal, create the PortalItem object passing the portal as a parameter to the constructor, then call PortalUser::addPortalItemWithJson or PortalUser::addPortalItemWithUrl. The portal user must have been created with credentials that provide sufficient privileges to add items to the portal. Before adding an item to the portal, the title and type must be set. If itemId is set, this will be ignored and a new unique ID will be provided when the item is added to the portal and loaded.

PortalItem* portalItem = new PortalItem(portal, parent);
portalItem->setTitle("My Item");
portalItem->setType(PortalItemType::WebMap);
portalItem->setTags(myTags);
portal->portalUser()->addPortalItemWithJson(portalItem, json);

Load existing portal item

To load an existing item from portal, create PortalItem object with valid itemId or url, and call PortalItem::load.

The portal item ID can be used along with a portal URL to quickly instantiate a new portal item object. The ID can be determined from the URL of the item details web page or the map viewer URL (for maps only) in your portal. The item details page has the following format: http://www.arcgis.com/home/item.html?id=[item_id]. The web map viewer has the following format: http://www.arcgis.com/home/webmap/viewer.html?webmap=[item_id]. In both cases the [item_id] can be used as the ID to instantiate a portal item.

PortalItem* portalItem = new PortalItem(portal, itemId, parent);
connect(portalItem, &PortalItem::doneLoading, this, [portalItem](){
  qDebug() << "Item title:" << portalItem->title();
});
portalItem->load();

Retrieve an existing portal item

Alternatively, you can search for and load existing items in the portal using Portal::findItems or PortalUser::items. If you know the specific ID of the item you wish to retrieve, you can construct the portalItem by passing both the portal and the ID to it's constructor and calling PortalItem::load to retrieve the details.

See also Portal.

Member Function Documentation

PortalItem::PortalItem(Portal *portal, QObject *parent = nullptr)

Constructor that accepts a portal and an optional parent.

PortalItem::PortalItem(const QString &itemId, QObject *parent = nullptr)

Constructor that accepts an item ID (itemId) and an optional parent.

Use this constructor you wish to fetch a particular item from a portal. Call load on the resultant object to fetch the metadata for this item. Note that most of the getter methods will return nullptr, 0 or an empty QString until the load operation is complete.

A portal item's ID can be obtained using the itemId method. The ID can also be determined from the URL of the item details web page or the map viewer URL (for maps only) in your portal. The item details page has the following format: http://www.arcgis.com/home/item.html?id=[item_id]. The web map viewer has the following format: http://www.arcgis.com/home/webmap/viewer.html?webmap=[item_id]. In both cases the [item_id] can be used as the ID to instantiate a portal item.

This constructor use a default portal to "https://www.arcgis.com".

PortalItem::PortalItem(Portal *portal, const QString &itemId, QObject *parent = nullptr)

Constructor that accepts a portal, an item ID (itemId) and an optional parent.

PortalItem::PortalItem(Portal *portal, PortalItemType portalItemType, QObject *parent = nullptr)

Constructor that accepts a portal, a portal item type (portalItemType) and an optional parent.

This function was introduced in Esri::ArcGISRuntime 100.6.

PortalItem::PortalItem(const QUrl &url, QObject *parent = nullptr)

Constructor that accepts a URL (url) for a portal and an optional parent.

The supported URL formats are:

  • The URL of the portal item (with or without the query parameter f=json). Example: http://www.arcgis.com/sharing/rest/content/items/12345678901234567890123456789012?f=json
  • The URL of the portal item data. Example: http://www.arcgis.com/sharing/rest/content/items/12345678901234567890123456789012/data
  • The URL of an ArcGIS.com item. Example: http://www.arcgis.com/home/item.html?id=12345678901234567890123456789012
  • The URL of an ArcGIS.com web map viewer. Example: http://www.arcgis.com/home/webmap/viewer.html?webmap=12345678901234567890123456789012

PortalItem::~PortalItem()

Destructor.

PortalAccess PortalItem::access() const

Returns the level of access to this item.

void PortalItem::addComment(const QString &comment)

Adds a comment to the PortalItem.

The addCommentCompleted signal will emit after the operation is complete.

[signal] void PortalItem::addCommentCompleted(bool success)

Signal emitted when the asynchronous addComment operation is complete.

  • success - Whether adding comment completed successfully.

This function was introduced in Esri::ArcGISRuntime 100.1.

void PortalItem::addRating(float rating)

Adds a rating to the PortalItem.

The addRatingCompleted signal will emit after the operation is complete.

rating must be a floating point number between 1.0 and 5.0.

[signal] void PortalItem::addRatingCompleted(bool success)

Signal emitted when the asynchronous addRating operation is complete.

  • success - Whether adding rating completed successfully.

This function was introduced in Esri::ArcGISRuntime 100.1.

PortalGroupListModel *PortalItem::adminGroups() const

Returns a list of groups that the item is in and for which the current portal user is an administrator.

To access these groups, call fetchGroups, and wait for the fetchGroupsCompleted signal to emit or an errorOccurred if unsuccessful.

float PortalItem::averageRating() const

Returns the average rating.

Uses a weighted average called "Bayesian average."

[virtual] void PortalItem::cancelLoad()

Reimplemented from Loadable::cancelLoad().

See Loadable.

int PortalItem::commentCount() const

Returns the number of comments for this item.

PortalItemCommentListModel *PortalItem::comments() const

Returns a list of comments about this item.

QString PortalItem::culture() const

Returns the item locale information (language and country).

[signal] void PortalItem::doneLoading(Esri::ArcGISRuntime::Error loadError)

Signal emitted when this object is done loading.

  • loadError - Details about any error that may have occurred.

Note: If there is a load error it will also be emitted on the errorOccurred signal.

See also Loadable and Object.

void PortalItem::fetchComments()

Starts an asynchronous task to fetch comments.

The fetchCommentsCompleted signal will emit after the operation is complete.

Example: Fetch the comments model for an item:

int totalCommentsCount = 0;
connect(portalItem, &PortalItem::fetchCommentsCompleted, [portalItem, &totalCommentsCount](bool success)
{
  if (!success)
    return;

  PortalItemCommentListModel* commentsModel = portalItem->comments();
  if (!commentsModel)
    return;

  totalCommentsCount = commentsModel->size();
});

portalItem->fetchComments();

[signal] void PortalItem::fetchCommentsCompleted(bool success)

Signal emitted when the asynchronous fetchComments operation is complete.

  • success - Whether fetching comments completed successfully.

This function was introduced in Esri::ArcGISRuntime 100.1.

[signal] void PortalItem::fetchDataProgressChanged(const Esri::ArcGISRuntime::NetworkRequestProgress &progress)

Signal emitted periodically to report fetch data progress.

Information about the fetch data progress is returned in progress.

void PortalItem::fetchGroups()

Starts an asynchronous task to fetch groups.

The fetchGroupsCompleted signal will emit after the operation is complete.

[signal] void PortalItem::fetchGroupsCompleted(bool success)

Signal emitted when the asynchronous fetchGroups operation is complete.

  • success - Whether fetching groups completed successfully.

This function was introduced in Esri::ArcGISRuntime 100.1.

QString PortalItem::folderId() const

Returns the ID of the folder containing this item.

[static] PortalItem *PortalItem::fromJson(const QString &json, Portal *portal = nullptr, QObject *parent = nullptr)

Creates a new PortalItem from json with an optional portal and parent.

If the portal is not specified, then the default Portal will be used (ArcGIS Online).

See also JsonSerializable.

bool PortalItem::isCommentsEnabled() const

Returns whether comments are allowed on the item.

[virtual] void PortalItem::load()

Reimplemented from Loadable::load().

See Loadable.

[virtual] Error PortalItem::loadError() const

Reimplemented from Loadable::loadError().

See Loadable.

[virtual] LoadStatus PortalItem::loadStatus() const

Reimplemented from Loadable::loadStatus().

See Loadable.

[signal] void PortalItem::loadStatusChanged(Esri::ArcGISRuntime::LoadStatus loadStatus)

Signal emitted when the loadStatus changes for this object.

See also Loadable.

PortalGroupListModel *PortalItem::memberGroups() const

Returns a list of groups that the item is in and for which the current portal user is a member (read-only).

To access these comments, call fetchGroups, and wait for the fetchGroupsCompleted signal to emit or an errorOccurred if unsuccessful.

PortalGroupListModel *PortalItem::otherGroups() const

Returns a list of groups that the item is in that are public or shared to the user's organization, but that the current portal user is not a member of (read-only).

To access these comments, call fetchGroups, and wait for the fetchGroupsCompleted signal to emit or an errorOccurred if unsuccessful.

QString PortalItem::owner() const

Returns the username of the user who owns this item.

Portal *PortalItem::portal() const

Returns the portal associated with this item.

int PortalItem::ratingCount() const

Returns the number of ratings received by this item.

[virtual] void PortalItem::retryLoad()

Reimplemented from Loadable::retryLoad().

See Loadable.

QUrl PortalItem::serviceUrl() const

Returns the service URL for this item.

void PortalItem::shareWith(bool everyone, bool organization)

Shares a PortalItem with everyone and/or the organization the item belongs to.

[signal] void PortalItem::shareWithCompleted(bool success)

Signal emitted when the asynchronous shareWith method completes.

The parameter success is true when the operation succeeded, otherwise false.

void PortalItem::shareWithGroups(const QStringList &groupIds)

Shares a PortalItem with the specified list of groupIds.

[signal] void PortalItem::shareWithGroupsCompleted(bool success, const QStringList &failedToShareGroupIds)

Signal emitted when the asynchronous shareWithGroups method completes.

The parameter success is true when the operation succeeded, otherwise false. The parameter failedToShareGroupIds is the list of groups the item could not be shared with.

This function was introduced in Esri::ArcGISRuntime 100.1.

qint64 PortalItem::size() const

Returns the size of the item in bytes.

[virtual] QString PortalItem::toJson() const

Reimplemented from JsonSerializable::toJson().

Returns the JSON representation of this object.

See also JsonSerializable.

PortalItemType PortalItem::type() const

Returns the item's type.

See also setType().

QString PortalItem::typeName() const

Returns the name of the type of this item.

[virtual] QJsonObject PortalItem::unknownJson() const

Reimplemented from JsonSerializable::unknownJson().

Returns the unknown JSON of this object.

See also JsonSerializable.

void PortalItem::unshare()

Unshares the PortalItem with everyone.

[signal] void PortalItem::unshareCompleted(bool success)

Signal emitted when the asynchronous unshare method completes.

The parameter success is true when the operation succeeded, otherwise false.

void PortalItem::unshareGroups(const QStringList &groupIds)

Unshares a PortalItem with the specified list of groupIds.

[signal] void PortalItem::unshareGroupsCompleted(bool success, const QStringList &failedToUnshareGroupIds)

Signal emitted when the asynchronous unshareGroups method completes.

The parameter success is true when the operation succeeded, otherwise false. The parameter failedToUnshareGroupIds is the list of groups the item could not be unshared with.

This function was introduced in Esri::ArcGISRuntime 100.1.

[virtual] QJsonObject PortalItem::unsupportedJson() const

Reimplemented from JsonSerializable::unsupportedJson().

Returns the unsupported JSON of this object.

See also JsonSerializable.

[signal] void PortalItem::updateDataCompleted(bool success, const QString &itemId)

Signal emitted when the asynchronous updateDataWithJson or updateDataWithUrl method completes.

success Whether the update was successful. itemId The item ID of the PortalItem that was updated.

This function was introduced in Esri::ArcGISRuntime 100.1.

void PortalItem::updateDataWithJson(const QString &json)

Starts an asynchronous task to update the remote PortalItem with the provided json.

The portalItem will be updated using the following arguments:

  • json. A string representation of the JSON to use when updating the item.

The updateDataCompleted signal will emit after the operation is complete.

This function was introduced in Esri::ArcGISRuntime 100.1.

void PortalItem::updateDataWithUrl(const QUrl &fromUrl, const QString &fileName = QString())

Starts an asynchronous task to update the remote PortalItem from a local or online url.

The portalItem will be updated using the following arguments:

  • fromUrl. The local or online URL from which the portalItem will be populated. For local files, this should be of the form "qrc:/example.csv" or "file://"; for online resources this should be of the form "https://...".
  • fileName (optional). The name of the file which will be associated with the PortalItem (including extension). If a file name is not supplied, the portal item will have no file associated with it for future downloads.

    Note: A file name is only relevant for certain item types such as PortalItemType.Image.

The updateDataCompleted signal will emit after the operation is complete.

This function was introduced in Esri::ArcGISRuntime 100.1.

See also Items and item types.

QUrl PortalItem::url() const

Returns the URL for the resource represented by the item.

int PortalItem::viewCount() const

Returns the number of times this item has been viewed.


Feedback on this topic?