QGIS API Documentation  2.17.0-Master (6f7b933)
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"
33 #include "qgsproject.h"
34 #include "qgsproviderregistry.h"
35 #include "qgsowsconnection.h"
36 #include "qgsdataprovider.h"
37 #include "qgsowssourceselect.h"
39 #include "qgscrscache.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, const 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
97  long currentCRS = QgsProject::instance()->readNumEntry( "SpatialRefSys", "/ProjectCRSID", -1 );
98  if ( currentCRS != -1 )
99  {
100  //convert CRS id to epsg
101  QgsCoordinateReferenceSystem currentRefSys = QgsCRSCache::instance()->crsBySrsId( currentCRS );
102  if ( currentRefSys.isValid() )
103  {
104  mSelectedCRS = currentRefSys.authid();
105  }
106  }
107  }
108  else
109  {
110  mTabWidget->removeTab( mTabWidget->indexOf( mLayerOrderTab ) );
111  mTabWidget->removeTab( mTabWidget->indexOf( mTilesetsTab ) );
112  mTimeWidget->hide();
113  mFormatWidget->hide();
114  mCRSWidget->hide();
115  mAddButton->hide();
116  mCacheWidget->hide();
117  }
118 
119  // set up the WMS connections we already know about
121 
122  QSettings settings;
123  QgsDebugMsg( "restoring geometry" );
124  restoreGeometry( settings.value( "/Windows/WMSSourceSelect/geometry" ).toByteArray() );
125 }
126 
128 {
129  QSettings settings;
130  QgsDebugMsg( "saving geometry" );
131  settings.setValue( "/Windows/WMSSourceSelect/geometry", saveGeometry() );
132 }
133 
135 {
136  mFormatComboBox->clear();
137  mFormatComboBox->setEnabled( false );
138 }
139 
141 {
142 
143  // A server may offer more similar formats, which are mapped
144  // to the same GDAL format, e.g. GeoTIFF and TIFF
145  // -> recreate always buttons for all available formats, enable supported
146 
147  clearFormats();
148 
149  if ( mProviderFormats.isEmpty() )
150  {
151  mProviderFormats = providerFormats();
152  for ( int i = 0; i < mProviderFormats.size(); i++ )
153  {
154  // GDAL mime types may be image/tiff, image/png, ...
155  mMimeLabelMap.insert( mProviderFormats[i].format, mProviderFormats[i].label );
156  }
157  }
158 
159  // selectedLayersFormats may come in various forms:
160  // image/tiff, GTiff, GeoTIFF, TIFF, geotiff_int16, geotiff_rgb,
161  // PNG, GTOPO30, ARCGRID, IMAGEMOSAIC
162  // and even any string defined in server configuration, for example the
163  // value used in UMN Mapserver for OUTPUTFORMAT->NAME is used in
164  // WCS 1.0.0 SupportedFormats/Format
165 
166  // TODO: It is impossible to cover all possible formats comming from server
167  // -> enabled all formats, GDAL may be able to open them
168 
169  QMap<QString, QString> formatsMap;
170  formatsMap.insert( "geotiff", "tiff" );
171  formatsMap.insert( "gtiff", "tiff" );
172  formatsMap.insert( "tiff", "tiff" );
173  formatsMap.insert( "tif", "tiff" );
174  formatsMap.insert( "gif", "gif" );
175  formatsMap.insert( "jpeg", "jpeg" );
176  formatsMap.insert( "jpg", "jpeg" );
177  formatsMap.insert( "png", "png" );
178 
179  int preferred = -1;
180  QStringList layersFormats = selectedLayersFormats();
181  for ( int i = 0; i < layersFormats.size(); i++ )
182  {
183  QString format = layersFormats.value( i );
184  QgsDebugMsg( "server format = " + format );
185  QString simpleFormat = format.toLower().remove( "image/" ).remove( QRegExp( "_.*" ) );
186  QgsDebugMsg( "server simpleFormat = " + simpleFormat );
187  QString mimeFormat = "image/" + formatsMap.value( simpleFormat );
188  QgsDebugMsg( "server mimeFormat = " + mimeFormat );
189 
190  QString label = format;
191 
192  if ( mMimeLabelMap.contains( mimeFormat ) )
193  {
194  if ( format != mMimeLabelMap.value( mimeFormat ) )
195  {
196  // Append name of GDAL driver
197  label += " / " + mMimeLabelMap.value( mimeFormat );
198  }
199 
200  if ( simpleFormat.contains( "tif" ) ) // prefer *tif*
201  {
202  if ( preferred < 0 || simpleFormat.startsWith( 'g' ) ) // prefer geotiff
203  {
204  preferred = i;
205  }
206  }
207  }
208  else
209  {
210  // We cannot always say that the format is not supported by GDAL because
211  // server can use strange names, but format itself is supported
212  QgsDebugMsg( QString( "format %1 unknown" ).arg( format ) );
213  }
214 
215  mFormatComboBox->insertItem( i, label );
216  }
217  // Set preferred
218  // TODO: all enabled for now, see above
219  preferred = preferred >= 0 ? preferred : 0;
220  mFormatComboBox->setCurrentIndex( preferred );
221 
222  mFormatComboBox->setEnabled( true );
223 }
224 
226 {
227  mTimeComboBox->clear();
228  mTimeComboBox->insertItems( 0, selectedLayersTimes() );
229  mTimeComboBox->setEnabled( !selectedLayersTimes().isEmpty() );
230 }
231 
233 {
234  mTimeComboBox->clear();
235  mTimeComboBox->setEnabled( false );
236 }
237 
239 {
240  mConnectionsComboBox->clear();
241  mConnectionsComboBox->addItems( QgsOWSConnection::connectionList( mService ) );
242 
244 }
246 {
247  QgsNewHttpConnection *nc = new QgsNewHttpConnection( this, "/Qgis/connections-" + mService.toLower() + '/' );
248 
249  if ( nc->exec() )
250  {
252  emit connectionsChanged();
253  }
254 
255  delete nc;
256 }
257 
259 {
260  QgsNewHttpConnection *nc = new QgsNewHttpConnection( this, "/Qgis/connections-" + mService.toLower() + '/', mConnectionsComboBox->currentText() );
261 
262  if ( nc->exec() )
263  {
265  emit connectionsChanged();
266  }
267 
268  delete nc;
269 }
270 
272 {
273  QString msg = tr( "Are you sure you want to remove the %1 connection and all associated settings?" )
274  .arg( mConnectionsComboBox->currentText() );
275  QMessageBox::StandardButton result = QMessageBox::information( this, tr( "Confirm Delete" ), msg, QMessageBox::Ok | QMessageBox::Cancel );
276  if ( result == QMessageBox::Ok )
277  {
278  QgsOWSConnection::deleteConnection( mService, mConnectionsComboBox->currentText() );
279  mConnectionsComboBox->removeItem( mConnectionsComboBox->currentIndex() ); // populateConnectionList();
281  emit connectionsChanged();
282  }
283 }
284 
286 {
288  dlg.exec();
289 }
290 
292 {
293  QString fileName = QFileDialog::getOpenFileName( this, tr( "Load connections" ), QDir::homePath(),
294  tr( "XML files (*.xml *XML)" ) );
295  if ( fileName.isEmpty() )
296  {
297  return;
298  }
299 
301  dlg.exec();
303  emit connectionsChanged();
304 }
305 
307  int id,
308  const QStringList &names,
310  int &layerAndStyleCount,
311  const QMap<int, int> &layerParents,
312  const QMap<int, QStringList> &layerParentNames )
313 {
314  QgsDebugMsg( QString( "id = %1 layerAndStyleCount = %2 names = %3 " ).arg( id ).arg( layerAndStyleCount ).arg( names.join( "," ) ) );
315  if ( items.contains( id ) )
316  return items[id];
317 
318 
320  if ( layerParents.contains( id ) )
321  {
322  // it has parent -> create first its parent
323  int parent = layerParents[ id ];
324  item = new QgsNumericSortTreeWidgetItem( createItem( parent, layerParentNames[ parent ], items, layerAndStyleCount, layerParents, layerParentNames ) );
325  }
326  else
327  item = new QgsNumericSortTreeWidgetItem( mLayersTreeWidget );
328 
329  item->setText( 0, QString::number( ++layerAndStyleCount ) );
330  item->setText( 1, names[0].simplified() );
331  item->setText( 2, names[1].simplified() );
332  item->setText( 3, names[2].simplified() );
333  item->setToolTip( 3, "<font color=black>" + names[2].simplified() + "</font>" );
334 
335  items[ id ] = item;
336 
337  return item;
338 }
339 
341 {
342 }
343 
345 {
346 
347  mLayersTreeWidget->clear();
348  clearFormats();
349  clearTimes();
350  clearCRS();
351 
352  mConnName = mConnectionsComboBox->currentText();
353 
354  QgsOWSConnection connection( mService, mConnectionsComboBox->currentText() );
355  mUri = connection.uri();
356 
357  QApplication::setOverrideCursor( Qt::WaitCursor );
358 
359  QgsDebugMsg( "call populateLayerList" );
361 
363 }
364 
366 {
367 }
368 
370 {
371 }
372 
374 {
375  QStringList layers;
376  Q_FOREACH ( QTreeWidgetItem *item, mLayersTreeWidget->selectedItems() )
377  {
378  QString layer = item->data( 0, Qt::UserRole + 0 ).toString();
379  if ( !layer.isEmpty() )
380  layers << layer;
381  }
382 
384  mySelector->setMessage();
385  mySelector->setOgcWmsCrsFilter( mSelectedLayersCRSs );
386 
387  QString myDefaultCrs = QgsProject::instance()->readEntry( "SpatialRefSys", "/ProjectCrs", GEO_EPSG_CRS_AUTHID );
388  QgsCoordinateReferenceSystem defaultCRS = QgsCRSCache::instance()->crsByOgcWmsCrs( myDefaultCrs );
389  if ( defaultCRS.isValid() )
390  {
391  mySelector->setSelectedCrsId( defaultCRS.srsid() );
392  }
393 
394  if ( !mySelector->exec() )
395  return;
396 
397  mSelectedCRS = mySelector->selectedAuthId();
398  delete mySelector;
399 
400  mSelectedCRSLabel->setText( descriptionForAuthId( mSelectedCRS ) );
401 
402  for ( int i = 0; i < mLayersTreeWidget->topLevelItemCount(); i++ )
403  {
404  enableLayersForCrs( mLayersTreeWidget->topLevelItem( i ) );
405  }
406 
407  updateButtons();
408 }
409 
411 {
412 }
413 
415 {
416  clearCRS();
417  mSelectedLayersCRSs = selectedLayersCRSs().toSet();
418  mCRSLabel->setText( tr( "Coordinate Reference System (%n available)", "crs count", mSelectedLayersCRSs.count() ) + ':' );
419 
420  mChangeCRSButton->setDisabled( mSelectedLayersCRSs.isEmpty() );
421 
422  if ( !mSelectedLayersCRSs.isEmpty() )
423  {
424  // check whether current CRS is supported
425  // if not, use one of the available CRS
426  QString defaultCRS;
427  QSet<QString>::const_iterator it = mSelectedLayersCRSs.constBegin();
428  for ( ; it != mSelectedLayersCRSs.constEnd(); ++it )
429  {
430  if ( it->compare( mSelectedCRS, Qt::CaseInsensitive ) == 0 )
431  break;
432 
433  // save first CRS in case the current CRS is not available
434  if ( it == mSelectedLayersCRSs.begin() )
435  defaultCRS = *it;
436 
437  // prefer value of DEFAULT_GEO_EPSG_CRS_ID if available
438  if ( *it == GEO_EPSG_CRS_AUTHID )
439  defaultCRS = *it;
440  }
441 
442  if ( it == mSelectedLayersCRSs.end() )
443  {
444  // not found
445  mSelectedCRS = defaultCRS;
446  }
447  mSelectedCRSLabel->setText( descriptionForAuthId( mSelectedCRS ) );
448  mChangeCRSButton->setEnabled( true );
449  }
450  QgsDebugMsg( "mSelectedCRS = " + mSelectedCRS );
451 }
452 
454 {
455  mCRSLabel->setText( tr( "Coordinate Reference System" ) + ':' );
456  mSelectedCRS = "";
457  mSelectedCRSLabel->setText( "" );
458  mChangeCRSButton->setEnabled( false );
459 }
460 
461 void QgsOWSSourceSelect::on_mTilesetsTableWidget_itemClicked( QTableWidgetItem *item )
462 {
463  Q_UNUSED( item );
464 
465  QTableWidgetItem *rowItem = mTilesetsTableWidget->item( mTilesetsTableWidget->currentRow(), 0 );
466  bool wasSelected = mCurrentTileset == rowItem;
467 
468  mTilesetsTableWidget->blockSignals( true );
469  mTilesetsTableWidget->clearSelection();
470  if ( !wasSelected )
471  {
472  QgsDebugMsg( QString( "selecting current row %1" ).arg( mTilesetsTableWidget->currentRow() ) );
473  mTilesetsTableWidget->selectRow( mTilesetsTableWidget->currentRow() );
474  mCurrentTileset = rowItem;
475  }
476  else
477  {
478  mCurrentTileset = nullptr;
479  }
480  mTilesetsTableWidget->blockSignals( false );
481 
482  updateButtons();
483 }
484 
485 
486 
488 {
489  return mConnName;
490 }
491 
493 {
494  return mConnectionInfo;
495 }
496 
498 {
499  return selectedLayersFormats().value( mFormatComboBox->currentIndex() );
500 }
501 
502 QNetworkRequest::CacheLoadControl QgsOWSSourceSelect::selectedCacheLoadControl()
503 {
504  int cache = mCacheComboBox->itemData( mCacheComboBox->currentIndex() ).toInt();
505  return static_cast<QNetworkRequest::CacheLoadControl>( cache );
506 }
507 
509 {
510  return mSelectedCRS;
511 }
512 
514 {
515  return mTimeComboBox->currentText();
516 }
517 
519 {
521 
522  mConnectionsComboBox->setCurrentIndex( mConnectionsComboBox->findText( toSelect ) );
523 
524  if ( mConnectionsComboBox->currentIndex() < 0 )
525  {
526  if ( toSelect.isNull() )
527  mConnectionsComboBox->setCurrentIndex( 0 );
528  else
529  mConnectionsComboBox->setCurrentIndex( mConnectionsComboBox->count() - 1 );
530  }
531 
532  if ( mConnectionsComboBox->count() == 0 )
533  {
534  // No connections - disable various buttons
535  mConnectButton->setEnabled( false );
536  mEditButton->setEnabled( false );
537  mDeleteButton->setEnabled( false );
538  mSaveButton->setEnabled( false );
539  }
540  else
541  {
542  // Connections - enable various buttons
543  mConnectButton->setEnabled( true );
544  mEditButton->setEnabled( true );
545  mDeleteButton->setEnabled( true );
546  mSaveButton->setEnabled( true );
547  }
548 
549  QgsOWSConnection::setSelectedConnection( mService, mConnectionsComboBox->currentText() );
550 }
551 
553 {
554  mStatusLabel->setText( theMessage );
555 
556  // update the display of this widget
557  update();
558 }
559 
560 
561 void QgsOWSSourceSelect::showError( QString const &theTitle, QString const &theFormat, QString const &theError )
562 {
563  QgsMessageViewer * mv = new QgsMessageViewer( this );
564  mv->setWindowTitle( theTitle );
565 
566  if ( theFormat == "text/html" )
567  {
568  mv->setMessageAsHtml( theError );
569  }
570  else
571  {
572  mv->setMessageAsPlainText( tr( "Could not understand the response:\n%1" ).arg( theError ) );
573  }
574  mv->showMessage( true ); // Is deleted when closed
575 }
576 
578 {
579  // Remember which server was selected.
580  QgsOWSConnection::setSelectedConnection( mService, mConnectionsComboBox->currentText() );
581 }
582 
584 {
586 }
587 
589 {
590  if ( mCrsNames.contains( authId ) )
591  return mCrsNames[ authId ];
592 
594  mCrsNames.insert( authId, qgisSrs.description() );
595  return qgisSrs.description();
596 }
597 
599 {
600  QMap<QString, QString> exampleServers;
601  exampleServers["DM Solutions GMap"] = "http://www2.dmsolutions.ca/cgi-bin/mswms_gmap";
602  exampleServers["Lizardtech server"] = "http://wms.lizardtech.com/lizardtech/iserv/ows";
603  // Nice to have the qgis users map, but I'm not sure of the URL at the moment.
604  // exampleServers["Qgis users map"] = "http://qgis.org/wms.cgi";
605 
606  QSettings settings;
607  settings.beginGroup( "/Qgis/connections-" + mService.toLower() );
609  for ( ; i != exampleServers.constEnd(); ++i )
610  {
611  // Only do a server if it's name doesn't already exist.
612  QStringList keys = settings.childGroups();
613  if ( !keys.contains( i.key() ) )
614  {
615  QString path = i.key();
616  settings.setValue( path + "/url", i.value() );
617  }
618  }
619  settings.endGroup();
621 
622  QMessageBox::information( this, tr( "WMS proxies" ), "<p>" + tr( "Several WMS servers have "
623  "been added to the server list. Note that if "
624  "you access the internet via a web proxy, you will "
625  "need to set the proxy settings in the QGIS options dialog." ) + "</p>" );
626 }
627 
628 void QgsOWSSourceSelect::addWMSListRow( const QDomElement& item, int row )
629 {
630  QDomElement title = item.firstChildElement( "title" );
631  addWMSListItem( title, row, 0 );
632  QDomElement description = item.firstChildElement( "description" );
633  addWMSListItem( description, row, 1 );
634  QDomElement link = item.firstChildElement( "link" );
635  addWMSListItem( link, row, 2 );
636 }
637 
638 void QgsOWSSourceSelect::addWMSListItem( const QDomElement& el, int row, int column )
639 {
640  if ( !el.isNull() )
641  {
642  QTableWidgetItem* tableItem = new QTableWidgetItem( el.text() );
643  // TODO: add linebreaks to long tooltips?
644  tableItem->setToolTip( el.text() );
645  mSearchTableWidget->setItem( row, column, tableItem );
646  }
647 }
648 
649 void QgsOWSSourceSelect::on_mSearchButton_clicked()
650 {
651  // clear results
652  mSearchTableWidget->clearContents();
653  mSearchTableWidget->setRowCount( 0 );
654 
655  // disable Add WMS button
656  mSearchAddButton->setEnabled( false );
657 
658  QApplication::setOverrideCursor( Qt::WaitCursor );
659 
660  QSettings settings;
661  // geopole.org (geopole.ch) 25.4.2012 : 503 Service Unavailable, archive: Recently added 20 Jul 2011
662  QString mySearchUrl = settings.value( "/qgis/WMSSearchUrl", "http://geopole.org/wms/search?search=%1&type=rss" ).toString();
663  QUrl url( mySearchUrl.arg( mSearchTermLineEdit->text() ) );
664  QgsDebugMsg( url.toString() );
665 
667  connect( r, SIGNAL( finished() ), SLOT( searchFinished() ) );
668 }
669 
671 {
673 
674  QNetworkReply *r = qobject_cast<QNetworkReply *>( sender() );
675  if ( !r )
676  return;
677 
678  if ( r->error() == QNetworkReply::NoError )
679  {
680  // parse results
681  QDomDocument doc( "RSS" );
682  QByteArray res = r->readAll();
683  QString error;
684  int line, column;
685  if ( doc.setContent( res, &error, &line, &column ) )
686  {
687  QDomNodeList list = doc.elementsByTagName( "item" );
688  mSearchTableWidget->setRowCount( list.size() );
689  for ( int i = 0; i < list.size(); i++ )
690  {
691  if ( list.item( i ).isElement() )
692  {
693  QDomElement item = list.item( i ).toElement();
694  addWMSListRow( item, i );
695  }
696  }
697 
698  mSearchTableWidget->resizeColumnsToContents();
699  }
700  else
701  {
702  QgsDebugMsg( "setContent failed" );
703  showStatusMessage( tr( "parse error at row %1, column %2: %3" ).arg( line ).arg( column ).arg( error ) );
704  }
705  }
706  else
707  {
708  showStatusMessage( tr( "network error: %1" ).arg( r->error() ) );
709  }
710 
711  r->deleteLater();
712 }
713 
714 void QgsOWSSourceSelect::on_mSearchTableWidget_itemSelectionChanged()
715 {
716  mSearchAddButton->setEnabled( mSearchTableWidget->currentRow() != -1 );
717 }
718 
719 void QgsOWSSourceSelect::on_mLayerUpButton_clicked()
720 {
721  QList<QTreeWidgetItem *> selectionList = mLayerOrderTreeWidget->selectedItems();
722  if ( selectionList.size() < 1 )
723  {
724  return;
725  }
726  int selectedIndex = mLayerOrderTreeWidget->indexOfTopLevelItem( selectionList[0] );
727  if ( selectedIndex < 1 )
728  {
729  return; //item not existing or already on top
730  }
731 
732  QTreeWidgetItem* selectedItem = mLayerOrderTreeWidget->takeTopLevelItem( selectedIndex );
733  mLayerOrderTreeWidget->insertTopLevelItem( selectedIndex - 1, selectedItem );
734  mLayerOrderTreeWidget->clearSelection();
735  selectedItem->setSelected( true );
736 }
737 
738 void QgsOWSSourceSelect::on_mLayerDownButton_clicked()
739 {
740  QList<QTreeWidgetItem *> selectionList = mLayerOrderTreeWidget->selectedItems();
741  if ( selectionList.size() < 1 )
742  {
743  return;
744  }
745  int selectedIndex = mLayerOrderTreeWidget->indexOfTopLevelItem( selectionList[0] );
746  if ( selectedIndex < 0 || selectedIndex > mLayerOrderTreeWidget->topLevelItemCount() - 2 )
747  {
748  return; //item not existing or already at bottom
749  }
750 
751  QTreeWidgetItem* selectedItem = mLayerOrderTreeWidget->takeTopLevelItem( selectedIndex );
752  mLayerOrderTreeWidget->insertTopLevelItem( selectedIndex + 1, selectedItem );
753  mLayerOrderTreeWidget->clearSelection();
754  selectedItem->setSelected( true );
755 }
756 
758 {
759  return QList<SupportedFormat>();
760 }
761 
763 {
764  return QStringList();
765 }
766 
768 {
769  return QStringList();
770 }
771 
773 {
774  return QStringList();
775 }
776 
777 void QgsOWSSourceSelect::updateButtons()
778 {
779 }
Connections management.
void on_mNewButton_clicked()
Opens the create connection dialog to build a new connection.
QByteArray toByteArray() const
QDomNode item(int index) const
void setupUi(QWidget *widget)
bool contains(const Key &key) const
QgsOWSSourceSelect(const QString &service, QWidget *parent=nullptr, const Qt::WindowFlags &fl=QgisGui::ModalDialogFlags, bool managerMode=false, bool embeddedMode=false)
Constructor.
QMap< QString, QString > mCrsNames
virtual void populateLayerList()
Populate the layer list.
QgsCoordinateReferenceSystem crsBySrsId(long srsId) const
Returns the CRS from a specified QGIS SRS ID.
void clearTimes()
Clear times.
QString selectedCRS()
Returns currently selected Crs.
QString connectionInfo()
Connection info (uri)
void setToolTip(int column, const QString &toolTip)
static QString selectedConnection(const QString &theService)
Retreives the selected connection for the specified service.
#define QgsDebugMsg(str)
Definition: qgslogger.h:33
long srsid() const
Returns the SrsId, if available.
void endGroup()
QObject * sender() const
bool isElement() const
const_iterator constBegin() const
~QgsOWSSourceSelect()
Destructor.
A generic dialog to prompt the user for a Coordinate Reference System.
bool contains(const QString &str, Qt::CaseSensitivity cs) const
static QStringList connectionList(const QString &theService)
Returns the list of connections for the specified service.
bool mManagerMode
Connections manager mode.
int exec()
QString selectedFormat()
Returns currently selected format.
void on_mChangeCRSButton_clicked()
Opens the Spatial Reference System dialog.
QString descriptionForAuthId(const QString &authId)
Returns a textual description for the authority id.
QSet< T > toSet() const
void setOgcWmsCrsFilter(const QSet< QString > &crsFilter)
filters this dialog by the given CRSs
QString join(const QString &separator) const
QString & remove(int position, int n)
virtual QVariant data(int column, int role) const
QString homePath()
virtual QStringList selectedLayersFormats()
List of formats supported for currently selected layer item(s)
QString toString(QFlags< QUrl::FormattingOption > options) const
QString tr(const char *sourceText, const char *disambiguation, int n)
StandardButton information(QWidget *parent, const QString &title, const QString &text, QFlags< QMessageBox::StandardButton > buttons, StandardButton defaultButton)
void populateCRS()
Set supported CRSs.
void update()
QNetworkRequest::CacheLoadControl selectedCacheLoadControl()
Returns currently selected cache load control.
int size() const
void on_mConnectionsComboBox_activated(int)
Stores the selected datasource whenerver it is changed.
bool isNull() const
static void setSelectedConnection(const QString &theService, const QString &name)
Marks the specified connection for the specified service as selected.
T value(int i) const
void finished(int result)
QDomElement toElement() const
void setMessageAsHtml(const QString &msg)
void setValue(const QString &key, const QVariant &value)
QString readEntry(const QString &scope, const QString &key, const QString &def=QString::null, bool *ok=nullptr) const
void populateConnectionList()
Populate the connection list combo box.
void setEnabled(bool)
QString number(int n, int base)
QgsCoordinateReferenceSystem crsByOgcWmsCrs(const QString &ogcCrs) const
Returns the CRS from a given OGC WMS-format Coordinate Reference System string.
QString text() const
bool mEmbeddedMode
Embedded mode, without &#39;Close&#39;.
static void deleteConnection(const QString &theService, const QString &name)
Deletes the connection for the specified service with the specified name.
bool restoreGeometry(const QByteArray &geometry)
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.
QDomNodeList elementsByTagName(const QString &tagname) const
bool isEmpty() const
void setMessage(QString theMessage="")
If no parameter is passed, the message will be a generic &#39;define the CRS for this layer&#39;...
const_iterator constEnd() const
void on_mEditButton_clicked()
Opens a dialog to edit an existing connection.
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const
QByteArray readAll()
QStringList childGroups() const
void setOverrideCursor(const QCursor &cursor)
void setMessageAsPlainText(const QString &msg)
void restoreOverrideCursor()
const QString GEO_EPSG_CRS_AUTHID
Geographic coord sys from EPSG authority.
Definition: qgis.cpp:74
const_iterator constEnd() const
int result() const
void populateFormats()
Populate supported formats.
QgsDataSourceURI mUri
URI for selected connection.
void deleteLater()
void hide()
int count() const
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.
QgsNumericSortTreeWidgetItem * createItem(int id, const QStringList &names, QMap< int, QgsNumericSortTreeWidgetItem * > &items, int &layerAndStyleCount, const QMap< int, int > &layerParents, const QMap< int, QStringList > &layerParentNames)
create an item including possible parents
void on_mAddDefaultButton_clicked()
Add some default wms servers to the list.
QString toLower() const
void addWMSListRow(const QDomElement &item, int row)
iterator begin()
int readNumEntry(const QString &scope, const QString &key, int def=0, bool *ok=nullptr) const
bool contains(QChar ch, Qt::CaseSensitivity cs) const
virtual void on_mLayersTreeWidget_itemSelectionChanged()
Signaled when a layer selection is changed.
void on_mDeleteButton_clicked()
Deletes the selected connection.
const_iterator constBegin() const
bool isNull() const
const Key key(const T &value) const
virtual void addClicked()
Determines the layers the user selected.
bool isValid() const
Returns whether this CRS is correctly initialized and usable.
QVariant value(const QString &key, const QVariant &defaultValue) const
QString connName()
Connection name.
void addWMSListItem(const QDomElement &el, int row, int column)
QString mConnectionInfo
Connection info for selected connection.
QByteArray saveGeometry() const
static QgsNetworkAccessManager * instance()
returns a pointer to the single instance
QTreeWidgetItem that can sort numerically (as opposed to just lexigraphically)
iterator end()
void setSelected(bool select)
static QgsProject * instance()
Returns the QgsProject singleton instance.
Definition: qgsproject.cpp:382
void setWindowTitle(const QString &)
QDomElement firstChildElement(const QString &tagName) const
Class for storing a coordinate reference system (CRS)
void setText(int column, const QString &text)
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, which includes both the authority (eg EPSG) and the CRS...
bool isEmpty() const
void showStatusMessage(const QString &theMessage)
Set status message to theMessage.
void on_mSaveButton_clicked()
Saves connections to the file.
void setText(const QString &text)
QString selectedTime()
Returns currently selected time.
NetworkError error() const
typedef WindowFlags
void clearFormats()
Clear previously set formats.
iterator insert(const Key &key, const T &value)
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".
QNetworkReply * get(const QNetworkRequest &request)
QTableWidgetItem * mCurrentTileset
void setToolTip(const QString &)
QString getOpenFileName(QWidget *parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedFilter, QFlags< QFileDialog::Option > options)
int size() const
Dialog to allow the user to configure and save connection information for an HTTP Server for WMS...
virtual QStringList selectedLayersCRSs()
Server CRS supported for currently selected layer item(s)
QString uri(bool expandAuthConfig=true) const
return complete uri
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QObject * parent() const
void setConnectionListPosition()
Set the server connection combo box to that stored in the config file.
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
QString toString() const
void populateTimes()
Populate times.
static QgsCRSCache * instance()
Returns a pointer to the QgsCRSCache singleton.
Definition: qgscrscache.cpp:91
void setToolTip(const QString &toolTip)
void beginGroup(const QString &prefix)
bool setContent(const QByteArray &data, bool namespaceProcessing, QString *errorMsg, int *errorLine, int *errorColumn)
const T value(const Key &key) const
QString mConnName
Name for selected connection.
void clearCRS()
Clear CRSs.