BookmarkListModel Class

  • BookmarkListModel
  • class Esri::ArcGISRuntime::BookmarkListModel

    A list model storing a list of bookmarks available in a Map. More...

    Header: #include <BookmarkListModel.h>
    Since: Esri::ArcGISRuntime 100.0
    Inherits: QAbstractListModel and Esri::ArcGISRuntime::Iterable

    Public Types

    enum BookmarkRoles { BookmarkNameRole }

    Public Functions

    virtual ~BookmarkListModel() override
    void append(Esri::ArcGISRuntime::Bookmark *bookmark)
    void clear()
    bool contains(Esri::ArcGISRuntime::Bookmark *bookmark) const
    Esri::ArcGISRuntime::Bookmark *first() const
    int indexOf(Esri::ArcGISRuntime::Bookmark *bookmark) const
    void insert(int index, Esri::ArcGISRuntime::Bookmark *bookmark)
    bool isEmpty() const
    Esri::ArcGISRuntime::Bookmark *last() const
    void move(int from, int to)
    void removeAt(int index)
    void removeOne(Esri::ArcGISRuntime::Bookmark *bookmark)

    Reimplemented Public Functions

    virtual Esri::ArcGISRuntime::Bookmark *at(int index) const override
    virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override
    virtual int size() const override

    Signals

    void errorOccurred(const Esri::ArcGISRuntime::Error &error)
    void itemAdded(int index)
    void itemRemoved(int index)

    Detailed Description

    Modifying this model (adding, removing, moving) will update the bookmarks available in the Map.

    The model returns data for the following roles:

    RoleTypeDescriptionBookmarkRoles
    nameQStringThe name of the bookmark.BookmarkNameRole

    Example:

    A common workflow would be to show the bookmark names in a QML UI, and zoom to the different bookmarks as each is selected. To do this, you could do following:

    Register the BookmarkListModel type as a QML type:

    qmlRegisterUncreatableType<BookmarkListModel>("Esri.Samples", 1, 0,
                                                  "BookmarkListModel",
                                                  "BookmarkListModel is an uncreatable type");

    Expose the BookmarkListModel as a Q_PROPERTY:

    Q_PROPERTY(QAbstractListModel* bookmarks READ bookmarks NOTIFY bookmarksChanged)

    Add some Bookmarks to the list model:

    // Get the bookmark list
    BookmarkListModel* bookmarks = dynamic_cast<BookmarkListModel*>(m_bookmarks);
    if (!bookmarks)
      return;
    
    // Create the bookmark from the name and viewpoint
    Bookmark* bookmark = new Bookmark(name, viewpoint, this);
    
    // Add it to the map's bookmark list
    bookmarks->append(bookmark);
    
    // emit that model has changed
    emit bookmarksChanged();

    Use the model in a QML view:

    ComboBox {
        id: bookmarkComboBox
        anchors {
            left: parent.left
            top: parent.top
            margins: 15
        }
        property int bestWidth: implicitWidth
        width: bestWidth + leftPadding + rightPadding + (indicator ? indicator.width : 10)
        // Set the model to the BookmarkListModel
        model: manageBookmarksSample.bookmarks
    
        onModelChanged: {
            const model = bookmarkComboBox.model;
            if (model)
            {
                let w = bestWidth;
                for (let i = 0; i < model.rowCount(); ++i) {
                    metrics.text = manageBookmarksSample.bookmarkNameForIndex(i);
                    w = Math.max(w, metrics.width);
                }
                bestWidth = w;
            }
        }
    
        onCurrentTextChanged: {
            // Call C++ invokable function to to go to the bookmark
            manageBookmarksSample.goToBookmark(bookmarkComboBox.currentIndex);
        }
    
        // Add a background to the ComboBox
        Rectangle {
            anchors.fill: parent
            radius: 10
            // Make the rectangle visible if a dropdown indicator exists
            // An indicator only exists if a theme is set
            visible: parent.indicator
            border.width: 1
        }
    
        TextMetrics {
            id: metrics
            font: bookmarkComboBox.font
        }
    }

    Member Type Documentation

    enum BookmarkListModel::BookmarkRoles

    This enum specifies the custom roles which can be used with BookmarkListModel::data.

    ConstantValueDescription
    Esri::ArcGISRuntime::BookmarkListModel::BookmarkNameRoleQt::UserRole + 1The name of the bookmark.

    Member Function Documentation

    [override virtual] BookmarkListModel::~BookmarkListModel()

    Destructor.

    void BookmarkListModel::append(Esri::ArcGISRuntime::Bookmark *bookmark)

    Appends a bookmark to the bookmark list model.

    [override virtual] Esri::ArcGISRuntime::Bookmark *BookmarkListModel::at(int index) const

    Returns the bookmark at the specified index.

    void BookmarkListModel::clear()

    Removes all bookmarks from the list model.

    List models do not take ownership of the objects they contain. Therefore, removing or clearing objects from the list model will not delete those objects. An RAII technique should be used to ensure that memory is properly deallocated.

    bool BookmarkListModel::contains(Esri::ArcGISRuntime::Bookmark *bookmark) const

    Returns true if the list model contains the specified bookmark.

    [override virtual] QVariant BookmarkListModel::data(const QModelIndex &index, int role = Qt::DisplayRole) const

    Reimplements: QAbstractItemModel::data(const QModelIndex &index, int role) const.

    Returns the data stored under the given role for the bookmark referred to by the index.

    • index. The index in the model for which to return data.
    • role. The role for which to return data.

    [signal] void BookmarkListModel::errorOccurred(const Esri::ArcGISRuntime::Error &error)

    Signal emitted when an error occurs.

    • error - Details about the error.

    Esri::ArcGISRuntime::Bookmark *BookmarkListModel::first() const

    Returns the first bookmark in the list model.

    int BookmarkListModel::indexOf(Esri::ArcGISRuntime::Bookmark *bookmark) const

    Returns the index of the bookmark specified.

    void BookmarkListModel::insert(int index, Esri::ArcGISRuntime::Bookmark *bookmark)

    Inserts a bookmark at a specified index in the list model.

    This method will append to the list model if the index is greater than the current size of the list.

    bool BookmarkListModel::isEmpty() const

    Returns true if the list model contains no bookmarks.

    [signal, since Esri::ArcGISRuntime 100.15] void BookmarkListModel::itemAdded(int index)

    Signal emitted when an item is added from the list model.

    index is the index of the removed bookmark.

    This function was introduced in Esri::ArcGISRuntime 100.15.

    [signal, since Esri::ArcGISRuntime 100.15] void BookmarkListModel::itemRemoved(int index)

    Signal emitted when an item is removed from the list model.

    index is the index of the removed item.

    This function was introduced in Esri::ArcGISRuntime 100.15.

    Esri::ArcGISRuntime::Bookmark *BookmarkListModel::last() const

    Returns the last bookmark in the list model.

    void BookmarkListModel::move(int from, int to)

    Moves one bookmark from an index in the list model to a different index.

    void BookmarkListModel::removeAt(int index)

    Removes a bookmark at the specified index.

    List models do not take ownership of the objects they contain. Therefore, removing or clearing objects from the list model will not delete those objects. An RAII technique should be used to ensure that memory is properly deallocated.

    void BookmarkListModel::removeOne(Esri::ArcGISRuntime::Bookmark *bookmark)

    Removes the specified bookmark from the list model.

    List models do not take ownership of the objects they contain. Therefore, removing or clearing objects from the list model will not delete those objects. An RAII technique should be used to ensure that memory is properly deallocated.

    [override virtual] int BookmarkListModel::size() const

    Returns the number of bookmarks contained in the list model.

    Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.