-
Notifications
You must be signed in to change notification settings - Fork 1
/
qgssossourceselect.cpp
193 lines (165 loc) · 6.31 KB
/
qgssossourceselect.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
/***************************************************************************
qgssossourceselect.cpp - description
------------------------------------
begin : June 2013
copyright : (C) 2013 by Marco Hugentobler
email : marco dot hugentobler at sourcepole dot ch
***************************************************************************/
/***************************************************************************
* *
* 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 "qgssossourceselect.h"
#include "qgssosconnectiondialog.h"
#include "qgsowsconnection.h"
#include "qgssoscapabilities.h"
#include "qgisinterface.h"
#include <QMessageBox>
#include <QSettings>
#include <QUrl>
QgsSOSSourceSelect::QgsSOSSourceSelect( QgisInterface* iface, QWidget* parent, Qt::WindowFlags fl ):
QDialog( parent, fl ), mCapabilities( 0 ), mIface( iface )
{
setupUi( this );
populateConnectionList();
QPushButton* mAddButton = new QPushButton( tr( "&Add" ) );
mButtonBox->addButton( mAddButton, QDialogButtonBox::ActionRole );
connect( mAddButton, SIGNAL( clicked() ), this, SLOT( addLayer() ) );
mFilterModel.setSourceModel( &mOfferingsModel );
mOfferingsView->setModel( &mFilterModel );
}
QgsSOSSourceSelect::~QgsSOSSourceSelect()
{
delete mCapabilities;
}
void QgsSOSSourceSelect::on_mConnectButton_clicked()
{
QgsOwsConnection connection( "SOS", mConnectionsComboBox->currentText() );
delete mCapabilities;
mCapabilities = new QgsSOSCapabilities( connection.uri().encodedUri() );
connect( mCapabilities, SIGNAL( gotCapabilities() ), this, SLOT( gotCapabilities() ) );
mCapabilities->requestCapabilities();
}
void QgsSOSSourceSelect::on_mNewButton_clicked()
{
showConnectionDialog();
}
void QgsSOSSourceSelect::on_mEditButton_clicked()
{
QSettings s;
QString connectionName = mConnectionsComboBox->currentText();
QString url = s.value( "qgis/connections-sos/" + connectionName + "/url" ).toString();
showConnectionDialog( connectionName, url );
}
void QgsSOSSourceSelect::showConnectionDialog( const QString& connectionName, const QString& connectionUrl )
{
QgsSOSConnectionDialog d( connectionName, connectionUrl, this );
if( d.exec() == QDialog::Accepted )
{
QSettings s;
s.setValue( QString( "qgis/connections-sos/" ) + d.name() + "/url", d.url() );
populateConnectionList();
}
}
void QgsSOSSourceSelect::on_mDeleteButton_clicked()
{
QString msg = tr( "Are you sure you want to remove the %1 connection and all associated settings?" )
.arg( mConnectionsComboBox->currentText() );
QMessageBox::StandardButton result = QMessageBox::information( this, tr( "Confirm Delete" ), msg, QMessageBox::Ok | QMessageBox::Cancel );
if ( result == QMessageBox::Ok )
{
QgsOwsConnection::deleteConnection( "SOS", mConnectionsComboBox->currentText() );
mConnectionsComboBox->removeItem( mConnectionsComboBox->currentIndex() );
}
}
void QgsSOSSourceSelect::on_mFilterLineEdit_textChanged( const QString& text )
{
mFilterModel.setFilterWildcard( text );
}
void QgsSOSSourceSelect::populateConnectionList()
{
mConnectionsComboBox->clear();
QStringList keys = QgsOwsConnection::connectionList( "SOS" );
QStringList::const_iterator it = keys.constBegin();
for ( ; it != keys.constEnd(); ++it )
{
mConnectionsComboBox->addItem( *it );
}
bool buttonsEnabled = ( keys.constBegin() != keys.constEnd() );
mConnectButton->setEnabled( buttonsEnabled );
mEditButton->setEnabled( buttonsEnabled );
mDeleteButton->setEnabled( buttonsEnabled );
//set last used connection
QString selectedConnection = QgsOwsConnection::selectedConnection( "SOS" );
int index = mConnectionsComboBox->findText( selectedConnection );
if ( index != -1 )
{
mConnectionsComboBox->setCurrentIndex( index );
}
}
void QgsSOSSourceSelect::gotCapabilities()
{
mOfferingsModel.clear();
if ( !mCapabilities )
{
return;
}
//check network error
const QString& networkError = mCapabilities->networkError();
if ( !networkError.isEmpty() )
{
QMessageBox::critical( this, tr( "Network error" ), networkError );
}
//check xml error
const QString& xmlError = mCapabilities->xmlError();
if ( !xmlError.isEmpty() )
{
}
const QStringList* observablePropertyList = mCapabilities->observableProperties();
if ( observablePropertyList )
{
QStringList::const_iterator pIt = observablePropertyList->constBegin();
for ( ; pIt != observablePropertyList->constEnd(); ++pIt )
{
mOfferingsModel.appendRow( new QStandardItem( *pIt ) );
}
}
}
void QgsSOSSourceSelect::addLayer()
{
QgsOwsConnection connection( "SOS", mConnectionsComboBox->currentText() );
QString urlString = connection.uri().param( "url" );
if( !urlString.endsWith( "?" ) && !urlString.endsWith( "&" ) )
{
urlString.append( urlString.contains( "?" ) ? "&" : "?" );
}
QString getFeatureOfInterestUrl = urlString + "SERVICE=SOS&request=GetFeatureOfInterest&Version=2.0.0";
QString observedPropertiesString;
QModelIndexList selectedIndexList = mOfferingsView->selectionModel()->selectedRows();
for ( int i = 0; i < selectedIndexList.size(); ++i )
{
if ( i > 0 )
{
observedPropertiesString.append( "," );
}
QStandardItem* item = mOfferingsModel.itemFromIndex( mFilterModel.mapToSource( selectedIndexList.at( i ) ) );
if( item )
{
observedPropertiesString.append( item->text() );
}
}
if ( !selectedIndexList.isEmpty() )
{
getFeatureOfInterestUrl += ( QString( "&observedProperty=" ) + QString( QUrl::toPercentEncoding( observedPropertiesString.toLocal8Bit() ) ) );
}
QString sosLayerName = observedPropertiesString.split( "/" ).last();
if ( mIface )
{
mIface->addVectorLayer( getFeatureOfInterestUrl, sosLayerName, "SOS" );
}
return;
}