Skip to content
Permalink
Browse files

Data items: add data provider origin key

Adds the data provider key of the data provider
that created the item.

Also keeps a map between data *item* provider name
(AKA data item provider "key") and the data provider
name (AKA data provider "key").
  • Loading branch information
elpaso committed Mar 10, 2020
1 parent 700a411 commit 867d0f6fdd166bd4d84965dae5a1ba5b4c524e24
Showing with 271 additions and 44 deletions.
  1. +8 −0 python/core/auto_generated/qgsdataitem.sip.in
  2. +7 −0 python/core/auto_generated/qgsdataitemprovider.sip.in
  3. +10 −0 python/core/auto_generated/qgsdataitemproviderregistry.sip.in
  4. +13 −2 src/core/providers/ogr/qgsgeopackagedataitems.cpp
  5. +5 −0 src/core/providers/ogr/qgsgeopackagedataitems.h
  6. +5 −0 src/core/providers/ogr/qgsogrdataitems.cpp
  7. +1 −1 src/core/providers/ogr/qgsogrdataitems.h
  8. +5 −0 src/core/qgsdataitem.cpp
  9. +7 −0 src/core/qgsdataitem.h
  10. +8 −0 src/core/qgsdataitemprovider.h
  11. +16 −0 src/core/qgsdataitemproviderregistry.cpp
  12. +13 −0 src/core/qgsdataitemproviderregistry.h
  13. +4 −4 src/providers/arcgisrest/qgsafsdataitems.cpp
  14. +4 −4 src/providers/arcgisrest/qgsamsdataitems.cpp
  15. +14 −3 src/providers/db2/qgsdb2dataitems.cpp
  16. +5 −0 src/providers/db2/qgsdb2dataitems.h
  17. +9 −3 src/providers/geonode/qgsgeonodedataitems.cpp
  18. +4 −0 src/providers/geonode/qgsgeonodedataitems.h
  19. +14 −3 src/providers/mssql/qgsmssqldataitems.cpp
  20. +6 −0 src/providers/mssql/qgsmssqldataitems.h
  21. +14 −3 src/providers/oracle/qgsoracledataitems.cpp
  22. +5 −0 src/providers/oracle/qgsoracledataitems.h
  23. +2 −2 src/providers/ows/qgsowsdataitems.cpp
  24. +14 −3 src/providers/postgres/qgspostgresdataitems.cpp
  25. +6 −0 src/providers/postgres/qgspostgresdataitems.h
  26. +14 −3 src/providers/spatialite/qgsspatialitedataitems.cpp
  27. +5 −0 src/providers/spatialite/qgsspatialitedataitems.h
  28. +7 −2 src/providers/wcs/qgswcsdataitems.cpp
  29. +1 −1 src/providers/wcs/qgswcsdataitems.h
  30. +13 −2 src/providers/wfs/qgswfsdataitems.cpp
  31. +5 −1 src/providers/wfs/qgswfsdataitems.h
  32. +21 −5 src/providers/wms/qgswmsdataitems.cpp
  33. +6 −2 src/providers/wms/qgswmsdataitems.h
@@ -69,6 +69,14 @@ The optional ``providerKey`` string (added in QGIS 3.12) can be used to specify

bool hasChildren();

virtual bool layerCollection() const;
%Docstring
Returns ``True`` if the data item is a collection of layers
The default implementation returns ``False``, subclasses must implement this method if their children are layers.

.. versionadded:: 3.14
%End

int rowCount();

virtual QVector<QgsDataItem *> createChildren() /Factory/;
@@ -38,6 +38,13 @@ or directory being inspected, parent item is a valid QgsDirectoryItem
Human-readable name of the provider name
%End

virtual QString dataProviderKey() const;
%Docstring
Returns the data provider key (if the data item provider is associated with a data provider),
the default implementation returns an empty string.

.. versionadded:: 3.14
%End
virtual int capabilities() const = 0;
%Docstring
Returns combination of flags from QgsDataProvider.DataCapabilities
@@ -10,6 +10,7 @@




class QgsDataItemProviderRegistry
{
%Docstring
@@ -47,6 +48,15 @@ is transferred to the registry.
%Docstring
Removes a ``provider`` implementation from the registry.
The provider object is automatically deleted.
%End

QString dataProviderKey( const QString &dataItemProviderName );
%Docstring
Returns the (possibly blank) data provider key for a given data item provider name.

:param dataItemProviderName: name of the data item provider

.. versionadded:: 3.14
%End

private:
@@ -46,6 +46,11 @@ QString QgsGeoPackageDataItemProvider::name()
return QStringLiteral( "GPKG" );
}

QString QgsGeoPackageDataItemProvider::dataProviderKey() const
{
return QStringLiteral( "ogr" );
}

int QgsGeoPackageDataItemProvider::capabilities() const
{
return QgsDataProvider::Database;
@@ -62,7 +67,7 @@ QgsDataItem *QgsGeoPackageDataItemProvider::createDataItem( const QString &path,
}

QgsGeoPackageRootItem::QgsGeoPackageRootItem( QgsDataItem *parent, const QString &name, const QString &path )
: QgsDataCollectionItem( parent, name, path )
: QgsDataCollectionItem( parent, name, path, QStringLiteral( "GPKG" ) )
{
mCapabilities |= Fast;
mIconName = QStringLiteral( "mGeoPackage.svg" );
@@ -97,7 +102,7 @@ void QgsGeoPackageRootItem::newConnection()
}

QgsGeoPackageCollectionItem::QgsGeoPackageCollectionItem( QgsDataItem *parent, const QString &name, const QString &path )
: QgsDataCollectionItem( parent, name, path )
: QgsDataCollectionItem( parent, name, path, QStringLiteral( "GPKG" ) )
{
mToolTip = path;
mCapabilities |= Collapse;
@@ -367,3 +372,9 @@ bool QgsGeoPackageVectorLayerItem::executeDeleteLayer( QString &errCause )
}

///@endcond


bool QgsGeoPackageCollectionItem::layerCollection() const
{
return true;
}
@@ -61,6 +61,10 @@ class CORE_EXPORT QgsGeoPackageCollectionItem : public QgsDataCollectionItem
void addConnection();
void deleteConnection();


// QgsDataItem interface
public:
bool layerCollection() const override;
};


@@ -160,6 +164,7 @@ class QgsGeoPackageDataItemProvider final: public QgsDataItemProvider
{
public:
QString name() override;
QString dataProviderKey() const override;
int capabilities() const override;
QgsDataItem *createDataItem( const QString &path, QgsDataItem *parentItem ) override;
};
@@ -410,6 +410,11 @@ QString QgsOgrDataItemProvider::name()
return QStringLiteral( "OGR" );
}

QString QgsOgrDataItemProvider::dataProviderKey() const
{
return QStringLiteral( "ogr" );
}

int QgsOgrDataItemProvider::capabilities() const
{
return QgsDataProvider::File | QgsDataProvider::Dir | QgsDataProvider::Net;
@@ -103,7 +103,7 @@ class QgsOgrDataItemProvider final: public QgsDataItemProvider
{
public:
QString name() override;

QString dataProviderKey() const override;
int capabilities() const override;

QgsDataItem *createDataItem( const QString &path, QgsDataItem *parentItem ) override;
@@ -459,6 +459,11 @@ bool QgsDataItem::hasChildren()
return ( state() == Populated ? !mChildren.isEmpty() : true );
}

bool QgsDataItem::layerCollection() const
{
return false;
}

void QgsDataItem::setParent( QgsDataItem *parent )
{
if ( mParent )
@@ -103,6 +103,13 @@ class CORE_EXPORT QgsDataItem : public QObject

bool hasChildren();

/**
* Returns TRUE if the data item is a collection of layers
* The default implementation returns FALSE, subclasses must implement this method if their children are layers.
* \since QGIS 3.14
*/
virtual bool layerCollection() const;

int rowCount();

/**
@@ -49,6 +49,14 @@ class CORE_EXPORT QgsDataItemProvider
//! Human-readable name of the provider name
virtual QString name() = 0;

/**
* Returns the data provider key (if the data item provider is associated with a data provider),
* the default implementation returns an empty string.
*
* \since QGIS 3.14
*/
virtual QString dataProviderKey() const { return QString(); };

//! Returns combination of flags from QgsDataProvider::DataCapabilities
virtual int capabilities() const = 0;

@@ -30,6 +30,13 @@ QgsDataItemProviderRegistry::QgsDataItemProviderRegistry()
{
QList<QgsDataItemProvider *> providerList = QgsProviderRegistry::instance()->dataItemProviders( key );
mProviders << providerList;
for ( const auto &p : qgis::as_const( providerList ) )
{
if ( ! p->dataProviderKey().isEmpty() )
{
mDataItemProviderOrigin[ p->name() ] = p->dataProviderKey();
}
}
}
}

@@ -42,6 +49,10 @@ QList<QgsDataItemProvider *> QgsDataItemProviderRegistry::providers() const { re

void QgsDataItemProviderRegistry::addProvider( QgsDataItemProvider *provider )
{
if ( ! provider->dataProviderKey().isEmpty() )
{
mDataItemProviderOrigin[ provider->name() ] = provider->dataProviderKey();
}
mProviders.append( provider );
}

@@ -51,3 +62,8 @@ void QgsDataItemProviderRegistry::removeProvider( QgsDataItemProvider *provider
if ( index >= 0 )
delete mProviders.takeAt( index );
}

QString QgsDataItemProviderRegistry::dataProviderKey( const QString &dataItemProviderName )
{
return mDataItemProviderOrigin.value( dataItemProviderName, QString() );
}
@@ -17,6 +17,8 @@
#define QGSDATAITEMPROVIDERREGISTRY_H

#include <QList>
#include <QMap>

#include "qgis_sip.h"

#include "qgis_core.h"
@@ -63,6 +65,14 @@ class CORE_EXPORT QgsDataItemProviderRegistry
*/
void removeProvider( QgsDataItemProvider *provider );

/**
* Returns the (possibly blank) data provider key for a given data item provider name.
*
* \param dataItemProviderName name of the data item provider
* \since QGIS 3.14
*/
QString dataProviderKey( const QString &dataItemProviderName );

private:
#ifdef SIP_RUN
QgsDataItemProviderRegistry( const QgsDataItemProviderRegistry &rh );
@@ -71,6 +81,9 @@ class CORE_EXPORT QgsDataItemProviderRegistry
//! Available providers, owned by this class
QList<QgsDataItemProvider *> mProviders;

//! Keeps track of data item provider <-> data provider association
QMap<QString, QString> mDataItemProviderOrigin;

};

#endif // QGSDATAITEMPROVIDERREGISTRY_H
@@ -29,7 +29,7 @@


QgsAfsRootItem::QgsAfsRootItem( QgsDataItem *parent, const QString &name, const QString &path )
: QgsDataCollectionItem( parent, name, path )
: QgsDataCollectionItem( parent, name, path, QStringLiteral( "AFS" ) )
{
mCapabilities |= Fast;
mIconName = QStringLiteral( "mIconAfs.svg" );
@@ -124,7 +124,7 @@ void addLayerItems( QVector< QgsDataItem * > &items, const QVariantMap &serviceD
}

QgsAfsConnectionItem::QgsAfsConnectionItem( QgsDataItem *parent, const QString &name, const QString &path, const QString &connectionName )
: QgsDataCollectionItem( parent, name, path )
: QgsDataCollectionItem( parent, name, path, QStringLiteral( "AFS" ) )
, mConnName( connectionName )
{
mIconName = QStringLiteral( "mIconConnect.svg" );
@@ -177,7 +177,7 @@ QString QgsAfsConnectionItem::url() const


QgsAfsFolderItem::QgsAfsFolderItem( QgsDataItem *parent, const QString &name, const QString &path, const QString &baseUrl, const QString &authcfg, const QgsStringMap &headers )
: QgsDataCollectionItem( parent, name, path )
: QgsDataCollectionItem( parent, name, path, QStringLiteral( "AFS" ) )
, mBaseUrl( baseUrl )
, mAuthCfg( authcfg )
, mHeaders( headers )
@@ -220,7 +220,7 @@ bool QgsAfsFolderItem::equal( const QgsDataItem *other )
}

QgsAfsServiceItem::QgsAfsServiceItem( QgsDataItem *parent, const QString &name, const QString &path, const QString &baseUrl, const QString &authcfg, const QgsStringMap &headers )
: QgsDataCollectionItem( parent, name, path )
: QgsDataCollectionItem( parent, name, path, QStringLiteral( "AFS" ) )
, mBaseUrl( baseUrl )
, mAuthCfg( authcfg )
, mHeaders( headers )
@@ -27,7 +27,7 @@
#include <QImageReader>

QgsAmsRootItem::QgsAmsRootItem( QgsDataItem *parent, const QString &name, const QString &path )
: QgsDataCollectionItem( parent, name, path )
: QgsDataCollectionItem( parent, name, path, QStringLiteral( "AMS" ) )
{
mCapabilities |= Fast;
mIconName = QStringLiteral( "mIconAms.svg" );
@@ -116,7 +116,7 @@ void addLayerItems( QVector< QgsDataItem * > &items, const QVariantMap &serviceD


QgsAmsConnectionItem::QgsAmsConnectionItem( QgsDataItem *parent, const QString &name, const QString &path, const QString &connectionName )
: QgsDataCollectionItem( parent, name, path )
: QgsDataCollectionItem( parent, name, path, QStringLiteral( "AMS" ) )
, mConnName( connectionName )
{
mIconName = QStringLiteral( "mIconConnect.svg" );
@@ -170,7 +170,7 @@ QString QgsAmsConnectionItem::url() const


QgsAmsFolderItem::QgsAmsFolderItem( QgsDataItem *parent, const QString &name, const QString &path, const QString &baseUrl, const QString &authcfg, const QgsStringMap &headers )
: QgsDataCollectionItem( parent, name, path )
: QgsDataCollectionItem( parent, name, path, QStringLiteral( "AMS" ) )
, mBaseUrl( baseUrl )
, mAuthCfg( authcfg )
, mHeaders( headers )
@@ -214,7 +214,7 @@ bool QgsAmsFolderItem::equal( const QgsDataItem *other )


QgsAmsServiceItem::QgsAmsServiceItem( QgsDataItem *parent, const QString &name, const QString &path, const QString &baseUrl, const QString &authcfg, const QgsStringMap &headers )
: QgsDataCollectionItem( parent, name, path )
: QgsDataCollectionItem( parent, name, path, QStringLiteral( "AMS" ) )
, mBaseUrl( baseUrl )
, mAuthCfg( authcfg )
, mHeaders( headers )
@@ -32,7 +32,7 @@
static const QString PROVIDER_KEY = QStringLiteral( "DB2" );

QgsDb2ConnectionItem::QgsDb2ConnectionItem( QgsDataItem *parent, const QString name, const QString path )
: QgsDataCollectionItem( parent, name, path )
: QgsDataCollectionItem( parent, name, path, QStringLiteral( "DB2" ) )
{
mIconName = QStringLiteral( "mIconConnect.svg" );
mCapabilities |= Collapse;
@@ -334,7 +334,7 @@ bool QgsDb2ConnectionItem::handleDrop( const QMimeData *data, const QString &toS
}

QgsDb2RootItem::QgsDb2RootItem( QgsDataItem *parent, QString name, QString path )
: QgsDataCollectionItem( parent, name, path )
: QgsDataCollectionItem( parent, name, path, QStringLiteral( "DB2" ) )
{
mIconName = QStringLiteral( "mIconDb2.svg" );
populate();
@@ -389,7 +389,7 @@ QString QgsDb2LayerItem::createUri()
}
// ---------------------------------------------------------------------------
QgsDb2SchemaItem::QgsDb2SchemaItem( QgsDataItem *parent, QString name, QString path )
: QgsDataCollectionItem( parent, name, path )
: QgsDataCollectionItem( parent, name, path, QStringLiteral( "DB2" ) )
{
mIconName = QStringLiteral( "mIconDbSchema.svg" );
}
@@ -479,6 +479,11 @@ QString QgsDb2DataItemProvider::name()
return QStringLiteral( "DB2" );
}

QString QgsDb2DataItemProvider::dataProviderKey() const
{
return QStringLiteral( "DB2" );
}

int QgsDb2DataItemProvider::capabilities() const
{
return QgsDataProvider::Database;
@@ -490,3 +495,9 @@ QgsDataItem *QgsDb2DataItemProvider::createDataItem( const QString &pathIn, QgsD
QgsDebugMsgLevel( QStringLiteral( "DB2: Browser Panel; data item detected." ), 2 );
return new QgsDb2RootItem( parentItem, PROVIDER_KEY, QStringLiteral( "DB2:" ) );
}


bool QgsDb2SchemaItem::layerCollection() const
{
return true;
}
@@ -108,6 +108,10 @@ class QgsDb2SchemaItem : public QgsDataCollectionItem

void refresh() override {} // do not refresh directly
void addLayers( QgsDataItem *newLayers );

// QgsDataItem interface
public:
bool layerCollection() const override;
};

/**
@@ -134,6 +138,7 @@ class QgsDb2DataItemProvider : public QgsDataItemProvider
{
public:
QString name() override;
QString dataProviderKey() const override;
int capabilities() const override;
QgsDataItem *createDataItem( const QString &pathIn, QgsDataItem *parentItem ) override;
};

0 comments on commit 867d0f6

Please sign in to comment.
You can’t perform that action at this time.