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 mAddButton = mDialogButtonBox->button( QDialogButtonBox::Apply );
73 mAddButton->setToolTip(
tr(
"Add selected layers to map" ) );
78 mTileWidthLineEdit->setValidator(
new QIntValidator( 0, 9999,
this ) );
79 mTileHeightLineEdit->setValidator(
new QIntValidator( 0, 9999,
this ) );
80 mFeatureCountLineEdit->setValidator(
new QIntValidator( 0, 9999,
this ) );
82 mCacheComboBox->addItem(
tr(
"Always cache" ), QNetworkRequest::AlwaysCache );
83 mCacheComboBox->addItem(
tr(
"Prefer cache" ), QNetworkRequest::PreferCache );
84 mCacheComboBox->addItem(
tr(
"Prefer network" ), QNetworkRequest::PreferNetwork );
85 mCacheComboBox->addItem(
tr(
"Always network" ), QNetworkRequest::AlwaysNetwork );
92 if ( currentCRS != -1 )
104 mTabWidget->removeTab( mTabWidget->indexOf( mLayerOrderTab ) );
105 mTabWidget->removeTab( mTabWidget->indexOf( mTilesetsTab ) );
107 mFormatWidget->hide();
110 mCacheWidget->hide();
118 restoreGeometry( settings.value(
"/Windows/WMSSourceSelect/geometry" ).toByteArray() );
125 settings.setValue(
"/Windows/WMSSourceSelect/geometry", saveGeometry() );
130 mFormatComboBox->clear();
131 mFormatComboBox->setEnabled(
false );
164 QMap<QString, QString> formatsMap;
165 formatsMap.insert(
"geotiff",
"tiff" );
166 formatsMap.insert(
"gtiff",
"tiff" );
167 formatsMap.insert(
"tiff",
"tiff" );
168 formatsMap.insert(
"tif",
"tiff" );
169 formatsMap.insert(
"gif",
"gif" );
170 formatsMap.insert(
"jpeg",
"jpeg" );
171 formatsMap.insert(
"jpg",
"jpeg" );
172 formatsMap.insert(
"png",
"png" );
176 for (
int i = 0; i < layersFormats.size(); i++ )
178 QString format = layersFormats.value( i );
180 QString simpleFormat = format.toLower().replace(
"image/",
"" ).replace( QRegExp(
"_.*" ),
"" );
181 QgsDebugMsg(
"server simpleFormat = " + simpleFormat );
182 QString mimeFormat =
"image/" + formatsMap.value( simpleFormat );
183 QgsDebugMsg(
"server mimeFormat = " + mimeFormat );
185 QString label = format;
195 if ( simpleFormat.contains(
"tif" ) )
197 if ( preferred < 0 || simpleFormat.startsWith(
"g" ) )
207 QgsDebugMsg( QString(
"format %1 unknown" ).arg( format ) );
210 mFormatComboBox->insertItem( i, label );
214 preferred = preferred >= 0 ? preferred : 0;
215 mFormatComboBox->setCurrentIndex( preferred );
217 mFormatComboBox->setEnabled(
true );
223 mTimeComboBox->clear();
230 mTimeComboBox->clear();
231 mTimeComboBox->setEnabled(
false );
236 mConnectionsComboBox->clear();
241 if ( mConnectionsComboBox->count() == 0 )
244 mConnectButton->setEnabled(
false );
245 mEditButton->setEnabled(
false );
246 mDeleteButton->setEnabled(
false );
251 mConnectButton->setEnabled(
true );
252 mEditButton->setEnabled(
true );
253 mDeleteButton->setEnabled(
true );
284 QString msg =
tr(
"Are you sure you want to remove the %1 connection and all associated settings?" )
285 .arg( mConnectionsComboBox->currentText() );
286 QMessageBox::StandardButton result = QMessageBox::information(
this,
tr(
"Confirm Delete" ), msg, QMessageBox::Ok | QMessageBox::Cancel );
287 if ( result == QMessageBox::Ok )
290 mConnectionsComboBox->removeItem( mConnectionsComboBox->currentIndex() );
304 QString fileName = QFileDialog::getOpenFileName(
this,
tr(
"Load connections" ),
".",
305 tr(
"XML files (*.xml *XML)" ) );
306 if ( fileName.isEmpty() )
319 const QStringList &names,
320 QMap<int, QgsNumericSortTreeWidgetItem *> &items,
321 int &layerAndStyleCount,
322 const QMap<int, int> &layerParents,
323 const QMap<int, QStringList> &layerParentNames )
325 QgsDebugMsg( QString(
"id = %1 layerAndStyleCount = %2 names = %3 " ).arg(
id ).arg( layerAndStyleCount ).arg( names.join(
"," ) ) );
326 if ( items.contains(
id ) )
331 if ( layerParents.contains(
id ) )
334 int parent = layerParents[ id ];
340 item->setText( 0, QString::number( ++layerAndStyleCount ) );
341 item->setText( 1, names[0].simplified() );
342 item->setText( 2, names[1].simplified() );
343 item->setText( 3, names[2].simplified() );
344 item->setToolTip( 3,
"<font color=black>" + names[2].simplified() +
"</font>" );
359 mLayersTreeWidget->clear();
364 mConnName = mConnectionsComboBox->currentText();
371 QApplication::setOverrideCursor( Qt::WaitCursor );
376 QApplication::restoreOverrideCursor();
391 foreach ( QTreeWidgetItem *item, mLayersTreeWidget->selectedItems() )
393 QString layer = item->data( 0, Qt::UserRole + 0 ).toString();
394 if ( !layer.isEmpty() )
409 if ( !mySelector->exec() )
417 for (
int i = 0; i < mLayersTreeWidget->topLevelItemCount(); i++ )
434 mCRSLabel->setText(
tr(
"Coordinate Reference System (%n available)",
"crs count",
mSelectedLayersCRSs.count() ) +
":" );
446 if ( it->compare(
mSelectedCRS, Qt::CaseInsensitive ) == 0 )
464 mChangeCRSButton->setEnabled(
true );
471 mCRSLabel->setText(
tr(
"Coordinate Reference System" ) +
":" );
473 mSelectedCRSLabel->setText(
"" );
474 mChangeCRSButton->setEnabled(
false );
481 QTableWidgetItem *rowItem = mTilesetsTableWidget->item( mTilesetsTableWidget->currentRow(), 0 );
484 mTilesetsTableWidget->blockSignals(
true );
485 mTilesetsTableWidget->clearSelection();
488 QgsDebugMsg( QString(
"selecting current row %1" ).arg( mTilesetsTableWidget->currentRow() ) );
489 mTilesetsTableWidget->selectRow( mTilesetsTableWidget->currentRow() );
496 mTilesetsTableWidget->blockSignals(
false );
520 int cache = mCacheComboBox->itemData( mCacheComboBox->currentIndex() ).toInt();
521 return static_cast<QNetworkRequest::CacheLoadControl
>( cache );
531 return mTimeComboBox->currentText();
538 mConnectionsComboBox->setCurrentIndex( mConnectionsComboBox->findText( toSelect ) );
540 if ( mConnectionsComboBox->currentIndex() < 0 )
542 if ( toSelect.isNull() )
543 mConnectionsComboBox->setCurrentIndex( 0 );
545 mConnectionsComboBox->setCurrentIndex( mConnectionsComboBox->count() - 1 );
552 mStatusLabel->setText( theMessage );
562 mv->setWindowTitle( theTitle );
564 if ( theFormat ==
"text/html" )
599 QMap<QString, QString> exampleServers;
600 exampleServers[
"DM Solutions GMap"] =
"http://www2.dmsolutions.ca/cgi-bin/mswms_gmap";
601 exampleServers[
"Lizardtech server"] =
"http://wms.lizardtech.com/lizardtech/iserv/ows";
606 settings.beginGroup(
"/Qgis/connections-" +
mService.toLower() );
607 QMap<QString, QString>::const_iterator i = exampleServers.constBegin();
608 for ( ; i != exampleServers.constEnd(); ++i )
611 QStringList keys = settings.childGroups();
612 if ( !keys.contains( i.key() ) )
614 QString path = i.key();
615 settings.setValue( path +
"/url", i.value() );
621 QMessageBox::information(
this,
tr(
"WMS proxies" ),
"<p>" +
tr(
"Several WMS servers have "
622 "been added to the server list. Note that if "
623 "you access the internet via a web proxy, you will "
624 "need to set the proxy settings in the QGIS options dialog." ) +
"</p>" );
629 QDomElement title = item.firstChildElement(
"title" );
631 QDomElement description = item.firstChildElement(
"description" );
633 QDomElement link = item.firstChildElement(
"link" );
641 QTableWidgetItem* tableItem =
new QTableWidgetItem( el.text() );
643 tableItem->setToolTip( el.text() );
644 mSearchTableWidget->setItem( row, column, tableItem );
651 mSearchTableWidget->clearContents();
652 mSearchTableWidget->setRowCount( 0 );
655 mSearchAddButton->setEnabled(
false );
657 QApplication::setOverrideCursor( Qt::WaitCursor );
661 QString mySearchUrl = settings.value(
"/qgis/WMSSearchUrl",
"http://geopole.org/wms/search?search=%1&type=rss" ).toString();
662 QUrl url( mySearchUrl.arg( mSearchTermLineEdit->text() ) );
671 QApplication::restoreOverrideCursor();
673 QNetworkReply *r = qobject_cast<QNetworkReply *>( sender() );
677 if ( r->error() == QNetworkReply::NoError )
680 QDomDocument doc(
"RSS" );
681 QByteArray res = r->readAll();
684 if ( doc.setContent( res, &error, &line, &column ) )
686 QDomNodeList list = doc.elementsByTagName(
"item" );
687 mSearchTableWidget->setRowCount( list.size() );
688 for (
int i = 0; i < list.size(); i++ )
690 if ( list.item( i ).isElement() )
692 QDomElement item = list.item( i ).toElement();
697 mSearchTableWidget->resizeColumnsToContents();
702 showStatusMessage(
tr(
"parse error at row %1, column %2: %3" ).arg( line ).arg( column ).arg( error ) );
715 mSearchAddButton->setEnabled( mSearchTableWidget->currentRow() != -1 );
720 QList<QTreeWidgetItem *> selectionList = mLayerOrderTreeWidget->selectedItems();
721 if ( selectionList.size() < 1 )
725 int selectedIndex = mLayerOrderTreeWidget->indexOfTopLevelItem( selectionList[0] );
726 if ( selectedIndex < 1 )
731 QTreeWidgetItem* selectedItem = mLayerOrderTreeWidget->takeTopLevelItem( selectedIndex );
732 mLayerOrderTreeWidget->insertTopLevelItem( selectedIndex - 1, selectedItem );
733 mLayerOrderTreeWidget->clearSelection();
734 selectedItem->setSelected(
true );
739 QList<QTreeWidgetItem *> selectionList = mLayerOrderTreeWidget->selectedItems();
740 if ( selectionList.size() < 1 )
744 int selectedIndex = mLayerOrderTreeWidget->indexOfTopLevelItem( selectionList[0] );
745 if ( selectedIndex < 0 || selectedIndex > mLayerOrderTreeWidget->topLevelItemCount() - 2 )
750 QTreeWidgetItem* selectedItem = mLayerOrderTreeWidget->takeTopLevelItem( selectedIndex );
751 mLayerOrderTreeWidget->insertTopLevelItem( selectedIndex + 1, selectedItem );
752 mLayerOrderTreeWidget->clearSelection();
753 selectedItem->setSelected(
true );
758 return QList<SupportedFormat>();
763 return QStringList();
768 return QStringList();
773 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.
QgsOWSSourceSelect(QString service, QWidget *parent=0, Qt::WFlags fl=QgisGui::ModalDialogFlags, bool managerMode=false, bool embeddedMode=false)
Constructor.
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.
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.