QGIS API Documentation  3.24.2-Tisler (13c1a02865)
qgsabstractdatasourcewidget.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsabstractdatasourcewidget.cpp - base class for source selector widgets
3  -------------------
4  begin : 10 July 2017
5  original : (C) 2017 by Alessandro Pasotti
6  email : apasotti at boundlessgeo dot com
7 
8  ***************************************************************************/
9 
10 /***************************************************************************
11  * *
12  * This program is free software; you can redistribute it and/or modify *
13  * it under the terms of the GNU General Public License as published by *
14  * the Free Software Foundation; either version 2 of the License, or *
15  * (at your option) any later version. *
16  * *
17  ***************************************************************************/
18 
20 #include <QPushButton>
21 
23  QDialog( parent, fl ),
24  mWidgetMode( widgetMode )
25 {
26 }
27 
29 {
30  return mWidgetMode;
31 }
32 
34 {
35  return mMapCanvas;
36 }
37 
39 {
40  return mBrowserModel;
41 }
42 
43 void QgsAbstractDataSourceWidget::setupButtons( QDialogButtonBox *buttonBox )
44 {
45  buttonBox->setStandardButtons( QDialogButtonBox::Apply | QDialogButtonBox::Close | QDialogButtonBox::Help );
46 #ifdef Q_OS_MACX
47  buttonBox->setStyleSheet( "* { button-layout: 2 }" );
48 #endif
49  mAddButton = buttonBox->button( QDialogButtonBox::Apply );
50  mAddButton->setText( tr( "&Add" ) );
51  mAddButton->setToolTip( tr( "Add selected layers to map" ) );
52  mAddButton->setEnabled( false );
53  connect( mAddButton, &QPushButton::clicked, this, &QgsAbstractDataSourceWidget::addButtonClicked );
54  connect( this, &QgsAbstractDataSourceWidget::enableButtons, mAddButton, &QPushButton::setEnabled );
55 
56  QPushButton *closeButton = buttonBox->button( QDialogButtonBox::Close );
57  closeButton->setToolTip( tr( "Close this dialog without adding any layer" ) );
58  connect( closeButton, &QPushButton::clicked, this, &QgsAbstractDataSourceWidget::reject );
59 }
60 
62 {
63  mMapCanvas = mapCanvas;
64 }
65 
67 {
68  mBrowserModel = model;
69 }
70 
72 {
73 }
74 
76 {
77 }
void enableButtons(bool enable)
Emitted when the ok/add buttons should be enabled/disabled.
void setMapCanvas(const QgsMapCanvas *mapCanvas)
Store a pointer to the map canvas to retrieve extent and CRS Used to select an appropriate CRS and po...
const QgsMapCanvas * mapCanvas() const
Returns the map canvas (can be nullptr)
QgsBrowserModel * browserModel()
Returns the associated browser model (may be nullptr).
void setupButtons(QDialogButtonBox *buttonBox)
Connect the ok and apply/add buttons to the slots.
QgsAbstractDataSourceWidget(QWidget *parent=nullptr, Qt::WindowFlags fl=QgsGuiUtils::ModalDialogFlags, QgsProviderRegistry::WidgetMode widgetMode=QgsProviderRegistry::WidgetMode::None)
Constructor.
virtual void addButtonClicked()
Triggered when the add button is clicked, the add layer signal is emitted Concrete classes should imp...
void setBrowserModel(QgsBrowserModel *model)
Sets a browser model to use with the widget.
QgsProviderRegistry::WidgetMode widgetMode() const
Returns the widget mode.
virtual void reset()
Called when this source select widget is being shown in a "new and clean" dialog.
A model for showing available data sources and other items in a structured tree.
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:90
WidgetMode
Different ways a source select dialog can be used.