QGIS API Documentation 3.99.0-Master (2fe06baccd8)
Loading...
Searching...
No Matches
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 "qgsowssourceselect.h"
22
23#include "qgis.h"
25#include "qgsdataprovider.h"
26#include "qgsdatasourceuri.h"
27#include "qgsgui.h"
28#include "qgslogger.h"
30#include "qgsmessageviewer.h"
32#include "qgsowsconnection.h"
33#include "qgsproject.h"
35#include "qgsproviderregistry.h"
36#include "qgssettings.h"
37#include "qgstreewidgetitem.h"
38
39#include <QButtonGroup>
40#include <QDomDocument>
41#include <QFileDialog>
42#include <QHeaderView>
43#include <QImageReader>
44#include <QInputDialog>
45#include <QMap>
46#include <QMessageBox>
47#include <QNetworkReply>
48#include <QNetworkRequest>
49#include <QPicture>
50#include <QRadioButton>
51#include <QRegularExpression>
52#include <QUrl>
53#include <QValidator>
54
55#include "moc_qgsowssourceselect.cpp"
56
57QgsOWSSourceSelect::QgsOWSSourceSelect( const QString &service, QWidget *parent, Qt::WindowFlags fl, QgsProviderRegistry::WidgetMode theWidgetMode )
58 : QgsAbstractDataSourceWidget( parent, fl, theWidgetMode )
59 , mService( service )
60
61{
62 setupUi( this );
64 connect( mNewButton, &QPushButton::clicked, this, &QgsOWSSourceSelect::mNewButton_clicked );
65 connect( mEditButton, &QPushButton::clicked, this, &QgsOWSSourceSelect::mEditButton_clicked );
66 connect( mDeleteButton, &QPushButton::clicked, this, &QgsOWSSourceSelect::mDeleteButton_clicked );
67 connect( mSaveButton, &QPushButton::clicked, this, &QgsOWSSourceSelect::mSaveButton_clicked );
68 connect( mLoadButton, &QPushButton::clicked, this, &QgsOWSSourceSelect::mLoadButton_clicked );
69 connect( mConnectButton, &QPushButton::clicked, this, &QgsOWSSourceSelect::mConnectButton_clicked );
70 connect( mChangeCRSButton, &QPushButton::clicked, this, &QgsOWSSourceSelect::mChangeCRSButton_clicked );
71 connect( mLayersTreeWidget, &QTreeWidget::itemSelectionChanged, this, &QgsOWSSourceSelect::mLayersTreeWidget_itemSelectionChanged );
72 connect( mConnectionsComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::activated ), this, &QgsOWSSourceSelect::mConnectionsComboBox_activated );
73 connect( mAddDefaultButton, &QPushButton::clicked, this, &QgsOWSSourceSelect::mAddDefaultButton_clicked );
74 connect( mTilesetsTableWidget, &QTableWidget::itemClicked, this, &QgsOWSSourceSelect::mTilesetsTableWidget_itemClicked );
75 connect( mLayerUpButton, &QPushButton::clicked, this, &QgsOWSSourceSelect::mLayerUpButton_clicked );
76 connect( mLayerDownButton, &QPushButton::clicked, this, &QgsOWSSourceSelect::mLayerDownButton_clicked );
77 setupButtons( buttonBox );
78
79
80 setWindowTitle( tr( "Add Layer(s) from a %1 Server" ).arg( service ) );
81
82 clearCrs();
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
93 {
94 //set the current project CRS if available
95 const QgsCoordinateReferenceSystem currentRefSys = QgsProject::instance()->crs();
96 //convert CRS id to epsg
97 if ( currentRefSys.isValid() )
98 {
99 mSelectedCRS = currentRefSys.authid();
100 }
101 }
102 else
103 {
104 mTabWidget->removeTab( mTabWidget->indexOf( mLayerOrderTab ) );
105 mTabWidget->removeTab( mTabWidget->indexOf( mTilesetsTab ) );
106 mTimeWidget->hide();
107 mFormatWidget->hide();
108 mCRSWidget->hide();
109 mCacheWidget->hide();
110 }
112
113 // set up the WMS connections we already know about
115}
116
122
124{
125 QgsCoordinateReferenceSystem crs = QgsCoordinateReferenceSystem( QStringLiteral( "EPSG:4326" ) );
126 mSpatialExtentBox->setOutputCrs( crs );
127 QgsMapCanvas *canvas = mapCanvas();
128 if ( !canvas )
129 return;
130 QgsCoordinateReferenceSystem destinationCrs = canvas->mapSettings().destinationCrs();
131 mSpatialExtentBox->setCurrentExtent( destinationCrs.bounds(), destinationCrs );
132 mSpatialExtentBox->setOutputExtentFromCurrent();
133 mSpatialExtentBox->setMapCanvas( canvas );
134}
135
140
142{
143 mLayersTreeWidget->clearSelection();
144}
145
147{
148 mFormatComboBox->clear();
149 mFormatComboBox->setEnabled( false );
150}
151
153{
154 // A server may offer more similar formats, which are mapped
155 // to the same GDAL format, e.g. GeoTIFF and TIFF
156 // -> recreate always buttons for all available formats, enable supported
157
158 clearFormats();
159
160 if ( mProviderFormats.isEmpty() )
161 {
162 mProviderFormats = providerFormats();
163 for ( int i = 0; i < mProviderFormats.size(); i++ )
164 {
165 // GDAL mime types may be image/tiff, image/png, ...
166 mMimeLabelMap.insert( mProviderFormats[i].format, mProviderFormats[i].label );
167 }
168 }
169
170 // selectedLayersFormats may come in various forms:
171 // image/tiff, GTiff, GeoTIFF, TIFF, geotiff_int16, geotiff_rgb,
172 // PNG, GTOPO30, ARCGRID, IMAGEMOSAIC
173 // and even any string defined in server configuration, for example the
174 // value used in UMN Mapserver for OUTPUTFORMAT->NAME is used in
175 // WCS 1.0.0 SupportedFormats/Format
176
177 // TODO: It is impossible to cover all possible formats coming from server
178 // -> enabled all formats, GDAL may be able to open them
179
180 QMap<QString, QString> formatsMap;
181 formatsMap.insert( QStringLiteral( "geotiff" ), QStringLiteral( "tiff" ) );
182 formatsMap.insert( QStringLiteral( "gtiff" ), QStringLiteral( "tiff" ) );
183 formatsMap.insert( QStringLiteral( "tiff" ), QStringLiteral( "tiff" ) );
184 formatsMap.insert( QStringLiteral( "tif" ), QStringLiteral( "tiff" ) );
185 formatsMap.insert( QStringLiteral( "gif" ), QStringLiteral( "gif" ) );
186 formatsMap.insert( QStringLiteral( "jpeg" ), QStringLiteral( "jpeg" ) );
187 formatsMap.insert( QStringLiteral( "jpg" ), QStringLiteral( "jpeg" ) );
188 formatsMap.insert( QStringLiteral( "png" ), QStringLiteral( "png" ) );
189
190 int preferred = -1;
191 const QStringList layersFormats = selectedLayersFormats();
192 for ( int i = 0; i < layersFormats.size(); i++ )
193 {
194 const QString format = layersFormats.value( i );
195 QgsDebugMsgLevel( "server format = " + format, 2 );
196 const QString simpleFormat = format.toLower().remove( QStringLiteral( "image/" ) ).remove( QRegularExpression( "_.*" ) );
197 QgsDebugMsgLevel( "server simpleFormat = " + simpleFormat, 2 );
198 const QString mimeFormat = "image/" + formatsMap.value( simpleFormat );
199 QgsDebugMsgLevel( "server mimeFormat = " + mimeFormat, 2 );
200
201 QString label = format;
202
203 if ( mMimeLabelMap.contains( mimeFormat ) )
204 {
205 if ( format != mMimeLabelMap.value( mimeFormat ) )
206 {
207 // Append name of GDAL driver
208 label += " / " + mMimeLabelMap.value( mimeFormat );
209 }
210
211 if ( simpleFormat.contains( QLatin1String( "tif" ) ) ) // prefer *tif*
212 {
213 if ( preferred < 0 || simpleFormat.startsWith( 'g' ) ) // prefer geotiff
214 {
215 preferred = i;
216 }
217 }
218 }
219 else
220 {
221 // We cannot always say that the format is not supported by GDAL because
222 // server can use strange names, but format itself is supported
223 QgsDebugMsgLevel( QStringLiteral( "format %1 unknown" ).arg( format ), 2 );
224 }
225
226 mFormatComboBox->insertItem( i, label );
227 }
228 // Set preferred
229 // TODO: all enabled for now, see above
230 preferred = preferred >= 0 ? preferred : 0;
231 mFormatComboBox->setCurrentIndex( preferred );
232
233 mFormatComboBox->setEnabled( true );
234}
235
237{
238 mTimeComboBox->clear();
239 mTimeComboBox->insertItems( 0, selectedLayersTimes() );
240 mTimeComboBox->setEnabled( !selectedLayersTimes().isEmpty() );
241}
242
244{
245 mTimeComboBox->clear();
246 mTimeComboBox->setEnabled( false );
247}
248
250{
251 mConnectionsComboBox->clear();
252 mConnectionsComboBox->addItems( QgsOwsConnection::connectionList( mService ) );
253
255}
256
258{
259 if ( string.compare( QLatin1String( "wms" ), Qt::CaseInsensitive ) == 0 )
261 else if ( string.compare( QLatin1String( "wfs" ), Qt::CaseInsensitive ) == 0 )
263 else if ( string.compare( QLatin1String( "wcs" ), Qt::CaseInsensitive ) == 0 )
265 else
267}
268
269void QgsOWSSourceSelect::mNewButton_clicked()
270{
272 QgsNewHttpConnection *nc = new QgsNewHttpConnection( this, type, mService.toUpper(), QString(), QgsNewHttpConnection::FlagShowHttpSettings );
273
274 if ( nc->exec() )
275 {
277 emit connectionsChanged();
278 }
279
280 delete nc;
281}
282
283void QgsOWSSourceSelect::mEditButton_clicked()
284{
286 QgsNewHttpConnection *nc = new QgsNewHttpConnection( this, type, mService.toUpper(), mConnectionsComboBox->currentText(), QgsNewHttpConnection::FlagShowHttpSettings );
287
288 if ( nc->exec() )
289 {
291 emit connectionsChanged();
292 }
293
294 delete nc;
295}
296
297void QgsOWSSourceSelect::mDeleteButton_clicked()
298{
299 const QString msg = tr( "Are you sure you want to remove the %1 connection and all associated settings?" )
300 .arg( mConnectionsComboBox->currentText() );
301 const QMessageBox::StandardButton result = QMessageBox::question( this, tr( "Remove Connection" ), msg, QMessageBox::Yes | QMessageBox::No );
302 if ( result == QMessageBox::Yes )
303 {
304 QgsOwsConnection::deleteConnection( mService, mConnectionsComboBox->currentText() );
305 mConnectionsComboBox->removeItem( mConnectionsComboBox->currentIndex() ); // populateConnectionList();
307 emit connectionsChanged();
308 }
309}
310
311void QgsOWSSourceSelect::mSaveButton_clicked()
312{
313 QgsManageConnectionsDialog dlg( this, QgsManageConnectionsDialog::Export, QgsManageConnectionsDialog::WCS );
314 dlg.exec();
315}
316
317void QgsOWSSourceSelect::mLoadButton_clicked()
318{
319 const QString fileName = QFileDialog::getOpenFileName( this, tr( "Load Connections" ), QDir::homePath(), tr( "XML files (*.xml *.XML)" ) );
320 if ( fileName.isEmpty() )
321 {
322 return;
323 }
324
325 QgsManageConnectionsDialog dlg( this, QgsManageConnectionsDialog::Import, QgsManageConnectionsDialog::WCS, fileName );
326 dlg.exec();
328 emit connectionsChanged();
329}
330
332 int id,
333 const QStringList &names,
334 QMap<int, QgsTreeWidgetItem *> &items,
335 int &layerAndStyleCount,
336 const QMap<int, int> &layerParents,
337 const QMap<int, QStringList> &layerParentNames
338)
339{
340 QgsDebugMsgLevel( QStringLiteral( "id = %1 layerAndStyleCount = %2 names = %3 " ).arg( id ).arg( layerAndStyleCount ).arg( names.join( "," ) ), 2 );
341 if ( items.contains( id ) )
342 return items[id];
343
344
345 QgsTreeWidgetItem *item = nullptr;
346 if ( layerParents.contains( id ) )
347 {
348 // it has parent -> create first its parent
349 const int parent = layerParents[id];
350 item = new QgsTreeWidgetItem( createItem( parent, layerParentNames[parent], items, layerAndStyleCount, layerParents, layerParentNames ) );
351 }
352 else
353 item = new QgsTreeWidgetItem( mLayersTreeWidget );
354
355 item->setText( 0, QString::number( ++layerAndStyleCount ) );
356 item->setText( 1, names[0].simplified() );
357 item->setText( 2, names[1].simplified() );
358 item->setText( 3, names[2].simplified() );
359 item->setToolTip( 3, "<font color=black>" + names[2].simplified() + "</font>" );
360
361 items[id] = item;
362
363 return item;
364}
365
369
370void QgsOWSSourceSelect::mConnectButton_clicked()
371{
372 mLayersTreeWidget->clear();
373 clearFormats();
374 clearTimes();
375 clearCrs();
376
377 mConnName = mConnectionsComboBox->currentText();
378
379 const QgsOwsConnection connection( mService, mConnectionsComboBox->currentText() );
380 mUri = connection.uri();
381
382 QApplication::setOverrideCursor( Qt::WaitCursor );
383
384 QgsDebugMsgLevel( QStringLiteral( "call populateLayerList" ), 3 );
386
387 QApplication::restoreOverrideCursor();
388}
389
391{
392}
393
394void QgsOWSSourceSelect::mChangeCRSButton_clicked()
395{
396 QStringList layers;
397 const auto constSelectedItems = mLayersTreeWidget->selectedItems();
398 for ( QTreeWidgetItem *item : constSelectedItems )
399 {
400 const QString layer = item->data( 0, Qt::UserRole + 0 ).toString();
401 if ( !layer.isEmpty() )
402 layers << layer;
403 }
404
405 QgsProjectionSelectionDialog *mySelector = new QgsProjectionSelectionDialog( this );
406 mySelector->setOgcWmsCrsFilter( mSelectedLayersCRSs );
407
408 const QgsCoordinateReferenceSystem defaultCRS = QgsProject::instance()->crs();
409 if ( defaultCRS.isValid() )
410 {
411 mySelector->setCrs( defaultCRS );
412 }
413 else
414 {
415 mySelector->showNoCrsForLayerMessage();
416 }
417
418 if ( !mySelector->exec() )
419 return;
420
421 mSelectedCRS = mySelector->crs().authid();
422 mSpatialExtentBox->setOutputCrs( mySelector->crs() );
423 delete mySelector;
424
425 mSelectedCRSLabel->setText( descriptionForAuthId( mSelectedCRS ) );
426
427 for ( int i = 0; i < mLayersTreeWidget->topLevelItemCount(); i++ )
428 {
429 enableLayersForCrs( mLayersTreeWidget->topLevelItem( i ) );
430 }
431
432 updateButtons();
433}
434
435void QgsOWSSourceSelect::mLayersTreeWidget_itemSelectionChanged()
436{
437}
438
440{
441 clearCrs();
442 mSelectedLayersCRSs = qgis::listToSet( selectedLayersCrses() );
443 mCRSLabel->setText( tr( "Coordinate Reference System (%n available)", "crs count", mSelectedLayersCRSs.count() ) + ':' );
444
445 mChangeCRSButton->setDisabled( mSelectedLayersCRSs.isEmpty() );
446
447 if ( !mSelectedLayersCRSs.isEmpty() )
448 {
449 // check whether current CRS is supported
450 // if not, use one of the available CRS
451 QString defaultCRS;
452 QSet<QString>::const_iterator it = mSelectedLayersCRSs.constBegin();
453 for ( ; it != mSelectedLayersCRSs.constEnd(); ++it )
454 {
455 if ( it->compare( mSelectedCRS, Qt::CaseInsensitive ) == 0 )
456 break;
457
458 // save first CRS in case the current CRS is not available
459 if ( it == mSelectedLayersCRSs.constBegin() )
460 defaultCRS = *it;
461
462 // prefer value of DEFAULT_GEO_EPSG_CRS_ID if available
463 if ( *it == Qgis::geographicCrsAuthId() )
464 defaultCRS = *it;
465 }
466
467 if ( it == mSelectedLayersCRSs.constEnd() )
468 {
469 if ( mSelectedLayersCRSs.constFind( QgsProject::instance()->crs().authid() ) != mSelectedLayersCRSs.constEnd() )
470 {
471 mSelectedCRS = QgsProject::instance()->crs().authid();
472 }
473 else
474 {
475 // not found
476 mSelectedCRS = defaultCRS;
477 }
478 }
479 mSpatialExtentBox->setOutputCrs( QgsCoordinateReferenceSystem( mSelectedCRS ) );
480 mSelectedCRSLabel->setText( descriptionForAuthId( mSelectedCRS ) );
481 mChangeCRSButton->setEnabled( true );
482 }
483 QgsDebugMsgLevel( "mSelectedCRS = " + mSelectedCRS, 2 );
484}
485
487{
488 mCRSLabel->setText( tr( "Coordinate Reference System" ) + ':' );
489 mSelectedCRS.clear();
490 mSelectedCRSLabel->clear();
491 mChangeCRSButton->setEnabled( false );
492}
493
494void QgsOWSSourceSelect::mTilesetsTableWidget_itemClicked( QTableWidgetItem *item )
495{
496 Q_UNUSED( item )
497
498 QTableWidgetItem *rowItem = mTilesetsTableWidget->item( mTilesetsTableWidget->currentRow(), 0 );
499 const bool wasSelected = mCurrentTileset == rowItem;
500
501 mTilesetsTableWidget->blockSignals( true );
502 mTilesetsTableWidget->clearSelection();
503 if ( !wasSelected )
504 {
505 QgsDebugMsgLevel( QStringLiteral( "selecting current row %1" ).arg( mTilesetsTableWidget->currentRow() ), 2 );
506 mTilesetsTableWidget->selectRow( mTilesetsTableWidget->currentRow() );
507 mCurrentTileset = rowItem;
508 }
509 else
510 {
511 mCurrentTileset = nullptr;
512 }
513 mTilesetsTableWidget->blockSignals( false );
514
515 updateButtons();
516}
517
518
520{
521 return mConnName;
522}
523
528
530{
531 return selectedLayersFormats().value( mFormatComboBox->currentIndex() );
532}
533
534QNetworkRequest::CacheLoadControl QgsOWSSourceSelect::selectedCacheLoadControl()
535{
536 const int cache = mCacheComboBox->currentData().toInt();
537 return static_cast<QNetworkRequest::CacheLoadControl>( cache );
538}
539
541{
542 return mSelectedCRS;
543}
544
546{
547 return mTimeComboBox->currentText();
548}
549
551{
552 const QString toSelect = QgsOwsConnection::selectedConnection( mService );
553
554 mConnectionsComboBox->setCurrentIndex( mConnectionsComboBox->findText( toSelect ) );
555
556 if ( mConnectionsComboBox->currentIndex() < 0 )
557 {
558 if ( toSelect.isNull() )
559 mConnectionsComboBox->setCurrentIndex( 0 );
560 else
561 mConnectionsComboBox->setCurrentIndex( mConnectionsComboBox->count() - 1 );
562 }
563
564 if ( mConnectionsComboBox->count() == 0 )
565 {
566 // No connections - disable various buttons
567 mConnectButton->setEnabled( false );
568 mEditButton->setEnabled( false );
569 mDeleteButton->setEnabled( false );
570 mSaveButton->setEnabled( false );
571 }
572 else
573 {
574 // Connections - enable various buttons
575 mConnectButton->setEnabled( true );
576 mEditButton->setEnabled( true );
577 mDeleteButton->setEnabled( true );
578 mSaveButton->setEnabled( true );
579 }
580
581 QgsOwsConnection::setSelectedConnection( mService, mConnectionsComboBox->currentText() );
582}
583
584void QgsOWSSourceSelect::showStatusMessage( QString const &message )
585{
586 mStatusLabel->setText( message );
587
588 // update the display of this widget
589 update();
590}
591
592
593void QgsOWSSourceSelect::showError( QString const &title, QString const &format, QString const &error )
594{
595 QgsMessageViewer *mv = new QgsMessageViewer( this );
596 mv->setWindowTitle( title );
597
598 if ( format == QLatin1String( "text/html" ) )
599 {
600 mv->setMessageAsHtml( error );
601 }
602 else
603 {
604 mv->setMessageAsPlainText( tr( "Could not understand the response:\n%1" ).arg( error ) );
605 }
606 mv->showMessage( true ); // Is deleted when closed
607}
608
609void QgsOWSSourceSelect::mConnectionsComboBox_activated( int )
610{
611 // Remember which server was selected.
612 QgsOwsConnection::setSelectedConnection( mService, mConnectionsComboBox->currentText() );
613}
614
615void QgsOWSSourceSelect::mAddDefaultButton_clicked()
616{
618}
619
620QString QgsOWSSourceSelect::descriptionForAuthId( const QString &authId )
621{
622 if ( mCrsNames.contains( authId ) )
623 return mCrsNames[authId];
624
626 mCrsNames.insert( authId, qgisSrs.userFriendlyIdentifier() );
627 return qgisSrs.userFriendlyIdentifier();
628}
629
631{
632 QMap<QString, QString> exampleServers;
633 exampleServers[QStringLiteral( "DM Solutions GMap" )] = QStringLiteral( "http://www2.dmsolutions.ca/cgi-bin/mswms_gmap" );
634 exampleServers[QStringLiteral( "Lizardtech server" )] = QStringLiteral( "http://wms.lizardtech.com/lizardtech/iserv/ows" );
635 // Nice to have the qgis users map, but I'm not sure of the URL at the moment.
636 // exampleServers["Qgis users map"] = "http://qgis.org/wms.cgi";
637
638 QgsSettings settings;
639 settings.beginGroup( "/qgis/connections-" + mService.toLower() );
640 QMap<QString, QString>::const_iterator i = exampleServers.constBegin();
641 for ( ; i != exampleServers.constEnd(); ++i )
642 {
643 // Only do a server if it's name doesn't already exist.
644 const QStringList keys = settings.childGroups();
645 if ( !keys.contains( i.key() ) )
646 {
647 const QString path = i.key();
648 settings.setValue( path + "/url", i.value() );
649 }
650 }
651 settings.endGroup();
653
654 QMessageBox::information( this, tr( "Add WMS Servers" ), "<p>" + tr( "Several WMS servers have "
655 "been added to the server list. Note that if "
656 "you access the Internet via a web proxy, you will "
657 "need to set the proxy settings in the QGIS options dialog." )
658 + "</p>" );
659}
660
661void QgsOWSSourceSelect::mLayerUpButton_clicked()
662{
663 QList<QTreeWidgetItem *> selectionList = mLayerOrderTreeWidget->selectedItems();
664 if ( selectionList.empty() )
665 {
666 return;
667 }
668 const int selectedIndex = mLayerOrderTreeWidget->indexOfTopLevelItem( selectionList[0] );
669 if ( selectedIndex < 1 )
670 {
671 return; //item not existing or already on top
672 }
673
674 QTreeWidgetItem *selectedItem = mLayerOrderTreeWidget->takeTopLevelItem( selectedIndex );
675 mLayerOrderTreeWidget->insertTopLevelItem( selectedIndex - 1, selectedItem );
676 mLayerOrderTreeWidget->clearSelection();
677 selectedItem->setSelected( true );
678}
679
680void QgsOWSSourceSelect::mLayerDownButton_clicked()
681{
682 QList<QTreeWidgetItem *> selectionList = mLayerOrderTreeWidget->selectedItems();
683 if ( selectionList.empty() )
684 {
685 return;
686 }
687 const int selectedIndex = mLayerOrderTreeWidget->indexOfTopLevelItem( selectionList[0] );
688 if ( selectedIndex < 0 || selectedIndex > mLayerOrderTreeWidget->topLevelItemCount() - 2 )
689 {
690 return; //item not existing or already at bottom
691 }
692
693 QTreeWidgetItem *selectedItem = mLayerOrderTreeWidget->takeTopLevelItem( selectedIndex );
694 mLayerOrderTreeWidget->insertTopLevelItem( selectedIndex + 1, selectedItem );
695 mLayerOrderTreeWidget->clearSelection();
696 selectedItem->setSelected( true );
697}
698
699QList<QgsOWSSourceSelect::SupportedFormat> QgsOWSSourceSelect::providerFormats()
700{
701 return QList<SupportedFormat>();
702}
703
705{
706 return QStringList();
707}
708
710{
711 return QStringList();
712}
713
715{
716 return QStringList();
717}
718
719void QgsOWSSourceSelect::updateButtons()
720{
721}
static QString geographicCrsAuthId()
Geographic coordinate system auth:id string for a default geographic CRS (EPSG:4326).
Definition qgis.h:6333
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.
QgsAbstractDataSourceWidget(QWidget *parent=nullptr, Qt::WindowFlags fl=QgsGuiUtils::ModalDialogFlags, QgsProviderRegistry::WidgetMode widgetMode=QgsProviderRegistry::WidgetMode::Standalone)
Constructor.
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.
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(Qgis::CrsIdentifierType type=Qgis::CrsIdentifierType::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:221
Map canvas is a class for displaying all GIS data types on a canvas.
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)
@ FlagShowHttpSettings
Display the 'http' group.
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.
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.
QgsOWSSourceSelect(const QString &service, QWidget *parent=nullptr, Qt::WindowFlags fl=QgsGuiUtils::ModalDialogFlags, QgsProviderRegistry::WidgetMode widgetMode=QgsProviderRegistry::WidgetMode::Standalone)
Constructor.
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 for OWS connections.
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.
QgsCoordinateReferenceSystem crs
Definition qgsproject.h:115
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.
@ Manager
Used by data items for QgsDataItem::paramWidget().
Stores settings for use within QGIS.
Definition qgssettings.h:65
QStringList childGroups(Qgis::SettingsOrigin origin=Qgis::SettingsOrigin::Any) 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.
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.
#define QgsDebugMsgLevel(str, level)
Definition qgslogger.h:61
QgsNewHttpConnection::ConnectionType connectionTypeFromServiceString(const QString &string)