1+ /* **************************************************************************
2+ qgsdatasourcemanagerdialog.cpp - datasource manager dialog
3+
4+ ---------------------
5+ begin : May 19, 2017
6+ copyright : (C) 2017 by Alessandro Pasotti
7+ email : apasotti at itopen dot it
8+ ***************************************************************************
9+ * *
10+ * This program is free software; you can redistribute it and/or modify *
11+ * it under the terms of the GNU General Public License as published by *
12+ * the Free Software Foundation; either version 2 of the License, or *
13+ * (at your option) any later version. *
14+ * *
15+ ***************************************************************************/
16+
117#include < QMessageBox>
218#include < QListWidgetItem>
3- #include < QMdiArea>
4- #include < QMdiSubWindow>
519
620#include " qgsdatasourcemanagerdialog.h"
721#include " ui_qgsdatasourcemanagerdialog.h"
822#include " qgsbrowserdockwidget.h"
923#include " qgssettings.h"
1024#include " qgsproviderregistry.h"
25+ #include " qgsopenvectorlayerdialog.h"
1126
1227QgsDataSourceManagerDialog::QgsDataSourceManagerDialog ( QWidget *parent ) :
1328 QDialog( parent ),
@@ -27,34 +42,47 @@ QgsDataSourceManagerDialog::QgsDataSourceManagerDialog( QWidget *parent ) :
2742 // Bind list index to the stacked dialogs
2843 connect ( ui->mList , SIGNAL ( currentRowChanged ( int ) ), this , SLOT ( setCurrentPage ( int ) ) );
2944
30- // Add the browser widget to the first stacked widget page
45+ // ///////////////////////////////////////////////////////////////////////////
46+ // BROWSER Add the browser widget to the first stacked widget page
47+
3148 mBrowserWidget = new QgsBrowserDockWidget ( QStringLiteral ( " Browser" ), this );
3249 mBrowserWidget ->setFeatures ( QDockWidget::NoDockWidgetFeatures );
3350 ui->mStackedWidget ->addWidget ( mBrowserWidget );
3451
52+ // ///////////////////////////////////////////////////////////////////////////
53+ // VECTOR Layers (completely different interface: it's not a provider)
54+
55+ QgsOpenVectorLayerDialog *ovl = new QgsOpenVectorLayerDialog ( this , Qt::Widget, true );
56+ ui->mStackedWidget ->addWidget ( ovl );
57+ QListWidgetItem *ogrItem = new QListWidgetItem ( tr ( " Vector files" ), ui->mList );
58+ ogrItem->setIcon ( QgsApplication::getThemeIcon ( QStringLiteral ( " /mActionAddOgrLayer.svg" ) ) );
59+ connect ( ovl, &QgsOpenVectorLayerDialog::addVectorLayers, this , &QgsDataSourceManagerDialog::vectorLayersAdded );
60+
3561 // Add data provider dialogs
62+ QDialog *dlg;
3663
64+ // ///////////////////////////////////////////////////////////////////////////
3765 // WMS
38- QDialog *wmss = dynamic_cast <QDialog *>( QgsProviderRegistry::instance ()->createSelectionWidget ( QStringLiteral ( " wms" ), this ) );
39- if ( !wmss )
66+
67+ dlg = providerDialog ( QStringLiteral ( " wms" ), tr ( " WMS" ), QStringLiteral ( " /mActionAddWmsLayer.svg" ) );
68+ if ( dlg )
4069 {
41- QMessageBox::warning ( this , tr ( " WMS" ), tr ( " Cannot get WMS select dialog from provider." ) );
70+ // Forward
71+ connect ( dlg, SIGNAL ( addRasterLayer ( QString const &, QString const &, QString const & ) ),
72+ this , SLOT ( rasterLayerAdded ( QString const &, QString const &, QString const & ) ) );
4273 }
43- else
74+
75+ // ///////////////////////////////////////////////////////////////////////////
76+ // WFS
77+
78+ dlg = providerDialog ( QStringLiteral ( " WFS" ), tr ( " WFS" ), QStringLiteral ( " /mActionAddWfsLayer.svg" ) );
79+ if ( dlg )
4480 {
45- connect ( wmss, SIGNAL ( addRasterLayer ( QString const &, QString const &, QString const & ) ),
46- qApp, SLOT ( addRasterLayer ( QString const &, QString const &, QString const & ) ) );
47- // wmss->exec();
48- wmss->setWindowFlags ( Qt::Widget );
49- QMdiArea *wmsMdi = new QMdiArea ( this );
50- QMdiSubWindow *wmsSub;
51- wmsMdi->setViewMode ( QMdiArea::TabbedView );
52- wmsSub = wmsMdi->addSubWindow ( wmss );
53- wmsSub->show ();
54- ui->mStackedWidget ->addWidget ( wmsMdi );
55- mDialogs .append ( wmss ); // TODO: rm
56- QListWidgetItem *wmsItem = new QListWidgetItem ( tr ( " WMS" ), ui->mList );
57- wmsItem->setIcon ( QgsApplication::getThemeIcon ( QStringLiteral ( " /mActionAddWmsLayer.svg" ) ) );
81+ // Forward (if only a common interface for the signals had been used in the providers ...)
82+ connect ( dlg, SIGNAL ( addWfsLayer ( QString, QString ) ), this , SIGNAL ( addWfsLayer ( QString, QString ) ) );
83+ connect ( this , &QgsDataSourceManagerDialog::addWfsLayer,
84+ this , [ = ]( const QString & vectorLayerPath, const QString & baseName )
85+ { this ->vectorLayerAdded ( vectorLayerPath, baseName, QStringLiteral ( " WFS" ) ); } );
5886 }
5987
6088}
@@ -66,5 +94,38 @@ QgsDataSourceManagerDialog::~QgsDataSourceManagerDialog()
6694
6795void QgsDataSourceManagerDialog::setCurrentPage ( int index )
6896{
97+ // TODO: change window title according to the active page
6998 ui->mStackedWidget ->setCurrentIndex ( index );
7099}
100+
101+ void QgsDataSourceManagerDialog::rasterLayerAdded ( const QString &uri, const QString &baseName, const QString &providerKey )
102+ {
103+ emit ( addRasterLayer ( uri, baseName, providerKey ) );
104+ }
105+
106+ void QgsDataSourceManagerDialog::vectorLayerAdded ( const QString &vectorLayerPath, const QString &baseName, const QString &providerKey )
107+ {
108+ emit ( addVectorLayer ( vectorLayerPath, baseName, providerKey ) );
109+ }
110+
111+ void QgsDataSourceManagerDialog::vectorLayersAdded ( const QStringList &layerQStringList, const QString &enc, const QString &dataSourceType )
112+ {
113+ emit addVectorLayers ( layerQStringList, enc, dataSourceType );
114+ }
115+
116+ QDialog *QgsDataSourceManagerDialog::providerDialog ( const QString providerKey, const QString providerName, const QString icon )
117+ {
118+ QDialog *dlg = dynamic_cast <QDialog *>( QgsProviderRegistry::instance ()->createSelectionWidget ( providerKey, this , Qt::Widget ) );
119+ if ( !dlg )
120+ {
121+ QMessageBox::warning ( this , providerName, tr ( " Cannot get %1 select dialog from provider %2." ).arg ( providerName, providerKey ) );
122+ return nullptr ;
123+ }
124+ else
125+ {
126+ ui->mStackedWidget ->addWidget ( dlg );
127+ QListWidgetItem *wmsItem = new QListWidgetItem ( providerName, ui->mList );
128+ wmsItem->setIcon ( QgsApplication::getThemeIcon ( icon ) );
129+ return dlg;
130+ }
131+ }
0 commit comments