Skip to content

Commit 04059eb

Browse files
authored
Merge pull request #4962 from boundlessgeo/unified-layer-dialog-mods
Unified layer dialog mods
2 parents 5e2b17a + fef3bc0 commit 04059eb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+195
-239
lines changed

python/gui/qgsabstractdatasourcewidget.sip

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,19 @@ Destructor
4646
The default implementation does nothing
4747
%End
4848

49+
virtual void addButtonClicked();
50+
%Docstring
51+
Triggered when the add button is clicked, the add layer signal is emitted
52+
Concrete classes should implement the right behavior depending on the layer
53+
being added.
54+
%End
55+
56+
virtual void okButtonClicked();
57+
%Docstring
58+
Triggered when the dialog is accepted, call addButtonClicked() and
59+
emit the accepted() signal
60+
%End
61+
4962
signals:
5063

5164
void connectionsChanged();
@@ -79,6 +92,12 @@ Emitted when a progress dialog is shown by the provider dialog
7992
Emitted when a progress dialog is shown by the provider dialog
8093
%End
8194

95+
void enableButtons( bool enable );
96+
%Docstring
97+
Emitted when the ok/add buttons should be enabled/disabled
98+
%End
99+
100+
82101
protected:
83102

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

95114
const QgsMapCanvas *mapCanvas() const;
96115
%Docstring
97-
Return the map canvas (can be null)
116+
Return the map canvas (can be null)
98117
:rtype: QgsMapCanvas
99118
%End
100119

120+
void setupButtons( QDialogButtonBox *buttonBox );
121+
%Docstring
122+
Connect the ok and apply/add buttons to the slots
123+
%End
124+
125+
QPushButton *addButton( ) const;
126+
%Docstring
127+
Return the add Button
128+
:rtype: QPushButton
129+
%End
130+
101131
};
102132

103133
/************************************************************************

python/gui/qgsowssourceselect.sip

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,6 @@ Loads connections from the file
7575
Once connected, available layers are displayed.
7676
%End
7777

78-
virtual void addClicked();
79-
%Docstring
80-
Determines the layers the user selected
81-
%End
82-
8378
void searchFinished();
8479

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

215210

216211

217-
218212
void addWmsListRow( const QDomElement &item, int row );
219213
%Docstring
220214
layer name derived from latest layer selection (updated as long it's not edited manually)

src/gui/ogr/qgsopenvectorlayerdialog.cpp

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,10 @@
3232
#include "qgsapplication.h"
3333

3434
QgsOpenVectorLayerDialog::QgsOpenVectorLayerDialog( QWidget *parent, Qt::WindowFlags fl, QgsProviderRegistry::WidgetMode widgetMode )
35-
: QDialog( parent, fl ),
36-
mWidgetMode( widgetMode ),
37-
mAddButton( nullptr )
35+
: QgsAbstractDataSourceWidget( parent, fl, widgetMode )
3836
{
3937
setupUi( this );
40-
41-
if ( mWidgetMode != QgsProviderRegistry::WidgetMode::None )
42-
{
43-
this->layout()->setSizeConstraint( QLayout::SetNoConstraint );
44-
buttonBox->removeButton( buttonBox->button( QDialogButtonBox::Cancel ) );
45-
}
46-
47-
mAddButton = new QPushButton( tr( "&Add" ) );
48-
// TODO: enable/disable according to valid selection
49-
mAddButton->setEnabled( true );
50-
buttonBox->addButton( mAddButton, QDialogButtonBox::AcceptRole );
38+
setupButtons( buttonBox );
5139

5240
cmbDatabaseTypes->blockSignals( true );
5341
cmbConnections->blockSignals( true );
@@ -287,7 +275,7 @@ void QgsOpenVectorLayerDialog::on_buttonSelectSrc_clicked()
287275
if ( !selected.isEmpty() )
288276
{
289277
inputSrcDataset->setText( selected.join( QStringLiteral( ";" ) ) );
290-
mAddButton->setFocus();
278+
addButton()->setFocus();
291279
}
292280
}
293281
else if ( radioSrcDirectory->isChecked() )
@@ -302,8 +290,7 @@ void QgsOpenVectorLayerDialog::on_buttonSelectSrc_clicked()
302290

303291

304292

305-
//********************auto connected slots *****************/
306-
void QgsOpenVectorLayerDialog::accept()
293+
void QgsOpenVectorLayerDialog::addButtonClicked()
307294
{
308295
QgsSettings settings;
309296
QgsDebugMsg( "dialog button accepted" );
@@ -395,16 +382,15 @@ void QgsOpenVectorLayerDialog::accept()
395382
// Save the used encoding
396383
settings.setValue( QStringLiteral( "UI/encoding" ), encoding() );
397384

398-
if ( mWidgetMode == QgsProviderRegistry::WidgetMode::None )
399-
{
400-
QDialog::accept();
401-
}
402-
else if ( ! mDataSources.isEmpty() )
385+
if ( ! mDataSources.isEmpty() )
403386
{
404387
emit addVectorLayers( mDataSources, encoding(), dataSourceType() );
405388
}
406389
}
407390

391+
392+
//********************auto connected slots *****************/
393+
408394
void QgsOpenVectorLayerDialog::on_radioSrcFile_toggled( bool checked )
409395
{
410396
if ( checked )

src/gui/ogr/qgsopenvectorlayerdialog.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <QDialog>
2424
#include "qgshelp.h"
2525
#include "qgsproviderregistry.h"
26+
#include "qgsabstractdatasourcewidget.h"
2627
#include "qgis_gui.h"
2728

2829
#define SIP_NO_FILE
@@ -32,7 +33,7 @@
3233
* file, database, directory and protocol sources.
3334
* \note not available in Python bindings
3435
*/
35-
class GUI_EXPORT QgsOpenVectorLayerDialog : public QDialog, private Ui::QgsOpenVectorLayerDialogBase
36+
class GUI_EXPORT QgsOpenVectorLayerDialog : public QgsAbstractDataSourceWidget, private Ui::QgsOpenVectorLayerDialogBase
3637
{
3738
Q_OBJECT
3839

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

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

84-
void accept() override;
85-
8686
void on_buttonSelectSrc_clicked();
8787
void on_radioSrcFile_toggled( bool checked );
8888
void on_radioSrcDirectory_toggled( bool checked );

src/gui/qgsabstractdatasourcewidget.cpp

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@
1717
***************************************************************************/
1818

1919
#include "qgsabstractdatasourcewidget.h"
20+
#include <QPushButton>
2021

2122
QgsAbstractDataSourceWidget::QgsAbstractDataSourceWidget( QWidget *parent, Qt::WindowFlags fl, QgsProviderRegistry::WidgetMode widgetMode ):
2223
QDialog( parent, fl ),
2324
mWidgetMode( widgetMode )
2425
{
25-
2626
}
2727

2828
QgsProviderRegistry::WidgetMode QgsAbstractDataSourceWidget::widgetMode() const
@@ -35,8 +35,40 @@ const QgsMapCanvas *QgsAbstractDataSourceWidget::mapCanvas() const
3535
return mMapCanvas;
3636
}
3737

38+
void QgsAbstractDataSourceWidget::setupButtons( QDialogButtonBox *buttonBox )
39+
{
40+
41+
if ( mWidgetMode == QgsProviderRegistry::WidgetMode::None )
42+
{
43+
QPushButton *closeButton = new QPushButton( tr( "&Close" ) );
44+
buttonBox->addButton( closeButton, QDialogButtonBox::ApplyRole );
45+
connect( closeButton, &QPushButton::clicked, this, &QgsAbstractDataSourceWidget::addButtonClicked );
46+
}
47+
48+
mAddButton = new QPushButton( tr( "&Add" ) );
49+
mAddButton->setToolTip( tr( "Add selected layers to map" ) );
50+
mAddButton->setEnabled( false );
51+
buttonBox->addButton( mAddButton, QDialogButtonBox::ApplyRole );
52+
connect( mAddButton, &QPushButton::clicked, this, &QgsAbstractDataSourceWidget::addButtonClicked );
53+
connect( this, &QgsAbstractDataSourceWidget::enableButtons, mAddButton, &QPushButton::setEnabled );
54+
55+
QPushButton *okButton = new QPushButton( tr( "&Ok" ) );
56+
okButton->setToolTip( tr( "Add selected layers to map and close this dialog" ) );
57+
okButton->setEnabled( false );
58+
buttonBox->addButton( okButton, QDialogButtonBox::AcceptRole );
59+
connect( okButton, &QPushButton::clicked, this, &QgsAbstractDataSourceWidget::okButtonClicked );
60+
connect( this, &QgsAbstractDataSourceWidget::enableButtons, okButton, &QPushButton::setEnabled );
61+
62+
}
63+
3864

3965
void QgsAbstractDataSourceWidget::setMapCanvas( const QgsMapCanvas *mapCanvas )
4066
{
4167
mMapCanvas = mapCanvas;
4268
}
69+
70+
void QgsAbstractDataSourceWidget::okButtonClicked()
71+
{
72+
addButtonClicked();
73+
emit accepted();
74+
}

src/gui/qgsabstractdatasourcewidget.h

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "qgsproviderregistry.h"
2727
#include "qgsguiutils.h"
2828
#include <QDialog>
29+
#include <QDialogButtonBox>
2930

3031
class QgsMapCanvas;
3132

@@ -58,6 +59,17 @@ class GUI_EXPORT QgsAbstractDataSourceWidget : public QDialog
5859
*/
5960
virtual void refresh() {}
6061

62+
/** Triggered when the add button is clicked, the add layer signal is emitted
63+
* Concrete classes should implement the right behavior depending on the layer
64+
* being added.
65+
*/
66+
virtual void addButtonClicked() { }
67+
68+
/** Triggered when the dialog is accepted, call addButtonClicked() and
69+
* emit the accepted() signal
70+
*/
71+
virtual void okButtonClicked();
72+
6173
signals:
6274

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

95+
//! Emitted when the ok/add buttons should be enabled/disabled
96+
void enableButtons( bool enable );
97+
98+
8399
protected:
84100

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

91-
/** Return the map canvas (can be null)
92-
*/
107+
//! Return the map canvas (can be null)
93108
const QgsMapCanvas *mapCanvas() const;
94109

95-
private:
110+
//! Connect the ok and apply/add buttons to the slots
111+
void setupButtons( QDialogButtonBox *buttonBox );
96112

113+
//! Return the add Button
114+
QPushButton *addButton( ) const { return mAddButton; }
115+
116+
private:
117+
QPushButton *mAddButton = nullptr;
97118
QgsProviderRegistry::WidgetMode mWidgetMode;
98119
QgsMapCanvas const *mMapCanvas = nullptr;
99120

src/gui/qgsdatasourcemanagerdialog.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ QgsAbstractDataSourceWidget *QgsDataSourceManagerDialog::providerDialog( const Q
192192
dlg->setMapCanvas( mMapCanvas );
193193
}
194194
connect( dlg, &QgsAbstractDataSourceWidget::rejected, this, &QgsDataSourceManagerDialog::reject );
195+
connect( dlg, &QgsAbstractDataSourceWidget::accepted, this, &QgsDataSourceManagerDialog::accept );
195196
return dlg;
196197
}
197198
}
@@ -208,7 +209,7 @@ void QgsDataSourceManagerDialog::addDbProviderDialog( const QString providerKey,
208209
connect( dlg, SIGNAL( progressMessage( QString ) ),
209210
this, SIGNAL( showStatusMessage( QString ) ) );
210211
connect( dlg, SIGNAL( connectionsChanged() ), this, SIGNAL( connectionsChanged() ) );
211-
connect( this, SIGNAL( providerDialogsRefreshRequested() ), dlg, SLOT( refresh() ) );
212+
connect( this, SIGNAL( providerDialogsRefreshRequested() ), dlg, SLOT( refresh() ) );
212213
}
213214
}
214215

src/gui/qgsowssourceselect.cpp

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -60,20 +60,11 @@ QgsOWSSourceSelect::QgsOWSSourceSelect( const QString &service, QWidget *parent,
6060
, mCurrentTileset( nullptr )
6161
{
6262
setupUi( this );
63-
64-
if ( widgetMode() != QgsProviderRegistry::WidgetMode::None )
65-
{
66-
buttonBox->removeButton( buttonBox->button( QDialogButtonBox::Close ) );
67-
}
63+
setupButtons( buttonBox );
6864

6965

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

72-
mAddButton = buttonBox->button( QDialogButtonBox::Apply );
73-
mAddButton->setText( tr( "&Add" ) );
74-
mAddButton->setToolTip( tr( "Add selected layers to map" ) );
75-
mAddButton->setEnabled( false );
76-
7768
clearCrs();
7869

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

9182
if ( widgetMode() != QgsProviderRegistry::WidgetMode::Manager )
9283
{
93-
connect( mAddButton, &QAbstractButton::clicked, this, &QgsOWSSourceSelect::addClicked );
9484
//set the current project CRS if available
9585
QgsCoordinateReferenceSystem currentRefSys = QgsProject::instance()->crs();
9686
//convert CRS id to epsg
@@ -106,7 +96,6 @@ QgsOWSSourceSelect::QgsOWSSourceSelect( const QString &service, QWidget *parent,
10696
mTimeWidget->hide();
10797
mFormatWidget->hide();
10898
mCRSWidget->hide();
109-
mAddButton->hide();
11099
mCacheWidget->hide();
111100
}
112101

@@ -361,10 +350,6 @@ void QgsOWSSourceSelect::on_mConnectButton_clicked()
361350
QApplication::restoreOverrideCursor();
362351
}
363352

364-
void QgsOWSSourceSelect::addClicked()
365-
{
366-
}
367-
368353
void QgsOWSSourceSelect::enableLayersForCrs( QTreeWidgetItem * )
369354
{
370355
}

src/gui/qgsowssourceselect.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,6 @@ class GUI_EXPORT QgsOWSSourceSelect : public QgsAbstractDataSourceWidget, protec
8787
*/
8888
void on_mConnectButton_clicked();
8989

90-
//! Determines the layers the user selected
91-
virtual void addClicked();
92-
9390
void searchFinished();
9491

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

190-
QPushButton *mAddButton = nullptr;
191-
192187
QMap<QString, QString> mCrsNames;
193188

194189
void addWmsListRow( const QDomElement &item, int row );

src/providers/arcgisrest/qgsafssourceselect.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,8 @@
2727

2828

2929
QgsAfsSourceSelect::QgsAfsSourceSelect( QWidget *parent, Qt::WindowFlags fl, QgsProviderRegistry::WidgetMode widgetMode )
30-
: QgsArcGisServiceSourceSelect( QStringLiteral( "ArcGisFeatureServer" ), QgsArcGisServiceSourceSelect::FeatureService, parent, fl )
30+
: QgsArcGisServiceSourceSelect( QStringLiteral( "ArcGisFeatureServer" ), QgsArcGisServiceSourceSelect::FeatureService, parent, fl, widgetMode )
3131
{
32-
if ( widgetMode == QgsProviderRegistry::WidgetMode::Embedded || widgetMode == QgsProviderRegistry::WidgetMode::Manager )
33-
{
34-
buttonBox->removeButton( buttonBox->button( QDialogButtonBox::Close ) );
35-
}
36-
3732
// import/export of connections not supported yet
3833
btnLoad->hide();
3934
btnSave->hide();

0 commit comments

Comments
 (0)