QGeoRectangle Class
QGeoRectangle 类用于定义一个矩形地理区域。更多内容...
| 头文件: | #include <QGeoRectangle> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS Positioning) target_link_libraries(mytarget PRIVATE Qt6::Positioning) |
| qmake: | QT += positioning |
| 继承自: | QGeoShape |
属性
|
公共函数
| QGeoRectangle() | |
| QGeoRectangle(const QGeoShape &other) | |
| QGeoRectangle(const QList<QGeoCoordinate> &coordinates) | |
| QGeoRectangle(const QGeoCoordinate &topLeft, const QGeoCoordinate &bottomRight) | |
| QGeoRectangle(const QGeoCoordinate ¢er, double degreesWidth, double degreesHeight) | |
| QGeoRectangle(const QGeoRectangle &other) | |
| ~QGeoRectangle() | |
| QGeoCoordinate | bottomLeft() const |
| QGeoCoordinate | bottomRight() const |
| QGeoCoordinate | center() const |
| bool | contains(const QGeoRectangle &rectangle) const |
| void | extendRectangle(const QGeoCoordinate &coordinate) |
| double | height() const |
| bool | intersects(const QGeoRectangle &rectangle) const |
| void | setBottomLeft(const QGeoCoordinate &bottomLeft) |
| void | setBottomRight(const QGeoCoordinate &bottomRight) |
| void | setCenter(const QGeoCoordinate ¢er) |
| void | setHeight(double degreesHeight) |
| void | setTopLeft(const QGeoCoordinate &topLeft) |
| void | setTopRight(const QGeoCoordinate &topRight) |
| void | setWidth(double degreesWidth) |
| QString | toString() const |
| QGeoCoordinate | topLeft() const |
| QGeoCoordinate | topRight() const |
| void | translate(double degreesLatitude, double degreesLongitude) |
| QGeoRectangle | translated(double degreesLatitude, double degreesLongitude) const |
| QGeoRectangle | united(const QGeoRectangle &rectangle) const |
| double | width() const |
| QGeoRectangle & | operator=(const QGeoRectangle &other) |
| QGeoRectangle | operator|(const QGeoRectangle &rectangle) const |
| QGeoRectangle & | operator|=(const QGeoRectangle &rectangle) |
详细说明
该矩形通过一个QGeoCoordinate (指定矩形的左上角坐标)和一个QGeoCoordinate (指定矩形的右下角坐标)来定义。
如果左上角或右下角坐标无效,或者左上角坐标位于右下角坐标以南,则该地理矩形被视为无效。
地理矩形绝不能穿过两极。
某些方法的行为仿佛地理矩形是通过中心坐标、地理矩形的宽度(以度为单位)和地理矩形的高度(以度为单位)来定义的一样。
如果地理矩形的高度或中心被调整到会穿越其中一个极点,则会修改高度,使地理矩形接触但不穿越该极点,并且中心坐标仍位于地理矩形的中心。
在 QML 中,也可通过geoRectangle 访问此类。
属性文档
bottomLeft : QGeoCoordinate
该属性存储了该几何矩形的左下角坐标。
虽然该属性是在 Qt 5.5 中引入的,但相关的访问器函数自该类的第一个版本起就已存在。
访问函数:
| QGeoCoordinate | bottomLeft() const |
| void | setBottomLeft(const QGeoCoordinate &bottomLeft) |
bottomRight : QGeoCoordinate
该属性存储了此几何矩形的右下角坐标。
虽然该属性是在 Qt 5.5 中引入的,但相关的访问器函数自该类的第一个版本起就已存在。
访问函数:
| QGeoCoordinate | bottomRight() const |
| void | setBottomRight(const QGeoCoordinate &bottomRight) |
center : QGeoCoordinate
该属性存储了此几何矩形的中心点。
虽然该属性是在 Qt 5.5 中引入的,但相关的访问器函数自该类的第一个版本起就已存在。
访问函数:
另请参阅 QGeoShape::center 。
height : double
该属性以度为单位存储此地理矩形的高度。
如果该地理矩形无效,则该属性值为未定义。
如果新高度小于 0.0 或该地理矩形无效,则该属性不会发生变化。要根据中心、宽度和高度设置无效地理矩形的值,应先使用setCenter() 使地理矩形有效。
如果高度的变化会导致地理矩形穿过极点,则会调整高度,使地理矩形仅与极点相切。
此调整确保中心坐标仍位于地理矩形的中心,这可能会导致地理矩形的高度小于预期。
只有当新高度大于或等于 180 时,才会使用 180.0 作为高度。
虽然该属性是在 Qt 5.5 中引入的,但相关的访问器函数自该类的第一个版本起就已存在。
访问函数:
topLeft : QGeoCoordinate
该属性存储了此地理矩形的左上角坐标。
虽然该属性是在 Qt 5.5 中引入的,但相关的访问器函数自该类的第一个版本起就已存在。
访问函数:
| QGeoCoordinate | topLeft() const |
| void | setTopLeft(const QGeoCoordinate &topLeft) |
topRight : QGeoCoordinate
该属性存储了此几何矩形的右上角坐标。
虽然该属性是在 Qt 5.5 中引入的,但相关的访问器函数自该类的第一个版本起就已存在。
访问函数:
| QGeoCoordinate | topRight() const |
| void | setTopRight(const QGeoCoordinate &topRight) |
width : double
该属性以度为单位存储此地理矩形的宽度。
如果该地理矩形无效,则该属性值为未定义。
如果新宽度小于 0.0 或该地理矩形无效,则此函数不执行任何操作。要根据中心、宽度和高度设置无效地理矩形的值,应先使用setCenter() 使地理矩形有效。
只有当新宽度大于或等于 360 时,才会使用 360.0 作为宽度。在这种情况下,地理矩形的最左侧经度将设置为 -180.0 度,最右侧经度将设置为 180.0 度。
虽然该属性是在 Qt 5.5 中引入的,但相关的访问器函数自该类的第一个版本起就已存在。
访问函数:
成员函数文档
QGeoRectangle::QGeoRectangle()
构建一个新的、无效的地理矩形。
QGeoRectangle::QGeoRectangle(const QGeoShape &other)
根据other 中的内容构建一个地理矩形。
QGeoRectangle::QGeoRectangle(const QList<QGeoCoordinate> &coordinates)
构建一个新的、最小尺寸的几何矩形,该矩形包含所有coordinates 。
QGeoRectangle::QGeoRectangle(const QGeoCoordinate &topLeft, const QGeoCoordinate &bottomRight)
创建一个新的地理矩形,其左上角坐标为topLeft ,右下角坐标为bottomRight 。
QGeoRectangle::QGeoRectangle(const QGeoCoordinate ¢er, double degreesWidth, double degreesHeight)
构建一个新的地理矩形,其中心位于center ,宽度(以度为单位)为degreesWidth ,高度(以度为单位)为degreesHeight 。
如果degreesHeight 会导致地理矩形超出其中一个极点,则该地理矩形的高度将被截断,使得地理矩形仅延伸至该极点为止。地理矩形的中心点保持不变,高度将进行调整,以确保中心点位于截断后地理矩形的中心位置。
QGeoRectangle::QGeoRectangle(const QGeoRectangle &other)
根据other 中的内容构建一个地理矩形。
[noexcept] QGeoRectangle::~QGeoRectangle()
删除此几何矩形。
QGeoCoordinate QGeoRectangle::bottomLeft() const
返回此几何矩形的左下角坐标。
注意: 这是 bottomLeft 属性的获取 函数。
另请参阅 setBottomLeft()。
QGeoCoordinate QGeoRectangle::bottomRight() const
返回该几何矩形的右下角坐标。
注意: 这是 bottomRight 属性的获取 函数。
另请参阅 setBottomRight()。
QGeoCoordinate QGeoRectangle::center() const
返回此几何矩形的中心。等同于QGeoShape::center()。
注意: 这是 center 属性的获取 函数。
另请参阅 setCenter()。
bool QGeoRectangle::contains(const QGeoRectangle &rectangle) const
返回地理矩形rectangle 是否包含于该地理矩形之中。
[invokable] void QGeoRectangle::extendRectangle(const QGeoCoordinate &coordinate)
将地理矩形扩展以覆盖该坐标coordinate
注意: 可通过元对象系统和 QML 调用此 函数。参见Q_INVOKABLE 。
double QGeoRectangle::height() const
返回此地理矩形的高度(单位为度)。
如果该地理矩形无效,则返回值为未定义。
注意: 这是 height 属性的获取 函数。
另请参阅 setHeight()。
[invokable] bool QGeoRectangle::intersects(const QGeoRectangle &rectangle) const
返回地理矩形rectangle 是否与该地理矩形相交。
如果两个地理矩形的顶边或底边均位于其中一个极点处,则认为这两个地理矩形相交,因为当边位于极点时,经度无关紧要。
注意: 可通过元对象系统和 QML 调用此 函数。参见Q_INVOKABLE 。
void QGeoRectangle::setBottomLeft(const QGeoCoordinate &bottomLeft)
将此几何矩形的左下角坐标设置为bottomLeft 。
注意: 这是属性bottomLeft 的设置 函数。
另请参阅 bottomLeft()。
void QGeoRectangle::setBottomRight(const QGeoCoordinate &bottomRight)
将此几何矩形的右下角坐标设置为bottomRight 。
注意: 这是属性bottomRight 的设置 函数。
另请参阅 bottomRight()。
void QGeoRectangle::setCenter(const QGeoCoordinate ¢er)
将此几何矩形的中心设置为center 。
如果这导致该地理矩形与其中一个极点相交,则地理矩形的高度将被截断,使得地理矩形仅延伸至该极点。地理矩形的中心点将保持不变,且高度将进行调整,以确保中心点位于截断后的地理矩形中心。
注意: 这是属性 `center`的设置 函数。
另请参阅 center()。
void QGeoRectangle::setHeight(double degreesHeight)
将此几何矩形的高度(以度为单位)设置为degreesHeight 。
注意: 这是属性 `height`的设置 函数。
另请参阅 height()。
void QGeoRectangle::setTopLeft(const QGeoCoordinate &topLeft)
将此几何矩形的左上角坐标设置为topLeft 。
注意: 这是属性 `topLeft`的设置 函数。
另请参阅 topLeft()。
void QGeoRectangle::setTopRight(const QGeoCoordinate &topRight)
将此几何矩形的右上角坐标设置为topRight 。
注意: 这是属性 `topRight`的设置 函数。
另请参阅 topRight()。
void QGeoRectangle::setWidth(double degreesWidth)
将此几何矩形的宽度(以度为单位)设置为degreesWidth 。
注意: 这是属性width 的设置 函数。
另请参阅 width()。
[invokable] QString QGeoRectangle::toString() const
返回地理矩形的属性,格式为字符串。
注意: 可通过元对象系统和 QML 调用此 函数。请参阅Q_INVOKABLE 。
QGeoCoordinate QGeoRectangle::topLeft() const
返回此地理矩形的左上角坐标。
注意: 这是 topLeft 属性的获取 函数。
另请参阅 setTopLeft()。
QGeoCoordinate QGeoRectangle::topRight() const
返回此地理矩形的右上角坐标。
注意: 这是属性 topRight 的获取 函数。
另请参阅 setTopRight()。
[invokable] void QGeoRectangle::translate(double degreesLatitude, double degreesLongitude)
将此地理矩形向北平移degreesLatitude ,向东平移degreesLongitude 。
degreesLatitude 和degreesLongitude 的负值分别对应向南和向西的平移。
如果平移会导致地理矩形穿过极点,则该地理矩形将被平移至其顶边或底边接触极点为止,但不会继续平移。
注意: 可通过元对象系统和 QML 调用此 函数。参见Q_INVOKABLE 。
[invokable] QGeoRectangle QGeoRectangle::translated(double degreesLatitude, double degreesLongitude) const
返回该地理矩形的副本,该副本沿degreesLatitude 向北平移,并沿degreesLongitude 向东平移。
degreesLatitude 和degreesLongitude 的负值分别对应向南和向西的平移。
注意: 可通过元对象系统和 QML 调用此 函数。参见Q_INVOKABLE 。
另请参阅 translate()。
[invokable] QGeoRectangle QGeoRectangle::united(const QGeoRectangle &rectangle) const
返回包含该地理矩形和rectangle 的最小地理矩形。
如果两个地理矩形的中心相隔恰好 180.0 度,则宽度将设置为 360.0 度,最左侧经度设置为 -180.0 度,最右侧经度设置为 180.0 度。 这样做是为了确保结果与操作数的顺序无关。
注意: 可通过元对象系统和 QML 调用此 函数。参见Q_INVOKABLE 。
double QGeoRectangle::width() const
返回该地理矩形的宽度(单位为度)。
如果该地理矩形无效,则返回值为未定义。
注意: 这是 width 属性的获取器 函数。
另请参阅 setWidth()。
QGeoRectangle &QGeoRectangle::operator=(const QGeoRectangle &other)
将other 分配给此地理矩形,并返回对此地理矩形的引用。
QGeoRectangle QGeoRectangle::operator|(const QGeoRectangle &rectangle) const
返回包含该地理矩形和rectangle 的最小地理矩形。
如果两个地理矩形的中心之间的夹角恰好为 180.0 度,则宽度将设置为 360.0 度,其中最左侧经度设置为 -180.0 度,最右侧经度设置为 180.0 度。 这样做是为了确保结果与操作数的顺序无关。
QGeoRectangle &QGeoRectangle::operator|=(const QGeoRectangle &rectangle)
返回同时包含该地理矩形和rectangle 的最小地理矩形。
如果这两个地理矩形的中心之间的夹角恰好为 180.0 度,则宽度将设置为 360.0 度,最左侧经度设置为 -180.0 度,最右侧经度设置为 180.0 度。 这样做是为了确保结果不受操作数顺序的影响。
© 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.