QPlaceManager Class
QPlaceManager 类提供了允许客户端访问存储在特定后端的位置的接口。更多
Header: | #include <QPlaceManager> |
qmake: | QT += location |
Inherits: | QObject |
公共函数
virtual | ~QPlaceManager() |
QPlaceCategory | category(const QString &categoryId) const |
QList<QPlaceCategory> | childCategories(const QString &parentId = QString()) const |
QStringList | childCategoryIds(const QString &parentId = QString()) const |
QPlace | compatiblePlace(const QPlace &original) const |
QPlaceContentReply * | getPlaceContent(const QPlaceContentRequest &request) const |
QPlaceDetailsReply * | getPlaceDetails(const QString &placeId) const |
QPlaceReply * | initializeCategories() |
QList<QLocale> | locales() const |
QString | managerName() const |
int | managerVersion() const |
QPlaceMatchReply * | matchingPlaces(const QPlaceMatchRequest &request) const |
QString | parentCategoryId(const QString &categoryId) const |
QPlaceIdReply * | removeCategory(const QString &categoryId) |
QPlaceIdReply * | removePlace(const QString &placeId) |
QPlaceIdReply * | saveCategory(const QPlaceCategory &category, const QString &parentId = QString()) |
QPlaceIdReply * | savePlace(const QPlace &place) |
QPlaceSearchReply * | search(const QPlaceSearchRequest &request) const |
QPlaceSearchSuggestionReply * | searchSuggestions(const QPlaceSearchRequest &request) const |
void | setLocale(const QLocale &locale) |
void | setLocales(const QList<QLocale> &locales) |
信号
void | categoryAdded(const QPlaceCategory &category, const QString &parentId) |
void | categoryRemoved(const QString &categoryId, const QString &parentId) |
void | categoryUpdated(const QPlaceCategory &category, const QString &parentId) |
void | dataChanged() |
void | errorOccurred(QPlaceReply *reply, QPlaceReply::Error error, const QString &errorString = QString()) |
void | finished(QPlaceReply *reply) |
void | placeAdded(const QString &placeId) |
void | placeRemoved(const QString &placeId) |
void | placeUpdated(const QString &placeId) |
详细说明
下表概述了 QPlaceManager 提供的功能
功能 | 功能描述 |
---|---|
搜索地点 | 使用一组参数(如搜索词和搜索区域),可向用户返回相关地点。 |
分类 | 地点可分为不同类别。管理器支持访问这些类别。 |
搜索词建议 | 在给出部分完整搜索词的情况下,可提供潜在搜索词列表。 |
推荐 | 给定一个现有地点后,可向用户推荐一组类似的推荐地点。 |
丰富内容 | 可以分页方式检索图片、评论等丰富内容。 |
地点或类别管理 | 可保存和删除地点和类别。发生这种情况时,可以发出通知。 |
本地化 | 可指定不同的本地语言,以返回不同语言的地点数据。 |
获取 QPlaceManager 实例
QGeoServiceProvider 可以帮助创建 QPlaceManager。有关如何创建管理器的示例,请参阅初始化管理器。
异步接口
QPlaceManager 类提供了包含位置信息的数据存储的抽象。QPlaceManager 提供的功能主要是异步的,并遵循请求-回复模式。通常情况下,向管理器发出的请求包含一组不同的参数,然后会创建一个回复对象。请求完成后,回复对象会发出信号通知,一旦完成,回复就会包含请求的结果以及发生的任何错误(如果有的话)。
异步请求一般按以下方式处理:
//1)提出适当的请求QPlaceSearchRequestsearchRequest; searchRequest.setSearchTerm("ice cream"); searchRequest.setSearchArea(QGeoCircle(QGeoCoordinate(12.34, 56.78));//2) 使用管理器发起请求并获取回复对象QPlaceSearchReply* searchReply=manager->search(searchRequest);//3)将回复对象连接到操作完成后调用的槽中connect(searchReply, &Reply)QPlaceSearchReply::finished, this, &RequestHandler::processSearchReply); ... ...//4)让插槽适当处理操作结果voidprocessSearchReply() {if(searchReply->error()==QPlaceReply::NoError) {for(constQPlaceSearchResult&result: searchReply->results()) {if(result.type()==::PlaceResult) QPlaceSearchResult::PlaceResult) qDebug() << "Title:" << result.title(); } }//5)完成后丢弃依赖对象。 searchReply->deleteLater(); searchReply=nullptr; }
请参阅常用操作,了解如何使用 QPlaceManger 的示例列表。
类别初始化
在启动应用程序时,应调用initializeCategories() 函数来设置类别。初始化类别可以使用以下函数:
- QPlaceManager::childCategories()
- QPlaceManager::category()
- QPlaceManager::parentCategoryId()
- QPlaceManager::childCategoryIds();
如果需要刷新或重新加载类别,可再次调用initializeCategories() 函数。
成员函数文档
[virtual noexcept]
QPlaceManager::~QPlaceManager()
销毁管理器。该析构函数由QGeoServiceProvider 内部使用,应用程序代码无需调用。
QPlaceCategory QPlaceManager::category(const QString &categoryId) const
返回与给定categoryId 对应的类别。
[signal]
void QPlaceManager::categoryAdded(const QPlaceCategory &category, const QString &parentId)
如果管理器的数据存储中添加了category ,则会发出该信号。category 的父节点由parentId 指定。
该信号仅由支持 QPlaceManager::NotificationsFeature 的管理器发出。
另请参阅 dataChanged() 。
[signal]
void QPlaceManager::categoryRemoved(const QString &categoryId, const QString &parentId)
当与categoryId 对应的类别已从管理器的数据存储中删除时,就会发出该信号。已移除类别的父类别由parentId 指定。
该信号仅由支持 QPlaceManager::NotificationsFeature 的管理器发出。
另请参阅 dataChanged().
[signal]
void QPlaceManager::categoryUpdated(const QPlaceCategory &category, const QString &parentId)
如果管理器数据存储中的category 被修改,就会发出该信号。修改类别的父类别由parentId 指定。
只有支持 QPlaceManager::NotificationsFeature 的管理器才会发出该信号。
另请参阅 dataChanged().
QList<QPlaceCategory> QPlaceManager::childCategories(const QString &parentId = QString()) const
返回与parentId 对应的类别的子类别列表。如果parentId 为空,则返回所有顶级类别。
QStringList QPlaceManager::childCategoryIds(const QString &parentId = QString()) const
返回与parentId 对应的类别的子类别标识符。如果parentId 为空,则返回所有顶级类别标识符。
QPlace QPlaceManager::compatiblePlace(const QPlace &original) const
返回适合保存到此管理器的original 地名的剪枝或修改版本。
修改后的版本只包含该管理器支持的地点详细信息。管理器的特定数据(如位置 ID)不会从original 复制过来。
[signal]
void QPlaceManager::dataChanged()
如果底层数据存储发生大规模变更,且管理器认为这些变更足以要求客户端重新加载所有数据,则管理器会发出该信号。
如果发出该信号,则不会就相关更改发出其他信号。
只有支持 QPlaceManager::NotificationsFeature 的管理器才会发出该信号。
[signal]
void QPlaceManager::errorOccurred(QPlaceReply *reply, QPlaceReply::Error error, const QString &errorString = QString())
当reply 的处理过程中检测到错误时,就会发出该信号。随后可能会发出QPlaceManager::finished() 信号。
错误代码error 将描述该错误。如果errorString 不为空,则将包含针对开发人员而非最终用户的错误文字说明。
该信号和QPlaceReply::errorOccurred() 将同时发出。
注意: 请勿删除与此信号连接的槽中的reply 对象。请使用deleteLater() 代替。
[signal]
void QPlaceManager::finished(QPlaceReply *reply)
reply 处理完毕时发出该信号。
如果 reply->error() 等于QPlaceReply::NoError ,则处理成功完成。
此信号和QPlaceReply::finished() 将同时发出。
注意: 请勿删除与此信号连接的槽中的reply 对象。请使用deleteLater() 代替。
QPlaceContentReply *QPlaceManager::getPlaceContent(const QPlaceContentRequest &request) const
根据request 中指定的参数读取一个地方的内容。
有关用法示例,请参阅 "获取丰富内容"。
QPlaceDetailsReply *QPlaceManager::getPlaceDetails(const QString &placeId) const
读取与给定placeId 相对应的地点详细信息。
使用示例请参阅 "获取地点详细信息"。
QPlaceReply *QPlaceManager::initializeCategories()
初始化管理器的类别。
有关使用示例,请参阅 "使用类别"。
QList<QLocale> QPlaceManager::locales() const
返回首选本地语言列表。本地语言用于提示管理器应使用哪种语言返回地点和类别的详细信息。
如果第一个指定的本地语言无法使用,管理器就会返回下一个,以此类推。有些管理器后端可能不支持严格定义的本地语言集。一个任意的例子是,法国的某些地区可能有法语和英语本地化,而美国的某些地区可能只有英语本地化。在这个例子中,支持的本地语言集取决于搜索地点的上下文。
如果管理器无法满足任何首选本地化要求,管理器就会退回到使用后端特定的受支持语言。
不同提供商对本地语言的支持可能有所不同。对于支持本地化的提供商,默认情况下,全局默认本地化会被设置为管理器的唯一本地化。
对于不支持本地语言的管理器,本地语言列表始终为空。
另请参阅 setLocales()。
QString QPlaceManager::managerName() const
返回管理器的名称
int QPlaceManager::managerVersion() const
返回管理器版本。
QPlaceMatchReply *QPlaceManager::matchingPlaces(const QPlaceMatchRequest &request) const
返回一个回复,其中包含与request 中指定的地点相对应/匹配的地点列表。请求中指定的地点来自不同的管理器。
QString QPlaceManager::parentCategoryId(const QString &categoryId) const
返回与categoryId 对应的类别的父类别标识符。
[signal]
void QPlaceManager::placeAdded(const QString &placeId)
如果管理器引擎的数据存储中添加了一个位置,就会发出该信号。具体添加的位置由placeId 指定。
该信号仅由支持 QPlaceManager::NotificationsFeature 的管理器发出。
另请参阅 dataChanged() 。
[signal]
void QPlaceManager::placeRemoved(const QString &placeId)
如果某个位置已从管理器的数据存储中移除,就会发出该信号。被移除的特定位置由placeId 指定。
只有支持 QPlaceManager::NotificationsFeature 的管理器才会发出该信号。
另请参见 dataChanged().
[signal]
void QPlaceManager::placeUpdated(const QString &placeId)
如果管理器数据存储中的某个位置被修改,就会发出该信号。具体修改的位置由placeId 指定。
该信号仅由支持 QPlaceManager::NotificationsFeature 的管理器发出。
另请参阅 dataChanged() 。
QPlaceIdReply *QPlaceManager::removeCategory(const QString &categoryId)
从管理器中删除与categoryId 对应的类别。
有关使用示例,请参阅删除类别。
QPlaceIdReply *QPlaceManager::removePlace(const QString &placeId)
从管理器中删除与placeId 对应的位置。
有关使用示例,请参阅删除位置 cpp。
QPlaceIdReply *QPlaceManager::saveCategory(const QPlaceCategory &category, const QString &parentId = QString())
保存一个category ,它是parentId 所指定类别的子类别。parentId 为空表示category 被保存为顶级类别。
有关使用示例,请参阅保存类别。
QPlaceIdReply *QPlaceManager::savePlace(const QPlace &place)
保存指定的place 。
使用示例请参见保存位置 cpp。
QPlaceSearchReply *QPlaceManager::search(const QPlaceSearchRequest &request) const
根据request 中指定的参数搜索地点。
使用示例请参见发现/搜索。
QPlaceSearchSuggestionReply *QPlaceManager::searchSuggestions(const QPlaceSearchRequest &request) const
根据request 中指定的参数请求一组搜索词建议。request 可以包含不完整的搜索词以及其他数据,如搜索区域,以缩小相关结果的范围。
有关用法示例,请参阅 "搜索建议"。
void QPlaceManager::setLocale(const QLocale &locale)
方便函数,用于将管理器的首选地域列表设置为单个locale 。
void QPlaceManager::setLocales(const QList<QLocale> &locales)
设置首选locales 列表。
另请参阅 locales() 。
© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.