Skip to content

Commit 4e65162

Browse files
committedSep 12, 2017
Misc optimisations to geonode data items, fix leaks
1 parent 29539e6 commit 4e65162

File tree

2 files changed

+33
-31
lines changed

2 files changed

+33
-31
lines changed
 

‎src/app/geocms/geonode/qgsgeonodedataitems.cpp

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,20 @@
2222

2323
typedef QList<QgsDataItemProvider *> *dataItemProviders_t();
2424

25-
QgsGeoNodeConnectionItem::QgsGeoNodeConnectionItem( QgsDataItem *parent, QString name, QString path, QgsGeoNodeConnection *conn )
25+
QgsGeoNodeConnectionItem::QgsGeoNodeConnectionItem( QgsDataItem *parent, QString name, QString path, std::unique_ptr<QgsGeoNodeConnection> conn )
2626
: QgsDataCollectionItem( parent, name, path )
2727
, mGeoNodeName( parent->name() )
2828
, mUri( conn->uri().uri() )
29-
, mConnection( conn )
3029
{
30+
mConnection = std::move( conn );
3131
mIconName = QStringLiteral( "mIconConnect.png" );
3232
}
3333

3434
QVector<QgsDataItem *> QgsGeoNodeConnectionItem::createChildren()
3535
{
3636
QVector<QgsDataItem *> services;
3737

38-
QString url = mConnection->uri().param( "url" );
38+
QString url = mConnection->uri().param( QStringLiteral( "url" ) );
3939
QgsGeoNodeRequest geonodeRequest( url, true );
4040

4141
QStringList wmsUrl = geonodeRequest.serviceUrls( QStringLiteral( "WMS" ) );
@@ -44,22 +44,22 @@ QVector<QgsDataItem *> QgsGeoNodeConnectionItem::createChildren()
4444

4545
if ( !wmsUrl.isEmpty() )
4646
{
47-
QString path = mPath + "/wms";
48-
QgsDataItem *service = new QgsGeoNodeServiceItem( this, mConnection, QStringLiteral( "WMS" ), path );
47+
QString path = mPath + QStringLiteral( "/wms" );
48+
QgsDataItem *service = new QgsGeoNodeServiceItem( this, mConnection.get(), QStringLiteral( "WMS" ), path );
4949
services.append( service );
5050
}
5151

5252
if ( !wfsUrl.isEmpty() )
5353
{
54-
QString path = mPath + "/wfs";
55-
QgsDataItem *service = new QgsGeoNodeServiceItem( this, mConnection, QStringLiteral( "WFS" ), path );
54+
QString path = mPath + QStringLiteral( "/wfs" );
55+
QgsDataItem *service = new QgsGeoNodeServiceItem( this, mConnection.get(), QStringLiteral( "WFS" ), path );
5656
services.append( service );
5757
}
5858

5959
if ( !xyzUrl.isEmpty() )
6060
{
61-
QString path = mPath + "/xyz";
62-
QgsDataItem *service = new QgsGeoNodeServiceItem( this, mConnection, QStringLiteral( "XYZ" ), path );
61+
QString path = mPath + QStringLiteral( "/xyz" );
62+
QgsDataItem *service = new QgsGeoNodeServiceItem( this, mConnection.get(), QStringLiteral( "XYZ" ), path );
6363
services.append( service );
6464
}
6565

@@ -68,19 +68,19 @@ QVector<QgsDataItem *> QgsGeoNodeConnectionItem::createChildren()
6868

6969
QList<QAction *> QgsGeoNodeConnectionItem::actions()
7070
{
71-
QAction *actionEdit = new QAction( tr( "Edit..." ), this );
72-
QAction *actionDelete = new QAction( tr( "Delete" ), this );
71+
QAction *actionEdit = new QAction( tr( "Edit Connection..." ), this );
72+
QAction *actionDelete = new QAction( tr( "Delete Connection" ), this );
7373
connect( actionEdit, &QAction::triggered, this, &QgsGeoNodeConnectionItem::editConnection );
7474
connect( actionDelete, &QAction::triggered, this, &QgsGeoNodeConnectionItem::deleteConnection );
7575
return QList<QAction *>() << actionEdit << actionDelete;
7676
}
7777

7878
void QgsGeoNodeConnectionItem::editConnection()
7979
{
80-
QgsGeoNodeNewConnection *nc = new QgsGeoNodeNewConnection( nullptr, mConnection->connName() );
81-
nc->setWindowTitle( tr( "Modify GeoNode connection" ) );
80+
QgsGeoNodeNewConnection nc( nullptr, mConnection->connName() );
81+
nc.setWindowTitle( tr( "Modify GeoNode connection" ) );
8282

83-
if ( nc->exec() )
83+
if ( nc.exec() )
8484
{
8585
// the parent should be updated
8686
mParent->refresh();
@@ -113,11 +113,11 @@ QVector<QgsDataItem *> QgsGeoNodeServiceItem::createChildren()
113113
bool skipProvider = false;
114114

115115
QgsGeoNodeConnectionItem *parentItem = dynamic_cast<QgsGeoNodeConnectionItem *>( mParent );
116-
QString pathPrefix = parentItem->mGeoNodeName.toLower() + ":/";
116+
QString pathPrefix = parentItem->mGeoNodeName.toLower() + QStringLiteral( ":/" );
117117

118118
while ( !skipProvider )
119119
{
120-
const QString &key = mServiceName != QString( "WFS" ) ? QString( "WMS" ).toLower() : mServiceName;
120+
const QString &key = mServiceName != QStringLiteral( "WFS" ) ? QStringLiteral( "wms" ) : mServiceName;
121121
std::unique_ptr< QLibrary > library( QgsProviderRegistry::instance()->createProviderLibrary( key ) );
122122
if ( !library )
123123
{
@@ -139,7 +139,10 @@ QVector<QgsDataItem *> QgsGeoNodeServiceItem::createChildren()
139139
QList<QgsDataItemProvider *> *providerList = dataItemProvidersFn();
140140
Q_FOREACH ( QgsDataItemProvider *pr, *providerList )
141141
{
142-
items = pr->name().startsWith( mServiceName ) ? pr->createDataItems( path, this ) : items;
142+
if ( !pr->name().startsWith( mServiceName ) )
143+
continue;
144+
145+
items = pr->createDataItems( path, this );
143146
if ( !items.isEmpty() )
144147
{
145148
break;
@@ -188,13 +191,13 @@ QVector<QgsDataItem *> QgsGeoNodeServiceItem::createChildren()
188191
// Add layers directly to service item
189192
Q_FOREACH ( QgsDataItem *subItem, item->children() )
190193
{
191-
if ( subItem->path().endsWith( QString( "error" ) ) )
194+
if ( subItem->path().endsWith( QStringLiteral( "error" ) ) )
192195
{
193196
continue;
194197
}
195198
item->removeChildItem( subItem );
196199
subItem->setParent( this );
197-
replacePath( subItem, providerKey.toLower() + ":/", pathPrefix );
200+
replacePath( subItem, providerKey.toLower() + QStringLiteral( ":/" ), pathPrefix );
198201
subItem->setActions( actions );
199202
children.append( subItem );
200203
}
@@ -230,10 +233,9 @@ QVector<QgsDataItem *> QgsGeoNodeRootItem::createChildren()
230233

231234
Q_FOREACH ( const QString &connName, QgsGeoNodeConnectionUtils::connectionList() )
232235
{
233-
QgsGeoNodeConnection *connection = nullptr;
234-
connection = new QgsGeoNodeConnection( connName );
235-
QString path = mPath + "/" + connName;
236-
QgsDataItem *conn = new QgsGeoNodeConnectionItem( this, connName, path, connection );
236+
std::unique_ptr< QgsGeoNodeConnection > connection( new QgsGeoNodeConnection( connName ) );
237+
QString path = mPath + '/' + connName;
238+
QgsDataItem *conn = new QgsGeoNodeConnectionItem( this, connName, path, std::move( connection ) );
237239
connections.append( conn );
238240
}
239241
return connections;
@@ -248,9 +250,9 @@ QList<QAction *> QgsGeoNodeRootItem::actions()
248250

249251
void QgsGeoNodeRootItem::newConnection()
250252
{
251-
QgsGeoNodeNewConnection *nc = new QgsGeoNodeNewConnection( nullptr );
253+
QgsGeoNodeNewConnection nc( nullptr );
252254

253-
if ( nc->exec() )
255+
if ( nc.exec() )
254256
{
255257
refresh();
256258
}
@@ -259,7 +261,7 @@ void QgsGeoNodeRootItem::newConnection()
259261

260262
QgsDataItem *QgsGeoNodeDataItemProvider::createDataItem( const QString &path, QgsDataItem *parentItem )
261263
{
262-
QgsDebugMsg( "thePath = " + path );
264+
QgsDebugMsgLevel( "thePath = " + path, 4 );
263265
if ( path.isEmpty() )
264266
{
265267
return new QgsGeoNodeRootItem( parentItem, QStringLiteral( "GeoNode" ), QStringLiteral( "geonode:" ) );
@@ -271,8 +273,8 @@ QgsDataItem *QgsGeoNodeDataItemProvider::createDataItem( const QString &path, Qg
271273
QString connectionName = path.split( '/' ).last();
272274
if ( QgsGeoNodeConnectionUtils::connectionList().contains( connectionName ) )
273275
{
274-
QgsGeoNodeConnection *connection = new QgsGeoNodeConnection( connectionName );
275-
return new QgsGeoNodeConnectionItem( parentItem, QStringLiteral( "GeoNode" ), path, connection );
276+
std::unique_ptr< QgsGeoNodeConnection > connection( new QgsGeoNodeConnection( connectionName ) );
277+
return new QgsGeoNodeConnectionItem( parentItem, QStringLiteral( "GeoNode" ), path, std::move( connection ) );
276278
}
277279
}
278280

‎src/app/geocms/geonode/qgsgeonodedataitems.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class QgsGeoNodeConnectionItem : public QgsDataCollectionItem
2626
{
2727
Q_OBJECT
2828
public:
29-
QgsGeoNodeConnectionItem( QgsDataItem *parent, QString name, QString path, QgsGeoNodeConnection *conn );
29+
QgsGeoNodeConnectionItem( QgsDataItem *parent, QString name, QString path, std::unique_ptr< QgsGeoNodeConnection > conn );
3030
QVector<QgsDataItem *> createChildren() override;
3131
virtual QList<QAction *> actions() override;
3232

@@ -38,10 +38,10 @@ class QgsGeoNodeConnectionItem : public QgsDataCollectionItem
3838
{
3939
QgsGeoNodeConnectionUtils::deleteConnection( name() );
4040
mParent->refresh();
41-
};
41+
}
4242

4343
QString mUri;
44-
QgsGeoNodeConnection *mConnection = nullptr;
44+
std::unique_ptr< QgsGeoNodeConnection > mConnection = nullptr;
4545
};
4646

4747
class QgsGeoNodeServiceItem : public QgsDataCollectionItem

0 commit comments

Comments
 (0)
Please sign in to comment.