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 );
94 if ( currentCRS != -1 )
106 mTabWidget->removeTab( mTabWidget->indexOf( mLayerOrderTab ) );
107 mTabWidget->removeTab( mTabWidget->indexOf( mTilesetsTab ) );
109 mFormatWidget->hide();
112 mCacheWidget->hide();
120 restoreGeometry( settings.value(
"/Windows/WMSSourceSelect/geometry" ).toByteArray() );
127 settings.setValue(
"/Windows/WMSSourceSelect/geometry", saveGeometry() );
132 mFormatComboBox->clear();
133 mFormatComboBox->setEnabled(
false );
166 QMap<QString, QString> formatsMap;
167 formatsMap.insert(
"geotiff",
"tiff" );
168 formatsMap.insert(
"gtiff",
"tiff" );
169 formatsMap.insert(
"tiff",
"tiff" );
170 formatsMap.insert(
"tif",
"tiff" );
171 formatsMap.insert(
"gif",
"gif" );
172 formatsMap.insert(
"jpeg",
"jpeg" );
173 formatsMap.insert(
"jpg",
"jpeg" );
174 formatsMap.insert(
"png",
"png" );
178 for (
int i = 0; i < layersFormats.size(); i++ )
180 QString format = layersFormats.value( i );
182 QString simpleFormat = format.toLower().replace(
"image/",
"" ).replace( QRegExp(
"_.*" ),
"" );
183 QgsDebugMsg(
"server simpleFormat = " + simpleFormat );
184 QString mimeFormat =
"image/" + formatsMap.value( simpleFormat );
185 QgsDebugMsg(
"server mimeFormat = " + mimeFormat );
187 QString label = format;
197 if ( simpleFormat.contains(
"tif" ) )
199 if ( preferred < 0 || simpleFormat.startsWith(
"g" ) )
209 QgsDebugMsg( QString(
"format %1 unknown" ).arg( format ) );
212 mFormatComboBox->insertItem( i, label );
216 preferred = preferred >= 0 ? preferred : 0;
217 mFormatComboBox->setCurrentIndex( preferred );
219 mFormatComboBox->setEnabled(
true );
225 mTimeComboBox->clear();
232 mTimeComboBox->clear();
233 mTimeComboBox->setEnabled(
false );
238 mConnectionsComboBox->clear();
271 QString msg =
tr(
"Are you sure you want to remove the %1 connection and all associated settings?" )
272 .arg( mConnectionsComboBox->currentText() );
273 QMessageBox::StandardButton result = QMessageBox::information(
this,
tr(
"Confirm Delete" ), msg, QMessageBox::Ok | QMessageBox::Cancel );
274 if ( result == QMessageBox::Ok )
277 mConnectionsComboBox->removeItem( mConnectionsComboBox->currentIndex() );
291 QString fileName = QFileDialog::getOpenFileName(
this,
tr(
"Load connections" ),
".",
292 tr(
"XML files (*.xml *XML)" ) );
293 if ( fileName.isEmpty() )
306 const QStringList &names,
307 QMap<int, QgsNumericSortTreeWidgetItem *> &items,
308 int &layerAndStyleCount,
309 const QMap<int, int> &layerParents,
310 const QMap<int, QStringList> &layerParentNames )
312 QgsDebugMsg( QString(
"id = %1 layerAndStyleCount = %2 names = %3 " ).arg(
id ).arg( layerAndStyleCount ).arg( names.join(
"," ) ) );
313 if ( items.contains(
id ) )
318 if ( layerParents.contains(
id ) )
321 int parent = layerParents[ id ];
327 item->setText( 0, QString::number( ++layerAndStyleCount ) );
328 item->setText( 1, names[0].simplified() );
329 item->setText( 2, names[1].simplified() );
330 item->setText( 3, names[2].simplified() );
331 item->setToolTip( 3,
"<font color=black>" + names[2].simplified() +
"</font>" );
346 mLayersTreeWidget->clear();
351 mConnName = mConnectionsComboBox->currentText();
358 QApplication::setOverrideCursor( Qt::WaitCursor );
363 QApplication::restoreOverrideCursor();
378 foreach ( QTreeWidgetItem *item, mLayersTreeWidget->selectedItems() )
380 QString layer = item->data( 0, Qt::UserRole + 0 ).toString();
381 if ( !layer.isEmpty() )
396 if ( !mySelector->exec() )
404 for (
int i = 0; i < mLayersTreeWidget->topLevelItemCount(); i++ )
421 mCRSLabel->setText(
tr(
"Coordinate Reference System (%n available)",
"crs count",
mSelectedLayersCRSs.count() ) +
":" );
433 if ( it->compare(
mSelectedCRS, Qt::CaseInsensitive ) == 0 )
451 mChangeCRSButton->setEnabled(
true );
458 mCRSLabel->setText(
tr(
"Coordinate Reference System" ) +
":" );
460 mSelectedCRSLabel->setText(
"" );
461 mChangeCRSButton->setEnabled(
false );
468 QTableWidgetItem *rowItem = mTilesetsTableWidget->item( mTilesetsTableWidget->currentRow(), 0 );
471 mTilesetsTableWidget->blockSignals(
true );
472 mTilesetsTableWidget->clearSelection();
475 QgsDebugMsg( QString(
"selecting current row %1" ).arg( mTilesetsTableWidget->currentRow() ) );
476 mTilesetsTableWidget->selectRow( mTilesetsTableWidget->currentRow() );
483 mTilesetsTableWidget->blockSignals(
false );
507 int cache = mCacheComboBox->itemData( mCacheComboBox->currentIndex() ).toInt();
508 return static_cast<QNetworkRequest::CacheLoadControl
>( cache );
518 return mTimeComboBox->currentText();
525 mConnectionsComboBox->setCurrentIndex( mConnectionsComboBox->findText( toSelect ) );
527 if ( mConnectionsComboBox->currentIndex() < 0 )
529 if ( toSelect.isNull() )
530 mConnectionsComboBox->setCurrentIndex( 0 );
532 mConnectionsComboBox->setCurrentIndex( mConnectionsComboBox->count() - 1 );
535 if ( mConnectionsComboBox->count() == 0 )
538 mConnectButton->setEnabled(
false );
539 mEditButton->setEnabled(
false );
540 mDeleteButton->setEnabled(
false );
541 mSaveButton->setEnabled(
false );
546 mConnectButton->setEnabled(
true );
547 mEditButton->setEnabled(
true );
548 mDeleteButton->setEnabled(
true );
549 mSaveButton->setEnabled(
true );
557 mStatusLabel->setText( theMessage );
567 mv->setWindowTitle( theTitle );
569 if ( theFormat ==
"text/html" )
604 QMap<QString, QString> exampleServers;
605 exampleServers[
"DM Solutions GMap"] =
"http://www2.dmsolutions.ca/cgi-bin/mswms_gmap";
606 exampleServers[
"Lizardtech server"] =
"http://wms.lizardtech.com/lizardtech/iserv/ows";
611 settings.beginGroup(
"/Qgis/connections-" +
mService.toLower() );
612 QMap<QString, QString>::const_iterator i = exampleServers.constBegin();
613 for ( ; i != exampleServers.constEnd(); ++i )
616 QStringList keys = settings.childGroups();
617 if ( !keys.contains( i.key() ) )
619 QString path = i.key();
620 settings.setValue( path +
"/url", i.value() );
626 QMessageBox::information(
this,
tr(
"WMS proxies" ),
"<p>" +
tr(
"Several WMS servers have "
627 "been added to the server list. Note that if "
628 "you access the internet via a web proxy, you will "
629 "need to set the proxy settings in the QGIS options dialog." ) +
"</p>" );
634 QDomElement title = item.firstChildElement(
"title" );
636 QDomElement description = item.firstChildElement(
"description" );
638 QDomElement link = item.firstChildElement(
"link" );
646 QTableWidgetItem* tableItem =
new QTableWidgetItem( el.text() );
648 tableItem->setToolTip( el.text() );
649 mSearchTableWidget->setItem( row, column, tableItem );
656 mSearchTableWidget->clearContents();
657 mSearchTableWidget->setRowCount( 0 );
660 mSearchAddButton->setEnabled(
false );
662 QApplication::setOverrideCursor( Qt::WaitCursor );
666 QString mySearchUrl = settings.value(
"/qgis/WMSSearchUrl",
"http://geopole.org/wms/search?search=%1&type=rss" ).toString();
667 QUrl url( mySearchUrl.arg( mSearchTermLineEdit->text() ) );
676 QApplication::restoreOverrideCursor();
678 QNetworkReply *r = qobject_cast<QNetworkReply *>( sender() );
682 if ( r->error() == QNetworkReply::NoError )
685 QDomDocument doc(
"RSS" );
686 QByteArray res = r->readAll();
689 if ( doc.setContent( res, &error, &line, &column ) )
691 QDomNodeList list = doc.elementsByTagName(
"item" );
692 mSearchTableWidget->setRowCount( list.size() );
693 for (
int i = 0; i < list.size(); i++ )
695 if ( list.item( i ).isElement() )
697 QDomElement item = list.item( i ).toElement();
702 mSearchTableWidget->resizeColumnsToContents();
707 showStatusMessage(
tr(
"parse error at row %1, column %2: %3" ).arg( line ).arg( column ).arg( error ) );
720 mSearchAddButton->setEnabled( mSearchTableWidget->currentRow() != -1 );
725 QList<QTreeWidgetItem *> selectionList = mLayerOrderTreeWidget->selectedItems();
726 if ( selectionList.size() < 1 )
730 int selectedIndex = mLayerOrderTreeWidget->indexOfTopLevelItem( selectionList[0] );
731 if ( selectedIndex < 1 )
736 QTreeWidgetItem* selectedItem = mLayerOrderTreeWidget->takeTopLevelItem( selectedIndex );
737 mLayerOrderTreeWidget->insertTopLevelItem( selectedIndex - 1, selectedItem );
738 mLayerOrderTreeWidget->clearSelection();
739 selectedItem->setSelected(
true );
744 QList<QTreeWidgetItem *> selectionList = mLayerOrderTreeWidget->selectedItems();
745 if ( selectionList.size() < 1 )
749 int selectedIndex = mLayerOrderTreeWidget->indexOfTopLevelItem( selectionList[0] );
750 if ( selectedIndex < 0 || selectedIndex > mLayerOrderTreeWidget->topLevelItemCount() - 2 )
755 QTreeWidgetItem* selectedItem = mLayerOrderTreeWidget->takeTopLevelItem( selectedIndex );
756 mLayerOrderTreeWidget->insertTopLevelItem( selectedIndex + 1, selectedItem );
757 mLayerOrderTreeWidget->clearSelection();
758 selectedItem->setSelected(
true );
763 return QList<SupportedFormat>();
768 return QStringList();
773 return QStringList();
778 return QStringList();
void on_mNewButton_clicked()
Opens the create connection dialog to build a new connection.
void on_mLayerUpButton_clicked()
QMap< QString, QString > mCrsNames
virtual void updateButtons()
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)
~QgsOWSSourceSelect()
Destructor.
A generic dialog to prompt the user for a Coordinate Reference System.
QString mSelectedCRS
Selected CRS.
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.
QList< SupportedFormat > mProviderFormats
Supported formats.
void on_mLayerDownButton_clicked()
void on_mSearchTableWidget_itemSelectionChanged()
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.
QSet< QString > mSelectedLayersCRSs
Common CRSs for selected layers.
void on_mConnectionsComboBox_activated(int)
Stores the selected datasource whenerver it is changed.
static void setSelectedConnection(const QString &theService, const QString &name)
void setMessageAsHtml(const QString &msg)
bool createFromOgcWmsCrs(QString theCrs)
Set up this CRS from the given OGC CRS.
void populateConnectionList()
Populate the connection list combo box.
virtual void showMessage(bool blocking=true)
display the message to the user
bool mEmbeddedMode
Embedded mode, without 'Close'.
static void deleteConnection(const QString &theService, const QString &name)
QString uri() const
return complete uri
virtual void enableLayersForCrs(QTreeWidgetItem *item)
void addDefaultServers()
Add a few example servers to the list.
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 on_mSearchButton_clicked()
void populateFormats()
Populate supported formats.
QgsDataSourceURI mUri
URI for selected connection.
virtual QStringList selectedLayersTimes()
List of times (temporalDomain timePosition/timePeriod for currently selected layer item(s) ...
void on_mLoadButton_clicked()
Loads connections from the file.
QgsNumericSortTreeWidgetItem * createItem(int id, const QStringList &names, QMap< int, QgsNumericSortTreeWidgetItem * > &items, int &layerAndStyleCount, const QMap< int, int > &layerParents, const QMap< int, QStringList > &layerParentNames)
create an item including possible parents
void on_mAddDefaultButton_clicked()
Add some default wms servers to the list.
void addWMSListRow(const QDomElement &item, int row)
virtual void on_mLayersTreeWidget_itemSelectionChanged()
Signaled when a layer selection is changed.
void on_mDeleteButton_clicked()
Deletes the selected connection.
QgsOWSSourceSelect(QString service, QWidget *parent=0, Qt::WindowFlags fl=QgisGui::ModalDialogFlags, bool managerMode=false, bool embeddedMode=false)
Constructor.
virtual void addClicked()
Determines the layers the user selected.
QString descriptionForAuthId(QString authId)
Returns a textual description for the authority id.
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)
void on_mTilesetsTableWidget_itemClicked(QTableWidgetItem *item)
QString mConnectionInfo
Connection info for selected connection.
static QgsNetworkAccessManager * instance()
returns a pointer to the single instance
void setOgcWmsCrsFilter(QSet< QString > crsFilter)
filters this dialog by the given CRSs
QMap< QString, QString > mMimeLabelMap
Map mime type labels to supported formats.
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.