Skip to content

Commit

Permalink
Allow double-clicking items in data source select dialog to choose them
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jun 12, 2019
1 parent 5bc50ff commit 54434a6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
4 changes: 2 additions & 2 deletions python/gui/auto_generated/qgsdatasourceselectdialog.sip.in
Expand Up @@ -33,7 +33,7 @@ will return a (possibly invalid) QgsMimeDataUtils.Uri.

QgsDataSourceSelectDialog( QgsBrowserModel *browserModel = 0,
bool setFilterByLayerType = false,
const QgsMapLayerType &layerType = QgsMapLayerType::VectorLayer,
QgsMapLayerType layerType = QgsMapLayerType::VectorLayer,
QWidget *parent = 0 );
%Docstring
Constructs a QgsDataSourceSelectDialog, optionally filtering by layer type
Expand All @@ -52,7 +52,7 @@ Constructs a QgsDataSourceSelectDialog, optionally filtering by layer type
Sets layer type filter to ``layerType`` and activates the filtering
%End

void setDescription( const QString description );
void setDescription( const QString &description );
%Docstring
Sets a description label

Expand Down
12 changes: 10 additions & 2 deletions src/gui/qgsdatasourceselectdialog.cpp
Expand Up @@ -29,7 +29,7 @@
QgsDataSourceSelectDialog::QgsDataSourceSelectDialog(
QgsBrowserModel *browserModel,
bool setFilterByLayerType,
const QgsMapLayerType &layerType,
QgsMapLayerType layerType,
QWidget *parent )
: QDialog( parent )
{
Expand Down Expand Up @@ -100,6 +100,7 @@ QgsDataSourceSelectDialog::QgsDataSourceSelectDialog(

connect( mActionRefresh, &QAction::triggered, this, [ = ] { refreshModel( QModelIndex() ); } );
connect( mBrowserTreeView, &QgsBrowserTreeView::clicked, this, &QgsDataSourceSelectDialog::onLayerSelected );
connect( mBrowserTreeView, &QgsBrowserTreeView::doubleClicked, this, &QgsDataSourceSelectDialog::itemDoubleClicked );
connect( mActionCollapse, &QAction::triggered, mBrowserTreeView, &QgsBrowserTreeView::collapseAll );
connect( mActionShowFilter, &QAction::triggered, this, &QgsDataSourceSelectDialog::showFilterWidget );
connect( mLeFilter, &QgsFilterLineEdit::returnPressed, this, &QgsDataSourceSelectDialog::setFilter );
Expand Down Expand Up @@ -162,7 +163,7 @@ void QgsDataSourceSelectDialog::showFilterWidget( bool visible )
}
}

void QgsDataSourceSelectDialog::setDescription( const QString description )
void QgsDataSourceSelectDialog::setDescription( const QString &description )
{
if ( !description.isEmpty() )
{
Expand Down Expand Up @@ -283,3 +284,10 @@ void QgsDataSourceSelectDialog::onLayerSelected( const QModelIndex &index )
buttonBox->button( QDialogButtonBox::StandardButton::Ok )->setEnabled( isLayerCompatible );
}

void QgsDataSourceSelectDialog::itemDoubleClicked( const QModelIndex &index )
{
onLayerSelected( index );
if ( buttonBox->button( QDialogButtonBox::StandardButton::Ok )->isEnabled() )
accept();
}

6 changes: 4 additions & 2 deletions src/gui/qgsdatasourceselectdialog.h
Expand Up @@ -58,7 +58,7 @@ class GUI_EXPORT QgsDataSourceSelectDialog: public QDialog, private Ui::QgsDataS
*/
QgsDataSourceSelectDialog( QgsBrowserModel *browserModel = nullptr,
bool setFilterByLayerType = false,
const QgsMapLayerType &layerType = QgsMapLayerType::VectorLayer,
QgsMapLayerType layerType = QgsMapLayerType::VectorLayer,
QWidget *parent = nullptr );


Expand All @@ -75,7 +75,7 @@ class GUI_EXPORT QgsDataSourceSelectDialog: public QDialog, private Ui::QgsDataS
* \note the description will be displayed at the bottom of the dialog
* \since 3.8
*/
void setDescription( const QString description );
void setDescription( const QString &description );

/**
* Returns the (possibly invalid) uri of the selected data source
Expand All @@ -98,6 +98,8 @@ class GUI_EXPORT QgsDataSourceSelectDialog: public QDialog, private Ui::QgsDataS
//! Triggered when a layer is selected in the browser
void onLayerSelected( const QModelIndex &index );

void itemDoubleClicked( const QModelIndex &index );

private:

//! Refresh the model
Expand Down

0 comments on commit 54434a6

Please sign in to comment.