17#include <QListWidgetItem>
20#include "moc_qgsdatasourcemanagerdialog.cpp"
21#include "ui_qgsdatasourcemanagerdialog.h"
39 , mMapCanvas( canvas )
40 , mBrowserModel( browserModel )
43 ui->verticalLayout_2->setSpacing( 6 );
44 ui->verticalLayout_2->setContentsMargins( 0, 0, 0, 0 );
47 mMessageBar->setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Fixed );
48 static_cast<QVBoxLayout *
>( layout() )->insertWidget( 0, mMessageBar );
60 mBrowserWidget->setFeatures( QDockWidget::NoDockWidgetFeatures );
61 mBrowserWidget->setTitleBarWidget(
new QWidget( mBrowserWidget ) );
63 QWidget *browserWidgetWrapper =
new QWidget(
this );
64 browserWidgetWrapper->setLayout(
new QVBoxLayout( browserWidgetWrapper ) );
65 browserWidgetWrapper->layout()->addWidget( mBrowserWidget );
66 QDialogButtonBox *browserButtonBox =
new QDialogButtonBox( QDialogButtonBox::StandardButton::Close | QDialogButtonBox::StandardButton::Help, browserWidgetWrapper );
67 browserWidgetWrapper->layout()->addWidget( browserButtonBox );
69 connect( browserButtonBox, &QDialogButtonBox::helpRequested,
this, [ = ]
71 QgsHelp::openHelp( QStringLiteral(
"managing_data_source/opening_data.html#the-browser-panel" ) );
73 connect( browserButtonBox, &QDialogButtonBox::rejected,
this, &QgsDataSourceManagerDialog::reject );
75 ui->mOptionsStackedWidget->addWidget( browserWidgetWrapper );
76 mPageProviderKeys.append( QStringLiteral(
"browser" ) );
77 mPageProviderNames.append( QStringLiteral(
"browser" ) );
95 addProviderDialog( dlg, provider->providerKey(), provider->name(), provider->text(), provider->icon( ), provider->toolTip( ) );
108 addProviderDialog( dlg, provider->providerKey(), provider->name(), provider->text(), provider->icon( ), provider->toolTip( ) );
114 removeProviderDialog( name );
128 const int pageIdx = mPageProviderKeys.indexOf( pageName );
131 QTimer::singleShot( 0,
this, [ = ] {
setCurrentPage( pageIdx ); } );
143 setWindowState( windowState() & ~Qt::WindowMinimized );
149 mPreviousRow = ui->mOptionsStackedWidget->currentIndex();
150 ui->mOptionsStackedWidget->setCurrentIndex( index );
151 setWindowTitle( tr(
"Data Source Manager | %1" ).arg( ui->mOptionsListWidget->currentItem()->text() ) );
157 const int prevPage = mPreviousRow != -1 ? mPreviousRow : 0;
169 const int pageCount = ui->mOptionsStackedWidget->count();
170 for (
int i = 0; i < pageCount; ++i )
172 QWidget *widget = ui->mOptionsStackedWidget->widget( i );
174 if ( dataSourceWidget )
175 dataSourceWidget->
reset();
181 const int pageIdx = mPageProviderNames.indexOf( pageName );
184 QTimer::singleShot( 0,
this, [ = ]
187 if (
QgsAbstractDataSourceWidget *dataSourceWidget = qobject_cast<QgsAbstractDataSourceWidget *>( ui->mOptionsStackedWidget->currentWidget() ) )
189 dataSourceWidget->configureFromUri( uri );
205void QgsDataSourceManagerDialog::addProviderDialog(
QgsAbstractDataSourceWidget *dlg,
const QString &providerKey,
const QString &providerName,
const QString &text,
const QIcon &icon,
const QString &toolTip )
207 mPageProviderKeys.append( providerKey );
208 mPageProviderNames.append( providerName );
209 ui->mOptionsStackedWidget->addWidget( dlg );
210 QListWidgetItem *layerItem =
new QListWidgetItem( text, ui->mOptionsListWidget );
211 layerItem->setData( Qt::UserRole, providerName );
212 layerItem->setToolTip( toolTip.isEmpty() ? tr(
"Add %1 layer" ).arg( text ) : toolTip );
213 layerItem->setIcon( icon );
221 connect( dlg, &QgsAbstractDataSourceWidget::rejected,
this, &QgsDataSourceManagerDialog::reject );
222 connect( dlg, &QgsAbstractDataSourceWidget::accepted,
this, &QgsDataSourceManagerDialog::accept );
223 makeConnections( dlg, providerKey );
226void QgsDataSourceManagerDialog::removeProviderDialog(
const QString &providerName )
228 const int pageIdx = mPageProviderNames.indexOf( providerName );
231 ui->mOptionsStackedWidget->removeWidget( ui->mOptionsStackedWidget->widget( pageIdx ) );
232 mPageProviderKeys.removeAt( pageIdx );
233 mPageProviderNames.removeAt( pageIdx );
234 ui->mOptionsListWidget->removeItemWidget( ui->mOptionsListWidget->item( pageIdx ) );
250 Q_UNUSED( providerKey )
267 emit
addLayer( type, url, baseName, providerKey );
276 const QString key = specifiedProvider.isEmpty() ? providerKey : specifiedProvider;
332 ui->mOptionsStackedWidget->currentWidget()->show();
MessageLevel
Level for messages This will be used both for message log and message bar in application.
@ Critical
Critical/error message.
LayerType
Types of layers that can be added to a map.
@ Group
Composite group layer. Added in QGIS 3.24.
@ Plugin
Plugin based layer.
@ TiledScene
Tiled scene layer. Added in QGIS 3.34.
@ Annotation
Contains freeform, georeferenced annotations. Added in QGIS 3.16.
@ VectorTile
Vector tile layer. Added in QGIS 3.14.
@ Mesh
Mesh layer. Added in QGIS 3.2.
@ PointCloud
Point cloud layer. Added in QGIS 3.18.
A model for showing available data sources and other items in a structured tree.
The QgsDataSourceManagerDialog class embeds the browser panel and all the provider dialogs.
void reset()
Resets the interface of the datasource manager after reopening the dialog.
void refresh()
Refresh the browser view.
void addVectorLayers(const QStringList &layerQStringList, const QString &enc, const QString &dataSourceType)
Emitted when a one or more layer were selected for addition: for signal forwarding to QgisApp.
void openFile(const QString &fileName, const QString &fileTypeHint=QString())
Emitted when a file needs to be opened.
QgsMessageBar * messageBar() const
Returns the dialog's message bar.
void rasterLayersAdded(const QStringList &layersList)
One or more raster layer were added: for signal forwarding to QgisApp.
void setPreviousPage()
Reset current page to previously selected page.
QgsDataSourceManagerDialog(QgsBrowserGuiModel *browserModel, QWidget *parent=nullptr, QgsMapCanvas *canvas=nullptr, Qt::WindowFlags fl=Qt::Window)
QgsDataSourceManagerDialog constructor.
void showStatusMessage(const QString &message)
Emitted when a status message needs to be shown: for signal forwarding to QgisApp.
void showEvent(QShowEvent *event) override
void replaceSelectedVectorLayer(const QString &oldId, const QString &uri, const QString &layerName, const QString &provider)
Replace the selected layer by a vector layer defined by uri, layer name, data source uri.
void configureFromUri(const QString &pageName, const QString &uri)
Shows the page pageName and configure the source select widget from the layer uri.
void openPage(const QString &pageName)
Open a given page in the dialog.
void activate()
Raise, unminimize and activate this window.
void connectionsChanged()
Emitted when a connection has changed inside the provider dialogs This signal is normally forwarded t...
void vectorLayersAdded(const QStringList &layerQStringList, const QString &enc, const QString &dataSourceType)
One or more vector layer were added: for signal forwarding to QgisApp.
void addDatabaseLayers(const QStringList &layerPathList, const QString &providerKey)
Emitted when a DB layer was selected for addition: for signal forwarding to QgisApp.
void handleDropUriList(const QgsMimeDataUtils::UriList &)
Emitted when drop uri list needs to be handled from the browser.
void providerDialogsRefreshRequested()
One or more provider connections have changed and the dialogs should be refreshed.
void addLayer(Qgis::LayerType type, const QString &url, const QString &baseName, const QString &providerKey)
Emitted when a layer has been selected for addition.
void updateProjectHome()
Update project home directory.
void setCurrentPage(int index)
Sync current page with the leftbar list.
void addRasterLayers(const QStringList &layersList)
Emitted when a one or more layer were selected for addition: for signal forwarding to QgisApp.
~QgsDataSourceManagerDialog() override
static QgsSourceSelectProviderRegistry * sourceSelectProviderRegistry()
Returns the global source select provider registry, used for managing all known source select widget ...
static void openHelp(const QString &key)
Opens help topic for the given help key using default system web browser.
Map canvas is a class for displaying all GIS data types on a canvas.
A bar for displaying non-blocking messages to the user.
void pushMessage(const QString &text, Qgis::MessageLevel level=Qgis::MessageLevel::Info, int duration=-1)
A convenience method for pushing a message with the specified text to the bar.
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::MessageLevel::Warning, bool notifyUser=true)
Adds a message to the log instance (and creates it if necessary).
A base dialog for options and properties dialogs that offers vertical tabs.
void resizeAlltabs(int index)
Resizes all tabs when the dialog is resized.
void restoreOptionsBaseUi(const QString &title=QString())
Restore the base ui.
void initOptionsBase(bool restoreUi=true, const QString &title=QString())
Set up the base ui connections for vertical tabs.
void showEvent(QShowEvent *e) override
void providerRemoved(const QString &name)
Emitted whenever a provider is removed from the registry.
void providerAdded(const QString &name)
Emitted whenever a provider is added to the registry.
QList< QgsSourceSelectProvider * > providers()
Gets list of available providers.
This is the interface for those who want to add entries to the QgsDataSourceManagerDialog.
#define Q_NOWARN_DEPRECATED_POP
#define Q_NOWARN_DEPRECATED_PUSH