22
22
23
23
typedef QList<QgsDataItemProvider *> *dataItemProviders_t ();
24
24
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 )
26
26
: QgsDataCollectionItem( parent, name, path )
27
27
, mGeoNodeName( parent->name () )
28
28
, mUri( conn->uri ().uri() )
29
- , mConnection( conn )
30
29
{
30
+ mConnection = std::move ( conn );
31
31
mIconName = QStringLiteral ( " mIconConnect.png" );
32
32
}
33
33
34
34
QVector<QgsDataItem *> QgsGeoNodeConnectionItem::createChildren ()
35
35
{
36
36
QVector<QgsDataItem *> services;
37
37
38
- QString url = mConnection ->uri ().param ( " url" );
38
+ QString url = mConnection ->uri ().param ( QStringLiteral ( " url" ) );
39
39
QgsGeoNodeRequest geonodeRequest ( url, true );
40
40
41
41
QStringList wmsUrl = geonodeRequest.serviceUrls ( QStringLiteral ( " WMS" ) );
@@ -44,22 +44,22 @@ QVector<QgsDataItem *> QgsGeoNodeConnectionItem::createChildren()
44
44
45
45
if ( !wmsUrl.isEmpty () )
46
46
{
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 );
49
49
services.append ( service );
50
50
}
51
51
52
52
if ( !wfsUrl.isEmpty () )
53
53
{
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 );
56
56
services.append ( service );
57
57
}
58
58
59
59
if ( !xyzUrl.isEmpty () )
60
60
{
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 );
63
63
services.append ( service );
64
64
}
65
65
@@ -68,19 +68,19 @@ QVector<QgsDataItem *> QgsGeoNodeConnectionItem::createChildren()
68
68
69
69
QList<QAction *> QgsGeoNodeConnectionItem::actions ()
70
70
{
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 );
73
73
connect ( actionEdit, &QAction::triggered, this , &QgsGeoNodeConnectionItem::editConnection );
74
74
connect ( actionDelete, &QAction::triggered, this , &QgsGeoNodeConnectionItem::deleteConnection );
75
75
return QList<QAction *>() << actionEdit << actionDelete;
76
76
}
77
77
78
78
void QgsGeoNodeConnectionItem::editConnection ()
79
79
{
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" ) );
82
82
83
- if ( nc-> exec () )
83
+ if ( nc. exec () )
84
84
{
85
85
// the parent should be updated
86
86
mParent ->refresh ();
@@ -113,11 +113,11 @@ QVector<QgsDataItem *> QgsGeoNodeServiceItem::createChildren()
113
113
bool skipProvider = false ;
114
114
115
115
QgsGeoNodeConnectionItem *parentItem = dynamic_cast <QgsGeoNodeConnectionItem *>( mParent );
116
- QString pathPrefix = parentItem->mGeoNodeName .toLower () + " :/" ;
116
+ QString pathPrefix = parentItem->mGeoNodeName .toLower () + QStringLiteral ( " :/" ) ;
117
117
118
118
while ( !skipProvider )
119
119
{
120
- const QString &key = mServiceName != QString ( " WFS" ) ? QString ( " WMS " ). toLower ( ) : mServiceName ;
120
+ const QString &key = mServiceName != QStringLiteral ( " WFS" ) ? QStringLiteral ( " wms " ) : mServiceName ;
121
121
std::unique_ptr< QLibrary > library ( QgsProviderRegistry::instance ()->createProviderLibrary ( key ) );
122
122
if ( !library )
123
123
{
@@ -139,7 +139,10 @@ QVector<QgsDataItem *> QgsGeoNodeServiceItem::createChildren()
139
139
QList<QgsDataItemProvider *> *providerList = dataItemProvidersFn ();
140
140
Q_FOREACH ( QgsDataItemProvider *pr, *providerList )
141
141
{
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 );
143
146
if ( !items.isEmpty () )
144
147
{
145
148
break ;
@@ -188,13 +191,13 @@ QVector<QgsDataItem *> QgsGeoNodeServiceItem::createChildren()
188
191
// Add layers directly to service item
189
192
Q_FOREACH ( QgsDataItem *subItem, item->children () )
190
193
{
191
- if ( subItem->path ().endsWith ( QString ( " error" ) ) )
194
+ if ( subItem->path ().endsWith ( QStringLiteral ( " error" ) ) )
192
195
{
193
196
continue ;
194
197
}
195
198
item->removeChildItem ( subItem );
196
199
subItem->setParent ( this );
197
- replacePath ( subItem, providerKey.toLower () + " :/" , pathPrefix );
200
+ replacePath ( subItem, providerKey.toLower () + QStringLiteral ( " :/" ) , pathPrefix );
198
201
subItem->setActions ( actions );
199
202
children.append ( subItem );
200
203
}
@@ -230,10 +233,9 @@ QVector<QgsDataItem *> QgsGeoNodeRootItem::createChildren()
230
233
231
234
Q_FOREACH ( const QString &connName, QgsGeoNodeConnectionUtils::connectionList () )
232
235
{
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 ) );
237
239
connections.append ( conn );
238
240
}
239
241
return connections;
@@ -248,9 +250,9 @@ QList<QAction *> QgsGeoNodeRootItem::actions()
248
250
249
251
void QgsGeoNodeRootItem::newConnection ()
250
252
{
251
- QgsGeoNodeNewConnection *nc = new QgsGeoNodeNewConnection ( nullptr );
253
+ QgsGeoNodeNewConnection nc ( nullptr );
252
254
253
- if ( nc-> exec () )
255
+ if ( nc. exec () )
254
256
{
255
257
refresh ();
256
258
}
@@ -259,7 +261,7 @@ void QgsGeoNodeRootItem::newConnection()
259
261
260
262
QgsDataItem *QgsGeoNodeDataItemProvider::createDataItem ( const QString &path, QgsDataItem *parentItem )
261
263
{
262
- QgsDebugMsg ( " thePath = " + path );
264
+ QgsDebugMsgLevel ( " thePath = " + path, 4 );
263
265
if ( path.isEmpty () )
264
266
{
265
267
return new QgsGeoNodeRootItem ( parentItem, QStringLiteral ( " GeoNode" ), QStringLiteral ( " geonode:" ) );
@@ -271,8 +273,8 @@ QgsDataItem *QgsGeoNodeDataItemProvider::createDataItem( const QString &path, Qg
271
273
QString connectionName = path.split ( ' /' ).last ();
272
274
if ( QgsGeoNodeConnectionUtils::connectionList ().contains ( connectionName ) )
273
275
{
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 ) );
276
278
}
277
279
}
278
280
0 commit comments