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
+
1
17
#include < QMessageBox>
2
18
#include < QListWidgetItem>
3
- #include < QMdiArea>
4
- #include < QMdiSubWindow>
5
19
6
20
#include " qgsdatasourcemanagerdialog.h"
7
21
#include " ui_qgsdatasourcemanagerdialog.h"
8
22
#include " qgsbrowserdockwidget.h"
9
23
#include " qgssettings.h"
10
24
#include " qgsproviderregistry.h"
25
+ #include " qgsopenvectorlayerdialog.h"
11
26
12
27
QgsDataSourceManagerDialog::QgsDataSourceManagerDialog ( QWidget *parent ) :
13
28
QDialog( parent ),
@@ -27,34 +42,47 @@ QgsDataSourceManagerDialog::QgsDataSourceManagerDialog( QWidget *parent ) :
27
42
// Bind list index to the stacked dialogs
28
43
connect ( ui->mList , SIGNAL ( currentRowChanged ( int ) ), this , SLOT ( setCurrentPage ( int ) ) );
29
44
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
+
31
48
mBrowserWidget = new QgsBrowserDockWidget ( QStringLiteral ( " Browser" ), this );
32
49
mBrowserWidget ->setFeatures ( QDockWidget::NoDockWidgetFeatures );
33
50
ui->mStackedWidget ->addWidget ( mBrowserWidget );
34
51
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
+
35
61
// Add data provider dialogs
62
+ QDialog *dlg;
36
63
64
+ // ///////////////////////////////////////////////////////////////////////////
37
65
// 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 )
40
69
{
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 & ) ) );
42
73
}
43
- else
74
+
75
+ // ///////////////////////////////////////////////////////////////////////////
76
+ // WFS
77
+
78
+ dlg = providerDialog ( QStringLiteral ( " WFS" ), tr ( " WFS" ), QStringLiteral ( " /mActionAddWfsLayer.svg" ) );
79
+ if ( dlg )
44
80
{
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" ) ); } );
58
86
}
59
87
60
88
}
@@ -66,5 +94,38 @@ QgsDataSourceManagerDialog::~QgsDataSourceManagerDialog()
66
94
67
95
void QgsDataSourceManagerDialog::setCurrentPage ( int index )
68
96
{
97
+ // TODO: change window title according to the active page
69
98
ui->mStackedWidget ->setCurrentIndex ( index );
70
99
}
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