Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 aed6c73
Show file tree
Hide file tree
Showing 170 changed files with 680 additions and 659 deletions.
2 changes: 1 addition & 1 deletion src/app/composer/qgscomposer.cpp
Expand Up @@ -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();

Expand Down
4 changes: 2 additions & 2 deletions src/app/dwg/qgsdwgimportdialog.cpp
Expand Up @@ -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" );
Expand Down Expand Up @@ -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" );
Expand Down
9 changes: 5 additions & 4 deletions src/app/dwg/qgsdwgimporter.cpp
Expand Up @@ -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; }
Expand Down Expand Up @@ -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;
Expand All @@ -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();
Expand Down Expand Up @@ -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
{
Expand Down
10 changes: 5 additions & 5 deletions src/app/qgisapp.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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 )
{
Expand Down Expand Up @@ -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" ),
Expand Down
4 changes: 2 additions & 2 deletions src/app/qgsannotationwidget.cpp
Expand Up @@ -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 );
}

Expand All @@ -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 );
}

5 changes: 3 additions & 2 deletions src/app/qgsannotationwidget.h
Expand Up @@ -20,6 +20,7 @@

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

class QgsMapCanvasAnnotationItem;
class QgsMarkerSymbol;
Expand Down Expand Up @@ -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();
Expand Down
12 changes: 6 additions & 6 deletions src/app/qgsapplayertreeviewmenuprovider.cpp
Expand Up @@ -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() );
}
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsbookmarks.cpp
Expand Up @@ -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() );
Expand Down
4 changes: 2 additions & 2 deletions src/app/qgsbookmarks.h
Expand Up @@ -18,7 +18,7 @@
#define QGSBOOKMARKS_H

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

#include "ui_qgsbookmarksbase.h"
#include "qgsdockwidget.h"
Expand Down Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions src/app/qgsdiagramproperties.cpp
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsdiagramproperties.h
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsfeatureaction.cpp
Expand Up @@ -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 );
Expand Down
4 changes: 2 additions & 2 deletions src/app/qgslabelingwidget.cpp
Expand Up @@ -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 );
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgslabelingwidget.h
Expand Up @@ -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;
};

Expand Down
4 changes: 2 additions & 2 deletions src/app/qgsmaptooladdfeature.cpp
Expand Up @@ -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?
Expand Down Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions src/app/qgsmaptooloffsetpointsymbol.cpp
Expand Up @@ -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;
Expand All @@ -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 ) )
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsmaptooloffsetpointsymbol.h
Expand Up @@ -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
QgsFeature mClickedFeature;
Expand Down
4 changes: 2 additions & 2 deletions src/app/qgsmaptoolrotatepointsymbols.cpp
Expand Up @@ -83,7 +83,7 @@ void QgsMapToolRotatePointSymbols::canvasPressOnFeature( QgsMapMouseEvent *e, co
}

mCurrentRotationFeature = attrVal.toDouble();
createPixmapItem( mMarkerSymbol.data() );
createPixmapItem( mMarkerSymbol.get() );
if ( mRotationItem )
{
mRotationItem->setPointLocation( snappedPoint );
Expand All @@ -101,7 +101,7 @@ bool QgsMapToolRotatePointSymbols::checkSymbolCompatibility( QgsMarkerSymbol* ma
{
mCurrentRotationAttributes << mActiveLayer->fields().indexFromName( ddAngle.field() );
ok = true;
if ( mMarkerSymbol.isNull() )
if ( !mMarkerSymbol )
{
mMarkerSymbol.reset( markerSymbol->clone() );
}
Expand Down
3 changes: 2 additions & 1 deletion src/app/qgsmaptoolrotatepointsymbols.h
Expand Up @@ -18,6 +18,7 @@

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

class QgsPointRotationItem;
class QgsMarkerSymbol;
Expand Down Expand Up @@ -62,7 +63,7 @@ class APP_EXPORT QgsMapToolRotatePointSymbols: public QgsMapToolPointSymbol
//! True if ctrl was pressed during the last mouse move event
bool mCtrlPressed;
//! Clone of first found marker symbol for feature with rotation attribute set
QScopedPointer< QgsMarkerSymbol > mMarkerSymbol;
std::unique_ptr< QgsMarkerSymbol > mMarkerSymbol;

void drawArrow( double azimut ) const;
//! Calculates the azimut between mousePos and mSnappedPoint
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgspointmarkeritem.cpp
Expand Up @@ -94,7 +94,7 @@ void QgsPointMarkerItem::setSymbol( QgsMarkerSymbol *symbol )

QgsMarkerSymbol*QgsPointMarkerItem::symbol()
{
return mMarkerSymbol.data();
return mMarkerSymbol.get();
}

void QgsPointMarkerItem::setFeature( const QgsFeature& feature )
Expand Down
5 changes: 3 additions & 2 deletions src/app/qgspointmarkeritem.h
Expand Up @@ -22,6 +22,7 @@
#include <QFontMetricsF>
#include <QPixmap>
#include "qgis_app.h"
#include <memory>

class QgsMarkerSymbol;

Expand Down Expand Up @@ -91,9 +92,9 @@ class APP_EXPORT QgsPointMarkerItem: public QgsMapCanvasItem
private:

QgsFeature mFeature;
QScopedPointer< QgsMarkerSymbol > mMarkerSymbol;
std::unique_ptr< QgsMarkerSymbol > mMarkerSymbol;
QPointF mLocation;
QScopedPointer< QgsDrawSourceEffect > mOpacityEffect;
std::unique_ptr< QgsDrawSourceEffect > mOpacityEffect;

QgsRenderContext renderContext( QPainter* painter );
};
Expand Down
4 changes: 2 additions & 2 deletions src/app/qgsprojectproperties.cpp
Expand Up @@ -1718,8 +1718,8 @@ void QgsProjectProperties::populateStyles()
for ( int i = 0; i < colorRamps.count(); ++i )
{
QString name = colorRamps[i];
QScopedPointer< QgsColorRamp > ramp( mStyle->colorRamp( name ) );
QIcon icon = QgsSymbolLayerUtils::colorRampPreviewIcon( ramp.data(), cboStyleColorRamp->iconSize() );
std::unique_ptr< QgsColorRamp > ramp( mStyle->colorRamp( name ) );
QIcon icon = QgsSymbolLayerUtils::colorRampPreviewIcon( ramp.get(), cboStyleColorRamp->iconSize() );
cboStyleColorRamp->addItem( icon, name );
}

Expand Down

0 comments on commit aed6c73

Please sign in to comment.