Skip to content

Commit

Permalink
Merge pull request #4962 from boundlessgeo/unified-layer-dialog-mods
Browse files Browse the repository at this point in the history
Unified layer dialog mods
  • Loading branch information
elpaso committed Aug 4, 2017
2 parents 5e2b17a + fef3bc0 commit 04059eb
Show file tree
Hide file tree
Showing 42 changed files with 195 additions and 239 deletions.
32 changes: 31 additions & 1 deletion python/gui/qgsabstractdatasourcewidget.sip
Expand Up @@ -46,6 +46,19 @@ Destructor
The default implementation does nothing The default implementation does nothing
%End %End


virtual void addButtonClicked();
%Docstring
Triggered when the add button is clicked, the add layer signal is emitted
Concrete classes should implement the right behavior depending on the layer
being added.
%End

virtual void okButtonClicked();
%Docstring
Triggered when the dialog is accepted, call addButtonClicked() and
emit the accepted() signal
%End

signals: signals:


void connectionsChanged(); void connectionsChanged();
Expand Down Expand Up @@ -79,6 +92,12 @@ Emitted when a progress dialog is shown by the provider dialog
Emitted when a progress dialog is shown by the provider dialog Emitted when a progress dialog is shown by the provider dialog
%End %End


void enableButtons( bool enable );
%Docstring
Emitted when the ok/add buttons should be enabled/disabled
%End


protected: protected:


QgsAbstractDataSourceWidget( QWidget *parent /TransferThis/ = 0, Qt::WindowFlags fl = QgsGuiUtils::ModalDialogFlags, QgsProviderRegistry::WidgetMode widgetMode = QgsProviderRegistry::WidgetMode::None ); QgsAbstractDataSourceWidget( QWidget *parent /TransferThis/ = 0, Qt::WindowFlags fl = QgsGuiUtils::ModalDialogFlags, QgsProviderRegistry::WidgetMode widgetMode = QgsProviderRegistry::WidgetMode::None );
Expand All @@ -94,10 +113,21 @@ Return the widget mode


const QgsMapCanvas *mapCanvas() const; const QgsMapCanvas *mapCanvas() const;
%Docstring %Docstring
Return the map canvas (can be null) Return the map canvas (can be null)
:rtype: QgsMapCanvas :rtype: QgsMapCanvas
%End %End


void setupButtons( QDialogButtonBox *buttonBox );
%Docstring
Connect the ok and apply/add buttons to the slots
%End

QPushButton *addButton( ) const;
%Docstring
Return the add Button
:rtype: QPushButton
%End

}; };


/************************************************************************ /************************************************************************
Expand Down
6 changes: 0 additions & 6 deletions python/gui/qgsowssourceselect.sip
Expand Up @@ -75,11 +75,6 @@ Loads connections from the file
Once connected, available layers are displayed. Once connected, available layers are displayed.
%End %End


virtual void addClicked();
%Docstring
Determines the layers the user selected
%End

void searchFinished(); void searchFinished();


void on_mChangeCRSButton_clicked(); void on_mChangeCRSButton_clicked();
Expand Down Expand Up @@ -214,7 +209,6 @@ Returns a textual description for the authority id







void addWmsListRow( const QDomElement &item, int row ); void addWmsListRow( const QDomElement &item, int row );
%Docstring %Docstring
layer name derived from latest layer selection (updated as long it's not edited manually) layer name derived from latest layer selection (updated as long it's not edited manually)
Expand Down
30 changes: 8 additions & 22 deletions src/gui/ogr/qgsopenvectorlayerdialog.cpp
Expand Up @@ -32,22 +32,10 @@
#include "qgsapplication.h" #include "qgsapplication.h"


QgsOpenVectorLayerDialog::QgsOpenVectorLayerDialog( QWidget *parent, Qt::WindowFlags fl, QgsProviderRegistry::WidgetMode widgetMode ) QgsOpenVectorLayerDialog::QgsOpenVectorLayerDialog( QWidget *parent, Qt::WindowFlags fl, QgsProviderRegistry::WidgetMode widgetMode )
: QDialog( parent, fl ), : QgsAbstractDataSourceWidget( parent, fl, widgetMode )
mWidgetMode( widgetMode ),
mAddButton( nullptr )
{ {
setupUi( this ); setupUi( this );

setupButtons( buttonBox );
if ( mWidgetMode != QgsProviderRegistry::WidgetMode::None )
{
this->layout()->setSizeConstraint( QLayout::SetNoConstraint );
buttonBox->removeButton( buttonBox->button( QDialogButtonBox::Cancel ) );
}

mAddButton = new QPushButton( tr( "&Add" ) );
// TODO: enable/disable according to valid selection
mAddButton->setEnabled( true );
buttonBox->addButton( mAddButton, QDialogButtonBox::AcceptRole );


cmbDatabaseTypes->blockSignals( true ); cmbDatabaseTypes->blockSignals( true );
cmbConnections->blockSignals( true ); cmbConnections->blockSignals( true );
Expand Down Expand Up @@ -287,7 +275,7 @@ void QgsOpenVectorLayerDialog::on_buttonSelectSrc_clicked()
if ( !selected.isEmpty() ) if ( !selected.isEmpty() )
{ {
inputSrcDataset->setText( selected.join( QStringLiteral( ";" ) ) ); inputSrcDataset->setText( selected.join( QStringLiteral( ";" ) ) );
mAddButton->setFocus(); addButton()->setFocus();
} }
} }
else if ( radioSrcDirectory->isChecked() ) else if ( radioSrcDirectory->isChecked() )
Expand All @@ -302,8 +290,7 @@ void QgsOpenVectorLayerDialog::on_buttonSelectSrc_clicked()






//********************auto connected slots *****************/ void QgsOpenVectorLayerDialog::addButtonClicked()
void QgsOpenVectorLayerDialog::accept()
{ {
QgsSettings settings; QgsSettings settings;
QgsDebugMsg( "dialog button accepted" ); QgsDebugMsg( "dialog button accepted" );
Expand Down Expand Up @@ -395,16 +382,15 @@ void QgsOpenVectorLayerDialog::accept()
// Save the used encoding // Save the used encoding
settings.setValue( QStringLiteral( "UI/encoding" ), encoding() ); settings.setValue( QStringLiteral( "UI/encoding" ), encoding() );


if ( mWidgetMode == QgsProviderRegistry::WidgetMode::None ) if ( ! mDataSources.isEmpty() )
{
QDialog::accept();
}
else if ( ! mDataSources.isEmpty() )
{ {
emit addVectorLayers( mDataSources, encoding(), dataSourceType() ); emit addVectorLayers( mDataSources, encoding(), dataSourceType() );
} }
} }



//********************auto connected slots *****************/

void QgsOpenVectorLayerDialog::on_radioSrcFile_toggled( bool checked ) void QgsOpenVectorLayerDialog::on_radioSrcFile_toggled( bool checked )
{ {
if ( checked ) if ( checked )
Expand Down
10 changes: 5 additions & 5 deletions src/gui/ogr/qgsopenvectorlayerdialog.h
Expand Up @@ -23,6 +23,7 @@
#include <QDialog> #include <QDialog>
#include "qgshelp.h" #include "qgshelp.h"
#include "qgsproviderregistry.h" #include "qgsproviderregistry.h"
#include "qgsabstractdatasourcewidget.h"
#include "qgis_gui.h" #include "qgis_gui.h"


#define SIP_NO_FILE #define SIP_NO_FILE
Expand All @@ -32,7 +33,7 @@
* file, database, directory and protocol sources. * file, database, directory and protocol sources.
* \note not available in Python bindings * \note not available in Python bindings
*/ */
class GUI_EXPORT QgsOpenVectorLayerDialog : public QDialog, private Ui::QgsOpenVectorLayerDialogBase class GUI_EXPORT QgsOpenVectorLayerDialog : public QgsAbstractDataSourceWidget, private Ui::QgsOpenVectorLayerDialogBase
{ {
Q_OBJECT Q_OBJECT


Expand Down Expand Up @@ -60,8 +61,9 @@ class GUI_EXPORT QgsOpenVectorLayerDialog : public QDialog, private Ui::QgsOpenV
QString mDataSourceType; QString mDataSourceType;
//! Embedded dialog (do not call parent's accept) and emit signals //! Embedded dialog (do not call parent's accept) and emit signals
QgsProviderRegistry::WidgetMode mWidgetMode = QgsProviderRegistry::WidgetMode::None; QgsProviderRegistry::WidgetMode mWidgetMode = QgsProviderRegistry::WidgetMode::None;
//! Add layer button
QPushButton *mAddButton = nullptr; public slots:
void addButtonClicked() override;


private slots: private slots:
//! Opens the create connection dialog to build a new connection //! Opens the create connection dialog to build a new connection
Expand All @@ -81,8 +83,6 @@ class GUI_EXPORT QgsOpenVectorLayerDialog : public QDialog, private Ui::QgsOpenV
//! Sets the selected connection //! Sets the selected connection
void setSelectedConnection(); void setSelectedConnection();


void accept() override;

void on_buttonSelectSrc_clicked(); void on_buttonSelectSrc_clicked();
void on_radioSrcFile_toggled( bool checked ); void on_radioSrcFile_toggled( bool checked );
void on_radioSrcDirectory_toggled( bool checked ); void on_radioSrcDirectory_toggled( bool checked );
Expand Down
34 changes: 33 additions & 1 deletion src/gui/qgsabstractdatasourcewidget.cpp
Expand Up @@ -17,12 +17,12 @@
***************************************************************************/ ***************************************************************************/


#include "qgsabstractdatasourcewidget.h" #include "qgsabstractdatasourcewidget.h"
#include <QPushButton>


QgsAbstractDataSourceWidget::QgsAbstractDataSourceWidget( QWidget *parent, Qt::WindowFlags fl, QgsProviderRegistry::WidgetMode widgetMode ): QgsAbstractDataSourceWidget::QgsAbstractDataSourceWidget( QWidget *parent, Qt::WindowFlags fl, QgsProviderRegistry::WidgetMode widgetMode ):
QDialog( parent, fl ), QDialog( parent, fl ),
mWidgetMode( widgetMode ) mWidgetMode( widgetMode )
{ {

} }


QgsProviderRegistry::WidgetMode QgsAbstractDataSourceWidget::widgetMode() const QgsProviderRegistry::WidgetMode QgsAbstractDataSourceWidget::widgetMode() const
Expand All @@ -35,8 +35,40 @@ const QgsMapCanvas *QgsAbstractDataSourceWidget::mapCanvas() const
return mMapCanvas; return mMapCanvas;
} }


void QgsAbstractDataSourceWidget::setupButtons( QDialogButtonBox *buttonBox )
{

if ( mWidgetMode == QgsProviderRegistry::WidgetMode::None )
{
QPushButton *closeButton = new QPushButton( tr( "&Close" ) );
buttonBox->addButton( closeButton, QDialogButtonBox::ApplyRole );
connect( closeButton, &QPushButton::clicked, this, &QgsAbstractDataSourceWidget::addButtonClicked );
}

mAddButton = new QPushButton( tr( "&Add" ) );
mAddButton->setToolTip( tr( "Add selected layers to map" ) );
mAddButton->setEnabled( false );
buttonBox->addButton( mAddButton, QDialogButtonBox::ApplyRole );
connect( mAddButton, &QPushButton::clicked, this, &QgsAbstractDataSourceWidget::addButtonClicked );
connect( this, &QgsAbstractDataSourceWidget::enableButtons, mAddButton, &QPushButton::setEnabled );

QPushButton *okButton = new QPushButton( tr( "&Ok" ) );
okButton->setToolTip( tr( "Add selected layers to map and close this dialog" ) );
okButton->setEnabled( false );
buttonBox->addButton( okButton, QDialogButtonBox::AcceptRole );
connect( okButton, &QPushButton::clicked, this, &QgsAbstractDataSourceWidget::okButtonClicked );
connect( this, &QgsAbstractDataSourceWidget::enableButtons, okButton, &QPushButton::setEnabled );

}



void QgsAbstractDataSourceWidget::setMapCanvas( const QgsMapCanvas *mapCanvas ) void QgsAbstractDataSourceWidget::setMapCanvas( const QgsMapCanvas *mapCanvas )
{ {
mMapCanvas = mapCanvas; mMapCanvas = mapCanvas;
} }

void QgsAbstractDataSourceWidget::okButtonClicked()
{
addButtonClicked();
emit accepted();
}
27 changes: 24 additions & 3 deletions src/gui/qgsabstractdatasourcewidget.h
Expand Up @@ -26,6 +26,7 @@
#include "qgsproviderregistry.h" #include "qgsproviderregistry.h"
#include "qgsguiutils.h" #include "qgsguiutils.h"
#include <QDialog> #include <QDialog>
#include <QDialogButtonBox>


class QgsMapCanvas; class QgsMapCanvas;


Expand Down Expand Up @@ -58,6 +59,17 @@ class GUI_EXPORT QgsAbstractDataSourceWidget : public QDialog
*/ */
virtual void refresh() {} virtual void refresh() {}


/** Triggered when the add button is clicked, the add layer signal is emitted
* Concrete classes should implement the right behavior depending on the layer
* being added.
*/
virtual void addButtonClicked() { }

/** Triggered when the dialog is accepted, call addButtonClicked() and
* emit the accepted() signal
*/
virtual void okButtonClicked();

signals: signals:


/** Emitted when the provider's connections have changed /** Emitted when the provider's connections have changed
Expand All @@ -80,6 +92,10 @@ class GUI_EXPORT QgsAbstractDataSourceWidget : public QDialog
//! Emitted when a progress dialog is shown by the provider dialog //! Emitted when a progress dialog is shown by the provider dialog
void progressMessage( QString message ); void progressMessage( QString message );


//! Emitted when the ok/add buttons should be enabled/disabled
void enableButtons( bool enable );


protected: protected:


//! Constructor //! Constructor
Expand All @@ -88,12 +104,17 @@ class GUI_EXPORT QgsAbstractDataSourceWidget : public QDialog
//! Return the widget mode //! Return the widget mode
QgsProviderRegistry::WidgetMode widgetMode() const; QgsProviderRegistry::WidgetMode widgetMode() const;


/** Return the map canvas (can be null) //! Return the map canvas (can be null)
*/
const QgsMapCanvas *mapCanvas() const; const QgsMapCanvas *mapCanvas() const;


private: //! Connect the ok and apply/add buttons to the slots
void setupButtons( QDialogButtonBox *buttonBox );


//! Return the add Button
QPushButton *addButton( ) const { return mAddButton; }

private:
QPushButton *mAddButton = nullptr;
QgsProviderRegistry::WidgetMode mWidgetMode; QgsProviderRegistry::WidgetMode mWidgetMode;
QgsMapCanvas const *mMapCanvas = nullptr; QgsMapCanvas const *mMapCanvas = nullptr;


Expand Down
3 changes: 2 additions & 1 deletion src/gui/qgsdatasourcemanagerdialog.cpp
Expand Up @@ -192,6 +192,7 @@ QgsAbstractDataSourceWidget *QgsDataSourceManagerDialog::providerDialog( const Q
dlg->setMapCanvas( mMapCanvas ); dlg->setMapCanvas( mMapCanvas );
} }
connect( dlg, &QgsAbstractDataSourceWidget::rejected, this, &QgsDataSourceManagerDialog::reject ); connect( dlg, &QgsAbstractDataSourceWidget::rejected, this, &QgsDataSourceManagerDialog::reject );
connect( dlg, &QgsAbstractDataSourceWidget::accepted, this, &QgsDataSourceManagerDialog::accept );
return dlg; return dlg;
} }
} }
Expand All @@ -208,7 +209,7 @@ void QgsDataSourceManagerDialog::addDbProviderDialog( const QString providerKey,
connect( dlg, SIGNAL( progressMessage( QString ) ), connect( dlg, SIGNAL( progressMessage( QString ) ),
this, SIGNAL( showStatusMessage( QString ) ) ); this, SIGNAL( showStatusMessage( QString ) ) );
connect( dlg, SIGNAL( connectionsChanged() ), this, SIGNAL( connectionsChanged() ) ); connect( dlg, SIGNAL( connectionsChanged() ), this, SIGNAL( connectionsChanged() ) );
connect( this, SIGNAL( providerDialogsRefreshRequested() ), dlg, SLOT( refresh() ) ); connect( this, SIGNAL( providerDialogsRefreshRequested() ), dlg, SLOT( refresh() ) );
} }
} }


Expand Down
17 changes: 1 addition & 16 deletions src/gui/qgsowssourceselect.cpp
Expand Up @@ -60,20 +60,11 @@ QgsOWSSourceSelect::QgsOWSSourceSelect( const QString &service, QWidget *parent,
, mCurrentTileset( nullptr ) , mCurrentTileset( nullptr )
{ {
setupUi( this ); setupUi( this );

setupButtons( buttonBox );
if ( widgetMode() != QgsProviderRegistry::WidgetMode::None )
{
buttonBox->removeButton( buttonBox->button( QDialogButtonBox::Close ) );
}




setWindowTitle( tr( "Add Layer(s) from a %1 Server" ).arg( service ) ); setWindowTitle( tr( "Add Layer(s) from a %1 Server" ).arg( service ) );


mAddButton = buttonBox->button( QDialogButtonBox::Apply );
mAddButton->setText( tr( "&Add" ) );
mAddButton->setToolTip( tr( "Add selected layers to map" ) );
mAddButton->setEnabled( false );

clearCrs(); clearCrs();


mTileWidthLineEdit->setValidator( new QIntValidator( 0, 9999, this ) ); mTileWidthLineEdit->setValidator( new QIntValidator( 0, 9999, this ) );
Expand All @@ -90,7 +81,6 @@ QgsOWSSourceSelect::QgsOWSSourceSelect( const QString &service, QWidget *parent,


if ( widgetMode() != QgsProviderRegistry::WidgetMode::Manager ) if ( widgetMode() != QgsProviderRegistry::WidgetMode::Manager )
{ {
connect( mAddButton, &QAbstractButton::clicked, this, &QgsOWSSourceSelect::addClicked );
//set the current project CRS if available //set the current project CRS if available
QgsCoordinateReferenceSystem currentRefSys = QgsProject::instance()->crs(); QgsCoordinateReferenceSystem currentRefSys = QgsProject::instance()->crs();
//convert CRS id to epsg //convert CRS id to epsg
Expand All @@ -106,7 +96,6 @@ QgsOWSSourceSelect::QgsOWSSourceSelect( const QString &service, QWidget *parent,
mTimeWidget->hide(); mTimeWidget->hide();
mFormatWidget->hide(); mFormatWidget->hide();
mCRSWidget->hide(); mCRSWidget->hide();
mAddButton->hide();
mCacheWidget->hide(); mCacheWidget->hide();
} }


Expand Down Expand Up @@ -361,10 +350,6 @@ void QgsOWSSourceSelect::on_mConnectButton_clicked()
QApplication::restoreOverrideCursor(); QApplication::restoreOverrideCursor();
} }


void QgsOWSSourceSelect::addClicked()
{
}

void QgsOWSSourceSelect::enableLayersForCrs( QTreeWidgetItem * ) void QgsOWSSourceSelect::enableLayersForCrs( QTreeWidgetItem * )
{ {
} }
Expand Down
5 changes: 0 additions & 5 deletions src/gui/qgsowssourceselect.h
Expand Up @@ -87,9 +87,6 @@ class GUI_EXPORT QgsOWSSourceSelect : public QgsAbstractDataSourceWidget, protec
*/ */
void on_mConnectButton_clicked(); void on_mConnectButton_clicked();


//! Determines the layers the user selected
virtual void addClicked();

void searchFinished(); void searchFinished();


//! Opens the Spatial Reference System dialog. //! Opens the Spatial Reference System dialog.
Expand Down Expand Up @@ -187,8 +184,6 @@ class GUI_EXPORT QgsOWSSourceSelect : public QgsAbstractDataSourceWidget, protec
//! layer name derived from latest layer selection (updated as long it's not edited manually) //! layer name derived from latest layer selection (updated as long it's not edited manually)
QString mLastLayerName; QString mLastLayerName;


QPushButton *mAddButton = nullptr;

QMap<QString, QString> mCrsNames; QMap<QString, QString> mCrsNames;


void addWmsListRow( const QDomElement &item, int row ); void addWmsListRow( const QDomElement &item, int row );
Expand Down
7 changes: 1 addition & 6 deletions src/providers/arcgisrest/qgsafssourceselect.cpp
Expand Up @@ -27,13 +27,8 @@




QgsAfsSourceSelect::QgsAfsSourceSelect( QWidget *parent, Qt::WindowFlags fl, QgsProviderRegistry::WidgetMode widgetMode ) QgsAfsSourceSelect::QgsAfsSourceSelect( QWidget *parent, Qt::WindowFlags fl, QgsProviderRegistry::WidgetMode widgetMode )
: QgsArcGisServiceSourceSelect( QStringLiteral( "ArcGisFeatureServer" ), QgsArcGisServiceSourceSelect::FeatureService, parent, fl ) : QgsArcGisServiceSourceSelect( QStringLiteral( "ArcGisFeatureServer" ), QgsArcGisServiceSourceSelect::FeatureService, parent, fl, widgetMode )
{ {
if ( widgetMode == QgsProviderRegistry::WidgetMode::Embedded || widgetMode == QgsProviderRegistry::WidgetMode::Manager )
{
buttonBox->removeButton( buttonBox->button( QDialogButtonBox::Close ) );
}

// import/export of connections not supported yet // import/export of connections not supported yet
btnLoad->hide(); btnLoad->hide();
btnSave->hide(); btnSave->hide();
Expand Down

0 comments on commit 04059eb

Please sign in to comment.