38#include <QButtonGroup> 
   40#include <QRadioButton> 
   41#include <QDomDocument> 
   43#include <QImageReader> 
   44#include <QInputDialog> 
   50#include <QNetworkRequest> 
   51#include <QNetworkReply> 
   52#include <QRegularExpression> 
   61  connect( mNewButton, &QPushButton::clicked, 
this, &QgsOWSSourceSelect::mNewButton_clicked );
 
   62  connect( mEditButton, &QPushButton::clicked, 
this, &QgsOWSSourceSelect::mEditButton_clicked );
 
   63  connect( mDeleteButton, &QPushButton::clicked, 
this, &QgsOWSSourceSelect::mDeleteButton_clicked );
 
   64  connect( mSaveButton, &QPushButton::clicked, 
this, &QgsOWSSourceSelect::mSaveButton_clicked );
 
   65  connect( mLoadButton, &QPushButton::clicked, 
this, &QgsOWSSourceSelect::mLoadButton_clicked );
 
   66  connect( mConnectButton, &QPushButton::clicked, 
this, &QgsOWSSourceSelect::mConnectButton_clicked );
 
   67  connect( mChangeCRSButton, &QPushButton::clicked, 
this, &QgsOWSSourceSelect::mChangeCRSButton_clicked );
 
   68  connect( mLayersTreeWidget, &QTreeWidget::itemSelectionChanged, 
this, &QgsOWSSourceSelect::mLayersTreeWidget_itemSelectionChanged );
 
   69  connect( mConnectionsComboBox, 
static_cast<void ( QComboBox::* )( 
int )
>( &QComboBox::activated ), 
this, &QgsOWSSourceSelect::mConnectionsComboBox_activated );
 
   70  connect( mAddDefaultButton, &QPushButton::clicked, 
this, &QgsOWSSourceSelect::mAddDefaultButton_clicked );
 
   71  connect( mTilesetsTableWidget, &QTableWidget::itemClicked, 
this, &QgsOWSSourceSelect::mTilesetsTableWidget_itemClicked );
 
   72  connect( mLayerUpButton, &QPushButton::clicked, 
this, &QgsOWSSourceSelect::mLayerUpButton_clicked );
 
   73  connect( mLayerDownButton, &QPushButton::clicked, 
this, &QgsOWSSourceSelect::mLayerDownButton_clicked );
 
   77  setWindowTitle( tr( 
"Add Layer(s) from a %1 Server" ).arg( service ) );
 
   81  mCacheComboBox->addItem( tr( 
"Always Cache" ), QNetworkRequest::AlwaysCache );
 
   82  mCacheComboBox->addItem( tr( 
"Prefer Cache" ), QNetworkRequest::PreferCache );
 
   83  mCacheComboBox->addItem( tr( 
"Prefer Network" ), QNetworkRequest::PreferNetwork );
 
   84  mCacheComboBox->addItem( tr( 
"Always Network" ), QNetworkRequest::AlwaysNetwork );
 
   87  mCacheComboBox->setCurrentIndex( mCacheComboBox->findData( QNetworkRequest::PreferNetwork ) );
 
   96      mSelectedCRS = currentRefSys.
authid();
 
  101    mTabWidget->removeTab( mTabWidget->indexOf( mLayerOrderTab ) );
 
  102    mTabWidget->removeTab( mTabWidget->indexOf( mTilesetsTab ) );
 
  104    mFormatWidget->hide();
 
  106    mCacheWidget->hide();
 
 
  123  mSpatialExtentBox->setOutputCrs( 
crs );
 
  128  mSpatialExtentBox->setCurrentExtent( destinationCrs.
bounds(), destinationCrs );
 
  129  mSpatialExtentBox->setOutputExtentFromCurrent();
 
  130  mSpatialExtentBox->setMapCanvas( canvas );
 
 
  140  mLayersTreeWidget->clearSelection();
 
 
  145  mFormatComboBox->clear();
 
  146  mFormatComboBox->setEnabled( 
false );
 
 
  158  if ( mProviderFormats.isEmpty() )
 
  161    for ( 
int i = 0; i < mProviderFormats.size(); i++ )
 
  164      mMimeLabelMap.insert( mProviderFormats[i].format, mProviderFormats[i].label );
 
  178  QMap<QString, QString> formatsMap;
 
  179  formatsMap.insert( QStringLiteral( 
"geotiff" ), QStringLiteral( 
"tiff" ) );
 
  180  formatsMap.insert( QStringLiteral( 
"gtiff" ), QStringLiteral( 
"tiff" ) );
 
  181  formatsMap.insert( QStringLiteral( 
"tiff" ), QStringLiteral( 
"tiff" ) );
 
  182  formatsMap.insert( QStringLiteral( 
"tif" ), QStringLiteral( 
"tiff" ) );
 
  183  formatsMap.insert( QStringLiteral( 
"gif" ), QStringLiteral( 
"gif" ) );
 
  184  formatsMap.insert( QStringLiteral( 
"jpeg" ), QStringLiteral( 
"jpeg" ) );
 
  185  formatsMap.insert( QStringLiteral( 
"jpg" ), QStringLiteral( 
"jpeg" ) );
 
  186  formatsMap.insert( QStringLiteral( 
"png" ), QStringLiteral( 
"png" ) );
 
  190  for ( 
int i = 0; i < layersFormats.size(); i++ )
 
  192    const QString format = layersFormats.value( i );
 
  194    const QString simpleFormat = format.toLower().remove( QStringLiteral( 
"image/" ) ).remove( QRegularExpression( 
"_.*" ) );
 
  196    const QString mimeFormat = 
"image/" + formatsMap.value( simpleFormat );
 
  199    QString label = format;
 
  201    if ( mMimeLabelMap.contains( mimeFormat ) )
 
  203      if ( format != mMimeLabelMap.value( mimeFormat ) )
 
  206        label += 
" / " + mMimeLabelMap.value( mimeFormat );
 
  209      if ( simpleFormat.contains( QLatin1String( 
"tif" ) ) ) 
 
  211        if ( preferred < 0 || simpleFormat.startsWith( 
'g' ) ) 
 
  224    mFormatComboBox->insertItem( i, label );
 
  228  preferred = preferred >= 0 ? preferred : 0;
 
  229  mFormatComboBox->setCurrentIndex( preferred );
 
  231  mFormatComboBox->setEnabled( 
true );
 
 
  236  mTimeComboBox->clear();
 
 
  243  mTimeComboBox->clear();
 
  244  mTimeComboBox->setEnabled( 
false );
 
 
  249  mConnectionsComboBox->clear();
 
 
  257  if ( 
string.compare( QLatin1String( 
"wms" ), Qt::CaseInsensitive ) == 0 )
 
  259  else if ( 
string.compare( QLatin1String( 
"wfs" ), Qt::CaseInsensitive ) == 0 )
 
  261  else if ( 
string.compare( QLatin1String( 
"wcs" ), Qt::CaseInsensitive ) == 0 )
 
 
  267void QgsOWSSourceSelect::mNewButton_clicked()
 
  281void QgsOWSSourceSelect::mEditButton_clicked()
 
  295void QgsOWSSourceSelect::mDeleteButton_clicked()
 
  297  const QString msg = tr( 
"Are you sure you want to remove the %1 connection and all associated settings?" )
 
  298                      .arg( mConnectionsComboBox->currentText() );
 
  299  const QMessageBox::StandardButton result = QMessageBox::question( 
this, tr( 
"Remove Connection" ), msg, QMessageBox::Yes | QMessageBox::No );
 
  300  if ( result == QMessageBox::Yes )
 
  303    mConnectionsComboBox->removeItem( mConnectionsComboBox->currentIndex() );  
 
  309void QgsOWSSourceSelect::mSaveButton_clicked()
 
  315void QgsOWSSourceSelect::mLoadButton_clicked()
 
  317  const QString fileName = QFileDialog::getOpenFileName( 
this, tr( 
"Load Connections" ), QDir::homePath(),
 
  318                           tr( 
"XML files (*.xml *.XML)" ) );
 
  319  if ( fileName.isEmpty() )
 
  332  const QStringList &names,
 
  333  QMap<int, QgsTreeWidgetItem *> &items,
 
  334  int &layerAndStyleCount,
 
  335  const QMap<int, int> &layerParents,
 
  336  const QMap<int, QStringList> &layerParentNames )
 
  338  QgsDebugMsgLevel( QStringLiteral( 
"id = %1 layerAndStyleCount = %2 names = %3 " ).arg( 
id ).arg( layerAndStyleCount ).arg( names.join( 
"," ) ), 2 );
 
  339  if ( items.contains( 
id ) )
 
  344  if ( layerParents.contains( 
id ) )
 
  347    const int parent = layerParents[ id ];
 
  348    item = 
new QgsTreeWidgetItem( 
createItem( parent, layerParentNames[ parent ], items, layerAndStyleCount, layerParents, layerParentNames ) );
 
  353  item->setText( 0, QString::number( ++layerAndStyleCount ) );
 
  354  item->setText( 1, names[0].simplified() );
 
  355  item->setText( 2, names[1].simplified() );
 
  356  item->setText( 3, names[2].simplified() );
 
  357  item->setToolTip( 3, 
"<font color=black>" + names[2].simplified()  + 
"</font>" );
 
 
  368void QgsOWSSourceSelect::mConnectButton_clicked()
 
  371  mLayersTreeWidget->clear();
 
  376  mConnName = mConnectionsComboBox->currentText();
 
  381  QApplication::setOverrideCursor( Qt::WaitCursor );
 
  386  QApplication::restoreOverrideCursor();
 
  393void QgsOWSSourceSelect::mChangeCRSButton_clicked()
 
  396  const auto constSelectedItems = mLayersTreeWidget->selectedItems();
 
  397  for ( QTreeWidgetItem *item : constSelectedItems )
 
  399    const QString layer = item->data( 0, Qt::UserRole + 0 ).toString();
 
  400    if ( !layer.isEmpty() )
 
  410    mySelector->
setCrs( defaultCRS );
 
  417  if ( !mySelector->exec() )
 
  420  mSelectedCRS = mySelector->
crs().
authid();
 
  421  mSpatialExtentBox->setOutputCrs( mySelector->
crs() );
 
  426  for ( 
int i = 0; i < mLayersTreeWidget->topLevelItemCount(); i++ )
 
  434void QgsOWSSourceSelect::mLayersTreeWidget_itemSelectionChanged()
 
  442  mCRSLabel->setText( tr( 
"Coordinate Reference System (%n available)", 
"crs count", mSelectedLayersCRSs.count() ) + 
':' );
 
  444  mChangeCRSButton->setDisabled( mSelectedLayersCRSs.isEmpty() );
 
  446  if ( !mSelectedLayersCRSs.isEmpty() )
 
  451    QSet<QString>::const_iterator it = mSelectedLayersCRSs.constBegin();
 
  452    for ( ; it != mSelectedLayersCRSs.constEnd(); ++it )
 
  454      if ( it->compare( mSelectedCRS, Qt::CaseInsensitive ) == 0 )
 
  458      if ( it == mSelectedLayersCRSs.constBegin() )
 
  466    if ( it == mSelectedLayersCRSs.constEnd() )
 
  475        mSelectedCRS = defaultCRS;
 
  480    mChangeCRSButton->setEnabled( 
true );
 
 
  487  mCRSLabel->setText( tr( 
"Coordinate Reference System" ) + 
':' );
 
  488  mSelectedCRS.clear();
 
  489  mSelectedCRSLabel->clear();
 
  490  mChangeCRSButton->setEnabled( 
false );
 
 
  493void QgsOWSSourceSelect::mTilesetsTableWidget_itemClicked( QTableWidgetItem *item )
 
  497  QTableWidgetItem *rowItem = mTilesetsTableWidget->item( mTilesetsTableWidget->currentRow(), 0 );
 
  500  mTilesetsTableWidget->blockSignals( 
true );
 
  501  mTilesetsTableWidget->clearSelection();
 
  504    QgsDebugMsgLevel( QStringLiteral( 
"selecting current row %1" ).arg( mTilesetsTableWidget->currentRow() ), 2 );
 
  505    mTilesetsTableWidget->selectRow( mTilesetsTableWidget->currentRow() );
 
  512  mTilesetsTableWidget->blockSignals( 
false );
 
  536  const int cache = mCacheComboBox->currentData().toInt();
 
  537  return static_cast<QNetworkRequest::CacheLoadControl
>( cache );
 
 
  547  return mTimeComboBox->currentText();
 
 
  554  mConnectionsComboBox->setCurrentIndex( mConnectionsComboBox->findText( toSelect ) );
 
  556  if ( mConnectionsComboBox->currentIndex() < 0 )
 
  558    if ( toSelect.isNull() )
 
  559      mConnectionsComboBox->setCurrentIndex( 0 );
 
  561      mConnectionsComboBox->setCurrentIndex( mConnectionsComboBox->count() - 1 );
 
  564  if ( mConnectionsComboBox->count() == 0 )
 
  567    mConnectButton->setEnabled( 
false );
 
  568    mEditButton->setEnabled( 
false );
 
  569    mDeleteButton->setEnabled( 
false );
 
  570    mSaveButton->setEnabled( 
false );
 
  575    mConnectButton->setEnabled( 
true );
 
  576    mEditButton->setEnabled( 
true );
 
  577    mDeleteButton->setEnabled( 
true );
 
  578    mSaveButton->setEnabled( 
true );
 
 
  586  mStatusLabel->setText( message );
 
 
  596  mv->setWindowTitle( title );
 
  598  if ( format == QLatin1String( 
"text/html" ) )
 
 
  609void QgsOWSSourceSelect::mConnectionsComboBox_activated( 
int )
 
  615void QgsOWSSourceSelect::mAddDefaultButton_clicked()
 
  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" );
 
  640  QMap<QString, QString>::const_iterator i = exampleServers.constBegin();
 
  641  for ( ; i != exampleServers.constEnd(); ++i )
 
  645    if ( !keys.contains( i.key() ) )
 
  647      const QString path = i.key();
 
  648      settings.
setValue( path + 
"/url", i.value() );
 
  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." ) + 
"</p>" );
 
 
  660void QgsOWSSourceSelect::mLayerUpButton_clicked()
 
  662  QList<QTreeWidgetItem *> selectionList = mLayerOrderTreeWidget->selectedItems();
 
  663  if ( selectionList.empty() )
 
  667  const int selectedIndex = mLayerOrderTreeWidget->indexOfTopLevelItem( selectionList[0] );
 
  668  if ( selectedIndex < 1 )
 
  673  QTreeWidgetItem *selectedItem = mLayerOrderTreeWidget->takeTopLevelItem( selectedIndex );
 
  674  mLayerOrderTreeWidget->insertTopLevelItem( selectedIndex - 1, selectedItem );
 
  675  mLayerOrderTreeWidget->clearSelection();
 
  676  selectedItem->setSelected( 
true );
 
  679void QgsOWSSourceSelect::mLayerDownButton_clicked()
 
  681  QList<QTreeWidgetItem *> selectionList = mLayerOrderTreeWidget->selectedItems();
 
  682  if ( selectionList.empty() )
 
  686  const int selectedIndex = mLayerOrderTreeWidget->indexOfTopLevelItem( selectionList[0] );
 
  687  if ( selectedIndex < 0 || selectedIndex > mLayerOrderTreeWidget->topLevelItemCount() - 2 )
 
  692  QTreeWidgetItem *selectedItem = mLayerOrderTreeWidget->takeTopLevelItem( selectedIndex );
 
  693  mLayerOrderTreeWidget->insertTopLevelItem( selectedIndex + 1, selectedItem );
 
  694  mLayerOrderTreeWidget->clearSelection();
 
  695  selectedItem->setSelected( 
true );
 
  700  return QList<SupportedFormat>();
 
 
  705  return QStringList();
 
 
  710  return QStringList();
 
 
  715  return QStringList();
 
 
  718void QgsOWSSourceSelect::updateButtons()
 
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(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...
 
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)
 
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
 
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
 
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.
 
@ Manager
Used by data items for QgsDataItem::paramWidget().
 
This class is a composition of two QSettings instances:
 
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.
 
CONSTLATIN1STRING geoEpsgCrsAuthId()
Geographic coord sys from EPSG authority.
 
#define QgsDebugMsgLevel(str, level)
 
QgsNewHttpConnection::ConnectionType connectionTypeFromServiceString(const QString &string)
 
const QgsCoordinateReferenceSystem & crs