Skip to content

Commit 858b93b

Browse files
committedSep 12, 2017
Misc code cleanup
1 parent ea4b2dd commit 858b93b

File tree

1 file changed

+24
-40
lines changed

1 file changed

+24
-40
lines changed
 

‎src/gui/geonode/qgsgeonodesourceselect.cpp

Lines changed: 24 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,11 @@ void QgsGeoNodeSourceSelect::connectToGeonodeConnection()
150150
QApplication::setOverrideCursor( Qt::BusyCursor );
151151
QgsGeoNodeConnection connection( cmbConnections->currentText() );
152152

153-
QString url = connection.uri().param( "url" );
153+
QString url = connection.uri().param( QStringLiteral( "url" ) );
154154
QgsGeoNodeRequest geonodeRequest( url, true );
155155

156156
QApplication::setOverrideCursor( Qt::WaitCursor );
157-
QList<QgsServiceLayerDetail> layers = geonodeRequest.getLayers();
157+
const QList<QgsServiceLayerDetail> layers = geonodeRequest.getLayers();
158158
QApplication::restoreOverrideCursor();
159159

160160
if ( !layers.empty() )
@@ -173,19 +173,19 @@ void QgsGeoNodeSourceSelect::connectToGeonodeConnection()
173173

174174
if ( !layers.isEmpty() )
175175
{
176-
Q_FOREACH ( const QgsServiceLayerDetail &layer, layers )
176+
for ( const QgsServiceLayerDetail &layer : layers )
177177
{
178178
QUuid uuid = layer.uuid;
179179

180180
QString wmsURL = layer.wmsURL;
181181
QString wfsURL = layer.wfsURL;
182182
QString xyzURL = layer.xyzURL;
183183

184-
if ( wmsURL.length() > 0 )
184+
if ( !wmsURL.isEmpty() )
185185
{
186186
QStandardItem *titleItem = new QStandardItem( layer.title );
187187
QStandardItem *nameItem;
188-
if ( layer.name > 0 )
188+
if ( !layer.name.isEmpty() )
189189
{
190190
nameItem = new QStandardItem( layer.name );
191191
}
@@ -206,13 +206,13 @@ void QgsGeoNodeSourceSelect::connectToGeonodeConnection()
206206
}
207207
else
208208
{
209-
qDebug() << "Layer " << layer.title << " does not have WMS url.";
209+
QgsDebugMsgLevel( QStringLiteral( "Layer %1 does not have WMS url." ).arg( layer.title ), 3 );
210210
}
211-
if ( wfsURL.length() > 0 )
211+
if ( !wfsURL.isEmpty() )
212212
{
213213
QStandardItem *titleItem = new QStandardItem( layer.title );
214214
QStandardItem *nameItem;
215-
if ( layer.name.length() > 0 )
215+
if ( !layer.name.isEmpty() )
216216
{
217217
nameItem = new QStandardItem( layer.name );
218218
}
@@ -233,13 +233,13 @@ void QgsGeoNodeSourceSelect::connectToGeonodeConnection()
233233
}
234234
else
235235
{
236-
qDebug() << "Layer " << layer.title << " does not have WFS url.";
236+
QgsDebugMsgLevel( QStringLiteral( "Layer %1 does not have WFS url." ).arg( layer.title ), 3 );
237237
}
238-
if ( xyzURL.length() > 0 )
238+
if ( !xyzURL.isEmpty() )
239239
{
240240
QStandardItem *titleItem = new QStandardItem( layer.title );
241241
QStandardItem *nameItem;
242-
if ( layer.name.length() > 0 )
242+
if ( !layer.name.isEmpty() )
243243
{
244244
nameItem = new QStandardItem( layer.name );
245245
}
@@ -260,18 +260,14 @@ void QgsGeoNodeSourceSelect::connectToGeonodeConnection()
260260
}
261261
else
262262
{
263-
qDebug() << "Layer " << layer.title << " does not have XYZ url.";
263+
QgsDebugMsgLevel( QStringLiteral( "Layer %1 does not have XYZ url." ).arg( layer.title ), 3 );
264264
}
265265
}
266266
}
267267

268268
else
269269
{
270-
QMessageBox *box = new QMessageBox( QMessageBox::Critical, tr( "Error" ), tr( "Cannot get any feature services" ), QMessageBox::Ok, this );
271-
box->setAttribute( Qt::WA_DeleteOnClose );
272-
box->setModal( true );
273-
box->setObjectName( QStringLiteral( "GeonodeCapabilitiesErrorBox" ) );
274-
box->open();
270+
QMessageBox::critical( this, tr( "Connect to GeoNode" ), tr( "Cannot get any feature services" ) );
275271
}
276272

277273
treeView->resizeColumnToContents( MODEL_IDX_TITLE );
@@ -297,7 +293,7 @@ void QgsGeoNodeSourceSelect::saveGeonodeConnection()
297293
void QgsGeoNodeSourceSelect::loadGeonodeConnection()
298294
{
299295
QString fileName = QFileDialog::getOpenFileName( this, tr( "Load connections" ), QDir::homePath(),
300-
tr( "XML files (*.xml *XML)" ) );
296+
tr( "XML files (*.xml *.XML)" ) );
301297
if ( fileName.isEmpty() )
302298
{
303299
return;
@@ -323,7 +319,6 @@ void QgsGeoNodeSourceSelect::treeViewSelectionChanged()
323319
QModelIndex currentIndex = treeView->selectionModel()->currentIndex();
324320
if ( !currentIndex.isValid() )
325321
{
326-
qDebug() << "Current index is invalid";
327322
return;
328323
}
329324
addButton()->setEnabled( false );
@@ -349,17 +344,14 @@ void QgsGeoNodeSourceSelect::treeViewSelectionChanged()
349344

350345
void QgsGeoNodeSourceSelect::addButtonClicked()
351346
{
352-
qDebug() << "Add button clicked";
353347
QApplication::setOverrideCursor( Qt::BusyCursor );
354348
// Get selected entry in treeview
355349
QModelIndex currentIndex = treeView->selectionModel()->currentIndex();
356350
if ( !currentIndex.isValid() )
357351
{
358-
qDebug() << "Current index is invalid";
359352
return;
360353
}
361354

362-
QgsGeoNodeConnection connection( cmbConnections->currentText() );
363355
QModelIndexList modelIndexList = treeView->selectionModel()->selectedRows();
364356
for ( int i = 0; i < modelIndexList.size(); i++ )
365357
{
@@ -370,12 +362,9 @@ void QgsGeoNodeSourceSelect::addButtonClicked()
370362
}
371363
int row = idx.row();
372364

373-
qDebug() << "Model index row " << row;
374-
375365
QString typeItem = mModel->item( row, MODEL_IDX_TYPE )->text();
376366
if ( typeItem == tr( "Map" ) )
377367
{
378-
qDebug() << "Skip adding map.";
379368
continue;
380369
}
381370
QString serviceURL = mModel->item( row, MODEL_IDX_TITLE )->data( Qt::UserRole + 2 ).toString();
@@ -388,19 +377,16 @@ void QgsGeoNodeSourceSelect::addButtonClicked()
388377
QString layerName = titleName;
389378
}
390379

391-
qDebug() << "Layer name: " << layerName << " Type: " << webServiceType;
392-
393-
if ( webServiceType == "WMS" )
380+
if ( webServiceType == QStringLiteral( "WMS" ) )
394381
{
395-
qDebug() << "Adding WMS layer of " << layerName;
396382
QgsDataSourceUri uri;
397383
uri.setParam( QStringLiteral( "url" ), serviceURL );
398384

399385
// Set static first, to see that it works. Need to think about the UI also.
400-
QString format( "image/png" );
401-
QString crs( "EPSG:4326" );
402-
QString styles( "" );
403-
QString contextualWMSLegend( "0" );
386+
QString format( QStringLiteral( "image/png" ) );
387+
QString crs( QStringLiteral( "EPSG:4326" ) );
388+
QString styles;
389+
QString contextualWMSLegend( QStringLiteral( "0" ) );
404390

405391
uri.setParam( QStringLiteral( "contextualWMSLegend" ), contextualWMSLegend );
406392
uri.setParam( QStringLiteral( "layers" ), layerName );
@@ -411,24 +397,22 @@ void QgsGeoNodeSourceSelect::addButtonClicked()
411397
QgsDebugMsg( "Add WMS from GeoNode : " + uri.encodedUri() );
412398
emit addRasterLayer( uri.encodedUri(), layerName, QStringLiteral( "wms" ) );
413399
}
414-
else if ( webServiceType == "WFS" )
400+
else if ( webServiceType == QStringLiteral( "WFS" ) )
415401
{
416-
qDebug() << "Adding WFS layer of " << layerName;
417-
418402
// Set static first, to see that it works. Need to think about the UI also.
419403
QString typeName = mModel->item( row, 0 )->data( Qt::UserRole + 3 ).toString();
420-
QString crs( "EPSG:4326" );
404+
QString crs( QStringLiteral( "EPSG:4326" ) );
421405

422406
// typeName, titleName, sql,
423407
// Build url for WFS
424408
// restrictToRequestBBOX='1' srsname='EPSG:26719' typename='geonode:cab_mun' url='http://demo.geonode.org/geoserver/geonode/wms' table=\"\" sql="
425409
QString uri;
426410
uri += QStringLiteral( " restrictToRequestBBOX='1'" );
427411
uri += QStringLiteral( " srsname='%1'" ).arg( crs );
428-
if ( serviceURL.contains( "qgis-server" ) )
412+
if ( serviceURL.contains( QStringLiteral( "qgis-server" ) ) )
429413
{
430414
// I need to do this since the typename used in qgis-server is without the workspace.
431-
QString qgisServerTypeName = QString( typeName ).split( ":" ).last();
415+
QString qgisServerTypeName = QString( typeName ).split( ':' ).last();
432416
uri += QStringLiteral( " typename='%1'" ).arg( qgisServerTypeName );
433417
}
434418
else
@@ -442,7 +426,7 @@ void QgsGeoNodeSourceSelect::addButtonClicked()
442426
QgsDebugMsg( "Add WFS from GeoNode : " + uri + " and typename: " + typeName );
443427
emit addVectorLayer( uri, typeName, QStringLiteral( "WFS" ) );
444428
}
445-
else if ( webServiceType == "XYZ" )
429+
else if ( webServiceType == QStringLiteral( "XYZ" ) )
446430
{
447431
QgsDebugMsg( "XYZ Url: " + serviceURL );
448432
QgsDebugMsg( "Add XYZ from GeoNode : " + serviceURL );

0 commit comments

Comments
 (0)
Please sign in to comment.