1,012 changes: 1,012 additions & 0 deletions src/gui/qgsowssourceselect.cpp

Large diffs are not rendered by default.

236 changes: 236 additions & 0 deletions src/gui/qgsowssourceselect.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,236 @@
/***************************************************************************
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() ); }

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 serverFormats();

//! Server CRS supported for currently selected layer item(s)
virtual QStringList serverCRS();

virtual QStringList layerCRS( int id );

//! Populate the connection list combo box
void populateConnectionList();

//! Populate supported formats
void populateFormats();

//! 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;

//! Selected CRS
QString mCRS;

//! Common CRSs for selected layers
QSet<QString> mCRSs;

//! Supported formats
QList<QgsOWSSupportedFormat> mProviderFormats;

//! Map mime types to supported formats
QMap<QString, int> mMimeMap;

/**
* \brief Populate the layer list - private for now.
*
* \retval false if the layers could not be retrieved or parsed -
* see mWmsProvider->errorString() for more info
*/
virtual bool 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 );

void applySelectionConstraints( QTreeWidgetItem *item );
void collectNamedLayers( QTreeWidgetItem *item, QStringList &layers, QStringList &styles );
virtual void enableLayersForCrs( QTreeWidgetItem *item );

//! Returns currently selected format
QString selectedFormat();

//! Returns currently selected Crs
QString selectedCrs();

QList<QTreeWidgetItem*> mCurrentSelection;
QTableWidgetItem* mCurrentTileset;

signals:
void addRasterLayer( QString const & rasterLayerPath,
QString const & baseName,
QString const & providerKey );
void connectionsChanged();

protected:
//! Name for selected connection
QString mConnName;

//! Cnnection info for selected connection
QString mConnectionInfo;

//! URI for selected connection
QgsDataSourceURI mUri;

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
502 changes: 502 additions & 0 deletions src/ui/qgsowssourceselectbase.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,502 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>QgsOWSSourceSelectBase</class>
<widget class="QDialog" name="QgsOWSSourceSelectBase">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>694</width>
<height>616</height>
</rect>
</property>
<property name="windowTitle">
<string>Add Layer(s) from a Server</string>
</property>
<property name="windowIcon">
<iconset>
<normaloff>../../../../.designer/backup</normaloff>../../../../.designer/backup</iconset>
</property>
<property name="sizeGripEnabled">
<bool>true</bool>
</property>
<property name="modal">
<bool>true</bool>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="3" column="0">
<widget class="QDialogButtonBox" name="mDialogButtonBox">
<property name="standardButtons">
<set>QDialogButtonBox::Apply|QDialogButtonBox::Close|QDialogButtonBox::Help</set>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="mStatusLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Ignored" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Ready</string>
</property>
<property name="wordWrap">
<bool>false</bool>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QTabWidget" name="mTabWidget">
<property name="enabled">
<bool>true</bool>
</property>
<property name="currentIndex">
<number>1</number>
</property>
<widget class="QWidget" name="mLayersTab">
<attribute name="title">
<string>Layers</string>
</attribute>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0" colspan="8">
<widget class="QComboBox" name="mConnectionsComboBox"/>
</item>
<item row="1" column="0">
<widget class="QPushButton" name="mConnectButton">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>C&amp;onnect</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QPushButton" name="mNewButton">
<property name="text">
<string>&amp;New</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QPushButton" name="mEditButton">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Edit</string>
</property>
</widget>
</item>
<item row="1" column="3">
<widget class="QPushButton" name="mDeleteButton">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Delete</string>
</property>
</widget>
</item>
<item row="1" column="4">
<spacer name="horizontalSpacer_1">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>8</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="5">
<widget class="QPushButton" name="mLoadButton">
<property name="toolTip">
<string>Load connections from file</string>
</property>
<property name="text">
<string>Load</string>
</property>
</widget>
</item>
<item row="1" column="6">
<widget class="QPushButton" name="mSaveButton">
<property name="toolTip">
<string>Save connections to file</string>
</property>
<property name="text">
<string>Save</string>
</property>
</widget>
</item>
<item row="1" column="7">
<widget class="QPushButton" name="mAddDefaultButton">
<property name="statusTip">
<string>Adds a few example WMS servers</string>
</property>
<property name="whatsThis">
<string comment="Adds several example WMS servers to the list"/>
</property>
<property name="text">
<string>Add default servers</string>
</property>
</widget>
</item>
<item row="2" column="0" colspan="8">
<widget class="QTreeWidget" name="mLayersTreeWidget">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::MultiSelection</enum>
</property>
<property name="allColumnsShowFocus">
<bool>true</bool>
</property>
<column>
<property name="text">
<string>ID</string>
</property>
</column>
<column>
<property name="text">
<string>Name</string>
</property>
</column>
<column>
<property name="text">
<string>Title</string>
</property>
</column>
<column>
<property name="text">
<string>Abstract</string>
</property>
</column>
</widget>
</item>
<item row="3" column="0" colspan="8">
<widget class="QGroupBox" name="mImageFormatsGroupBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>16</width>
<height>64</height>
</size>
</property>
<property name="title">
<string>Format</string>
</property>
</widget>
</item>
<item row="4" column="0" colspan="8">
<widget class="QGroupBox" name="mWMSGroupBox">
<property name="title">
<string>Options</string>
</property>
<layout class="QGridLayout">
<item row="0" column="0">
<widget class="QLabel" name="mLayerNameLabel">
<property name="text">
<string>Layer name</string>
</property>
<property name="buddy">
<cstring>mLayerNameLineEdit</cstring>
</property>
</widget>
</item>
<item row="0" column="1" colspan="2">
<widget class="QLineEdit" name="mLayerNameLineEdit"/>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="mTileWidthLineEdit"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="mTileSizeLabel">
<property name="text">
<string>Tile size</string>
</property>
<property name="buddy">
<cstring>mTileWidthLineEdit</cstring>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QLineEdit" name="mTileHeightLineEdit"/>
</item>
<item row="2" column="0" colspan="2">
<widget class="QLabel" name="mFeatureCountLabel">
<property name="text">
<string>Feature limit for GetFeatureInfo</string>
</property>
<property name="buddy">
<cstring>mFeatureCountLineEdit</cstring>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QLineEdit" name="mFeatureCountLineEdit"/>
</item>
</layout>
</widget>
</item>
<item row="5" column="0" colspan="8">
<widget class="QGroupBox" name="mCRSGroupBox">
<property name="title">
<string>Coordinate Reference System</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="mCRSLabel">
<property name="text">
<string>Coordinate Reference System</string>
</property>
<property name="buddy">
<cstring>mChangeCRSButton</cstring>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="mChangeCRSButton">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Change ...</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="mLayerOrderTab">
<attribute name="title">
<string>Layer Order</string>
</attribute>
<layout class="QGridLayout">
<item row="0" column="0">
<widget class="QPushButton" name="mLayerUpButton">
<property name="toolTip">
<string>Move selected layer UP</string>
</property>
<property name="text">
<string>Up</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QPushButton" name="mLayerDownButton">
<property name="toolTip">
<string>Move selected layer DOWN</string>
</property>
<property name="text">
<string>Down</string>
</property>
</widget>
</item>
<item row="0" column="2">
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>391</width>
<height>30</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="0" colspan="3">
<widget class="QTreeWidget" name="mLayerOrderTreeWidget">
<property name="columnCount">
<number>2</number>
</property>
<column>
<property name="text">
<string>Layer</string>
</property>
</column>
<column>
<property name="text">
<string>Style</string>
</property>
</column>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="mTilesetsTab">
<attribute name="title">
<string>Tilesets</string>
</attribute>
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0">
<widget class="QTableWidget" name="mTilesetsTableWidget">
<property name="alternatingRowColors">
<bool>true</bool>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::SingleSelection</enum>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
</property>
<property name="cornerButtonEnabled">
<bool>false</bool>
</property>
<attribute name="verticalHeaderVisible">
<bool>false</bool>
</attribute>
<attribute name="verticalHeaderVisible">
<bool>false</bool>
</attribute>
<column>
<property name="text">
<string>Layers</string>
</property>
</column>
<column>
<property name="text">
<string>Styles</string>
</property>
</column>
<column>
<property name="text">
<string>Size</string>
</property>
</column>
<column>
<property name="text">
<string>Format</string>
</property>
</column>
<column>
<property name="text">
<string>CRS</string>
</property>
</column>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="mSearchTab">
<attribute name="title">
<string>Server Search</string>
</attribute>
<layout class="QGridLayout">
<item row="0" column="0">
<widget class="QLineEdit" name="mSearchTermLineEdit"/>
</item>
<item row="0" column="1">
<widget class="QPushButton" name="mSearchButton">
<property name="text">
<string>Search</string>
</property>
<property name="default">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="0" colspan="2">
<widget class="QTableWidget" name="mSearchTableWidget">
<property name="selectionMode">
<enum>QAbstractItemView::SingleSelection</enum>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
</property>
<property name="cornerButtonEnabled">
<bool>false</bool>
</property>
<attribute name="verticalHeaderVisible">
<bool>false</bool>
</attribute>
<attribute name="verticalHeaderVisible">
<bool>false</bool>
</attribute>
<column>
<property name="text">
<string>Title</string>
</property>
</column>
<column>
<property name="text">
<string>Description</string>
</property>
</column>
<column>
<property name="text">
<string>URL</string>
</property>
</column>
</widget>
</item>
<item row="2" column="0" colspan="2">
<widget class="QPushButton" name="mSearchAddButton">
<property name="text">
<string>Add selected row to WMS list</string>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</widget>
<layoutdefault spacing="6" margin="11"/>
<tabstops>
<tabstop>mTabWidget</tabstop>
<tabstop>mConnectionsComboBox</tabstop>
<tabstop>mConnectButton</tabstop>
<tabstop>mNewButton</tabstop>
<tabstop>mEditButton</tabstop>
<tabstop>mDeleteButton</tabstop>
<tabstop>mAddDefaultButton</tabstop>
<tabstop>mLayersTreeWidget</tabstop>
<tabstop>mLayerNameLineEdit</tabstop>
<tabstop>mLayerUpButton</tabstop>
<tabstop>mLayerDownButton</tabstop>
<tabstop>mLayerOrderTreeWidget</tabstop>
<tabstop>mTilesetsTableWidget</tabstop>
<tabstop>mSearchTermLineEdit</tabstop>
<tabstop>mSearchButton</tabstop>
<tabstop>mSearchTableWidget</tabstop>
<tabstop>mSearchAddButton</tabstop>
<tabstop>mDialogButtonBox</tabstop>
</tabstops>
<resources/>
<connections>
<connection>
<sender>mDialogButtonBox</sender>
<signal>rejected()</signal>
<receiver>QgsOWSSourceSelectBase</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>518</x>
<y>510</y>
</hint>
<hint type="destinationlabel">
<x>551</x>
<y>370</y>
</hint>
</hints>
</connection>
</connections>
</ui>