mirror of
https://github.com/qgis/QGIS.git
synced 2025-03-12 00:02:25 -04:00
Do not allow invalid map settings (fixes #12757)
This commit is contained in:
parent
9c73a22af5
commit
1bf9844652
@ -99,9 +99,16 @@ int QgsMapToPixel::mapWidth() const
|
||||
return mWidth;
|
||||
}
|
||||
|
||||
void QgsMapToPixel::updateMatrix()
|
||||
bool QgsMapToPixel::updateMatrix()
|
||||
{
|
||||
mMatrix = transform();
|
||||
QTransform newMatrix = transform();
|
||||
|
||||
// http://hub.qgis.org/issues/12757
|
||||
if ( !newMatrix.isInvertible() )
|
||||
return false;
|
||||
|
||||
mMatrix = newMatrix;
|
||||
return true;
|
||||
}
|
||||
|
||||
QgsPoint QgsMapToPixel::toMapPoint( qreal x, qreal y ) const
|
||||
@ -133,8 +140,12 @@ QgsPoint QgsMapToPixel::toMapCoordinatesF( double x, double y ) const
|
||||
|
||||
void QgsMapToPixel::setMapUnitsPerPixel( double mapUnitsPerPixel )
|
||||
{
|
||||
double oldUnits = mMapUnitsPerPixel;
|
||||
mMapUnitsPerPixel = mapUnitsPerPixel;
|
||||
updateMatrix();
|
||||
if ( !updateMatrix() )
|
||||
{
|
||||
mMapUnitsPerPixel = oldUnits;
|
||||
}
|
||||
}
|
||||
|
||||
double QgsMapToPixel::mapUnitsPerPixel() const
|
||||
@ -144,6 +155,11 @@ double QgsMapToPixel::mapUnitsPerPixel() const
|
||||
|
||||
void QgsMapToPixel::setMapRotation( double degrees, double cx, double cy )
|
||||
{
|
||||
double oldRotation = mRotation;
|
||||
double oldXCenter = xCenter;
|
||||
double oldYCenter = yCenter;
|
||||
double oldWidth = mWidth;
|
||||
|
||||
mRotation = degrees;
|
||||
xCenter = cx;
|
||||
yCenter = cy;
|
||||
@ -152,7 +168,14 @@ void QgsMapToPixel::setMapRotation( double degrees, double cx, double cy )
|
||||
// set width not that we can compute it
|
||||
mWidth = (( xCenter - xMin ) * 2 ) / mMapUnitsPerPixel;
|
||||
}
|
||||
updateMatrix();
|
||||
|
||||
if ( !updateMatrix() )
|
||||
{
|
||||
mRotation = oldRotation;
|
||||
xCenter = oldXCenter;
|
||||
yCenter = oldYCenter;
|
||||
mWidth = oldWidth;
|
||||
}
|
||||
}
|
||||
|
||||
double QgsMapToPixel::mapRotation() const
|
||||
@ -163,22 +186,45 @@ double QgsMapToPixel::mapRotation() const
|
||||
// @deprecated in 2.8
|
||||
void QgsMapToPixel::setYMinimum( double ymin )
|
||||
{
|
||||
double oldRotation = mRotation;
|
||||
double oldYCenter = yCenter;
|
||||
|
||||
yCenter = ymin + mHeight * mMapUnitsPerPixel / 2.0;
|
||||
mRotation = 0.0;
|
||||
updateMatrix();
|
||||
if ( !updateMatrix() )
|
||||
{
|
||||
mRotation = oldRotation;
|
||||
yCenter = oldYCenter;
|
||||
}
|
||||
}
|
||||
|
||||
// @deprecated in 2.8
|
||||
void QgsMapToPixel::setXMinimum( double xmin )
|
||||
{
|
||||
double oldRotation = mRotation;
|
||||
double oldXCenter = xCenter;
|
||||
|
||||
xCenter = xmin + mWidth * mMapUnitsPerPixel / 2.0;
|
||||
mRotation = 0.0;
|
||||
updateMatrix();
|
||||
|
||||
if ( !updateMatrix() )
|
||||
{
|
||||
mRotation = oldRotation;
|
||||
xCenter = oldXCenter;
|
||||
}
|
||||
}
|
||||
|
||||
// @deprecated in 2.8
|
||||
void QgsMapToPixel::setParameters( double mapUnitsPerPixel, double xmin, double ymin, double ymax )
|
||||
{
|
||||
double oldMUPP = mMapUnitsPerPixel;
|
||||
double oldXMin = xMin;
|
||||
double oldYMin = yMin;
|
||||
double oldHeight = mHeight;
|
||||
double oldXCenter = xCenter;
|
||||
double oldYCenter = yCenter;
|
||||
double oldRotation = mRotation;
|
||||
|
||||
mMapUnitsPerPixel = mapUnitsPerPixel;
|
||||
xMin = xmin;
|
||||
yMin = ymin;
|
||||
@ -186,7 +232,17 @@ void QgsMapToPixel::setParameters( double mapUnitsPerPixel, double xmin, double
|
||||
xCenter = xmin + mWidth * mMapUnitsPerPixel / 2.0;
|
||||
yCenter = ymin + mHeight * mMapUnitsPerPixel / 2.0;
|
||||
mRotation = 0.0;
|
||||
updateMatrix();
|
||||
|
||||
if ( !updateMatrix() )
|
||||
{
|
||||
mMapUnitsPerPixel = oldMUPP;
|
||||
xMin = oldXMin;
|
||||
yMin = oldYMin;
|
||||
mHeight = oldHeight;
|
||||
xCenter = oldXCenter;
|
||||
yCenter = oldYCenter;
|
||||
mRotation = oldRotation;
|
||||
}
|
||||
}
|
||||
|
||||
void QgsMapToPixel::setParameters( double mapUnitsPerPixel,
|
||||
@ -196,6 +252,15 @@ void QgsMapToPixel::setParameters( double mapUnitsPerPixel,
|
||||
int height,
|
||||
double rotation )
|
||||
{
|
||||
double oldMUPP = mMapUnitsPerPixel;
|
||||
double oldXCenter = xCenter;
|
||||
double oldYCenter = yCenter;
|
||||
double oldWidth = mWidth;
|
||||
double oldHeight = mHeight;
|
||||
double oldRotation = mRotation;
|
||||
double oldXMin = xMin;
|
||||
double oldYMin = yMin;
|
||||
|
||||
mMapUnitsPerPixel = mapUnitsPerPixel;
|
||||
xCenter = xc;
|
||||
yCenter = yc;
|
||||
@ -204,7 +269,18 @@ void QgsMapToPixel::setParameters( double mapUnitsPerPixel,
|
||||
mRotation = rotation;
|
||||
xMin = xc - ( mWidth * mMapUnitsPerPixel / 2.0 );
|
||||
yMin = yc - ( mHeight * mMapUnitsPerPixel / 2.0 );
|
||||
updateMatrix();
|
||||
|
||||
if ( !updateMatrix() )
|
||||
{
|
||||
mMapUnitsPerPixel = oldMUPP;
|
||||
xCenter = oldXCenter;
|
||||
yCenter = oldYCenter;
|
||||
mWidth = oldWidth;
|
||||
mHeight = oldHeight;
|
||||
mRotation = oldRotation;
|
||||
xMin = oldXMin;
|
||||
yMin = oldYMin;
|
||||
}
|
||||
}
|
||||
|
||||
QString QgsMapToPixel::showParameters() const
|
||||
@ -250,6 +326,11 @@ void QgsMapToPixel::transformInPlace( qreal &x, qreal &y ) const
|
||||
|
||||
QTransform QgsMapToPixel::transform() const
|
||||
{
|
||||
// NOTE: operations are done in the reverse order in which
|
||||
// they are configured, so translation to geographical
|
||||
// center happens first, then scaling, then rotation
|
||||
// and finally translation to output viewport center
|
||||
|
||||
double rotation = mapRotation();
|
||||
if ( qgsDoubleNear( rotation, 0.0 ) )
|
||||
{
|
||||
@ -257,11 +338,13 @@ QTransform QgsMapToPixel::transform() const
|
||||
return QTransform::fromScale( 1.0 / mMapUnitsPerPixel, -1.0 / mMapUnitsPerPixel )
|
||||
.translate( -xMin, - ( yMin + mHeight * mMapUnitsPerPixel ) );
|
||||
}
|
||||
|
||||
double cy = mapHeight() / 2.0;
|
||||
double cx = mapWidth() / 2.0;
|
||||
return QTransform::fromTranslate( cx, cy )
|
||||
.rotate( rotation )
|
||||
.scale( 1 / mMapUnitsPerPixel, -1 / mMapUnitsPerPixel )
|
||||
.translate( -xCenter, -yCenter );
|
||||
else
|
||||
{
|
||||
double cy = mapHeight() / 2.0;
|
||||
double cx = mapWidth() / 2.0;
|
||||
return QTransform::fromTranslate( cx, cy )
|
||||
.rotate( rotation )
|
||||
.scale( 1 / mMapUnitsPerPixel, -1 / mMapUnitsPerPixel )
|
||||
.translate( -xCenter, -yCenter );
|
||||
}
|
||||
}
|
||||
|
@ -226,7 +226,7 @@ class CORE_EXPORT QgsMapToPixel
|
||||
double yMin; //!< @deprecated in 2.8
|
||||
QTransform mMatrix;
|
||||
|
||||
void updateMatrix();
|
||||
bool updateMatrix();
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user