Make QgsRectangle protected members private

This class is not designed to be subclassed
This commit is contained in:
Nyall Dawson 2017-04-11 14:55:57 +10:00
parent a45e5700da
commit 5fb63c066f
3 changed files with 114 additions and 112 deletions

View File

@ -1727,6 +1727,11 @@ QgsRasterRenderer
- MinMaxOrigin enum, minMaxOriginName(), minMaxOriginLabel(), minMaxOriginFromName() removed. Use minMaxOrigin() instead - MinMaxOrigin enum, minMaxOriginName(), minMaxOriginLabel(), minMaxOriginFromName() removed. Use minMaxOrigin() instead
QgsRectangle {#qgis_api_break_3_0_QgsRectangle}
------------
- The protected members were removed - QgsRectangle is not intended to be subclassed.
QgsRelation {#qgis_api_break_3_0_QgsRelation} QgsRelation {#qgis_api_break_3_0_QgsRelation}
----------- -----------

View File

@ -30,10 +30,10 @@
#include "qgslogger.h" #include "qgslogger.h"
QgsRectangle::QgsRectangle( double newxmin, double newymin, double newxmax, double newymax ) QgsRectangle::QgsRectangle( double newxmin, double newymin, double newxmax, double newymax )
: xmin( newxmin ) : mXmin( newxmin )
, ymin( newymin ) , mYmin( newymin )
, xmax( newxmax ) , mXmax( newxmax )
, ymax( newymax ) , mYmax( newymax )
{ {
normalize(); normalize();
} }
@ -45,36 +45,36 @@ QgsRectangle::QgsRectangle( const QgsPoint &p1, const QgsPoint &p2 )
QgsRectangle::QgsRectangle( QRectF const &qRectF ) QgsRectangle::QgsRectangle( QRectF const &qRectF )
{ {
xmin = qRectF.topLeft().x(); mXmin = qRectF.topLeft().x();
ymin = qRectF.topLeft().y(); mYmin = qRectF.topLeft().y();
xmax = qRectF.bottomRight().x(); mXmax = qRectF.bottomRight().x();
ymax = qRectF.bottomRight().y(); mYmax = qRectF.bottomRight().y();
} }
QgsRectangle::QgsRectangle( const QgsRectangle &r ) QgsRectangle::QgsRectangle( const QgsRectangle &r )
{ {
xmin = r.xMinimum(); mXmin = r.xMinimum();
ymin = r.yMinimum(); mYmin = r.yMinimum();
xmax = r.xMaximum(); mXmax = r.xMaximum();
ymax = r.yMaximum(); mYmax = r.yMaximum();
} }
void QgsRectangle::set( const QgsPoint &p1, const QgsPoint &p2 ) void QgsRectangle::set( const QgsPoint &p1, const QgsPoint &p2 )
{ {
xmin = p1.x(); mXmin = p1.x();
xmax = p2.x(); mXmax = p2.x();
ymin = p1.y(); mYmin = p1.y();
ymax = p2.y(); mYmax = p2.y();
normalize(); normalize();
} }
void QgsRectangle::set( double xmin_, double ymin_, double xmax_, double ymax_ ) void QgsRectangle::set( double xmin_, double ymin_, double xmax_, double ymax_ )
{ {
xmin = xmin_; mXmin = xmin_;
ymin = ymin_; mYmin = ymin_;
xmax = xmax_; mXmax = xmax_;
ymax = ymax_; mYmax = ymax_;
normalize(); normalize();
} }
@ -83,23 +83,23 @@ void QgsRectangle::normalize()
if ( isNull() ) if ( isNull() )
return; return;
if ( xmin > xmax ) if ( mXmin > mXmax )
{ {
std::swap( xmin, xmax ); std::swap( mXmin, mXmax );
} }
if ( ymin > ymax ) if ( mYmin > mYmax )
{ {
std::swap( ymin, ymax ); std::swap( mYmin, mYmax );
} }
} // QgsRectangle::normalize() } // QgsRectangle::normalize()
void QgsRectangle::setMinimal() void QgsRectangle::setMinimal()
{ {
xmin = std::numeric_limits<double>::max(); mXmin = std::numeric_limits<double>::max();
ymin = std::numeric_limits<double>::max(); mYmin = std::numeric_limits<double>::max();
xmax = -std::numeric_limits<double>::max(); mXmax = -std::numeric_limits<double>::max();
ymax = -std::numeric_limits<double>::max(); mYmax = -std::numeric_limits<double>::max();
} }
void QgsRectangle::scale( double scaleFactor, const QgsPoint *cp ) void QgsRectangle::scale( double scaleFactor, const QgsPoint *cp )
@ -113,8 +113,8 @@ void QgsRectangle::scale( double scaleFactor, const QgsPoint *cp )
} }
else else
{ {
centerX = xmin + width() / 2; centerX = mXmin + width() / 2;
centerY = ymin + height() / 2; centerY = mYmin + height() / 2;
} }
scale( scaleFactor, centerX, centerY ); scale( scaleFactor, centerX, centerY );
} }
@ -123,18 +123,18 @@ void QgsRectangle::scale( double scaleFactor, double centerX, double centerY )
{ {
double newWidth = width() * scaleFactor; double newWidth = width() * scaleFactor;
double newHeight = height() * scaleFactor; double newHeight = height() * scaleFactor;
xmin = centerX - newWidth / 2.0; mXmin = centerX - newWidth / 2.0;
xmax = centerX + newWidth / 2.0; mXmax = centerX + newWidth / 2.0;
ymin = centerY - newHeight / 2.0; mYmin = centerY - newHeight / 2.0;
ymax = centerY + newHeight / 2.0; mYmax = centerY + newHeight / 2.0;
} }
void QgsRectangle::grow( double delta ) void QgsRectangle::grow( double delta )
{ {
xmin -= delta; mXmin -= delta;
xmax += delta; mXmax += delta;
ymin -= delta; mYmin -= delta;
ymax += delta; mYmax += delta;
} }
void QgsRectangle::include( const QgsPoint &p ) void QgsRectangle::include( const QgsPoint &p )
@ -151,7 +151,7 @@ void QgsRectangle::include( const QgsPoint &p )
QgsRectangle QgsRectangle::buffer( double width ) QgsRectangle QgsRectangle::buffer( double width )
{ {
return QgsRectangle( xmin - width, ymin - width, xmax + width, ymax + width ); return QgsRectangle( mXmin - width, mYmin - width, mXmax + width, mYmax + width );
} }
QgsRectangle QgsRectangle::intersect( const QgsRectangle *rect ) const QgsRectangle QgsRectangle::intersect( const QgsRectangle *rect ) const
@ -163,21 +163,21 @@ QgsRectangle QgsRectangle::intersect( const QgsRectangle *rect ) const
return intersection; return intersection;
} }
intersection.setXMinimum( xmin > rect->xMinimum() ? xmin : rect->xMinimum() ); intersection.setXMinimum( mXmin > rect->xMinimum() ? mXmin : rect->xMinimum() );
intersection.setXMaximum( xmax < rect->xMaximum() ? xmax : rect->xMaximum() ); intersection.setXMaximum( mXmax < rect->xMaximum() ? mXmax : rect->xMaximum() );
intersection.setYMinimum( ymin > rect->yMinimum() ? ymin : rect->yMinimum() ); intersection.setYMinimum( mYmin > rect->yMinimum() ? mYmin : rect->yMinimum() );
intersection.setYMaximum( ymax < rect->yMaximum() ? ymax : rect->yMaximum() ); intersection.setYMaximum( mYmax < rect->yMaximum() ? mYmax : rect->yMaximum() );
return intersection; return intersection;
} }
bool QgsRectangle::intersects( const QgsRectangle &rect ) const bool QgsRectangle::intersects( const QgsRectangle &rect ) const
{ {
double x1 = ( xmin > rect.xmin ? xmin : rect.xmin ); double x1 = ( mXmin > rect.mXmin ? mXmin : rect.mXmin );
double x2 = ( xmax < rect.xmax ? xmax : rect.xmax ); double x2 = ( mXmax < rect.mXmax ? mXmax : rect.mXmax );
if ( x1 > x2 ) if ( x1 > x2 )
return false; return false;
double y1 = ( ymin > rect.ymin ? ymin : rect.ymin ); double y1 = ( mYmin > rect.mYmin ? mYmin : rect.mYmin );
double y2 = ( ymax < rect.ymax ? ymax : rect.ymax ); double y2 = ( mYmax < rect.mYmax ? mYmax : rect.mYmax );
if ( y1 > y2 ) if ( y1 > y2 )
return false; return false;
return true; return true;
@ -185,13 +185,13 @@ bool QgsRectangle::intersects( const QgsRectangle &rect ) const
bool QgsRectangle::contains( const QgsRectangle &rect ) const bool QgsRectangle::contains( const QgsRectangle &rect ) const
{ {
return ( rect.xmin >= xmin && rect.xmax <= xmax && rect.ymin >= ymin && rect.ymax <= ymax ); return ( rect.mXmin >= mXmin && rect.mXmax <= mXmax && rect.mYmin >= mYmin && rect.mYmax <= mYmax );
} }
bool QgsRectangle::contains( const QgsPoint &p ) const bool QgsRectangle::contains( const QgsPoint &p ) const
{ {
return xmin <= p.x() && p.x() <= xmax && return mXmin <= p.x() && p.x() <= mXmax &&
ymin <= p.y() && p.y() <= ymax; mYmin <= p.y() && p.y() <= mYmax;
} }
void QgsRectangle::combineExtentWith( const QgsRectangle &rect ) void QgsRectangle::combineExtentWith( const QgsRectangle &rect )
@ -200,11 +200,11 @@ void QgsRectangle::combineExtentWith( const QgsRectangle &rect )
*this = rect; *this = rect;
else else
{ {
xmin = ( ( xmin < rect.xMinimum() ) ? xmin : rect.xMinimum() ); mXmin = ( ( mXmin < rect.xMinimum() ) ? mXmin : rect.xMinimum() );
xmax = ( ( xmax > rect.xMaximum() ) ? xmax : rect.xMaximum() ); mXmax = ( ( mXmax > rect.xMaximum() ) ? mXmax : rect.xMaximum() );
ymin = ( ( ymin < rect.yMinimum() ) ? ymin : rect.yMinimum() ); mYmin = ( ( mYmin < rect.yMinimum() ) ? mYmin : rect.yMinimum() );
ymax = ( ( ymax > rect.yMaximum() ) ? ymax : rect.yMaximum() ); mYmax = ( ( mYmax > rect.yMaximum() ) ? mYmax : rect.yMaximum() );
} }
} }
@ -215,32 +215,32 @@ void QgsRectangle::combineExtentWith( double x, double y )
*this = QgsRectangle( x, y, x, y ); *this = QgsRectangle( x, y, x, y );
else else
{ {
xmin = ( ( xmin < x ) ? xmin : x ); mXmin = ( ( mXmin < x ) ? mXmin : x );
xmax = ( ( xmax > x ) ? xmax : x ); mXmax = ( ( mXmax > x ) ? mXmax : x );
ymin = ( ( ymin < y ) ? ymin : y ); mYmin = ( ( mYmin < y ) ? mYmin : y );
ymax = ( ( ymax > y ) ? ymax : y ); mYmax = ( ( mYmax > y ) ? mYmax : y );
} }
} }
bool QgsRectangle::isEmpty() const bool QgsRectangle::isEmpty() const
{ {
return xmax <= xmin || ymax <= ymin; return mXmax <= mXmin || mYmax <= mYmin;
} }
bool QgsRectangle::isNull() const bool QgsRectangle::isNull() const
{ {
// rectangle created QgsRectangle() or with rect.setMinimal() ? // rectangle created QgsRectangle() or with rect.setMinimal() ?
return ( qgsDoubleNear( xmin, 0.0 ) && qgsDoubleNear( xmax, 0.0 ) && qgsDoubleNear( ymin, 0.0 ) && qgsDoubleNear( ymax, 0.0 ) ) || return ( qgsDoubleNear( mXmin, 0.0 ) && qgsDoubleNear( mXmax, 0.0 ) && qgsDoubleNear( mYmin, 0.0 ) && qgsDoubleNear( mYmax, 0.0 ) ) ||
( qgsDoubleNear( xmin, std::numeric_limits<double>::max() ) && qgsDoubleNear( ymin, std::numeric_limits<double>::max() ) && ( qgsDoubleNear( mXmin, std::numeric_limits<double>::max() ) && qgsDoubleNear( mYmin, std::numeric_limits<double>::max() ) &&
qgsDoubleNear( xmax, -std::numeric_limits<double>::max() ) && qgsDoubleNear( ymax, -std::numeric_limits<double>::max() ) ); qgsDoubleNear( mXmax, -std::numeric_limits<double>::max() ) && qgsDoubleNear( mYmax, -std::numeric_limits<double>::max() ) );
} }
QString QgsRectangle::asWktCoordinates() const QString QgsRectangle::asWktCoordinates() const
{ {
QString rep = QString rep =
qgsDoubleToString( xmin ) + ' ' + qgsDoubleToString( ymin ) + ", " + qgsDoubleToString( mXmin ) + ' ' + qgsDoubleToString( mYmin ) + ", " +
qgsDoubleToString( xmax ) + ' ' + qgsDoubleToString( ymax ); qgsDoubleToString( mXmax ) + ' ' + qgsDoubleToString( mYmax );
return rep; return rep;
} }
@ -249,11 +249,11 @@ QString QgsRectangle::asWktPolygon() const
{ {
QString rep = QString rep =
QStringLiteral( "POLYGON((" ) + QStringLiteral( "POLYGON((" ) +
qgsDoubleToString( xmin ) + ' ' + qgsDoubleToString( ymin ) + ", " + qgsDoubleToString( mXmin ) + ' ' + qgsDoubleToString( mYmin ) + ", " +
qgsDoubleToString( xmax ) + ' ' + qgsDoubleToString( ymin ) + ", " + qgsDoubleToString( mXmax ) + ' ' + qgsDoubleToString( mYmin ) + ", " +
qgsDoubleToString( xmax ) + ' ' + qgsDoubleToString( ymax ) + ", " + qgsDoubleToString( mXmax ) + ' ' + qgsDoubleToString( mYmax ) + ", " +
qgsDoubleToString( xmin ) + ' ' + qgsDoubleToString( ymax ) + ", " + qgsDoubleToString( mXmin ) + ' ' + qgsDoubleToString( mYmax ) + ", " +
qgsDoubleToString( xmin ) + ' ' + qgsDoubleToString( ymin ) + qgsDoubleToString( mXmin ) + ' ' + qgsDoubleToString( mYmin ) +
QStringLiteral( "))" ); QStringLiteral( "))" );
return rep; return rep;
@ -261,7 +261,7 @@ QString QgsRectangle::asWktPolygon() const
QRectF QgsRectangle::toRectF() const QRectF QgsRectangle::toRectF() const
{ {
return QRectF( static_cast< qreal >( xmin ), static_cast< qreal >( ymin ), static_cast< qreal >( xmax - xmin ), static_cast< qreal >( ymax - ymin ) ); return QRectF( static_cast< qreal >( mXmin ), static_cast< qreal >( mYmin ), static_cast< qreal >( mXmax - mXmin ), static_cast< qreal >( mYmax - mYmin ) );
} }
// Returns a string representation of form xmin,ymin : xmax,ymax. Coordinates will be truncated // Returns a string representation of form xmin,ymin : xmax,ymax. Coordinates will be truncated
@ -287,10 +287,10 @@ QString QgsRectangle::toString( int precision ) const
rep = QStringLiteral( "Empty" ); rep = QStringLiteral( "Empty" );
else else
rep = QStringLiteral( "%1,%2 : %3,%4" ) rep = QStringLiteral( "%1,%2 : %3,%4" )
.arg( xmin, 0, 'f', precision ) .arg( mXmin, 0, 'f', precision )
.arg( ymin, 0, 'f', precision ) .arg( mYmin, 0, 'f', precision )
.arg( xmax, 0, 'f', precision ) .arg( mXmax, 0, 'f', precision )
.arg( ymax, 0, 'f', precision ); .arg( mYmax, 0, 'f', precision );
QgsDebugMsgLevel( QString( "Extents : %1" ).arg( rep ), 4 ); QgsDebugMsgLevel( QString( "Extents : %1" ).arg( rep ), 4 );
@ -312,11 +312,11 @@ QString QgsRectangle::asPolygon() const
// NOTE: a polygon isn't a polygon unless its closed. In the case of // NOTE: a polygon isn't a polygon unless its closed. In the case of
// a rectangle, that means 5 points (last == first) // a rectangle, that means 5 points (last == first)
foo foo
<< xmin << ' ' << ymin << ", " << mXmin << ' ' << mYmin << ", "
<< xmin << ' ' << ymax << ", " << mXmin << ' ' << mYmax << ", "
<< xmax << ' ' << ymax << ", " << mXmax << ' ' << mYmax << ", "
<< xmax << ' ' << ymin << ", " << mXmax << ' ' << mYmin << ", "
<< xmin << ' ' << ymin; << mXmin << ' ' << mYmin;
return rep; return rep;
@ -342,10 +342,10 @@ QgsRectangle &QgsRectangle::operator=( const QgsRectangle &r )
{ {
if ( &r != this ) if ( &r != this )
{ {
xmax = r.xMaximum(); mXmax = r.xMaximum();
xmin = r.xMinimum(); mXmin = r.xMinimum();
ymax = r.yMaximum(); mYmax = r.yMaximum();
ymin = r.yMinimum(); mYmin = r.yMinimum();
} }
return *this; return *this;
@ -366,11 +366,11 @@ void QgsRectangle::unionRect( const QgsRectangle &r )
bool QgsRectangle::isFinite() const bool QgsRectangle::isFinite() const
{ {
if ( qIsInf( xmin ) || qIsInf( ymin ) || qIsInf( xmax ) || qIsInf( ymax ) ) if ( qIsInf( mXmin ) || qIsInf( mYmin ) || qIsInf( mXmax ) || qIsInf( mYmax ) )
{ {
return false; return false;
} }
if ( qIsNaN( xmin ) || qIsNaN( ymin ) || qIsNaN( xmax ) || qIsNaN( ymax ) ) if ( qIsNaN( mXmin ) || qIsNaN( mYmin ) || qIsNaN( mXmax ) || qIsNaN( mYmax ) )
{ {
return false; return false;
} }
@ -380,12 +380,12 @@ bool QgsRectangle::isFinite() const
void QgsRectangle::invert() void QgsRectangle::invert()
{ {
double tmp; double tmp;
tmp = xmin; tmp = mXmin;
xmin = ymin; mXmin = mYmin;
ymin = tmp; mYmin = tmp;
tmp = xmax; tmp = mXmax;
xmax = ymax; mXmax = mYmax;
ymax = tmp; mYmax = tmp;
} }
QDataStream &operator<<( QDataStream &out, const QgsRectangle &rectangle ) QDataStream &operator<<( QDataStream &out, const QgsRectangle &rectangle )

View File

@ -37,7 +37,7 @@ class CORE_EXPORT QgsRectangle
{ {
public: public:
//! Constructor //! Constructor
QgsRectangle( double xmin = 0, double ymin = 0, double xmax = 0, double ymax = 0 ); QgsRectangle( double mXmin = 0, double mYmin = 0, double mXmax = 0, double mYmax = 0 );
//! Construct a rectangle from two points. The rectangle is normalized after construction. //! Construct a rectangle from two points. The rectangle is normalized after construction.
QgsRectangle( const QgsPoint &p1, const QgsPoint &p2 ); QgsRectangle( const QgsPoint &p1, const QgsPoint &p2 );
//! Construct a rectangle from a QRectF. The rectangle is normalized after construction. //! Construct a rectangle from a QRectF. The rectangle is normalized after construction.
@ -51,7 +51,7 @@ class CORE_EXPORT QgsRectangle
void set( const QgsPoint &p1, const QgsPoint &p2 ); void set( const QgsPoint &p1, const QgsPoint &p2 );
//! Set the rectangle from four points. The rectangle is //! Set the rectangle from four points. The rectangle is
//! normalised after construction. //! normalised after construction.
void set( double xmin, double ymin, double xmax, double ymax ); void set( double mXmin, double mYmin, double mXmax, double mYmax );
//! Set the minimum x value //! Set the minimum x value
void setXMinimum( double x ); void setXMinimum( double x );
//! Set the maximum x value //! Set the maximum x value
@ -151,15 +151,12 @@ class CORE_EXPORT QgsRectangle
//! swap x/y //! swap x/y
void invert(); void invert();
protected: private:
// These are protected instead of private so that things like double mXmin;
// the QgsPostGisBox3d can get at them. double mYmin;
double mXmax;
double xmin; double mYmax;
double ymin;
double xmax;
double ymax;
}; };
@ -174,57 +171,57 @@ inline QgsRectangle::~QgsRectangle()
inline void QgsRectangle::setXMinimum( double x ) inline void QgsRectangle::setXMinimum( double x )
{ {
xmin = x; mXmin = x;
} }
inline void QgsRectangle::setXMaximum( double x ) inline void QgsRectangle::setXMaximum( double x )
{ {
xmax = x; mXmax = x;
} }
inline void QgsRectangle::setYMinimum( double y ) inline void QgsRectangle::setYMinimum( double y )
{ {
ymin = y; mYmin = y;
} }
inline void QgsRectangle::setYMaximum( double y ) inline void QgsRectangle::setYMaximum( double y )
{ {
ymax = y; mYmax = y;
} }
inline double QgsRectangle::xMaximum() const inline double QgsRectangle::xMaximum() const
{ {
return xmax; return mXmax;
} }
inline double QgsRectangle::xMinimum() const inline double QgsRectangle::xMinimum() const
{ {
return xmin; return mXmin;
} }
inline double QgsRectangle::yMaximum() const inline double QgsRectangle::yMaximum() const
{ {
return ymax; return mYmax;
} }
inline double QgsRectangle::yMinimum() const inline double QgsRectangle::yMinimum() const
{ {
return ymin; return mYmin;
} }
inline double QgsRectangle::width() const inline double QgsRectangle::width() const
{ {
return xmax - xmin; return mXmax - mXmin;
} }
inline double QgsRectangle::height() const inline double QgsRectangle::height() const
{ {
return ymax - ymin; return mYmax - mYmin;
} }
inline QgsPoint QgsRectangle::center() const inline QgsPoint QgsRectangle::center() const
{ {
return QgsPoint( xmin + width() / 2, ymin + height() / 2 ); return QgsPoint( mXmin + width() / 2, mYmin + height() / 2 );
} }
inline std::ostream &operator << ( std::ostream &os, const QgsRectangle &r ) inline std::ostream &operator << ( std::ostream &os, const QgsRectangle &r )
{ {