QGIS API Documentation  2.99.0-Master (dc72e14)
qgsowssourceselect.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsowssourceselect.cpp - selector for WMS,WFS,WCS
3  -------------------
4  begin : 3 April 2005
5  copyright :
6  original : (C) 2005 by Brendan Morley email : morb at ozemail dot com dot au
7  wms search : (C) 2009 Mathias Walker <mwa at sourcepole.ch>, Sourcepole AG
8  wms-c support : (C) 2010 Juergen E. Fischer < jef at norbit dot de >, norBIT GmbH
9 
10  generalized : (C) 2012 Radim Blazek, based on qgswmssourceselect.cpp
11 
12  ***************************************************************************/
13 
14 /***************************************************************************
15  * *
16  * This program is free software; you can redistribute it and/or modify *
17  * it under the terms of the GNU General Public License as published by *
18  * the Free Software Foundation; either version 2 of the License, or *
19  * (at your option) any later version. *
20  * *
21  ***************************************************************************/
22 
23 #include "qgis.h" // GEO_EPSG_CRS_ID
25 #include "qgsdatasourceuri.h"
27 #include "qgslogger.h"
29 #include "qgsmessageviewer.h"
30 #include "qgsnewhttpconnection.h"
31 #include "qgstreewidgetitem.h"
32 #include "qgsproject.h"
33 #include "qgsproviderregistry.h"
34 #include "qgsowsconnection.h"
35 #include "qgsdataprovider.h"
36 #include "qgsowssourceselect.h"
38 #include "qgsapplication.h"
39 #include "qgssettings.h"
40 
41 #include <QButtonGroup>
42 #include <QFileDialog>
43 #include <QRadioButton>
44 #include <QDomDocument>
45 #include <QHeaderView>
46 #include <QImageReader>
47 #include <QInputDialog>
48 #include <QMap>
49 #include <QMessageBox>
50 #include <QPicture>
51 #include <QUrl>
52 #include <QValidator>
53 #include <QNetworkRequest>
54 #include <QNetworkReply>
55 
56 QgsOWSSourceSelect::QgsOWSSourceSelect( const QString &service, QWidget *parent, Qt::WindowFlags fl, QgsProviderRegistry::WidgetMode theWidgetMode )
57  : QgsAbstractDataSourceWidget( parent, fl, theWidgetMode )
58  , mService( service )
59 
60 {
61  setupUi( this );
62  setupButtons( buttonBox );
63 
64 
65  setWindowTitle( tr( "Add Layer(s) from a %1 Server" ).arg( service ) );
66 
67  clearCrs();
68 
69  mTileWidthLineEdit->setValidator( new QIntValidator( 0, 9999, this ) );
70  mTileHeightLineEdit->setValidator( new QIntValidator( 0, 9999, this ) );
71  mFeatureCountLineEdit->setValidator( new QIntValidator( 0, 9999, this ) );
72 
73  mCacheComboBox->addItem( tr( "Always cache" ), QNetworkRequest::AlwaysCache );
74  mCacheComboBox->addItem( tr( "Prefer cache" ), QNetworkRequest::PreferCache );
75  mCacheComboBox->addItem( tr( "Prefer network" ), QNetworkRequest::PreferNetwork );
76  mCacheComboBox->addItem( tr( "Always network" ), QNetworkRequest::AlwaysNetwork );
77 
78  // 'Prefer network' is the default noted in the combobox's tool tip
79  mCacheComboBox->setCurrentIndex( mCacheComboBox->findData( QNetworkRequest::PreferNetwork ) );
80 
81  if ( widgetMode() != QgsProviderRegistry::WidgetMode::Manager )
82  {
83  //set the current project CRS if available
85  //convert CRS id to epsg
86  if ( currentRefSys.isValid() )
87  {
88  mSelectedCRS = currentRefSys.authid();
89  }
90  }
91  else
92  {
93  mTabWidget->removeTab( mTabWidget->indexOf( mLayerOrderTab ) );
94  mTabWidget->removeTab( mTabWidget->indexOf( mTilesetsTab ) );
95  mTimeWidget->hide();
96  mFormatWidget->hide();
97  mCRSWidget->hide();
98  mCacheWidget->hide();
99  }
100 
101  // set up the WMS connections we already know about
103 
104  QgsSettings settings;
105  QgsDebugMsg( "restoring geometry" );
106  restoreGeometry( settings.value( QStringLiteral( "Windows/WMSSourceSelect/geometry" ) ).toByteArray() );
107 }
108 
110 {
111  QgsSettings settings;
112  QgsDebugMsg( "saving geometry" );
113  settings.setValue( QStringLiteral( "Windows/WMSSourceSelect/geometry" ), saveGeometry() );
114 }
115 
117 {
119 }
120 
122 {
123  mFormatComboBox->clear();
124  mFormatComboBox->setEnabled( false );
125 }
126 
128 {
129 
130  // A server may offer more similar formats, which are mapped
131  // to the same GDAL format, e.g. GeoTIFF and TIFF
132  // -> recreate always buttons for all available formats, enable supported
133 
134  clearFormats();
135 
136  if ( mProviderFormats.isEmpty() )
137  {
138  mProviderFormats = providerFormats();
139  for ( int i = 0; i < mProviderFormats.size(); i++ )
140  {
141  // GDAL mime types may be image/tiff, image/png, ...
142  mMimeLabelMap.insert( mProviderFormats[i].format, mProviderFormats[i].label );
143  }
144  }
145 
146  // selectedLayersFormats may come in various forms:
147  // image/tiff, GTiff, GeoTIFF, TIFF, geotiff_int16, geotiff_rgb,
148  // PNG, GTOPO30, ARCGRID, IMAGEMOSAIC
149  // and even any string defined in server configuration, for example the
150  // value used in UMN Mapserver for OUTPUTFORMAT->NAME is used in
151  // WCS 1.0.0 SupportedFormats/Format
152 
153  // TODO: It is impossible to cover all possible formats coming from server
154  // -> enabled all formats, GDAL may be able to open them
155 
156  QMap<QString, QString> formatsMap;
157  formatsMap.insert( QStringLiteral( "geotiff" ), QStringLiteral( "tiff" ) );
158  formatsMap.insert( QStringLiteral( "gtiff" ), QStringLiteral( "tiff" ) );
159  formatsMap.insert( QStringLiteral( "tiff" ), QStringLiteral( "tiff" ) );
160  formatsMap.insert( QStringLiteral( "tif" ), QStringLiteral( "tiff" ) );
161  formatsMap.insert( QStringLiteral( "gif" ), QStringLiteral( "gif" ) );
162  formatsMap.insert( QStringLiteral( "jpeg" ), QStringLiteral( "jpeg" ) );
163  formatsMap.insert( QStringLiteral( "jpg" ), QStringLiteral( "jpeg" ) );
164  formatsMap.insert( QStringLiteral( "png" ), QStringLiteral( "png" ) );
165 
166  int preferred = -1;
167  QStringList layersFormats = selectedLayersFormats();
168  for ( int i = 0; i < layersFormats.size(); i++ )
169  {
170  QString format = layersFormats.value( i );
171  QgsDebugMsg( "server format = " + format );
172  QString simpleFormat = format.toLower().remove( QStringLiteral( "image/" ) ).remove( QRegExp( "_.*" ) );
173  QgsDebugMsg( "server simpleFormat = " + simpleFormat );
174  QString mimeFormat = "image/" + formatsMap.value( simpleFormat );
175  QgsDebugMsg( "server mimeFormat = " + mimeFormat );
176 
177  QString label = format;
178 
179  if ( mMimeLabelMap.contains( mimeFormat ) )
180  {
181  if ( format != mMimeLabelMap.value( mimeFormat ) )
182  {
183  // Append name of GDAL driver
184  label += " / " + mMimeLabelMap.value( mimeFormat );
185  }
186 
187  if ( simpleFormat.contains( QLatin1String( "tif" ) ) ) // prefer *tif*
188  {
189  if ( preferred < 0 || simpleFormat.startsWith( 'g' ) ) // prefer geotiff
190  {
191  preferred = i;
192  }
193  }
194  }
195  else
196  {
197  // We cannot always say that the format is not supported by GDAL because
198  // server can use strange names, but format itself is supported
199  QgsDebugMsg( QString( "format %1 unknown" ).arg( format ) );
200  }
201 
202  mFormatComboBox->insertItem( i, label );
203  }
204  // Set preferred
205  // TODO: all enabled for now, see above
206  preferred = preferred >= 0 ? preferred : 0;
207  mFormatComboBox->setCurrentIndex( preferred );
208 
209  mFormatComboBox->setEnabled( true );
210 }
211 
213 {
214  mTimeComboBox->clear();
215  mTimeComboBox->insertItems( 0, selectedLayersTimes() );
216  mTimeComboBox->setEnabled( !selectedLayersTimes().isEmpty() );
217 }
218 
220 {
221  mTimeComboBox->clear();
222  mTimeComboBox->setEnabled( false );
223 }
224 
226 {
227  mConnectionsComboBox->clear();
228  mConnectionsComboBox->addItems( QgsOwsConnection::connectionList( mService ) );
229 
231 }
232 
234 {
235  if ( string.compare( QStringLiteral( "wms" ), Qt::CaseInsensitive ) == 0 )
237  else if ( string.compare( QStringLiteral( "wfs" ), Qt::CaseInsensitive ) == 0 )
239  else if ( string.compare( QStringLiteral( "wcs" ), Qt::CaseInsensitive ) == 0 )
241  else
243 }
244 
246 {
248  QgsNewHttpConnection *nc = new QgsNewHttpConnection( this, type, "/qgis/connections-" + mService.toLower() + '/' );
249 
250  if ( nc->exec() )
251  {
253  emit connectionsChanged();
254  }
255 
256  delete nc;
257 }
258 
260 {
262  QgsNewHttpConnection *nc = new QgsNewHttpConnection( this, type, "/qgis/connections-" + mService.toLower() + '/', mConnectionsComboBox->currentText() );
263 
264  if ( nc->exec() )
265  {
267  emit connectionsChanged();
268  }
269 
270  delete nc;
271 }
272 
274 {
275  QString msg = tr( "Are you sure you want to remove the %1 connection and all associated settings?" )
276  .arg( mConnectionsComboBox->currentText() );
277  QMessageBox::StandardButton result = QMessageBox::information( this, tr( "Confirm Delete" ), msg, QMessageBox::Ok | QMessageBox::Cancel );
278  if ( result == QMessageBox::Ok )
279  {
280  QgsOwsConnection::deleteConnection( mService, mConnectionsComboBox->currentText() );
281  mConnectionsComboBox->removeItem( mConnectionsComboBox->currentIndex() ); // populateConnectionList();
283  emit connectionsChanged();
284  }
285 }
286 
288 {
290  dlg.exec();
291 }
292 
294 {
295  QString fileName = QFileDialog::getOpenFileName( this, tr( "Load connections" ), QDir::homePath(),
296  tr( "XML files (*.xml *XML)" ) );
297  if ( fileName.isEmpty() )
298  {
299  return;
300  }
301 
303  dlg.exec();
305  emit connectionsChanged();
306 }
307 
309  int id,
310  const QStringList &names,
311  QMap<int, QgsTreeWidgetItem *> &items,
312  int &layerAndStyleCount,
313  const QMap<int, int> &layerParents,
314  const QMap<int, QStringList> &layerParentNames )
315 {
316  QgsDebugMsg( QString( "id = %1 layerAndStyleCount = %2 names = %3 " ).arg( id ).arg( layerAndStyleCount ).arg( names.join( "," ) ) );
317  if ( items.contains( id ) )
318  return items[id];
319 
320 
321  QgsTreeWidgetItem *item = nullptr;
322  if ( layerParents.contains( id ) )
323  {
324  // it has parent -> create first its parent
325  int parent = layerParents[ id ];
326  item = new QgsTreeWidgetItem( createItem( parent, layerParentNames[ parent ], items, layerAndStyleCount, layerParents, layerParentNames ) );
327  }
328  else
329  item = new QgsTreeWidgetItem( mLayersTreeWidget );
330 
331  item->setText( 0, QString::number( ++layerAndStyleCount ) );
332  item->setText( 1, names[0].simplified() );
333  item->setText( 2, names[1].simplified() );
334  item->setText( 3, names[2].simplified() );
335  item->setToolTip( 3, "<font color=black>" + names[2].simplified() + "</font>" );
336 
337  items[ id ] = item;
338 
339  return item;
340 }
341 
343 {
344 }
345 
347 {
348 
349  mLayersTreeWidget->clear();
350  clearFormats();
351  clearTimes();
352  clearCrs();
353 
354  mConnName = mConnectionsComboBox->currentText();
355 
356  QgsOwsConnection connection( mService, mConnectionsComboBox->currentText() );
357  mUri = connection.uri();
358 
359  QApplication::setOverrideCursor( Qt::WaitCursor );
360 
361  QgsDebugMsg( "call populateLayerList" );
363 
364  QApplication::restoreOverrideCursor();
365 }
366 
367 void QgsOWSSourceSelect::enableLayersForCrs( QTreeWidgetItem * )
368 {
369 }
370 
372 {
373  QStringList layers;
374  Q_FOREACH ( QTreeWidgetItem *item, mLayersTreeWidget->selectedItems() )
375  {
376  QString layer = item->data( 0, Qt::UserRole + 0 ).toString();
377  if ( !layer.isEmpty() )
378  layers << layer;
379  }
380 
382  mySelector->setMessage( QString() );
383  mySelector->setOgcWmsCrsFilter( mSelectedLayersCRSs );
384 
386  if ( defaultCRS.isValid() )
387  {
388  mySelector->setCrs( defaultCRS );
389  }
390 
391  if ( !mySelector->exec() )
392  return;
393 
394  mSelectedCRS = mySelector->crs().authid();
395  delete mySelector;
396 
397  mSelectedCRSLabel->setText( descriptionForAuthId( mSelectedCRS ) );
398 
399  for ( int i = 0; i < mLayersTreeWidget->topLevelItemCount(); i++ )
400  {
401  enableLayersForCrs( mLayersTreeWidget->topLevelItem( i ) );
402  }
403 
404  updateButtons();
405 }
406 
408 {
409 }
410 
412 {
413  clearCrs();
414  mSelectedLayersCRSs = selectedLayersCrses().toSet();
415  mCRSLabel->setText( tr( "Coordinate Reference System (%n available)", "crs count", mSelectedLayersCRSs.count() ) + ':' );
416 
417  mChangeCRSButton->setDisabled( mSelectedLayersCRSs.isEmpty() );
418 
419  if ( !mSelectedLayersCRSs.isEmpty() )
420  {
421  // check whether current CRS is supported
422  // if not, use one of the available CRS
423  QString defaultCRS;
424  QSet<QString>::const_iterator it = mSelectedLayersCRSs.constBegin();
425  for ( ; it != mSelectedLayersCRSs.constEnd(); ++it )
426  {
427  if ( it->compare( mSelectedCRS, Qt::CaseInsensitive ) == 0 )
428  break;
429 
430  // save first CRS in case the current CRS is not available
431  if ( it == mSelectedLayersCRSs.constBegin() )
432  defaultCRS = *it;
433 
434  // prefer value of DEFAULT_GEO_EPSG_CRS_ID if available
435  if ( *it == GEO_EPSG_CRS_AUTHID )
436  defaultCRS = *it;
437  }
438 
439  if ( it == mSelectedLayersCRSs.constEnd() )
440  {
441  // not found
442  mSelectedCRS = defaultCRS;
443  }
444  mSelectedCRSLabel->setText( descriptionForAuthId( mSelectedCRS ) );
445  mChangeCRSButton->setEnabled( true );
446  }
447  QgsDebugMsg( "mSelectedCRS = " + mSelectedCRS );
448 }
449 
451 {
452  mCRSLabel->setText( tr( "Coordinate Reference System" ) + ':' );
453  mSelectedCRS = QLatin1String( "" );
454  mSelectedCRSLabel->setText( QLatin1String( "" ) );
455  mChangeCRSButton->setEnabled( false );
456 }
457 
458 void QgsOWSSourceSelect::on_mTilesetsTableWidget_itemClicked( QTableWidgetItem *item )
459 {
460  Q_UNUSED( item );
461 
462  QTableWidgetItem *rowItem = mTilesetsTableWidget->item( mTilesetsTableWidget->currentRow(), 0 );
463  bool wasSelected = mCurrentTileset == rowItem;
464 
465  mTilesetsTableWidget->blockSignals( true );
466  mTilesetsTableWidget->clearSelection();
467  if ( !wasSelected )
468  {
469  QgsDebugMsg( QString( "selecting current row %1" ).arg( mTilesetsTableWidget->currentRow() ) );
470  mTilesetsTableWidget->selectRow( mTilesetsTableWidget->currentRow() );
471  mCurrentTileset = rowItem;
472  }
473  else
474  {
475  mCurrentTileset = nullptr;
476  }
477  mTilesetsTableWidget->blockSignals( false );
478 
479  updateButtons();
480 }
481 
482 
483 
485 {
486  return mConnName;
487 }
488 
490 {
491  return mConnectionInfo;
492 }
493 
495 {
496  return selectedLayersFormats().value( mFormatComboBox->currentIndex() );
497 }
498 
499 QNetworkRequest::CacheLoadControl QgsOWSSourceSelect::selectedCacheLoadControl()
500 {
501  int cache = mCacheComboBox->currentData().toInt();
502  return static_cast<QNetworkRequest::CacheLoadControl>( cache );
503 }
504 
506 {
507  return mSelectedCRS;
508 }
509 
511 {
512  return mTimeComboBox->currentText();
513 }
514 
516 {
517  QString toSelect = QgsOwsConnection::selectedConnection( mService );
518 
519  mConnectionsComboBox->setCurrentIndex( mConnectionsComboBox->findText( toSelect ) );
520 
521  if ( mConnectionsComboBox->currentIndex() < 0 )
522  {
523  if ( toSelect.isNull() )
524  mConnectionsComboBox->setCurrentIndex( 0 );
525  else
526  mConnectionsComboBox->setCurrentIndex( mConnectionsComboBox->count() - 1 );
527  }
528 
529  if ( mConnectionsComboBox->count() == 0 )
530  {
531  // No connections - disable various buttons
532  mConnectButton->setEnabled( false );
533  mEditButton->setEnabled( false );
534  mDeleteButton->setEnabled( false );
535  mSaveButton->setEnabled( false );
536  }
537  else
538  {
539  // Connections - enable various buttons
540  mConnectButton->setEnabled( true );
541  mEditButton->setEnabled( true );
542  mDeleteButton->setEnabled( true );
543  mSaveButton->setEnabled( true );
544  }
545 
546  QgsOwsConnection::setSelectedConnection( mService, mConnectionsComboBox->currentText() );
547 }
548 
549 void QgsOWSSourceSelect::showStatusMessage( QString const &message )
550 {
551  mStatusLabel->setText( message );
552 
553  // update the display of this widget
554  update();
555 }
556 
557 
558 void QgsOWSSourceSelect::showError( QString const &title, QString const &format, QString const &error )
559 {
560  QgsMessageViewer *mv = new QgsMessageViewer( this );
561  mv->setWindowTitle( title );
562 
563  if ( format == QLatin1String( "text/html" ) )
564  {
565  mv->setMessageAsHtml( error );
566  }
567  else
568  {
569  mv->setMessageAsPlainText( tr( "Could not understand the response:\n%1" ).arg( error ) );
570  }
571  mv->showMessage( true ); // Is deleted when closed
572 }
573 
575 {
576  // Remember which server was selected.
577  QgsOwsConnection::setSelectedConnection( mService, mConnectionsComboBox->currentText() );
578 }
579 
581 {
583 }
584 
585 QString QgsOWSSourceSelect::descriptionForAuthId( const QString &authId )
586 {
587  if ( mCrsNames.contains( authId ) )
588  return mCrsNames[ authId ];
589 
591  mCrsNames.insert( authId, qgisSrs.description() );
592  return qgisSrs.description();
593 }
594 
596 {
597  QMap<QString, QString> exampleServers;
598  exampleServers[QStringLiteral( "DM Solutions GMap" )] = QStringLiteral( "http://www2.dmsolutions.ca/cgi-bin/mswms_gmap" );
599  exampleServers[QStringLiteral( "Lizardtech server" )] = QStringLiteral( "http://wms.lizardtech.com/lizardtech/iserv/ows" );
600  // Nice to have the qgis users map, but I'm not sure of the URL at the moment.
601  // exampleServers["Qgis users map"] = "http://qgis.org/wms.cgi";
602 
603  QgsSettings settings;
604  settings.beginGroup( "/qgis/connections-" + mService.toLower() );
605  QMap<QString, QString>::const_iterator i = exampleServers.constBegin();
606  for ( ; i != exampleServers.constEnd(); ++i )
607  {
608  // Only do a server if it's name doesn't already exist.
609  QStringList keys = settings.childGroups();
610  if ( !keys.contains( i.key() ) )
611  {
612  QString path = i.key();
613  settings.setValue( path + "/url", i.value() );
614  }
615  }
616  settings.endGroup();
618 
619  QMessageBox::information( this, tr( "WMS proxies" ), "<p>" + tr( "Several WMS servers have "
620  "been added to the server list. Note that if "
621  "you access the internet via a web proxy, you will "
622  "need to set the proxy settings in the QGIS options dialog." ) + "</p>" );
623 }
624 
625 void QgsOWSSourceSelect::addWmsListRow( const QDomElement &item, int row )
626 {
627  QDomElement title = item.firstChildElement( QStringLiteral( "title" ) );
628  addWmsListItem( title, row, 0 );
629  QDomElement description = item.firstChildElement( QStringLiteral( "description" ) );
630  addWmsListItem( description, row, 1 );
631  QDomElement link = item.firstChildElement( QStringLiteral( "link" ) );
632  addWmsListItem( link, row, 2 );
633 }
634 
635 void QgsOWSSourceSelect::addWmsListItem( const QDomElement &el, int row, int column )
636 {
637  if ( !el.isNull() )
638  {
639  QTableWidgetItem *tableItem = new QTableWidgetItem( el.text() );
640  // TODO: add linebreaks to long tooltips?
641  tableItem->setToolTip( el.text() );
642  mSearchTableWidget->setItem( row, column, tableItem );
643  }
644 }
645 
646 void QgsOWSSourceSelect::on_mSearchButton_clicked()
647 {
648  // clear results
649  mSearchTableWidget->clearContents();
650  mSearchTableWidget->setRowCount( 0 );
651 
652  // disable Add WMS button
653  mSearchAddButton->setEnabled( false );
654 
655  QApplication::setOverrideCursor( Qt::WaitCursor );
656 
657  QgsSettings settings;
658  // geopole.org (geopole.ch) 25.4.2012 : 503 Service Unavailable, archive: Recently added 20 Jul 2011
659  QString mySearchUrl = settings.value( QStringLiteral( "qgis/WMSSearchUrl" ), "http://geopole.org/wms/search?search=%1&type=rss" ).toString();
660  QUrl url( mySearchUrl.arg( mSearchTermLineEdit->text() ) );
661  QgsDebugMsg( url.toString() );
662 
663  QNetworkReply *r = QgsNetworkAccessManager::instance()->get( QNetworkRequest( url ) );
664  connect( r, &QNetworkReply::finished, this, &QgsOWSSourceSelect::searchFinished );
665 }
666 
668 {
669  QApplication::restoreOverrideCursor();
670 
671  QNetworkReply *r = qobject_cast<QNetworkReply *>( sender() );
672  if ( !r )
673  return;
674 
675  if ( r->error() == QNetworkReply::NoError )
676  {
677  // parse results
678  QDomDocument doc( QStringLiteral( "RSS" ) );
679  QByteArray res = r->readAll();
680  QString error;
681  int line, column;
682  if ( doc.setContent( res, &error, &line, &column ) )
683  {
684  QDomNodeList list = doc.elementsByTagName( QStringLiteral( "item" ) );
685  mSearchTableWidget->setRowCount( list.size() );
686  for ( int i = 0; i < list.size(); i++ )
687  {
688  if ( list.item( i ).isElement() )
689  {
690  QDomElement item = list.item( i ).toElement();
691  addWmsListRow( item, i );
692  }
693  }
694 
695  mSearchTableWidget->resizeColumnsToContents();
696  }
697  else
698  {
699  QgsDebugMsg( "setContent failed" );
700  showStatusMessage( tr( "parse error at row %1, column %2: %3" ).arg( line ).arg( column ).arg( error ) );
701  }
702  }
703  else
704  {
705  showStatusMessage( tr( "network error: %1" ).arg( r->error() ) );
706  }
707 
708  r->deleteLater();
709 }
710 
711 void QgsOWSSourceSelect::on_mSearchTableWidget_itemSelectionChanged()
712 {
713  mSearchAddButton->setEnabled( mSearchTableWidget->currentRow() != -1 );
714 }
715 
716 void QgsOWSSourceSelect::on_mLayerUpButton_clicked()
717 {
718  QList<QTreeWidgetItem *> selectionList = mLayerOrderTreeWidget->selectedItems();
719  if ( selectionList.empty() )
720  {
721  return;
722  }
723  int selectedIndex = mLayerOrderTreeWidget->indexOfTopLevelItem( selectionList[0] );
724  if ( selectedIndex < 1 )
725  {
726  return; //item not existing or already on top
727  }
728 
729  QTreeWidgetItem *selectedItem = mLayerOrderTreeWidget->takeTopLevelItem( selectedIndex );
730  mLayerOrderTreeWidget->insertTopLevelItem( selectedIndex - 1, selectedItem );
731  mLayerOrderTreeWidget->clearSelection();
732  selectedItem->setSelected( true );
733 }
734 
735 void QgsOWSSourceSelect::on_mLayerDownButton_clicked()
736 {
737  QList<QTreeWidgetItem *> selectionList = mLayerOrderTreeWidget->selectedItems();
738  if ( selectionList.empty() )
739  {
740  return;
741  }
742  int selectedIndex = mLayerOrderTreeWidget->indexOfTopLevelItem( selectionList[0] );
743  if ( selectedIndex < 0 || selectedIndex > mLayerOrderTreeWidget->topLevelItemCount() - 2 )
744  {
745  return; //item not existing or already at bottom
746  }
747 
748  QTreeWidgetItem *selectedItem = mLayerOrderTreeWidget->takeTopLevelItem( selectedIndex );
749  mLayerOrderTreeWidget->insertTopLevelItem( selectedIndex + 1, selectedItem );
750  mLayerOrderTreeWidget->clearSelection();
751  selectedItem->setSelected( true );
752 }
753 
754 QList<QgsOWSSourceSelect::SupportedFormat> QgsOWSSourceSelect::providerFormats()
755 {
756  return QList<SupportedFormat>();
757 }
758 
760 {
761  return QStringList();
762 }
763 
765 {
766  return QStringList();
767 }
768 
770 {
771  return QStringList();
772 }
773 
774 void QgsOWSSourceSelect::updateButtons()
775 {
776 }
void on_mNewButton_clicked()
Opens the create connection dialog to build a new connection.
QStringList childGroups() const
Returns a list of all key top-level groups that contain keys that can be read using the QSettings obj...
void endGroup()
Resets the group to what it was before the corresponding beginGroup() call.
Definition: qgssettings.cpp:95
WidgetMode
Different ways a source select dialog can be used (embedded is for the data source manager dialog) ...
void setupButtons(QDialogButtonBox *buttonBox)
Connect the ok and apply/add buttons to the slots.
QMap< QString, QString > mCrsNames
void populateCrs()
Set supported CRSs.
virtual void populateLayerList()
Populate the layer list.
void clearTimes()
Clear times.
This class is a composition of two QSettings instances:
Definition: qgssettings.h:54
Abstract base Data Source Widget to create connections and add layers This class provides common func...
QString connectionInfo()
Connection info (uri)
void beginGroup(const QString &prefix)
Appends prefix to the current group.
Definition: qgssettings.cpp:86
#define QgsDebugMsg(str)
Definition: qgslogger.h:37
QgsNewHttpConnection::ConnectionType connectionTypeFromServiceString(const QString &string)
void setMessage(const QString &message)
Sets a message to show in the dialog.
QgsOWSSourceSelect(const QString &service, QWidget *parent=nullptr, Qt::WindowFlags fl=QgsGuiUtils::ModalDialogFlags, QgsProviderRegistry::WidgetMode widgetMode=QgsProviderRegistry::WidgetMode::None)
Constructor.
QString selectedFormat()
Returns currently selected format.
void on_mChangeCRSButton_clicked()
Opens the Spatial Reference System dialog.
virtual QStringList selectedLayersCrses()
Server CRS supported for currently selected layer item(s)
static QStringList connectionList(const QString &service)
Returns the list of connections for the specified service.
QString descriptionForAuthId(const QString &authId)
Returns a textual description for the authority id.
virtual QStringList selectedLayersFormats()
List of formats supported for currently selected layer item(s)
QgsCoordinateReferenceSystem crs() const
Returns the CRS currently selected in the widget.
QNetworkRequest::CacheLoadControl selectedCacheLoadControl()
Returns currently selected cache load control.
void on_mConnectionsComboBox_activated(int)
Stores the selected datasource whenerver it is changed.
A generic dialog to prompt the user for a Coordinate Reference System.
void setMessageAsHtml(const QString &msg)
void populateConnectionList()
Populate the connection list combo box.
void setValue(const QString &key, const QVariant &value, const QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.
void addWmsListItem(const QDomElement &el, int row, int column)
virtual void enableLayersForCrs(QTreeWidgetItem *item)
void addDefaultServers()
Add a few example servers to the list.
void on_mConnectButton_clicked()
Connects to the database using the stored connection parameters.
QgsCoordinateReferenceSystem crs
Definition: qgsproject.h:85
void on_mEditButton_clicked()
Opens a dialog to edit an existing connection.
void setMessageAsPlainText(const QString &msg)
QString description() const
Returns the descriptive name of the CRS, e.g., "WGS 84" or "GDA 94 / Vicgrid94".
QgsProviderRegistry::WidgetMode widgetMode() const
Return the widget mode.
const QString GEO_EPSG_CRS_AUTHID
Geographic coord sys from EPSG authority.
Definition: qgis.cpp:69
static void setSelectedConnection(const QString &service, const QString &name)
Marks the specified connection for the specified service as selected.
void populateFormats()
Populate supported formats.
Connections management.
void clearCrs()
Clear CRSs.
virtual QStringList selectedLayersTimes()
List of times (temporalDomain timePosition/timePeriod for currently selected layer item(s) ...
virtual void showMessage(bool blocking=true) override
display the message to the user and deletes itself
void on_mLoadButton_clicked()
Loads connections from the file.
void setCrs(const QgsCoordinateReferenceSystem &crs)
Sets the initial crs to show within the dialog.
void on_mAddDefaultButton_clicked()
Add some default wms servers to the list.
virtual void on_mLayersTreeWidget_itemSelectionChanged()
Signaled when a layer selection is changed.
void on_mDeleteButton_clicked()
Deletes the selected connection.
QString uri(bool expandAuthConfig=true) const
return complete uri
void setOgcWmsCrsFilter(const QSet< QString > &crsFilter)
filters this dialog by the given CRSs
ConnectionType
Available connection types for configuring in the dialog.
QString connName()
Connection name.
void showStatusMessage(const QString &message)
Set status message to theMessage.
static QgsCoordinateReferenceSystem fromOgcWmsCrs(const QString &ogcCrs)
Creates a CRS from a given OGC WMS-format Coordinate Reference System string.
QString mConnectionInfo
Connection info for selected connection.
static QgsNetworkAccessManager * instance()
returns a pointer to the single instance
QTreeWidgetItem subclass with custom handling for item sorting.
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), const Section section=NoSection) const
Returns the value for setting key.
void showError(const QString &title, const QString &format, const QString &error)
show whatever error is exposed.
static QgsProject * instance()
Returns the QgsProject singleton instance.
Definition: qgsproject.cpp:379
This class represents a coordinate reference system (CRS).
A generic message view for displaying QGIS messages.
virtual QList< QgsOWSSourceSelect::SupportedFormat > providerFormats()
List of image formats (encodings) supported by provider.
void connectionsChanged()
Emitted when the provider&#39;s connections have changed This signal is normally forwarded the app and us...
void refresh() override
Triggered when the provider&#39;s connections need to be refreshed.
void on_mSaveButton_clicked()
Saves connections to the file.
QString selectedTime()
Returns currently selected time.
void addWmsListRow(const QDomElement &item, int row)
void clearFormats()
Clear previously set formats.
QString mService
Service name.
QTableWidgetItem * mCurrentTileset
Dialog to allow the user to configure and save connection information for an HTTP Server for WMS...
void setConnectionListPosition()
Set the server connection combo box to that stored in the config file.
QgsTreeWidgetItem * createItem(int id, const QStringList &names, QMap< int, QgsTreeWidgetItem *> &items, int &layerAndStyleCount, const QMap< int, int > &layerParents, const QMap< int, QStringList > &layerParentNames)
create an item including possible parents
QgsDataSourceUri mUri
URI for selected connection.
void populateTimes()
Populate times.
static QString selectedConnection(const QString &service)
Retrieves the selected connection for the specified service.
QString authid() const
Returns the authority identifier for the CRS.
QString mConnName
Name for selected connection.
QString selectedCrs()
Returns currently selected Crs.
static void deleteConnection(const QString &service, const QString &name)
Deletes the connection for the specified service with the specified name.
bool isValid() const
Returns whether this CRS is correctly initialized and usable.