Пример #1
0
// reset path recursively
void QgsGeoNodeServiceItem::replacePath( QgsDataItem *item, QString before, QString after )
{
  item->setPath( item->path().replace( before, after ) );
  const QVector< QgsDataItem * > children = item->children();
  for ( QgsDataItem *subItem : children )
  {
    replacePath( subItem, before, after );
  }
}
Пример #2
0
 std::string
 replacePath(const std::string& path)
 { return replacePath(path.c_str()); }
Пример #3
0
QVector<QgsDataItem *> QgsGeoNodeServiceItem::createChildren()
{
  QVector<QgsDataItem *> children;
  QHash<QgsDataItem *, QString> serviceItems; // service/provider key

  int layerCount = 0;
  // Try to open with service provider
  bool skipProvider = false;

  QgsGeoNodeConnectionItem *parentItem = dynamic_cast<QgsGeoNodeConnectionItem *>( mParent );
  QString pathPrefix = parentItem->mGeoNodeName.toLower() + QStringLiteral( ":/" );

  while ( !skipProvider )
  {
    const QString &key = mServiceName != QStringLiteral( "WFS" ) ? QStringLiteral( "wms" ) : mServiceName;
    std::unique_ptr< QLibrary > library( QgsProviderRegistry::instance()->createProviderLibrary( key ) );
    if ( !library )
    {
      skipProvider = true;
      continue;
    }

    dataItemProviders_t *dataItemProvidersFn = reinterpret_cast< dataItemProviders_t * >( cast_to_fptr( library->resolve( "dataItemProviders" ) ) );
    dataItem_t *dItem = ( dataItem_t * ) cast_to_fptr( library->resolve( "dataItem" ) );
    if ( !dItem && !dataItemProvidersFn )
    {
      skipProvider = true;
      continue;
    }

    QString path = pathPrefix + mName;

    QVector<QgsDataItem *> items;
    QList<QgsDataItemProvider *> *providerList = dataItemProvidersFn();
    for ( QgsDataItemProvider *pr : qgis::as_const( *providerList ) )
    {
      if ( !pr->name().startsWith( mServiceName ) )
        continue;

      items = pr->createDataItems( path, this );
      if ( !items.isEmpty() )
      {
        break;
      }
    }

    if ( items.isEmpty() )
    {
      skipProvider = true;
      continue;
    }

    if ( mServiceName == QStringLiteral( "XYZ" ) )
    {
      return items;
    }

    for ( QgsDataItem *item : qgis::as_const( items ) )
    {
      item->populate( true ); // populate in foreground - this is already run in a thread

      layerCount += item->rowCount();
      if ( item->rowCount() > 0 )
      {
        serviceItems.insert( item, key );
      }
      else
      {
        //delete item;
      }
    }

    skipProvider = true;
  }

  auto serviceItemIt = serviceItems.constBegin();
  for ( ; serviceItemIt != serviceItems.constEnd(); ++serviceItemIt )
  {
    QgsDataItem *item = serviceItemIt.key();
    QString providerKey = serviceItemIt.value();

    // Add layers directly to service item
    const QVector< QgsDataItem * > serviceChildItems = item->children();
    for ( QgsDataItem *subItem : serviceChildItems )
    {
      if ( subItem->path().endsWith( QStringLiteral( "error" ) ) )
      {
        continue;
      }
      item->removeChildItem( subItem );
      subItem->setParent( this );
      replacePath( subItem, providerKey.toLower() + QStringLiteral( ":/" ), pathPrefix );
      children.append( subItem );
    }

    delete item;
  }

  return children;
}