Skip to content
Permalink
Browse files
invalidate map settings when ...
parameters of QgsMapToPixel leads to an invalid transform
  • Loading branch information
vcloarec authored and nyalldawson committed May 31, 2021
1 parent 8ff0efd commit 09b5ba4e2d5845f5d4d7965d016da0bb36946b9f
@@ -181,9 +181,14 @@ Set parameters for use in transforming coordinates
:param heightPixels: Output height, in pixels
:param rotation: clockwise rotation in degrees

.. note::

if parameters leads to a non valid transform, parameters are not changed

.. versionadded:: 2.8
%End


QString showParameters() const;
%Docstring
String representation of the parameters used in the transform
@@ -194,12 +194,16 @@ void QgsMapSettings::updateDerived()
mScaleCalculator.setDpi( mDpi * mDevicePixelRatio );
mScale = mScaleCalculator.calculate( mVisibleExtent, mSize.width() );

mMapToPixel.setParameters( mapUnitsPerPixel(),
visibleExtent().center().x(),
visibleExtent().center().y(),
outputSize().width(),
outputSize().height(),
mRotation );
bool ok = true;
mMapToPixel.setParameters(
mapUnitsPerPixel(),
visibleExtent().center().x(),
visibleExtent().center().y(),
outputSize().width(),
outputSize().height(),
mRotation, &ok );

mValid = ok;

#if 1 // set visible extent taking rotation in consideration
if ( mRotation )
@@ -228,7 +232,6 @@ void QgsMapSettings::updateDerived()
QgsDebugMsgLevel( QStringLiteral( "Visible Extent: %1" ).arg( mVisibleExtent.asWktCoordinates() ), 5 );
QgsDebugMsgLevel( QStringLiteral( "Magnification factor: %1" ).arg( mMagnificationFactor ), 5 );

mValid = true;
}


@@ -118,7 +118,8 @@ void QgsMapToPixel::setParameters( double mapUnitsPerPixel,
double yc,
int width,
int height,
double rotation )
double rotation,
bool *ok )
{
double oldMUPP = mMapUnitsPerPixel;
double oldXCenter = mXCenter;
@@ -148,9 +149,25 @@ void QgsMapToPixel::setParameters( double mapUnitsPerPixel,
mRotation = oldRotation;
mXMin = oldXMin;
mYMin = oldYMin;
*ok = false;
}
else
{
*ok = true;
}
}

void QgsMapToPixel::setParameters( double mapUnitsPerPixel,
double xc,
double yc,
int width,
int height,
double rotation )
{
bool ok;
setParameters( mapUnitsPerPixel, xc, yc, width, height, rotation, &ok );
}

QString QgsMapToPixel::showParameters() const
{
QString rep;
@@ -185,3 +202,4 @@ QTransform QgsMapToPixel::transform() const
.translate( -mXCenter, -mYCenter );
}
}

@@ -237,10 +237,26 @@ class CORE_EXPORT QgsMapToPixel
* \param widthPixels Output width, in pixels
* \param heightPixels Output height, in pixels
* \param rotation clockwise rotation in degrees
*
* \note if parameters leads to a non valid transform, parameters are not changed
* \since QGIS 2.8
*/
void setParameters( double mapUnitsPerPixel, double centerX, double centerY, int widthPixels, int heightPixels, double rotation );

/**
* Set parameters for use in transforming coordinates
* \param mapUnitsPerPixel Map units per pixel
* \param centerX X coordinate of map center, in geographical units
* \param centerY Y coordinate of map center, in geographical units
* \param widthPixels Output width, in pixels
* \param heightPixels Output height, in pixels
* \param rotation clockwise rotation in degrees
* \param ok will be set to true if parameters leads to a valid transform, otherwise parameters are not changed and ok will be set to false
*
* \since QGIS 3.20
*/
void setParameters( double mapUnitsPerPixel, double centerX, double centerY, int widthPixels, int heightPixels, double rotation, bool *ok ) SIP_SKIP;

//! String representation of the parameters used in the transform
QString showParameters() const;

0 comments on commit 09b5ba4

Please sign in to comment.