Skip to content
Permalink
Browse files

Merge pull request #34968 from elpaso/tablewidget

[api] New database table name widget
  • Loading branch information
elpaso committed Mar 12, 2020
2 parents 4c49625 + 3719370 commit 6b3679b2ef9ffb42af78024e80d7e912e4fc1033
Showing with 1,742 additions and 92 deletions.
  1. +47 −5 python/core/auto_generated/qgsbrowserproxymodel.sip.in
  2. +8 −0 python/core/auto_generated/qgsdataitem.sip.in
  3. +7 −0 python/core/auto_generated/qgsdataitemprovider.sip.in
  4. +17 −0 python/core/auto_generated/qgsdataitemproviderregistry.sip.in
  5. +133 −0 python/gui/auto_generated/qgsnewdatabasetablenamewidget.sip.in
  6. +1 −0 python/gui/gui_auto.sip
  7. +16 −5 src/core/providers/ogr/qgsgeopackagedataitems.cpp
  8. +5 −0 src/core/providers/ogr/qgsgeopackagedataitems.h
  9. +5 −0 src/core/providers/ogr/qgsogrdataitems.cpp
  10. +1 −1 src/core/providers/ogr/qgsogrdataitems.h
  11. +41 −3 src/core/qgsbrowserproxymodel.cpp
  12. +51 −6 src/core/qgsbrowserproxymodel.h
  13. +5 −0 src/core/qgsdataitem.cpp
  14. +7 −0 src/core/qgsdataitem.h
  15. +8 −0 src/core/qgsdataitemprovider.h
  16. +28 −0 src/core/qgsdataitemproviderregistry.cpp
  17. +19 −0 src/core/qgsdataitemproviderregistry.h
  18. +4 −0 src/core/qgsdatasourceuri.cpp
  19. +2 −0 src/gui/CMakeLists.txt
  20. +2 −2 src/gui/qgsbrowserdockwidget.cpp
  21. +373 −0 src/gui/qgsnewdatabasetablenamewidget.cpp
  22. +163 −0 src/gui/qgsnewdatabasetablenamewidget.h
  23. +4 −4 src/providers/arcgisrest/qgsafsdataitems.cpp
  24. +4 −4 src/providers/arcgisrest/qgsamsdataitems.cpp
  25. +14 −3 src/providers/db2/qgsdb2dataitems.cpp
  26. +5 −0 src/providers/db2/qgsdb2dataitems.h
  27. +9 −3 src/providers/geonode/qgsgeonodedataitems.cpp
  28. +4 −0 src/providers/geonode/qgsgeonodedataitems.h
  29. +14 −3 src/providers/mssql/qgsmssqldataitems.cpp
  30. +6 −0 src/providers/mssql/qgsmssqldataitems.h
  31. +14 −3 src/providers/oracle/qgsoracledataitems.cpp
  32. +5 −0 src/providers/oracle/qgsoracledataitems.h
  33. +2 −2 src/providers/ows/qgsowsdataitems.cpp
  34. +14 −3 src/providers/postgres/qgspostgresdataitems.cpp
  35. +6 −0 src/providers/postgres/qgspostgresdataitems.h
  36. +80 −20 src/providers/postgres/qgspostgresprovider.cpp
  37. +1 −0 src/providers/postgres/qgspostgresprovider.h
  38. +14 −3 src/providers/spatialite/qgsspatialitedataitems.cpp
  39. +5 −0 src/providers/spatialite/qgsspatialitedataitems.h
  40. +7 −2 src/providers/wcs/qgswcsdataitems.cpp
  41. +1 −1 src/providers/wcs/qgswcsdataitems.h
  42. +13 −2 src/providers/wfs/qgswfsdataitems.cpp
  43. +5 −1 src/providers/wfs/qgswfsdataitems.h
  44. +21 −5 src/providers/wms/qgswmsdataitems.cpp
  45. +6 −2 src/providers/wms/qgswmsdataitems.h
  46. +94 −0 src/ui/qgsnewdatabasetablenamewidget.ui
  47. +63 −3 tests/src/core/testqgsbrowserproxymodel.cpp
  48. +50 −5 tests/src/core/testqgsdatasourceuri.cpp
  49. +1 −0 tests/src/gui/CMakeLists.txt
  50. +269 −0 tests/src/gui/testqgsnewdatabasetablewidget.cpp
  51. +60 −1 tests/src/python/test_provider_postgres.py
  52. +8 −0 tests/src/python/test_qgsdataitemproviderregistry.py
@@ -133,26 +133,68 @@ filterByLayerType() is ``True``.
.. seealso:: :py:func:`setFilterByLayerType`
%End

void setDataItemProviderKeyFilter( const QStringList &filter );
void setHiddenDataItemProviderKeyFilter( const QStringList &hiddenItemsFilter );
%Docstring
Sets the customization filters for data items based on item's data provider key
Sets a filter to hide data items based on on item's data item provider key.

By default browser model shows all items from all available data items provider and few special
items (e.g. Favourites). To customize the behavior, set the filter to not load certain data items.
By default browser model shows all items from all available data item providers and few special
items (e.g. Favourites).
To customize the behavior, set the filter to not load certain data items.
The items that are not based on data item providers have prefix "special:", for example
"special:Favourites", "special:Home", "PostGIS", "MSSQL"
"special:Favorites", "special:Home", "PostGIS", "MSSQL"

All items created by the providers listed in filter are hidden from the layer tree.
This filter is always evaluated.

:param hiddenItemsFilter: a list of data provider prefixes that will be hidden.

.. versionadded:: 3.12
%End

void setShownDataItemProviderKeyFilter( const QStringList &shownItemsFilter );
%Docstring
Sets a filter to show data items based on on item's data item provider key.

By default browser model shows all items from all available data item providers and few special
items (e.g. Favourites).
To customize the behavior, set the filter to load only certain data items.
The items that are not based on data item providers have prefix "special:", for example
"special:Favorites", "special:Home", "PostGIS", "MSSQL"

Only the items created by the providers listed in filter are shown in the layer tree.
This filter is always evaluated.

:param shownItemsFilter: a list of data provider prefixes that will be hidden.

.. versionadded:: 3.14
%End

bool showLayers() const;
%Docstring
Returns ``True`` if layers must be shown, this flag is ``True`` by default.

.. seealso:: :py:func:`setShowLayers`

.. versionadded:: 3.14
%End

void setShowLayers( bool showLayers );
%Docstring
Sets show layers to ``showLayers``

.. seealso:: :py:func:`showLayers`

.. versionadded:: 3.14
%End

protected:

virtual bool filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const;


public:
virtual bool hasChildren( const QModelIndex &parent = QModelIndex() ) const;

};

/************************************************************************
@@ -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
@@ -35,6 +36,13 @@ QgsDataItemProviderRegistry is not usually directly created, but rather accessed
QList<QgsDataItemProvider *> providers() const;
%Docstring
Returns the list of available providers.
%End

QgsDataItemProvider *provider( const QString &providerName ) const;
%Docstring
Returns the (possibly NULL) data item provider named ``providerName``

.. versionadded:: 3.14
%End

void addProvider( QgsDataItemProvider *provider /Transfer/ );
@@ -47,6 +55,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:
@@ -0,0 +1,133 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/qgsnewdatabasetablenamewidget.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/





class QgsNewDatabaseTableNameWidget : QWidget
{
%Docstring
The QgsNewDatabaseTableNameWidget class embeds the browser view to
select a DB schema and a new table name.

The table name is validated for uniqueness and the selected
data item provider, schema and table names can be retrieved with
getters.

.. warning::

The data provider that originated the data item provider
must support the connections API

.. versionadded:: 3.14
%End

%TypeHeaderCode
#include "qgsnewdatabasetablenamewidget.h"
%End
public:

explicit QgsNewDatabaseTableNameWidget( QgsBrowserGuiModel *browserModel = 0,
const QStringList &providersFilter = QStringList(),
QWidget *parent = 0 );
%Docstring
Constructs a new QgsNewDatabaseTableNameWidget

:param browserModel: an existing browser model (typically from app), if NULL an instance will be created
:param providersFilter: optional white list of data provider keys that should be
shown in the widget, if not specified all providers data items with database
capabilities will be shown
:param parent: optional parent for this widget
%End

QString schema() const;
%Docstring
Returns the currently selected schema or file path (in case of filesystem-based DBs like spatialite or GPKG) for the new table
%End

QString uri() const;
%Docstring
Returns the (possibly blank) string representation of the new table data source URI.
The URI might be invalid in case the widget is not in a valid state.
%End

QString table() const;
%Docstring
Returns the current name of the new table
%End

QString dataProviderKey() const;
%Docstring
Returns the currently selected data item provider key
%End

bool isValid() const;
%Docstring
Returns ``True`` if the widget contains a valid new table name
%End

QString validationError() const;
%Docstring
Returns the validation error or an empty string is the widget status is valid
%End

virtual void showEvent( QShowEvent *e );

%Docstring
Scroll to last selected index and expand it's children
%End

signals:

void validationChanged( bool isValid );
%Docstring
This signal is emitted whenever the validation status of the widget changes.

:param isValid: ``True`` if the current status of the widget is valid
%End

void schemaNameChanged( const QString &schemaName );
%Docstring
This signal is emitted when the user selects a schema (or file path for filesystem-based DBs like spatialite or GPKG).

:param schemaName: the name of the selected schema
%End

void tableNameChanged( const QString &tableName );
%Docstring
This signal is emitted when the user enters a table name

:param tableName: the name of the new table
%End

void providerKeyChanged( const QString &providerKey );
%Docstring
This signal is emitted when the selects a data provider or a schema name
that has a different data provider than the previously selected one.

:param providerKey: the data provider key of the selected schema
%End

void uriChanged( const QString &uri );
%Docstring
This signal is emitted when the URI of the new table changes, whether or not it is a valid one.

:param uri: URI string representation
%End


};

/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/qgsnewdatabasetablenamewidget.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
@@ -59,6 +59,7 @@
%Include auto_generated/qgsdataitemguiprovider.sip
%Include auto_generated/qgsdataitemguiproviderregistry.sip
%Include auto_generated/qgsdatasourceselectdialog.sip
%Include auto_generated/qgsnewdatabasetablenamewidget.sip
%Include auto_generated/qgsdetaileditemdata.sip
%Include auto_generated/qgsdetaileditemdelegate.sip
%Include auto_generated/qgsdetaileditemwidget.sip
@@ -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" );
@@ -76,7 +81,7 @@ QVector<QgsDataItem *> QgsGeoPackageRootItem::createChildren()
for ( const QString &connName : connList )
{
QgsOgrDbConnection connection( connName, QStringLiteral( "GPKG" ) );
QgsDataItem *conn = new QgsGeoPackageConnectionItem( this, connection.name(), connection.path() );
QgsDataItem *conn = new QgsGeoPackageConnectionItem( this, connection.name(), mPath + '/' + connection.path() );

connections.append( conn );
}
@@ -97,17 +102,17 @@ 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;
mToolTip = QString( path ).remove( QLatin1String( "gpkg:/" ) );
mCapabilities |= Collapse;
}


QVector<QgsDataItem *> QgsGeoPackageCollectionItem::createChildren()
{
QVector<QgsDataItem *> children;
const auto layers = QgsOgrLayerItem::subLayers( mPath, QStringLiteral( "GPKG" ) );
const auto layers = QgsOgrLayerItem::subLayers( mPath.remove( QLatin1String( "gpkg:/" ) ), QStringLiteral( "GPKG" ) );
for ( const QgsOgrDbLayerInfo *info : layers )
{
if ( info->layerType() == QgsLayerItem::LayerType::Raster )
@@ -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;

0 comments on commit 6b3679b

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