Skip to content

Commit b6193db

Browse files
committedMay 1, 2012
OWS meta provider; represents all OWS services under single connection in browser
1 parent ff8b451 commit b6193db

12 files changed

+572
-42
lines changed
 

‎src/core/qgsdataitem.cpp

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,16 @@ const QIcon &QgsFavouritesItem::iconFavourites()
134134
}
135135

136136
QgsDataItem::QgsDataItem( QgsDataItem::Type type, QgsDataItem* parent, QString name, QString path )
137-
: QObject( parent ), mType( type ), mParent( parent ), mPopulated( false ), mName( name ), mPath( path )
137+
// Do not pass parent to QObject, Qt would delete this when parent is deleted
138+
: QObject(), mType( type ), mParent( parent ), mPopulated( false ), mName( name ), mPath( path )
138139
{
139140
}
140141

142+
QgsDataItem::~QgsDataItem()
143+
{
144+
QgsDebugMsg( "mName = " + mName + " mPath = " + mPath);
145+
}
146+
141147
// TODO: This is copy from QgisApp, bad
142148
// TODO: add some caching mechanism ?
143149
QPixmap QgsDataItem::getThemePixmap( const QString theName )
@@ -215,6 +221,7 @@ bool QgsDataItem::hasChildren()
215221
void QgsDataItem::addChildItem( QgsDataItem * child, bool refresh )
216222
{
217223
QgsDebugMsg( QString( "add child #%1 - %2" ).arg( mChildren.size() ).arg( child->mName ) );
224+
QgsDebugMsg( QString("child = 0x%0").arg((qlonglong)child,8,16,QLatin1Char('0')) );
218225

219226
int i;
220227
if ( type() == Directory )
@@ -264,6 +271,26 @@ void QgsDataItem::deleteChildItem( QgsDataItem * child )
264271
emit endRemoveItems();
265272
}
266273

274+
QgsDataItem * QgsDataItem::removeChildItem( QgsDataItem * child )
275+
{
276+
QgsDebugMsg( "mName = " + child->mName );
277+
int i = mChildren.indexOf( child );
278+
Q_ASSERT( i >= 0 );
279+
emit beginRemoveItems( this, i, i );
280+
mChildren.remove( i );
281+
emit endRemoveItems();
282+
disconnect( child, SIGNAL( beginInsertItems( QgsDataItem*, int, int ) ),
283+
this, SLOT( emitBeginInsertItems( QgsDataItem*, int, int ) ) );
284+
disconnect( child, SIGNAL( endInsertItems() ),
285+
this, SLOT( emitEndInsertItems() ) );
286+
disconnect( child, SIGNAL( beginRemoveItems( QgsDataItem*, int, int ) ),
287+
this, SLOT( emitBeginRemoveItems( QgsDataItem*, int, int ) ) );
288+
disconnect( child, SIGNAL( endRemoveItems() ),
289+
this, SLOT( emitEndRemoveItems() ) );
290+
child->setParent(0);
291+
return child;
292+
}
293+
267294
int QgsDataItem::findItem( QVector<QgsDataItem*> items, QgsDataItem * item )
268295
{
269296
for ( int i = 0; i < items.size(); i++ )
@@ -368,8 +395,12 @@ QgsDataCollectionItem::QgsDataCollectionItem( QgsDataItem* parent, QString name,
368395

369396
QgsDataCollectionItem::~QgsDataCollectionItem()
370397
{
398+
QgsDebugMsg( "Entered");
371399
foreach( QgsDataItem* i, mChildren )
372-
delete i;
400+
{
401+
QgsDebugMsg( QString("delete child = 0x%0").arg((qlonglong)i,8,16,QLatin1Char('0')) );
402+
delete i;
403+
}
373404
}
374405

375406
//-----------------------------------------------------------------------

‎src/core/qgsdataitem.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class CORE_EXPORT QgsDataItem : public QObject
5252
};
5353

5454
QgsDataItem( QgsDataItem::Type type, QgsDataItem* parent, QString name, QString path );
55-
virtual ~QgsDataItem() {}
55+
virtual ~QgsDataItem();
5656

5757
bool hasChildren();
5858

@@ -75,6 +75,10 @@ class CORE_EXPORT QgsDataItem : public QObject
7575
// remove and delete child item, signals to browser are emited
7676
virtual void deleteChildItem( QgsDataItem * child );
7777

78+
// remove child item but don't delete it, signals to browser are emited
79+
// returns pointer to the removed item or null if no such item was found
80+
virtual QgsDataItem * removeChildItem( QgsDataItem * child );
81+
7882
virtual bool equal( const QgsDataItem *other );
7983

8084
virtual QWidget * paramWidget() { return 0; }
@@ -113,6 +117,7 @@ class CORE_EXPORT QgsDataItem : public QObject
113117

114118
Type type() const { return mType; }
115119
QgsDataItem* parent() const { return mParent; }
120+
void setParent( QgsDataItem* parent ) { mParent = parent; }
116121
QVector<QgsDataItem*> children() const { return mChildren; }
117122
QIcon icon() const { return mIcon; }
118123
QString name() const { return mName; }

‎src/providers/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ ADD_SUBDIRECTORY(osm)
1010
ADD_SUBDIRECTORY(sqlanywhere)
1111
ADD_SUBDIRECTORY(gdal)
1212
ADD_SUBDIRECTORY(mssql)
13+
ADD_SUBDIRECTORY(ows)
1314

1415
IF (POSTGRES_FOUND)
1516
ADD_SUBDIRECTORY(postgres)

‎src/providers/gdal/qgsgdaldataitems.cpp

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,28 +60,31 @@ bool QgsGdalLayerItem::setCrs( QgsCoordinateReferenceSystem crs )
6060
QgsWCSConnectionItem::QgsWCSConnectionItem( QgsDataItem* parent, QString name, QString path )
6161
: QgsDataCollectionItem( parent, name, path )
6262
{
63-
mIcon = QIcon( getThemePixmap( "mIconConnect.png" ) );
63+
mIcon = QIcon( getThemePixmap( "mIconWcs.png" ) );
6464
}
6565

6666
QgsWCSConnectionItem::~QgsWCSConnectionItem()
6767
{
68+
QgsDebugMsg( "Entered");
6869
}
6970

7071
QVector<QgsDataItem*> QgsWCSConnectionItem::createChildren()
7172
{
7273
QgsDebugMsg( "Entered" );
7374
QVector<QgsDataItem*> children;
7475

75-
QgsOWSConnection connection( "WCS", mName );
76+
QString encodedUri = mPath;
77+
QgsDataSourceURI uri;
78+
uri.setEncodedUri ( encodedUri );
79+
QgsDebugMsg( "encodedUri = " + encodedUri );
7680

77-
QgsDataSourceURI uri = connection.uri();
78-
QgsDebugMsg( "uri = " + uri.encodedUri() );
7981
mCapabilities.setUri( uri );
8082

8183
// Attention: supportedLayers() gives tree leafes, not top level
8284
if ( !mCapabilities.lastError().isEmpty() )
8385
{
84-
children.append( new QgsErrorItem( this, tr( "Failed to retrieve layers" ), mPath + "/error" ) );
86+
//children.append( new QgsErrorItem( this, tr( "Failed to retrieve layers" ), mPath + "/error" ) );
87+
// TODO: show the error without adding child
8588
return children;
8689
}
8790

@@ -105,9 +108,12 @@ bool QgsWCSConnectionItem::equal( const QgsDataItem *other )
105108
return false;
106109
}
107110
const QgsWCSConnectionItem *o = dynamic_cast<const QgsWCSConnectionItem *>( other );
108-
//TODO
109-
//return ( mPath == o->mPath && mName == o->mName && mConnInfo == o->mConnInfo );
110-
return false;
111+
if ( !o )
112+
{
113+
return false;
114+
}
115+
116+
return ( mPath == o->mPath && mName == o->mName );
111117
}
112118

113119
QList<QAction*> QgsWCSConnectionItem::actions()
@@ -166,7 +172,8 @@ QgsWCSLayerItem::QgsWCSLayerItem( QgsDataItem* parent, QString name, QString pat
166172

167173
if ( mChildren.size() == 0 )
168174
{
169-
mIcon = iconRaster();
175+
//mIcon = iconRaster();
176+
mIcon = QIcon( getThemePixmap( "mIconWcs.png" ) );
170177
}
171178
mPopulated = true;
172179
}
@@ -246,7 +253,11 @@ QVector<QgsDataItem*>QgsWCSRootItem::createChildren()
246253
QVector<QgsDataItem*> connections;
247254
foreach( QString connName, QgsOWSConnection::connectionList( "WCS" ) )
248255
{
249-
QgsDataItem * conn = new QgsWCSConnectionItem( this, connName, mPath + "/" + connName );
256+
//QgsDataItem * conn = new QgsWCSConnectionItem( this, connName, mPath + "/" + connName );
257+
QgsOWSConnection connection( "WCS", connName );
258+
QgsDataItem * conn = new QgsWCSConnectionItem( this, connName, connection.uri().encodedUri() );
259+
260+
conn->setIcon ( QIcon( getThemePixmap( "mIconConnect.png" ) ) );
250261
connections.append( conn );
251262
}
252263
return connections;
@@ -294,17 +305,25 @@ static QStringList wildcards = QStringList();
294305

295306
QGISEXTERN int dataCapabilities()
296307
{
297-
return QgsDataProvider::File | QgsDataProvider::Dir;
308+
return QgsDataProvider::File | QgsDataProvider::Dir | QgsDataProvider::Net;
298309
}
299310

300311
QGISEXTERN QgsDataItem * dataItem( QString thePath, QgsDataItem* parentItem )
301312
{
313+
QgsDebugMsg( "thePath = " + thePath );
302314
if ( thePath.isEmpty() )
303315
{
304316
// Top level WCS
305317
return new QgsWCSRootItem( parentItem, "WCS", "wcs:" );
306318
}
307319

320+
if ( thePath.contains ( "url=" ) )
321+
{
322+
// OWS server
323+
QgsDebugMsg( "connection found in uri" );
324+
return new QgsWCSConnectionItem( parentItem, "WCS", thePath );
325+
}
326+
308327
QFileInfo info( thePath );
309328
if ( info.isFile() )
310329
{

‎src/providers/gdal/qgsgdaldataitems.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ class QgsWCSConnectionItem : public QgsDataCollectionItem
3030
virtual QList<QAction*> actions();
3131

3232
QgsWcsCapabilities mCapabilities;
33-
//QgsDataSourceURI mUri;
34-
//QgsOWSConnection mConnection;
3533
QVector<QgsWcsCoverageSummary> mLayerProperties;
3634

3735
public slots:

‎src/providers/ows/CMakeLists.txt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
SET(OWS_SRCS
2+
qgsowsprovider.cpp
3+
qgsowsdataitems.cpp
4+
)
5+
SET(OWS_MOC_HDRS
6+
qgsowsprovider.h
7+
qgsowsdataitems.h
8+
)
9+
10+
INCLUDE_DIRECTORIES (
11+
../../core
12+
../../gui
13+
${CMAKE_CURRENT_BINARY_DIR}/../../ui
14+
)
15+
16+
QT4_WRAP_CPP(OWS_MOC_SRCS ${OWS_MOC_HDRS})
17+
ADD_LIBRARY (owsprovider MODULE ${OWS_SRCS} ${OWS_MOC_SRCS})
18+
19+
TARGET_LINK_LIBRARIES (owsprovider
20+
qgis_core
21+
qgis_gui
22+
)
23+
24+
INSTALL(TARGETS owsprovider
25+
RUNTIME DESTINATION ${QGIS_PLUGIN_DIR}
26+
LIBRARY DESTINATION ${QGIS_PLUGIN_DIR})

‎src/providers/ows/qgsowsdataitems.cpp

Lines changed: 239 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,239 @@
1+
#include "qgsproviderregistry.h"
2+
#include "qgsowsdataitems.h"
3+
#include "qgsowsprovider.h"
4+
#include "qgslogger.h"
5+
#include "qgsdatasourceuri.h"
6+
//#include "qgsowssourceselect.h"
7+
#include "qgsowsconnection.h"
8+
#include "qgsnewhttpconnection.h"
9+
10+
#include <QFileInfo>
11+
12+
// ---------------------------------------------------------------------------
13+
QgsOWSConnectionItem::QgsOWSConnectionItem( QgsDataItem* parent, QString name, QString path )
14+
: QgsDataCollectionItem( parent, name, path )
15+
{
16+
mIcon = QIcon( getThemePixmap( "mIconConnect.png" ) );
17+
}
18+
19+
QgsOWSConnectionItem::~QgsOWSConnectionItem()
20+
{
21+
}
22+
23+
QVector<QgsDataItem*> QgsOWSConnectionItem::createChildren()
24+
{
25+
QgsDebugMsg( "Entered" );
26+
QVector<QgsDataItem*> children;
27+
28+
QVector<QgsDataItem*> serviceItems;
29+
30+
int layerCount;
31+
// Try to open with WMS,WFS,WCS
32+
foreach( QString key, QStringList() << "wms" << "WFS" << "gdal" )
33+
{
34+
QgsDebugMsg( "Add connection for provider " + key );
35+
QLibrary *library = QgsProviderRegistry::instance()->providerLibrary( key );
36+
if ( !library ) continue;
37+
38+
dataItem_t * dItem = ( dataItem_t * ) cast_to_fptr( library->resolve( "dataItem" ) );
39+
if ( !dItem )
40+
{
41+
QgsDebugMsg( library->fileName() + " does not have dataItem" );
42+
continue;
43+
}
44+
45+
QgsDataItem *item = dItem( mPath, this ); // empty path -> top level
46+
if ( !item ) continue;
47+
48+
layerCount += item->rowCount();
49+
if ( item->rowCount() > 0 )
50+
{
51+
QgsDebugMsg( "Add new item : " + item->name() );
52+
serviceItems.append( item );
53+
}
54+
else
55+
{
56+
//delete item;
57+
}
58+
}
59+
60+
foreach( QgsDataItem* item, serviceItems )
61+
{
62+
QgsDebugMsg( QString("serviceItems.size = %1 layerCount = %2 rowCount = %3").arg(serviceItems.size()).arg(layerCount).arg(item->rowCount() ) );
63+
if ( serviceItems.size() == 1 || layerCount <= 30 || item->rowCount() <= 10 )
64+
{
65+
// Add layers directly to OWS connection
66+
foreach( QgsDataItem* subItem, item->children() )
67+
{
68+
item->removeChildItem ( subItem );
69+
subItem->setParent ( this );
70+
children.append( subItem );
71+
}
72+
delete item;
73+
}
74+
else // Add service
75+
{
76+
children.append( item );
77+
}
78+
}
79+
80+
return children;
81+
}
82+
83+
bool QgsOWSConnectionItem::equal( const QgsDataItem *other )
84+
{
85+
if ( type() != other->type() )
86+
{
87+
return false;
88+
}
89+
const QgsOWSConnectionItem *o = dynamic_cast<const QgsOWSConnectionItem *>( other );
90+
return ( mPath == o->mPath && mName == o->mName );
91+
}
92+
93+
QList<QAction*> QgsOWSConnectionItem::actions()
94+
{
95+
QList<QAction*> lst;
96+
97+
QAction* actionEdit = new QAction( tr( "Edit..." ), this );
98+
connect( actionEdit, SIGNAL( triggered() ), this, SLOT( editConnection() ) );
99+
lst.append( actionEdit );
100+
101+
QAction* actionDelete = new QAction( tr( "Delete" ), this );
102+
connect( actionDelete, SIGNAL( triggered() ), this, SLOT( deleteConnection() ) );
103+
lst.append( actionDelete );
104+
105+
return lst;
106+
}
107+
108+
void QgsOWSConnectionItem::editConnection()
109+
{
110+
/*
111+
QgsNewHttpConnection nc( 0, "/Qgis/connections-ows/", mName );
112+
113+
if ( nc.exec() )
114+
{
115+
// the parent should be updated
116+
mParent->refresh();
117+
}
118+
*/
119+
}
120+
121+
void QgsOWSConnectionItem::deleteConnection()
122+
{
123+
/*
124+
QgsOWSConnection::deleteConnection( "OWS", mName );
125+
// the parent should be updated
126+
mParent->refresh();
127+
*/
128+
}
129+
130+
131+
// ---------------------------------------------------------------------------
132+
133+
134+
QgsOWSRootItem::QgsOWSRootItem( QgsDataItem* parent, QString name, QString path )
135+
: QgsDataCollectionItem( parent, name, path )
136+
{
137+
mIcon = QIcon( getThemePixmap( "mIconOws.png" ) );
138+
139+
populate();
140+
}
141+
142+
QgsOWSRootItem::~QgsOWSRootItem()
143+
{
144+
}
145+
146+
QVector<QgsDataItem*>QgsOWSRootItem::createChildren()
147+
{
148+
QgsDebugMsg( "Entered" );
149+
QVector<QgsDataItem*> connections;
150+
// Combine all WMS,WFS,WCS connections
151+
QMap<QString, QStringList> uris;
152+
foreach( QString service, QStringList() << "WMS" << "WFS" << "WCS" )
153+
{
154+
foreach( QString connName, QgsOWSConnection::connectionList( service ) )
155+
{
156+
QgsOWSConnection connection( service, connName );
157+
158+
QString encodedUri = connection.uri().encodedUri();
159+
QStringList labels = uris.value ( encodedUri );
160+
if ( !labels.contains ( connName ) )
161+
{
162+
labels << connName;
163+
}
164+
uris[encodedUri] = labels;
165+
}
166+
}
167+
foreach( QString encodedUri, uris.keys() )
168+
{
169+
QgsDataItem * conn = new QgsOWSConnectionItem( this, uris.value(encodedUri).join(" / "), encodedUri );
170+
connections.append( conn );
171+
}
172+
return connections;
173+
}
174+
175+
QList<QAction*> QgsOWSRootItem::actions()
176+
{
177+
QList<QAction*> lst;
178+
179+
/*
180+
QAction* actionNew = new QAction( tr( "New Connection..." ), this );
181+
connect( actionNew, SIGNAL( triggered() ), this, SLOT( newConnection() ) );
182+
lst.append( actionNew );
183+
*/
184+
return lst;
185+
}
186+
187+
188+
QWidget * QgsOWSRootItem::paramWidget()
189+
{
190+
/*
191+
QgsOWSSourceSelect *select = new QgsOWSSourceSelect( 0, 0, true, true );
192+
connect( select, SIGNAL( connectionsChanged() ), this, SLOT( connectionsChanged() ) );
193+
return select;
194+
*/
195+
return 0;
196+
}
197+
void QgsOWSRootItem::connectionsChanged()
198+
{
199+
refresh();
200+
}
201+
202+
void QgsOWSRootItem::newConnection()
203+
{
204+
/*
205+
QgsNewHttpConnection nc( 0, "/Qgis/connections-ows/" );
206+
207+
if ( nc.exec() )
208+
{
209+
refresh();
210+
}
211+
*/
212+
}
213+
214+
215+
// ---------------------------------------------------------------------------
216+
217+
static QStringList extensions = QStringList();
218+
static QStringList wildcards = QStringList();
219+
220+
QGISEXTERN int dataCapabilities()
221+
{
222+
return QgsDataProvider::Net;
223+
}
224+
225+
QGISEXTERN QgsDataItem * dataItem( QString thePath, QgsDataItem* parentItem )
226+
{
227+
if ( thePath.isEmpty() )
228+
{
229+
return new QgsOWSRootItem( parentItem, "OWS", "ows:" );
230+
}
231+
232+
}
233+
234+
//QGISEXTERN QgsOWSSourceSelect * selectWidget( QWidget * parent, Qt::WFlags fl )
235+
QGISEXTERN QDialog * selectWidget( QWidget * parent, Qt::WFlags fl )
236+
{
237+
//return new QgsOWSSourceSelect( parent, fl );
238+
return 0;
239+
}

‎src/providers/ows/qgsowsdataitems.h

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#ifndef QGSOWSDATAITEMS_H
2+
#define QGSOWSDATAITEMS_H
3+
4+
#include "qgsdataitem.h"
5+
#include "qgsdatasourceuri.h"
6+
class QgsOWSConnectionItem : public QgsDataCollectionItem
7+
{
8+
Q_OBJECT
9+
public:
10+
QgsOWSConnectionItem( QgsDataItem* parent, QString name, QString path );
11+
~QgsOWSConnectionItem();
12+
13+
QVector<QgsDataItem*> createChildren();
14+
virtual bool equal( const QgsDataItem *other );
15+
16+
virtual QList<QAction*> actions();
17+
18+
public slots:
19+
void editConnection();
20+
void deleteConnection();
21+
};
22+
23+
class QgsOWSRootItem : public QgsDataCollectionItem
24+
{
25+
Q_OBJECT
26+
public:
27+
QgsOWSRootItem( QgsDataItem* parent, QString name, QString path );
28+
~QgsOWSRootItem();
29+
30+
QVector<QgsDataItem*> createChildren();
31+
32+
virtual QList<QAction*> actions();
33+
34+
virtual QWidget * paramWidget();
35+
36+
public slots:
37+
void connectionsChanged();
38+
39+
void newConnection();
40+
};
41+
42+
#endif // QGSOWSDATAITEMS_H

‎src/providers/ows/qgsowsprovider.cpp

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/***************************************************************************
2+
qgsowsprovider.cpp - OWS meta provider for WMS,WFS,WCS in browser
3+
-------------------
4+
begin : 4/2012
5+
copyright : (C) 2010 by Radim Blazek
6+
email : radim dot blazek at gmail dot com
7+
***************************************************************************/
8+
9+
/***************************************************************************
10+
* *
11+
* This program is free software; you can redistribute it and/or modify *
12+
* it under the terms of the GNU General Public License as published by *
13+
* the Free Software Foundation; either version 2 of the License, or *
14+
* (at your option) any later version. *
15+
* *
16+
***************************************************************************/
17+
18+
#include "qgslogger.h"
19+
#include "qgsowsprovider.h"
20+
#include "qgsconfig.h"
21+
22+
#include <QString>
23+
24+
static QString PROVIDER_KEY = "ows";
25+
static QString PROVIDER_DESCRIPTION = "OWS meta provider";
26+
27+
QgsOwsProvider::QgsOwsProvider( QString const & uri )
28+
: QgsDataProvider( uri )
29+
{
30+
}
31+
32+
QgsOwsProvider::~QgsOwsProvider()
33+
{
34+
}
35+
36+
QGISEXTERN QgsOwsProvider * classFactory( const QString *uri )
37+
{
38+
return new QgsOwsProvider( *uri );
39+
}
40+
41+
QString QgsOwsProvider::name() const
42+
{
43+
return PROVIDER_KEY;
44+
}
45+
46+
QString QgsOwsProvider::description() const
47+
{
48+
return PROVIDER_DESCRIPTION;
49+
}
50+
51+
QGISEXTERN QString providerKey()
52+
{
53+
return PROVIDER_KEY;
54+
}
55+
56+
QGISEXTERN QString description()
57+
{
58+
return PROVIDER_DESCRIPTION;
59+
}
60+
61+
QGISEXTERN bool isProvider()
62+
{
63+
return true;
64+
}
65+

‎src/providers/ows/qgsowsprovider.h

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/***************************************************************************
2+
qgsowsprovider.h - OWS meta provider for WMS,WFS,WCS in browser
3+
-------------------
4+
begin : 4/2012
5+
copyright : (C) 2012 by Radim Blazek
6+
email : radim dot blazek at gmail dot com
7+
***************************************************************************/
8+
9+
/***************************************************************************
10+
* *
11+
* This program is free software; you can redistribute it and/or modify *
12+
* it under the terms of the GNU General Public License as published by *
13+
* the Free Software Foundation; either version 2 of the License, or *
14+
* (at your option) any later version. *
15+
* *
16+
***************************************************************************/
17+
18+
#ifndef QGSOWSPROVIDER_H
19+
#define QGSOWSPROVIDER_H
20+
21+
#include "qgsdataprovider.h"
22+
#include "qgscoordinatereferencesystem.h"
23+
#include "qgsdataitem.h"
24+
#include "qgsrectangle.h"
25+
26+
#include <QString>
27+
28+
/**
29+
30+
\brief Data provider for GDAL layers.
31+
32+
This provider implements the interface defined in the QgsDataProvider class
33+
to provide access to spatial data residing in a GDAL layers.
34+
35+
*/
36+
class QgsOwsProvider : public QgsDataProvider
37+
{
38+
Q_OBJECT
39+
40+
public:
41+
/**
42+
* Constructor for the provider.
43+
*
44+
* \param uri HTTP URL of the Web Server. If needed a proxy will be used
45+
* otherwise we contact the host directly.
46+
*
47+
*/
48+
QgsOwsProvider( QString const & uri = 0 );
49+
50+
//! Destructor
51+
~QgsOwsProvider();
52+
53+
/* Pure virtuals */
54+
55+
QString name() const;
56+
57+
QString description() const;
58+
59+
QgsCoordinateReferenceSystem crs() { return QgsCoordinateReferenceSystem(); }
60+
61+
QgsRectangle extent() { return QgsRectangle(); }
62+
63+
bool isValid() { return false; }
64+
};
65+
66+
#endif // QGSOWSPROVIDER_H

‎src/providers/wfs/qgswfsdataitems.cpp

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
#include "qgswfsdataitems.h"
2-
3-
#include "qgswfsprovider.h"
1+
#include "qgslogger.h"
2+
#include "qgsnewhttpconnection.h"
43
#include "qgsowsconnection.h"
54
#include "qgswfscapabilities.h"
5+
#include "qgswfsdataitems.h"
6+
#include "qgswfsprovider.h"
67
#include "qgswfssourceselect.h"
78

8-
#include "qgsnewhttpconnection.h"
9-
109
#include <QSettings>
1110
#include <QCoreApplication>
1211

@@ -16,6 +15,8 @@ QgsWFSLayerItem::QgsWFSLayerItem( QgsDataItem* parent, QString name, QgsDataSour
1615
{
1716
mUri = QgsWFSCapabilities( uri.encodedUri() ).uriGetFeature( featureType );
1817
mPopulated = true;
18+
//mIcon = QIcon( getThemePixmap( "mIconVectorLayer.png" ) );
19+
mIcon = QIcon( getThemePixmap( "mIconWfs.png" ) );
1920
}
2021

2122
QgsWFSLayerItem::~QgsWFSLayerItem()
@@ -27,7 +28,7 @@ QgsWFSLayerItem::~QgsWFSLayerItem()
2728
QgsWFSConnectionItem::QgsWFSConnectionItem( QgsDataItem* parent, QString name, QString path )
2829
: QgsDataCollectionItem( parent, name, path ), mName( name ), mCapabilities( NULL )
2930
{
30-
mIcon = QIcon( getThemePixmap( "mIconConnect.png" ) );
31+
mIcon = QIcon( getThemePixmap( "mIconWfs.png" ) );
3132
}
3233

3334
QgsWFSConnectionItem::~QgsWFSConnectionItem()
@@ -38,9 +39,10 @@ QVector<QgsDataItem*> QgsWFSConnectionItem::createChildren()
3839
{
3940
mGotCapabilities = false;
4041

41-
QgsOWSConnection connection( "WFS", mName );
42-
QgsDataSourceURI uri = connection.uri();
43-
QString encodedUri = uri.encodedUri();
42+
QString encodedUri = mPath;
43+
QgsDataSourceURI uri;
44+
uri.setEncodedUri ( encodedUri );
45+
QgsDebugMsg( "encodedUri = " + encodedUri );
4446

4547
mCapabilities = new QgsWFSCapabilities( encodedUri );
4648
connect( mCapabilities, SIGNAL( gotCapabilities() ), this, SLOT( gotCapabilities() ) );
@@ -65,7 +67,8 @@ QVector<QgsDataItem*> QgsWFSConnectionItem::createChildren()
6567
}
6668
else
6769
{
68-
layers.append( new QgsErrorItem( this, tr( "Failed to retrieve layers" ), mPath + "/error" ) );
70+
//layers.append( new QgsErrorItem( this, tr( "Failed to retrieve layers" ), mPath + "/error" ) );
71+
// TODO: show the error without adding child
6972
}
7073

7174
mCapabilities->deleteLater();
@@ -136,7 +139,9 @@ QVector<QgsDataItem*> QgsWFSRootItem::createChildren()
136139

137140
foreach( QString connName, QgsOWSConnection::connectionList( "WFS" ) )
138141
{
139-
QgsDataItem * conn = new QgsWFSConnectionItem( this, connName, mPath + "/" + connName );
142+
QgsOWSConnection connection( "WF", connName );
143+
QgsDataItem * conn = new QgsWFSConnectionItem( this, connName, connection.uri().encodedUri() );
144+
conn->setIcon ( QIcon( getThemePixmap( "mIconConnect.png" ) ) );
140145
connections.append( conn );
141146
}
142147
return connections;
@@ -190,8 +195,12 @@ QGISEXTERN int dataCapabilities()
190195

191196
QGISEXTERN QgsDataItem * dataItem( QString thePath, QgsDataItem* parentItem )
192197
{
193-
Q_UNUSED( thePath );
198+
QgsDebugMsg( "thePath = " + thePath );
199+
if ( thePath.isEmpty() )
200+
{
201+
return new QgsWFSRootItem( parentItem, "WFS", "wfs:" );
202+
}
194203

195-
return new QgsWFSRootItem( parentItem, "WFS", "wfs:" );
204+
return new QgsWFSConnectionItem( parentItem, "WFS", thePath );
196205
}
197206

‎src/providers/wms/qgswmsdataitems.cpp

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
QgsWMSConnectionItem::QgsWMSConnectionItem( QgsDataItem* parent, QString name, QString path )
1313
: QgsDataCollectionItem( parent, name, path )
1414
{
15-
mIcon = QIcon( getThemePixmap( "mIconConnect.png" ) );
15+
mIcon = QIcon( getThemePixmap( "mIconWms.png" ) );
1616
}
1717

1818
QgsWMSConnectionItem::~QgsWMSConnectionItem()
@@ -23,18 +23,33 @@ QVector<QgsDataItem*> QgsWMSConnectionItem::createChildren()
2323
{
2424
QgsDebugMsg( "Entered" );
2525
QVector<QgsDataItem*> children;
26-
QgsWMSConnection connection( mName );
27-
QgsWmsProvider *wmsProvider = connection.provider( );
28-
if ( !wmsProvider )
29-
return children;
3026

31-
QgsDataSourceURI uri = connection.uri();
32-
QgsDebugMsg( "uri = " + uri.encodedUri() );
27+
QString encodedUri = mPath;
28+
QgsDataSourceURI uri;
29+
uri.setEncodedUri ( encodedUri );
30+
/*
31+
if ( mPath.contains ( "url=" ) )
32+
{
33+
encodedUri = mPath;
34+
uri.setEncodedUri ( encodedUri );
35+
}
36+
else
37+
{
38+
QgsWMSConnection connection( mName );
39+
uri = connection.uri();
40+
encodedUri = uri.encodedUri();
41+
}
42+
*/
43+
QgsDebugMsg( "encodedUri = " + encodedUri );
44+
45+
QgsWmsProvider *wmsProvider = new QgsWmsProvider ( encodedUri );
46+
if ( !wmsProvider ) return children;
3347

3448
// Attention: supportedLayers() gives tree leafes, not top level
3549
if ( !wmsProvider->supportedLayers( mLayerProperties ) )
3650
{
37-
children.append( new QgsErrorItem( this, tr( "Failed to retrieve layers" ), mPath + "/error" ) );
51+
//children.append( new QgsErrorItem( this, tr( "Failed to retrieve layers" ), mPath + "/error" ) );
52+
// TODO: show the error without adding child
3853
return children;
3954
}
4055

@@ -65,7 +80,12 @@ bool QgsWMSConnectionItem::equal( const QgsDataItem *other )
6580
return false;
6681
}
6782
const QgsWMSConnectionItem *o = dynamic_cast<const QgsWMSConnectionItem *>( other );
68-
return ( mPath == o->mPath && mName == o->mName && mConnInfo == o->mConnInfo );
83+
if ( !o )
84+
{
85+
return false;
86+
}
87+
88+
return ( mPath == o->mPath && mName == o->mName );
6989
}
7090

7191
QList<QAction*> QgsWMSConnectionItem::actions()
@@ -126,7 +146,8 @@ QgsWMSLayerItem::QgsWMSLayerItem( QgsDataItem* parent, QString name, QString pat
126146

127147
if ( mChildren.size() == 0 )
128148
{
129-
mIcon = iconRaster();
149+
//mIcon = iconRaster();
150+
mIcon = QIcon( getThemePixmap( "mIconWms.png" ) );
130151
}
131152
mPopulated = true;
132153
}
@@ -199,7 +220,11 @@ QVector<QgsDataItem*>QgsWMSRootItem::createChildren()
199220

200221
foreach( QString connName, QgsWMSConnection::connectionList() )
201222
{
202-
QgsDataItem * conn = new QgsWMSConnectionItem( this, connName, mPath + "/" + connName );
223+
//QgsDataItem * conn = new QgsWMSConnectionItem( this, connName, mPath + "/" + connName );
224+
QgsWMSConnection connection( connName );
225+
QgsDataItem * conn = new QgsWMSConnectionItem( this, connName, connection.uri().encodedUri() );
226+
227+
conn->setIcon ( QIcon( getThemePixmap( "mIconConnect.png" ) ) );
203228
connections.append( conn );
204229
}
205230
return connections;
@@ -253,7 +278,11 @@ QGISEXTERN int dataCapabilities()
253278

254279
QGISEXTERN QgsDataItem * dataItem( QString thePath, QgsDataItem* parentItem )
255280
{
256-
Q_UNUSED( thePath );
281+
if ( thePath.isEmpty() )
282+
{
283+
return new QgsWMSRootItem( parentItem, "WMS", "wms:" );
284+
}
257285

258-
return new QgsWMSRootItem( parentItem, "WMS", "wms:" );
286+
// The path should contain encoded connection URI
287+
return new QgsWMSConnectionItem( parentItem, "WMS", thePath );
259288
}

0 commit comments

Comments
 (0)
Please sign in to comment.