Skip to content
Permalink
Browse files
Swap QScopedPointer to std::unique_ptr
Why?
- no benefits to QScopedPointer over std::unique_ptr
- unlike QScopedPointer, std::unique_ptr has no overhead
over regular pointers
- using standard language features makes it more likely that
compilers can optimise this use and static analysers can
correctly handle code using unique_ptrs
- QScopedPointer has an (IMO) uncertain future (given that
Qt is dropping features which have become part of the c++
standard). Better to port now before wider use of QScopedPointer
in the codebase!
  • Loading branch information
nyalldawson committed Feb 7, 2017
1 parent 9475850 commit aed6c735a6db5c2dbad526ae4d1670e8e6d76fe5
Show file tree
Hide file tree
Showing 170 changed files with 680 additions and 659 deletions.
@@ -913,7 +913,7 @@ void QgsComposer::setTitle( const QString& title )
bool QgsComposer::loadFromTemplate( const QDomDocument& templateDoc, bool clearExisting )
{
// provide feedback, since composer will be hidden when loading template (much faster)
QScopedPointer< QDialog > dlg( new QgsBusyIndicatorDialog( tr( "Loading template into composer..." ), this ) );
std::unique_ptr< QDialog > dlg( new QgsBusyIndicatorDialog( tr( "Loading template into composer..." ), this ) );
dlg->setStyleSheet( mQgis->styleSheet() );
dlg->show();

@@ -155,7 +155,7 @@ void QgsDwgImportDialog::on_pbLoadDatabase_clicked()

bool lblVisible = false;

QScopedPointer<QgsVectorLayer> d( new QgsVectorLayer( QString( "%1|layername=drawing" ).arg( leDatabase->text() ), "layers", "ogr", false ) );
std::unique_ptr<QgsVectorLayer> d( new QgsVectorLayer( QString( "%1|layername=drawing" ).arg( leDatabase->text() ), "layers", "ogr", false ) );
if ( d && d->isValid() )
{
int idxPath = d->fields().lookupField( "path" );
@@ -190,7 +190,7 @@ void QgsDwgImportDialog::on_pbLoadDatabase_clicked()

lblMessage->setVisible( lblVisible );

QScopedPointer<QgsVectorLayer> l( new QgsVectorLayer( QString( "%1|layername=layers" ).arg( leDatabase->text() ), "layers", "ogr", false ) );
std::unique_ptr<QgsVectorLayer> l( new QgsVectorLayer( QString( "%1|layername=layers" ).arg( leDatabase->text() ), "layers", "ogr", false ) );
if ( l && l->isValid() )
{
int idxName = l->fields().lookupField( "name" );
@@ -44,6 +44,7 @@
#include <cpl_string.h>
#include <gdal.h>
#include <ogr_srs_api.h>
#include <memory>

#define LOG( x ) { QgsDebugMsg( x ); QgsMessageLog::logMessage( x, QObject::tr( "DWG/DXF import" ) ); }
#define ONCE( x ) { static bool show=true; if( show ) LOG( x ); show=false; }
@@ -614,7 +615,7 @@ bool QgsDwgImporter::import( const QString &drawing, QString &error, bool doExpa
if ( fi.suffix().toLower() == "dxf" )
{
//loads dxf
QScopedPointer<dxfRW> dxf( new dxfRW( drawing.toUtf8() ) );
std::unique_ptr<dxfRW> dxf( new dxfRW( drawing.toUtf8() ) );
if ( !dxf->read( this, false ) )
{
result = DRW::BAD_UNKNOWN;
@@ -623,7 +624,7 @@ bool QgsDwgImporter::import( const QString &drawing, QString &error, bool doExpa
else if ( fi.suffix().toLower() == "dwg" )
{
//loads dwg
QScopedPointer<dwgR> dwg( new dwgR( drawing.toUtf8() ) );
std::unique_ptr<dwgR> dwg( new dwgR( drawing.toUtf8() ) );
if ( !dwg->read( this, false ) )
{
result = dwg->getError();
@@ -1185,12 +1186,12 @@ void QgsDwgImporter::addAppId( const DRW_AppId &data )
bool QgsDwgImporter::createFeature( OGRLayerH layer, OGRFeatureH f, const QgsAbstractGeometry &g0 ) const
{
const QgsAbstractGeometry *g;
QScopedPointer<QgsAbstractGeometry> sg( nullptr );
std::unique_ptr<QgsAbstractGeometry> sg( nullptr );

if ( !mUseCurves && g0.hasCurvedSegments() )
{
sg.reset( g0.segmentize() );
g = sg.data();
g = sg.get();
}
else
{
@@ -449,15 +449,15 @@ void QgisApp::layerTreeViewDoubleClicked( const QModelIndex& index )
if ( !originalSymbol )
return;

QScopedPointer< QgsSymbol > symbol( originalSymbol->clone() );
std::unique_ptr< QgsSymbol > symbol( originalSymbol->clone() );
QgsVectorLayer* vlayer = qobject_cast<QgsVectorLayer*>( node->layerNode()->layer() );
QgsSymbolSelectorDialog dlg( symbol.data(), QgsStyle::defaultStyle(), vlayer, this );
QgsSymbolSelectorDialog dlg( symbol.get(), QgsStyle::defaultStyle(), vlayer, this );
QgsSymbolWidgetContext context;
context.setMapCanvas( mMapCanvas );
dlg.setContext( context );
if ( dlg.exec() )
{
node->setSymbol( symbol.take() );
node->setSymbol( symbol.release() );
}

return;
@@ -6241,7 +6241,7 @@ void QgisApp::saveAsRasterFile()
// TODO: show error dialogs
// TODO: this code should go somewhere else, but probably not into QgsRasterFileWriter
// clone pipe/provider is not really necessary, ready for threads
QScopedPointer<QgsRasterPipe> pipe( nullptr );
std::unique_ptr<QgsRasterPipe> pipe( nullptr );

if ( d.mode() == QgsRasterLayerSaveAsDialog::RawDataMode )
{
@@ -6303,7 +6303,7 @@ void QgisApp::saveAsRasterFile()
fileWriter.setPyramidsFormat( d.pyramidsFormat() );
fileWriter.setPyramidsConfigOptions( d.pyramidsConfigOptions() );

QgsRasterFileWriter::WriterError err = fileWriter.writeRaster( pipe.data(), d.nColumns(), d.nRows(), d.outputRectangle(), d.outputCrs(), &pd );
QgsRasterFileWriter::WriterError err = fileWriter.writeRaster( pipe.get(), d.nColumns(), d.nRows(), d.outputRectangle(), d.outputCrs(), &pd );
if ( err != QgsRasterFileWriter::NoError )
{
QMessageBox::warning( this, tr( "Error" ),
@@ -147,7 +147,7 @@ void QgsAnnotationWidget::updateCenterIcon()
{
return;
}
QIcon icon = QgsSymbolLayerUtils::symbolPreviewIcon( mMarkerSymbol.data(), mMapMarkerButton->iconSize() );
QIcon icon = QgsSymbolLayerUtils::symbolPreviewIcon( mMarkerSymbol.get(), mMapMarkerButton->iconSize() );
mMapMarkerButton->setIcon( icon );
}

@@ -157,7 +157,7 @@ void QgsAnnotationWidget::updateFillIcon()
{
return;
}
QIcon icon = QgsSymbolLayerUtils::symbolPreviewIcon( mFillSymbol.data(), mFrameStyleButton->iconSize() );
QIcon icon = QgsSymbolLayerUtils::symbolPreviewIcon( mFillSymbol.get(), mFrameStyleButton->iconSize() );
mFrameStyleButton->setIcon( icon );
}

@@ -20,6 +20,7 @@

#include "ui_qgsannotationwidgetbase.h"
#include "qgis_app.h"
#include <memory>

class QgsMapCanvasAnnotationItem;
class QgsMarkerSymbol;
@@ -47,8 +48,8 @@ class APP_EXPORT QgsAnnotationWidget: public QWidget, private Ui::QgsAnnotationW

private:
QgsMapCanvasAnnotationItem* mItem = nullptr;
QScopedPointer< QgsMarkerSymbol > mMarkerSymbol;
QScopedPointer< QgsFillSymbol > mFillSymbol;
std::unique_ptr< QgsMarkerSymbol > mMarkerSymbol;
std::unique_ptr< QgsFillSymbol > mFillSymbol;

void blockAllSignals( bool block );
void updateCenterIcon();
@@ -500,15 +500,15 @@ void QgsAppLayerTreeViewMenuProvider::editVectorSymbol()
if ( !singleRenderer )
return;

QScopedPointer< QgsSymbol > symbol( singleRenderer->symbol() ? singleRenderer->symbol()->clone() : nullptr );
QgsSymbolSelectorDialog dlg( symbol.data(), QgsStyle::defaultStyle(), layer, mView->window() );
std::unique_ptr< QgsSymbol > symbol( singleRenderer->symbol() ? singleRenderer->symbol()->clone() : nullptr );
QgsSymbolSelectorDialog dlg( symbol.get(), QgsStyle::defaultStyle(), layer, mView->window() );
dlg.setWindowTitle( tr( "Symbol selector" ) );
QgsSymbolWidgetContext context;
context.setMapCanvas( mCanvas );
dlg.setContext( context );
if ( dlg.exec() )
{
singleRenderer->setSymbol( symbol.take() );
singleRenderer->setSymbol( symbol.release() );
layer->triggerRepaint();
mView->refreshLayerSymbology( layer->id() );
}
@@ -576,16 +576,16 @@ void QgsAppLayerTreeViewMenuProvider::editSymbolLegendNodeSymbol()
if ( !originalSymbol )
return;

QScopedPointer< QgsSymbol > symbol( originalSymbol->clone() );
std::unique_ptr< QgsSymbol > symbol( originalSymbol->clone() );
QgsVectorLayer* vlayer = qobject_cast<QgsVectorLayer*>( node->layerNode()->layer() );
QgsSymbolSelectorDialog dlg( symbol.data(), QgsStyle::defaultStyle(), vlayer, mView->window() );
QgsSymbolSelectorDialog dlg( symbol.get(), QgsStyle::defaultStyle(), vlayer, mView->window() );
dlg.setWindowTitle( tr( "Symbol selector" ) );
QgsSymbolWidgetContext context;
context.setMapCanvas( mCanvas );
dlg.setContext( context );
if ( dlg.exec() )
{
node->setSymbol( symbol.take() );
node->setSymbol( symbol.release() );
if ( vlayer )
{
vlayer->emitStyleChanged();
@@ -101,7 +101,7 @@ QgsBookmarks::QgsBookmarks( QWidget *parent )
mProjectModel = new QgsProjectBookmarksTableModel();
mModel.reset( new QgsMergedBookmarksTableModel( *mQgisModel, *mProjectModel, lstBookmarks ) );

lstBookmarks->setModel( mModel.data() );
lstBookmarks->setModel( mModel.get() );

QSettings settings;
lstBookmarks->header()->restoreState( settings.value( QStringLiteral( "/Windows/Bookmarks/headerstate" ) ).toByteArray() );
@@ -18,7 +18,7 @@
#define QGSBOOKMARKS_H

#include <QSqlTableModel>
#include <QScopedPointer>
#include <memory>

#include "ui_qgsbookmarksbase.h"
#include "qgsdockwidget.h"
@@ -121,7 +121,7 @@ class APP_EXPORT QgsBookmarks : public QgsDockWidget, private Ui::QgsBookmarksBa
private:
QSqlTableModel* mQgisModel;
QgsProjectBookmarksTableModel* mProjectModel;
QScopedPointer<QgsMergedBookmarksTableModel> mModel;
std::unique_ptr<QgsMergedBookmarksTableModel> mModel;

void saveWindowLocation();
void restorePosition();
@@ -251,7 +251,7 @@ QgsDiagramProperties::QgsDiagramProperties( QgsVectorLayer* layer, QWidget* pare
mCheckBoxAttributeLegend->setChecked( dr->attributeLegend() );
mCheckBoxSizeLegend->setChecked( dr->sizeLegend() );
mSizeLegendSymbol.reset( dr->sizeLegendSymbol() ? dr->sizeLegendSymbol()->clone() : QgsMarkerSymbol::createSimple( QgsStringMap() ) );
QIcon icon = QgsSymbolLayerUtils::symbolPreviewIcon( mSizeLegendSymbol.data(), mButtonSizeLegendSymbol->iconSize() );
QIcon icon = QgsSymbolLayerUtils::symbolPreviewIcon( mSizeLegendSymbol.get(), mButtonSizeLegendSymbol->iconSize() );
mButtonSizeLegendSymbol->setIcon( icon );

//assume single category or linearly interpolated diagram renderer for now
@@ -943,7 +943,7 @@ void QgsDiagramProperties::on_mButtonSizeLegendSymbol_clicked()
if ( d.exec() == QDialog::Accepted )
{
mSizeLegendSymbol.reset( newSymbol );
QIcon icon = QgsSymbolLayerUtils::symbolPreviewIcon( mSizeLegendSymbol.data(), mButtonSizeLegendSymbol->iconSize() );
QIcon icon = QgsSymbolLayerUtils::symbolPreviewIcon( mSizeLegendSymbol.get(), mButtonSizeLegendSymbol->iconSize() );
mButtonSizeLegendSymbol->setIcon( icon );
}
else
@@ -80,7 +80,7 @@ class APP_EXPORT QgsDiagramProperties : public QWidget, private Ui::QgsDiagramPr

// Keeps track of the diagram type to properly save / restore settings when the diagram type combo box is set to no diagram.
QString mDiagramType;
QScopedPointer< QgsMarkerSymbol > mSizeLegendSymbol;
std::unique_ptr< QgsMarkerSymbol > mSizeLegendSymbol;

QString guessLegendText( const QString &expression );
QgsMapCanvas *mMapCanvas;
@@ -116,7 +116,7 @@ bool QgsFeatureAction::editFeature( bool showModal )

if ( showModal )
{
QScopedPointer<QgsAttributeDialog> dialog( newDialog( false ) );
std::unique_ptr<QgsAttributeDialog> dialog( newDialog( false ) );

if ( !mFeature->isValid() )
dialog->setMode( QgsAttributeForm::AddFeatureMode );
@@ -46,13 +46,13 @@ QgsLabelingWidget::QgsLabelingWidget( QgsVectorLayer* layer, QgsMapCanvas* canva

void QgsLabelingWidget::resetSettings()
{
if ( mOldSettings.data() )
if ( mOldSettings )
{
if ( mOldSettings->type() == QLatin1String( "simple" ) )
{
mOldPalSettings.writeToLayer( mLayer );
}
mLayer->setLabeling( mOldSettings.take() );
mLayer->setLabeling( mOldSettings.release() );
}
setLayer( mLayer );
}
@@ -65,7 +65,7 @@ class QgsLabelingWidget : public QgsMapLayerConfigWidget, private Ui::QgsLabelin

QWidget* mWidget;
QgsLabelingGui* mLabelGui;
QScopedPointer< QgsAbstractVectorLayerLabeling > mOldSettings;
std::unique_ptr< QgsAbstractVectorLayerLabeling > mOldSettings;
QgsPalLayerSettings mOldPalSettings;
};

@@ -233,7 +233,7 @@ void QgsMapToolAddFeature::cadCanvasReleaseEvent( QgsMapMouseEvent* e )
}

//create QgsFeature with wkb representation
QScopedPointer< QgsFeature > f( new QgsFeature( vlayer->fields(), 0 ) );
std::unique_ptr< QgsFeature > f( new QgsFeature( vlayer->fields(), 0 ) );

//does compoundcurve contain circular strings?
//does provider support circular strings?
@@ -288,7 +288,7 @@ void QgsMapToolAddFeature::cadCanvasReleaseEvent( QgsMapMouseEvent* e )
}
f->setValid( true );

if ( addFeature( vlayer, f.data(), false ) )
if ( addFeature( vlayer, f.get(), false ) )
{
//add points to other features to keep topology up-to-date
bool topologicalEditing = QgsProject::instance()->topologicalEditing();
@@ -77,7 +77,7 @@ void QgsMapToolOffsetPointSymbol::canvasPressOnFeature( QgsMapMouseEvent *e, con
{
Q_UNUSED( e );
mClickedFeature = feature;
createPreviewItem( mMarkerSymbol.data() );
createPreviewItem( mMarkerSymbol.get() );
mOffsetItem->setPointLocation( snappedPoint );
updateOffsetPreviewItem( mClickedPoint, mClickedPoint );
mOffsetting = true;
@@ -97,7 +97,7 @@ bool QgsMapToolOffsetPointSymbol::checkSymbolCompatibility( QgsMarkerSymbol* mar
continue;

ok = true;
if ( mMarkerSymbol.isNull() )
if ( !mMarkerSymbol )
{
double symbolRotation = markerSymbol->angle();
if ( layer->dataDefinedProperties().isActive( QgsSymbolLayer::PropertyAngle ) )
@@ -60,7 +60,7 @@ class APP_EXPORT QgsMapToolOffsetPointSymbol: public QgsMapToolPointSymbol
QgsPointMarkerItem* mOffsetItem;

//! Clone of first found marker symbol for feature with offset attribute set
QScopedPointer< QgsMarkerSymbol > mMarkerSymbol;
std::unique_ptr< QgsMarkerSymbol > mMarkerSymbol;

//! Feature which was clicked on