QGIS API Documentation  3.22.4-Białowieża (ce8e65e95e)
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 #include "qgsgui.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 #include <QRegularExpression>
57 
58 QgsOWSSourceSelect::QgsOWSSourceSelect( const QString &service, QWidget *parent, Qt::WindowFlags fl, QgsProviderRegistry::WidgetMode theWidgetMode )
59  : QgsAbstractDataSourceWidget( parent, fl, theWidgetMode )
60  , mService( service )
61 
62 {
63  setupUi( this );
65  connect( mNewButton, &QPushButton::clicked, this, &QgsOWSSourceSelect::mNewButton_clicked );
66  connect( mEditButton, &QPushButton::clicked, this, &QgsOWSSourceSelect::mEditButton_clicked );
67  connect( mDeleteButton, &QPushButton::clicked, this, &QgsOWSSourceSelect::mDeleteButton_clicked );
68  connect( mSaveButton, &QPushButton::clicked, this, &QgsOWSSourceSelect::mSaveButton_clicked );
69  connect( mLoadButton, &QPushButton::clicked, this, &QgsOWSSourceSelect::mLoadButton_clicked );
70  connect( mConnectButton, &QPushButton::clicked, this, &QgsOWSSourceSelect::mConnectButton_clicked );
71  connect( mChangeCRSButton, &QPushButton::clicked, this, &QgsOWSSourceSelect::mChangeCRSButton_clicked );
72  connect( mLayersTreeWidget, &QTreeWidget::itemSelectionChanged, this, &QgsOWSSourceSelect::mLayersTreeWidget_itemSelectionChanged );
73  connect( mConnectionsComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::activated ), this, &QgsOWSSourceSelect::mConnectionsComboBox_activated );
74  connect( mAddDefaultButton, &QPushButton::clicked, this, &QgsOWSSourceSelect::mAddDefaultButton_clicked );
75  connect( mTilesetsTableWidget, &QTableWidget::itemClicked, this, &QgsOWSSourceSelect::mTilesetsTableWidget_itemClicked );
76  connect( mLayerUpButton, &QPushButton::clicked, this, &QgsOWSSourceSelect::mLayerUpButton_clicked );
77  connect( mLayerDownButton, &QPushButton::clicked, this, &QgsOWSSourceSelect::mLayerDownButton_clicked );
78  setupButtons( buttonBox );
79 
80 
81  setWindowTitle( tr( "Add Layer(s) from a %1 Server" ).arg( service ) );
82 
83  clearCrs();
84 
85  mTileWidthLineEdit->setValidator( new QIntValidator( 0, 9999, this ) );
86  mTileHeightLineEdit->setValidator( new QIntValidator( 0, 9999, this ) );
87  mFeatureCountLineEdit->setValidator( new QIntValidator( 0, 9999, this ) );
88 
89  mCacheComboBox->addItem( tr( "Always Cache" ), QNetworkRequest::AlwaysCache );
90  mCacheComboBox->addItem( tr( "Prefer Cache" ), QNetworkRequest::PreferCache );
91  mCacheComboBox->addItem( tr( "Prefer Network" ), QNetworkRequest::PreferNetwork );
92  mCacheComboBox->addItem( tr( "Always Network" ), QNetworkRequest::AlwaysNetwork );
93 
94  // 'Prefer network' is the default noted in the combobox's tool tip
95  mCacheComboBox->setCurrentIndex( mCacheComboBox->findData( QNetworkRequest::PreferNetwork ) );
96 
97  if ( widgetMode() != QgsProviderRegistry::WidgetMode::Manager )
98  {
99  //set the current project CRS if available
100  const QgsCoordinateReferenceSystem currentRefSys = QgsProject::instance()->crs();
101  //convert CRS id to epsg
102  if ( currentRefSys.isValid() )
103  {
104  mSelectedCRS = currentRefSys.authid();
105  }
106  }
107  else
108  {
109  mTabWidget->removeTab( mTabWidget->indexOf( mLayerOrderTab ) );
110  mTabWidget->removeTab( mTabWidget->indexOf( mTilesetsTab ) );
111  mTimeWidget->hide();
112  mFormatWidget->hide();
113  mCRSWidget->hide();
114  mCacheWidget->hide();
115  }
116 
117  // set up the WMS connections we already know about
119 }
120 
122 {
124 }
125 
127 {
128  mLayersTreeWidget->clearSelection();
129 }
130 
132 {
133  mFormatComboBox->clear();
134  mFormatComboBox->setEnabled( false );
135 }
136 
138 {
139 
140  // A server may offer more similar formats, which are mapped
141  // to the same GDAL format, e.g. GeoTIFF and TIFF
142  // -> recreate always buttons for all available formats, enable supported
143 
144  clearFormats();
145 
146  if ( mProviderFormats.isEmpty() )
147  {
148  mProviderFormats = providerFormats();
149  for ( int i = 0; i < mProviderFormats.size(); i++ )
150  {
151  // GDAL mime types may be image/tiff, image/png, ...
152  mMimeLabelMap.insert( mProviderFormats[i].format, mProviderFormats[i].label );
153  }
154  }
155 
156  // selectedLayersFormats may come in various forms:
157  // image/tiff, GTiff, GeoTIFF, TIFF, geotiff_int16, geotiff_rgb,
158  // PNG, GTOPO30, ARCGRID, IMAGEMOSAIC
159  // and even any string defined in server configuration, for example the
160  // value used in UMN Mapserver for OUTPUTFORMAT->NAME is used in
161  // WCS 1.0.0 SupportedFormats/Format
162 
163  // TODO: It is impossible to cover all possible formats coming from server
164  // -> enabled all formats, GDAL may be able to open them
165 
166  QMap<QString, QString> formatsMap;
167  formatsMap.insert( QStringLiteral( "geotiff" ), QStringLiteral( "tiff" ) );
168  formatsMap.insert( QStringLiteral( "gtiff" ), QStringLiteral( "tiff" ) );
169  formatsMap.insert( QStringLiteral( "tiff" ), QStringLiteral( "tiff" ) );
170  formatsMap.insert( QStringLiteral( "tif" ), QStringLiteral( "tiff" ) );
171  formatsMap.insert( QStringLiteral( "gif" ), QStringLiteral( "gif" ) );
172  formatsMap.insert( QStringLiteral( "jpeg" ), QStringLiteral( "jpeg" ) );
173  formatsMap.insert( QStringLiteral( "jpg" ), QStringLiteral( "jpeg" ) );
174  formatsMap.insert( QStringLiteral( "png" ), QStringLiteral( "png" ) );
175 
176  int preferred = -1;
177  const QStringList layersFormats = selectedLayersFormats();
178  for ( int i = 0; i < layersFormats.size(); i++ )
179  {
180  const QString format = layersFormats.value( i );
181  QgsDebugMsg( "server format = " + format );
182  const QString simpleFormat = format.toLower().remove( QStringLiteral( "image/" ) ).remove( QRegularExpression( "_.*" ) );
183  QgsDebugMsg( "server simpleFormat = " + simpleFormat );
184  const QString mimeFormat = "image/" + formatsMap.value( simpleFormat );
185  QgsDebugMsg( "server mimeFormat = " + mimeFormat );
186 
187  QString label = format;
188 
189  if ( mMimeLabelMap.contains( mimeFormat ) )
190  {
191  if ( format != mMimeLabelMap.value( mimeFormat ) )
192  {
193  // Append name of GDAL driver
194  label += " / " + mMimeLabelMap.value( mimeFormat );
195  }
196 
197  if ( simpleFormat.contains( QLatin1String( "tif" ) ) ) // prefer *tif*
198  {
199  if ( preferred < 0 || simpleFormat.startsWith( 'g' ) ) // prefer geotiff
200  {
201  preferred = i;
202  }
203  }
204  }
205  else
206  {
207  // We cannot always say that the format is not supported by GDAL because
208  // server can use strange names, but format itself is supported
209  QgsDebugMsg( QStringLiteral( "format %1 unknown" ).arg( format ) );
210  }
211 
212  mFormatComboBox->insertItem( i, label );
213  }
214  // Set preferred
215  // TODO: all enabled for now, see above
216  preferred = preferred >= 0 ? preferred : 0;
217  mFormatComboBox->setCurrentIndex( preferred );
218 
219  mFormatComboBox->setEnabled( true );
220 }
221 
223 {
224  mTimeComboBox->clear();
225  mTimeComboBox->insertItems( 0, selectedLayersTimes() );
226  mTimeComboBox->setEnabled( !selectedLayersTimes().isEmpty() );
227 }
228 
230 {
231  mTimeComboBox->clear();
232  mTimeComboBox->setEnabled( false );
233 }
234 
236 {
237  mConnectionsComboBox->clear();
238  mConnectionsComboBox->addItems( QgsOwsConnection::connectionList( mService ) );
239 
241 }
242 
244 {
245  if ( string.compare( QLatin1String( "wms" ), Qt::CaseInsensitive ) == 0 )
247  else if ( string.compare( QLatin1String( "wfs" ), Qt::CaseInsensitive ) == 0 )
249  else if ( string.compare( QLatin1String( "wcs" ), Qt::CaseInsensitive ) == 0 )
251  else
253 }
254 
255 void QgsOWSSourceSelect::mNewButton_clicked()
256 {
258  QgsNewHttpConnection *nc = new QgsNewHttpConnection( this, type, "/qgis/connections-" + mService.toLower() + '/' );
259 
260  if ( nc->exec() )
261  {
263  emit connectionsChanged();
264  }
265 
266  delete nc;
267 }
268 
269 void QgsOWSSourceSelect::mEditButton_clicked()
270 {
272  QgsNewHttpConnection *nc = new QgsNewHttpConnection( this, type, "/qgis/connections-" + mService.toLower() + '/', mConnectionsComboBox->currentText() );
273 
274  if ( nc->exec() )
275  {
277  emit connectionsChanged();
278  }
279 
280  delete nc;
281 }
282 
283 void QgsOWSSourceSelect::mDeleteButton_clicked()
284 {
285  const QString msg = tr( "Are you sure you want to remove the %1 connection and all associated settings?" )
286  .arg( mConnectionsComboBox->currentText() );
287  const QMessageBox::StandardButton result = QMessageBox::question( this, tr( "Remove Connection" ), msg, QMessageBox::Yes | QMessageBox::No );
288  if ( result == QMessageBox::Yes )
289  {
290  QgsOwsConnection::deleteConnection( mService, mConnectionsComboBox->currentText() );
291  mConnectionsComboBox->removeItem( mConnectionsComboBox->currentIndex() ); // populateConnectionList();
293  emit connectionsChanged();
294  }
295 }
296 
297 void QgsOWSSourceSelect::mSaveButton_clicked()
298 {
300  dlg.exec();
301 }
302 
303 void QgsOWSSourceSelect::mLoadButton_clicked()
304 {
305  const QString fileName = QFileDialog::getOpenFileName( this, tr( "Load Connections" ), QDir::homePath(),
306  tr( "XML files (*.xml *.XML)" ) );
307  if ( fileName.isEmpty() )
308  {
309  return;
310  }
311 
313  dlg.exec();
315  emit connectionsChanged();
316 }
317 
319  int id,
320  const QStringList &names,
321  QMap<int, QgsTreeWidgetItem *> &items,
322  int &layerAndStyleCount,
323  const QMap<int, int> &layerParents,
324  const QMap<int, QStringList> &layerParentNames )
325 {
326  QgsDebugMsg( QStringLiteral( "id = %1 layerAndStyleCount = %2 names = %3 " ).arg( id ).arg( layerAndStyleCount ).arg( names.join( "," ) ) );
327  if ( items.contains( id ) )
328  return items[id];
329 
330 
331  QgsTreeWidgetItem *item = nullptr;
332  if ( layerParents.contains( id ) )
333  {
334  // it has parent -> create first its parent
335  const int parent = layerParents[ id ];
336  item = new QgsTreeWidgetItem( createItem( parent, layerParentNames[ parent ], items, layerAndStyleCount, layerParents, layerParentNames ) );
337  }
338  else
339  item = new QgsTreeWidgetItem( mLayersTreeWidget );
340 
341  item->setText( 0, QString::number( ++layerAndStyleCount ) );
342  item->setText( 1, names[0].simplified() );
343  item->setText( 2, names[1].simplified() );
344  item->setText( 3, names[2].simplified() );
345  item->setToolTip( 3, "<font color=black>" + names[2].simplified() + "</font>" );
346 
347  items[ id ] = item;
348 
349  return item;
350 }
351 
353 {
354 }
355 
356 void QgsOWSSourceSelect::mConnectButton_clicked()
357 {
358 
359  mLayersTreeWidget->clear();
360  clearFormats();
361  clearTimes();
362  clearCrs();
363 
364  mConnName = mConnectionsComboBox->currentText();
365 
366  const QgsOwsConnection connection( mService, mConnectionsComboBox->currentText() );
367  mUri = connection.uri();
368 
369  QApplication::setOverrideCursor( Qt::WaitCursor );
370 
371  QgsDebugMsg( QStringLiteral( "call populateLayerList" ) );
373 
374  QApplication::restoreOverrideCursor();
375 }
376 
377 void QgsOWSSourceSelect::enableLayersForCrs( QTreeWidgetItem * )
378 {
379 }
380 
381 void QgsOWSSourceSelect::mChangeCRSButton_clicked()
382 {
383  QStringList layers;
384  const auto constSelectedItems = mLayersTreeWidget->selectedItems();
385  for ( QTreeWidgetItem *item : constSelectedItems )
386  {
387  const QString layer = item->data( 0, Qt::UserRole + 0 ).toString();
388  if ( !layer.isEmpty() )
389  layers << layer;
390  }
391 
393  mySelector->setOgcWmsCrsFilter( mSelectedLayersCRSs );
394 
395  const QgsCoordinateReferenceSystem defaultCRS = QgsProject::instance()->crs();
396  if ( defaultCRS.isValid() )
397  {
398  mySelector->setCrs( defaultCRS );
399  }
400  else
401  {
402  mySelector->showNoCrsForLayerMessage();
403  }
404 
405  if ( !mySelector->exec() )
406  return;
407 
408  mSelectedCRS = mySelector->crs().authid();
409  delete mySelector;
410 
411  mSelectedCRSLabel->setText( descriptionForAuthId( mSelectedCRS ) );
412 
413  for ( int i = 0; i < mLayersTreeWidget->topLevelItemCount(); i++ )
414  {
415  enableLayersForCrs( mLayersTreeWidget->topLevelItem( i ) );
416  }
417 
418  updateButtons();
419 }
420 
421 void QgsOWSSourceSelect::mLayersTreeWidget_itemSelectionChanged()
422 {
423 }
424 
426 {
427  clearCrs();
428  mSelectedLayersCRSs = qgis::listToSet( selectedLayersCrses() );
429  mCRSLabel->setText( tr( "Coordinate Reference System (%n available)", "crs count", mSelectedLayersCRSs.count() ) + ':' );
430 
431  mChangeCRSButton->setDisabled( mSelectedLayersCRSs.isEmpty() );
432 
433  if ( !mSelectedLayersCRSs.isEmpty() )
434  {
435  // check whether current CRS is supported
436  // if not, use one of the available CRS
437  QString defaultCRS;
438  QSet<QString>::const_iterator it = mSelectedLayersCRSs.constBegin();
439  for ( ; it != mSelectedLayersCRSs.constEnd(); ++it )
440  {
441  if ( it->compare( mSelectedCRS, Qt::CaseInsensitive ) == 0 )
442  break;
443 
444  // save first CRS in case the current CRS is not available
445  if ( it == mSelectedLayersCRSs.constBegin() )
446  defaultCRS = *it;
447 
448  // prefer value of DEFAULT_GEO_EPSG_CRS_ID if available
449  if ( *it == geoEpsgCrsAuthId() )
450  defaultCRS = *it;
451  }
452 
453  if ( it == mSelectedLayersCRSs.constEnd() )
454  {
455  if ( mSelectedLayersCRSs.constFind( QgsProject::instance()->crs().authid() ) != mSelectedLayersCRSs.constEnd() )
456  {
457  mSelectedCRS = QgsProject::instance()->crs().authid();
458  }
459  else
460  {
461  // not found
462  mSelectedCRS = defaultCRS;
463  }
464  }
465  mSelectedCRSLabel->setText( descriptionForAuthId( mSelectedCRS ) );
466  mChangeCRSButton->setEnabled( true );
467  }
468  QgsDebugMsg( "mSelectedCRS = " + mSelectedCRS );
469 }
470 
472 {
473  mCRSLabel->setText( tr( "Coordinate Reference System" ) + ':' );
474  mSelectedCRS.clear();
475  mSelectedCRSLabel->clear();
476  mChangeCRSButton->setEnabled( false );
477 }
478 
479 void QgsOWSSourceSelect::mTilesetsTableWidget_itemClicked( QTableWidgetItem *item )
480 {
481  Q_UNUSED( item )
482 
483  QTableWidgetItem *rowItem = mTilesetsTableWidget->item( mTilesetsTableWidget->currentRow(), 0 );
484  const bool wasSelected = mCurrentTileset == rowItem;
485 
486  mTilesetsTableWidget->blockSignals( true );
487  mTilesetsTableWidget->clearSelection();
488  if ( !wasSelected )
489  {
490  QgsDebugMsg( QStringLiteral( "selecting current row %1" ).arg( mTilesetsTableWidget->currentRow() ) );
491  mTilesetsTableWidget->selectRow( mTilesetsTableWidget->currentRow() );
492  mCurrentTileset = rowItem;
493  }
494  else
495  {
496  mCurrentTileset = nullptr;
497  }
498  mTilesetsTableWidget->blockSignals( false );
499 
500  updateButtons();
501 }
502 
503 
504 
506 {
507  return mConnName;
508 }
509 
511 {
512  return mConnectionInfo;
513 }
514 
516 {
517  return selectedLayersFormats().value( mFormatComboBox->currentIndex() );
518 }
519 
520 QNetworkRequest::CacheLoadControl QgsOWSSourceSelect::selectedCacheLoadControl()
521 {
522  const int cache = mCacheComboBox->currentData().toInt();
523  return static_cast<QNetworkRequest::CacheLoadControl>( cache );
524 }
525 
527 {
528  return mSelectedCRS;
529 }
530 
532 {
533  return mTimeComboBox->currentText();
534 }
535 
537 {
538  const QString toSelect = QgsOwsConnection::selectedConnection( mService );
539 
540  mConnectionsComboBox->setCurrentIndex( mConnectionsComboBox->findText( toSelect ) );
541 
542  if ( mConnectionsComboBox->currentIndex() < 0 )
543  {
544  if ( toSelect.isNull() )
545  mConnectionsComboBox->setCurrentIndex( 0 );
546  else
547  mConnectionsComboBox->setCurrentIndex( mConnectionsComboBox->count() - 1 );
548  }
549 
550  if ( mConnectionsComboBox->count() == 0 )
551  {
552  // No connections - disable various buttons
553  mConnectButton->setEnabled( false );
554  mEditButton->setEnabled( false );
555  mDeleteButton->setEnabled( false );
556  mSaveButton->setEnabled( false );
557  }
558  else
559  {
560  // Connections - enable various buttons
561  mConnectButton->setEnabled( true );
562  mEditButton->setEnabled( true );
563  mDeleteButton->setEnabled( true );
564  mSaveButton->setEnabled( true );
565  }
566 
567  QgsOwsConnection::setSelectedConnection( mService, mConnectionsComboBox->currentText() );
568 }
569 
570 void QgsOWSSourceSelect::showStatusMessage( QString const &message )
571 {
572  mStatusLabel->setText( message );
573 
574  // update the display of this widget
575  update();
576 }
577 
578 
579 void QgsOWSSourceSelect::showError( QString const &title, QString const &format, QString const &error )
580 {
581  QgsMessageViewer *mv = new QgsMessageViewer( this );
582  mv->setWindowTitle( title );
583 
584  if ( format == QLatin1String( "text/html" ) )
585  {
586  mv->setMessageAsHtml( error );
587  }
588  else
589  {
590  mv->setMessageAsPlainText( tr( "Could not understand the response:\n%1" ).arg( error ) );
591  }
592  mv->showMessage( true ); // Is deleted when closed
593 }
594 
595 void QgsOWSSourceSelect::mConnectionsComboBox_activated( int )
596 {
597  // Remember which server was selected.
598  QgsOwsConnection::setSelectedConnection( mService, mConnectionsComboBox->currentText() );
599 }
600 
601 void QgsOWSSourceSelect::mAddDefaultButton_clicked()
602 {
604 }
605 
606 QString QgsOWSSourceSelect::descriptionForAuthId( const QString &authId )
607 {
608  if ( mCrsNames.contains( authId ) )
609  return mCrsNames[ authId ];
610 
612  mCrsNames.insert( authId, qgisSrs.userFriendlyIdentifier() );
613  return qgisSrs.userFriendlyIdentifier();
614 }
615 
617 {
618  QMap<QString, QString> exampleServers;
619  exampleServers[QStringLiteral( "DM Solutions GMap" )] = QStringLiteral( "http://www2.dmsolutions.ca/cgi-bin/mswms_gmap" );
620  exampleServers[QStringLiteral( "Lizardtech server" )] = QStringLiteral( "http://wms.lizardtech.com/lizardtech/iserv/ows" );
621  // Nice to have the qgis users map, but I'm not sure of the URL at the moment.
622  // exampleServers["Qgis users map"] = "http://qgis.org/wms.cgi";
623 
624  QgsSettings settings;
625  settings.beginGroup( "/qgis/connections-" + mService.toLower() );
626  QMap<QString, QString>::const_iterator i = exampleServers.constBegin();
627  for ( ; i != exampleServers.constEnd(); ++i )
628  {
629  // Only do a server if it's name doesn't already exist.
630  const QStringList keys = settings.childGroups();
631  if ( !keys.contains( i.key() ) )
632  {
633  const QString path = i.key();
634  settings.setValue( path + "/url", i.value() );
635  }
636  }
637  settings.endGroup();
639 
640  QMessageBox::information( this, tr( "Add WMS Servers" ), "<p>" + tr( "Several WMS servers have "
641  "been added to the server list. Note that if "
642  "you access the Internet via a web proxy, you will "
643  "need to set the proxy settings in the QGIS options dialog." ) + "</p>" );
644 }
645 
646 void QgsOWSSourceSelect::mLayerUpButton_clicked()
647 {
648  QList<QTreeWidgetItem *> selectionList = mLayerOrderTreeWidget->selectedItems();
649  if ( selectionList.empty() )
650  {
651  return;
652  }
653  const int selectedIndex = mLayerOrderTreeWidget->indexOfTopLevelItem( selectionList[0] );
654  if ( selectedIndex < 1 )
655  {
656  return; //item not existing or already on top
657  }
658 
659  QTreeWidgetItem *selectedItem = mLayerOrderTreeWidget->takeTopLevelItem( selectedIndex );
660  mLayerOrderTreeWidget->insertTopLevelItem( selectedIndex - 1, selectedItem );
661  mLayerOrderTreeWidget->clearSelection();
662  selectedItem->setSelected( true );
663 }
664 
665 void QgsOWSSourceSelect::mLayerDownButton_clicked()
666 {
667  QList<QTreeWidgetItem *> selectionList = mLayerOrderTreeWidget->selectedItems();
668  if ( selectionList.empty() )
669  {
670  return;
671  }
672  const int selectedIndex = mLayerOrderTreeWidget->indexOfTopLevelItem( selectionList[0] );
673  if ( selectedIndex < 0 || selectedIndex > mLayerOrderTreeWidget->topLevelItemCount() - 2 )
674  {
675  return; //item not existing or already at bottom
676  }
677 
678  QTreeWidgetItem *selectedItem = mLayerOrderTreeWidget->takeTopLevelItem( selectedIndex );
679  mLayerOrderTreeWidget->insertTopLevelItem( selectedIndex + 1, selectedItem );
680  mLayerOrderTreeWidget->clearSelection();
681  selectedItem->setSelected( true );
682 }
683 
684 QList<QgsOWSSourceSelect::SupportedFormat> QgsOWSSourceSelect::providerFormats()
685 {
686  return QList<SupportedFormat>();
687 }
688 
690 {
691  return QStringList();
692 }
693 
695 {
696  return QStringList();
697 }
698 
700 {
701  return QStringList();
702 }
703 
704 void QgsOWSSourceSelect::updateButtons()
705 {
706 }
Abstract base Data Source Widget to create connections and add layers This class provides common func...
void setupButtons(QDialogButtonBox *buttonBox)
Connect the ok and apply/add buttons to the slots.
void connectionsChanged()
Emitted when the provider's connections have changed This signal is normally forwarded the app and us...
QgsProviderRegistry::WidgetMode widgetMode() const
Returns the widget mode.
This class represents a coordinate reference system (CRS).
static QgsCoordinateReferenceSystem fromOgcWmsCrs(const QString &ogcCrs)
Creates a CRS from a given OGC WMS-format Coordinate Reference System string.
bool isValid() const
Returns whether this CRS is correctly initialized and usable.
QString userFriendlyIdentifier(IdentifierType type=MediumString) const
Returns a user friendly identifier for the CRS.
QString authid() const
Returns the authority identifier for the CRS.
QString uri(bool expandAuthConfig=true) const
Returns the complete URI as a string.
static QgsGui * instance()
Returns a pointer to the singleton instance.
Definition: qgsgui.cpp:67
static void enableAutoGeometryRestore(QWidget *widget, const QString &key=QString())
Register the widget to allow its position to be automatically saved and restored when open and closed...
Definition: qgsgui.cpp:168
A generic message view for displaying QGIS messages.
void setMessageAsPlainText(const QString &msg)
void showMessage(bool blocking=true) override
display the message to the user and deletes itself
void setMessageAsHtml(const QString &msg)
Dialog to allow the user to configure and save connection information for an HTTP Server for WMS,...
ConnectionType
Available connection types for configuring in the dialog.
@ ConnectionWms
WMS connection.
@ ConnectionWfs
WFS connection.
@ ConnectionWcs
WCS connection.
virtual QStringList selectedLayersCrses()
Server CRS supported for currently selected layer item(s)
virtual QStringList selectedLayersTimes()
List of times (temporalDomain timePosition/timePeriod for currently selected layer item(s)
QString descriptionForAuthId(const QString &authId)
Returns a textual description for the authority id.
void refresh() override
Triggered when the provider's connections need to be refreshed.
QString selectedTime()
Returns currently selected time.
void clearCrs()
Clear CRSs.
void populateCrs()
Sets supported CRSs.
virtual void enableLayersForCrs(QTreeWidgetItem *item)
QString mService
Service name.
virtual QList< QgsOWSSourceSelect::SupportedFormat > providerFormats()
List of image formats (encodings) supported by provider.
QgsOWSSourceSelect(const QString &service, QWidget *parent=nullptr, Qt::WindowFlags fl=QgsGuiUtils::ModalDialogFlags, QgsProviderRegistry::WidgetMode widgetMode=QgsProviderRegistry::WidgetMode::None)
Constructor.
QString connectionInfo()
Connection info (uri)
QNetworkRequest::CacheLoadControl selectedCacheLoadControl()
Returns currently selected cache load control.
void populateFormats()
Populate supported formats.
QTableWidgetItem * mCurrentTileset
QString selectedCrs()
Returns currently selected Crs.
void populateTimes()
Populate times.
virtual QStringList selectedLayersFormats()
List of formats supported for currently selected layer item(s)
void reset() override
Called when this source select widget is being shown in a "new and clean" dialog.
void setConnectionListPosition()
Sets the server connection combo box to that stored in the config file.
void clearTimes()
Clear times.
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
QString selectedFormat()
Returns currently selected format.
QString mConnName
Name for selected connection.
void showError(const QString &title, const QString &format, const QString &error)
show whatever error is exposed.
void populateConnectionList()
Populate the connection list combo box.
QString connName()
Connection name.
void addDefaultServers()
Add a few example servers to the list.
void showStatusMessage(const QString &message)
Sets status message to theMessage.
QgsDataSourceUri mUri
URI for selected connection.
QString mConnectionInfo
Connection info for selected connection.
void clearFormats()
Clear previously set formats.
virtual void populateLayerList()
Populate the layer list.
QMap< QString, QString > mCrsNames
Connections management.
static QStringList connectionList(const QString &service)
Returns the list of connections for the specified service.
static void setSelectedConnection(const QString &service, const QString &name)
Marks the specified connection for the specified service as selected.
static void deleteConnection(const QString &service, const QString &name)
Deletes the connection for the specified service with the specified name.
static QString selectedConnection(const QString &service)
Retrieves the selected connection for the specified service.
static QgsProject * instance()
Returns the QgsProject singleton instance.
Definition: qgsproject.cpp:467
QgsCoordinateReferenceSystem crs
Definition: qgsproject.h:106
A generic dialog to prompt the user for a Coordinate Reference System.
void showNoCrsForLayerMessage()
When called, the dialog will show a default "layer has no CRS set" message above the projection selec...
void setCrs(const QgsCoordinateReferenceSystem &crs)
Sets the initial crs to show within the dialog.
QgsCoordinateReferenceSystem crs() const
Returns the CRS currently selected in the widget.
void setOgcWmsCrsFilter(const QSet< QString > &crsFilter)
filters this dialog by the given CRSs
WidgetMode
Different ways a source select dialog can be used.
This class is a composition of two QSettings instances:
Definition: qgssettings.h:62
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:99
void beginGroup(const QString &prefix, QgsSettings::Section section=QgsSettings::NoSection)
Appends prefix to the current group.
Definition: qgssettings.cpp:89
void setValue(const QString &key, const QVariant &value, QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.
QTreeWidgetItem subclass with custom handling for item sorting.
CONSTLATIN1STRING geoEpsgCrsAuthId()
Geographic coord sys from EPSG authority.
Definition: qgis.h:1654
#define QgsDebugMsg(str)
Definition: qgslogger.h:38
QgsNewHttpConnection::ConnectionType connectionTypeFromServiceString(const QString &string)