@@ -39,16 +39,19 @@ QVector<QgsDataItem*> QgsOWSConnectionItem::createChildren()
3939{
4040 QgsDebugMsg ( " Entered" );
4141 QVector<QgsDataItem*> children;
42- QVector <QgsDataItem*> serviceItems;
42+ QMap <QgsDataItem*, QString > serviceItems; // service/provider key
4343
4444 int layerCount = 0 ;
4545 // Try to open with WMS,WFS,WCS
46- foreach ( QString key, QStringList () << " wms" << " WFS" << " gdal " )
46+ foreach ( QString key, QStringList () << " wms" << " WFS" << " wcs " )
4747 {
4848 QgsDebugMsg ( " Add connection for provider " + key );
4949 QLibrary *library = QgsProviderRegistry::instance ()->providerLibrary ( key );
5050 if ( !library )
51+ {
52+ QgsDebugMsg ( " Cannot get provider " + key );
5153 continue ;
54+ }
5255
5356 dataItem_t * dItem = ( dataItem_t * ) cast_to_fptr ( library->resolve ( " dataItem" ) );
5457 if ( !dItem )
@@ -57,47 +60,65 @@ QVector<QgsDataItem*> QgsOWSConnectionItem::createChildren()
5760 continue ;
5861 }
5962
60- QgsDataItem *item = dItem ( mPath , this ); // empty path -> top level
63+ QString path = key.toLower () + " :/" + name ();
64+ QgsDebugMsg ( " path = " + path );
65+ QgsDataItem *item = dItem ( path, this ); // empty path -> top level
6166 if ( !item )
67+ {
68+ QgsDebugMsg ( " Connection not found by provider" );
6269 continue ;
70+ }
6371
6472 item->populate ();
6573
6674 layerCount += item->rowCount ();
6775 if ( item->rowCount () > 0 )
6876 {
6977 QgsDebugMsg ( " Add new item : " + item->name () );
70- serviceItems.append ( item );
78+ serviceItems.insert ( item, key );
7179 }
7280 else
7381 {
7482 // delete item;
7583 }
7684 }
7785
78- foreach ( QgsDataItem* item, serviceItems )
86+ foreach ( QgsDataItem* item, serviceItems. keys () )
7987 {
8088 QgsDebugMsg ( QString ( " serviceItems.size = %1 layerCount = %2 rowCount = %3" ).arg ( serviceItems.size () ).arg ( layerCount ).arg ( item->rowCount () ) );
89+ QString providerKey = serviceItems.value ( item );
8190 if ( serviceItems.size () == 1 || layerCount <= 30 || item->rowCount () <= 10 )
8291 {
8392 // Add layers directly to OWS connection
8493 foreach ( QgsDataItem* subItem, item->children () )
8594 {
8695 item->removeChildItem ( subItem );
8796 subItem->setParent ( this );
97+ replacePath ( subItem, providerKey.toLower () + " :/" , " ows:/" );
8898 children.append ( subItem );
8999 }
90100 delete item;
91101 }
92102 else // Add service
93103 {
104+ replacePath ( item, item->path (), path () + " /" + providerKey.toLower () );
94105 children.append ( item );
95106 }
96107 }
97108
98109 return children;
99110}
100111
112+ // reset path recursively
113+ void QgsOWSConnectionItem::replacePath ( QgsDataItem* item, QString before, QString after )
114+ {
115+ item->setPath ( item->path ().replace ( before, after ) );
116+ foreach ( QgsDataItem* subItem, item->children () )
117+ {
118+ replacePath ( subItem, before, after );
119+ }
120+ }
121+
101122bool QgsOWSConnectionItem::equal ( const QgsDataItem *other )
102123{
103124 if ( type () != other->type () )
@@ -166,25 +187,20 @@ QVector<QgsDataItem*> QgsOWSRootItem::createChildren()
166187 QgsDebugMsg ( " Entered" );
167188 QVector<QgsDataItem*> connections;
168189 // Combine all WMS,WFS,WCS connections
169- QMap<QString, QStringList> uris ;
190+ QStringList connNames ;
170191 foreach ( QString service, QStringList () << " WMS" << " WFS" << " WCS" )
171192 {
172193 foreach ( QString connName, QgsOWSConnection::connectionList ( service ) )
173194 {
174- QgsOWSConnection connection ( service, connName );
175-
176- QString encodedUri = connection.uri ().encodedUri ();
177- QStringList labels = uris.value ( encodedUri );
178- if ( !labels.contains ( connName ) )
195+ if ( !connNames.contains ( connName ) )
179196 {
180- labels << connName;
197+ connNames << connName;
181198 }
182- uris[encodedUri] = labels;
183199 }
184200 }
185- foreach ( QString encodedUri, uris. keys () )
201+ foreach ( QString connName, connNames )
186202 {
187- QgsDataItem * conn = new QgsOWSConnectionItem ( this , uris. value ( encodedUri ). join ( " / " ), encodedUri );
203+ QgsDataItem * conn = new QgsOWSConnectionItem ( this , connName, " ows:/ " + connName );
188204 connections.append ( conn );
189205 }
190206 return connections;
0 commit comments