QGIS API Documentation  2.99.0-Master (f867b65)
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  , mCurrentTileset( nullptr )
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 }
233 {
234  QgsNewHttpConnection *nc = new QgsNewHttpConnection( this, "/qgis/connections-" + mService.toLower() + '/' );
235 
236  if ( nc->exec() )
237  {
239  emit connectionsChanged();
240  }
241 
242  delete nc;
243 }
244 
246 {
247  QgsNewHttpConnection *nc = new QgsNewHttpConnection( this, "/qgis/connections-" + mService.toLower() + '/', mConnectionsComboBox->currentText() );
248 
249  if ( nc->exec() )
250  {
252  emit connectionsChanged();
253  }
254 
255  delete nc;
256 }
257 
259 {
260  QString msg = tr( "Are you sure you want to remove the %1 connection and all associated settings?" )
261  .arg( mConnectionsComboBox->currentText() );
262  QMessageBox::StandardButton result = QMessageBox::information( this, tr( "Confirm Delete" ), msg, QMessageBox::Ok | QMessageBox::Cancel );
263  if ( result == QMessageBox::Ok )
264  {
265  QgsOwsConnection::deleteConnection( mService, mConnectionsComboBox->currentText() );
266  mConnectionsComboBox->removeItem( mConnectionsComboBox->currentIndex() ); // populateConnectionList();
268  emit connectionsChanged();
269  }
270 }
271 
273 {
275  dlg.exec();
276 }
277 
279 {
280  QString fileName = QFileDialog::getOpenFileName( this, tr( "Load connections" ), QDir::homePath(),
281  tr( "XML files (*.xml *XML)" ) );
282  if ( fileName.isEmpty() )
283  {
284  return;
285  }
286 
288  dlg.exec();
290  emit connectionsChanged();
291 }
292 
294  int id,
295  const QStringList &names,
296  QMap<int, QgsTreeWidgetItem *> &items,
297  int &layerAndStyleCount,
298  const QMap<int, int> &layerParents,
299  const QMap<int, QStringList> &layerParentNames )
300 {
301  QgsDebugMsg( QString( "id = %1 layerAndStyleCount = %2 names = %3 " ).arg( id ).arg( layerAndStyleCount ).arg( names.join( "," ) ) );
302  if ( items.contains( id ) )
303  return items[id];
304 
305 
306  QgsTreeWidgetItem *item = nullptr;
307  if ( layerParents.contains( id ) )
308  {
309  // it has parent -> create first its parent
310  int parent = layerParents[ id ];
311  item = new QgsTreeWidgetItem( createItem( parent, layerParentNames[ parent ], items, layerAndStyleCount, layerParents, layerParentNames ) );
312  }
313  else
314  item = new QgsTreeWidgetItem( mLayersTreeWidget );
315 
316  item->setText( 0, QString::number( ++layerAndStyleCount ) );
317  item->setText( 1, names[0].simplified() );
318  item->setText( 2, names[1].simplified() );
319  item->setText( 3, names[2].simplified() );
320  item->setToolTip( 3, "<font color=black>" + names[2].simplified() + "</font>" );
321 
322  items[ id ] = item;
323 
324  return item;
325 }
326 
328 {
329 }
330 
332 {
333 
334  mLayersTreeWidget->clear();
335  clearFormats();
336  clearTimes();
337  clearCrs();
338 
339  mConnName = mConnectionsComboBox->currentText();
340 
341  QgsOwsConnection connection( mService, mConnectionsComboBox->currentText() );
342  mUri = connection.uri();
343 
344  QApplication::setOverrideCursor( Qt::WaitCursor );
345 
346  QgsDebugMsg( "call populateLayerList" );
348 
349  QApplication::restoreOverrideCursor();
350 }
351 
352 void QgsOWSSourceSelect::enableLayersForCrs( QTreeWidgetItem * )
353 {
354 }
355 
357 {
358  QStringList layers;
359  Q_FOREACH ( QTreeWidgetItem *item, mLayersTreeWidget->selectedItems() )
360  {
361  QString layer = item->data( 0, Qt::UserRole + 0 ).toString();
362  if ( !layer.isEmpty() )
363  layers << layer;
364  }
365 
367  mySelector->setMessage( QString() );
368  mySelector->setOgcWmsCrsFilter( mSelectedLayersCRSs );
369 
371  if ( defaultCRS.isValid() )
372  {
373  mySelector->setCrs( defaultCRS );
374  }
375 
376  if ( !mySelector->exec() )
377  return;
378 
379  mSelectedCRS = mySelector->crs().authid();
380  delete mySelector;
381 
382  mSelectedCRSLabel->setText( descriptionForAuthId( mSelectedCRS ) );
383 
384  for ( int i = 0; i < mLayersTreeWidget->topLevelItemCount(); i++ )
385  {
386  enableLayersForCrs( mLayersTreeWidget->topLevelItem( i ) );
387  }
388 
389  updateButtons();
390 }
391 
393 {
394 }
395 
397 {
398  clearCrs();
399  mSelectedLayersCRSs = selectedLayersCrses().toSet();
400  mCRSLabel->setText( tr( "Coordinate Reference System (%n available)", "crs count", mSelectedLayersCRSs.count() ) + ':' );
401 
402  mChangeCRSButton->setDisabled( mSelectedLayersCRSs.isEmpty() );
403 
404  if ( !mSelectedLayersCRSs.isEmpty() )
405  {
406  // check whether current CRS is supported
407  // if not, use one of the available CRS
408  QString defaultCRS;
409  QSet<QString>::const_iterator it = mSelectedLayersCRSs.constBegin();
410  for ( ; it != mSelectedLayersCRSs.constEnd(); ++it )
411  {
412  if ( it->compare( mSelectedCRS, Qt::CaseInsensitive ) == 0 )
413  break;
414 
415  // save first CRS in case the current CRS is not available
416  if ( it == mSelectedLayersCRSs.begin() )
417  defaultCRS = *it;
418 
419  // prefer value of DEFAULT_GEO_EPSG_CRS_ID if available
420  if ( *it == GEO_EPSG_CRS_AUTHID )
421  defaultCRS = *it;
422  }
423 
424  if ( it == mSelectedLayersCRSs.end() )
425  {
426  // not found
427  mSelectedCRS = defaultCRS;
428  }
429  mSelectedCRSLabel->setText( descriptionForAuthId( mSelectedCRS ) );
430  mChangeCRSButton->setEnabled( true );
431  }
432  QgsDebugMsg( "mSelectedCRS = " + mSelectedCRS );
433 }
434 
436 {
437  mCRSLabel->setText( tr( "Coordinate Reference System" ) + ':' );
438  mSelectedCRS = QLatin1String( "" );
439  mSelectedCRSLabel->setText( QLatin1String( "" ) );
440  mChangeCRSButton->setEnabled( false );
441 }
442 
443 void QgsOWSSourceSelect::on_mTilesetsTableWidget_itemClicked( QTableWidgetItem *item )
444 {
445  Q_UNUSED( item );
446 
447  QTableWidgetItem *rowItem = mTilesetsTableWidget->item( mTilesetsTableWidget->currentRow(), 0 );
448  bool wasSelected = mCurrentTileset == rowItem;
449 
450  mTilesetsTableWidget->blockSignals( true );
451  mTilesetsTableWidget->clearSelection();
452  if ( !wasSelected )
453  {
454  QgsDebugMsg( QString( "selecting current row %1" ).arg( mTilesetsTableWidget->currentRow() ) );
455  mTilesetsTableWidget->selectRow( mTilesetsTableWidget->currentRow() );
456  mCurrentTileset = rowItem;
457  }
458  else
459  {
460  mCurrentTileset = nullptr;
461  }
462  mTilesetsTableWidget->blockSignals( false );
463 
464  updateButtons();
465 }
466 
467 
468 
470 {
471  return mConnName;
472 }
473 
475 {
476  return mConnectionInfo;
477 }
478 
480 {
481  return selectedLayersFormats().value( mFormatComboBox->currentIndex() );
482 }
483 
484 QNetworkRequest::CacheLoadControl QgsOWSSourceSelect::selectedCacheLoadControl()
485 {
486  int cache = mCacheComboBox->currentData().toInt();
487  return static_cast<QNetworkRequest::CacheLoadControl>( cache );
488 }
489 
491 {
492  return mSelectedCRS;
493 }
494 
496 {
497  return mTimeComboBox->currentText();
498 }
499 
501 {
502  QString toSelect = QgsOwsConnection::selectedConnection( mService );
503 
504  mConnectionsComboBox->setCurrentIndex( mConnectionsComboBox->findText( toSelect ) );
505 
506  if ( mConnectionsComboBox->currentIndex() < 0 )
507  {
508  if ( toSelect.isNull() )
509  mConnectionsComboBox->setCurrentIndex( 0 );
510  else
511  mConnectionsComboBox->setCurrentIndex( mConnectionsComboBox->count() - 1 );
512  }
513 
514  if ( mConnectionsComboBox->count() == 0 )
515  {
516  // No connections - disable various buttons
517  mConnectButton->setEnabled( false );
518  mEditButton->setEnabled( false );
519  mDeleteButton->setEnabled( false );
520  mSaveButton->setEnabled( false );
521  }
522  else
523  {
524  // Connections - enable various buttons
525  mConnectButton->setEnabled( true );
526  mEditButton->setEnabled( true );
527  mDeleteButton->setEnabled( true );
528  mSaveButton->setEnabled( true );
529  }
530 
531  QgsOwsConnection::setSelectedConnection( mService, mConnectionsComboBox->currentText() );
532 }
533 
534 void QgsOWSSourceSelect::showStatusMessage( QString const &message )
535 {
536  mStatusLabel->setText( message );
537 
538  // update the display of this widget
539  update();
540 }
541 
542 
543 void QgsOWSSourceSelect::showError( QString const &title, QString const &format, QString const &error )
544 {
545  QgsMessageViewer *mv = new QgsMessageViewer( this );
546  mv->setWindowTitle( title );
547 
548  if ( format == QLatin1String( "text/html" ) )
549  {
550  mv->setMessageAsHtml( error );
551  }
552  else
553  {
554  mv->setMessageAsPlainText( tr( "Could not understand the response:\n%1" ).arg( error ) );
555  }
556  mv->showMessage( true ); // Is deleted when closed
557 }
558 
560 {
561  // Remember which server was selected.
562  QgsOwsConnection::setSelectedConnection( mService, mConnectionsComboBox->currentText() );
563 }
564 
566 {
568 }
569 
570 QString QgsOWSSourceSelect::descriptionForAuthId( const QString &authId )
571 {
572  if ( mCrsNames.contains( authId ) )
573  return mCrsNames[ authId ];
574 
576  mCrsNames.insert( authId, qgisSrs.description() );
577  return qgisSrs.description();
578 }
579 
581 {
582  QMap<QString, QString> exampleServers;
583  exampleServers[QStringLiteral( "DM Solutions GMap" )] = QStringLiteral( "http://www2.dmsolutions.ca/cgi-bin/mswms_gmap" );
584  exampleServers[QStringLiteral( "Lizardtech server" )] = QStringLiteral( "http://wms.lizardtech.com/lizardtech/iserv/ows" );
585  // Nice to have the qgis users map, but I'm not sure of the URL at the moment.
586  // exampleServers["Qgis users map"] = "http://qgis.org/wms.cgi";
587 
588  QgsSettings settings;
589  settings.beginGroup( "/qgis/connections-" + mService.toLower() );
590  QMap<QString, QString>::const_iterator i = exampleServers.constBegin();
591  for ( ; i != exampleServers.constEnd(); ++i )
592  {
593  // Only do a server if it's name doesn't already exist.
594  QStringList keys = settings.childGroups();
595  if ( !keys.contains( i.key() ) )
596  {
597  QString path = i.key();
598  settings.setValue( path + "/url", i.value() );
599  }
600  }
601  settings.endGroup();
603 
604  QMessageBox::information( this, tr( "WMS proxies" ), "<p>" + tr( "Several WMS servers have "
605  "been added to the server list. Note that if "
606  "you access the internet via a web proxy, you will "
607  "need to set the proxy settings in the QGIS options dialog." ) + "</p>" );
608 }
609 
610 void QgsOWSSourceSelect::addWmsListRow( const QDomElement &item, int row )
611 {
612  QDomElement title = item.firstChildElement( QStringLiteral( "title" ) );
613  addWmsListItem( title, row, 0 );
614  QDomElement description = item.firstChildElement( QStringLiteral( "description" ) );
615  addWmsListItem( description, row, 1 );
616  QDomElement link = item.firstChildElement( QStringLiteral( "link" ) );
617  addWmsListItem( link, row, 2 );
618 }
619 
620 void QgsOWSSourceSelect::addWmsListItem( const QDomElement &el, int row, int column )
621 {
622  if ( !el.isNull() )
623  {
624  QTableWidgetItem *tableItem = new QTableWidgetItem( el.text() );
625  // TODO: add linebreaks to long tooltips?
626  tableItem->setToolTip( el.text() );
627  mSearchTableWidget->setItem( row, column, tableItem );
628  }
629 }
630 
631 void QgsOWSSourceSelect::on_mSearchButton_clicked()
632 {
633  // clear results
634  mSearchTableWidget->clearContents();
635  mSearchTableWidget->setRowCount( 0 );
636 
637  // disable Add WMS button
638  mSearchAddButton->setEnabled( false );
639 
640  QApplication::setOverrideCursor( Qt::WaitCursor );
641 
642  QgsSettings settings;
643  // geopole.org (geopole.ch) 25.4.2012 : 503 Service Unavailable, archive: Recently added 20 Jul 2011
644  QString mySearchUrl = settings.value( QStringLiteral( "qgis/WMSSearchUrl" ), "http://geopole.org/wms/search?search=%1&type=rss" ).toString();
645  QUrl url( mySearchUrl.arg( mSearchTermLineEdit->text() ) );
646  QgsDebugMsg( url.toString() );
647 
648  QNetworkReply *r = QgsNetworkAccessManager::instance()->get( QNetworkRequest( url ) );
649  connect( r, &QNetworkReply::finished, this, &QgsOWSSourceSelect::searchFinished );
650 }
651 
653 {
654  QApplication::restoreOverrideCursor();
655 
656  QNetworkReply *r = qobject_cast<QNetworkReply *>( sender() );
657  if ( !r )
658  return;
659 
660  if ( r->error() == QNetworkReply::NoError )
661  {
662  // parse results
663  QDomDocument doc( QStringLiteral( "RSS" ) );
664  QByteArray res = r->readAll();
665  QString error;
666  int line, column;
667  if ( doc.setContent( res, &error, &line, &column ) )
668  {
669  QDomNodeList list = doc.elementsByTagName( QStringLiteral( "item" ) );
670  mSearchTableWidget->setRowCount( list.size() );
671  for ( int i = 0; i < list.size(); i++ )
672  {
673  if ( list.item( i ).isElement() )
674  {
675  QDomElement item = list.item( i ).toElement();
676  addWmsListRow( item, i );
677  }
678  }
679 
680  mSearchTableWidget->resizeColumnsToContents();
681  }
682  else
683  {
684  QgsDebugMsg( "setContent failed" );
685  showStatusMessage( tr( "parse error at row %1, column %2: %3" ).arg( line ).arg( column ).arg( error ) );
686  }
687  }
688  else
689  {
690  showStatusMessage( tr( "network error: %1" ).arg( r->error() ) );
691  }
692 
693  r->deleteLater();
694 }
695 
696 void QgsOWSSourceSelect::on_mSearchTableWidget_itemSelectionChanged()
697 {
698  mSearchAddButton->setEnabled( mSearchTableWidget->currentRow() != -1 );
699 }
700 
701 void QgsOWSSourceSelect::on_mLayerUpButton_clicked()
702 {
703  QList<QTreeWidgetItem *> selectionList = mLayerOrderTreeWidget->selectedItems();
704  if ( selectionList.size() < 1 )
705  {
706  return;
707  }
708  int selectedIndex = mLayerOrderTreeWidget->indexOfTopLevelItem( selectionList[0] );
709  if ( selectedIndex < 1 )
710  {
711  return; //item not existing or already on top
712  }
713 
714  QTreeWidgetItem *selectedItem = mLayerOrderTreeWidget->takeTopLevelItem( selectedIndex );
715  mLayerOrderTreeWidget->insertTopLevelItem( selectedIndex - 1, selectedItem );
716  mLayerOrderTreeWidget->clearSelection();
717  selectedItem->setSelected( true );
718 }
719 
720 void QgsOWSSourceSelect::on_mLayerDownButton_clicked()
721 {
722  QList<QTreeWidgetItem *> selectionList = mLayerOrderTreeWidget->selectedItems();
723  if ( selectionList.size() < 1 )
724  {
725  return;
726  }
727  int selectedIndex = mLayerOrderTreeWidget->indexOfTopLevelItem( selectionList[0] );
728  if ( selectedIndex < 0 || selectedIndex > mLayerOrderTreeWidget->topLevelItemCount() - 2 )
729  {
730  return; //item not existing or already at bottom
731  }
732 
733  QTreeWidgetItem *selectedItem = mLayerOrderTreeWidget->takeTopLevelItem( selectedIndex );
734  mLayerOrderTreeWidget->insertTopLevelItem( selectedIndex + 1, selectedItem );
735  mLayerOrderTreeWidget->clearSelection();
736  selectedItem->setSelected( true );
737 }
738 
739 QList<QgsOWSSourceSelect::SupportedFormat> QgsOWSSourceSelect::providerFormats()
740 {
741  return QList<SupportedFormat>();
742 }
743 
745 {
746  return QStringList();
747 }
748 
750 {
751  return QStringList();
752 }
753 
755 {
756  return QStringList();
757 }
758 
759 void QgsOWSSourceSelect::updateButtons()
760 {
761 }
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) ...
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: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.
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
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.