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