Skip to content

Commit a3d6227

Browse files
committedMay 15, 2016
Avoid detaching temporary containers
1 parent e25ffc4 commit a3d6227

File tree

8 files changed

+39
-37
lines changed

8 files changed

+39
-37
lines changed
 

‎src/core/qgsvectorfilewriter.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ void QgsVectorFileWriter::init( QString vectorFileName,
189189
OGRSFDriverH poDriver;
190190
QgsApplication::registerOgrDrivers();
191191

192-
poDriver = OGRGetDriverByName( mOgrDriverName.toLocal8Bit().data() );
192+
poDriver = OGRGetDriverByName( mOgrDriverName.toLocal8Bit().constData() );
193193

194194
if ( !poDriver )
195195
{
@@ -284,7 +284,7 @@ void QgsVectorFileWriter::init( QString vectorFileName,
284284
options = new char *[ datasourceOptions.size()+1 ];
285285
for ( int i = 0; i < datasourceOptions.size(); i++ )
286286
{
287-
options[i] = CPLStrdup( datasourceOptions[i].toLocal8Bit().data() );
287+
options[i] = CPLStrdup( datasourceOptions[i].toLocal8Bit().constData() );
288288
}
289289
options[ datasourceOptions.size()] = nullptr;
290290
}
@@ -332,7 +332,7 @@ void QgsVectorFileWriter::init( QString vectorFileName,
332332
{
333333
QString srsWkt = srs->toWkt();
334334
QgsDebugMsg( "WKT to save as is " + srsWkt );
335-
mOgrRef = OSRNewSpatialReference( srsWkt.toLocal8Bit().data() );
335+
mOgrRef = OSRNewSpatialReference( srsWkt.toLocal8Bit().constData() );
336336
}
337337

338338
// datasource created, now create the output layer
@@ -351,7 +351,7 @@ void QgsVectorFileWriter::init( QString vectorFileName,
351351
options = new char *[ layerOptions.size()+1 ];
352352
for ( int i = 0; i < layerOptions.size(); i++ )
353353
{
354-
options[i] = CPLStrdup( layerOptions[i].toLocal8Bit().data() );
354+
options[i] = CPLStrdup( layerOptions[i].toLocal8Bit().constData() );
355355
}
356356
options[ layerOptions.size()] = nullptr;
357357
}
@@ -384,7 +384,7 @@ void QgsVectorFileWriter::init( QString vectorFileName,
384384
if ( prjFile.open( QIODevice::WriteOnly ) )
385385
{
386386
QTextStream prjStream( &prjFile );
387-
prjStream << srs->toWkt().toLocal8Bit().data() << endl;
387+
prjStream << srs->toWkt().toLocal8Bit().constData() << endl;
388388
prjFile.close();
389389
}
390390
else
@@ -1827,15 +1827,15 @@ bool QgsVectorFileWriter::addFeature( QgsFeature& feature, QgsFeatureRendererV2*
18271827
}
18281828
else if ( mSymbologyExport == SymbolLayerSymbology )
18291829
{
1830-
OGR_F_SetStyleString( poFeature, currentStyle.toLocal8Bit().data() );
1830+
OGR_F_SetStyleString( poFeature, currentStyle.toLocal8Bit().constData() );
18311831
if ( !writeFeature( mLayer, poFeature ) )
18321832
{
18331833
return false;
18341834
}
18351835
}
18361836
}
18371837
}
1838-
OGR_F_SetStyleString( poFeature, styleString.toLocal8Bit().data() );
1838+
OGR_F_SetStyleString( poFeature, styleString.toLocal8Bit().constData() );
18391839
}
18401840

18411841
if ( mSymbologyExport == NoSymbology || mSymbologyExport == FeatureSymbology )
@@ -1899,7 +1899,7 @@ OGRFeatureH QgsVectorFileWriter::createFeature( QgsFeature& feature )
18991899
OGR_F_SetFieldInteger64( poFeature, ogrField, attrValue.toLongLong() );
19001900
break;
19011901
case QVariant::String:
1902-
OGR_F_SetFieldString( poFeature, ogrField, mCodec->fromUnicode( attrValue.toString() ).data() );
1902+
OGR_F_SetFieldString( poFeature, ogrField, mCodec->fromUnicode( attrValue.toString() ).constData() );
19031903
break;
19041904
#else
19051905
case QVariant::Int:
@@ -1909,7 +1909,7 @@ OGRFeatureH QgsVectorFileWriter::createFeature( QgsFeature& feature )
19091909
case QVariant::LongLong:
19101910
case QVariant::UInt:
19111911
case QVariant::ULongLong:
1912-
OGR_F_SetFieldString( poFeature, ogrField, mCodec->fromUnicode( attrValue.toString() ).data() );
1912+
OGR_F_SetFieldString( poFeature, ogrField, mCodec->fromUnicode( attrValue.toString() ).constData() );
19131913
break;
19141914
#endif
19151915
case QVariant::Double:
@@ -1925,7 +1925,7 @@ OGRFeatureH QgsVectorFileWriter::createFeature( QgsFeature& feature )
19251925
case QVariant::DateTime:
19261926
if ( mOgrDriverName == "ESRI Shapefile" )
19271927
{
1928-
OGR_F_SetFieldString( poFeature, ogrField, mCodec->fromUnicode( attrValue.toDateTime().toString( "yyyy/MM/dd hh:mm:ss.zzz" ) ).data() );
1928+
OGR_F_SetFieldString( poFeature, ogrField, mCodec->fromUnicode( attrValue.toDateTime().toString( "yyyy/MM/dd hh:mm:ss.zzz" ) ).constData() );
19291929
}
19301930
else
19311931
{
@@ -1942,7 +1942,7 @@ OGRFeatureH QgsVectorFileWriter::createFeature( QgsFeature& feature )
19421942
case QVariant::Time:
19431943
if ( mOgrDriverName == "ESRI Shapefile" )
19441944
{
1945-
OGR_F_SetFieldString( poFeature, ogrField, mCodec->fromUnicode( attrValue.toString() ).data() );
1945+
OGR_F_SetFieldString( poFeature, ogrField, mCodec->fromUnicode( attrValue.toString() ).constData() );
19461946
}
19471947
else
19481948
{
@@ -2517,11 +2517,11 @@ QMap<QString, QString> QgsVectorFileWriter::ogrDriverList()
25172517
// -> test if creation failes
25182518
QString option = "SPATIALITE=YES";
25192519
char **options = new char *[2];
2520-
options[0] = CPLStrdup( option.toLocal8Bit().data() );
2520+
options[0] = CPLStrdup( option.toLocal8Bit().constData() );
25212521
options[1] = nullptr;
25222522
OGRSFDriverH poDriver;
25232523
QgsApplication::registerOgrDrivers();
2524-
poDriver = OGRGetDriverByName( drvName.toLocal8Bit().data() );
2524+
poDriver = OGRGetDriverByName( drvName.toLocal8Bit().constData() );
25252525
if ( poDriver )
25262526
{
25272527
OGRDataSourceH ds = OGR_Dr_CreateDataSource( poDriver, TO8F( QString( "/vsimem/spatialitetest.sqlite" ) ), options );
@@ -2972,7 +2972,7 @@ QgsVectorFileWriter::WriterError QgsVectorFileWriter::exportFeaturesSymbolLevels
29722972
QString styleString = levelIt.key()->symbolLayer( llayer )->ogrFeatureStyle( mmsf, musf );
29732973
if ( !styleString.isEmpty() )
29742974
{
2975-
OGR_F_SetStyleString( ogrFeature, styleString.toLocal8Bit().data() );
2975+
OGR_F_SetStyleString( ogrFeature, styleString.toLocal8Bit().constData() );
29762976
if ( !writeFeature( mLayer, ogrFeature ) )
29772977
{
29782978
++nErrors;

‎src/core/symbology-ng/qgsarrowsymbollayer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ QPolygonF curvedArrow( QPointF po, QPointF pm, QPointF pd, qreal startWidth, qre
484484
path.lineTo( circlePoint( circleCenter, circleRadius + direction * width / 2, angle_o + headAngle ) );
485485
}
486486

487-
return path.toSubpathPolygons()[0];
487+
return path.toSubpathPolygons().at( 0 );
488488
}
489489

490490
void QgsArrowSymbolLayer::_resolveDataDefined( QgsSymbolV2RenderContext& context )

‎src/gui/attributetable/qgsattributetableview.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ QWidget* QgsAttributeTableView::createActionWidget( QgsFeatureId fid )
192192
}
193193

194194
if ( toolButton && !toolButton->actions().isEmpty() && actions->defaultAction() == -1 )
195-
toolButton->setDefaultAction( toolButton->actions().first() );
195+
toolButton->setDefaultAction( toolButton->actions().at( 0 ) );
196196

197197
return container;
198198
}

‎src/plugins/topology/checkDock.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ void checkDock::deleteErrors()
150150

151151
void checkDock::parseErrorListByLayer( const QString& layerId )
152152
{
153-
QgsVectorLayer *layer = qobject_cast<QgsVectorLayer*>( mLayerRegistry->mapLayers()[layerId] );
153+
QgsVectorLayer *layer = qobject_cast<QgsVectorLayer*>( mLayerRegistry->mapLayer( layerId ) );
154154
QList<TopolError*>::Iterator it = mErrorList.begin();
155155

156156
while ( it != mErrorList.end() )
@@ -334,11 +334,11 @@ void checkDock::runTests( ValidateType type )
334334
return;
335335
}
336336

337-
QgsVectorLayer* layer1 = ( QgsVectorLayer* )mLayerRegistry->mapLayers()[layer1Str];
337+
QgsVectorLayer* layer1 = ( QgsVectorLayer* )mLayerRegistry->mapLayer( layer1Str );
338338
QgsVectorLayer* layer2 = nullptr;
339339

340340
if (( QgsVectorLayer* )mLayerRegistry->mapLayers().contains( layer2Str ) )
341-
layer2 = ( QgsVectorLayer* )mLayerRegistry->mapLayers()[layer2Str];
341+
layer2 = ( QgsVectorLayer* )mLayerRegistry->mapLayer( layer2Str );
342342

343343
QProgressDialog progress( testName, tr( "Abort" ), 0, layer1->featureCount(), this );
344344
progress.setWindowModality( Qt::WindowModal );

‎src/plugins/topology/rulesDialog.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ void rulesDialog::readTest( int index, QgsMapLayerRegistry* layerRegistry )
9494
if ( !( QgsVectorLayer* )layerRegistry->mapLayers().contains( layer1Id ) )
9595
return;
9696

97-
l1 = ( QgsVectorLayer* )layerRegistry->mapLayers()[layer1Id];
97+
l1 = ( QgsVectorLayer* )layerRegistry->mapLayer( layer1Id );
9898
if ( !l1 )
9999
return;
100100

@@ -108,7 +108,7 @@ void rulesDialog::readTest( int index, QgsMapLayerRegistry* layerRegistry )
108108
return;
109109
else
110110
{
111-
l2 = ( QgsVectorLayer* )layerRegistry->mapLayers()[layer2Id];
111+
l2 = ( QgsVectorLayer* )layerRegistry->mapLayer( layer2Id );
112112
layer2Name = l2->name();
113113
}
114114
}
@@ -175,7 +175,7 @@ void rulesDialog::showControls( const QString& testName )
175175
mLayer2Box->setVisible( true );
176176
for ( int i = 0; i < layerList.count(); ++i )
177177
{
178-
QgsVectorLayer* v1 = ( QgsVectorLayer* )layerRegistry->mapLayers()[layerList[i]];
178+
QgsVectorLayer* v1 = ( QgsVectorLayer* )layerRegistry->mapLayer( layerList[i] );
179179

180180
if ( !v1 )
181181
{
@@ -319,7 +319,7 @@ void rulesDialog::updateRuleItems( const QString &layerName )
319319
QString layerId = mLayer1Box->itemData( mLayer1Box->currentIndex() ).toString();
320320

321321
QgsMapLayerRegistry* layerRegistry = QgsMapLayerRegistry::instance();
322-
QgsVectorLayer* vlayer = ( QgsVectorLayer* )layerRegistry->mapLayers()[layerId];
322+
QgsVectorLayer* vlayer = ( QgsVectorLayer* )layerRegistry->mapLayer( layerId );
323323

324324
if ( !vlayer )
325325
{
@@ -353,7 +353,7 @@ void rulesDialog::initGui()
353353
mLayer1Box->blockSignals( true );
354354
for ( int i = 0; i < layerList.size(); ++i )
355355
{
356-
QgsVectorLayer* v1 = ( QgsVectorLayer* )layerRegistry->mapLayers()[layerList[i]];
356+
QgsVectorLayer* v1 = ( QgsVectorLayer* )layerRegistry->mapLayer( layerList[i] );
357357
qDebug() << "layerid = " + layerList[i];
358358

359359
// add layer name to the layer combo boxes

‎src/plugins/topology/topolError.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ bool TopolError::fixSnap()
9090
const QgsGeometry* ge = f1.constGeometry();
9191

9292
QgsPolyline line = ge->asPolyline();
93-
line.last() = mConflict->asPolyline().last();
93+
QgsPolyline conflictLine = mConflict->asPolyline();
94+
line.last() = conflictLine.last();
9495

9596
QgsGeometry* newG = QgsGeometry::fromPolyline( line );
9697
bool ret = fl.layer->changeGeometry( f1.id(), newG );

‎src/plugins/topology/topolTest.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1256,8 +1256,9 @@ ErrorList topolTest::checkPointCoveredByLineEnds( double tolerance, QgsVectorLay
12561256
QgsMessageLog::logMessage( tr( "Second geometry missing or GEOS import failed." ), tr( "Topology plugin" ) );
12571257
continue;
12581258
}
1259-
QgsGeometry* startPoint = QgsGeometry::fromPoint( g2->asPolyline().at( 0 ) );
1260-
QgsGeometry* endPoint = QgsGeometry::fromPoint( g2->asPolyline().last() );
1259+
QgsPolyline g2Line = g2->asPolyline();
1260+
QgsGeometry* startPoint = QgsGeometry::fromPoint( g2Line.at( 0 ) );
1261+
QgsGeometry* endPoint = QgsGeometry::fromPoint( g2Line.last() );
12611262
touched = g1->intersects( startPoint ) || g1->intersects( endPoint );
12621263
delete startPoint;
12631264
delete endPoint;
@@ -1322,8 +1323,9 @@ ErrorList topolTest::checkyLineEndsCoveredByPoints( double tolerance, QgsVectorL
13221323
break;
13231324
QgsGeometry* g1 = it->feature.geometry();
13241325

1325-
QgsGeometry* startPoint = QgsGeometry::fromPoint( g1->asPolyline().at( 0 ) );
1326-
QgsGeometry* endPoint = QgsGeometry::fromPoint( g1->asPolyline().last() );
1326+
QgsPolyline g1Polyline = g1->asPolyline();
1327+
QgsGeometry* startPoint = QgsGeometry::fromPoint( g1Polyline.at( 0 ) );
1328+
QgsGeometry* endPoint = QgsGeometry::fromPoint( g1Polyline.last() );
13271329

13281330
QgsRectangle bb = g1->boundingBox();
13291331
QList<QgsFeatureId> crossingIds;
@@ -1680,7 +1682,6 @@ ErrorList topolTest::runTest( const QString& testName, QgsVectorLayer* layer1, Q
16801682
return errors;
16811683
}
16821684

1683-
QString secondLayerId;
16841685
mFeatureList1.clear();
16851686
mFeatureMap2.clear();
16861687

@@ -1705,8 +1706,6 @@ ErrorList topolTest::runTest( const QString& testName, QgsVectorLayer* layer1, Q
17051706
fillFeatureList( layer1, extent );
17061707
//fillFeatureMap( layer1, extent );
17071708

1708-
QString secondLayerId = layer2->id();
1709-
17101709
if ( !mLayerIndexes.contains( layer2->id() ) )
17111710
{
17121711
mLayerIndexes[layer2->id()] = createIndex( layer2, extent );

‎tests/src/core/testqgsgml.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,13 @@ void TestQgsGML::testFromByteArray()
118118
QgsGml gmlParser( "mytypename", "mygeom", fields );
119119
QGis::WkbType wkbType;
120120
QCOMPARE( gmlParser.getFeatures( data1.toAscii(), &wkbType ), 0 );
121-
QCOMPARE( gmlParser.featuresMap().size(), 1 );
122-
QVERIFY( gmlParser.featuresMap().find( 0 ) != gmlParser.featuresMap().end() );
123-
QCOMPARE( gmlParser.featuresMap()[0]->attributes().size(), 1 );
124-
QVERIFY( gmlParser.idsMap().find( 0 ) != gmlParser.idsMap().end() );
125-
QCOMPARE( gmlParser.idsMap()[0], QString( "mytypename.1" ) );
121+
QMap<QgsFeatureId, QgsFeature* > featureMaps = gmlParser.featuresMap();
122+
QCOMPARE( featureMaps.size(), 1 );
123+
QVERIFY( featureMaps.constFind( 0 ) != featureMaps.constEnd() );
124+
QCOMPARE( featureMaps[ 0 ]->attributes().size(), 1 );
125+
QMap<QgsFeatureId, QString > idsMap = gmlParser.idsMap();
126+
QVERIFY( idsMap.constFind( 0 ) != idsMap.constEnd() );
127+
QCOMPARE( idsMap[ 0 ], QString( "mytypename.1" ) );
126128
}
127129

128130
void TestQgsGML::testStreamingParser()

0 commit comments

Comments
 (0)
Please sign in to comment.