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() 为该形状返回的边框有关,边框左上角的纬度将设置为路径点集中的最大纬度。同样,右下角的纬度将是路径点集中的最小纬度。

该类是Q_GADGET 。它可直接用于 C++ 和 QML

如果一个 QGeoPath 不包含坐标,那么它既是无效的,也是空的。

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

属性文档

path : const 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)

根据坐标列表 (pathwidth) 构建新的地理路径。

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)

coordinate 替换指定index 处的路径元素。

注: 可通过元对象系统和 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 向东平移该地理路径。

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

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

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

返回degreesLatitude 向北和degreesLongitude 向东平移后的地理路径副本。

degreesLatitudedegreesLongitude 的负值分别对应于向南和向西平移。

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

另请参阅 translate() 。

qreal QGeoPath::width() const

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

注: 宽度属性的获取函数。

另请参阅 setWidth().

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

为该地理路径指定other ,并返回对该地理路径的引用。

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