Modifying this model (adding, removing, moving) will update the bookmarks available in the Map.
The model returns data for the following roles:
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 } }
Relevant samples:
[override virtual noexcept]
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.
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) constReturns 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.
[signal]
void BookmarkListModel::errorOccurred(const Esri::ArcGISRuntime::Error &error)
Signal emitted when an error occurs.
Returns the first bookmark in the list model.
int BookmarkListModel::indexOf(Esri::ArcGISRuntime::Bookmark *bookmark) constReturns 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() constReturns 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() constReturns 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.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4