Skip to content
Permalink
Browse files

Wrap QgsNewDatabaseTableNameWidget in a dialog class for convenience

  • Loading branch information
nyalldawson committed Mar 15, 2020
1 parent 40d5efc commit 3966d3f06ea73d154a38a1701135d7c81a3c1805
@@ -124,6 +124,74 @@ This signal is emitted when the URI of the new table changes, whether or not it

};


class QgsNewDatabaseTableNameDialog: QDialog
{
%Docstring
QgsNewDatabaseTableNameDialog is a dialog which allows selection of 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 QgsNewDatabaseTableNameDialog( QgsBrowserGuiModel *browserModel = 0,
const QStringList &providersFilter = QStringList(),
QWidget *parent = 0 );
%Docstring
Constructs a new QgsNewDatabaseTableNameDialog

: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

};
/************************************************************************
* This file has been generated automatically from *
* *
@@ -24,6 +24,8 @@
#include "qgsprovidermetadata.h"
#include "qgssettings.h"

#include <QDialogButtonBox>
#include <QPushButton>

// List of data item provider keys that are filesystem based
QStringList QgsNewDatabaseTableNameWidget::FILESYSTEM_BASED_DATAITEM_PROVIDERS { QStringLiteral( "GPKG" ), QStringLiteral( "SPATIALITE" ) };
@@ -371,3 +373,51 @@ void QgsNewDatabaseTableNameWidget::showEvent( QShowEvent *e )
}
}
}

//
// QgsNewDatabaseTableNameDialog
//
QgsNewDatabaseTableNameDialog::QgsNewDatabaseTableNameDialog( QgsBrowserGuiModel *browserModel, const QStringList &providersFilter, QWidget *parent )
: QDialog( parent )
{
mWidget = new QgsNewDatabaseTableNameWidget( browserModel, providersFilter );
QVBoxLayout *vl = new QVBoxLayout();
vl->addWidget( mWidget, 1 );
QDialogButtonBox *buttonBox = new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel );
connect( buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept );
connect( buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject );
buttonBox->button( QDialogButtonBox::Ok )->setEnabled( false );
connect( mWidget, &QgsNewDatabaseTableNameWidget::validationChanged, buttonBox->button( QDialogButtonBox::Ok ), &QWidget::setEnabled );
vl->addWidget( buttonBox );
setLayout( vl );
}

QString QgsNewDatabaseTableNameDialog::schema() const
{
return mWidget->schema();
}

QString QgsNewDatabaseTableNameDialog::uri() const
{
return mWidget->uri();
}

QString QgsNewDatabaseTableNameDialog::table() const
{
return mWidget->table();
}

QString QgsNewDatabaseTableNameDialog::dataProviderKey() const
{
return mWidget->dataProviderKey();
}

bool QgsNewDatabaseTableNameDialog::isValid() const
{
return mWidget->isValid();
}

QString QgsNewDatabaseTableNameDialog::validationError() const
{
return mWidget->validationError();
}
@@ -24,6 +24,7 @@
#include "qgsbrowserproxymodel.h"

#include <QWidget>
#include <QDialog>

/**
* \ingroup gui
@@ -160,4 +161,73 @@ class GUI_EXPORT QgsNewDatabaseTableNameWidget : public QWidget, private Ui::Qgs

};


/**
* \ingroup gui
* QgsNewDatabaseTableNameDialog is a dialog which allows selection of 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
*
* \since QGIS 3.14
*/
class GUI_EXPORT QgsNewDatabaseTableNameDialog: public QDialog
{
Q_OBJECT

public:

/**
* Constructs a new QgsNewDatabaseTableNameDialog
*
* \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
*/
explicit QgsNewDatabaseTableNameDialog( QgsBrowserGuiModel *browserModel = nullptr,
const QStringList &providersFilter = QStringList(),
QWidget *parent = nullptr );

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

/**
* 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.
*/
QString uri() const;

/**
* Returns the current name of the new table
*/
QString table() const;

/**
* Returns the currently selected data item provider key
*/
QString dataProviderKey() const;

/**
* Returns TRUE if the widget contains a valid new table name
*/
bool isValid() const;

/**
* Returns the validation error or an empty string is the widget status is valid
*/
QString validationError() const;

private:

QgsNewDatabaseTableNameWidget *mWidget = nullptr;

};
#endif // QGSNEWDATABASETABLENAMEWIDGET_H

0 comments on commit 3966d3f

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