Skip to content
Permalink
Browse files

Revert endless mess in providerKey

the big issue is that layer items return the QgsDataProvder key
while other items return the QgsDataItemProvder key.

This needs a complete refactoring (and API break).
  • Loading branch information
elpaso committed Jul 17, 2020
1 parent ecb5f4b commit a775665d203816bfb493fad80e1ae644251fd953
@@ -41,6 +41,7 @@
#include "qgsabstractdatabaseproviderconnection.h"
#include "qgsprovidermetadata.h"
#include "qgsnewvectortabledialog.h"
#include "qgsdataitemproviderregistry.h"

#include <QFileInfo>
#include <QMenu>
@@ -832,7 +833,9 @@ void QgsDatabaseItemGuiProvider::populateContextMenu( QgsDataItem *item, QMenu *
{
if ( QgsDataCollectionItem * collectionItem { qobject_cast<QgsDataCollectionItem *>( item ) } )
{
QgsProviderMetadata *md { QgsProviderRegistry::instance()->providerMetadata( collectionItem->providerKey() ) };
// This is super messy: we need the QgsDataProvider key and NOT the QgsDataItemProvider key!
const QString dataProviderKey { QgsApplication::dataItemProviderRegistry()->dataProviderKey( collectionItem->providerKey() ) };
QgsProviderMetadata *md { QgsProviderRegistry::instance()->providerMetadata( dataProviderKey ) };
if ( md )
{
const bool isSchema { qobject_cast<QgsDatabaseSchemaItem *>( item ) };
@@ -874,7 +877,14 @@ void QgsDatabaseItemGuiProvider::populateContextMenu( QgsDataItem *item, QMenu *
conn2->createVectorTable( schemaName, tableName, fields, geometryType, crs, true, &options );
if ( createSpatialIndex && conn2->capabilities().testFlag( QgsAbstractDatabaseProviderConnection::Capability::CreateSpatialIndex ) )
{
conn2->createSpatialIndex( schemaName, tableName );
try
{
conn2->createSpatialIndex( schemaName, tableName );
}
catch ( QgsProviderConnectionException &ex )
{
notify( QObject::tr( "Create Spatial Index" ), QObject::tr( "Could not create spatial index for table '%1':%2." ).arg( tableName, ex.what() ), context, Qgis::MessageLevel::Warning );
}
}
// Ok, here is the trick: we cannot refresh the connection item because the refresh is not
// recursive.
@@ -67,7 +67,7 @@ QgsDataItem *QgsGeoPackageDataItemProvider::createDataItem( const QString &path,
}

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

QgsGeoPackageCollectionItem::QgsGeoPackageCollectionItem( QgsDataItem *parent, const QString &name, const QString &path )
: QgsDataCollectionItem( parent, name, path, QStringLiteral( "ogr" ) )
: QgsDataCollectionItem( parent, name, path, QStringLiteral( "GPKG" ) )
{
mToolTip = QString( path ).remove( QLatin1String( "gpkg:/" ) );
mCapabilities |= Collapse;
@@ -161,7 +161,7 @@ bool QgsPostgresUtils::deleteSchema( const QString &schema, const QgsDataSourceU

// ---------------------------------------------------------------------------
QgsPGConnectionItem::QgsPGConnectionItem( QgsDataItem *parent, const QString &name, const QString &path )
: QgsDataCollectionItem( parent, name, path, QStringLiteral( "postgres" ) )
: QgsDataCollectionItem( parent, name, path, QStringLiteral( "PostGIS" ) )
{
mIconName = QStringLiteral( "mIconConnect.svg" );
mCapabilities |= Collapse;
@@ -368,7 +368,7 @@ QString QgsPGLayerItem::createUri()

// ---------------------------------------------------------------------------
QgsPGSchemaItem::QgsPGSchemaItem( QgsDataItem *parent, const QString &connectionName, const QString &name, const QString &path )
: QgsDatabaseSchemaItem( parent, name, path, QStringLiteral( "postgres" ) )
: QgsDatabaseSchemaItem( parent, name, path, QStringLiteral( "PostGIS" ) )
, mConnectionName( connectionName )
{
mIconName = QStringLiteral( "mIconDbSchema.svg" );
@@ -533,7 +533,7 @@ QVector<QgsDataItem *> QgsPGLayerItem::createChildren()

// ---------------------------------------------------------------------------
QgsPGRootItem::QgsPGRootItem( QgsDataItem *parent, const QString &name, const QString &path )
: QgsConnectionsRootItem( parent, name, path, QStringLiteral( "postgres" ) )
: QgsConnectionsRootItem( parent, name, path, QStringLiteral( "PostGIS" ) )
{
mCapabilities |= Fast;
mIconName = QStringLiteral( "mIconPostgis.svg" );
@@ -138,6 +138,14 @@ void TestQgsNewDatabaseTableNameWidget::testWidgetSignalsPostgres()

QVERIFY( ! w->isValid() );

/*
QDialog d;
QVBoxLayout l;
l.addWidget( w.get() );
d.setLayout( &l );
d.exec();
//*/

QCOMPARE( providerSpy.count(), 1 );
QCOMPARE( uriSpy.count(), 0 );
QCOMPARE( tableSpy.count(), 0 );

0 comments on commit a775665

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