本页内容

QGeoPath Class

QGeoPath 类定义了一个地理路径。更多内容...

头文件: #include <QGeoPath>
CMake: find_package(Qt6 REQUIRED COMPONENTS Positioning)
target_link_libraries(mytarget PRIVATE Qt6::Positioning)
qmake: QT += positioning
继承自: QGeoShape

属性

公共函数

QGeoPath()
QGeoPath(const QGeoShape &other)
QGeoPath(const QList<QGeoCoordinate> &path, const qreal &width = 0.0)
QGeoPath(const QGeoPath &other)
~QGeoPath()
void addCoordinate(const QGeoCoordinate &coordinate)
void clearPath()
bool containsCoordinate(const QGeoCoordinate &coordinate) const
QGeoCoordinate coordinateAt(qsizetype index) const
void insertCoordinate(qsizetype index, const QGeoCoordinate &coordinate)
double length(qsizetype indexFrom = 0, qsizetype indexTo = -1) const
const QList<QGeoCoordinate> &path() const
void removeCoordinate(const QGeoCoordinate &coordinate)
void removeCoordinate(qsizetype index)
void replaceCoordinate(qsizetype index, const QGeoCoordinate &coordinate)
void setPath(const QList<QGeoCoordinate> &path)
void setWidth(const qreal &width)
qsizetype size() const
QString toString() const
void translate(double degreesLatitude, double degreesLongitude)
QGeoPath translated(double degreesLatitude, double degreesLongitude) const
qreal width() const
QGeoPath &operator=(const QGeoPath &other)

详细说明

路径由一组有序的QGeoCoordinate 对象列表定义。

路径中每两个相邻元素应通过一条经过这两个元素且方位角恒定的最短线段连接起来。此类连接可以在经度方向上跨越国际日期变更线,但绝不能跨越两极。

这与计算该形状的QGeoShape::boundingGeoRectangle()返回的边界框有关,该边界框的左上角纬度将设置为路径点集中的最大纬度。同样,右下角的纬度将设置为路径点集中的最小纬度。

该类在 QML 中也可通过geoPath 访问。

如果 QGeoPath 不包含任何坐标,则它既无效又为空。

注意: 默认构造的 QGeoPath 既无效又为空,因为它不包含任何坐标。

属性文档

path : QVariantList

该属性存储了地理路径的坐标列表。

注意:坐标 无法就地处理。若要更改此属性的值,请先检索完整的坐标列表,对其进行处理,然后将新值赋给该属性。

width : qreal

该属性表示路径的宽度(单位:米)。

访问函数:

qreal width() const
void setWidth(const qreal &width)

成员函数文档

QGeoPath::QGeoPath()

创建一个新的、空的几何路径。

QGeoPath::QGeoPath(const QGeoShape &other)

根据other 中的内容构建一条新的地理路径。

QGeoPath::QGeoPath(const QList<QGeoCoordinate> &path, const qreal &width = 0.0)

根据一组坐标(path 和width )构建一条新的地理路径。

QGeoPath::QGeoPath(const QGeoPath &other)

根据other 的内容构建一条新的地理路径。

[noexcept] QGeoPath::~QGeoPath()

删除此路径。

[invokable] void QGeoPath::addCoordinate(const QGeoCoordinate &coordinate)

将coordinate 追加到路径中。

注意:此 函数可通过元对象系统以及从 QML 中调用。参见Q_INVOKABLE 。

void QGeoPath::clearPath()

扫清障碍。

[invokable] bool QGeoPath::containsCoordinate(const QGeoCoordinate &coordinate) const

如果路径中包含coordinate 作为其中一个元素,则返回 true。

注意: 可通过元对象系统和 QML 调用此 函数。参见Q_INVOKABLE 。

[invokable] QGeoCoordinate QGeoPath::coordinateAt(qsizetype index) const

返回坐标index 处的坐标。

注意: 可通过元对象系统和 QML 调用此 函数。参见Q_INVOKABLE 。

[invokable] void QGeoPath::insertCoordinate(qsizetype index, const QGeoCoordinate &coordinate)

在指定的index 位置插入coordinate 。

注意: 可通过元对象系统或从 QML 中调用此 函数。请参阅Q_INVOKABLE 。

[invokable] double QGeoPath::length(qsizetype indexFrom = 0, qsizetype indexTo = -1) const

返回从元素indexFrom 到元素indexTo 的路径长度(单位:米)。该长度应为每对相邻点之间最短距离之和。

如果indexTo 为 -1(默认值),则长度将包含最后一个坐标与第一个坐标之间的距离(闭合环)。要获取路径的长度,请将indexFrom 设为 0,并将QGeoPath::size() - 1 设为indexTo 。

注意:该 函数可通过元对象系统以及从 QML 中调用。参见Q_INVOKABLE 。

const QList<QGeoCoordinate> &QGeoPath::path() const

返回路径中的所有元素。

另请参阅 setPath()。

[invokable] void QGeoPath::removeCoordinate(const QGeoCoordinate &coordinate)

从路径中移除最后一个“coordinate ”。

注意: 可通过元对象系统和 QML 调用此 函数。参见Q_INVOKABLE 。

[invokable] void QGeoPath::removeCoordinate(qsizetype index)

从路径中移除位于位置index 的元素。

注意: 可通过元对象系统或从 QML 调用此 函数。参见Q_INVOKABLE 。

[invokable] void QGeoPath::replaceCoordinate(qsizetype index, const QGeoCoordinate &coordinate)

将位于指定位置index 的 path 元素替换为coordinate 。

注意:此 函数可通过元对象系统以及从 QML 中调用。参见Q_INVOKABLE 。

void QGeoPath::setPath(const QList<QGeoCoordinate> &path)

设置path 中的所有元素。

另请参阅 path()。

[invokable] qsizetype QGeoPath::size() const

返回路径中的元素个数。

注意: 可通过元对象系统和 QML 调用此 函数。参见Q_INVOKABLE 。

[invokable] QString QGeoPath::toString() const

返回地理路径属性,格式为字符串。

注意: 可通过元对象系统和 QML 调用此 函数。参见Q_INVOKABLE 。

[invokable] void QGeoPath::translate(double degreesLatitude, double degreesLongitude)

将此地理路径沿degreesLatitude 向北平移,并沿degreesLongitude 向东平移。

degreesLatitude 和degreesLongitude 的负值分别对应向南和向西的平移。

注意: 可通过元对象系统和 QML 调用此 函数。参见Q_INVOKABLE 。

[invokable] QGeoPath QGeoPath::translated(double degreesLatitude, double degreesLongitude) const

返回该地理路径的副本,该副本经由degreesLatitude 向北平移,并经由degreesLongitude 向东平移。

degreesLatitude 和degreesLongitude 的负值分别对应向南和向西平移。

注意: 可通过元对象系统和从 QML 调用此 函数。参见Q_INVOKABLE 。

另请参阅 translate()。

qreal QGeoPath::width() const

返回路径的宽度(单位为米)。该信息用于contains 方法。默认值为0。

注意: 这是 width 属性的获取器 函数。

另请参阅 setWidth()。

QGeoPath &QGeoPath::operator=(const QGeoPath &other)

将other 分配给此地理路径,并返回对此地理路径的引用。

© 2026 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.