40 #include <QButtonGroup> 41 #include <QFileDialog> 42 #include <QRadioButton> 43 #include <QDomDocument> 44 #include <QHeaderView> 45 #include <QImageReader> 46 #include <QInputDialog> 48 #include <QMessageBox> 54 #include <QNetworkRequest> 55 #include <QNetworkReply> 58 : QDialog( parent, fl )
60 , mManagerMode( managerMode )
61 , mEmbeddedMode( embeddedMode )
62 , mCurrentTileset( 0 )
68 mDialogButtonBox->button( QDialogButtonBox::Close )->hide();
71 setWindowTitle(
tr(
"Add Layer(s) from a %1 Server" ).arg( service ) );
73 mAddButton = mDialogButtonBox->button( QDialogButtonBox::Apply );
75 mAddButton->setToolTip(
tr(
"Add selected layers to map" ) );
80 mTileWidthLineEdit->setValidator(
new QIntValidator( 0, 9999,
this ) );
81 mTileHeightLineEdit->setValidator(
new QIntValidator( 0, 9999,
this ) );
82 mFeatureCountLineEdit->setValidator(
new QIntValidator( 0, 9999,
this ) );
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 );
90 mCacheComboBox->setCurrentIndex( mCacheComboBox->findData( QNetworkRequest::PreferNetwork ) );
97 if ( currentCRS != -1 )
103 mSelectedCRS = currentRefSys.
authid();
109 mTabWidget->removeTab( mTabWidget->indexOf( mLayerOrderTab ) );
110 mTabWidget->removeTab( mTabWidget->indexOf( mTilesetsTab ) );
112 mFormatWidget->hide();
115 mCacheWidget->hide();
123 restoreGeometry( settings.value(
"/Windows/WMSSourceSelect/geometry" ).toByteArray() );
130 settings.setValue(
"/Windows/WMSSourceSelect/geometry", saveGeometry() );
135 mFormatComboBox->clear();
136 mFormatComboBox->setEnabled(
false );
149 if ( mProviderFormats.size() == 0 )
152 for (
int i = 0; i < mProviderFormats.size(); i++ )
155 mMimeLabelMap.insert( mProviderFormats[i].format, mProviderFormats[i].label );
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" );
181 for (
int i = 0; i < layersFormats.size(); i++ )
183 QString format = layersFormats.value( i );
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 );
190 QString label = format;
192 if ( mMimeLabelMap.contains( mimeFormat ) )
194 if ( format != mMimeLabelMap.value( mimeFormat ) )
197 label +=
" / " + mMimeLabelMap.value( mimeFormat );
200 if ( simpleFormat.contains(
"tif" ) )
202 if ( preferred < 0 || simpleFormat.startsWith(
"g" ) )
212 QgsDebugMsg( QString(
"format %1 unknown" ).arg( format ) );
215 mFormatComboBox->insertItem( i, label );
219 preferred = preferred >= 0 ? preferred : 0;
220 mFormatComboBox->setCurrentIndex( preferred );
222 mFormatComboBox->setEnabled(
true );
228 mTimeComboBox->clear();
235 mTimeComboBox->clear();
236 mTimeComboBox->setEnabled(
false );
241 mConnectionsComboBox->clear();
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 )
280 mConnectionsComboBox->removeItem( mConnectionsComboBox->currentIndex() );
294 QString fileName = QFileDialog::getOpenFileName(
this,
tr(
"Load connections" ),
".",
295 tr(
"XML files (*.xml *XML)" ) );
296 if ( fileName.isEmpty() )
309 const QStringList &names,
310 QMap<int, QgsNumericSortTreeWidgetItem *> &items,
311 int &layerAndStyleCount,
312 const QMap<int, int> &layerParents,
313 const QMap<int, QStringList> &layerParentNames )
315 QgsDebugMsg( QString(
"id = %1 layerAndStyleCount = %2 names = %3 " ).arg(
id ).arg( layerAndStyleCount ).arg( names.join(
"," ) ) );
316 if ( items.contains(
id ) )
321 if ( layerParents.contains(
id ) )
324 int parent = layerParents[ id ];
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>" );
349 mLayersTreeWidget->clear();
354 mConnName = mConnectionsComboBox->currentText();
359 QApplication::setOverrideCursor( Qt::WaitCursor );
364 QApplication::restoreOverrideCursor();
379 foreach ( QTreeWidgetItem *item, mLayersTreeWidget->selectedItems() )
381 QString layer = item->data( 0, Qt::UserRole + 0 ).toString();
382 if ( !layer.isEmpty() )
397 if ( !mySelector->exec() )
405 for (
int i = 0; i < mLayersTreeWidget->topLevelItemCount(); i++ )
422 mCRSLabel->setText(
tr(
"Coordinate Reference System (%n available)",
"crs count", mSelectedLayersCRSs.count() ) +
":" );
424 mChangeCRSButton->setDisabled( mSelectedLayersCRSs.isEmpty() );
426 if ( !mSelectedLayersCRSs.isEmpty() )
431 QSet<QString>::const_iterator it = mSelectedLayersCRSs.begin();
432 for ( ; it != mSelectedLayersCRSs.end(); ++it )
434 if ( it->compare( mSelectedCRS, Qt::CaseInsensitive ) == 0 )
438 if ( it == mSelectedLayersCRSs.begin() )
446 if ( it == mSelectedLayersCRSs.end() )
449 mSelectedCRS = defaultCRS;
452 mChangeCRSButton->setEnabled(
true );
459 mCRSLabel->setText(
tr(
"Coordinate Reference System" ) +
":" );
461 mSelectedCRSLabel->setText(
"" );
462 mChangeCRSButton->setEnabled(
false );
465 void QgsOWSSourceSelect::on_mTilesetsTableWidget_itemClicked( QTableWidgetItem *item )
469 QTableWidgetItem *rowItem = mTilesetsTableWidget->item( mTilesetsTableWidget->currentRow(), 0 );
472 mTilesetsTableWidget->blockSignals(
true );
473 mTilesetsTableWidget->clearSelection();
476 QgsDebugMsg( QString(
"selecting current row %1" ).arg( mTilesetsTableWidget->currentRow() ) );
477 mTilesetsTableWidget->selectRow( mTilesetsTableWidget->currentRow() );
484 mTilesetsTableWidget->blockSignals(
false );
508 int cache = mCacheComboBox->itemData( mCacheComboBox->currentIndex() ).toInt();
509 return static_cast<QNetworkRequest::CacheLoadControl
>( cache );
519 return mTimeComboBox->currentText();
526 mConnectionsComboBox->setCurrentIndex( mConnectionsComboBox->findText( toSelect ) );
528 if ( mConnectionsComboBox->currentIndex() < 0 )
530 if ( toSelect.isNull() )
531 mConnectionsComboBox->setCurrentIndex( 0 );
533 mConnectionsComboBox->setCurrentIndex( mConnectionsComboBox->count() - 1 );
536 if ( mConnectionsComboBox->count() == 0 )
539 mConnectButton->setEnabled(
false );
540 mEditButton->setEnabled(
false );
541 mDeleteButton->setEnabled(
false );
542 mSaveButton->setEnabled(
false );
547 mConnectButton->setEnabled(
true );
548 mEditButton->setEnabled(
true );
549 mDeleteButton->setEnabled(
true );
550 mSaveButton->setEnabled(
true );
558 mStatusLabel->setText( theMessage );
568 mv->setWindowTitle( theTitle );
570 if ( theFormat ==
"text/html" )
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";
612 settings.beginGroup(
"/Qgis/connections-" +
mService.toLower() );
613 QMap<QString, QString>::const_iterator i = exampleServers.constBegin();
614 for ( ; i != exampleServers.constEnd(); ++i )
617 QStringList keys = settings.childGroups();
618 if ( !keys.contains( i.key() ) )
620 QString path = i.key();
621 settings.setValue( path +
"/url", i.value() );
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>" );
635 QDomElement title = item.firstChildElement(
"title" );
637 QDomElement description = item.firstChildElement(
"description" );
639 QDomElement link = item.firstChildElement(
"link" );
647 QTableWidgetItem* tableItem =
new QTableWidgetItem( el.text() );
649 tableItem->setToolTip( el.text() );
650 mSearchTableWidget->setItem( row, column, tableItem );
654 void QgsOWSSourceSelect::on_mSearchButton_clicked()
657 mSearchTableWidget->clearContents();
658 mSearchTableWidget->setRowCount( 0 );
661 mSearchAddButton->setEnabled(
false );
663 QApplication::setOverrideCursor( Qt::WaitCursor );
667 QString mySearchUrl = settings.value(
"/qgis/WMSSearchUrl",
"http://geopole.org/wms/search?search=%1&type=rss" ).toString();
668 QUrl url( mySearchUrl.arg( mSearchTermLineEdit->text() ) );
677 QApplication::restoreOverrideCursor();
679 QNetworkReply *r = qobject_cast<QNetworkReply *>( sender() );
683 if ( r->error() == QNetworkReply::NoError )
686 QDomDocument doc(
"RSS" );
687 QByteArray res = r->readAll();
690 if ( doc.setContent( res, &error, &line, &column ) )
692 QDomNodeList list = doc.elementsByTagName(
"item" );
693 mSearchTableWidget->setRowCount( list.size() );
694 for (
int i = 0; i < list.size(); i++ )
696 if ( list.item( i ).isElement() )
698 QDomElement item = list.item( i ).toElement();
703 mSearchTableWidget->resizeColumnsToContents();
708 showStatusMessage(
tr(
"parse error at row %1, column %2: %3" ).arg( line ).arg( column ).arg( error ) );
719 void QgsOWSSourceSelect::on_mSearchTableWidget_itemSelectionChanged()
721 mSearchAddButton->setEnabled( mSearchTableWidget->currentRow() != -1 );
724 void QgsOWSSourceSelect::on_mLayerUpButton_clicked()
726 QList<QTreeWidgetItem *> selectionList = mLayerOrderTreeWidget->selectedItems();
727 if ( selectionList.size() < 1 )
731 int selectedIndex = mLayerOrderTreeWidget->indexOfTopLevelItem( selectionList[0] );
732 if ( selectedIndex < 1 )
737 QTreeWidgetItem* selectedItem = mLayerOrderTreeWidget->takeTopLevelItem( selectedIndex );
738 mLayerOrderTreeWidget->insertTopLevelItem( selectedIndex - 1, selectedItem );
739 mLayerOrderTreeWidget->clearSelection();
740 selectedItem->setSelected(
true );
743 void QgsOWSSourceSelect::on_mLayerDownButton_clicked()
745 QList<QTreeWidgetItem *> selectionList = mLayerOrderTreeWidget->selectedItems();
746 if ( selectionList.size() < 1 )
750 int selectedIndex = mLayerOrderTreeWidget->indexOfTopLevelItem( selectionList[0] );
751 if ( selectedIndex < 0 || selectedIndex > mLayerOrderTreeWidget->topLevelItemCount() - 2 )
756 QTreeWidgetItem* selectedItem = mLayerOrderTreeWidget->takeTopLevelItem( selectedIndex );
757 mLayerOrderTreeWidget->insertTopLevelItem( selectedIndex + 1, selectedItem );
758 mLayerOrderTreeWidget->clearSelection();
759 selectedItem->setSelected(
true );
764 return QList<SupportedFormat>();
769 return QStringList();
774 return QStringList();
779 return QStringList();
782 void QgsOWSSourceSelect::updateButtons()
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)
static QgsNetworkAccessManager * instance()
~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.
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.
void on_mConnectButton_clicked()
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) ...
virtual void showMessage(bool blocking=true) override
display the message to the user
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.
void connectionsChanged()
QString connName()
Connection name.
QString readEntry(const QString &scope, const QString &key, const QString &def=QString::null, bool *ok=0) const
void setSelectedCrsId(long theID)
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
static QgsProject * instance()
access to canonical QgsProject instance
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.
QString description() const
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.
QString mConnName
Name for selected connection.
void clearCRS()
Clear CRSs.