Skip to content

Commit

Permalink
Misc optimisations to geonode data items, fix leaks
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Sep 12, 2017
1 parent 29539e6 commit 4e65162
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 31 deletions.
58 changes: 30 additions & 28 deletions src/app/geocms/geonode/qgsgeonodedataitems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,20 @@

typedef QList<QgsDataItemProvider *> *dataItemProviders_t();

QgsGeoNodeConnectionItem::QgsGeoNodeConnectionItem( QgsDataItem *parent, QString name, QString path, QgsGeoNodeConnection *conn )
QgsGeoNodeConnectionItem::QgsGeoNodeConnectionItem( QgsDataItem *parent, QString name, QString path, std::unique_ptr<QgsGeoNodeConnection> conn )
: QgsDataCollectionItem( parent, name, path )
, mGeoNodeName( parent->name() )
, mUri( conn->uri().uri() )
, mConnection( conn )
{
mConnection = std::move( conn );
mIconName = QStringLiteral( "mIconConnect.png" );
}

QVector<QgsDataItem *> QgsGeoNodeConnectionItem::createChildren()
{
QVector<QgsDataItem *> services;

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

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

if ( !wmsUrl.isEmpty() )
{
QString path = mPath + "/wms";
QgsDataItem *service = new QgsGeoNodeServiceItem( this, mConnection, QStringLiteral( "WMS" ), path );
QString path = mPath + QStringLiteral( "/wms" );
QgsDataItem *service = new QgsGeoNodeServiceItem( this, mConnection.get(), QStringLiteral( "WMS" ), path );
services.append( service );
}

if ( !wfsUrl.isEmpty() )
{
QString path = mPath + "/wfs";
QgsDataItem *service = new QgsGeoNodeServiceItem( this, mConnection, QStringLiteral( "WFS" ), path );
QString path = mPath + QStringLiteral( "/wfs" );
QgsDataItem *service = new QgsGeoNodeServiceItem( this, mConnection.get(), QStringLiteral( "WFS" ), path );
services.append( service );
}

if ( !xyzUrl.isEmpty() )
{
QString path = mPath + "/xyz";
QgsDataItem *service = new QgsGeoNodeServiceItem( this, mConnection, QStringLiteral( "XYZ" ), path );
QString path = mPath + QStringLiteral( "/xyz" );
QgsDataItem *service = new QgsGeoNodeServiceItem( this, mConnection.get(), QStringLiteral( "XYZ" ), path );
services.append( service );
}

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

QList<QAction *> QgsGeoNodeConnectionItem::actions()
{
QAction *actionEdit = new QAction( tr( "Edit..." ), this );
QAction *actionDelete = new QAction( tr( "Delete" ), this );
QAction *actionEdit = new QAction( tr( "Edit Connection..." ), this );
QAction *actionDelete = new QAction( tr( "Delete Connection" ), this );
connect( actionEdit, &QAction::triggered, this, &QgsGeoNodeConnectionItem::editConnection );
connect( actionDelete, &QAction::triggered, this, &QgsGeoNodeConnectionItem::deleteConnection );
return QList<QAction *>() << actionEdit << actionDelete;
}

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

if ( nc->exec() )
if ( nc.exec() )
{
// the parent should be updated
mParent->refresh();
Expand Down Expand Up @@ -113,11 +113,11 @@ QVector<QgsDataItem *> QgsGeoNodeServiceItem::createChildren()
bool skipProvider = false;

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

while ( !skipProvider )
{
const QString &key = mServiceName != QString( "WFS" ) ? QString( "WMS" ).toLower() : mServiceName;
const QString &key = mServiceName != QStringLiteral( "WFS" ) ? QStringLiteral( "wms" ) : mServiceName;
std::unique_ptr< QLibrary > library( QgsProviderRegistry::instance()->createProviderLibrary( key ) );
if ( !library )
{
Expand All @@ -139,7 +139,10 @@ QVector<QgsDataItem *> QgsGeoNodeServiceItem::createChildren()
QList<QgsDataItemProvider *> *providerList = dataItemProvidersFn();
Q_FOREACH ( QgsDataItemProvider *pr, *providerList )
{
items = pr->name().startsWith( mServiceName ) ? pr->createDataItems( path, this ) : items;
if ( !pr->name().startsWith( mServiceName ) )
continue;

items = pr->createDataItems( path, this );
if ( !items.isEmpty() )
{
break;
Expand Down Expand Up @@ -188,13 +191,13 @@ QVector<QgsDataItem *> QgsGeoNodeServiceItem::createChildren()
// Add layers directly to service item
Q_FOREACH ( QgsDataItem *subItem, item->children() )
{
if ( subItem->path().endsWith( QString( "error" ) ) )
if ( subItem->path().endsWith( QStringLiteral( "error" ) ) )
{
continue;
}
item->removeChildItem( subItem );
subItem->setParent( this );
replacePath( subItem, providerKey.toLower() + ":/", pathPrefix );
replacePath( subItem, providerKey.toLower() + QStringLiteral( ":/" ), pathPrefix );
subItem->setActions( actions );
children.append( subItem );
}
Expand Down Expand Up @@ -230,10 +233,9 @@ QVector<QgsDataItem *> QgsGeoNodeRootItem::createChildren()

Q_FOREACH ( const QString &connName, QgsGeoNodeConnectionUtils::connectionList() )
{
QgsGeoNodeConnection *connection = nullptr;
connection = new QgsGeoNodeConnection( connName );
QString path = mPath + "/" + connName;
QgsDataItem *conn = new QgsGeoNodeConnectionItem( this, connName, path, connection );
std::unique_ptr< QgsGeoNodeConnection > connection( new QgsGeoNodeConnection( connName ) );
QString path = mPath + '/' + connName;
QgsDataItem *conn = new QgsGeoNodeConnectionItem( this, connName, path, std::move( connection ) );
connections.append( conn );
}
return connections;
Expand All @@ -248,9 +250,9 @@ QList<QAction *> QgsGeoNodeRootItem::actions()

void QgsGeoNodeRootItem::newConnection()
{
QgsGeoNodeNewConnection *nc = new QgsGeoNodeNewConnection( nullptr );
QgsGeoNodeNewConnection nc( nullptr );

if ( nc->exec() )
if ( nc.exec() )
{
refresh();
}
Expand All @@ -259,7 +261,7 @@ void QgsGeoNodeRootItem::newConnection()

QgsDataItem *QgsGeoNodeDataItemProvider::createDataItem( const QString &path, QgsDataItem *parentItem )
{
QgsDebugMsg( "thePath = " + path );
QgsDebugMsgLevel( "thePath = " + path, 4 );
if ( path.isEmpty() )
{
return new QgsGeoNodeRootItem( parentItem, QStringLiteral( "GeoNode" ), QStringLiteral( "geonode:" ) );
Expand All @@ -271,8 +273,8 @@ QgsDataItem *QgsGeoNodeDataItemProvider::createDataItem( const QString &path, Qg
QString connectionName = path.split( '/' ).last();
if ( QgsGeoNodeConnectionUtils::connectionList().contains( connectionName ) )
{
QgsGeoNodeConnection *connection = new QgsGeoNodeConnection( connectionName );
return new QgsGeoNodeConnectionItem( parentItem, QStringLiteral( "GeoNode" ), path, connection );
std::unique_ptr< QgsGeoNodeConnection > connection( new QgsGeoNodeConnection( connectionName ) );
return new QgsGeoNodeConnectionItem( parentItem, QStringLiteral( "GeoNode" ), path, std::move( connection ) );
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/app/geocms/geonode/qgsgeonodedataitems.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class QgsGeoNodeConnectionItem : public QgsDataCollectionItem
{
Q_OBJECT
public:
QgsGeoNodeConnectionItem( QgsDataItem *parent, QString name, QString path, QgsGeoNodeConnection *conn );
QgsGeoNodeConnectionItem( QgsDataItem *parent, QString name, QString path, std::unique_ptr< QgsGeoNodeConnection > conn );
QVector<QgsDataItem *> createChildren() override;
virtual QList<QAction *> actions() override;

Expand All @@ -38,10 +38,10 @@ class QgsGeoNodeConnectionItem : public QgsDataCollectionItem
{
QgsGeoNodeConnectionUtils::deleteConnection( name() );
mParent->refresh();
};
}

QString mUri;
QgsGeoNodeConnection *mConnection = nullptr;
std::unique_ptr< QgsGeoNodeConnection > mConnection = nullptr;
};

class QgsGeoNodeServiceItem : public QgsDataCollectionItem
Expand Down

0 comments on commit 4e65162

Please sign in to comment.