Skip to content
Permalink
Browse files

Data source select dialog now accepts a model

  • Loading branch information
elpaso committed Nov 2, 2018
1 parent 086be38 commit 8493636f1884f52273c7fe757d68fd0237da9d1c
@@ -31,12 +31,14 @@ will return a (possibly invalid) QgsMimeDataUtils.Uri.
%End
public:

QgsDataSourceSelectDialog( bool setFilterByLayerType = false,
QgsDataSourceSelectDialog( QgsBrowserModel *browserModel = 0,
bool setFilterByLayerType = false,
const QgsMapLayer::LayerType &layerType = QgsMapLayer::LayerType::VectorLayer,
QWidget *parent = 0 );
%Docstring
Constructs a QgsDataSourceSelectDialog, optionally filtering by layer type

:param browserModel: an existing browser model (typically from app), if null an instance will be created
:param setFilterByLayerType: activates filtering by layer type
:param layerType: sets the layer type filter, this is in effect only if filtering by layer type is also active
:param parent: the object
@@ -6945,7 +6945,7 @@ void QgisApp::changeDataSource( QgsMapLayer *layer )
QString providerType( layer->providerType() );
QgsMapLayer::LayerType layerType( layer->type() );

QgsDataSourceSelectDialog dlg( true, layerType );
QgsDataSourceSelectDialog dlg( mBrowserModel, true, layerType );

if ( dlg.exec() == QDialog::Accepted )
{
@@ -22,17 +22,30 @@

#include <QPushButton>

QgsDataSourceSelectDialog::QgsDataSourceSelectDialog( bool setFilterByLayerType,
const QgsMapLayer::LayerType &layerType,
QWidget *parent )
QgsDataSourceSelectDialog::QgsDataSourceSelectDialog(
QgsBrowserModel *browserModel,
bool setFilterByLayerType,
const QgsMapLayer::LayerType &layerType,
QWidget *parent )
: QDialog( parent )
{
if ( ! browserModel )
{
mBrowserModel = qgis::make_unique<QgsBrowserModel>();
mOwnModel = true;
}
else
{
mBrowserModel.reset( browserModel );
mOwnModel = false;
}

setupUi( this );
setWindowTitle( tr( "Select a Data Source" ) );
QgsGui::enableAutoGeometryRestore( this );

mBrowserModel.initialize();
mBrowserProxyModel.setBrowserModel( &mBrowserModel );
mBrowserModel->initialize();
mBrowserProxyModel.setBrowserModel( mBrowserModel.get() );
mBrowserTreeView->setHeaderHidden( true );

if ( setFilterByLayerType )
@@ -47,6 +60,12 @@ QgsDataSourceSelectDialog::QgsDataSourceSelectDialog( bool setFilterByLayerType,
connect( mBrowserTreeView, &QgsBrowserTreeView::clicked, this, &QgsDataSourceSelectDialog::onLayerSelected );
}

QgsDataSourceSelectDialog::~QgsDataSourceSelectDialog()
{
if ( ! mOwnModel )
mBrowserModel.release();
}

void QgsDataSourceSelectDialog::setLayerTypeFilter( QgsMapLayer::LayerType layerType )
{
mBrowserProxyModel.setFilterByLayerType( true );
@@ -50,11 +50,13 @@ class GUI_EXPORT QgsDataSourceSelectDialog: public QDialog, private Ui::QgsDataS
/**
* Constructs a QgsDataSourceSelectDialog, optionally filtering by layer type
*
* \param browserModel an existing browser model (typically from app), if null an instance will be created
* \param setFilterByLayerType activates filtering by layer type
* \param layerType sets the layer type filter, this is in effect only if filtering by layer type is also active
* \param parent the object
*/
QgsDataSourceSelectDialog( bool setFilterByLayerType = false,
QgsDataSourceSelectDialog( QgsBrowserModel *browserModel = nullptr,
bool setFilterByLayerType = false,
const QgsMapLayer::LayerType &layerType = QgsMapLayer::LayerType::VectorLayer,
QWidget *parent = nullptr );

@@ -75,8 +77,9 @@ class GUI_EXPORT QgsDataSourceSelectDialog: public QDialog, private Ui::QgsDataS

private:

QgsBrowserModel mBrowserModel;
QgsBrowserProxyModel mBrowserProxyModel;
std::unique_ptr<QgsBrowserModel> mBrowserModel;
bool mOwnModel = true;
QgsMimeDataUtils::Uri mUri;

};
Binary file not shown.

0 comments on commit 8493636

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