Skip to content

Commit b2dea8e

Browse files
committedJun 2, 2017
[addlayerbutton] Initial implementation
1 parent c9e6f15 commit b2dea8e

File tree

8 files changed

+247
-0
lines changed

8 files changed

+247
-0
lines changed
 

‎images/images.qrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@
102102
<file>themes/default/lockedGray.svg</file>
103103
<file>themes/default/mAction.svg</file>
104104
<file>themes/default/mActionAdd.svg</file>
105+
<file>themes/default/mActionDataSourceManager.svg</file>
105106
<file>themes/default/mActionAddLayer.svg</file>
106107
<file>themes/default/mActionAddAllToOverview.svg</file>
107108
<file>themes/default/mActionAddArrow.svg</file>

‎src/app/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ SET(QGIS_APP_SRCS
6161
qgsversioninfo.cpp
6262
qgswelcomepageitemsmodel.cpp
6363
qgswelcomepage.cpp
64+
qgsdatasourcemanagerdialog.cpp
6465

6566
qgsmaptooladdfeature.cpp
6667
qgsmaptooladdpart.cpp
@@ -247,6 +248,7 @@ SET (QGIS_APP_MOC_HDRS
247248
qgsversioninfo.h
248249
qgswelcomepageitemsmodel.h
249250
qgswelcomepage.h
251+
qgsdatasourcemanagerdialog.h
250252

251253
qgsmaptooladdfeature.h
252254
qgsmaptoolannotation.h

‎src/app/qgisapp.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,7 @@ Q_GUI_EXPORT extern int qt_defaultDpiX();
285285
#include "qgsmapdecoration.h"
286286
#include "qgsnewnamedialog.h"
287287
#include "qgsgui.h"
288+
#include "qgsdatasourcemanagerdialog.h"
288289

289290
#include "qgssublayersdialog.h"
290291
#include "ogr/qgsopenvectorlayerdialog.h"
@@ -1392,6 +1393,8 @@ QgisApp::~QgisApp()
13921393
delete mPythonUtils;
13931394

13941395
delete mTray;
1396+
1397+
delete mDataSourceManagerDialog;
13951398
}
13961399

13971400
void QgisApp::dragEnterEvent( QDragEnterEvent *event )
@@ -1584,6 +1587,16 @@ bool QgisApp::event( QEvent *event )
15841587
return done;
15851588
}
15861589

1590+
void QgisApp::dataSourceManager()
1591+
{
1592+
if ( ! mDataSourceManagerDialog )
1593+
{
1594+
mDataSourceManagerDialog = new QgsDataSourceManagerDialog( this );
1595+
}
1596+
// TODO: handle docked
1597+
mDataSourceManagerDialog->exec();
1598+
}
1599+
15871600
QgisAppStyleSheet *QgisApp::styleSheetBuilder()
15881601
{
15891602
Q_ASSERT( mStyleSheetBuilder );
@@ -1808,6 +1821,7 @@ void QgisApp::createActions()
18081821

18091822
// Layer Menu Items
18101823

1824+
connect( mActionDataSourceManager, &QAction::triggered, this, &QgisApp::dataSourceManager );
18111825
connect( mActionNewVectorLayer, &QAction::triggered, this, &QgisApp::newVectorLayer );
18121826
connect( mActionNewSpatiaLiteLayer, &QAction::triggered, this, &QgisApp::newSpatialiteLayer );
18131827
connect( mActionNewGeoPackageLayer, &QAction::triggered, this, &QgisApp::newGeoPackageLayer );
@@ -2364,6 +2378,7 @@ void QgisApp::createToolBars()
23642378

23652379
bt = new QToolButton();
23662380
bt->setPopupMode( QToolButton::MenuButtonPopup );
2381+
bt->addAction( mActionDataSourceManager );
23672382
bt->addAction( mActionNewVectorLayer );
23682383
bt->addAction( mActionNewSpatiaLiteLayer );
23692384
bt->addAction( mActionNewGeoPackageLayer );
@@ -2772,6 +2787,7 @@ void QgisApp::setTheme( const QString &themeName )
27722787
mActionSetLayerCRS->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionSetLayerCRS.png" ) ) );
27732788
mActionSetProjectCRSFromLayer->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionSetProjectCRSFromLayer.png" ) ) );
27742789
mActionNewVectorLayer->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionNewVectorLayer.svg" ) ) );
2790+
mActionDataSourceManager->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionDataSourceManager.svg" ) ) );
27752791
mActionNewMemoryLayer->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionCreateMemory.svg" ) ) );
27762792
mActionAddAllToOverview->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddAllToOverview.svg" ) ) );
27772793
mActionHideAllLayers->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionHideAllLayers.svg" ) ) );

‎src/app/qgisapp.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ class QgsLabelingWidget;
117117
class QgsLayerStylingWidget;
118118
class QgsDiagramProperties;
119119
class QgsLocatorWidget;
120+
class QgsDataSourceManagerDialog;
120121

121122
#include <QMainWindow>
122123
#include <QToolBar>
@@ -442,6 +443,7 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
442443
QAction *actionDraw() { return mActionDraw; }
443444

444445
QAction *actionNewVectorLayer() { return mActionNewVectorLayer; }
446+
QAction *actionDataSourceManager() { return mActionDataSourceManager; }
445447
QAction *actionNewSpatialLiteLayer() { return mActionNewSpatiaLiteLayer; }
446448
QAction *actionEmbedLayers() { return mActionEmbedLayers; }
447449
QAction *actionAddOgrLayer() { return mActionAddOgrLayer; }
@@ -780,6 +782,9 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
780782
//! Watch for QFileOpenEvent.
781783
virtual bool event( QEvent *event ) override;
782784

785+
//! Open the DataSourceManager dialog/dock
786+
void dataSourceManager( );
787+
783788
/** Add a raster layer directly without prompting user for location
784789
The caller must provide information compatible with the provider plugin
785790
using the uri and baseName. The provider can use these
@@ -1912,6 +1917,9 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
19121917
QgsStatisticalSummaryDockWidget *mStatisticalSummaryDockWidget = nullptr;
19131918
QgsBookmarks *mBookMarksDockWidget = nullptr;
19141919

1920+
//! Data Source Manager
1921+
QgsDataSourceManagerDialog *mDataSourceManagerDialog = nullptr;
1922+
19151923
//! snapping widget
19161924
QgsSnappingWidget *mSnappingWidget = nullptr;
19171925
QWidget *mSnappingDialogContainer = nullptr;
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#include <QMessageBox>
2+
#include <QListWidgetItem>
3+
#include <QMdiArea>
4+
#include <QMdiSubWindow>
5+
6+
#include "qgsdatasourcemanagerdialog.h"
7+
#include "ui_qgsdatasourcemanagerdialog.h"
8+
#include "qgsbrowserdockwidget.h"
9+
#include "qgssettings.h"
10+
#include "qgsproviderregistry.h"
11+
12+
QgsDataSourceManagerDialog::QgsDataSourceManagerDialog( QWidget *parent ) :
13+
QDialog( parent ),
14+
ui( new Ui::QgsDataSourceManagerDialog )
15+
{
16+
ui->setupUi( this );
17+
18+
// More setup
19+
int size = QgsSettings().value( QStringLiteral( "/IconSize" ), 24 ).toInt();
20+
// buffer size to match displayed icon size in toolbars, and expected geometry restore
21+
// newWidth (above) may need adjusted if you adjust iconBuffer here
22+
int iconBuffer = 4;
23+
ui->mList->setIconSize( QSize( size + iconBuffer, size + iconBuffer ) );
24+
ui->mList->setFrameStyle( QFrame::NoFrame );
25+
ui->mListFrame->layout()->setContentsMargins( 0, 3, 3, 3 );
26+
27+
// Bind list index to the stacked dialogs
28+
connect( ui->mList, SIGNAL( currentRowChanged( int ) ), this, SLOT( setCurrentPage( int ) ) );
29+
30+
// Add the browser widget to the first stacked widget page
31+
mBrowserWidget = new QgsBrowserDockWidget( QStringLiteral( "Browser" ), this );
32+
mBrowserWidget->setFeatures( QDockWidget::NoDockWidgetFeatures );
33+
ui->mStackedWidget->addWidget( mBrowserWidget );
34+
35+
// Add data provider dialogs
36+
37+
// WMS
38+
QDialog *wmss = dynamic_cast<QDialog *>( QgsProviderRegistry::instance()->createSelectionWidget( QStringLiteral( "wms" ), this ) );
39+
if ( !wmss )
40+
{
41+
QMessageBox::warning( this, tr( "WMS" ), tr( "Cannot get WMS select dialog from provider." ) );
42+
}
43+
else
44+
{
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" ) ) );
58+
}
59+
60+
}
61+
62+
QgsDataSourceManagerDialog::~QgsDataSourceManagerDialog()
63+
{
64+
delete ui;
65+
}
66+
67+
void QgsDataSourceManagerDialog::setCurrentPage( int index )
68+
{
69+
ui->mStackedWidget->setCurrentIndex( index );
70+
}

‎src/app/qgsdatasourcemanagerdialog.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#ifndef QGSDATASOURCEMANAGERDIALOG_H
2+
#define QGSDATASOURCEMANAGERDIALOG_H
3+
4+
#include <QList>
5+
#include <QDialog>
6+
class QgsBrowserDockWidget;
7+
8+
9+
namespace Ui
10+
{
11+
class QgsDataSourceManagerDialog;
12+
}
13+
14+
class QgsDataSourceManagerDialog : public QDialog
15+
{
16+
Q_OBJECT
17+
18+
public:
19+
explicit QgsDataSourceManagerDialog( QWidget *parent = 0 );
20+
~QgsDataSourceManagerDialog();
21+
22+
public slots:
23+
void setCurrentPage( int index );
24+
25+
private:
26+
Ui::QgsDataSourceManagerDialog *ui;
27+
QgsBrowserDockWidget *mBrowserWidget = nullptr;
28+
QList<QDialog *> mDialogs;
29+
};
30+
31+
#endif // QGSDATASOURCEMANAGERDIALOG_H

‎src/ui/qgisapp.ui

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,7 @@
352352
<attribute name="toolBarBreak">
353353
<bool>false</bool>
354354
</attribute>
355+
<addaction name="mActionDataSourceManager"/>
355356
<addaction name="mActionAddOgrLayer"/>
356357
<addaction name="mActionAddRasterLayer"/>
357358
<addaction name="mActionAddSpatiaLiteLayer"/>
@@ -2635,6 +2636,18 @@ Acts on currently active editable layer</string>
26352636
<string>Layout Extents</string>
26362637
</property>
26372638
</action>
2639+
<action name="mActionDataSourceManager">
2640+
<property name="icon">
2641+
<iconset resource="../../images/images.qrc">
2642+
<normaloff>:/images/themes/default/mActionDataSourceManager.svg</normaloff>:/images/themes/default/mActionDataSourceManager.svg</iconset>
2643+
</property>
2644+
<property name="text">
2645+
<string>&amp;Data Source Manager</string>
2646+
</property>
2647+
<property name="toolTip">
2648+
<string>Open Data Source Manager</string>
2649+
</property>
2650+
</action>
26382651
</widget>
26392652
<resources>
26402653
<include location="../../images/images.qrc"/>

‎src/ui/qgsdatasourcemanagerdialog.ui

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ui version="4.0">
3+
<class>QgsDataSourceManagerDialog</class>
4+
<widget class="QDialog" name="QgsDataSourceManagerDialog">
5+
<property name="geometry">
6+
<rect>
7+
<x>0</x>
8+
<y>0</y>
9+
<width>900</width>
10+
<height>600</height>
11+
</rect>
12+
</property>
13+
<property name="windowTitle">
14+
<string>Data Source Manager</string>
15+
</property>
16+
<layout class="QHBoxLayout" name="horizontalLayout_3">
17+
<item>
18+
<widget class="QSplitter" name="mSplitter">
19+
<property name="orientation">
20+
<enum>Qt::Horizontal</enum>
21+
</property>
22+
<widget class="QFrame" name="mListFrame">
23+
<property name="sizePolicy">
24+
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
25+
<horstretch>0</horstretch>
26+
<verstretch>0</verstretch>
27+
</sizepolicy>
28+
</property>
29+
<property name="frameShape">
30+
<enum>QFrame::StyledPanel</enum>
31+
</property>
32+
<property name="frameShadow">
33+
<enum>QFrame::Raised</enum>
34+
</property>
35+
<layout class="QHBoxLayout" name="horizontalLayout_2">
36+
<item>
37+
<widget class="QListWidget" name="mList">
38+
<property name="sizePolicy">
39+
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
40+
<horstretch>0</horstretch>
41+
<verstretch>0</verstretch>
42+
</sizepolicy>
43+
</property>
44+
<property name="minimumSize">
45+
<size>
46+
<width>58</width>
47+
<height>0</height>
48+
</size>
49+
</property>
50+
<property name="maximumSize">
51+
<size>
52+
<width>160</width>
53+
<height>16777215</height>
54+
</size>
55+
</property>
56+
<item>
57+
<property name="text">
58+
<string>Browser</string>
59+
</property>
60+
<property name="icon">
61+
<iconset resource="../../images/images.qrc">
62+
<normaloff>:/images/themes/default/mActionFileOpen.svg</normaloff>:/images/themes/default/mActionFileOpen.svg</iconset>
63+
</property>
64+
</item>
65+
</widget>
66+
</item>
67+
</layout>
68+
</widget>
69+
<widget class="QFrame" name="mDialogsFrame">
70+
<property name="sizePolicy">
71+
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
72+
<horstretch>0</horstretch>
73+
<verstretch>0</verstretch>
74+
</sizepolicy>
75+
</property>
76+
<property name="frameShape">
77+
<enum>QFrame::StyledPanel</enum>
78+
</property>
79+
<property name="frameShadow">
80+
<enum>QFrame::Raised</enum>
81+
</property>
82+
<layout class="QHBoxLayout" name="horizontalLayout">
83+
<item>
84+
<widget class="QStackedWidget" name="mStackedWidget">
85+
<property name="sizePolicy">
86+
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
87+
<horstretch>0</horstretch>
88+
<verstretch>0</verstretch>
89+
</sizepolicy>
90+
</property>
91+
<property name="currentIndex">
92+
<number>-1</number>
93+
</property>
94+
</widget>
95+
</item>
96+
</layout>
97+
</widget>
98+
</widget>
99+
</item>
100+
</layout>
101+
</widget>
102+
<resources>
103+
<include location="../../images/images.qrc"/>
104+
</resources>
105+
<connections/>
106+
</ui>

0 commit comments

Comments
 (0)
Please sign in to comment.