QGIS API Documentation  2.7.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 
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( 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( 0 )
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
96  long currentCRS = QgsProject::instance()->readNumEntry( "SpatialRefSys", "/ProjectCRSID", -1 );
97  if ( currentCRS != -1 )
98  {
99  //convert CRS id to epsg
101  if ( currentRefSys.isValid() )
102  {
103  mSelectedCRS = currentRefSys.authid();
104  }
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  mAddButton->hide();
115  mCacheWidget->hide();
116  }
117 
118  // set up the WMS connections we already know about
120 
121  QSettings settings;
122  QgsDebugMsg( "restoring geometry" );
123  restoreGeometry( settings.value( "/Windows/WMSSourceSelect/geometry" ).toByteArray() );
124 }
125 
127 {
128  QSettings settings;
129  QgsDebugMsg( "saving geometry" );
130  settings.setValue( "/Windows/WMSSourceSelect/geometry", saveGeometry() );
131 }
132 
134 {
135  mFormatComboBox->clear();
136  mFormatComboBox->setEnabled( false );
137 }
138 
140 {
141  QgsDebugMsg( "entered" );
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.size() == 0 )
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().replace( "image/", "" ).replace( 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  QgsDebugMsg( "entered" );
228  mTimeComboBox->clear();
229  mTimeComboBox->insertItems( 0, selectedLayersTimes() );
230  mTimeComboBox->setEnabled( !selectedLayersTimes().isEmpty() );
231 }
232 
234 {
235  mTimeComboBox->clear();
236  mTimeComboBox->setEnabled( false );
237 }
238 
240 {
241  mConnectionsComboBox->clear();
242  mConnectionsComboBox->addItems( QgsOWSConnection::connectionList( mService ) );
243 
245 }
247 {
248  QgsNewHttpConnection *nc = new QgsNewHttpConnection( this, "/Qgis/connections-" + mService.toLower() + "/" );
249 
250  if ( nc->exec() )
251  {
253  emit connectionsChanged();
254  }
255 
256  delete nc;
257 }
258 
260 {
261  QgsNewHttpConnection *nc = new QgsNewHttpConnection( this, "/Qgis/connections-" + mService.toLower() + "/", mConnectionsComboBox->currentText() );
262 
263  if ( nc->exec() )
264  {
266  emit connectionsChanged();
267  }
268 
269  delete nc;
270 }
271 
273 {
274  QString msg = tr( "Are you sure you want to remove the %1 connection and all associated settings?" )
275  .arg( mConnectionsComboBox->currentText() );
276  QMessageBox::StandardButton result = QMessageBox::information( this, tr( "Confirm Delete" ), msg, QMessageBox::Ok | QMessageBox::Cancel );
277  if ( result == QMessageBox::Ok )
278  {
279  QgsOWSConnection::deleteConnection( mService, mConnectionsComboBox->currentText() );
280  mConnectionsComboBox->removeItem( mConnectionsComboBox->currentIndex() ); // populateConnectionList();
282  emit connectionsChanged();
283  }
284 }
285 
287 {
289  dlg.exec();
290 }
291 
293 {
294  QString fileName = QFileDialog::getOpenFileName( this, tr( "Load connections" ), ".",
295  tr( "XML files (*.xml *XML)" ) );
296  if ( fileName.isEmpty() )
297  {
298  return;
299  }
300 
302  dlg.exec();
304  emit connectionsChanged();
305 }
306 
308  int id,
309  const QStringList &names,
310  QMap<int, QgsNumericSortTreeWidgetItem *> &items,
311  int &layerAndStyleCount,
312  const QMap<int, int> &layerParents,
313  const QMap<int, QStringList> &layerParentNames )
314 {
315  QgsDebugMsg( QString( "id = %1 layerAndStyleCount = %2 names = %3 " ).arg( id ).arg( layerAndStyleCount ).arg( names.join( "," ) ) );
316  if ( items.contains( id ) )
317  return items[id];
318 
319 
321  if ( layerParents.contains( id ) )
322  {
323  // it has parent -> create first its parent
324  int parent = layerParents[ id ];
325  item = new QgsNumericSortTreeWidgetItem( createItem( parent, layerParentNames[ parent ], items, layerAndStyleCount, layerParents, layerParentNames ) );
326  }
327  else
328  item = new QgsNumericSortTreeWidgetItem( mLayersTreeWidget );
329 
330  item->setText( 0, QString::number( ++layerAndStyleCount ) );
331  item->setText( 1, names[0].simplified() );
332  item->setText( 2, names[1].simplified() );
333  item->setText( 3, names[2].simplified() );
334  item->setToolTip( 3, "<font color=black>" + names[2].simplified() + "</font>" );
335 
336  items[ id ] = item;
337 
338  return item;
339 }
340 
342 {
343 }
344 
346 {
347  QgsDebugMsg( "entered" );
348 
349  mLayersTreeWidget->clear();
350  clearFormats();
351  clearTimes();
352  clearCRS();
353 
354  mConnName = mConnectionsComboBox->currentText();
355 
356  QgsOWSConnection connection( mService, mConnectionsComboBox->currentText() );
357  mUri = connection.uri();
358 
359  QApplication::setOverrideCursor( Qt::WaitCursor );
360 
361  QgsDebugMsg( "call populateLayerList" );
363 
364  QApplication::restoreOverrideCursor();
365 }
366 
368 {
369  QgsDebugMsg( "entered" );
370 }
371 
372 void QgsOWSSourceSelect::enableLayersForCrs( QTreeWidgetItem * )
373 {
374 }
375 
377 {
378  QStringList layers;
379  foreach ( QTreeWidgetItem *item, mLayersTreeWidget->selectedItems() )
380  {
381  QString layer = item->data( 0, Qt::UserRole + 0 ).toString();
382  if ( !layer.isEmpty() )
383  layers << layer;
384  }
385 
387  mySelector->setMessage();
388  mySelector->setOgcWmsCrsFilter( mSelectedLayersCRSs );
389 
390  QString myDefaultCrs = QgsProject::instance()->readEntry( "SpatialRefSys", "/ProjectCrs", GEO_EPSG_CRS_AUTHID );
391  QgsCoordinateReferenceSystem defaultCRS;
392  if ( defaultCRS.createFromOgcWmsCrs( myDefaultCrs ) )
393  {
394  mySelector->setSelectedCrsId( defaultCRS.srsid() );
395  }
396 
397  if ( !mySelector->exec() )
398  return;
399 
400  mSelectedCRS = mySelector->selectedAuthId();
401  delete mySelector;
402 
403  mSelectedCRSLabel->setText( descriptionForAuthId( mSelectedCRS ) );
404 
405  for ( int i = 0; i < mLayersTreeWidget->topLevelItemCount(); i++ )
406  {
407  enableLayersForCrs( mLayersTreeWidget->topLevelItem( i ) );
408  }
409 
410  updateButtons();
411 }
412 
414 {
415 }
416 
418 {
419  QgsDebugMsg( "Entered" );
420  clearCRS();
421  mSelectedLayersCRSs = selectedLayersCRSs().toSet();
422  mCRSLabel->setText( tr( "Coordinate Reference System (%n available)", "crs count", mSelectedLayersCRSs.count() ) + ":" );
423 
424  mChangeCRSButton->setDisabled( mSelectedLayersCRSs.isEmpty() );
425 
426  if ( !mSelectedLayersCRSs.isEmpty() )
427  {
428  // check whether current CRS is supported
429  // if not, use one of the available CRS
430  QString defaultCRS;
431  QSet<QString>::const_iterator it = mSelectedLayersCRSs.begin();
432  for ( ; it != mSelectedLayersCRSs.end(); ++it )
433  {
434  if ( it->compare( mSelectedCRS, Qt::CaseInsensitive ) == 0 )
435  break;
436 
437  // save first CRS in case the current CRS is not available
438  if ( it == mSelectedLayersCRSs.begin() )
439  defaultCRS = *it;
440 
441  // prefer value of DEFAULT_GEO_EPSG_CRS_ID if available
442  if ( *it == GEO_EPSG_CRS_AUTHID )
443  defaultCRS = *it;
444  }
445 
446  if ( it == mSelectedLayersCRSs.end() )
447  {
448  // not found
449  mSelectedCRS = defaultCRS;
450  }
451  mSelectedCRSLabel->setText( descriptionForAuthId( mSelectedCRS ) );
452  mChangeCRSButton->setEnabled( true );
453  }
454  QgsDebugMsg( "mSelectedCRS = " + mSelectedCRS );
455 }
456 
458 {
459  mCRSLabel->setText( tr( "Coordinate Reference System" ) + ":" );
460  mSelectedCRS = "";
461  mSelectedCRSLabel->setText( "" );
462  mChangeCRSButton->setEnabled( false );
463 }
464 
465 void QgsOWSSourceSelect::on_mTilesetsTableWidget_itemClicked( QTableWidgetItem *item )
466 {
467  Q_UNUSED( item );
468 
469  QTableWidgetItem *rowItem = mTilesetsTableWidget->item( mTilesetsTableWidget->currentRow(), 0 );
470  bool wasSelected = mCurrentTileset == rowItem;
471 
472  mTilesetsTableWidget->blockSignals( true );
473  mTilesetsTableWidget->clearSelection();
474  if ( !wasSelected )
475  {
476  QgsDebugMsg( QString( "selecting current row %1" ).arg( mTilesetsTableWidget->currentRow() ) );
477  mTilesetsTableWidget->selectRow( mTilesetsTableWidget->currentRow() );
478  mCurrentTileset = rowItem;
479  }
480  else
481  {
482  mCurrentTileset = 0;
483  }
484  mTilesetsTableWidget->blockSignals( false );
485 
486  updateButtons();
487 }
488 
489 
490 
492 {
493  return mConnName;
494 }
495 
497 {
498  return mConnectionInfo;
499 }
500 
502 {
503  return selectedLayersFormats().value( mFormatComboBox->currentIndex() );
504 }
505 
506 QNetworkRequest::CacheLoadControl QgsOWSSourceSelect::selectedCacheLoadControl()
507 {
508  int cache = mCacheComboBox->itemData( mCacheComboBox->currentIndex() ).toInt();
509  return static_cast<QNetworkRequest::CacheLoadControl>( cache );
510 }
511 
513 {
514  return mSelectedCRS;
515 }
516 
518 {
519  return mTimeComboBox->currentText();
520 }
521 
523 {
524  QString toSelect = QgsOWSConnection::selectedConnection( mService );
525 
526  mConnectionsComboBox->setCurrentIndex( mConnectionsComboBox->findText( toSelect ) );
527 
528  if ( mConnectionsComboBox->currentIndex() < 0 )
529  {
530  if ( toSelect.isNull() )
531  mConnectionsComboBox->setCurrentIndex( 0 );
532  else
533  mConnectionsComboBox->setCurrentIndex( mConnectionsComboBox->count() - 1 );
534  }
535 
536  if ( mConnectionsComboBox->count() == 0 )
537  {
538  // No connections - disable various buttons
539  mConnectButton->setEnabled( false );
540  mEditButton->setEnabled( false );
541  mDeleteButton->setEnabled( false );
542  mSaveButton->setEnabled( false );
543  }
544  else
545  {
546  // Connections - enable various buttons
547  mConnectButton->setEnabled( true );
548  mEditButton->setEnabled( true );
549  mDeleteButton->setEnabled( true );
550  mSaveButton->setEnabled( true );
551  }
552 
553  QgsOWSConnection::setSelectedConnection( mService, mConnectionsComboBox->currentText() );
554 }
555 
556 void QgsOWSSourceSelect::showStatusMessage( QString const &theMessage )
557 {
558  mStatusLabel->setText( theMessage );
559 
560  // update the display of this widget
561  update();
562 }
563 
564 
565 void QgsOWSSourceSelect::showError( QString const &theTitle, QString const &theFormat, QString const &theError )
566 {
567  QgsMessageViewer * mv = new QgsMessageViewer( this );
568  mv->setWindowTitle( theTitle );
569 
570  if ( theFormat == "text/html" )
571  {
572  mv->setMessageAsHtml( theError );
573  }
574  else
575  {
576  mv->setMessageAsPlainText( tr( "Could not understand the response:\n%1" ).arg( theError ) );
577  }
578  mv->showMessage( true ); // Is deleted when closed
579 }
580 
582 {
583  // Remember which server was selected.
584  QgsOWSConnection::setSelectedConnection( mService, mConnectionsComboBox->currentText() );
585 }
586 
588 {
590 }
591 
593 {
594  if ( mCrsNames.contains( authId ) )
595  return mCrsNames[ authId ];
596 
598  qgisSrs.createFromOgcWmsCrs( authId );
599  mCrsNames.insert( authId, qgisSrs.description() );
600  return qgisSrs.description();
601 }
602 
604 {
605  QMap<QString, QString> exampleServers;
606  exampleServers["DM Solutions GMap"] = "http://www2.dmsolutions.ca/cgi-bin/mswms_gmap";
607  exampleServers["Lizardtech server"] = "http://wms.lizardtech.com/lizardtech/iserv/ows";
608  // Nice to have the qgis users map, but I'm not sure of the URL at the moment.
609  // exampleServers["Qgis users map"] = "http://qgis.org/wms.cgi";
610 
611  QSettings settings;
612  settings.beginGroup( "/Qgis/connections-" + mService.toLower() );
613  QMap<QString, QString>::const_iterator i = exampleServers.constBegin();
614  for ( ; i != exampleServers.constEnd(); ++i )
615  {
616  // Only do a server if it's name doesn't already exist.
617  QStringList keys = settings.childGroups();
618  if ( !keys.contains( i.key() ) )
619  {
620  QString path = i.key();
621  settings.setValue( path + "/url", i.value() );
622  }
623  }
624  settings.endGroup();
626 
627  QMessageBox::information( this, tr( "WMS proxies" ), "<p>" + tr( "Several WMS servers have "
628  "been added to the server list. Note that if "
629  "you access the internet via a web proxy, you will "
630  "need to set the proxy settings in the QGIS options dialog." ) + "</p>" );
631 }
632 
633 void QgsOWSSourceSelect::addWMSListRow( const QDomElement& item, int row )
634 {
635  QDomElement title = item.firstChildElement( "title" );
636  addWMSListItem( title, row, 0 );
637  QDomElement description = item.firstChildElement( "description" );
638  addWMSListItem( description, row, 1 );
639  QDomElement link = item.firstChildElement( "link" );
640  addWMSListItem( link, row, 2 );
641 }
642 
643 void QgsOWSSourceSelect::addWMSListItem( const QDomElement& el, int row, int column )
644 {
645  if ( !el.isNull() )
646  {
647  QTableWidgetItem* tableItem = new QTableWidgetItem( el.text() );
648  // TODO: add linebreaks to long tooltips?
649  tableItem->setToolTip( el.text() );
650  mSearchTableWidget->setItem( row, column, tableItem );
651  }
652 }
653 
654 void QgsOWSSourceSelect::on_mSearchButton_clicked()
655 {
656  // clear results
657  mSearchTableWidget->clearContents();
658  mSearchTableWidget->setRowCount( 0 );
659 
660  // disable Add WMS button
661  mSearchAddButton->setEnabled( false );
662 
663  QApplication::setOverrideCursor( Qt::WaitCursor );
664 
665  QSettings settings;
666  // geopole.org (geopole.ch) 25.4.2012 : 503 Service Unavailable, archive: Recently added 20 Jul 2011
667  QString mySearchUrl = settings.value( "/qgis/WMSSearchUrl", "http://geopole.org/wms/search?search=%1&type=rss" ).toString();
668  QUrl url( mySearchUrl.arg( mSearchTermLineEdit->text() ) );
669  QgsDebugMsg( url.toString() );
670 
671  QNetworkReply *r = QgsNetworkAccessManager::instance()->get( QNetworkRequest( url ) );
672  connect( r, SIGNAL( finished() ), SLOT( searchFinished() ) );
673 }
674 
676 {
677  QApplication::restoreOverrideCursor();
678 
679  QNetworkReply *r = qobject_cast<QNetworkReply *>( sender() );
680  if ( !r )
681  return;
682 
683  if ( r->error() == QNetworkReply::NoError )
684  {
685  // parse results
686  QDomDocument doc( "RSS" );
687  QByteArray res = r->readAll();
688  QString error;
689  int line, column;
690  if ( doc.setContent( res, &error, &line, &column ) )
691  {
692  QDomNodeList list = doc.elementsByTagName( "item" );
693  mSearchTableWidget->setRowCount( list.size() );
694  for ( int i = 0; i < list.size(); i++ )
695  {
696  if ( list.item( i ).isElement() )
697  {
698  QDomElement item = list.item( i ).toElement();
699  addWMSListRow( item, i );
700  }
701  }
702 
703  mSearchTableWidget->resizeColumnsToContents();
704  }
705  else
706  {
707  QgsDebugMsg( "setContent failed" );
708  showStatusMessage( tr( "parse error at row %1, column %2: %3" ).arg( line ).arg( column ).arg( error ) );
709  }
710  }
711  else
712  {
713  showStatusMessage( tr( "network error: %1" ).arg( r->error() ) );
714  }
715 
716  r->deleteLater();
717 }
718 
719 void QgsOWSSourceSelect::on_mSearchTableWidget_itemSelectionChanged()
720 {
721  mSearchAddButton->setEnabled( mSearchTableWidget->currentRow() != -1 );
722 }
723 
724 void QgsOWSSourceSelect::on_mLayerUpButton_clicked()
725 {
726  QList<QTreeWidgetItem *> selectionList = mLayerOrderTreeWidget->selectedItems();
727  if ( selectionList.size() < 1 )
728  {
729  return;
730  }
731  int selectedIndex = mLayerOrderTreeWidget->indexOfTopLevelItem( selectionList[0] );
732  if ( selectedIndex < 1 )
733  {
734  return; //item not existing or already on top
735  }
736 
737  QTreeWidgetItem* selectedItem = mLayerOrderTreeWidget->takeTopLevelItem( selectedIndex );
738  mLayerOrderTreeWidget->insertTopLevelItem( selectedIndex - 1, selectedItem );
739  mLayerOrderTreeWidget->clearSelection();
740  selectedItem->setSelected( true );
741 }
742 
743 void QgsOWSSourceSelect::on_mLayerDownButton_clicked()
744 {
745  QList<QTreeWidgetItem *> selectionList = mLayerOrderTreeWidget->selectedItems();
746  if ( selectionList.size() < 1 )
747  {
748  return;
749  }
750  int selectedIndex = mLayerOrderTreeWidget->indexOfTopLevelItem( selectionList[0] );
751  if ( selectedIndex < 0 || selectedIndex > mLayerOrderTreeWidget->topLevelItemCount() - 2 )
752  {
753  return; //item not existing or already at bottom
754  }
755 
756  QTreeWidgetItem* selectedItem = mLayerOrderTreeWidget->takeTopLevelItem( selectedIndex );
757  mLayerOrderTreeWidget->insertTopLevelItem( selectedIndex + 1, selectedItem );
758  mLayerOrderTreeWidget->clearSelection();
759  selectedItem->setSelected( true );
760 }
761 
762 QList<QgsOWSSourceSelect::SupportedFormat> QgsOWSSourceSelect::providerFormats()
763 {
764  return QList<SupportedFormat>();
765 }
766 
768 {
769  return QStringList();
770 }
771 
773 {
774  return QStringList();
775 }
776 
778 {
779  return QStringList();
780 }
781 
782 void QgsOWSSourceSelect::updateButtons()
783 {
784 }
Connections management.
void on_mNewButton_clicked()
Opens the create connection dialog to build a new connection.
QMap< QString, QString > mCrsNames
virtual void populateLayerList()
Populate the layer list.
void clearTimes()
Clear times.
QString selectedCRS()
Returns currently selected Crs.
QString connectionInfo()
Connection info (uri)
static QString selectedConnection(const QString &theService)
#define QgsDebugMsg(str)
Definition: qgslogger.h:33
static QgsNetworkAccessManager * instance()
Definition: qgssingleton.h:23
~QgsOWSSourceSelect()
Destructor.
A generic dialog to prompt the user for a Coordinate Reference System.
static QStringList connectionList(const QString &theService)
bool mManagerMode
Connections manager mode.
QString selectedFormat()
Returns currently selected format.
void on_mChangeCRSButton_clicked()
Opens the Spatial Reference System dialog.
virtual QStringList selectedLayersFormats()
List of formats supported for currently selected layer item(s)
int readNumEntry(const QString &scope, const QString &key, int def=0, bool *ok=0) const
void populateCRS()
Set supported CRSs.
QNetworkRequest::CacheLoadControl selectedCacheLoadControl()
Returns currently selected cache load control.
void on_mConnectionsComboBox_activated(int)
Stores the selected datasource whenerver it is changed.
static void setSelectedConnection(const QString &theService, const QString &name)
void setMessageAsHtml(const QString &msg)
bool createFromOgcWmsCrs(QString theCrs)
Set up this CRS from the given OGC CRS.
void populateConnectionList()
Populate the connection list combo box.
virtual void showMessage(bool blocking=true)
display the message to the user
bool mEmbeddedMode
Embedded mode, without 'Close'.
static void deleteConnection(const QString &theService, const QString &name)
QString uri() const
return complete uri
virtual void enableLayersForCrs(QTreeWidgetItem *item)
void addDefaultServers()
Add a few example servers to the list.
QPushButton * mAddButton
void setMessage(QString theMessage="")
If no parameter is passed, the message will be a generic 'define the CRS for this layer'...
void on_mEditButton_clicked()
Opens a dialog to edit an existing connection.
void setMessageAsPlainText(const QString &msg)
void populateFormats()
Populate supported formats.
QgsDataSourceURI mUri
URI for selected connection.
virtual QStringList selectedLayersTimes()
List of times (temporalDomain timePosition/timePeriod for currently selected layer item(s) ...
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.
void addWMSListRow(const QDomElement &item, int row)
virtual void on_mLayersTreeWidget_itemSelectionChanged()
Signaled when a layer selection is changed.
void on_mDeleteButton_clicked()
Deletes the selected connection.
QgsOWSSourceSelect(QString service, QWidget *parent=0, Qt::WindowFlags fl=QgisGui::ModalDialogFlags, bool managerMode=false, bool embeddedMode=false)
Constructor.
virtual void addClicked()
Determines the layers the user selected.
QString descriptionForAuthId(QString authId)
Returns a textual description for the authority id.
QString connName()
Connection name.
QString readEntry(const QString &scope, const QString &key, const QString &def=QString::null, bool *ok=0) const
void addWMSListItem(const QDomElement &el, int row, int column)
QString mConnectionInfo
Connection info for selected connection.
void setOgcWmsCrsFilter(QSet< QString > crsFilter)
filters this dialog by the given CRSs
QTreeWidgetItem that can sort numerically (as opposed to just lexigraphically)
static QgsProject * instance()
access to canonical QgsProject instance
Definition: qgsproject.cpp:362
Class for storing 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 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 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.
QTableWidgetItem * mCurrentTileset
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)
void setConnectionListPosition()
Set the server connection combo box to that stored in the config file.
void populateTimes()
Populate times.
const CORE_EXPORT QString GEO_EPSG_CRS_AUTHID
Geographic coord sys from EPSG authority.
Definition: qgis.cpp:71
QString mConnName
Name for selected connection.
#define tr(sourceText)
void clearCRS()
Clear CRSs.