Skip to content

Commit b6193db

Browse files
committed
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

+33-2
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

+6-1
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

+1
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

+30-11
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

-2
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

+26
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})

0 commit comments

Comments
 (0)