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
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,19 @@ Destructor
The default implementation does nothing
%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:

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
%End

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


protected:

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;
%Docstring
Return the map canvas (can be null)
Return the map canvas (can be null)
:rtype: QgsMapCanvas
%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
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,6 @@ Loads connections from the file
Once connected, available layers are displayed.
%End

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

void searchFinished();

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 );
%Docstring
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
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,10 @@
#include "qgsapplication.h"

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

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 );
setupButtons( buttonBox );

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



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

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


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

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

#define SIP_NO_FILE
Expand All @@ -32,7 +33,7 @@
* file, database, directory and protocol sources.
* \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

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

public slots:
void addButtonClicked() override;

private slots:
//! 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
void setSelectedConnection();

void accept() override;

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

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

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

}

QgsProviderRegistry::WidgetMode QgsAbstractDataSourceWidget::widgetMode() const
Expand All @@ -35,8 +35,40 @@ const QgsMapCanvas *QgsAbstractDataSourceWidget::mapCanvas() const
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 )
{
mMapCanvas = mapCanvas;
}

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

class QgsMapCanvas;

Expand Down Expand Up @@ -58,6 +59,17 @@ class GUI_EXPORT QgsAbstractDataSourceWidget : public QDialog
*/
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:

/** 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
void progressMessage( QString message );

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


protected:

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

/** Return the map canvas (can be null)
*/
//! Return the map canvas (can be null)
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;
QgsMapCanvas const *mMapCanvas = nullptr;

Expand Down
3 changes: 2 additions & 1 deletion src/gui/qgsdatasourcemanagerdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ QgsAbstractDataSourceWidget *QgsDataSourceManagerDialog::providerDialog( const Q
dlg->setMapCanvas( mMapCanvas );
}
connect( dlg, &QgsAbstractDataSourceWidget::rejected, this, &QgsDataSourceManagerDialog::reject );
connect( dlg, &QgsAbstractDataSourceWidget::accepted, this, &QgsDataSourceManagerDialog::accept );
return dlg;
}
}
Expand All @@ -208,7 +209,7 @@ void QgsDataSourceManagerDialog::addDbProviderDialog( const QString providerKey,
connect( dlg, SIGNAL( progressMessage( QString ) ),
this, SIGNAL( showStatusMessage( QString ) ) );
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
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,11 @@ QgsOWSSourceSelect::QgsOWSSourceSelect( const QString &service, QWidget *parent,
, mCurrentTileset( nullptr )
{
setupUi( this );

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


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();

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

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

void QgsOWSSourceSelect::addClicked()
{
}

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

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

void searchFinished();

//! 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)
QString mLastLayerName;

QPushButton *mAddButton = nullptr;

QMap<QString, QString> mCrsNames;

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


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
btnLoad->hide();
btnSave->hide();
Expand Down
Loading

0 comments on commit 04059eb

Please sign in to comment.