Skip to content
Permalink
Browse files

[addlayerbutton] Added embeddedMode to all providers

Also switched managerMode and embeddedMode arguments
for a more logical arg passing from the factory function.
  • Loading branch information
elpaso committed Jun 2, 2017
1 parent ff83bfe commit 129e00d7f343b4b828df249db2298f68998ede38
@@ -88,7 +88,7 @@ Set library directory where to search for plugins
%End

QWidget *createSelectionWidget( const QString &providerKey,
QWidget *parent = 0, Qt::WindowFlags fl = Qt::WindowFlags() );
QWidget *parent = 0, Qt::WindowFlags fl = Qt::WindowFlags(), bool embeddedMode = false );
%Docstring
Returns a new widget for selecting layers from a provider.
Either the ``parent`` widget must be set or the caller becomes
@@ -1599,6 +1599,9 @@ void QgisApp::dataSourceManager()
this, SLOT( addVectorLayer( QString const &, QString const &, QString const & ) ) );
connect( mDataSourceManagerDialog, SIGNAL( addVectorLayers( QStringList const &, QString const &, QString const & ) ),
this, SLOT( addVectorLayers( QStringList const &, QString const &, QString const & ) ) );
connect( mDataSourceManagerDialog, &QgsDataSourceManagerDialog::showProgress, this, &QgisApp::showProgress );
connect( mDataSourceManagerDialog, &QgsDataSourceManagerDialog::showStatusMessage, this, &QgisApp::showStatusMessage );
connect( mDataSourceManagerDialog, &QgsDataSourceManagerDialog::addDatabaseLayers, this, &QgisApp::addDatabaseLayers );
}
// TODO: handle docked
mDataSourceManagerDialog->exec();
@@ -85,6 +85,21 @@ QgsDataSourceManagerDialog::QgsDataSourceManagerDialog( QWidget *parent ) :
{ this->vectorLayerAdded( vectorLayerPath, baseName, QStringLiteral( "WFS" ) ); } );
}

#ifdef HAVE_POSTGRESQL
/////////////////////////////////////////////////////////////////////////////
// POSTGIS
dlg = providerDialog( QStringLiteral( "postgres" ), tr( "PostgreSQL" ), QStringLiteral( "/mActionAddPostgisLayer.svg" ) );
if ( dlg )
{
connect( dlg, SIGNAL( addDatabaseLayers( QStringList const &, QString const & ) ),
this, SIGNAL( addDatabaseLayers( QStringList const &, QString const & ) ) );
connect( dlg, SIGNAL( progress( int, int ) ),
this, SIGNAL( showProgress( int, int ) ) );
connect( dlg, SIGNAL( progressMessage( QString ) ),
this, SIGNAL( showStatusMessage( QString ) ) );
}
#endif

}

QgsDataSourceManagerDialog::~QgsDataSourceManagerDialog()
@@ -115,7 +130,7 @@ void QgsDataSourceManagerDialog::vectorLayersAdded( const QStringList &layerQStr

QDialog *QgsDataSourceManagerDialog::providerDialog( const QString providerKey, const QString providerName, const QString icon )
{
QDialog *dlg = dynamic_cast<QDialog *>( QgsProviderRegistry::instance()->createSelectionWidget( providerKey, this, Qt::Widget ) );
QDialog *dlg = dynamic_cast<QDialog *>( QgsProviderRegistry::instance()->createSelectionWidget( providerKey, this, Qt::Widget, true ) );
if ( !dlg )
{
QMessageBox::warning( this, providerName, tr( "Cannot get %1 select dialog from provider %2." ).arg( providerName, providerKey ) );
@@ -52,6 +52,9 @@ class QgsDataSourceManagerDialog : public QDialog
void addVectorLayer( const QString &vectorLayerPath, const QString &baseName, const QString &providerKey );
void addWfsLayer( const QString &uri, const QString &typeName );
void addVectorLayers( const QStringList &layerQStringList, const QString &enc, const QString &dataSourceType );
void showProgress( int progress, int totalSteps );
void showStatusMessage( const QString &message );
void addDatabaseLayers( QStringList const &layerPathList, QString const &providerKey );

private:
//! Return the dialog from the provider
@@ -438,18 +438,18 @@ int QgsProviderRegistry::providerCapabilities( const QString &providerKey ) cons
}

// This should be QWidget, not QDialog
typedef QWidget *selectFactoryFunction_t( QWidget *parent, Qt::WindowFlags fl );
typedef QWidget *selectFactoryFunction_t( QWidget *parent, Qt::WindowFlags fl, bool embeddedMode );

QWidget *QgsProviderRegistry::createSelectionWidget( const QString &providerKey,
QWidget *parent, Qt::WindowFlags fl )
QWidget *parent, Qt::WindowFlags fl, bool embeddedMode )
{
selectFactoryFunction_t *selectFactory =
reinterpret_cast< selectFactoryFunction_t * >( cast_to_fptr( function( providerKey, "selectWidget" ) ) );

if ( !selectFactory )
return nullptr;

return selectFactory( parent, fl );
return selectFactory( parent, fl, embeddedMode );
}

QFunctionPointer QgsProviderRegistry::function( QString const &providerKey,
@@ -98,7 +98,7 @@ class CORE_EXPORT QgsProviderRegistry
* responsible for deleting the returned widget.
*/
QWidget *createSelectionWidget( const QString &providerKey,
QWidget *parent = nullptr, Qt::WindowFlags fl = Qt::WindowFlags() );
QWidget *parent = nullptr, Qt::WindowFlags fl = Qt::WindowFlags(), bool embeddedMode = false );

/**
* Get pointer to provider function
@@ -45,9 +45,9 @@ QGISEXTERN bool isProvider()
return true;
}

QGISEXTERN QgsAfsSourceSelect *selectWidget( QWidget *parent, Qt::WindowFlags fl )
QGISEXTERN QgsAfsSourceSelect *selectWidget( QWidget *parent, Qt::WindowFlags fl, bool embeddedMode )
{
return new QgsAfsSourceSelect( parent, fl );
return new QgsAfsSourceSelect( parent, fl, embeddedMode );
}

QGISEXTERN int dataCapabilities()
@@ -45,9 +45,9 @@ QGISEXTERN bool isProvider()
return true;
}

QGISEXTERN QgsAmsSourceSelect *selectWidget( QWidget *parent, Qt::WindowFlags fl )
QGISEXTERN QgsAmsSourceSelect *selectWidget( QWidget *parent, Qt::WindowFlags fl, bool embeddedMode )
{
return new QgsAmsSourceSelect( parent, fl );
return new QgsAmsSourceSelect( parent, fl, embeddedMode );
}

QGISEXTERN int dataCapabilities()
@@ -1711,9 +1711,9 @@ QGISEXTERN int dataCapabilities()
return QgsDataProvider::Database;
}

QGISEXTERN void *selectWidget( QWidget *parent, Qt::WindowFlags fl )
QGISEXTERN void *selectWidget( QWidget *parent, Qt::WindowFlags fl, bool embeddedMode )
{
return new QgsDb2SourceSelect( parent, fl );
return new QgsDb2SourceSelect( parent, fl, embeddedMode );
}

QGISEXTERN QgsDataItem *dataItem( QString path, QgsDataItem *parentItem )
@@ -116,7 +116,7 @@ void QgsDb2SourceSelectDelegate::setModelData( QWidget *editor, QAbstractItemMod
model->setData( index, le->text() );
}

QgsDb2SourceSelect::QgsDb2SourceSelect( QWidget *parent, Qt::WindowFlags fl, bool managerMode, bool embeddedMode )
QgsDb2SourceSelect::QgsDb2SourceSelect( QWidget *parent, Qt::WindowFlags fl, bool embeddedMode, bool managerMode )
: QDialog( parent, fl )
, mManagerMode( managerMode )
, mEmbeddedMode( embeddedMode )
@@ -1187,7 +1187,7 @@ QGISEXTERN bool isProvider()
return true;
}

QGISEXTERN QgsDelimitedTextSourceSelect *selectWidget( QWidget *parent, Qt::WindowFlags fl )
QGISEXTERN QgsDelimitedTextSourceSelect *selectWidget( QWidget *parent, Qt::WindowFlags fl, bool embeddedMode )
{
return new QgsDelimitedTextSourceSelect( parent, fl );
return new QgsDelimitedTextSourceSelect( parent, fl, embeddedMode );
}
@@ -1972,9 +1972,9 @@ QGISEXTERN bool isProvider()
return true;
}

QGISEXTERN void *selectWidget( QWidget *parent, Qt::WindowFlags fl )
QGISEXTERN void *selectWidget( QWidget *parent, Qt::WindowFlags fl, bool embeddedMode )
{
return new QgsMssqlSourceSelect( parent, fl );
return new QgsMssqlSourceSelect( parent, fl, embeddedMode );
}

QGISEXTERN int dataCapabilities()
@@ -117,7 +117,7 @@ void QgsMssqlSourceSelectDelegate::setModelData( QWidget *editor, QAbstractItemM
model->setData( index, le->text() );
}

QgsMssqlSourceSelect::QgsMssqlSourceSelect( QWidget *parent, Qt::WindowFlags fl, bool managerMode, bool embeddedMode )
QgsMssqlSourceSelect::QgsMssqlSourceSelect( QWidget *parent, Qt::WindowFlags fl, bool embeddedMode, bool managerMode )
: QDialog( parent, fl )
, mManagerMode( managerMode )
, mEmbeddedMode( embeddedMode )
@@ -3031,9 +3031,9 @@ QGISEXTERN bool isProvider()
return true;
}

QGISEXTERN QgsOracleSourceSelect *selectWidget( QWidget *parent, Qt::WindowFlags fl )
QGISEXTERN QgsOracleSourceSelect *selectWidget( QWidget *parent, Qt::WindowFlags fl, bool embeddedMode )
{
return new QgsOracleSourceSelect( parent, fl );
return new QgsOracleSourceSelect( parent, fl, embeddedMode );
}

QGISEXTERN int dataCapabilities()
@@ -166,7 +166,7 @@ void QgsOracleSourceSelectDelegate::setModelData( QWidget *editor, QAbstractItem
}
}

QgsOracleSourceSelect::QgsOracleSourceSelect( QWidget *parent, Qt::WindowFlags fl, bool managerMode, bool embeddedMode )
QgsOracleSourceSelect::QgsOracleSourceSelect( QWidget *parent, Qt::WindowFlags fl, bool embeddedMode, bool managerMode )
: QDialog( parent, fl )
, mManagerMode( managerMode )
, mEmbeddedMode( embeddedMode )
@@ -265,10 +265,11 @@ QGISEXTERN QgsDataItem *dataItem( QString path, QgsDataItem *parentItem )
}

//QGISEXTERN QgsOWSSourceSelect * selectWidget( QWidget * parent, Qt::WindowFlags fl )
QGISEXTERN QDialog *selectWidget( QWidget *parent, Qt::WindowFlags fl )
QGISEXTERN QDialog *selectWidget( QWidget *parent, Qt::WindowFlags fl, bool embeddedMode )
{
Q_UNUSED( parent );
Q_UNUSED( fl );
//return new QgsOWSSourceSelect( parent, fl );
Q_UNUSED( embeddedMode );
//return new QgsOWSSourceSelect( parent, fl, embeddedMode );
return nullptr;
}
@@ -193,7 +193,7 @@ void QgsPgSourceSelectDelegate::setModelData( QWidget *editor, QAbstractItemMode
}
}

QgsPgSourceSelect::QgsPgSourceSelect( QWidget *parent, Qt::WindowFlags fl, bool managerMode, bool embeddedMode )
QgsPgSourceSelect::QgsPgSourceSelect( QWidget *parent, Qt::WindowFlags fl, bool embeddedMode, bool managerMode )
: QDialog( parent, fl )
, mManagerMode( managerMode )
, mEmbeddedMode( embeddedMode )
@@ -204,7 +204,9 @@ QgsPgSourceSelect::QgsPgSourceSelect( QWidget *parent, Qt::WindowFlags fl, bool

if ( mEmbeddedMode )
{
buttonBox->button( QDialogButtonBox::Close )->hide();
buttonBox->removeButton( buttonBox->button( QDialogButtonBox::Close ) );
mHoldDialogOpen->setHidden( true );
mHoldDialogOpen->hide();
}
else
{
@@ -509,7 +511,7 @@ void QgsPgSourceSelect::addTables()
else
{
emit addDatabaseLayers( mSelectedTables, QStringLiteral( "postgres" ) );
if ( !mHoldDialogOpen->isChecked() )
if ( !( mHoldDialogOpen->isChecked() || mEmbeddedMode ) )
{
accept();
}
@@ -4255,9 +4255,9 @@ QGISEXTERN bool isProvider()
return true;
}

QGISEXTERN QgsPgSourceSelect *selectWidget( QWidget *parent, Qt::WindowFlags fl )
QGISEXTERN QgsPgSourceSelect *selectWidget( QWidget *parent, Qt::WindowFlags fl, bool embeddedMode )
{
return new QgsPgSourceSelect( parent, fl );
return new QgsPgSourceSelect( parent, fl, embeddedMode );
}

QGISEXTERN int dataCapabilities()
@@ -348,7 +348,7 @@ void QgsSLRootItem::createDatabase()

// ---------------------------------------------------------------------------

QGISEXTERN QgsSpatiaLiteSourceSelect *selectWidget( QWidget *parent, Qt::WindowFlags fl )
QGISEXTERN QgsSpatiaLiteSourceSelect *selectWidget( QWidget *parent, Qt::WindowFlags fl, bool embeddedMode )
{
// TODO: this should be somewhere else
return new QgsSpatiaLiteSourceSelect( parent, fl, false );
@@ -36,9 +36,10 @@ email : hugo dot mercier at oslandia dot com
#include <QMessageBox>
#include <QTextStream>

QgsVirtualLayerSourceSelect::QgsVirtualLayerSourceSelect( QWidget *parent, Qt::WindowFlags fl )
QgsVirtualLayerSourceSelect::QgsVirtualLayerSourceSelect( QWidget *parent, Qt::WindowFlags fl, bool embeddedMode )
: QDialog( parent, fl )
, mSrid( 0 )
, mEmbeddedMode( embeddedMode )
{
setupUi( this );

@@ -329,8 +330,8 @@ void QgsVirtualLayerSourceSelect::on_buttonBox_accepted()
emit addVectorLayer( def.toString(), layerName, QStringLiteral( "virtual" ) );
}

QGISEXTERN QgsVirtualLayerSourceSelect *selectWidget( QWidget *parent, Qt::WindowFlags fl )
QGISEXTERN QgsVirtualLayerSourceSelect *selectWidget( QWidget *parent, Qt::WindowFlags fl, bool embeddedMode )
{
return new QgsVirtualLayerSourceSelect( parent, fl );
return new QgsVirtualLayerSourceSelect( parent, fl, embeddedMode );
}

@@ -33,7 +33,7 @@ class QgsVirtualLayerSourceSelect : public QDialog, private Ui::QgsVirtualLayerS
Q_OBJECT

public:
QgsVirtualLayerSourceSelect( QWidget *parent, Qt::WindowFlags fl = QgsGuiUtils::ModalDialogFlags );
QgsVirtualLayerSourceSelect( QWidget *parent, Qt::WindowFlags fl = QgsGuiUtils::ModalDialogFlags, bool embeddedMode = false );

private slots:
void on_buttonBox_accepted();
@@ -56,6 +56,7 @@ class QgsVirtualLayerSourceSelect : public QDialog, private Ui::QgsVirtualLayerS
long mSrid;
QStringList mProviderList;
QgsEmbeddedLayerSelectDialog *mEmbeddedSelectionDialog = nullptr;
bool mEmbeddedMode;
void addEmbeddedLayer( const QString &name, const QString &provider, const QString &encoding, const QString &source );
};

@@ -303,8 +303,8 @@ QGISEXTERN QgsDataItem *dataItem( QString path, QgsDataItem *parentItem )
return nullptr;
}

QGISEXTERN QgsWCSSourceSelect *selectWidget( QWidget *parent, Qt::WindowFlags fl )
QGISEXTERN QgsWCSSourceSelect *selectWidget( QWidget *parent, Qt::WindowFlags fl, bool embeddedMode )
{
return new QgsWCSSourceSelect( parent, fl );
return new QgsWCSSourceSelect( parent, fl, embeddedMode );
}

@@ -27,8 +27,8 @@

#include <QWidget>

QgsWCSSourceSelect::QgsWCSSourceSelect( QWidget *parent, Qt::WindowFlags fl, bool managerMode, bool embeddedMode )
: QgsOWSSourceSelect( QStringLiteral( "WCS" ), parent, fl, managerMode, embeddedMode )
QgsWCSSourceSelect::QgsWCSSourceSelect( QWidget *parent, Qt::WindowFlags fl, bool embeddedMode, bool managerMode )
: QgsOWSSourceSelect( QStringLiteral( "WCS" ), parent, fl, embeddedMode, managerMode )
{
// Hide irrelevant widgets
mWMSGroupBox->hide();
@@ -187,9 +187,9 @@ void QgsWfsRootItem::newConnection()

// ---------------------------------------------------------------------------

QGISEXTERN QgsWFSSourceSelect *selectWidget( QWidget *parent, Qt::WindowFlags fl )
QGISEXTERN QgsWFSSourceSelect *selectWidget( QWidget *parent, Qt::WindowFlags fl, bool embeddedMode )
{
return new QgsWFSSourceSelect( parent, fl );
return new QgsWFSSourceSelect( parent, fl, embeddedMode );
}

QGISEXTERN int dataCapabilities()
@@ -56,15 +56,13 @@ QgsWFSSourceSelect::QgsWFSSourceSelect( QWidget *parent, Qt::WindowFlags fl, boo
{
setupUi( this );

if ( mEmbeddedMode || ( Qt::Widget == fl ) )
if ( mEmbeddedMode )
{
// For some osbscure reson hiding does not work!
// buttonBox->button( QDialogButtonBox::Close )->hide();
buttonBox->removeButton( buttonBox->button( QDialogButtonBox::Close ) );
mHoldDialogOpen->setHidden( true );
mHoldDialogOpen->hide();
// Set this in any event, to prevent auto-close
mEmbeddedMode = true;
}

mAddButton = new QPushButton( tr( "&Add" ) );
@@ -438,9 +438,9 @@ QGISEXTERN void registerGui( QMainWindow *mainWindow )
QgsTileScaleWidget::showTileScale( mainWindow );
}

QGISEXTERN QgsWMSSourceSelect *selectWidget( QWidget *parent, Qt::WindowFlags fl )
QGISEXTERN QgsWMSSourceSelect *selectWidget( QWidget *parent, Qt::WindowFlags fl, bool embeddedMode )
{
return new QgsWMSSourceSelect( parent, fl );
return new QgsWMSSourceSelect( parent, fl, embeddedMode );
}


@@ -54,7 +54,7 @@
#include <QNetworkRequest>
#include <QNetworkReply>

QgsWMSSourceSelect::QgsWMSSourceSelect( QWidget *parent, Qt::WindowFlags fl, bool managerMode, bool embeddedMode )
QgsWMSSourceSelect::QgsWMSSourceSelect( QWidget *parent, Qt::WindowFlags fl, bool embeddedMode, bool managerMode )
: QDialog( parent, fl )
, mManagerMode( managerMode )
, mEmbeddedMode( embeddedMode )
@@ -63,7 +63,7 @@ QgsWMSSourceSelect::QgsWMSSourceSelect( QWidget *parent, Qt::WindowFlags fl, boo
{
setupUi( this );

if ( mEmbeddedMode || ( Qt::Widget == fl ) )
if ( mEmbeddedMode )
{
// For some osbscure reson hiding does not work!
// buttonBox->button( QDialogButtonBox::Close )->hide();
@@ -48,7 +48,7 @@ class QgsWMSSourceSelect : public QDialog, private Ui::QgsWMSSourceSelectBase

public:
//! Constructor
QgsWMSSourceSelect( QWidget *parent = nullptr, Qt::WindowFlags fl = QgsGuiUtils::ModalDialogFlags, bool managerMode = false, bool embeddedMode = false );
QgsWMSSourceSelect( QWidget *parent = nullptr, Qt::WindowFlags fl = QgsGuiUtils::ModalDialogFlags, bool embeddedMode = false, bool managerMode = false );

~QgsWMSSourceSelect();

0 comments on commit 129e00d

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