Skip to content
Permalink
Browse files

QgsNewDatabaseTableNameWidget implementation (WIP)

  • Loading branch information
elpaso committed Mar 9, 2020
1 parent 7edf1f2 commit 700a411285854a10da8ffccca28ffac067554133
@@ -133,19 +133,40 @@ filterByLayerType() is ``True``.
.. seealso:: :py:func:`setFilterByLayerType`
%End

void setDataItemProviderKeyFilter( const QStringList &filter );
void setDataItemProviderKeyFilter( 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 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

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:
@@ -0,0 +1,100 @@
/************************************************************************
* 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.

.. 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 item provider names (not data providers!) 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();
%Docstring
Returns the currently selected schema for the new table
%End

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

QString dataItemProviderName();
%Docstring
Returns the currently selected data item provider name (which is NOT the data provider key!) for the new table
%End

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

QString validationError();
%Docstring
Returns the validation error or an empty string is the widget status is valid
%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.

: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


};

/************************************************************************
* 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
@@ -153,9 +153,28 @@ bool QgsBrowserProxyModel::filterAcceptsRow( int sourceRow, const QModelIndex &s
if ( !filterAcceptsProviderKey( sourceIndex ) || !filterRootAcceptsProviderKey( sourceIndex ) )
return false;

if ( ! mShowLayers )
{
QgsDataItem *item = mModel->dataItem( sourceIndex );
if ( qobject_cast< QgsLayerItem * >( item ) )
{
return false;
}
}

return filterAcceptsItem( sourceIndex ) || filterAcceptsAncestor( sourceIndex ) || filterAcceptsDescendant( sourceIndex );
}

bool QgsBrowserProxyModel::showLayers() const
{
return mShowLayers;
}

void QgsBrowserProxyModel::setShowLayers( bool showLayers )
{
mShowLayers = showLayers;
}

QgsMapLayerType QgsBrowserProxyModel::layerType() const
{
return mLayerType;
@@ -144,19 +144,38 @@ class CORE_EXPORT QgsBrowserProxyModel : public QSortFilterProxyModel
void setLayerType( QgsMapLayerType type );

/**
* 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 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.
*
* \since QGIS 3.12
*/
void setDataItemProviderKeyFilter( const QStringList &filter );
void setDataItemProviderKeyFilter( const QStringList &hiddenItemsFilter );

/**
* Returns TRUE if layers must be shown, this flag is TRUE by default.
*
* \see setShowLayers()
* \since QGIS 3.14
*/
bool showLayers() const;

/**
* Sets show layers to \a showLayers
*
* \see showLayers()
* \since QGIS 3.14
*/
void setShowLayers( bool showLayers );

protected:

@@ -172,6 +191,7 @@ class CORE_EXPORT QgsBrowserProxyModel : public QSortFilterProxyModel
Qt::CaseSensitivity mCaseSensitivity = Qt::CaseInsensitive;

bool mFilterByLayerType = false;
bool mShowLayers = true;
QgsMapLayerType mLayerType = QgsMapLayerType::VectorLayer;

//! Update filter
@@ -194,6 +214,8 @@ class CORE_EXPORT QgsBrowserProxyModel : public QSortFilterProxyModel

//! Root item accepts provider key.
bool filterRootAcceptsProviderKey( const QModelIndex &sourceIndex ) const;


};

#endif // QGSBROWSERPROXYMODEL_H
@@ -351,6 +351,7 @@ SET(QGIS_GUI_SRCS
qgsdataitemguiproviderregistry.cpp
qgsdatumtransformdialog.cpp
qgsdatasourceselectdialog.cpp
qgsnewdatabasetablenamewidget.cpp
qgsdetaileditemdata.cpp
qgsdetaileditemdelegate.cpp
qgsdetaileditemwidget.cpp
@@ -563,6 +564,7 @@ SET(QGIS_GUI_HDRS
qgsdataitemguiproviderregistry.h
qgsdatasourcemanagerdialog.h
qgsdatasourceselectdialog.h
qgsnewdatabasetablenamewidget.h
qgsdatumtransformdialog.h
qgsdetaileditemdata.h
qgsdetaileditemdelegate.h

0 comments on commit 700a411

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