mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-14 00:07:35 -04:00
QgsExpression::setGeomCalculator now takes a pointer
This allows the calculator to be cleared
This commit is contained in:
parent
cd5f813112
commit
b160f101c2
@ -99,10 +99,11 @@ class QgsExpression
|
||||
* (used by $length, $area and $perimeter functions only). By default, no geometry
|
||||
* calculator is set and all distance and area calculations are performed using simple
|
||||
* cartesian methods (ie no ellipsoidal calculations).
|
||||
* @param calc geometry calculator. Ownership is not transferred. Set to a nullptr to force
|
||||
* cartesian calculations.
|
||||
* @see geomCalculator()
|
||||
*/
|
||||
//TODO QGIS 3.0 change calc to a pointer, so that calculator can be cleared by passing nullptr
|
||||
void setGeomCalculator( const QgsDistanceArea &calc );
|
||||
void setGeomCalculator( const QgsDistanceArea* calc );
|
||||
|
||||
/** Returns the desired distance units for calculations involving geomCalculator(), eg "$length" and "$perimeter".
|
||||
* @note distances are only converted when a geomCalculator() has been set
|
||||
|
@ -443,7 +443,7 @@ void QgsAttributeTableDialog::runFieldCalculation( QgsVectorLayer* layer, const
|
||||
QString error;
|
||||
|
||||
QgsExpression exp( expression );
|
||||
exp.setGeomCalculator( *myDa );
|
||||
exp.setGeomCalculator( myDa );
|
||||
exp.setDistanceUnits( QgsProject::instance()->distanceUnits() );
|
||||
exp.setAreaUnits( QgsProject::instance()->areaUnits() );
|
||||
bool useGeometry = exp.needsGeometry();
|
||||
@ -945,7 +945,7 @@ void QgsAttributeTableDialog::setFilterExpression( const QString& filterString,
|
||||
|
||||
QApplication::setOverrideCursor( Qt::WaitCursor );
|
||||
|
||||
filterExpression.setGeomCalculator( myDa );
|
||||
filterExpression.setGeomCalculator( &myDa );
|
||||
filterExpression.setDistanceUnits( QgsProject::instance()->distanceUnits() );
|
||||
filterExpression.setAreaUnits( QgsProject::instance()->areaUnits() );
|
||||
QgsFeatureRequest request( mMainView->masterModel()->request() );
|
||||
|
@ -164,7 +164,7 @@ void QgsFieldCalculator::accept()
|
||||
|
||||
QString calcString = builder->expressionText();
|
||||
QgsExpression exp( calcString );
|
||||
exp.setGeomCalculator( myDa );
|
||||
exp.setGeomCalculator( &myDa );
|
||||
exp.setDistanceUnits( QgsProject::instance()->distanceUnits() );
|
||||
exp.setAreaUnits( QgsProject::instance()->areaUnits() );
|
||||
|
||||
|
@ -3500,9 +3500,13 @@ void QgsExpression::detach()
|
||||
}
|
||||
}
|
||||
|
||||
void QgsExpression::setGeomCalculator( const QgsDistanceArea &calc )
|
||||
void QgsExpression::setGeomCalculator( const QgsDistanceArea *calc )
|
||||
{
|
||||
d->mCalc = QSharedPointer<QgsDistanceArea>( new QgsDistanceArea( calc ) );
|
||||
detach();
|
||||
if ( calc )
|
||||
d->mCalc = QSharedPointer<QgsDistanceArea>( new QgsDistanceArea( *calc ) );
|
||||
else
|
||||
d->mCalc.clear();
|
||||
}
|
||||
|
||||
bool QgsExpression::prepare( const QgsExpressionContext *context )
|
||||
@ -3633,7 +3637,7 @@ QString QgsExpression::replaceExpressionText( const QString &action, const QgsEx
|
||||
if ( distanceArea )
|
||||
{
|
||||
//if QgsDistanceArea specified for area/distance conversion, use it
|
||||
exp.setGeomCalculator( *distanceArea );
|
||||
exp.setGeomCalculator( distanceArea );
|
||||
}
|
||||
|
||||
QVariant result = exp.evaluate( context );
|
||||
|
@ -219,10 +219,11 @@ class CORE_EXPORT QgsExpression
|
||||
* (used by $length, $area and $perimeter functions only). By default, no geometry
|
||||
* calculator is set and all distance and area calculations are performed using simple
|
||||
* cartesian methods (ie no ellipsoidal calculations).
|
||||
* @param calc geometry calculator. Ownership is not transferred. Set to a nullptr to force
|
||||
* cartesian calculations.
|
||||
* @see geomCalculator()
|
||||
*/
|
||||
//TODO QGIS 3.0 change calc to a pointer, so that calculator can be cleared by passing nullptr
|
||||
void setGeomCalculator( const QgsDistanceArea &calc );
|
||||
void setGeomCalculator( const QgsDistanceArea* calc );
|
||||
|
||||
/** Returns the desired distance units for calculations involving geomCalculator(), eg "$length" and "$perimeter".
|
||||
* @note distances are only converted when a geomCalculator() has been set
|
||||
|
@ -529,7 +529,7 @@ void QgsVectorLayerFeatureIterator::prepareExpression( int fieldIdx )
|
||||
da.setSourceCrs( mSource->mCrsId );
|
||||
da.setEllipsoidalMode( true );
|
||||
da.setEllipsoid( QgsProject::instance()->readEntry( "Measure", "/Ellipsoid", GEO_NONE ) );
|
||||
exp->setGeomCalculator( da );
|
||||
exp->setGeomCalculator( &da );
|
||||
exp->setDistanceUnits( QgsProject::instance()->distanceUnits() );
|
||||
exp->setAreaUnits( QgsProject::instance()->areaUnits() );
|
||||
|
||||
|
@ -540,7 +540,7 @@ void QgsExpressionBuilderWidget::on_txtExpressionString_textChanged()
|
||||
if ( mLayer )
|
||||
{
|
||||
// Only set calculator if we have layer, else use default.
|
||||
exp.setGeomCalculator( mDa );
|
||||
exp.setGeomCalculator( &mDa );
|
||||
|
||||
if ( !mFeature.isValid() )
|
||||
{
|
||||
|
@ -1685,7 +1685,7 @@ class TestQgsExpression: public QObject
|
||||
|
||||
// test area with geomCalculator
|
||||
QgsExpression expArea2( "$area" );
|
||||
expArea2.setGeomCalculator( da );
|
||||
expArea2.setGeomCalculator( &da );
|
||||
vArea = expArea2.evaluate( &context );
|
||||
expected = 1009089817.0;
|
||||
QVERIFY( qgsDoubleNear( vArea.toDouble(), expected, 1.0 ) );
|
||||
@ -1716,7 +1716,7 @@ class TestQgsExpression: public QObject
|
||||
|
||||
// test perimeter with geomCalculator
|
||||
QgsExpression expPerimeter2( "$perimeter" );
|
||||
expPerimeter2.setGeomCalculator( da );
|
||||
expPerimeter2.setGeomCalculator( &da );
|
||||
vPerimeter = expPerimeter2.evaluate( &context );
|
||||
expected = 128289.074;
|
||||
QVERIFY( qgsDoubleNear( vPerimeter.toDouble(), expected, 0.001 ) );
|
||||
@ -1753,7 +1753,7 @@ class TestQgsExpression: public QObject
|
||||
|
||||
// test length with geomCalculator
|
||||
QgsExpression expLength2( "$length" );
|
||||
expLength2.setGeomCalculator( da );
|
||||
expLength2.setGeomCalculator( &da );
|
||||
vLength = expLength2.evaluate( &context );
|
||||
expected = 26932.156;
|
||||
QVERIFY( qgsDoubleNear( vLength.toDouble(), expected, 0.001 ) );
|
||||
|
Loading…
x
Reference in New Issue
Block a user