QGIS API Documentation  2.99.0-Master (dcec6bb)
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
24 #include "qgscontexthelp.h"
26 #include "qgsdatasourceuri.h"
28 #include "qgslogger.h"
30 #include "qgsmessageviewer.h"
31 #include "qgsnewhttpconnection.h"
32 #include "qgstreewidgetitem.h"
33 #include "qgsproject.h"
34 #include "qgsproviderregistry.h"
35 #include "qgsowsconnection.h"
36 #include "qgsdataprovider.h"
37 #include "qgsowssourceselect.h"
39 #include "qgsapplication.h"
40 #include "qgssettings.h"
41 
42 #include <QButtonGroup>
43 #include <QFileDialog>
44 #include <QRadioButton>
45 #include <QDomDocument>
46 #include <QHeaderView>
47 #include <QImageReader>
48 #include <QInputDialog>
49 #include <QMap>
50 #include <QMessageBox>
51 #include <QPicture>
52 #include <QUrl>
53 #include <QValidator>
54 #include <QNetworkRequest>
55 #include <QNetworkReply>
56 
57 QgsOWSSourceSelect::QgsOWSSourceSelect( const QString &service, QWidget *parent, Qt::WindowFlags fl, QgsProviderRegistry::WidgetMode theWidgetMode )
58  : QgsAbstractDataSourceWidget( parent, fl, theWidgetMode )
59  , mService( service )
60  , mCurrentTileset( nullptr )
61 {
62  setupUi( this );
63 
64  if ( widgetMode() != QgsProviderRegistry::WidgetMode::None )
65  {
66  buttonBox->removeButton( buttonBox->button( QDialogButtonBox::Close ) );
67  }
68 
69 
70  setWindowTitle( tr( "Add Layer(s) from a %1 Server" ).arg( service ) );
71 
72  mAddButton = buttonBox->button( QDialogButtonBox::Apply );
73  mAddButton->setText( tr( "&Add" ) );
74  mAddButton->setToolTip( tr( "Add selected layers to map" ) );
75  mAddButton->setEnabled( false );
76 
77  clearCrs();
78 
79  mTileWidthLineEdit->setValidator( new QIntValidator( 0, 9999, this ) );
80  mTileHeightLineEdit->setValidator( new QIntValidator( 0, 9999, this ) );
81  mFeatureCountLineEdit->setValidator( new QIntValidator( 0, 9999, this ) );
82 
83  mCacheComboBox->addItem( tr( "Always cache" ), QNetworkRequest::AlwaysCache );
84  mCacheComboBox->addItem( tr( "Prefer cache" ), QNetworkRequest::PreferCache );
85  mCacheComboBox->addItem( tr( "Prefer network" ), QNetworkRequest::PreferNetwork );
86  mCacheComboBox->addItem( tr( "Always network" ), QNetworkRequest::AlwaysNetwork );
87 
88  // 'Prefer network' is the default noted in the combobox's tool tip
89  mCacheComboBox->setCurrentIndex( mCacheComboBox->findData( QNetworkRequest::PreferNetwork ) );
90 
91  if ( widgetMode() != QgsProviderRegistry::WidgetMode::Manager )
92  {
93  connect( mAddButton, &QAbstractButton::clicked, this, &QgsOWSSourceSelect::addClicked );
94  //set the current project CRS if available
96  //convert CRS id to epsg
97  if ( currentRefSys.isValid() )
98  {
99  mSelectedCRS = currentRefSys.authid();
100  }
101  }
102  else
103  {
104  mTabWidget->removeTab( mTabWidget->indexOf( mLayerOrderTab ) );
105  mTabWidget->removeTab( mTabWidget->indexOf( mTilesetsTab ) );
106  mTimeWidget->hide();
107  mFormatWidget->hide();
108  mCRSWidget->hide();
109  mAddButton->hide();
110  mCacheWidget->hide();
111  }
112 
113  // set up the WMS connections we already know about
115 
116  QgsSettings settings;
117  QgsDebugMsg( "restoring geometry" );
118  restoreGeometry( settings.value( QStringLiteral( "Windows/WMSSourceSelect/geometry" ) ).toByteArray() );
119 }
120 
122 {
123  QgsSettings settings;
124  QgsDebugMsg( "saving geometry" );
125  settings.setValue( QStringLiteral( "Windows/WMSSourceSelect/geometry" ), saveGeometry() );
126 }
127 
129 {
131 }
132 
134 {
135  mFormatComboBox->clear();
136  mFormatComboBox->setEnabled( false );
137 }
138 
140 {
141 
142  // A server may offer more similar formats, which are mapped
143  // to the same GDAL format, e.g. GeoTIFF and TIFF
144  // -> recreate always buttons for all available formats, enable supported
145 
146  clearFormats();
147 
148  if ( mProviderFormats.isEmpty() )
149  {
150  mProviderFormats = providerFormats();
151  for ( int i = 0; i < mProviderFormats.size(); i++ )
152  {
153  // GDAL mime types may be image/tiff, image/png, ...
154  mMimeLabelMap.insert( mProviderFormats[i].format, mProviderFormats[i].label );
155  }
156  }
157 
158  // selectedLayersFormats may come in various forms:
159  // image/tiff, GTiff, GeoTIFF, TIFF, geotiff_int16, geotiff_rgb,
160  // PNG, GTOPO30, ARCGRID, IMAGEMOSAIC
161  // and even any string defined in server configuration, for example the
162  // value used in UMN Mapserver for OUTPUTFORMAT->NAME is used in
163  // WCS 1.0.0 SupportedFormats/Format
164 
165  // TODO: It is impossible to cover all possible formats coming from server
166  // -> enabled all formats, GDAL may be able to open them
167 
168  QMap<QString, QString> formatsMap;
169  formatsMap.insert( QStringLiteral( "geotiff" ), QStringLiteral( "tiff" ) );
170  formatsMap.insert( QStringLiteral( "gtiff" ), QStringLiteral( "tiff" ) );
171  formatsMap.insert( QStringLiteral( "tiff" ), QStringLiteral( "tiff" ) );
172  formatsMap.insert( QStringLiteral( "tif" ), QStringLiteral( "tiff" ) );
173  formatsMap.insert( QStringLiteral( "gif" ), QStringLiteral( "gif" ) );
174  formatsMap.insert( QStringLiteral( "jpeg" ), QStringLiteral( "jpeg" ) );
175  formatsMap.insert( QStringLiteral( "jpg" ), QStringLiteral( "jpeg" ) );
176  formatsMap.insert( QStringLiteral( "png" ), QStringLiteral( "png" ) );
177 
178  int preferred = -1;
179  QStringList layersFormats = selectedLayersFormats();
180  for ( int i = 0; i < layersFormats.size(); i++ )
181  {
182  QString format = layersFormats.value( i );
183  QgsDebugMsg( "server format = " + format );
184  QString simpleFormat = format.toLower().remove( QStringLiteral( "image/" ) ).remove( QRegExp( "_.*" ) );
185  QgsDebugMsg( "server simpleFormat = " + simpleFormat );
186  QString mimeFormat = "image/" + formatsMap.value( simpleFormat );
187  QgsDebugMsg( "server mimeFormat = " + mimeFormat );
188 
189  QString label = format;
190 
191  if ( mMimeLabelMap.contains( mimeFormat ) )
192  {
193  if ( format != mMimeLabelMap.value( mimeFormat ) )
194  {
195  // Append name of GDAL driver
196  label += " / " + mMimeLabelMap.value( mimeFormat );
197  }
198 
199  if ( simpleFormat.contains( QLatin1String( "tif" ) ) ) // prefer *tif*
200  {
201  if ( preferred < 0 || simpleFormat.startsWith( 'g' ) ) // prefer geotiff
202  {
203  preferred = i;
204  }
205  }
206  }
207  else
208  {
209  // We cannot always say that the format is not supported by GDAL because
210  // server can use strange names, but format itself is supported
211  QgsDebugMsg( QString( "format %1 unknown" ).arg( format ) );
212  }
213 
214  mFormatComboBox->insertItem( i, label );
215  }
216  // Set preferred
217  // TODO: all enabled for now, see above
218  preferred = preferred >= 0 ? preferred : 0;
219  mFormatComboBox->setCurrentIndex( preferred );
220 
221  mFormatComboBox->setEnabled( true );
222 }
223 
225 {
226  mTimeComboBox->clear();
227  mTimeComboBox->insertItems( 0, selectedLayersTimes() );
228  mTimeComboBox->setEnabled( !selectedLayersTimes().isEmpty() );
229 }
230 
232 {
233  mTimeComboBox->clear();
234  mTimeComboBox->setEnabled( false );
235 }
236 
238 {
239  mConnectionsComboBox->clear();
240  mConnectionsComboBox->addItems( QgsOwsConnection::connectionList( mService ) );
241 
243 }
245 {
246  QgsNewHttpConnection *nc = new QgsNewHttpConnection( this, "/Qgis/connections-" + mService.toLower() + '/' );
247 
248  if ( nc->exec() )
249  {
251  emit connectionsChanged();
252  }
253 
254  delete nc;
255 }
256 
258 {
259  QgsNewHttpConnection *nc = new QgsNewHttpConnection( this, "/Qgis/connections-" + mService.toLower() + '/', mConnectionsComboBox->currentText() );
260 
261  if ( nc->exec() )
262  {
264  emit connectionsChanged();
265  }
266 
267  delete nc;
268 }
269 
271 {
272  QString msg = tr( "Are you sure you want to remove the %1 connection and all associated settings?" )
273  .arg( mConnectionsComboBox->currentText() );
274  QMessageBox::StandardButton result = QMessageBox::information( this, tr( "Confirm Delete" ), msg, QMessageBox::Ok | QMessageBox::Cancel );
275  if ( result == QMessageBox::Ok )
276  {
277  QgsOwsConnection::deleteConnection( mService, mConnectionsComboBox->currentText() );
278  mConnectionsComboBox->removeItem( mConnectionsComboBox->currentIndex() ); // populateConnectionList();
280  emit connectionsChanged();
281  }
282 }
283 
285 {
287  dlg.exec();
288 }
289 
291 {
292  QString fileName = QFileDialog::getOpenFileName( this, tr( "Load connections" ), QDir::homePath(),
293  tr( "XML files (*.xml *XML)" ) );
294  if ( fileName.isEmpty() )
295  {
296  return;
297  }
298 
300  dlg.exec();
302  emit connectionsChanged();
303 }
304 
306  int id,
307  const QStringList &names,
308  QMap<int, QgsTreeWidgetItem *> &items,
309  int &layerAndStyleCount,
310  const QMap<int, int> &layerParents,
311  const QMap<int, QStringList> &layerParentNames )
312 {
313  QgsDebugMsg( QString( "id = %1 layerAndStyleCount = %2 names = %3 " ).arg( id ).arg( layerAndStyleCount ).arg( names.join( "," ) ) );
314  if ( items.contains( id ) )
315  return items[id];
316 
317 
318  QgsTreeWidgetItem *item = nullptr;
319  if ( layerParents.contains( id ) )
320  {
321  // it has parent -> create first its parent
322  int parent = layerParents[ id ];
323  item = new QgsTreeWidgetItem( createItem( parent, layerParentNames[ parent ], items, layerAndStyleCount, layerParents, layerParentNames ) );
324  }
325  else
326  item = new QgsTreeWidgetItem( mLayersTreeWidget );
327 
328  item->setText( 0, QString::number( ++layerAndStyleCount ) );
329  item->setText( 1, names[0].simplified() );
330  item->setText( 2, names[1].simplified() );
331  item->setText( 3, names[2].simplified() );
332  item->setToolTip( 3, "<font color=black>" + names[2].simplified() + "</font>" );
333 
334  items[ id ] = item;
335 
336  return item;
337 }
338 
340 {
341 }
342 
344 {
345 
346  mLayersTreeWidget->clear();
347  clearFormats();
348  clearTimes();
349  clearCrs();
350 
351  mConnName = mConnectionsComboBox->currentText();
352 
353  QgsOwsConnection connection( mService, mConnectionsComboBox->currentText() );
354  mUri = connection.uri();
355 
356  QApplication::setOverrideCursor( Qt::WaitCursor );
357 
358  QgsDebugMsg( "call populateLayerList" );
360 
361  QApplication::restoreOverrideCursor();
362 }
363 
365 {
366 }
367 
368 void QgsOWSSourceSelect::enableLayersForCrs( QTreeWidgetItem * )
369 {
370 }
371 
373 {
374  QStringList layers;
375  Q_FOREACH ( QTreeWidgetItem *item, mLayersTreeWidget->selectedItems() )
376  {
377  QString layer = item->data( 0, Qt::UserRole + 0 ).toString();
378  if ( !layer.isEmpty() )
379  layers << layer;
380  }
381 
383  mySelector->setMessage( QString() );
384  mySelector->setOgcWmsCrsFilter( mSelectedLayersCRSs );
385 
387  if ( defaultCRS.isValid() )
388  {
389  mySelector->setCrs( defaultCRS );
390  }
391 
392  if ( !mySelector->exec() )
393  return;
394 
395  mSelectedCRS = mySelector->crs().authid();
396  delete mySelector;
397 
398  mSelectedCRSLabel->setText( descriptionForAuthId( mSelectedCRS ) );
399 
400  for ( int i = 0; i < mLayersTreeWidget->topLevelItemCount(); i++ )
401  {
402  enableLayersForCrs( mLayersTreeWidget->topLevelItem( i ) );
403  }
404 
405  updateButtons();
406 }
407 
409 {
410 }
411 
413 {
414  clearCrs();
415  mSelectedLayersCRSs = selectedLayersCrses().toSet();
416  mCRSLabel->setText( tr( "Coordinate Reference System (%n available)", "crs count", mSelectedLayersCRSs.count() ) + ':' );
417 
418  mChangeCRSButton->setDisabled( mSelectedLayersCRSs.isEmpty() );
419 
420  if ( !mSelectedLayersCRSs.isEmpty() )
421  {
422  // check whether current CRS is supported
423  // if not, use one of the available CRS
424  QString defaultCRS;
425  QSet<QString>::const_iterator it = mSelectedLayersCRSs.constBegin();
426  for ( ; it != mSelectedLayersCRSs.constEnd(); ++it )
427  {
428  if ( it->compare( mSelectedCRS, Qt::CaseInsensitive ) == 0 )
429  break;
430 
431  // save first CRS in case the current CRS is not available
432  if ( it == mSelectedLayersCRSs.begin() )
433  defaultCRS = *it;
434 
435  // prefer value of DEFAULT_GEO_EPSG_CRS_ID if available
436  if ( *it == GEO_EPSG_CRS_AUTHID )
437  defaultCRS = *it;
438  }
439 
440  if ( it == mSelectedLayersCRSs.end() )
441  {
442  // not found
443  mSelectedCRS = defaultCRS;
444  }
445  mSelectedCRSLabel->setText( descriptionForAuthId( mSelectedCRS ) );
446  mChangeCRSButton->setEnabled( true );
447  }
448  QgsDebugMsg( "mSelectedCRS = " + mSelectedCRS );
449 }
450 
452 {
453  mCRSLabel->setText( tr( "Coordinate Reference System" ) + ':' );
454  mSelectedCRS = QLatin1String( "" );
455  mSelectedCRSLabel->setText( QLatin1String( "" ) );
456  mChangeCRSButton->setEnabled( false );
457 }
458 
459 void QgsOWSSourceSelect::on_mTilesetsTableWidget_itemClicked( QTableWidgetItem *item )
460 {
461  Q_UNUSED( item );
462 
463  QTableWidgetItem *rowItem = mTilesetsTableWidget->item( mTilesetsTableWidget->currentRow(), 0 );
464  bool wasSelected = mCurrentTileset == rowItem;
465 
466  mTilesetsTableWidget->blockSignals( true );
467  mTilesetsTableWidget->clearSelection();
468  if ( !wasSelected )
469  {
470  QgsDebugMsg( QString( "selecting current row %1" ).arg( mTilesetsTableWidget->currentRow() ) );
471  mTilesetsTableWidget->selectRow( mTilesetsTableWidget->currentRow() );
472  mCurrentTileset = rowItem;
473  }
474  else
475  {
476  mCurrentTileset = nullptr;
477  }
478  mTilesetsTableWidget->blockSignals( false );
479 
480  updateButtons();
481 }
482 
483 
484 
486 {
487  return mConnName;
488 }
489 
491 {
492  return mConnectionInfo;
493 }
494 
496 {
497  return selectedLayersFormats().value( mFormatComboBox->currentIndex() );
498 }
499 
500 QNetworkRequest::CacheLoadControl QgsOWSSourceSelect::selectedCacheLoadControl()
501 {
502  int cache = mCacheComboBox->currentData().toInt();
503  return static_cast<QNetworkRequest::CacheLoadControl>( cache );
504 }
505 
507 {
508  return mSelectedCRS;
509 }
510 
512 {
513  return mTimeComboBox->currentText();
514 }
515 
517 {
518  QString toSelect = QgsOwsConnection::selectedConnection( mService );
519 
520  mConnectionsComboBox->setCurrentIndex( mConnectionsComboBox->findText( toSelect ) );
521 
522  if ( mConnectionsComboBox->currentIndex() < 0 )
523  {
524  if ( toSelect.isNull() )
525  mConnectionsComboBox->setCurrentIndex( 0 );
526  else
527  mConnectionsComboBox->setCurrentIndex( mConnectionsComboBox->count() - 1 );
528  }
529 
530  if ( mConnectionsComboBox->count() == 0 )
531  {
532  // No connections - disable various buttons
533  mConnectButton->setEnabled( false );
534  mEditButton->setEnabled( false );
535  mDeleteButton->setEnabled( false );
536  mSaveButton->setEnabled( false );
537  }
538  else
539  {
540  // Connections - enable various buttons
541  mConnectButton->setEnabled( true );
542  mEditButton->setEnabled( true );
543  mDeleteButton->setEnabled( true );
544  mSaveButton->setEnabled( true );
545  }
546 
547  QgsOwsConnection::setSelectedConnection( mService, mConnectionsComboBox->currentText() );
548 }
549 
550 void QgsOWSSourceSelect::showStatusMessage( QString const &message )
551 {
552  mStatusLabel->setText( message );
553 
554  // update the display of this widget
555  update();
556 }
557 
558 
559 void QgsOWSSourceSelect::showError( QString const &title, QString const &format, QString const &error )
560 {
561  QgsMessageViewer *mv = new QgsMessageViewer( this );
562  mv->setWindowTitle( title );
563 
564  if ( format == QLatin1String( "text/html" ) )
565  {
566  mv->setMessageAsHtml( error );
567  }
568  else
569  {
570  mv->setMessageAsPlainText( tr( "Could not understand the response:\n%1" ).arg( error ) );
571  }
572  mv->showMessage( true ); // Is deleted when closed
573 }
574 
576 {
577  // Remember which server was selected.
578  QgsOwsConnection::setSelectedConnection( mService, mConnectionsComboBox->currentText() );
579 }
580 
582 {
584 }
585 
586 QString QgsOWSSourceSelect::descriptionForAuthId( const QString &authId )
587 {
588  if ( mCrsNames.contains( authId ) )
589  return mCrsNames[ authId ];
590 
592  mCrsNames.insert( authId, qgisSrs.description() );
593  return qgisSrs.description();
594 }
595 
597 {
598  QMap<QString, QString> exampleServers;
599  exampleServers[QStringLiteral( "DM Solutions GMap" )] = QStringLiteral( "http://www2.dmsolutions.ca/cgi-bin/mswms_gmap" );
600  exampleServers[QStringLiteral( "Lizardtech server" )] = QStringLiteral( "http://wms.lizardtech.com/lizardtech/iserv/ows" );
601  // Nice to have the qgis users map, but I'm not sure of the URL at the moment.
602  // exampleServers["Qgis users map"] = "http://qgis.org/wms.cgi";
603 
604  QgsSettings settings;
605  settings.beginGroup( "/Qgis/connections-" + mService.toLower() );
606  QMap<QString, QString>::const_iterator i = exampleServers.constBegin();
607  for ( ; i != exampleServers.constEnd(); ++i )
608  {
609  // Only do a server if it's name doesn't already exist.
610  QStringList keys = settings.childGroups();
611  if ( !keys.contains( i.key() ) )
612  {
613  QString path = i.key();
614  settings.setValue( path + "/url", i.value() );
615  }
616  }
617  settings.endGroup();
619 
620  QMessageBox::information( this, tr( "WMS proxies" ), "<p>" + tr( "Several WMS servers have "
621  "been added to the server list. Note that if "
622  "you access the internet via a web proxy, you will "
623  "need to set the proxy settings in the QGIS options dialog." ) + "</p>" );
624 }
625 
626 void QgsOWSSourceSelect::addWmsListRow( const QDomElement &item, int row )
627 {
628  QDomElement title = item.firstChildElement( QStringLiteral( "title" ) );
629  addWmsListItem( title, row, 0 );
630  QDomElement description = item.firstChildElement( QStringLiteral( "description" ) );
631  addWmsListItem( description, row, 1 );
632  QDomElement link = item.firstChildElement( QStringLiteral( "link" ) );
633  addWmsListItem( link, row, 2 );
634 }
635 
636 void QgsOWSSourceSelect::addWmsListItem( const QDomElement &el, int row, int column )
637 {
638  if ( !el.isNull() )
639  {
640  QTableWidgetItem *tableItem = new QTableWidgetItem( el.text() );
641  // TODO: add linebreaks to long tooltips?
642  tableItem->setToolTip( el.text() );
643  mSearchTableWidget->setItem( row, column, tableItem );
644  }
645 }
646 
647 void QgsOWSSourceSelect::on_mSearchButton_clicked()
648 {
649  // clear results
650  mSearchTableWidget->clearContents();
651  mSearchTableWidget->setRowCount( 0 );
652 
653  // disable Add WMS button
654  mSearchAddButton->setEnabled( false );
655 
656  QApplication::setOverrideCursor( Qt::WaitCursor );
657 
658  QgsSettings settings;
659  // geopole.org (geopole.ch) 25.4.2012 : 503 Service Unavailable, archive: Recently added 20 Jul 2011
660  QString mySearchUrl = settings.value( QStringLiteral( "qgis/WMSSearchUrl" ), "http://geopole.org/wms/search?search=%1&type=rss" ).toString();
661  QUrl url( mySearchUrl.arg( mSearchTermLineEdit->text() ) );
662  QgsDebugMsg( url.toString() );
663 
664  QNetworkReply *r = QgsNetworkAccessManager::instance()->get( QNetworkRequest( url ) );
665  connect( r, &QNetworkReply::finished, this, &QgsOWSSourceSelect::searchFinished );
666 }
667 
669 {
670  QApplication::restoreOverrideCursor();
671 
672  QNetworkReply *r = qobject_cast<QNetworkReply *>( sender() );
673  if ( !r )
674  return;
675 
676  if ( r->error() == QNetworkReply::NoError )
677  {
678  // parse results
679  QDomDocument doc( QStringLiteral( "RSS" ) );
680  QByteArray res = r->readAll();
681  QString error;
682  int line, column;
683  if ( doc.setContent( res, &error, &line, &column ) )
684  {
685  QDomNodeList list = doc.elementsByTagName( QStringLiteral( "item" ) );
686  mSearchTableWidget->setRowCount( list.size() );
687  for ( int i = 0; i < list.size(); i++ )
688  {
689  if ( list.item( i ).isElement() )
690  {
691  QDomElement item = list.item( i ).toElement();
692  addWmsListRow( item, i );
693  }
694  }
695 
696  mSearchTableWidget->resizeColumnsToContents();
697  }
698  else
699  {
700  QgsDebugMsg( "setContent failed" );
701  showStatusMessage( tr( "parse error at row %1, column %2: %3" ).arg( line ).arg( column ).arg( error ) );
702  }
703  }
704  else
705  {
706  showStatusMessage( tr( "network error: %1" ).arg( r->error() ) );
707  }
708 
709  r->deleteLater();
710 }
711 
712 void QgsOWSSourceSelect::on_mSearchTableWidget_itemSelectionChanged()
713 {
714  mSearchAddButton->setEnabled( mSearchTableWidget->currentRow() != -1 );
715 }
716 
717 void QgsOWSSourceSelect::on_mLayerUpButton_clicked()
718 {
719  QList<QTreeWidgetItem *> selectionList = mLayerOrderTreeWidget->selectedItems();
720  if ( selectionList.size() < 1 )
721  {
722  return;
723  }
724  int selectedIndex = mLayerOrderTreeWidget->indexOfTopLevelItem( selectionList[0] );
725  if ( selectedIndex < 1 )
726  {
727  return; //item not existing or already on top
728  }
729 
730  QTreeWidgetItem *selectedItem = mLayerOrderTreeWidget->takeTopLevelItem( selectedIndex );
731  mLayerOrderTreeWidget->insertTopLevelItem( selectedIndex - 1, selectedItem );
732  mLayerOrderTreeWidget->clearSelection();
733  selectedItem->setSelected( true );
734 }
735 
736 void QgsOWSSourceSelect::on_mLayerDownButton_clicked()
737 {
738  QList<QTreeWidgetItem *> selectionList = mLayerOrderTreeWidget->selectedItems();
739  if ( selectionList.size() < 1 )
740  {
741  return;
742  }
743  int selectedIndex = mLayerOrderTreeWidget->indexOfTopLevelItem( selectionList[0] );
744  if ( selectedIndex < 0 || selectedIndex > mLayerOrderTreeWidget->topLevelItemCount() - 2 )
745  {
746  return; //item not existing or already at bottom
747  }
748 
749  QTreeWidgetItem *selectedItem = mLayerOrderTreeWidget->takeTopLevelItem( selectedIndex );
750  mLayerOrderTreeWidget->insertTopLevelItem( selectedIndex + 1, selectedItem );
751  mLayerOrderTreeWidget->clearSelection();
752  selectedItem->setSelected( true );
753 }
754 
755 QList<QgsOWSSourceSelect::SupportedFormat> QgsOWSSourceSelect::providerFormats()
756 {
757  return QList<SupportedFormat>();
758 }
759 
761 {
762  return QStringList();
763 }
764 
766 {
767  return QStringList();
768 }
769 
771 {
772  return QStringList();
773 }
774 
775 void QgsOWSSourceSelect::updateButtons()
776 {
777 }
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:94
WidgetMode
Different ways a source select dialog can be used (embedded is for the data source manager dialog) ...
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:85
#define QgsDebugMsg(str)
Definition: qgslogger.h:37
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.
QPushButton * mAddButton
void on_mConnectButton_clicked()
Connects to the database using the stored connection parameters.
QgsCoordinateReferenceSystem crs
Definition: qgsproject.h:84
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
virtual void addClicked()
Determines the layers the user selected.
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:377
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.