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