Skip to content
Permalink
Browse files

More clazy optimisations

(cherry picked from commit d4cf8cf)
  • Loading branch information
nyalldawson committed Oct 29, 2018
1 parent 2d7b4ce commit 9094b83f6152bde6bfe198ee09ef98d9b993ad43
@@ -168,7 +168,7 @@ void QgsCameraController::setCamera( Qt3DRender::QCamera *camera )
emit cameraChanged();
}

void QgsCameraController::setViewport( const QRect &viewport )
void QgsCameraController::setViewport( QRect viewport )
{
if ( mViewport == viewport )
return;
@@ -178,7 +178,7 @@ void QgsCameraController::setViewport( const QRect &viewport )
}


static QVector3D unproject( const QVector3D &v, const QMatrix4x4 &modelView, const QMatrix4x4 &projection, const QRect &viewport )
static QVector3D unproject( QVector3D v, const QMatrix4x4 &modelView, const QMatrix4x4 &projection, QRect viewport )
{
// Reimplementation of QVector3D::unproject() - see qtbase/src/gui/math3d/qvector3d.cpp
// The only difference is that the original implementation uses tolerance 1e-5
@@ -208,7 +208,7 @@ float find_x_on_line( float x0, float y0, float x1, float y1, float y )
return x0 + k * d_x;
}

QPointF screen_point_to_point_on_plane( const QPointF &pt, const QRect &viewport, Qt3DRender::QCamera *camera, float y )
QPointF screen_point_to_point_on_plane( QPointF pt, QRect viewport, Qt3DRender::QCamera *camera, float y )
{
// get two points of the ray
QVector3D l0 = unproject( QVector3D( pt.x(), viewport.height() - pt.y(), 0 ), camera->viewMatrix(), camera->projectionMatrix(), viewport );
@@ -432,7 +432,7 @@ void QgsCameraController::setCameraPose( const QgsCameraPose &camPose )

QDomElement QgsCameraController::writeXml( QDomDocument &doc ) const
{
QDomElement elemCamera = doc.createElement( "camera" );
QDomElement elemCamera = doc.createElement( QStringLiteral( "camera" ) );
elemCamera.setAttribute( QStringLiteral( "x" ), mCameraPose.centerPoint().x() );
elemCamera.setAttribute( QStringLiteral( "y" ), mCameraPose.centerPoint().z() );
elemCamera.setAttribute( QStringLiteral( "elev" ), mCameraPose.centerPoint().y() );
@@ -60,7 +60,7 @@ class _3D_EXPORT QgsCameraController : public Qt3DCore::QEntity
//! Assigns camera that should be controlled by this class. Called internally from 3D scene.
void setCamera( Qt3DRender::QCamera *camera );
//! Sets viewport rectangle. Called internally from 3D canvas. Allows conversion of mouse coordinates.
void setViewport( const QRect &viewport );
void setViewport( QRect viewport );
//! Called internally from 3D scene when a new frame is generated. Updates camera according to keyboard/mouse input
void frameTriggered( float dt );

@@ -113,8 +113,8 @@ void QgsFlatTerrainGenerator::writeXml( QDomElement &elem ) const
QDomElement elemExtent = elem.ownerDocument().createElement( QStringLiteral( "extent" ) );
elemExtent.setAttribute( QStringLiteral( "xmin" ), QString::number( r.xMinimum() ) );
elemExtent.setAttribute( QStringLiteral( "xmax" ), QString::number( r.xMaximum() ) );
elemExtent.setAttribute( "ymin", QString::number( r.yMinimum() ) );
elemExtent.setAttribute( "ymax", QString::number( r.yMaximum() ) );
elemExtent.setAttribute( QStringLiteral( "ymin" ), QString::number( r.yMinimum() ) );
elemExtent.setAttribute( QStringLiteral( "ymax" ), QString::number( r.yMaximum() ) );

// crs is not read/written - it should be the same as destination crs of the map
}
@@ -124,8 +124,8 @@ void QgsFlatTerrainGenerator::readXml( const QDomElement &elem )
QDomElement elemExtent = elem.firstChildElement( QStringLiteral( "extent" ) );
double xmin = elemExtent.attribute( QStringLiteral( "xmin" ) ).toDouble();
double xmax = elemExtent.attribute( QStringLiteral( "xmax" ) ).toDouble();
double ymin = elemExtent.attribute( "ymin" ).toDouble();
double ymax = elemExtent.attribute( "ymax" ).toDouble();
double ymin = elemExtent.attribute( QStringLiteral( "ymin" ) ).toDouble();
double ymax = elemExtent.attribute( QStringLiteral( "ymax" ) ).toDouble();

setExtent( QgsRectangle( xmin, ymin, xmax, ymax ) );

@@ -384,6 +384,7 @@ void QgsVectorLayerDirector::makeGraph( QgsGraphBuilderInterface *builder, const
{
double distance = builder->distanceArea()->measureLine( arcPt1, arcPt2 );
QVector< QVariant > prop;
prop.reserve( mStrategies.size() );
for ( QgsNetworkStrategy *strategy : mStrategies )
{
prop.push_back( strategy->cost( distance, feature ) );
@@ -149,6 +149,7 @@ QgsFeatureList QgsAddIncrementalFieldAlgorithm::processFeature( const QgsFeature
else
{
QgsAttributes groupAttributes;
groupAttributes.reserve( mGroupedFields.size() );
for ( int index : qgis::as_const( mGroupedFields ) )
{
groupAttributes << f.attribute( index );
@@ -99,6 +99,7 @@ QgsFeatureList QgsCentroidAlgorithm::processFeature( const QgsFeature &f, QgsPro
{
const QgsGeometryCollection *geomCollection = static_cast<const QgsGeometryCollection *>( geom.constGet() );

list.reserve( geomCollection->partCount() );
for ( int i = 0; i < geomCollection->partCount(); ++i )
{
QgsGeometry partGeometry( geomCollection->geometryN( i )->clone() );
@@ -86,6 +86,7 @@ void QgsLocationBasedAlgorithm::process( const QgsProcessingContext &context, Qg
// we actually test the reverse of what the user wants (allowing us
// to prepare geometries and optimise the algorithm)
QList< Predicate > predicates;
predicates.reserve( selectedPredicates.count() );
for ( int i : selectedPredicates )
{
predicates << reversePredicate( static_cast< Predicate >( i ) );
@@ -94,7 +94,7 @@ bool QgsImportPhotosAlgorithm::extractGeoTagFromMetadata( const QVariantMap &met
if ( !ok )
return false;

if ( metadata.value( QStringLiteral( "EXIF_GPSLongitudeRef" ) ).toString().right( 1 ).compare( QLatin1String( "W" ), Qt::CaseInsensitive ) == 0
if ( metadata.value( QStringLiteral( "EXIF_GPSLongitudeRef" ) ).toString().rightRef( 1 ).compare( QLatin1String( "W" ), Qt::CaseInsensitive ) == 0
|| metadata.value( QStringLiteral( "EXIF_GPSLongitudeRef" ) ).toDouble() < 0 )
x = -x;
}
@@ -111,7 +111,7 @@ bool QgsImportPhotosAlgorithm::extractGeoTagFromMetadata( const QVariantMap &met
if ( !ok )
return false;

if ( metadata.value( QStringLiteral( "EXIF_GPSLatitudeRef" ) ).toString().right( 1 ).compare( QLatin1String( "S" ), Qt::CaseInsensitive ) == 0
if ( metadata.value( QStringLiteral( "EXIF_GPSLatitudeRef" ) ).toString().rightRef( 1 ).compare( QLatin1String( "S" ), Qt::CaseInsensitive ) == 0
|| metadata.value( QStringLiteral( "EXIF_GPSLatitudeRef" ) ).toDouble() < 0 )
y = -y;
}
@@ -130,13 +130,15 @@ QVariantMap QgsJoinByAttributeAlgorithm::processAlgorithm( const QVariantMap &pa
if ( fieldsToCopy.empty() )
{
outFields2 = input2->fields();
fields2Indices.reserve( outFields2.count() );
for ( int i = 0; i < outFields2.count(); ++i )
{
fields2Indices << i;
}
}
else
{
fields2Indices.reserve( fieldsToCopy.count() );
for ( const QString &field : fieldsToCopy )
{
int index = input2->fields().lookupField( field );
@@ -111,13 +111,15 @@ QVariantMap QgsJoinWithLinesAlgorithm::processAlgorithm( const QVariantMap &para
if ( hubFieldsToCopy.empty() )
{
hubOutFields = hubSource->fields();
hubFieldIndices.reserve( hubOutFields.count() );
for ( int i = 0; i < hubOutFields.count(); ++i )
{
hubFieldIndices << i;
}
}
else
{
hubFieldIndices.reserve( hubOutFields.count() );
for ( const QString &field : hubFieldsToCopy )
{
int index = hubSource->fields().lookupField( field );
@@ -315,6 +315,7 @@ QVector<QgsReclassifyUtils::RasterClass> QgsReclassifyByTableAlgorithm::createCl

const int rows = table.count() / 3;
QVector< QgsReclassifyUtils::RasterClass > classes;
classes.reserve( rows );
for ( int row = 0; row < rows; ++row )
{
bool ok = false;
@@ -170,7 +170,7 @@ QVariantMap QgsZonalHistogramAlgorithm::processAlgorithm( const QVariantMap &par
QgsFields newFields;
for ( auto it = uniqueValues.constBegin(); it != uniqueValues.constEnd(); ++it )
{
newFields.append( QgsField( QStringLiteral( "%1%2" ).arg( fieldPrefix ).arg( mHasNoDataValue && *it == mNodataValue ? QStringLiteral( "NODATA" ) : QString::number( *it ) ), QVariant::LongLong, QString(), -1, 0 ) );
newFields.append( QgsField( QStringLiteral( "%1%2" ).arg( fieldPrefix, mHasNoDataValue && *it == mNodataValue ? QStringLiteral( "NODATA" ) : QString::number( *it ) ), QVariant::LongLong, QString(), -1, 0 ) );
}
QgsFields fields = QgsProcessingUtils::combineFields( zones->fields(), newFields );

@@ -95,7 +95,7 @@ QgsLayout3DMapWidget::QgsLayout3DMapWidget( QgsLayoutItem3DMap *map3D )

QList<QgsDoubleSpinBox *> lst;
lst << mCenterXSpinBox << mCenterYSpinBox << mCenterZSpinBox << mDistanceToCenterSpinBox << mPitchAngleSpinBox << mHeadingAngleSpinBox;
for ( QgsDoubleSpinBox *spinBox : lst )
for ( QgsDoubleSpinBox *spinBox : qgis::as_const( lst ) )
connect( spinBox, qgis::overload<double>::of( &QgsDoubleSpinBox::valueChanged ), this, &QgsLayout3DMapWidget::updateCameraPose );

updateCameraPoseWidgetsFromItem();
@@ -91,7 +91,7 @@ void QgsLayoutAtlasWidget::mUseAtlasCheckBox_stateChanged( int state )

void QgsLayoutAtlasWidget::changeCoverageLayer( QgsMapLayer *layer )
{
QgsVectorLayer *vl = dynamic_cast<QgsVectorLayer *>( layer );
QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( layer );

mLayout->undoStack()->beginCommand( mAtlas, tr( "Change Atlas Layer" ) );
mLayout->reportContext().setLayer( vl );
@@ -266,7 +266,7 @@ void QgsLayoutAtlasWidget::mAtlasFeatureFilterEdit_editingFinished()

void QgsLayoutAtlasWidget::mAtlasFeatureFilterButton_clicked()
{
QgsVectorLayer *vl = dynamic_cast<QgsVectorLayer *>( mAtlasCoverageLayerComboBox->currentLayer() );
QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( mAtlasCoverageLayerComboBox->currentLayer() );

if ( !vl )
{
@@ -97,7 +97,7 @@ QVariant QgsLayoutAttributeTableColumnModel::data( const QModelIndex &index, int
if ( role == Qt::UserRole )
{
//user role stores reference in column object
return qVariantFromValue( qobject_cast<QObject *>( column ) );
return qVariantFromValue( column );
}

switch ( index.column() )
@@ -76,9 +76,10 @@ int QgsCompoundCurve::dimension() const
QgsCompoundCurve::QgsCompoundCurve( const QgsCompoundCurve &curve ): QgsCurve( curve )
{
mWkbType = curve.wkbType();
mCurves.reserve( curve.mCurves.size() );
for ( const QgsCurve *c : curve.mCurves )
{
mCurves.append( static_cast<QgsCurve *>( c->clone() ) );
mCurves.append( c->clone() );
}
}

@@ -90,7 +91,7 @@ QgsCompoundCurve &QgsCompoundCurve::operator=( const QgsCompoundCurve &curve )
QgsCurve::operator=( curve );
for ( const QgsCurve *c : curve.mCurves )
{
mCurves.append( static_cast<QgsCurve *>( c->clone() ) );
mCurves.append( c->clone() );
}
}
return *this;
@@ -221,6 +222,7 @@ QByteArray QgsCompoundCurve::asWkb() const
{
int binarySize = sizeof( char ) + sizeof( quint32 ) + sizeof( quint32 );
QVector<QByteArray> wkbForCurves;
wkbForCurves.reserve( mCurves.size() );
for ( const QgsCurve *curve : mCurves )
{
QByteArray wkbForCurve = curve->asWkb();
@@ -62,12 +62,12 @@ QgsCurvePolygon::QgsCurvePolygon( const QgsCurvePolygon &p )
mWkbType = p.mWkbType;
if ( p.mExteriorRing )
{
mExteriorRing.reset( static_cast<QgsCurve *>( p.mExteriorRing->clone() ) );
mExteriorRing.reset( p.mExteriorRing->clone() );
}

for ( const QgsCurve *ring : p.mInteriorRings )
{
mInteriorRings.push_back( static_cast<QgsCurve *>( ring->clone() ) );
mInteriorRings.push_back( ring->clone() );
}
}

@@ -79,12 +79,12 @@ QgsCurvePolygon &QgsCurvePolygon::operator=( const QgsCurvePolygon &p )
QgsSurface::operator=( p );
if ( p.mExteriorRing )
{
mExteriorRing.reset( static_cast<QgsCurve *>( p.mExteriorRing->clone() ) );
mExteriorRing.reset( p.mExteriorRing->clone() );
}

for ( const QgsCurve *ring : p.mInteriorRings )
{
mInteriorRings.push_back( static_cast<QgsCurve *>( ring->clone() ) );
mInteriorRings.push_back( ring->clone() );
}
}
return *this;
@@ -282,6 +282,7 @@ QByteArray QgsCurvePolygon::asWkb() const
{
int binarySize = sizeof( char ) + sizeof( quint32 ) + sizeof( quint32 );
QVector<QByteArray> wkbForRings;
wkbForRings.reserve( 1 + mInteriorRings.size() );
if ( mExteriorRing )
{
QByteArray wkb( mExteriorRing->asWkb() );
@@ -580,6 +581,7 @@ QgsPolygon *QgsCurvePolygon::toPolygon( double tolerance, SegmentationToleranceT
poly->setExteriorRing( mExteriorRing->curveToLine( tolerance, toleranceType ) );

QVector<QgsCurve *> rings;
rings.reserve( mInteriorRings.size() );
for ( const QgsCurve *ring : mInteriorRings )
{
rings.push_back( ring->curveToLine( tolerance, toleranceType ) );
@@ -200,6 +200,7 @@ QgsPointSequence QgsEllipse::points( unsigned int segments ) const
double m = mCenter.m();

QVector<double> t;
t.reserve( segments );
double azimuth = std::atan2( quadrant().at( 0 ).y() - mCenter.y(), quadrant().at( 0 ).x() - mCenter.x() );
for ( unsigned int i = 0; i < segments; ++i )
{
@@ -748,6 +748,7 @@ QgsGeometry QgsGeometry::removeInteriorRings( double minimumRingArea ) const
{
const QVector<QgsGeometry> parts = asGeometryCollection();
QVector<QgsGeometry> results;
results.reserve( parts.count() );
for ( const QgsGeometry &part : parts )
{
QgsGeometry result = part.removeInteriorRings( minimumRingArea );
@@ -621,7 +621,7 @@ bool QgsGeometryCollection::fromCollectionWkt( const QString &wkt, const QVector
}
mWkbType = parts.first;

QString defChildWkbType = QStringLiteral( "%1%2%3 " ).arg( defaultChildWkbType, is3D() ? "Z" : "", isMeasure() ? "M" : "" );
QString defChildWkbType = QStringLiteral( "%1%2%3 " ).arg( defaultChildWkbType, is3D() ? QStringLiteral( "Z" ) : QString(), isMeasure() ? QStringLiteral( "M" ) : QString() );

const QStringList blocks = QgsGeometryUtils::wktGetChildBlocks( parts.second, defChildWkbType );
for ( const QString &childWkt : blocks )
@@ -169,6 +169,7 @@ std::unique_ptr<QgsPolygon> QgsGeometryFactory::fromPolygonXY( const QgsPolygonX
std::unique_ptr< QgsPolygon > poly = qgis::make_unique< QgsPolygon >();

QVector<QgsCurve *> holes;
holes.reserve( polygon.size() );
for ( int i = 0; i < polygon.size(); ++i )
{
std::unique_ptr< QgsLineString > l = linestringFromPolyline( polygon.at( i ) );
@@ -1079,7 +1079,7 @@ QString QgsGeometryUtils::pointsToWKT( const QgsPointSequence &points, int preci
return wkt;
}

QDomElement QgsGeometryUtils::pointsToGML2( const QgsPointSequence &points, QDomDocument &doc, int precision, const QString &ns, const QgsAbstractGeometry::AxisOrder &axisOrder )
QDomElement QgsGeometryUtils::pointsToGML2( const QgsPointSequence &points, QDomDocument &doc, int precision, const QString &ns, QgsAbstractGeometry::AxisOrder axisOrder )
{
QDomElement elemCoordinates = doc.createElementNS( ns, QStringLiteral( "coordinates" ) );

@@ -1106,7 +1106,7 @@ QDomElement QgsGeometryUtils::pointsToGML2( const QgsPointSequence &points, QDom
return elemCoordinates;
}

QDomElement QgsGeometryUtils::pointsToGML3( const QgsPointSequence &points, QDomDocument &doc, int precision, const QString &ns, bool is3D, const QgsAbstractGeometry::AxisOrder &axisOrder )
QDomElement QgsGeometryUtils::pointsToGML3( const QgsPointSequence &points, QDomDocument &doc, int precision, const QString &ns, bool is3D, QgsAbstractGeometry::AxisOrder axisOrder )
{
QDomElement elemPosList = doc.createElementNS( ns, QStringLiteral( "posList" ) );
elemPosList.setAttribute( QStringLiteral( "srsDimension" ), is3D ? 3 : 2 );
@@ -372,13 +372,13 @@ class CORE_EXPORT QgsGeometryUtils
* Returns a gml::coordinates DOM element.
* \note not available in Python bindings
*/
static QDomElement pointsToGML2( const QgsPointSequence &points, QDomDocument &doc, int precision, const QString &ns, const QgsAbstractGeometry::AxisOrder &axisOrder = QgsAbstractGeometry::AxisOrder::XY ) SIP_SKIP;
static QDomElement pointsToGML2( const QgsPointSequence &points, QDomDocument &doc, int precision, const QString &ns, QgsAbstractGeometry::AxisOrder axisOrder = QgsAbstractGeometry::AxisOrder::XY ) SIP_SKIP;

/**
* Returns a gml::posList DOM element.
* \note not available in Python bindings
*/
static QDomElement pointsToGML3( const QgsPointSequence &points, QDomDocument &doc, int precision, const QString &ns, bool is3D, const QgsAbstractGeometry::AxisOrder &axisOrder = QgsAbstractGeometry::AxisOrder::XY ) SIP_SKIP;
static QDomElement pointsToGML3( const QgsPointSequence &points, QDomDocument &doc, int precision, const QString &ns, bool is3D, QgsAbstractGeometry::AxisOrder axisOrder = QgsAbstractGeometry::AxisOrder::XY ) SIP_SKIP;

/**
* Returns a geoJSON coordinates string.
@@ -157,7 +157,7 @@ QgsGeometry QgsGeos::geometryFromGeos( GEOSGeometry *geos )
return g;
}

QgsGeometry QgsGeos::geometryFromGeos( geos::unique_ptr geos )
QgsGeometry QgsGeos::geometryFromGeos( const geos::unique_ptr &geos )
{
QgsGeometry g( QgsGeos::fromGeos( geos.get() ) );
return g;
@@ -1187,7 +1187,9 @@ std::unique_ptr<QgsPolygon> QgsGeos::fromGeosPolygon( const GEOSGeometry *geos )
}

QVector<QgsCurve *> interiorRings;
for ( int i = 0; i < GEOSGetNumInteriorRings_r( geosinit.ctxt, geos ); ++i )
const int ringCount = GEOSGetNumInteriorRings_r( geosinit.ctxt, geos );
interiorRings.reserve( ringCount );
for ( int i = 0; i < ringCount; ++i )
{
ring = GEOSGetInteriorRingN_r( geosinit.ctxt, geos, i );
if ( ring )
@@ -120,7 +120,7 @@ class CORE_EXPORT QgsGeos: public QgsGeometryEngine
/**
* Creates a new QgsGeometry object, feeding in a geometry in GEOS format.
*/
static QgsGeometry geometryFromGeos( geos::unique_ptr geos );
static QgsGeometry geometryFromGeos( const geos::unique_ptr &geos );

/**
* Adds a new island polygon to a multipolygon feature
@@ -49,6 +49,7 @@ QgsGeometry QgsInternalGeometryEngine::extrude( double x, double y ) const
const QgsMultiCurve *multiCurve = qgsgeometry_cast< const QgsMultiCurve * >( mGeometry );
if ( multiCurve )
{
linesToProcess.reserve( multiCurve->partCount() );
for ( int i = 0; i < multiCurve->partCount(); ++i )
{
linesToProcess << static_cast<QgsLineString *>( multiCurve->geometryN( i )->clone() );
@@ -920,6 +921,7 @@ QgsGeometry QgsInternalGeometryEngine::variableWidthBuffer( int segments, const
}

QVector<QgsGeometry> bufferedLines;
bufferedLines.reserve( linesToProcess.size() );

for ( std::unique_ptr< QgsLineString > &line : linesToProcess )
{
@@ -466,7 +466,7 @@ QgsLineString *QgsLineString::curveToLine( double tolerance, SegmentationToleran
{
Q_UNUSED( tolerance );
Q_UNUSED( toleranceType );
return static_cast<QgsLineString *>( clone() );
return clone();
}

int QgsLineString::numPoints() const

0 comments on commit 9094b83

Please sign in to comment.
You can’t perform that action at this time.