Skip to content

Commit

Permalink
Merge pull request #34968 from elpaso/tablewidget
Browse files Browse the repository at this point in the history
[api] New database table name widget
  • Loading branch information
elpaso committed Mar 12, 2020
2 parents 4c49625 + 3719370 commit 6b3679b
Show file tree
Hide file tree
Showing 52 changed files with 1,742 additions and 92 deletions.
52 changes: 47 additions & 5 deletions python/core/auto_generated/qgsbrowserproxymodel.sip.in
Expand Up @@ -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;

};

/************************************************************************
Expand Down
8 changes: 8 additions & 0 deletions python/core/auto_generated/qgsdataitem.sip.in
Expand Up @@ -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/;
Expand Down
7 changes: 7 additions & 0 deletions python/core/auto_generated/qgsdataitemprovider.sip.in
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions python/core/auto_generated/qgsdataitemproviderregistry.sip.in
Expand Up @@ -10,6 +10,7 @@




class QgsDataItemProviderRegistry
{
%Docstring
Expand All @@ -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/ );
Expand All @@ -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:
Expand Down
133 changes: 133 additions & 0 deletions python/gui/auto_generated/qgsnewdatabasetablenamewidget.sip.in
@@ -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 *
************************************************************************/
1 change: 1 addition & 0 deletions python/gui/gui_auto.sip
Expand Up @@ -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
Expand Down
21 changes: 16 additions & 5 deletions src/core/providers/ogr/qgsgeopackagedataitems.cpp
Expand Up @@ -46,6 +46,11 @@ QString QgsGeoPackageDataItemProvider::name()
return QStringLiteral( "GPKG" );
}

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

int QgsGeoPackageDataItemProvider::capabilities() const
{
return QgsDataProvider::Database;
Expand All @@ -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" );
Expand All @@ -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 );
}
Expand All @@ -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 )
Expand Down Expand Up @@ -367,3 +372,9 @@ bool QgsGeoPackageVectorLayerItem::executeDeleteLayer( QString &errCause )
}

///@endcond


bool QgsGeoPackageCollectionItem::layerCollection() const
{
return true;
}
5 changes: 5 additions & 0 deletions src/core/providers/ogr/qgsgeopackagedataitems.h
Expand Up @@ -61,6 +61,10 @@ class CORE_EXPORT QgsGeoPackageCollectionItem : public QgsDataCollectionItem
void addConnection();
void deleteConnection();


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


Expand Down Expand Up @@ -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;
};
Expand Down
5 changes: 5 additions & 0 deletions src/core/providers/ogr/qgsogrdataitems.cpp
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/core/providers/ogr/qgsogrdataitems.h
Expand Up @@ -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;
Expand Down

0 comments on commit 6b3679b

Please sign in to comment.