Skip to content

Commit

Permalink
Avoid detaching temporary containers
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed May 15, 2016
1 parent e25ffc4 commit a3d6227
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 37 deletions.
28 changes: 14 additions & 14 deletions src/core/qgsvectorfilewriter.cpp
Expand Up @@ -189,7 +189,7 @@ void QgsVectorFileWriter::init( QString vectorFileName,
OGRSFDriverH poDriver;
QgsApplication::registerOgrDrivers();

poDriver = OGRGetDriverByName( mOgrDriverName.toLocal8Bit().data() );
poDriver = OGRGetDriverByName( mOgrDriverName.toLocal8Bit().constData() );

if ( !poDriver )
{
Expand Down Expand Up @@ -284,7 +284,7 @@ void QgsVectorFileWriter::init( QString vectorFileName,
options = new char *[ datasourceOptions.size()+1 ];
for ( int i = 0; i < datasourceOptions.size(); i++ )
{
options[i] = CPLStrdup( datasourceOptions[i].toLocal8Bit().data() );
options[i] = CPLStrdup( datasourceOptions[i].toLocal8Bit().constData() );
}
options[ datasourceOptions.size()] = nullptr;
}
Expand Down Expand Up @@ -332,7 +332,7 @@ void QgsVectorFileWriter::init( QString vectorFileName,
{
QString srsWkt = srs->toWkt();
QgsDebugMsg( "WKT to save as is " + srsWkt );
mOgrRef = OSRNewSpatialReference( srsWkt.toLocal8Bit().data() );
mOgrRef = OSRNewSpatialReference( srsWkt.toLocal8Bit().constData() );
}

// datasource created, now create the output layer
Expand All @@ -351,7 +351,7 @@ void QgsVectorFileWriter::init( QString vectorFileName,
options = new char *[ layerOptions.size()+1 ];
for ( int i = 0; i < layerOptions.size(); i++ )
{
options[i] = CPLStrdup( layerOptions[i].toLocal8Bit().data() );
options[i] = CPLStrdup( layerOptions[i].toLocal8Bit().constData() );
}
options[ layerOptions.size()] = nullptr;
}
Expand Down Expand Up @@ -384,7 +384,7 @@ void QgsVectorFileWriter::init( QString vectorFileName,
if ( prjFile.open( QIODevice::WriteOnly ) )
{
QTextStream prjStream( &prjFile );
prjStream << srs->toWkt().toLocal8Bit().data() << endl;
prjStream << srs->toWkt().toLocal8Bit().constData() << endl;
prjFile.close();
}
else
Expand Down Expand Up @@ -1827,15 +1827,15 @@ bool QgsVectorFileWriter::addFeature( QgsFeature& feature, QgsFeatureRendererV2*
}
else if ( mSymbologyExport == SymbolLayerSymbology )
{
OGR_F_SetStyleString( poFeature, currentStyle.toLocal8Bit().data() );
OGR_F_SetStyleString( poFeature, currentStyle.toLocal8Bit().constData() );
if ( !writeFeature( mLayer, poFeature ) )
{
return false;
}
}
}
}
OGR_F_SetStyleString( poFeature, styleString.toLocal8Bit().data() );
OGR_F_SetStyleString( poFeature, styleString.toLocal8Bit().constData() );
}

if ( mSymbologyExport == NoSymbology || mSymbologyExport == FeatureSymbology )
Expand Down Expand Up @@ -1899,7 +1899,7 @@ OGRFeatureH QgsVectorFileWriter::createFeature( QgsFeature& feature )
OGR_F_SetFieldInteger64( poFeature, ogrField, attrValue.toLongLong() );
break;
case QVariant::String:
OGR_F_SetFieldString( poFeature, ogrField, mCodec->fromUnicode( attrValue.toString() ).data() );
OGR_F_SetFieldString( poFeature, ogrField, mCodec->fromUnicode( attrValue.toString() ).constData() );
break;
#else
case QVariant::Int:
Expand All @@ -1909,7 +1909,7 @@ OGRFeatureH QgsVectorFileWriter::createFeature( QgsFeature& feature )
case QVariant::LongLong:
case QVariant::UInt:
case QVariant::ULongLong:
OGR_F_SetFieldString( poFeature, ogrField, mCodec->fromUnicode( attrValue.toString() ).data() );
OGR_F_SetFieldString( poFeature, ogrField, mCodec->fromUnicode( attrValue.toString() ).constData() );
break;
#endif
case QVariant::Double:
Expand All @@ -1925,7 +1925,7 @@ OGRFeatureH QgsVectorFileWriter::createFeature( QgsFeature& feature )
case QVariant::DateTime:
if ( mOgrDriverName == "ESRI Shapefile" )
{
OGR_F_SetFieldString( poFeature, ogrField, mCodec->fromUnicode( attrValue.toDateTime().toString( "yyyy/MM/dd hh:mm:ss.zzz" ) ).data() );
OGR_F_SetFieldString( poFeature, ogrField, mCodec->fromUnicode( attrValue.toDateTime().toString( "yyyy/MM/dd hh:mm:ss.zzz" ) ).constData() );
}
else
{
Expand All @@ -1942,7 +1942,7 @@ OGRFeatureH QgsVectorFileWriter::createFeature( QgsFeature& feature )
case QVariant::Time:
if ( mOgrDriverName == "ESRI Shapefile" )
{
OGR_F_SetFieldString( poFeature, ogrField, mCodec->fromUnicode( attrValue.toString() ).data() );
OGR_F_SetFieldString( poFeature, ogrField, mCodec->fromUnicode( attrValue.toString() ).constData() );
}
else
{
Expand Down Expand Up @@ -2517,11 +2517,11 @@ QMap<QString, QString> QgsVectorFileWriter::ogrDriverList()
// -> test if creation failes
QString option = "SPATIALITE=YES";
char **options = new char *[2];
options[0] = CPLStrdup( option.toLocal8Bit().data() );
options[0] = CPLStrdup( option.toLocal8Bit().constData() );
options[1] = nullptr;
OGRSFDriverH poDriver;
QgsApplication::registerOgrDrivers();
poDriver = OGRGetDriverByName( drvName.toLocal8Bit().data() );
poDriver = OGRGetDriverByName( drvName.toLocal8Bit().constData() );
if ( poDriver )
{
OGRDataSourceH ds = OGR_Dr_CreateDataSource( poDriver, TO8F( QString( "/vsimem/spatialitetest.sqlite" ) ), options );
Expand Down Expand Up @@ -2972,7 +2972,7 @@ QgsVectorFileWriter::WriterError QgsVectorFileWriter::exportFeaturesSymbolLevels
QString styleString = levelIt.key()->symbolLayer( llayer )->ogrFeatureStyle( mmsf, musf );
if ( !styleString.isEmpty() )
{
OGR_F_SetStyleString( ogrFeature, styleString.toLocal8Bit().data() );
OGR_F_SetStyleString( ogrFeature, styleString.toLocal8Bit().constData() );
if ( !writeFeature( mLayer, ogrFeature ) )
{
++nErrors;
Expand Down
2 changes: 1 addition & 1 deletion src/core/symbology-ng/qgsarrowsymbollayer.cpp
Expand Up @@ -484,7 +484,7 @@ QPolygonF curvedArrow( QPointF po, QPointF pm, QPointF pd, qreal startWidth, qre
path.lineTo( circlePoint( circleCenter, circleRadius + direction * width / 2, angle_o + headAngle ) );
}

return path.toSubpathPolygons()[0];
return path.toSubpathPolygons().at( 0 );
}

void QgsArrowSymbolLayer::_resolveDataDefined( QgsSymbolV2RenderContext& context )
Expand Down
2 changes: 1 addition & 1 deletion src/gui/attributetable/qgsattributetableview.cpp
Expand Up @@ -192,7 +192,7 @@ QWidget* QgsAttributeTableView::createActionWidget( QgsFeatureId fid )
}

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

return container;
}
Expand Down
6 changes: 3 additions & 3 deletions src/plugins/topology/checkDock.cpp
Expand Up @@ -150,7 +150,7 @@ void checkDock::deleteErrors()

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

while ( it != mErrorList.end() )
Expand Down Expand Up @@ -334,11 +334,11 @@ void checkDock::runTests( ValidateType type )
return;
}

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

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

QProgressDialog progress( testName, tr( "Abort" ), 0, layer1->featureCount(), this );
progress.setWindowModality( Qt::WindowModal );
Expand Down
10 changes: 5 additions & 5 deletions src/plugins/topology/rulesDialog.cpp
Expand Up @@ -94,7 +94,7 @@ void rulesDialog::readTest( int index, QgsMapLayerRegistry* layerRegistry )
if ( !( QgsVectorLayer* )layerRegistry->mapLayers().contains( layer1Id ) )
return;

l1 = ( QgsVectorLayer* )layerRegistry->mapLayers()[layer1Id];
l1 = ( QgsVectorLayer* )layerRegistry->mapLayer( layer1Id );
if ( !l1 )
return;

Expand All @@ -108,7 +108,7 @@ void rulesDialog::readTest( int index, QgsMapLayerRegistry* layerRegistry )
return;
else
{
l2 = ( QgsVectorLayer* )layerRegistry->mapLayers()[layer2Id];
l2 = ( QgsVectorLayer* )layerRegistry->mapLayer( layer2Id );
layer2Name = l2->name();
}
}
Expand Down Expand Up @@ -175,7 +175,7 @@ void rulesDialog::showControls( const QString& testName )
mLayer2Box->setVisible( true );
for ( int i = 0; i < layerList.count(); ++i )
{
QgsVectorLayer* v1 = ( QgsVectorLayer* )layerRegistry->mapLayers()[layerList[i]];
QgsVectorLayer* v1 = ( QgsVectorLayer* )layerRegistry->mapLayer( layerList[i] );

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

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

if ( !vlayer )
{
Expand Down Expand Up @@ -353,7 +353,7 @@ void rulesDialog::initGui()
mLayer1Box->blockSignals( true );
for ( int i = 0; i < layerList.size(); ++i )
{
QgsVectorLayer* v1 = ( QgsVectorLayer* )layerRegistry->mapLayers()[layerList[i]];
QgsVectorLayer* v1 = ( QgsVectorLayer* )layerRegistry->mapLayer( layerList[i] );
qDebug() << "layerid = " + layerList[i];

// add layer name to the layer combo boxes
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/topology/topolError.cpp
Expand Up @@ -90,7 +90,8 @@ bool TopolError::fixSnap()
const QgsGeometry* ge = f1.constGeometry();

QgsPolyline line = ge->asPolyline();
line.last() = mConflict->asPolyline().last();
QgsPolyline conflictLine = mConflict->asPolyline();
line.last() = conflictLine.last();

QgsGeometry* newG = QgsGeometry::fromPolyline( line );
bool ret = fl.layer->changeGeometry( f1.id(), newG );
Expand Down
13 changes: 6 additions & 7 deletions src/plugins/topology/topolTest.cpp
Expand Up @@ -1256,8 +1256,9 @@ ErrorList topolTest::checkPointCoveredByLineEnds( double tolerance, QgsVectorLay
QgsMessageLog::logMessage( tr( "Second geometry missing or GEOS import failed." ), tr( "Topology plugin" ) );
continue;
}
QgsGeometry* startPoint = QgsGeometry::fromPoint( g2->asPolyline().at( 0 ) );
QgsGeometry* endPoint = QgsGeometry::fromPoint( g2->asPolyline().last() );
QgsPolyline g2Line = g2->asPolyline();
QgsGeometry* startPoint = QgsGeometry::fromPoint( g2Line.at( 0 ) );
QgsGeometry* endPoint = QgsGeometry::fromPoint( g2Line.last() );
touched = g1->intersects( startPoint ) || g1->intersects( endPoint );
delete startPoint;
delete endPoint;
Expand Down Expand Up @@ -1322,8 +1323,9 @@ ErrorList topolTest::checkyLineEndsCoveredByPoints( double tolerance, QgsVectorL
break;
QgsGeometry* g1 = it->feature.geometry();

QgsGeometry* startPoint = QgsGeometry::fromPoint( g1->asPolyline().at( 0 ) );
QgsGeometry* endPoint = QgsGeometry::fromPoint( g1->asPolyline().last() );
QgsPolyline g1Polyline = g1->asPolyline();
QgsGeometry* startPoint = QgsGeometry::fromPoint( g1Polyline.at( 0 ) );
QgsGeometry* endPoint = QgsGeometry::fromPoint( g1Polyline.last() );

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

QString secondLayerId;
mFeatureList1.clear();
mFeatureMap2.clear();

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

QString secondLayerId = layer2->id();

if ( !mLayerIndexes.contains( layer2->id() ) )
{
mLayerIndexes[layer2->id()] = createIndex( layer2, extent );
Expand Down
12 changes: 7 additions & 5 deletions tests/src/core/testqgsgml.cpp
Expand Up @@ -118,11 +118,13 @@ void TestQgsGML::testFromByteArray()
QgsGml gmlParser( "mytypename", "mygeom", fields );
QGis::WkbType wkbType;
QCOMPARE( gmlParser.getFeatures( data1.toAscii(), &wkbType ), 0 );
QCOMPARE( gmlParser.featuresMap().size(), 1 );
QVERIFY( gmlParser.featuresMap().find( 0 ) != gmlParser.featuresMap().end() );
QCOMPARE( gmlParser.featuresMap()[0]->attributes().size(), 1 );
QVERIFY( gmlParser.idsMap().find( 0 ) != gmlParser.idsMap().end() );
QCOMPARE( gmlParser.idsMap()[0], QString( "mytypename.1" ) );
QMap<QgsFeatureId, QgsFeature* > featureMaps = gmlParser.featuresMap();
QCOMPARE( featureMaps.size(), 1 );
QVERIFY( featureMaps.constFind( 0 ) != featureMaps.constEnd() );
QCOMPARE( featureMaps[ 0 ]->attributes().size(), 1 );
QMap<QgsFeatureId, QString > idsMap = gmlParser.idsMap();
QVERIFY( idsMap.constFind( 0 ) != idsMap.constEnd() );
QCOMPARE( idsMap[ 0 ], QString( "mytypename.1" ) );
}

void TestQgsGML::testStreamingParser()
Expand Down

0 comments on commit a3d6227

Please sign in to comment.