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 定义,前者指定矩形的左上坐标,后者指定矩形的右下坐标。
如果左上角或右下角坐标无效,或者左上角坐标位于右下角坐标以南,则地理矩形被视为无效。
地理矩形永远不能穿过两极。
有几种方法的行为就好像地理矩形是根据中心坐标、地理矩形的宽度(度)和地理矩形的高度(度)定义的。
如果调整了地理矩形的高度或中心,使其与某个极点相交,则会修改高度,使地理矩形接触但不与极点相交,并且中心坐标仍位于地理矩形的中心。
自 Qt XML 5.5 起,该类是Q_GADGET 。它可直接用于 C++ 和 QML。
属性文档
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()。
注: 属性中心的获取函数。
另请参阅 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
以度为单位返回该地理矩形的宽度。
如果该地理矩形无效,则返回值未定义。
注: 宽度属性的获取函数。
另请参见 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 度。这样做是为了确保结果与操作数的顺序无关。
© 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.