Skip to content
Permalink
Browse files

Memory safety

  • Loading branch information
nyalldawson committed Jun 9, 2018
1 parent b3ef029 commit 7b1861e4735274802f77382b1112e1f0e92f18a3
@@ -53,12 +53,12 @@ void QgsLayerTreeViewEmbeddedIndicatorProvider::onAddedChildren( QgsLayerTreeNod
}
}

QgsLayerTreeViewIndicator *QgsLayerTreeViewEmbeddedIndicatorProvider::newIndicator( const QString &project )
std::unique_ptr< QgsLayerTreeViewIndicator > QgsLayerTreeViewEmbeddedIndicatorProvider::newIndicator( const QString &project )
{
QgsLayerTreeViewIndicator *indicator = new QgsLayerTreeViewIndicator( this );
std::unique_ptr< QgsLayerTreeViewIndicator > indicator = qgis::make_unique< QgsLayerTreeViewIndicator >( this );
indicator->setIcon( mIcon );
indicator->setToolTip( tr( "Embedded from <b>%1</b>" ).arg( project ) );
mIndicators.insert( indicator );
mIndicators.insert( indicator.get() );
return indicator;
}

@@ -85,5 +85,5 @@ void QgsLayerTreeViewEmbeddedIndicatorProvider::addIndicatorForEmbeddedLayer( Qg
}

// it does not exist: need to create a new one
mLayerTreeView->addIndicator( node, newIndicator( project ) );
mLayerTreeView->addIndicator( node, newIndicator( project ).release() );
}
@@ -19,6 +19,7 @@
#include "qgslayertreeviewindicator.h"

#include <QSet>
#include <memory>

class QgsLayerTreeNode;
class QgsLayerTreeView;
@@ -35,7 +36,7 @@ class QgsLayerTreeViewEmbeddedIndicatorProvider : public QObject
void onAddedChildren( QgsLayerTreeNode *node, int indexFrom, int indexTo );

private:
QgsLayerTreeViewIndicator *newIndicator( const QString &project );
std::unique_ptr< QgsLayerTreeViewIndicator > newIndicator( const QString &project );
void addIndicatorForEmbeddedLayer( QgsLayerTreeNode *node );

private:
@@ -151,19 +151,19 @@ void QgsLayerTreeViewFilterIndicatorProvider::onIndicatorClicked( const QModelIn
vlayer->setSubsetString( qb.sql() );
}

QgsLayerTreeViewIndicator *QgsLayerTreeViewFilterIndicatorProvider::newIndicator( const QString &filter )
std::unique_ptr<QgsLayerTreeViewIndicator> QgsLayerTreeViewFilterIndicatorProvider::newIndicator( const QString &filter )
{
QgsLayerTreeViewIndicator *indicator = new QgsLayerTreeViewIndicator( this );
std::unique_ptr< QgsLayerTreeViewIndicator > indicator = qgis::make_unique< QgsLayerTreeViewIndicator >( this );
indicator->setIcon( mIcon );
updateIndicator( indicator, filter );
connect( indicator, &QgsLayerTreeViewIndicator::clicked, this, &QgsLayerTreeViewFilterIndicatorProvider::onIndicatorClicked );
mIndicators.insert( indicator );
updateIndicator( indicator.get(), filter );
connect( indicator.get(), &QgsLayerTreeViewIndicator::clicked, this, &QgsLayerTreeViewFilterIndicatorProvider::onIndicatorClicked );
mIndicators.insert( indicator.get() );
return indicator;
}

void QgsLayerTreeViewFilterIndicatorProvider::updateIndicator( QgsLayerTreeViewIndicator *indicator, const QString &filter )
{
indicator->setToolTip( QString( "<b>%1:</b><br>%2" ).arg( tr( "Filter" ) ).arg( filter ) );
indicator->setToolTip( QStringLiteral( "<b>%1:</b><br>%2" ).arg( tr( "Filter" ), filter ) );
}


@@ -185,7 +185,7 @@ void QgsLayerTreeViewFilterIndicatorProvider::addOrRemoveIndicator( QgsLayerTree
}

// it does not exist: need to create a new one
mLayerTreeView->addIndicator( node, newIndicator( filter ) );
mLayerTreeView->addIndicator( node, newIndicator( filter ).release() );
}
else
{
@@ -19,6 +19,7 @@
#include "qgslayertreeviewindicator.h"

#include <QSet>
#include <memory>

class QgsLayerTreeNode;
class QgsLayerTreeView;
@@ -45,7 +46,7 @@ class QgsLayerTreeViewFilterIndicatorProvider : public QObject
void onIndicatorClicked( const QModelIndex &index );

private:
QgsLayerTreeViewIndicator *newIndicator( const QString &filter );
std::unique_ptr< QgsLayerTreeViewIndicator > newIndicator( const QString &filter );
void updateIndicator( QgsLayerTreeViewIndicator *indicator, const QString &filter );
void addOrRemoveIndicator( QgsLayerTreeNode *node, QgsVectorLayer *vlayer );

0 comments on commit 7b1861e

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