1515#include " qgsgdaldataitems.h"
1616#include " qgsgdalprovider.h"
1717#include " qgslogger.h"
18- #include " qgsdatasourceuri.h"
19- #include " qgswcssourceselect.h"
20- #include " qgsowsconnection.h"
21- #include " qgsnewhttpconnection.h"
2218
2319#include < QFileInfo>
2420#include < QSettings>
@@ -128,259 +124,6 @@ QString QgsGdalLayerItem::layerName() const
128124 return info.completeBaseName ();
129125}
130126
131- // ---------------------------------------------------------------------------
132- QgsWCSConnectionItem::QgsWCSConnectionItem ( QgsDataItem* parent, QString name, QString path )
133- : QgsDataCollectionItem( parent, name, path )
134- {
135- mIcon = QIcon ( getThemePixmap ( " mIconWcs.png" ) );
136- }
137-
138- QgsWCSConnectionItem::~QgsWCSConnectionItem ()
139- {
140- QgsDebugMsg ( " Entered" );
141- }
142-
143- QVector<QgsDataItem*> QgsWCSConnectionItem::createChildren ()
144- {
145- QgsDebugMsg ( " Entered" );
146- QVector<QgsDataItem*> children;
147-
148- QString encodedUri = mPath ;
149- QgsDataSourceURI uri;
150- uri.setEncodedUri ( encodedUri );
151- QgsDebugMsg ( " encodedUri = " + encodedUri );
152-
153- mCapabilities .setUri ( uri );
154-
155- // Attention: supportedLayers() gives tree leafes, not top level
156- if ( !mCapabilities .lastError ().isEmpty () )
157- {
158- // children.append( new QgsErrorItem( this, tr( "Failed to retrieve layers" ), mPath + "/error" ) );
159- // TODO: show the error without adding child
160- return children;
161- }
162-
163- foreach ( QgsWcsCoverageSummary coverageSummary, mCapabilities .capabilities ().contents .coverageSummary )
164- {
165- // Attention, the name may be empty
166- QgsDebugMsg ( QString::number ( coverageSummary.orderId ) + " " + coverageSummary.identifier + " " + coverageSummary.title );
167- QString pathName = coverageSummary.identifier .isEmpty () ? QString::number ( coverageSummary.orderId ) : coverageSummary.identifier ;
168-
169- QgsWCSLayerItem * layer = new QgsWCSLayerItem ( this , coverageSummary.title , mPath + " /" + pathName, mCapabilities .capabilities (), uri, coverageSummary );
170-
171- children.append ( layer );
172- }
173- return children;
174- }
175-
176- bool QgsWCSConnectionItem::equal ( const QgsDataItem *other )
177- {
178- if ( type () != other->type () )
179- {
180- return false ;
181- }
182- const QgsWCSConnectionItem *o = dynamic_cast <const QgsWCSConnectionItem *>( other );
183- if ( !o )
184- {
185- return false ;
186- }
187-
188- return ( mPath == o->mPath && mName == o->mName );
189- }
190-
191- QList<QAction*> QgsWCSConnectionItem::actions ()
192- {
193- QList<QAction*> lst;
194-
195- QAction* actionEdit = new QAction ( tr ( " Edit..." ), this );
196- connect ( actionEdit, SIGNAL ( triggered () ), this , SLOT ( editConnection () ) );
197- lst.append ( actionEdit );
198-
199- QAction* actionDelete = new QAction ( tr ( " Delete" ), this );
200- connect ( actionDelete, SIGNAL ( triggered () ), this , SLOT ( deleteConnection () ) );
201- lst.append ( actionDelete );
202-
203- return lst;
204- }
205-
206- void QgsWCSConnectionItem::editConnection ()
207- {
208- QgsNewHttpConnection nc ( 0 , " /Qgis/connections-wcs/" , mName );
209-
210- if ( nc.exec () )
211- {
212- // the parent should be updated
213- mParent ->refresh ();
214- }
215- }
216-
217- void QgsWCSConnectionItem::deleteConnection ()
218- {
219- QgsOWSConnection::deleteConnection ( " WCS" , mName );
220- // the parent should be updated
221- mParent ->refresh ();
222- }
223-
224-
225- // ---------------------------------------------------------------------------
226-
227- QgsWCSLayerItem::QgsWCSLayerItem ( QgsDataItem* parent, QString name, QString path, QgsWcsCapabilitiesProperty capabilitiesProperty, QgsDataSourceURI dataSourceUri, QgsWcsCoverageSummary coverageSummary )
228- : QgsLayerItem( parent, name, path, QString(), QgsLayerItem::Raster, "gdal" ),
229- mCapabilities( capabilitiesProperty ),
230- mDataSourceUri( dataSourceUri ),
231- mCoverageSummary( coverageSummary )
232- {
233- QgsDebugMsg ( " uri = " + mDataSourceUri .encodedUri () );
234- mUri = createUri ();
235- // Populate everything, it costs nothing, all info about layers is collected
236- foreach ( QgsWcsCoverageSummary coverageSummary, mCoverageSummary .coverageSummary )
237- {
238- // Attention, the name may be empty
239- QgsDebugMsg ( QString::number ( coverageSummary.orderId ) + " " + coverageSummary.identifier + " " + coverageSummary.title );
240- QString pathName = coverageSummary.identifier .isEmpty () ? QString::number ( coverageSummary.orderId ) : coverageSummary.identifier ;
241- QgsWCSLayerItem * layer = new QgsWCSLayerItem ( this , coverageSummary.title , mPath + " /" + pathName, mCapabilities , mDataSourceUri , coverageSummary );
242- mChildren .append ( layer );
243- }
244-
245- if ( mChildren .size () == 0 )
246- {
247- // mIcon = iconRaster();
248- mIcon = QIcon ( getThemePixmap ( " mIconWcs.png" ) );
249- }
250- mPopulated = true ;
251- }
252-
253- QgsWCSLayerItem::~QgsWCSLayerItem ()
254- {
255- }
256-
257- QString QgsWCSLayerItem::createUri ()
258- {
259- if ( mCoverageSummary .identifier .isEmpty () )
260- return " " ; // layer collection
261-
262- // Number of styles must match number of layers
263- mDataSourceUri .setParam ( " identifier" , mCoverageSummary .identifier );
264-
265- // TODO(?): with WCS 1.0 GetCapabilities does not contain CRS and formats,
266- // to get them we would need to call QgsWcsCapabilities::describeCoverage
267- // but it is problematic to get QgsWcsCapabilities here (copy not allowed
268- // by QObject, pointer is dangerous (OWS provider is changing parent))
269- // We leave CRS and format default for now.
270-
271- QString format;
272- // get first supported by GDAL and server
273- QStringList mimes = QgsGdalProvider::supportedMimes ().keys ();
274- // prefer tiff
275- if ( mimes.contains ( " image/tiff" ) && mCoverageSummary .supportedFormat .contains ( " image/tiff" ) )
276- {
277- format = " image/tiff" ;
278- }
279- else
280- {
281- foreach ( QString f, mimes )
282- {
283- if ( mCoverageSummary .supportedFormat .indexOf ( f ) >= 0 )
284- {
285- format = f;
286- break ;
287- }
288- }
289- }
290- if ( !format.isEmpty () )
291- {
292- mDataSourceUri .setParam ( " format" , format );
293- }
294-
295- QString crs;
296-
297- // TODO: prefer project CRS
298- // get first known if possible
299- QgsCoordinateReferenceSystem testCrs;
300- foreach ( QString c, mCoverageSummary .supportedCrs )
301- {
302- testCrs.createFromOgcWmsCrs ( c );
303- if ( testCrs.isValid () )
304- {
305- crs = c;
306- break ;
307- }
308- }
309- if ( crs.isEmpty () && mCoverageSummary .supportedCrs .size () > 0 )
310- {
311- crs = mCoverageSummary .supportedCrs .value ( 0 );
312- }
313- if ( !crs.isEmpty () )
314- {
315- mDataSourceUri .setParam ( " crs" , crs );
316- }
317-
318- return mDataSourceUri .encodedUri ();
319- }
320-
321- // ---------------------------------------------------------------------------
322-
323- QgsWCSRootItem::QgsWCSRootItem ( QgsDataItem* parent, QString name, QString path )
324- : QgsDataCollectionItem( parent, name, path )
325- {
326- mIcon = QIcon ( getThemePixmap ( " mIconWcs.png" ) );
327-
328- populate ();
329- }
330-
331- QgsWCSRootItem::~QgsWCSRootItem ()
332- {
333- }
334-
335- QVector<QgsDataItem*>QgsWCSRootItem::createChildren ()
336- {
337- QVector<QgsDataItem*> connections;
338- foreach ( QString connName, QgsOWSConnection::connectionList ( " WCS" ) )
339- {
340- // QgsDataItem * conn = new QgsWCSConnectionItem( this, connName, mPath + "/" + connName );
341- QgsOWSConnection connection ( " WCS" , connName );
342- QgsDataItem * conn = new QgsWCSConnectionItem ( this , connName, connection.uri ().encodedUri () );
343-
344- conn->setIcon ( QIcon ( getThemePixmap ( " mIconConnect.png" ) ) );
345- connections.append ( conn );
346- }
347- return connections;
348- }
349-
350- QList<QAction*> QgsWCSRootItem::actions ()
351- {
352- QList<QAction*> lst;
353-
354- QAction* actionNew = new QAction ( tr ( " New Connection..." ), this );
355- connect ( actionNew, SIGNAL ( triggered () ), this , SLOT ( newConnection () ) );
356- lst.append ( actionNew );
357-
358- return lst;
359- }
360-
361-
362- QWidget * QgsWCSRootItem::paramWidget ()
363- {
364- QgsWCSSourceSelect *select = new QgsWCSSourceSelect ( 0 , 0 , true , true );
365- connect ( select, SIGNAL ( connectionsChanged () ), this , SLOT ( connectionsChanged () ) );
366- return select;
367- return 0 ;
368- }
369- void QgsWCSRootItem::connectionsChanged ()
370- {
371- refresh ();
372- }
373-
374- void QgsWCSRootItem::newConnection ()
375- {
376- QgsNewHttpConnection nc ( 0 , " /Qgis/connections-wcs/" );
377-
378- if ( nc.exec () )
379- {
380- refresh ();
381- }
382- }
383-
384127// ---------------------------------------------------------------------------
385128
386129static QString filterString;
@@ -395,18 +138,6 @@ QGISEXTERN int dataCapabilities()
395138QGISEXTERN QgsDataItem * dataItem ( QString thePath, QgsDataItem* parentItem )
396139{
397140 QgsDebugMsg ( " thePath = " + thePath );
398- if ( thePath.isEmpty () )
399- {
400- // Top level WCS
401- return new QgsWCSRootItem ( parentItem, " WCS" , " wcs:" );
402- }
403-
404- if ( thePath.contains ( " url=" ) )
405- {
406- // OWS server
407- QgsDebugMsg ( " connection found in uri" );
408- return new QgsWCSConnectionItem ( parentItem, " WCS" , thePath );
409- }
410141
411142 // zip settings + info
412143 QSettings settings;
@@ -534,7 +265,3 @@ QGISEXTERN QgsDataItem * dataItem( QString thePath, QgsDataItem* parentItem )
534265 return item;
535266}
536267
537- QGISEXTERN QgsWCSSourceSelect * selectWidget ( QWidget * parent, Qt::WFlags fl )
538- {
539- return new QgsWCSSourceSelect ( parent, fl );
540- }
0 commit comments