Skip to content
Permalink
Browse files

[addlayerbutton] Use enum for window mode instead of booleans

  • Loading branch information
elpaso committed Jun 2, 2017
1 parent 402b7ad commit de5996c7dce3d43c1861f9623e92a74658618e1a
Showing with 154 additions and 122 deletions.
  1. +10 −1 python/core/qgsproviderregistry.sip
  2. +1 −1 python/gui/qgsowssourceselect.sip
  3. +4 −4 src/app/ogr/qgsopenvectorlayerdialog.cpp
  4. +3 −2 src/app/ogr/qgsopenvectorlayerdialog.h
  5. +2 −2 src/app/qgsdatasourcemanagerdialog.cpp
  6. +3 −3 src/core/qgsproviderregistry.cpp
  7. +12 −1 src/core/qgsproviderregistry.h
  8. +4 −5 src/gui/qgsowssourceselect.cpp
  9. +3 −2 src/gui/qgsowssourceselect.h
  10. +5 −1 src/gui/qgssourceselectdialog.cpp
  11. +1 −0 src/gui/qgssourceselectdialog.h
  12. +1 −1 src/providers/arcgisrest/qgsafsdataitems.cpp
  13. +2 −2 src/providers/arcgisrest/qgsafsproviderextern.cpp
  14. +2 −2 src/providers/arcgisrest/qgsafssourceselect.cpp
  15. +3 −2 src/providers/arcgisrest/qgsafssourceselect.h
  16. +2 −1 src/providers/arcgisrest/qgsamsdataitems.cpp
  17. +2 −2 src/providers/arcgisrest/qgsamsproviderextern.cpp
  18. +2 −2 src/providers/arcgisrest/qgsamssourceselect.cpp
  19. +2 −1 src/providers/arcgisrest/qgsamssourceselect.h
  20. +2 −2 src/providers/db2/qgsdb2provider.cpp
  21. +4 −5 src/providers/db2/qgsdb2sourceselect.cpp
  22. +3 −2 src/providers/db2/qgsdb2sourceselect.h
  23. +3 −2 src/providers/delimitedtext/qgsdelimitedtextprovider.cpp
  24. +1 −1 src/providers/mssql/qgsmssqldataitems.cpp
  25. +2 −2 src/providers/mssql/qgsmssqlprovider.cpp
  26. +4 −5 src/providers/mssql/qgsmssqlsourceselect.cpp
  27. +3 −2 src/providers/mssql/qgsmssqlsourceselect.h
  28. +2 −2 src/providers/oracle/qgsoracleprovider.cpp
  29. +3 −3 src/providers/oracle/qgsoraclesourceselect.cpp
  30. +2 −2 src/providers/oracle/qgsoraclesourceselect.h
  31. +3 −3 src/providers/ows/qgsowsdataitems.cpp
  32. +5 −6 src/providers/postgres/qgspgsourceselect.cpp
  33. +3 −5 src/providers/postgres/qgspgsourceselect.h
  34. +1 −1 src/providers/postgres/qgspostgresdataitems.cpp
  35. +2 −2 src/providers/postgres/qgspostgresprovider.cpp
  36. +3 −3 src/providers/spatialite/qgsspatialitedataitems.cpp
  37. +5 −4 src/providers/spatialite/qgsspatialitesourceselect.cpp
  38. +3 −2 src/providers/spatialite/qgsspatialitesourceselect.h
  39. +5 −4 src/providers/virtual/qgsvirtuallayersourceselect.cpp
  40. +4 −2 src/providers/virtual/qgsvirtuallayersourceselect.h
  41. +3 −3 src/providers/wcs/qgswcsdataitems.cpp
  42. +2 −2 src/providers/wcs/qgswcssourceselect.cpp
  43. +2 −2 src/providers/wcs/qgswcssourceselect.h
  44. +3 −3 src/providers/wfs/qgswfsdataitems.cpp
  45. +4 −4 src/providers/wfs/qgswfssourceselect.cpp
  46. +3 −2 src/providers/wfs/qgswfssourceselect.h
  47. +3 −3 src/providers/wms/qgswmsdataitems.cpp
  48. +4 −5 src/providers/wms/qgswmssourceselect.cpp
  49. +3 −3 src/providers/wms/qgswmssourceselect.h
@@ -35,6 +35,13 @@ class QgsProviderRegistry
%End
public:

enum WidgetMode
{
None,
Embedded,
Manager,
};

static QgsProviderRegistry *instance( const QString &pluginPath = QString::null );
%Docstring
Means of accessing canonical single instance
@@ -88,7 +95,9 @@ Set library directory where to search for plugins
%End

QWidget *createSelectionWidget( const QString &providerKey,
QWidget *parent = 0, Qt::WindowFlags fl = Qt::WindowFlags(), bool embeddedMode = false );
QWidget *parent = 0,
Qt::WindowFlags fl = Qt::WindowFlags(),
QgsProviderRegistry::WidgetMode widgetMode = QgsProviderRegistry::WidgetMode::None );
%Docstring
Returns a new widget for selecting layers from a provider.
Either the ``parent`` widget must be set or the caller becomes
@@ -23,7 +23,7 @@ class QgsOWSSourceSelect : QDialog
};

//! Constructor
QgsOWSSourceSelect( const QString &service, QWidget *parent /TransferThis/ = 0, const Qt::WindowFlags &fl = QgsGuiUtils::ModalDialogFlags, bool managerMode = false, bool embeddedMode = false );
QgsOWSSourceSelect( const QString &service, QWidget *parent /TransferThis/ = 0, const Qt::WindowFlags &fl = QgsGuiUtils::ModalDialogFlags, QgsProviderRegistry::WidgetMode widgetMode = QgsProviderRegistry::WidgetMode::None);
//! Destructor
~QgsOWSSourceSelect();

@@ -31,13 +31,13 @@
#include "qgscontexthelp.h"
#include "qgsapplication.h"

QgsOpenVectorLayerDialog::QgsOpenVectorLayerDialog( QWidget *parent, Qt::WindowFlags fl, bool embeddedMode )
QgsOpenVectorLayerDialog::QgsOpenVectorLayerDialog( QWidget *parent, Qt::WindowFlags fl, QgsProviderRegistry::WidgetMode widgetMode )
: QDialog( parent, fl ),
mEmbeddedMode( embeddedMode )
mWidgetMode( widgetMode )
{
setupUi( this );

if ( mEmbeddedMode )
if ( mWidgetMode != QgsProviderRegistry::WidgetMode::None )
{
buttonBox->removeButton( buttonBox->button( QDialogButtonBox::Cancel ) );
}
@@ -387,7 +387,7 @@ void QgsOpenVectorLayerDialog::accept()
// Save the used encoding
settings.setValue( QStringLiteral( "UI/encoding" ), encoding() );

if ( ! mEmbeddedMode )
if ( mWidgetMode == QgsProviderRegistry::WidgetMode::None )
{
QDialog::accept();
}
@@ -22,6 +22,7 @@
#include <ui_qgsopenvectorlayerdialogbase.h>
#include <QDialog>
#include "qgshelp.h"
#include "qgsproviderregistry.h"

/**
* Class for a dialog to select the type and source for ogr vectors, supports
@@ -32,7 +33,7 @@ class QgsOpenVectorLayerDialog : public QDialog, private Ui::QgsOpenVectorLayerD
Q_OBJECT

public:
QgsOpenVectorLayerDialog( QWidget *parent = nullptr, Qt::WindowFlags fl = 0, bool embeddedMode = false );
QgsOpenVectorLayerDialog( QWidget *parent = nullptr, Qt::WindowFlags fl = 0, QgsProviderRegistry::WidgetMode widgetMode = QgsProviderRegistry::WidgetMode::None );
~QgsOpenVectorLayerDialog();
//! Opens a dialog to select a file datasource*/
QStringList openFile();
@@ -54,7 +55,7 @@ class QgsOpenVectorLayerDialog : public QDialog, private Ui::QgsOpenVectorLayerD
//! Stores the datasource type
QString mDataSourceType;
//! Embedded dialog (do not call parent's accept) and emit signals
bool mEmbeddedMode;
QgsProviderRegistry::WidgetMode mWidgetMode = QgsProviderRegistry::WidgetMode::None;

private slots:
//! Opens the create connection dialog to build a new connection
@@ -48,7 +48,7 @@ QgsDataSourceManagerDialog::QgsDataSourceManagerDialog( QgsMapCanvas *mapCanvas,
ui->mOptionsStackedWidget->addWidget( mBrowserWidget );

// VECTOR Layers (completely different interface: it's not a provider)
QgsOpenVectorLayerDialog *ovl = new QgsOpenVectorLayerDialog( this, Qt::Widget, true );
QgsOpenVectorLayerDialog *ovl = new QgsOpenVectorLayerDialog( this, Qt::Widget, QgsProviderRegistry::WidgetMode::Embedded );
ui->mOptionsStackedWidget->addWidget( ovl );
QListWidgetItem *ogrItem = new QListWidgetItem( tr( "Vector files" ), ui->mOptionsListWidget );
ogrItem->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddOgrLayer.svg" ) ) );
@@ -129,7 +129,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, true ) );
QDialog *dlg = dynamic_cast<QDialog *>( QgsProviderRegistry::instance()->createSelectionWidget( providerKey, this, Qt::Widget, QgsProviderRegistry::WidgetMode::Embedded ) );
if ( !dlg )
{
QMessageBox::warning( this, providerName, tr( "Cannot get %1 select dialog from provider %2." ).arg( providerName, providerKey ) );
@@ -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, bool embeddedMode );
typedef QWidget *selectFactoryFunction_t( QWidget *parent, Qt::WindowFlags fl, QgsProviderRegistry::WidgetMode widgetMode );

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

if ( !selectFactory )
return nullptr;

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

QFunctionPointer QgsProviderRegistry::function( QString const &providerKey,
@@ -53,6 +53,15 @@ class CORE_EXPORT QgsProviderRegistry

public:

//! Different ways a source select dialog can be used
//! (embedded is for the data source manager dialog)
enum WidgetMode
{
None,
Embedded,
Manager,
};

//! Means of accessing canonical single instance
static QgsProviderRegistry *instance( const QString &pluginPath = QString::null );

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

/**
* Get pointer to provider function
@@ -54,16 +54,15 @@
#include <QNetworkRequest>
#include <QNetworkReply>

QgsOWSSourceSelect::QgsOWSSourceSelect( const QString &service, QWidget *parent, Qt::WindowFlags fl, bool embeddedMode, bool managerMode )
QgsOWSSourceSelect::QgsOWSSourceSelect( const QString &service, QWidget *parent, Qt::WindowFlags fl, QgsProviderRegistry::WidgetMode widgetMode )
: QDialog( parent, fl )
, mService( service )
, mManagerMode( managerMode )
, mEmbeddedMode( embeddedMode )
, mWidgetMode( widgetMode )
, mCurrentTileset( nullptr )
{
setupUi( this );

if ( mEmbeddedMode )
if ( mWidgetMode != QgsProviderRegistry::WidgetMode::None )
{
buttonBox->removeButton( buttonBox->button( QDialogButtonBox::Close ) );
}
@@ -90,7 +89,7 @@ QgsOWSSourceSelect::QgsOWSSourceSelect( const QString &service, QWidget *parent,
// 'Prefer network' is the default noted in the combobox's tool tip
mCacheComboBox->setCurrentIndex( mCacheComboBox->findData( QNetworkRequest::PreferNetwork ) );

if ( !mManagerMode )
if ( mWidgetMode != QgsProviderRegistry::WidgetMode::Manager )
{
connect( mAddButton, &QAbstractButton::clicked, this, &QgsOWSSourceSelect::addClicked );
//set the current project CRS if available
@@ -25,6 +25,7 @@
#include "qgsdatasourceuri.h"
#include "qgsguiutils.h"
#include "qgscontexthelp.h"
#include "qgsproviderregistry.h"

#include <QStringList>
#include <QPushButton>
@@ -60,7 +61,7 @@ class GUI_EXPORT QgsOWSSourceSelect : public QDialog, public Ui::QgsOWSSourceSel
};

//! Constructor
QgsOWSSourceSelect( const QString &service, QWidget *parent = nullptr, Qt::WindowFlags fl = QgsGuiUtils::ModalDialogFlags, bool embeddedMode = false, bool managerMode = false );
QgsOWSSourceSelect( const QString &service, QWidget *parent = nullptr, Qt::WindowFlags fl = QgsGuiUtils::ModalDialogFlags, QgsProviderRegistry::WidgetMode widgetMode = QgsProviderRegistry::WidgetMode::None );

~QgsOWSSourceSelect();

@@ -172,7 +173,7 @@ class GUI_EXPORT QgsOWSSourceSelect : public QDialog, public Ui::QgsOWSSourceSel
bool mManagerMode;

//! Embedded mode, without 'Close'
bool mEmbeddedMode;
QgsProviderRegistry::WidgetMode mWidgetMode = QgsProviderRegistry::WidgetMode::None;


/**
@@ -50,7 +50,11 @@ class QgsSourceSelectItemDelegate : public QItemDelegate


QgsSourceSelectDialog::QgsSourceSelectDialog( const QString &serviceName, ServiceType serviceType, QWidget *parent, Qt::WindowFlags fl )
: QDialog( parent, fl ), mServiceName( serviceName ), mServiceType( serviceType ), mBuildQueryButton( 0 ), mImageEncodingGroup( 0 )
: QDialog( parent, fl ),
mServiceName( serviceName ),
mServiceType( serviceType ),
mBuildQueryButton( 0 ),
mImageEncodingGroup( 0 )
{
setupUi( this );
setWindowTitle( QStringLiteral( "Add %1 Layer from a Server" ).arg( mServiceName ) );
@@ -19,6 +19,7 @@
#include "ui_qgssourceselectdialogbase.h"
#include "qgsrectangle.h"
#include "qgscoordinatereferencesystem.h"

#include "qgis_gui.h"

class QStandardItemModel;
@@ -55,7 +55,7 @@ QList<QAction *> QgsAfsRootItem::actions()

QWidget *QgsAfsRootItem::paramWidget()
{
QgsAfsSourceSelect *select = new QgsAfsSourceSelect( 0, 0, true );
QgsAfsSourceSelect *select = new QgsAfsSourceSelect( 0, 0, QgsProviderRegistry::WidgetMode::Manager );
connect( select, &QgsSourceSelectDialog::connectionsChanged, this, &QgsAfsRootItem::connectionsChanged );
return select;
}
@@ -45,9 +45,9 @@ QGISEXTERN bool isProvider()
return true;
}

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

QGISEXTERN int dataCapabilities()
@@ -26,10 +26,10 @@
#include <QMessageBox>


QgsAfsSourceSelect::QgsAfsSourceSelect( QWidget *parent, Qt::WindowFlags fl, bool embeddedMode )
QgsAfsSourceSelect::QgsAfsSourceSelect( QWidget *parent, Qt::WindowFlags fl, QgsProviderRegistry::WidgetMode widgetMode )
: QgsSourceSelectDialog( QStringLiteral( "ArcGisFeatureServer" ), QgsSourceSelectDialog::FeatureService, parent, fl )
{
if ( embeddedMode )
if ( widgetMode == QgsProviderRegistry::WidgetMode::Embedded || widgetMode == QgsProviderRegistry::WidgetMode::Manager )
{
buttonBox->removeButton( buttonBox->button( QDialogButtonBox::Close ) );
}
@@ -18,6 +18,8 @@
#ifndef QGSAFSSOURCESELECT_H
#define QGSAFSSOURCESELECT_H

#include "qgsguiutils.h"
#include "qgsproviderregistry.h"
#include "qgssourceselectdialog.h"

class QCheckBox;
@@ -27,8 +29,7 @@ class QgsAfsSourceSelect: public QgsSourceSelectDialog
Q_OBJECT

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

QgsAfsSourceSelect( QWidget *parent, Qt::WindowFlags fl = QgsGuiUtils::ModalDialogFlags, QgsProviderRegistry::WidgetMode widgetMode = QgsProviderRegistry::WidgetMode::None );
protected:
bool connectToService( const QgsOwsConnection &connection ) override;
void buildQuery( const QgsOwsConnection &connection, const QModelIndex & ) override;
@@ -19,6 +19,7 @@
#include "qgsarcgisrestutils.h"
#include "qgsnewhttpconnection.h"
#include "qgsowsconnection.h"
#include "qgsproviderregistry.h"

#include <QImageReader>

@@ -53,7 +54,7 @@ QList<QAction *> QgsAmsRootItem::actions()

QWidget *QgsAmsRootItem::paramWidget()
{
QgsAmsSourceSelect *select = new QgsAmsSourceSelect( 0, 0, true );
QgsAmsSourceSelect *select = new QgsAmsSourceSelect( 0, 0, QgsProviderRegistry::WidgetMode::Manager );
connect( select, &QgsSourceSelectDialog::connectionsChanged, this, &QgsAmsRootItem::connectionsChanged );
return select;
}
@@ -45,9 +45,9 @@ QGISEXTERN bool isProvider()
return true;
}

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

QGISEXTERN int dataCapabilities()
@@ -25,10 +25,10 @@
#include <QMessageBox>


QgsAmsSourceSelect::QgsAmsSourceSelect( QWidget *parent, Qt::WindowFlags fl, bool embeddedMode )
QgsAmsSourceSelect::QgsAmsSourceSelect( QWidget *parent, Qt::WindowFlags fl, QgsProviderRegistry::WidgetMode widgetMode )
: QgsSourceSelectDialog( QStringLiteral( "ArcGisMapServer" ), QgsSourceSelectDialog::MapService, parent, fl )
{
if ( embeddedMode )
if ( widgetMode == QgsProviderRegistry::WidgetMode::Embedded || widgetMode == QgsProviderRegistry::WidgetMode::Manager )
{
buttonBox->removeButton( buttonBox->button( QDialogButtonBox::Close ) );
}
@@ -19,6 +19,7 @@
#define QGSAMSSOURCESELECT_H

#include "qgssourceselectdialog.h"
#include "qgsproviderregistry.h"

class QCheckBox;

@@ -27,7 +28,7 @@ class QgsAmsSourceSelect: public QgsSourceSelectDialog
Q_OBJECT

public:
QgsAmsSourceSelect( QWidget *parent, Qt::WindowFlags fl, bool embeddedMode = false );
QgsAmsSourceSelect( QWidget *parent, Qt::WindowFlags fl, QgsProviderRegistry::WidgetMode widgetMode = QgsProviderRegistry::WidgetMode::None );

protected:
bool connectToService( const QgsOwsConnection &connection ) override;
@@ -1711,9 +1711,9 @@ QGISEXTERN int dataCapabilities()
return QgsDataProvider::Database;
}

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

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

QgsDb2SourceSelect::QgsDb2SourceSelect( QWidget *parent, Qt::WindowFlags fl, bool embeddedMode, bool managerMode )
QgsDb2SourceSelect::QgsDb2SourceSelect( QWidget *parent, Qt::WindowFlags fl, QgsProviderRegistry::WidgetMode widgetMode )
: QDialog( parent, fl )
, mManagerMode( managerMode )
, mEmbeddedMode( embeddedMode )
, mWidgetMode( widgetMode )
, mColumnTypeThread( NULL )
, mUseEstimatedMetadata( false )
{
setupUi( this );

setWindowTitle( tr( "Add Db2 Table(s)" ) );

if ( mEmbeddedMode )
if ( mWidgetMode != QgsProviderRegistry::WidgetMode::None )
{
buttonBox->removeButton( buttonBox->button( QDialogButtonBox::Close ) );
mHoldDialogOpen->hide();
@@ -140,7 +139,7 @@ QgsDb2SourceSelect::QgsDb2SourceSelect( QWidget *parent, Qt::WindowFlags fl, boo
mBuildQueryButton->setToolTip( tr( "Set Filter" ) );
mBuildQueryButton->setDisabled( true );

if ( !mManagerMode )
if ( mWidgetMode != QgsProviderRegistry::WidgetMode::Manager )
{
buttonBox->addButton( mAddButton, QDialogButtonBox::ActionRole );
connect( mAddButton, &QAbstractButton::clicked, this, &QgsDb2SourceSelect::addTables );

0 comments on commit de5996c

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