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