| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,181 @@ | ||
| /*************************************************************************** | ||
| qgsowsconnection.cpp - selector for WMS servers, etc. | ||
| ------------------- | ||
| begin : 3 April 2005 | ||
| copyright : | ||
| original : (C) 2005 by Brendan Morley email : morb at ozemail dot com dot au | ||
| wms search : (C) 2009 Mathias Walker <mwa at sourcepole.ch>, Sourcepole AG | ||
| wms-c support : (C) 2010 Juergen E. Fischer < jef at norbit dot de >, norBIT GmbH | ||
| generalized : (C) 2012 Radim Blazek, based on qgswmsconnection.cpp | ||
| ***************************************************************************/ | ||
|
|
||
| /*************************************************************************** | ||
| * * | ||
| * This program is free software; you can redistribute it and/or modify * | ||
| * it under the terms of the GNU General Public License as published by * | ||
| * the Free Software Foundation; either version 2 of the License, or * | ||
| * (at your option) any later version. * | ||
| * * | ||
| ***************************************************************************/ | ||
|
|
||
| //#include "../providers/wms/qgswmsprovider.h" | ||
| #include "qgis.h" // GEO_EPSG_CRS_ID | ||
| //#include "qgisapp.h" //for getThemeIcon | ||
| //#include "qgscontexthelp.h" | ||
| //#include "qgscoordinatereferencesystem.h" | ||
| #include "qgsdatasourceuri.h" | ||
| //#include "qgsgenericprojectionselector.h" | ||
| #include "qgslogger.h" | ||
| //#include "qgsmanageconnectionsdialog.h" | ||
| //#include "qgsmessageviewer.h" | ||
| //#include "qgsnewhttpconnection.h" | ||
| //#include "qgsnumericsortlistviewitem.h" | ||
| #include "qgsproject.h" | ||
| #include "qgsproviderregistry.h" | ||
| #include "qgsowsconnection.h" | ||
| //#include "qgsnetworkaccessmanager.h" | ||
|
|
||
| //#include <QButtonGroup> | ||
| //#include <QFileDialog> | ||
| //#include <QRadioButton> | ||
| //#include <QDomDocument> | ||
| //#include <QHeaderView> | ||
| //#include <QImageReader> | ||
| #include <QInputDialog> | ||
| //#include <QMap> | ||
| #include <QMessageBox> | ||
| #include <QPicture> | ||
| #include <QSettings> | ||
| #include <QUrl> | ||
|
|
||
| #include <QNetworkRequest> | ||
| #include <QNetworkReply> | ||
|
|
||
| QgsOWSConnection::QgsOWSConnection( const QString & theService, const QString & theConnName ) : | ||
| mConnName( theConnName ), | ||
| mService( theService ) | ||
| { | ||
| QgsDebugMsg( "theConnName = " + theConnName ); | ||
|
|
||
| QSettings settings; | ||
|
|
||
| // WMS (providers/wfs/qgswmsconnection.cpp): | ||
| //QString key = "/Qgis/connections-wms/" + mConnName; | ||
| //QString credentialsKey = "/Qgis/WMS/" + mConnName; | ||
|
|
||
| // WFS (providers/wfs/qgswfsconnection.cpp): | ||
| //QString key = "/Qgis/connections-wfs/" + mConnName + "/url"; | ||
|
|
||
| // WCS - there was no WCS before | ||
|
|
||
| QString key = "/Qgis/connections-" + mService.toLower() + "/" + mConnName; | ||
| QString credentialsKey = "/Qgis/" + mService + "/" + mConnName; | ||
|
|
||
| QStringList connStringParts; | ||
|
|
||
| mConnectionInfo = settings.value( key + "/url" ).toString(); | ||
| mUri.setParam( "url", settings.value( key + "/url" ).toString() ); | ||
|
|
||
| // Check for credentials and prepend to the connection info | ||
| QString username = settings.value( credentialsKey + "/username" ).toString(); | ||
| QString password = settings.value( credentialsKey + "/password" ).toString(); | ||
| if ( !username.isEmpty() ) | ||
| { | ||
| // check for a password, if none prompt to get it | ||
| if ( password.isEmpty() ) | ||
| { | ||
| //password = QInputDialog::getText( this, tr( "WMS Password for %1" ).arg( theConnName ), "Password", QLineEdit::Password ); | ||
| password = QInputDialog::getText( 0, tr( "WMS Password for %1" ).arg( mConnName ), "Password", QLineEdit::Password ); | ||
| } | ||
| mConnectionInfo = "username=" + username + ",password=" + password + ",url=" + mConnectionInfo; | ||
| mUri.setParam( "username", username ); | ||
| mUri.setParam( "password", password ); | ||
| } | ||
|
|
||
| bool ignoreGetMap = settings.value( key + "/ignoreGetMapURI", false ).toBool(); | ||
| bool ignoreGetFeatureInfo = settings.value( key + "/ignoreGetFeatureInfoURI", false ).toBool(); | ||
| bool ignoreAxisOrientation = settings.value( key + "/ignoreAxisOrientation", false ).toBool(); | ||
| bool invertAxisOrientation = settings.value( key + "/invertAxisOrientation", false ).toBool(); | ||
| if ( ignoreGetMap ) | ||
| { | ||
| mUri.setParam( "IgnoreGetMapUrl", "1" ); | ||
| } | ||
| if ( ignoreGetFeatureInfo ) | ||
| { | ||
| mUri.setParam( "IgnoreGetFeatureInfoUrl", "1" ); | ||
| } | ||
| if ( ignoreAxisOrientation ) | ||
| { | ||
| mUri.setParam( "IgnoreAxisOrientation", "1" ); | ||
| } | ||
| if ( invertAxisOrientation ) | ||
| { | ||
| mUri.setParam( "InvertAxisOrientation", "1" ); | ||
| } | ||
|
|
||
| QgsDebugMsg( QString( "Connection info: '%1'." ).arg( mConnectionInfo ) ); | ||
| } | ||
|
|
||
| QgsOWSConnection::~QgsOWSConnection() | ||
| { | ||
|
|
||
| } | ||
|
|
||
| QString QgsOWSConnection::connectionInfo( ) | ||
| { | ||
| return mConnectionInfo; | ||
| } | ||
|
|
||
| QgsDataSourceURI QgsOWSConnection::uri() | ||
| { | ||
| return mUri; | ||
| } | ||
| /* | ||
| QgsDataProvider * QgsOWSConnection::provider( ) | ||
| { | ||
| // TODO: remove completely from this class? | ||
| // load the server data provider plugin | ||
| QgsProviderRegistry * pReg = QgsProviderRegistry::instance(); | ||
| //QMap<QString,QString> keys; | ||
| QgsDataProvider *provider = | ||
| ( QgsDataProvider* ) pReg->provider( "wms", mUri.encodedUri() ); | ||
| return provider; | ||
| } | ||
| */ | ||
|
|
||
|
|
||
| QStringList QgsOWSConnection::connectionList( const QString & theService ) | ||
| { | ||
| QSettings settings; | ||
| //settings.beginGroup( "/Qgis/connections-wms" ); | ||
| settings.beginGroup( "/Qgis/connections-" + theService.toLower() ); | ||
| return settings.childGroups(); | ||
| } | ||
|
|
||
| QString QgsOWSConnection::selectedConnection( const QString & theService ) | ||
| { | ||
| QSettings settings; | ||
| //return settings.value( "/Qgis/connections-wms/selected" ).toString(); | ||
| return settings.value( "/Qgis/connections-" + theService.toLower() + "/selected" ).toString(); | ||
| } | ||
|
|
||
| void QgsOWSConnection::setSelectedConnection( const QString & theService, const QString & name ) | ||
| { | ||
| QSettings settings; | ||
| //settings.setValue( "/Qgis/connections-wms/selected", name ); | ||
| settings.setValue( "/Qgis/connections-" + theService.toLower() + "/selected", name ); | ||
| } | ||
|
|
||
| void QgsOWSConnection::deleteConnection( const QString & theService, const QString & name ) | ||
| { | ||
| QSettings settings; | ||
| //settings.remove( "/Qgis/connections-wms/" + name ); | ||
| //settings.remove( "/Qgis/WMS/" + name ); | ||
| settings.remove( "/Qgis/connections-" + theService.toLower() + "/" + name ); | ||
| settings.remove( "/Qgis/" + theService + "/" + name ); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| /*************************************************************************** | ||
| qgsowsconnection.h - OWS connection | ||
| ------------------- | ||
| begin : 3 April 2005 | ||
| original : (C) 2005 by Brendan Morley email : morb at ozemail dot com dot au | ||
| wms search : (C) 2009 Mathias Walker <mwa at sourcepole.ch>, Sourcepole AG | ||
| generalized : (C) 2012 Radim Blazek, based on qgswmsconnection.h | ||
| ***************************************************************************/ | ||
|
|
||
| /*************************************************************************** | ||
| * * | ||
| * This program is free software; you can redistribute it and/or modify * | ||
| * it under the terms of the GNU General Public License as published by * | ||
| * the Free Software Foundation; either version 2 of the License, or * | ||
| * (at your option) any later version. * | ||
| * * | ||
| ***************************************************************************/ | ||
|
|
||
| #ifndef QGSOWSCONNECTION_H | ||
| #define QGSOWSCONNECTION_H | ||
| #include "qgsdatasourceuri.h" | ||
| //#include "qgisgui.h" | ||
| //#include "qgscontexthelp.h" | ||
|
|
||
| #include <QStringList> | ||
| #include <QPushButton> | ||
|
|
||
| class QgisApp; | ||
| //class QgsDataProvider; | ||
| class QgsDataProvider; | ||
| /*class QButtonGroup;*/ | ||
| /*class QgsNumericSortTreeWidgetItem;*/ | ||
| class QDomDocument; | ||
| class QDomElement; | ||
|
|
||
| /*! | ||
| * \brief Connections management | ||
| */ | ||
| class QgsOWSConnection : public QObject | ||
| { | ||
| // Q_OBJECT | ||
|
|
||
| public: | ||
| /** | ||
| * Constructor | ||
| * @param theService service name: WMS,WFS,WCS | ||
| */ | ||
| QgsOWSConnection( const QString & theService, const QString & theConnName ); | ||
| //! Destructor | ||
| ~QgsOWSConnection(); | ||
|
|
||
| static QStringList connectionList( const QString & theService ); | ||
|
|
||
| static void deleteConnection( const QString & theService, const QString & name ); | ||
|
|
||
| static QString selectedConnection( const QString & theService ); | ||
| static void setSelectedConnection( const QString & theService, const QString & name ); | ||
|
|
||
|
|
||
| public: | ||
| //QgsDataProvider *provider(); | ||
| QString connectionInfo(); | ||
| QString mConnName; | ||
| QString mConnectionInfo; | ||
| QgsDataSourceURI uri(); | ||
| private: | ||
| QgsDataSourceURI mUri; | ||
| QString mService; | ||
| }; | ||
|
|
||
|
|
||
| #endif // QGSOWSCONNECTION_H |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,237 @@ | ||
| /*************************************************************************** | ||
| qgsowssourceselect.h - selector for WMS,WFS,WCS layers | ||
| ------------------- | ||
| begin : 3 April 2005 | ||
| original : (C) 2005 by Brendan Morley email : morb at ozemail dot com dot au | ||
| wms search : (C) 2009 Mathias Walker <mwa at sourcepole.ch>, Sourcepole AG | ||
| generalized : (C) 2012 Radim Blazek, based on qgsowsconnection.h | ||
| ***************************************************************************/ | ||
|
|
||
| /*************************************************************************** | ||
| * * | ||
| * This program is free software; you can redistribute it and/or modify * | ||
| * it under the terms of the GNU General Public License as published by * | ||
| * the Free Software Foundation; either version 2 of the License, or * | ||
| * (at your option) any later version. * | ||
| * * | ||
| ***************************************************************************/ | ||
|
|
||
| #ifndef QGSOWSSOURCESELECT_H | ||
| #define QGSOWSSOURCESELECT_H | ||
| #include "ui_qgsowssourceselectbase.h" | ||
| #include "qgsdatasourceuri.h" | ||
| #include "qgisgui.h" | ||
| #include "qgscontexthelp.h" | ||
|
|
||
| #include "qgsdataprovider.h" | ||
|
|
||
| #include <QStringList> | ||
| #include <QPushButton> | ||
|
|
||
| class QgisApp; | ||
| class QgsDataProvider; | ||
| class QButtonGroup; | ||
| class QgsNumericSortTreeWidgetItem; | ||
| class QDomDocument; | ||
| class QDomElement; | ||
|
|
||
| /** Formats supported by provider */ | ||
| struct QgsOWSSupportedFormat | ||
| { | ||
| QString format; | ||
| QString label; | ||
| }; | ||
|
|
||
| /*! | ||
| * \brief Dialog to create connections and add layers from WMS, WFS, WCS etc. | ||
| * | ||
| * This dialog allows the user to define and save connection information | ||
| * for WMS servers, etc. | ||
| * | ||
| * The user can then connect and add | ||
| * layers from the WMS server to the map canvas. | ||
| */ | ||
| class QgsOWSSourceSelect : public QDialog, public Ui::QgsOWSSourceSelectBase | ||
| { | ||
| Q_OBJECT | ||
|
|
||
| public: | ||
| //! Constructor | ||
| QgsOWSSourceSelect( QString service, QWidget *parent = 0, Qt::WFlags fl = QgisGui::ModalDialogFlags, bool managerMode = false, bool embeddedMode = false ); | ||
| //! Destructor | ||
| ~QgsOWSSourceSelect(); | ||
|
|
||
| public slots: | ||
|
|
||
| //! Opens the create connection dialog to build a new connection | ||
| void on_mNewButton_clicked(); | ||
| //! Opens a dialog to edit an existing connection | ||
| void on_mEditButton_clicked(); | ||
| //! Deletes the selected connection | ||
| void on_mDeleteButton_clicked(); | ||
| //! Saves connections to the file | ||
| void on_mSaveButton_clicked(); | ||
| //! Loads connections from the file | ||
| void on_mLoadButton_clicked(); | ||
|
|
||
| /*! Connects to the database using the stored connection parameters. | ||
| * Once connected, available layers are displayed. | ||
| */ | ||
| void on_mConnectButton_clicked(); | ||
|
|
||
| //! Determines the layers the user selected | ||
| virtual void addClicked(); | ||
|
|
||
| void searchFinished(); | ||
|
|
||
| //! Opens the Spatial Reference System dialog. | ||
| void on_mChangeCRSButton_clicked(); | ||
|
|
||
| //! Signaled when a layer selection is changed. | ||
| virtual void on_mLayersTreeWidget_itemSelectionChanged(); | ||
|
|
||
| //! Set status message to theMessage | ||
| void showStatusMessage( QString const &theMessage ); | ||
|
|
||
| //! show whatever error is exposed. | ||
| void showError( QString const &theTitle, QString const &theFormat, QString const &theError ); | ||
|
|
||
| //! Stores the selected datasource whenerver it is changed | ||
| void on_mConnectionsComboBox_activated( int ); | ||
|
|
||
| //! Add some default wms servers to the list | ||
| void on_mAddDefaultButton_clicked(); | ||
|
|
||
| void on_mDialogButtonBox_helpRequested() { QgsContextHelp::run( metaObject()->className() ); } | ||
|
|
||
| signals: | ||
| void addRasterLayer( QString const & rasterLayerPath, | ||
| QString const & baseName, | ||
| QString const & providerKey ); | ||
| void connectionsChanged(); | ||
|
|
||
| protected: | ||
| /** | ||
| * List of image formats (encodings) supported by provider | ||
| * @return list of format/label pairs | ||
| */ | ||
| virtual QList<QgsOWSSupportedFormat> providerFormats(); | ||
|
|
||
| //! List of formats supported for currently selected layer item(s) | ||
| virtual QStringList selectedLayersFormats(); | ||
|
|
||
| //! Server CRS supported for currently selected layer item(s) | ||
| virtual QStringList selectedLayersCRSs(); | ||
|
|
||
| //virtual QStringList layerCRS( int id ); | ||
|
|
||
| //! Populate the connection list combo box | ||
| void populateConnectionList(); | ||
|
|
||
| //! Populate supported formats | ||
| void populateFormats(); | ||
|
|
||
| //! Clear previously set formats | ||
| void clearFormats(); | ||
|
|
||
| //! Set supported CRSs | ||
| void populateCRS(); | ||
|
|
||
| //! Connection name | ||
| QString connName(); | ||
|
|
||
| //! Connection info (uri) | ||
| QString connectionInfo(); | ||
|
|
||
| //! Set the server connection combo box to that stored in the config file. | ||
| void setConnectionListPosition(); | ||
|
|
||
| //! Add a few example servers to the list. | ||
| void addDefaultServers(); | ||
|
|
||
| //! Service name | ||
| QString mService; | ||
|
|
||
| //! Connections manager mode | ||
| bool mManagerMode; | ||
|
|
||
| //! Embedded mode, without 'Close' | ||
| bool mEmbeddedMode; | ||
|
|
||
|
|
||
| /** | ||
| * \brief Populate the layer list. | ||
| * | ||
| * \retval false if the layers could not be retrieved or parsed | ||
| */ | ||
| virtual void populateLayerList( ); | ||
|
|
||
| //! create an item including possible parents | ||
| QgsNumericSortTreeWidgetItem *createItem( int id, | ||
| const QStringList &names, | ||
| QMap<int, QgsNumericSortTreeWidgetItem *> &items, | ||
| int &layerAndStyleCount, | ||
| const QMap<int, int> &layerParents, | ||
| const QMap<int, QStringList> &layerParentNames ); | ||
|
|
||
| //! Returns a textual description for the authority id | ||
| QString descriptionForAuthId( QString authId ); | ||
|
|
||
| //! layer name derived from latest layer selection (updated as long it's not edited manually) | ||
| QString mLastLayerName; | ||
|
|
||
| //! The widget that controls the image format radio buttons | ||
| QButtonGroup *mImageFormatGroup; | ||
|
|
||
| QPushButton *mAddButton; | ||
|
|
||
| QMap<QString, QString> mCrsNames; | ||
|
|
||
| void addWMSListRow( const QDomElement& item, int row ); | ||
| void addWMSListItem( const QDomElement& el, int row, int column ); | ||
|
|
||
| virtual void enableLayersForCrs( QTreeWidgetItem *item ); | ||
|
|
||
| //! Returns currently selected format | ||
| QString selectedFormat(); | ||
|
|
||
| //! Returns currently selected Crs | ||
| QString selectedCRS(); | ||
|
|
||
| QList<QTreeWidgetItem*> mCurrentSelection; | ||
| QTableWidgetItem* mCurrentTileset; | ||
|
|
||
| //! Name for selected connection | ||
| QString mConnName; | ||
|
|
||
| //! Cnnection info for selected connection | ||
| QString mConnectionInfo; | ||
|
|
||
| //! URI for selected connection | ||
| QgsDataSourceURI mUri; | ||
|
|
||
| private: | ||
| //! Selected CRS | ||
| QString mSelectedCRS; | ||
|
|
||
| //! Common CRSs for selected layers | ||
| QSet<QString> mSelectedLayersCRSs; | ||
|
|
||
| //! Supported formats | ||
| QList<QgsOWSSupportedFormat> mProviderFormats; | ||
|
|
||
| //! Map mime type labels to supported formats | ||
| QMap<QString, QString> mMimeLabelMap; | ||
|
|
||
| private slots: | ||
| void on_mSearchButton_clicked(); | ||
| void on_mAddWMSButton_clicked(); | ||
| void on_mSearchTableWidget_itemSelectionChanged(); | ||
| void on_mTilesetsTableWidget_itemClicked( QTableWidgetItem *item ); | ||
| void on_mLayerUpButton_clicked(); | ||
| void on_mLayerDownButton_clicked(); | ||
| virtual void updateButtons(); | ||
| }; | ||
|
|
||
| #endif // QGSOWSSOURCESELECT_H |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,362 @@ | ||
| /*************************************************************************** | ||
| qgswcscapabilities.h - WCS capabilities | ||
| ------------------- | ||
| begin : 17 Mar, 2005 | ||
| copyright : (C) 2005 by Brendan Morley | ||
| email : morb at ozemail dot com dot au | ||
| wcs : 4/2012 Radim Blazek, based on qgswmsprovider.h | ||
| ***************************************************************************/ | ||
|
|
||
| /*************************************************************************** | ||
| * * | ||
| * This program is free software; you can redistribute it and/or modify * | ||
| * it under the terms of the GNU General Public License as published by * | ||
| * the Free Software Foundation; either version 2 of the License, or * | ||
| * (at your option) any later version. * | ||
| * * | ||
| ***************************************************************************/ | ||
| #ifndef QGSWCSCAPABILITIES_H | ||
| #define QGSWCSCAPABILITIES_H | ||
|
|
||
| //#include "qgsrasterdataprovider.h" | ||
| #include "qgsdatasourceuri.h" | ||
| #include "qgsrectangle.h" | ||
|
|
||
| #include <QString> | ||
| #include <QStringList> | ||
| #include <QDomElement> | ||
| #include <QMap> | ||
| #include <QVector> | ||
| #include <QUrl> | ||
|
|
||
| class QgsCoordinateTransform; | ||
| class QNetworkAccessManager; | ||
| class QNetworkReply; | ||
| class QNetworkRequest; | ||
|
|
||
| /* | ||
| * The following structs reflect the WCS XML schema, | ||
| * as illustrated in ... the Web Coverage Service standard, version x.x xxxx-xx-xx. | ||
| */ | ||
|
|
||
| /** Get Property structure */ | ||
| struct QgsWcsGet | ||
| { | ||
| QString xlinkHref; | ||
| }; | ||
|
|
||
| /** HTTP Property structure */ | ||
| struct QgsWcsHTTP | ||
| { | ||
| QgsWcsGet get; | ||
| }; | ||
|
|
||
| /** DCP Type Property structure */ | ||
| struct QgsWcsDCP | ||
| { | ||
| QgsWcsHTTP http; | ||
| }; | ||
|
|
||
| /** Version parameter */ | ||
| struct QgsWcsVersion | ||
| { | ||
| QStringList allowedValues; | ||
| }; | ||
|
|
||
| /** Operation type structure */ | ||
| struct QgsWcsOperation | ||
| { | ||
| QgsWcsVersion version; | ||
| QgsWcsDCP dcp; | ||
| }; | ||
|
|
||
| /** OperationsMetadata */ | ||
| struct QgsWcsOperationsMetadata | ||
| { | ||
| QgsWcsOperation getCoverage; | ||
| }; | ||
|
|
||
| /** ServiceerviceIdentification structure */ | ||
| struct QgsWcsServiceIdentification | ||
| { | ||
| QString title; | ||
| QString abstract; | ||
| }; | ||
|
|
||
| /** CoverageSummary structure */ | ||
| struct QgsWcsCoverageSummary | ||
| { | ||
| int orderId; | ||
| QString identifier; | ||
| QString title; | ||
| QString abstract; | ||
| QStringList supportedCrs; | ||
| QStringList supportedFormat; | ||
| QgsRectangle wgs84BoundingBox; | ||
| QVector<QgsWcsCoverageSummary> coverageSummary; | ||
| bool described; // 1.0 | ||
| }; | ||
|
|
||
| /** Contents structure */ | ||
| /* | ||
| struct QgsWcsContents | ||
| { | ||
| QStringList supportedCrs; | ||
| QStringList supportedFormat; | ||
| QVector<QgsWcsCoverageSummary> coverageSummary; | ||
| }; | ||
| */ | ||
|
|
||
| /** Capability Property structure */ | ||
| struct QgsWcsCapabilitiesProperty | ||
| { | ||
| QString version; | ||
| QgsWcsServiceIdentification serviceIdentification; | ||
| QgsWcsOperationsMetadata operationsMetadata; | ||
| // QgsWcsContents contents; | ||
| // using QgsWcsCoverageSummary for contents for simplification | ||
| QgsWcsCoverageSummary contents; | ||
| }; | ||
|
|
||
| /** | ||
| \brief Data provider for OGC WCS layers. | ||
| */ | ||
| class QgsWcsCapabilities : public QObject | ||
| { | ||
| Q_OBJECT | ||
|
|
||
| public: | ||
| /** | ||
| * Constructor for the provider. | ||
| * | ||
| * \param uri HTTP URL of the Web Server. If needed a proxy will be used | ||
| * otherwise we contact the host directly. | ||
| * | ||
| */ | ||
| QgsWcsCapabilities( QgsDataSourceURI const & theUri ); | ||
| QgsWcsCapabilities( ); | ||
|
|
||
| //! Destructor | ||
| ~QgsWcsCapabilities(); | ||
|
|
||
| void setUri( QgsDataSourceURI const &theUri ); | ||
|
|
||
| QgsWcsCapabilitiesProperty capabilities(); | ||
|
|
||
| /** | ||
| * \brief Returns a list of the supported layers of the WCS server | ||
| * | ||
| * \param[out] layers The list of layers will be placed here. | ||
| * | ||
| * \retval false if the layers could not be retrieved or parsed - | ||
| * see lastError() for more info | ||
| */ | ||
| bool supportedCoverages( QVector<QgsWcsCoverageSummary> &coverageSummary ); | ||
|
|
||
|
|
||
| /** | ||
| * \brief Returns a map for the hierarchy of layers | ||
| */ | ||
| void coverageParents( QMap<int, int> &parents, QMap<int, QStringList> &parentNames ) const; | ||
|
|
||
| //! Get coverage summare for identifier | ||
| QgsWcsCoverageSummary * coverageSummary( QString const & theIdentifier, QgsWcsCoverageSummary* parent = 0 ); | ||
|
|
||
| /** | ||
| * \brief Prepare the URI so that we can later simply append param=value | ||
| * \param uri uri to prepare | ||
| * \retval prepared uri | ||
| */ | ||
| static QString prepareUri( QString uri ); | ||
|
|
||
| /**Returns the GetCoverage url | ||
| * @added in 1.5 | ||
| */ | ||
| QString getCoverageUrl() const; | ||
|
|
||
| //! Send request to server | ||
| bool sendRequest( QString const & url ); | ||
|
|
||
| /** Get additional coverage info from server. Version 1.0 GetCapabilities | ||
| * response does not contain all info (CRS, formats). | ||
| */ | ||
| bool describeCoverage( QString const &identifier, bool forceRefresh = false ); | ||
|
|
||
| bool convertToDom( QByteArray const &xml ); | ||
| bool parseDescribeCoverageDom( QByteArray const &xml, QgsWcsCoverageSummary *coverage ); | ||
|
|
||
| //! set authorization header | ||
| void setAuthorization( QNetworkRequest &request ) const; | ||
|
|
||
| /** | ||
| * \brief Returns the caption error text for the last error in this provider | ||
| * | ||
| * If an operation returns 0 (e.g. draw()), this function | ||
| * returns the text of the error associated with the failure. | ||
| * Interactive users of this provider can then, for example, | ||
| * call a QMessageBox to display the contents. | ||
| */ | ||
| QString lastErrorTitle(); | ||
|
|
||
| /** | ||
| * \brief Returns the verbose error text for the last error in this provider | ||
| * | ||
| * If an operation returns 0 (e.g. draw()), this function | ||
| * returns the text of the error associated with the failure. | ||
| * Interactive users of this provider can then, for example, | ||
| * call a QMessageBox to display the contents. | ||
| */ | ||
| QString lastError(); | ||
|
|
||
| /** | ||
| * \brief Returns the format of the error message (text or html) | ||
| */ | ||
| QString lastErrorFormat(); | ||
|
|
||
| signals: | ||
|
|
||
| /** \brief emit a signal to notify of a progress event */ | ||
| void progressChanged( int theProgress, int theTotalSteps ); | ||
|
|
||
| /** \brief emit a signal to be caught by qgisapp and display a msg on status bar */ | ||
| void statusChanged( QString const & theStatusQString ); | ||
|
|
||
| private slots: | ||
| void capabilitiesReplyFinished(); | ||
| void capabilitiesReplyProgress( qint64, qint64 ); | ||
|
|
||
| private: | ||
| void showMessageBox( const QString &title, const QString &text ); | ||
|
|
||
| //! Get tag name without namespace | ||
| QString stripNS( const QString &name ); | ||
|
|
||
| //! Get text of first child of specified name, NS is ignored | ||
| QString firstChildText( const QDomElement &element, const QString &name ); | ||
|
|
||
| //! Get first child of specified name, NS is ignored | ||
| QDomElement firstChild( const QDomElement &element, const QString &name ); | ||
|
|
||
| /** | ||
| * \brief Retrieve and parse the (cached) Capabilities document from the server | ||
| * | ||
| * \param forceRefresh if true, ignores any previous response cached in memory | ||
| * and always contact the server for a new copy. | ||
| * \retval false if the capabilities document could not be retrieved or parsed - | ||
| * see lastError() for more info | ||
| * | ||
| * When this returns, "layers" will make sense. | ||
| * | ||
| * TODO: Make network-timeout tolerant | ||
| */ | ||
| bool retrieveServerCapabilities( bool forceRefresh = false ); | ||
|
|
||
| //! \return false if the capabilities document could not be parsed - see lastError() for more info | ||
| bool parseCapabilitiesDom( QByteArray const &xml, QgsWcsCapabilitiesProperty &capabilities ); | ||
|
|
||
| // ------------- 1.0 -------------------- | ||
| //! parse the WCS Service XML element | ||
| void parseService( QDomElement const &e, QgsWcsServiceIdentification &serviceIdentification ); | ||
|
|
||
| //! parse the WCS Capability XML element | ||
| void parseCapability( QDomElement const &e, QgsWcsOperationsMetadata &operationsMetadata ); | ||
|
|
||
| //! parse the WCS Layer XML element | ||
| void parseContentMetadata( QDomElement const &e, QgsWcsCoverageSummary &coverageSummary ); | ||
|
|
||
| //! parse the WCS Layer XML element | ||
| void parseCoverageOfferingBrief( QDomElement const &e, QgsWcsCoverageSummary &coverageSummary, | ||
| QgsWcsCoverageSummary *parent = 0 ); | ||
|
|
||
| // ------------- 1.1 -------------------- | ||
| //! parse the WCS ServiceIdentificatio XML element | ||
| void parseServiceIdentification( QDomElement const &e, QgsWcsServiceIdentification &serviceIdentification ); | ||
|
|
||
| //! parse the WCS OperationsMetadata XML element | ||
| void parseOperationsMetadata( QDomElement const &e, QgsWcsOperationsMetadata &operationsMetadata ); | ||
|
|
||
| //! parse the WCS GetCoverage | ||
| void parseOperation( QDomElement const & e, QgsWcsOperation& operation ); | ||
|
|
||
| //! parse the WCS HTTP XML element | ||
| void parseHttp( QDomElement const &e, QgsWcsHTTP &http ); | ||
|
|
||
| //! parse the WCS DCPType XML element | ||
| void parseDcp( QDomElement const &e, QgsWcsDCP &dcp ); | ||
|
|
||
| //! parse the WCS Layer XML element | ||
| void parseCoverageSummary( QDomElement const &e, QgsWcsCoverageSummary &coverageSummary, | ||
| QgsWcsCoverageSummary *parent = 0 ); | ||
|
|
||
| //! Data source uri | ||
| QgsDataSourceURI mUri; | ||
|
|
||
| //! Response capabilities version | ||
| QString mVersion; | ||
|
|
||
| /** | ||
| * Capabilities of the WCS Server (raw) | ||
| */ | ||
| QByteArray mCapabilitiesResponse; | ||
|
|
||
| /** | ||
| * Capabilities of the WCS Server | ||
| */ | ||
| QDomDocument mCapabilitiesDom; | ||
|
|
||
| /** | ||
| * Last Service Exception Report from the WCS Server | ||
| */ | ||
| QDomDocument mServiceExceptionReportDom; | ||
|
|
||
| /** | ||
| * Parsed capabilities of the WCS Server | ||
| */ | ||
| QgsWcsCapabilitiesProperty mCapabilities; | ||
|
|
||
| /** | ||
| * layers hosted by the WCS Server | ||
| * This vector contain initial copies which are not updated by coverageSummary()!!! | ||
| */ | ||
| QVector<QgsWcsCoverageSummary> mCoveragesSupported; | ||
|
|
||
| /** | ||
| * The reply to the capabilities request | ||
| */ | ||
| QNetworkReply *mCapabilitiesReply; | ||
|
|
||
| /** | ||
| * The error caption associated with the last WCS error. | ||
| */ | ||
| QString mErrorTitle; | ||
|
|
||
| /** | ||
| * The error message associated with the last WCS error. | ||
| */ | ||
| QString mError; | ||
|
|
||
| /** The mime type of the message | ||
| */ | ||
| QString mErrorFormat; | ||
|
|
||
| int mCoverageCount; | ||
|
|
||
| //! number of layers and parents | ||
| QMap<int, int> mCoverageParents; | ||
| QMap<int, QStringList> mCoverageParentIdentifiers; | ||
|
|
||
| //! Username for basic http authentication | ||
| QString mUserName; | ||
|
|
||
| //! Password for basic http authentication | ||
| QString mPassword; | ||
| }; | ||
|
|
||
|
|
||
| #endif | ||
|
|
||
| // ENDS |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,239 @@ | ||
| /*************************************************************************** | ||
| qgswcssourceselect.cpp - selector for WCS | ||
| ------------------- | ||
| begin : 04 2012 | ||
| copyright : | ||
| original : (C) 2012 Radim Blazek | ||
| ***************************************************************************/ | ||
|
|
||
| /*************************************************************************** | ||
| * * | ||
| * This program is free software; you can redistribute it and/or modify * | ||
| * it under the terms of the GNU General Public License as published by * | ||
| * the Free Software Foundation; either version 2 of the License, or * | ||
| * (at your option) any later version. * | ||
| * * | ||
| ***************************************************************************/ | ||
|
|
||
| #include "qgis.h" | ||
| #include "qgslogger.h" | ||
|
|
||
| #include "qgsgdalprovider.h" | ||
| #include "qgswcssourceselect.h" | ||
| #include "qgswcscapabilities.h" | ||
| #include "qgsnumericsortlistviewitem.h" | ||
|
|
||
| #include <QWidget> | ||
|
|
||
| #define CPL_SUPRESS_CPLUSPLUS | ||
| #include <gdal.h> | ||
|
|
||
| #if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM >= 1800 | ||
| #define TO8F(x) (x).toUtf8().constData() | ||
| #define FROM8(x) QString::fromUtf8(x) | ||
| #else | ||
| #define TO8F(x) QFile::encodeName( x ).constData() | ||
| #define FROM8(x) QString::fromLocal8Bit(x) | ||
| #endif | ||
|
|
||
| QgsWCSSourceSelect::QgsWCSSourceSelect( QWidget * parent, Qt::WFlags fl, bool managerMode, bool embeddedMode ) | ||
| : QgsOWSSourceSelect( "WCS", parent, fl, managerMode, embeddedMode ) | ||
| { | ||
| // Hide irrelevant widgets | ||
| mWMSGroupBox->hide(); | ||
| mLayersTab->layout()->removeWidget( mWMSGroupBox ); | ||
| mTabWidget->removeTab( mTabWidget->indexOf( mLayerOrderTab ) ); | ||
| mTabWidget->removeTab( mTabWidget->indexOf( mTilesetsTab ) ); | ||
| mTabWidget->removeTab( mTabWidget->indexOf( mSearchTab ) ); | ||
| mAddDefaultButton->hide(); | ||
|
|
||
| mLayersTreeWidget->setSelectionMode( QAbstractItemView::SingleSelection ); | ||
| } | ||
|
|
||
| QgsWCSSourceSelect::~QgsWCSSourceSelect() | ||
| { | ||
| } | ||
|
|
||
| void QgsWCSSourceSelect::populateLayerList( ) | ||
| { | ||
| QgsDebugMsg( "entered" ); | ||
|
|
||
| mLayersTreeWidget->clear(); | ||
|
|
||
| mCapabilities.setUri( mUri ); | ||
|
|
||
| if ( !mCapabilities.lastError().isEmpty() ) | ||
| { | ||
| showError( mCapabilities.lastErrorTitle(), mCapabilities.lastErrorFormat(), mCapabilities.lastError() ); | ||
| return; | ||
| } | ||
|
|
||
| QVector<QgsWcsCoverageSummary> coverages; | ||
| if ( !mCapabilities.supportedCoverages( coverages ) ) | ||
| return; | ||
|
|
||
| QMap<int, QgsNumericSortTreeWidgetItem *> items; | ||
| QMap<int, int> coverageParents; | ||
| QMap<int, QStringList> coverageParentNames; | ||
| mCapabilities.coverageParents( coverageParents, coverageParentNames ); | ||
|
|
||
| mLayersTreeWidget->setSortingEnabled( true ); | ||
|
|
||
| int coverageAndStyleCount = -1; | ||
|
|
||
| for ( QVector<QgsWcsCoverageSummary>::iterator coverage = coverages.begin(); | ||
| coverage != coverages.end(); | ||
| coverage++ ) | ||
| { | ||
| QgsDebugMsg( QString( "coverage orderId = %1 identifier = %2" ).arg( coverage->orderId ).arg( coverage->identifier ) ); | ||
|
|
||
| QgsNumericSortTreeWidgetItem *lItem = createItem( coverage->orderId, QStringList() << coverage->identifier << coverage->title << coverage->abstract, items, coverageAndStyleCount, coverageParents, coverageParentNames ); | ||
|
|
||
| lItem->setData( 0, Qt::UserRole + 0, coverage->identifier ); | ||
| lItem->setData( 0, Qt::UserRole + 1, "" ); | ||
|
|
||
| // Make only leaves selectable | ||
| if ( coverageParents.keys( coverage->orderId ).size() > 0 ) | ||
| { | ||
| lItem->setFlags( Qt::ItemIsEnabled ); | ||
| } | ||
| } | ||
|
|
||
| mLayersTreeWidget->sortByColumn( 0, Qt::AscendingOrder ); | ||
|
|
||
| // If we got some coverages, let the user add them to the map | ||
| if ( mLayersTreeWidget->topLevelItemCount() == 1 ) | ||
| { | ||
| mLayersTreeWidget->expandItem( mLayersTreeWidget->topLevelItem( 0 ) ); | ||
| } | ||
| } | ||
|
|
||
| QString QgsWCSSourceSelect::selectedIdentifier() | ||
| { | ||
| QList<QTreeWidgetItem *> selectionList = mLayersTreeWidget->selectedItems(); | ||
| if ( selectionList.size() < 1 ) return QString(); // should not happen | ||
| QString identifier = selectionList.value( 0 )->data( 0, Qt::UserRole + 0 ).toString(); | ||
| QgsDebugMsg( " identifier = " + identifier ); | ||
| return identifier; | ||
| } | ||
|
|
||
| void QgsWCSSourceSelect::addClicked( ) | ||
| { | ||
| QgsDebugMsg( "entered" ); | ||
| QgsDataSourceURI uri = mUri; | ||
|
|
||
| QString identifier = selectedIdentifier(); | ||
| if ( identifier.isEmpty() ) { return; } | ||
|
|
||
| uri.setParam( "identifier", identifier ); | ||
|
|
||
| // Set crs only if necessary (multiple offered), so that we can decide in the | ||
| // provider if WCS 1.0 with RESPONSE_CRS has to be used. Not perfect, they can | ||
| // add more CRS in future and URI will be saved in project without any. | ||
| if ( selectedLayersCRSs().size() > 1 ) | ||
| { | ||
| uri.setParam( "crs", selectedCRS() ); | ||
| } | ||
|
|
||
| QgsDebugMsg( "selectedFormat = " + selectedFormat() ); | ||
| if ( !selectedFormat().isEmpty() ) | ||
| { | ||
| uri.setParam( "format", selectedFormat() ); | ||
| } | ||
|
|
||
| emit addRasterLayer( uri.encodedUri(), identifier, "gdal" ); | ||
| } | ||
|
|
||
| void QgsWCSSourceSelect::on_mLayersTreeWidget_itemSelectionChanged() | ||
| { | ||
| QgsDebugMsg( "entered" ); | ||
|
|
||
| QString identifier = selectedIdentifier(); | ||
| if ( identifier.isEmpty() ) { return; } | ||
|
|
||
| mCapabilities.describeCoverage( identifier ); // 1.0 get additional info | ||
|
|
||
| populateFormats(); | ||
|
|
||
| populateCRS(); | ||
|
|
||
| updateButtons(); | ||
|
|
||
| mAddButton->setEnabled( true ); | ||
| } | ||
|
|
||
| void QgsWCSSourceSelect::updateButtons() | ||
| { | ||
| QgsDebugMsg( "entered" ); | ||
|
|
||
| if ( mLayersTreeWidget->selectedItems().isEmpty() ) | ||
| { | ||
| showStatusMessage( tr( "Select a layer" ) ); | ||
| } | ||
| else | ||
| { | ||
| if ( selectedCRS().isEmpty() ) | ||
| { | ||
| showStatusMessage( tr( "No CRS selected" ) ); | ||
| } | ||
| } | ||
|
|
||
| mAddButton->setEnabled( !mLayersTreeWidget->selectedItems().isEmpty() && !selectedCRS().isEmpty() && !selectedFormat().isEmpty() ); | ||
| } | ||
|
|
||
| QList<QgsOWSSupportedFormat> QgsWCSSourceSelect::providerFormats() | ||
| { | ||
| QgsDebugMsg( "entered" ); | ||
| QList<QgsOWSSupportedFormat> formats; | ||
|
|
||
| QMap<QString, QString> mimes = QgsGdalProvider::supportedMimes(); | ||
| foreach( QString mime, mimes.keys() ) | ||
| { | ||
| QgsOWSSupportedFormat format = { mime, mimes.value( mime ) }; | ||
|
|
||
| // prefer tiff | ||
| if ( mime == "image/tiff" ) | ||
| { | ||
| formats.prepend( format ); | ||
| } | ||
| else | ||
| { | ||
| formats.append( format ); | ||
| } | ||
| } | ||
|
|
||
| return formats; | ||
| } | ||
|
|
||
| QStringList QgsWCSSourceSelect::selectedLayersFormats() | ||
| { | ||
| QgsDebugMsg( "entered" ); | ||
|
|
||
| QString identifier = selectedIdentifier(); | ||
| if ( identifier.isEmpty() ) { return QStringList(); } | ||
|
|
||
| QgsWcsCoverageSummary * c = mCapabilities.coverageSummary( identifier ); | ||
| if ( !c ) { return QStringList(); } | ||
|
|
||
| QgsDebugMsg( "supportedFormat = " + c->supportedFormat.join( "," ) ); | ||
| return c->supportedFormat; | ||
| } | ||
|
|
||
| QStringList QgsWCSSourceSelect::selectedLayersCRSs() | ||
| { | ||
| QgsDebugMsg( "entered" ); | ||
|
|
||
| QString identifier = selectedIdentifier(); | ||
| if ( identifier.isEmpty() ) { return QStringList(); } | ||
|
|
||
| QgsWcsCoverageSummary * c = mCapabilities.coverageSummary( identifier ); | ||
| if ( !c ) { return QStringList(); } | ||
|
|
||
| return c->supportedCrs; | ||
| } | ||
|
|
||
| void QgsWCSSourceSelect::enableLayersForCrs( QTreeWidgetItem *item ) | ||
| { | ||
| // TODO: I am not convinced to disable layers according to selected CRS | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| /*************************************************************************** | ||
| qgswcssourceselect.h - selector for WCS layers | ||
| ------------------- | ||
| begin : 3 April 2005 | ||
| original : (C) 2005 by Brendan Morley email : morb at ozemail dot com dot au | ||
| wms search : (C) 2009 Mathias Walker <mwa at sourcepole.ch>, Sourcepole AG | ||
| generalized : (C) 2012 Radim Blazek, based on qgsowsconnection.h | ||
| ***************************************************************************/ | ||
|
|
||
| /*************************************************************************** | ||
| * * | ||
| * This program is free software; you can redistribute it and/or modify * | ||
| * it under the terms of the GNU General Public License as published by * | ||
| * the Free Software Foundation; either version 2 of the License, or * | ||
| * (at your option) any later version. * | ||
| * * | ||
| ***************************************************************************/ | ||
|
|
||
| #ifndef QGSWCSSOURCESELECT_H | ||
| #define QGSWCSSOURCESELECT_H | ||
| #include "qgsowssourceselect.h" | ||
| #include "qgsdatasourceuri.h" | ||
| #include "qgisgui.h" | ||
| #include "qgscontexthelp.h" | ||
| #include "qgswcscapabilities.h" | ||
|
|
||
| #include "qgsdataprovider.h" | ||
|
|
||
| #include <QStringList> | ||
| #include <QPushButton> | ||
|
|
||
| class QgisApp; | ||
| class QgsDataProvider; | ||
| class QButtonGroup; | ||
| class QgsNumericSortTreeWidgetItem; | ||
| class QDomDocument; | ||
| class QDomElement; | ||
|
|
||
| /*! | ||
| * \brief Dialog to create connections and add layers from WMS, WFS, WCS etc. | ||
| * | ||
| * This dialog allows the user to define and save connection information | ||
| * for WMS servers, etc. | ||
| * | ||
| * The user can then connect and add | ||
| * layers from the WMS server to the map canvas. | ||
| */ | ||
| class QgsWCSSourceSelect : public QgsOWSSourceSelect | ||
| { | ||
| Q_OBJECT | ||
|
|
||
| public: | ||
| //! Constructor | ||
| QgsWCSSourceSelect( QWidget *parent = 0, Qt::WFlags fl = QgisGui::ModalDialogFlags, bool managerMode = false, bool embeddedMode = false ); | ||
| //! Destructor | ||
| ~QgsWCSSourceSelect(); | ||
|
|
||
| public slots: | ||
|
|
||
| signals: | ||
| void addRasterLayer( QString const & rasterLayerPath, | ||
| QString const & baseName, | ||
| QString const & providerKey ); | ||
|
|
||
| private: | ||
| QgsWcsCapabilities mCapabilities; | ||
|
|
||
| QString selectedIdentifier(); | ||
|
|
||
| // QgsWcsCapabilities virtual methods | ||
| void populateLayerList( ); | ||
| void addClicked(); | ||
| void on_mLayersTreeWidget_itemSelectionChanged(); | ||
| void enableLayersForCrs( QTreeWidgetItem *item ); | ||
| void updateButtons(); | ||
| QList<QgsOWSSupportedFormat> providerFormats(); | ||
| QStringList selectedLayersFormats(); | ||
| QStringList selectedLayersCRSs(); | ||
| }; | ||
| #endif // QGSWCSSOURCESELECT_H | ||
|
|
||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| SET(OWS_SRCS | ||
| qgsowsprovider.cpp | ||
| qgsowsdataitems.cpp | ||
| ) | ||
| SET(OWS_MOC_HDRS | ||
| qgsowsprovider.h | ||
| qgsowsdataitems.h | ||
| ) | ||
|
|
||
| INCLUDE_DIRECTORIES ( | ||
| ../../core | ||
| ../../gui | ||
| ${CMAKE_CURRENT_BINARY_DIR}/../../ui | ||
| ) | ||
|
|
||
| QT4_WRAP_CPP(OWS_MOC_SRCS ${OWS_MOC_HDRS}) | ||
| ADD_LIBRARY (owsprovider MODULE ${OWS_SRCS} ${OWS_MOC_SRCS}) | ||
|
|
||
| TARGET_LINK_LIBRARIES (owsprovider | ||
| qgis_core | ||
| qgis_gui | ||
| ) | ||
|
|
||
| INSTALL(TARGETS owsprovider | ||
| RUNTIME DESTINATION ${QGIS_PLUGIN_DIR} | ||
| LIBRARY DESTINATION ${QGIS_PLUGIN_DIR}) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,239 @@ | ||
| #include "qgsproviderregistry.h" | ||
| #include "qgsowsdataitems.h" | ||
| #include "qgsowsprovider.h" | ||
| #include "qgslogger.h" | ||
| #include "qgsdatasourceuri.h" | ||
| //#include "qgsowssourceselect.h" | ||
| #include "qgsowsconnection.h" | ||
| #include "qgsnewhttpconnection.h" | ||
|
|
||
| #include <QFileInfo> | ||
|
|
||
| // --------------------------------------------------------------------------- | ||
| QgsOWSConnectionItem::QgsOWSConnectionItem( QgsDataItem* parent, QString name, QString path ) | ||
| : QgsDataCollectionItem( parent, name, path ) | ||
| { | ||
| mIcon = QIcon( getThemePixmap( "mIconConnect.png" ) ); | ||
| } | ||
|
|
||
| QgsOWSConnectionItem::~QgsOWSConnectionItem() | ||
| { | ||
| } | ||
|
|
||
| QVector<QgsDataItem*> QgsOWSConnectionItem::createChildren() | ||
| { | ||
| QgsDebugMsg( "Entered" ); | ||
| QVector<QgsDataItem*> children; | ||
|
|
||
| QVector<QgsDataItem*> serviceItems; | ||
|
|
||
| int layerCount; | ||
| // Try to open with WMS,WFS,WCS | ||
| foreach( QString key, QStringList() << "wms" << "WFS" << "gdal" ) | ||
| { | ||
| QgsDebugMsg( "Add connection for provider " + key ); | ||
| QLibrary *library = QgsProviderRegistry::instance()->providerLibrary( key ); | ||
| if ( !library ) continue; | ||
|
|
||
| dataItem_t * dItem = ( dataItem_t * ) cast_to_fptr( library->resolve( "dataItem" ) ); | ||
| if ( !dItem ) | ||
| { | ||
| QgsDebugMsg( library->fileName() + " does not have dataItem" ); | ||
| continue; | ||
| } | ||
|
|
||
| QgsDataItem *item = dItem( mPath, this ); // empty path -> top level | ||
| if ( !item ) continue; | ||
|
|
||
| layerCount += item->rowCount(); | ||
| if ( item->rowCount() > 0 ) | ||
| { | ||
| QgsDebugMsg( "Add new item : " + item->name() ); | ||
| serviceItems.append( item ); | ||
| } | ||
| else | ||
| { | ||
| //delete item; | ||
| } | ||
| } | ||
|
|
||
| foreach( QgsDataItem* item, serviceItems ) | ||
| { | ||
| QgsDebugMsg( QString( "serviceItems.size = %1 layerCount = %2 rowCount = %3" ).arg( serviceItems.size() ).arg( layerCount ).arg( item->rowCount() ) ); | ||
| if ( serviceItems.size() == 1 || layerCount <= 30 || item->rowCount() <= 10 ) | ||
| { | ||
| // Add layers directly to OWS connection | ||
| foreach( QgsDataItem* subItem, item->children() ) | ||
| { | ||
| item->removeChildItem( subItem ); | ||
| subItem->setParent( this ); | ||
| children.append( subItem ); | ||
| } | ||
| delete item; | ||
| } | ||
| else // Add service | ||
| { | ||
| children.append( item ); | ||
| } | ||
| } | ||
|
|
||
| return children; | ||
| } | ||
|
|
||
| bool QgsOWSConnectionItem::equal( const QgsDataItem *other ) | ||
| { | ||
| if ( type() != other->type() ) | ||
| { | ||
| return false; | ||
| } | ||
| const QgsOWSConnectionItem *o = dynamic_cast<const QgsOWSConnectionItem *>( other ); | ||
| return ( mPath == o->mPath && mName == o->mName ); | ||
| } | ||
|
|
||
| QList<QAction*> QgsOWSConnectionItem::actions() | ||
| { | ||
| QList<QAction*> lst; | ||
|
|
||
| QAction* actionEdit = new QAction( tr( "Edit..." ), this ); | ||
| connect( actionEdit, SIGNAL( triggered() ), this, SLOT( editConnection() ) ); | ||
| lst.append( actionEdit ); | ||
|
|
||
| QAction* actionDelete = new QAction( tr( "Delete" ), this ); | ||
| connect( actionDelete, SIGNAL( triggered() ), this, SLOT( deleteConnection() ) ); | ||
| lst.append( actionDelete ); | ||
|
|
||
| return lst; | ||
| } | ||
|
|
||
| void QgsOWSConnectionItem::editConnection() | ||
| { | ||
| /* | ||
| QgsNewHttpConnection nc( 0, "/Qgis/connections-ows/", mName ); | ||
| if ( nc.exec() ) | ||
| { | ||
| // the parent should be updated | ||
| mParent->refresh(); | ||
| } | ||
| */ | ||
| } | ||
|
|
||
| void QgsOWSConnectionItem::deleteConnection() | ||
| { | ||
| /* | ||
| QgsOWSConnection::deleteConnection( "OWS", mName ); | ||
| // the parent should be updated | ||
| mParent->refresh(); | ||
| */ | ||
| } | ||
|
|
||
|
|
||
| // --------------------------------------------------------------------------- | ||
|
|
||
|
|
||
| QgsOWSRootItem::QgsOWSRootItem( QgsDataItem* parent, QString name, QString path ) | ||
| : QgsDataCollectionItem( parent, name, path ) | ||
| { | ||
| mIcon = QIcon( getThemePixmap( "mIconOws.png" ) ); | ||
|
|
||
| populate(); | ||
| } | ||
|
|
||
| QgsOWSRootItem::~QgsOWSRootItem() | ||
| { | ||
| } | ||
|
|
||
| QVector<QgsDataItem*>QgsOWSRootItem::createChildren() | ||
| { | ||
| QgsDebugMsg( "Entered" ); | ||
| QVector<QgsDataItem*> connections; | ||
| // Combine all WMS,WFS,WCS connections | ||
| QMap<QString, QStringList> uris; | ||
| foreach( QString service, QStringList() << "WMS" << "WFS" << "WCS" ) | ||
| { | ||
| foreach( QString connName, QgsOWSConnection::connectionList( service ) ) | ||
| { | ||
| QgsOWSConnection connection( service, connName ); | ||
|
|
||
| QString encodedUri = connection.uri().encodedUri(); | ||
| QStringList labels = uris.value( encodedUri ); | ||
| if ( !labels.contains( connName ) ) | ||
| { | ||
| labels << connName; | ||
| } | ||
| uris[encodedUri] = labels; | ||
| } | ||
| } | ||
| foreach( QString encodedUri, uris.keys() ) | ||
| { | ||
| QgsDataItem * conn = new QgsOWSConnectionItem( this, uris.value( encodedUri ).join( " / " ), encodedUri ); | ||
| connections.append( conn ); | ||
| } | ||
| return connections; | ||
| } | ||
|
|
||
| QList<QAction*> QgsOWSRootItem::actions() | ||
| { | ||
| QList<QAction*> lst; | ||
|
|
||
| /* | ||
| QAction* actionNew = new QAction( tr( "New Connection..." ), this ); | ||
| connect( actionNew, SIGNAL( triggered() ), this, SLOT( newConnection() ) ); | ||
| lst.append( actionNew ); | ||
| */ | ||
| return lst; | ||
| } | ||
|
|
||
|
|
||
| QWidget * QgsOWSRootItem::paramWidget() | ||
| { | ||
| /* | ||
| QgsOWSSourceSelect *select = new QgsOWSSourceSelect( 0, 0, true, true ); | ||
| connect( select, SIGNAL( connectionsChanged() ), this, SLOT( connectionsChanged() ) ); | ||
| return select; | ||
| */ | ||
| return 0; | ||
| } | ||
| void QgsOWSRootItem::connectionsChanged() | ||
| { | ||
| refresh(); | ||
| } | ||
|
|
||
| void QgsOWSRootItem::newConnection() | ||
| { | ||
| /* | ||
| QgsNewHttpConnection nc( 0, "/Qgis/connections-ows/" ); | ||
| if ( nc.exec() ) | ||
| { | ||
| refresh(); | ||
| } | ||
| */ | ||
| } | ||
|
|
||
|
|
||
| // --------------------------------------------------------------------------- | ||
|
|
||
| static QStringList extensions = QStringList(); | ||
| static QStringList wildcards = QStringList(); | ||
|
|
||
| QGISEXTERN int dataCapabilities() | ||
| { | ||
| return QgsDataProvider::Net; | ||
| } | ||
|
|
||
| QGISEXTERN QgsDataItem * dataItem( QString thePath, QgsDataItem* parentItem ) | ||
| { | ||
| if ( thePath.isEmpty() ) | ||
| { | ||
| return new QgsOWSRootItem( parentItem, "OWS", "ows:" ); | ||
| } | ||
|
|
||
| } | ||
|
|
||
| //QGISEXTERN QgsOWSSourceSelect * selectWidget( QWidget * parent, Qt::WFlags fl ) | ||
| QGISEXTERN QDialog * selectWidget( QWidget * parent, Qt::WFlags fl ) | ||
| { | ||
| //return new QgsOWSSourceSelect( parent, fl ); | ||
| return 0; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| #ifndef QGSOWSDATAITEMS_H | ||
| #define QGSOWSDATAITEMS_H | ||
|
|
||
| #include "qgsdataitem.h" | ||
| #include "qgsdatasourceuri.h" | ||
| class QgsOWSConnectionItem : public QgsDataCollectionItem | ||
| { | ||
| Q_OBJECT | ||
| public: | ||
| QgsOWSConnectionItem( QgsDataItem* parent, QString name, QString path ); | ||
| ~QgsOWSConnectionItem(); | ||
|
|
||
| QVector<QgsDataItem*> createChildren(); | ||
| virtual bool equal( const QgsDataItem *other ); | ||
|
|
||
| virtual QList<QAction*> actions(); | ||
|
|
||
| public slots: | ||
| void editConnection(); | ||
| void deleteConnection(); | ||
| }; | ||
|
|
||
| class QgsOWSRootItem : public QgsDataCollectionItem | ||
| { | ||
| Q_OBJECT | ||
| public: | ||
| QgsOWSRootItem( QgsDataItem* parent, QString name, QString path ); | ||
| ~QgsOWSRootItem(); | ||
|
|
||
| QVector<QgsDataItem*> createChildren(); | ||
|
|
||
| virtual QList<QAction*> actions(); | ||
|
|
||
| virtual QWidget * paramWidget(); | ||
|
|
||
| public slots: | ||
| void connectionsChanged(); | ||
|
|
||
| void newConnection(); | ||
| }; | ||
|
|
||
| #endif // QGSOWSDATAITEMS_H |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| /*************************************************************************** | ||
| qgsowsprovider.cpp - OWS meta provider for WMS,WFS,WCS in browser | ||
| ------------------- | ||
| begin : 4/2012 | ||
| copyright : (C) 2010 by Radim Blazek | ||
| email : radim dot blazek at gmail dot com | ||
| ***************************************************************************/ | ||
|
|
||
| /*************************************************************************** | ||
| * * | ||
| * This program is free software; you can redistribute it and/or modify * | ||
| * it under the terms of the GNU General Public License as published by * | ||
| * the Free Software Foundation; either version 2 of the License, or * | ||
| * (at your option) any later version. * | ||
| * * | ||
| ***************************************************************************/ | ||
|
|
||
| #include "qgslogger.h" | ||
| #include "qgsowsprovider.h" | ||
| #include "qgsconfig.h" | ||
|
|
||
| #include <QString> | ||
|
|
||
| static QString PROVIDER_KEY = "ows"; | ||
| static QString PROVIDER_DESCRIPTION = "OWS meta provider"; | ||
|
|
||
| QgsOwsProvider::QgsOwsProvider( QString const & uri ) | ||
| : QgsDataProvider( uri ) | ||
| { | ||
| } | ||
|
|
||
| QgsOwsProvider::~QgsOwsProvider() | ||
| { | ||
| } | ||
|
|
||
| QGISEXTERN QgsOwsProvider * classFactory( const QString *uri ) | ||
| { | ||
| return new QgsOwsProvider( *uri ); | ||
| } | ||
|
|
||
| QString QgsOwsProvider::name() const | ||
| { | ||
| return PROVIDER_KEY; | ||
| } | ||
|
|
||
| QString QgsOwsProvider::description() const | ||
| { | ||
| return PROVIDER_DESCRIPTION; | ||
| } | ||
|
|
||
| QGISEXTERN QString providerKey() | ||
| { | ||
| return PROVIDER_KEY; | ||
| } | ||
|
|
||
| QGISEXTERN QString description() | ||
| { | ||
| return PROVIDER_DESCRIPTION; | ||
| } | ||
|
|
||
| QGISEXTERN bool isProvider() | ||
| { | ||
| return true; | ||
| } | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| /*************************************************************************** | ||
| qgsowsprovider.h - OWS meta provider for WMS,WFS,WCS in browser | ||
| ------------------- | ||
| begin : 4/2012 | ||
| copyright : (C) 2012 by Radim Blazek | ||
| email : radim dot blazek at gmail dot com | ||
| ***************************************************************************/ | ||
|
|
||
| /*************************************************************************** | ||
| * * | ||
| * This program is free software; you can redistribute it and/or modify * | ||
| * it under the terms of the GNU General Public License as published by * | ||
| * the Free Software Foundation; either version 2 of the License, or * | ||
| * (at your option) any later version. * | ||
| * * | ||
| ***************************************************************************/ | ||
|
|
||
| #ifndef QGSOWSPROVIDER_H | ||
| #define QGSOWSPROVIDER_H | ||
|
|
||
| #include "qgsdataprovider.h" | ||
| #include "qgscoordinatereferencesystem.h" | ||
| #include "qgsdataitem.h" | ||
| #include "qgsrectangle.h" | ||
|
|
||
| #include <QString> | ||
|
|
||
| /** | ||
| \brief Data provider for GDAL layers. | ||
| This provider implements the interface defined in the QgsDataProvider class | ||
| to provide access to spatial data residing in a GDAL layers. | ||
| */ | ||
| class QgsOwsProvider : public QgsDataProvider | ||
| { | ||
| Q_OBJECT | ||
|
|
||
| public: | ||
| /** | ||
| * Constructor for the provider. | ||
| * | ||
| * \param uri HTTP URL of the Web Server. If needed a proxy will be used | ||
| * otherwise we contact the host directly. | ||
| * | ||
| */ | ||
| QgsOwsProvider( QString const & uri = 0 ); | ||
|
|
||
| //! Destructor | ||
| ~QgsOwsProvider(); | ||
|
|
||
| /* Pure virtuals */ | ||
|
|
||
| QString name() const; | ||
|
|
||
| QString description() const; | ||
|
|
||
| QgsCoordinateReferenceSystem crs() { return QgsCoordinateReferenceSystem(); } | ||
|
|
||
| QgsRectangle extent() { return QgsRectangle(); } | ||
|
|
||
| bool isValid() { return false; } | ||
| }; | ||
|
|
||
| #endif // QGSOWSPROVIDER_H |