Skip to content
Permalink
Browse files

[addlayerbutton] Initial implementation

  • Loading branch information
elpaso committed Jun 2, 2017
1 parent c9e6f15 commit b2dea8e058ad8d76ddafc71dcba9e76f7bad8668
@@ -102,6 +102,7 @@
<file>themes/default/lockedGray.svg</file>
<file>themes/default/mAction.svg</file>
<file>themes/default/mActionAdd.svg</file>
<file>themes/default/mActionDataSourceManager.svg</file>
<file>themes/default/mActionAddLayer.svg</file>
<file>themes/default/mActionAddAllToOverview.svg</file>
<file>themes/default/mActionAddArrow.svg</file>
@@ -61,6 +61,7 @@ SET(QGIS_APP_SRCS
qgsversioninfo.cpp
qgswelcomepageitemsmodel.cpp
qgswelcomepage.cpp
qgsdatasourcemanagerdialog.cpp

qgsmaptooladdfeature.cpp
qgsmaptooladdpart.cpp
@@ -247,6 +248,7 @@ SET (QGIS_APP_MOC_HDRS
qgsversioninfo.h
qgswelcomepageitemsmodel.h
qgswelcomepage.h
qgsdatasourcemanagerdialog.h

qgsmaptooladdfeature.h
qgsmaptoolannotation.h
@@ -285,6 +285,7 @@ Q_GUI_EXPORT extern int qt_defaultDpiX();
#include "qgsmapdecoration.h"
#include "qgsnewnamedialog.h"
#include "qgsgui.h"
#include "qgsdatasourcemanagerdialog.h"

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

delete mTray;

delete mDataSourceManagerDialog;
}

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

void QgisApp::dataSourceManager()
{
if ( ! mDataSourceManagerDialog )
{
mDataSourceManagerDialog = new QgsDataSourceManagerDialog( this );
}
// TODO: handle docked
mDataSourceManagerDialog->exec();
}

QgisAppStyleSheet *QgisApp::styleSheetBuilder()
{
Q_ASSERT( mStyleSheetBuilder );
@@ -1808,6 +1821,7 @@ void QgisApp::createActions()

// Layer Menu Items

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

bt = new QToolButton();
bt->setPopupMode( QToolButton::MenuButtonPopup );
bt->addAction( mActionDataSourceManager );
bt->addAction( mActionNewVectorLayer );
bt->addAction( mActionNewSpatiaLiteLayer );
bt->addAction( mActionNewGeoPackageLayer );
@@ -2772,6 +2787,7 @@ void QgisApp::setTheme( const QString &themeName )
mActionSetLayerCRS->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionSetLayerCRS.png" ) ) );
mActionSetProjectCRSFromLayer->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionSetProjectCRSFromLayer.png" ) ) );
mActionNewVectorLayer->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionNewVectorLayer.svg" ) ) );
mActionDataSourceManager->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionDataSourceManager.svg" ) ) );
mActionNewMemoryLayer->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionCreateMemory.svg" ) ) );
mActionAddAllToOverview->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddAllToOverview.svg" ) ) );
mActionHideAllLayers->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionHideAllLayers.svg" ) ) );
@@ -117,6 +117,7 @@ class QgsLabelingWidget;
class QgsLayerStylingWidget;
class QgsDiagramProperties;
class QgsLocatorWidget;
class QgsDataSourceManagerDialog;

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

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

//! Open the DataSourceManager dialog/dock
void dataSourceManager( );

/** Add a raster layer directly without prompting user for location
The caller must provide information compatible with the provider plugin
using the uri and baseName. The provider can use these
@@ -1912,6 +1917,9 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
QgsStatisticalSummaryDockWidget *mStatisticalSummaryDockWidget = nullptr;
QgsBookmarks *mBookMarksDockWidget = nullptr;

//! Data Source Manager
QgsDataSourceManagerDialog *mDataSourceManagerDialog = nullptr;

//! snapping widget
QgsSnappingWidget *mSnappingWidget = nullptr;
QWidget *mSnappingDialogContainer = nullptr;
@@ -0,0 +1,70 @@
#include <QMessageBox>
#include <QListWidgetItem>
#include <QMdiArea>
#include <QMdiSubWindow>

#include "qgsdatasourcemanagerdialog.h"
#include "ui_qgsdatasourcemanagerdialog.h"
#include "qgsbrowserdockwidget.h"
#include "qgssettings.h"
#include "qgsproviderregistry.h"

QgsDataSourceManagerDialog::QgsDataSourceManagerDialog( QWidget *parent ) :
QDialog( parent ),
ui( new Ui::QgsDataSourceManagerDialog )
{
ui->setupUi( this );

// More setup
int size = QgsSettings().value( QStringLiteral( "/IconSize" ), 24 ).toInt();
// buffer size to match displayed icon size in toolbars, and expected geometry restore
// newWidth (above) may need adjusted if you adjust iconBuffer here
int iconBuffer = 4;
ui->mList->setIconSize( QSize( size + iconBuffer, size + iconBuffer ) );
ui->mList->setFrameStyle( QFrame::NoFrame );
ui->mListFrame->layout()->setContentsMargins( 0, 3, 3, 3 );

// Bind list index to the stacked dialogs
connect( ui->mList, SIGNAL( currentRowChanged( int ) ), this, SLOT( setCurrentPage( int ) ) );

// Add the browser widget to the first stacked widget page
mBrowserWidget = new QgsBrowserDockWidget( QStringLiteral( "Browser" ), this );
mBrowserWidget->setFeatures( QDockWidget::NoDockWidgetFeatures );
ui->mStackedWidget->addWidget( mBrowserWidget );

// Add data provider dialogs

// WMS
QDialog *wmss = dynamic_cast<QDialog *>( QgsProviderRegistry::instance()->createSelectionWidget( QStringLiteral( "wms" ), this ) );
if ( !wmss )
{
QMessageBox::warning( this, tr( "WMS" ), tr( "Cannot get WMS select dialog from provider." ) );
}
else
{
connect( wmss, SIGNAL( addRasterLayer( QString const &, QString const &, QString const & ) ),
qApp, SLOT( addRasterLayer( QString const &, QString const &, QString const & ) ) );
//wmss->exec();
wmss->setWindowFlags( Qt::Widget );
QMdiArea *wmsMdi = new QMdiArea( this );
QMdiSubWindow *wmsSub;
wmsMdi->setViewMode( QMdiArea::TabbedView );
wmsSub = wmsMdi->addSubWindow( wmss );
wmsSub->show();
ui->mStackedWidget->addWidget( wmsMdi );
mDialogs.append( wmss ); // TODO: rm
QListWidgetItem *wmsItem = new QListWidgetItem( tr( "WMS" ), ui->mList );
wmsItem->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddWmsLayer.svg" ) ) );
}

}

QgsDataSourceManagerDialog::~QgsDataSourceManagerDialog()
{
delete ui;
}

void QgsDataSourceManagerDialog::setCurrentPage( int index )
{
ui->mStackedWidget->setCurrentIndex( index );
}
@@ -0,0 +1,31 @@
#ifndef QGSDATASOURCEMANAGERDIALOG_H
#define QGSDATASOURCEMANAGERDIALOG_H

#include <QList>
#include <QDialog>
class QgsBrowserDockWidget;


namespace Ui
{
class QgsDataSourceManagerDialog;
}

class QgsDataSourceManagerDialog : public QDialog
{
Q_OBJECT

public:
explicit QgsDataSourceManagerDialog( QWidget *parent = 0 );
~QgsDataSourceManagerDialog();

public slots:
void setCurrentPage( int index );

private:
Ui::QgsDataSourceManagerDialog *ui;
QgsBrowserDockWidget *mBrowserWidget = nullptr;
QList<QDialog *> mDialogs;
};

#endif // QGSDATASOURCEMANAGERDIALOG_H
@@ -352,6 +352,7 @@
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
<addaction name="mActionDataSourceManager"/>
<addaction name="mActionAddOgrLayer"/>
<addaction name="mActionAddRasterLayer"/>
<addaction name="mActionAddSpatiaLiteLayer"/>
@@ -2635,6 +2636,18 @@ Acts on currently active editable layer</string>
<string>Layout Extents</string>
</property>
</action>
<action name="mActionDataSourceManager">
<property name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/mActionDataSourceManager.svg</normaloff>:/images/themes/default/mActionDataSourceManager.svg</iconset>
</property>
<property name="text">
<string>&amp;Data Source Manager</string>
</property>
<property name="toolTip">
<string>Open Data Source Manager</string>
</property>
</action>
</widget>
<resources>
<include location="../../images/images.qrc"/>
@@ -0,0 +1,106 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>QgsDataSourceManagerDialog</class>
<widget class="QDialog" name="QgsDataSourceManagerDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>900</width>
<height>600</height>
</rect>
</property>
<property name="windowTitle">
<string>Data Source Manager</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QSplitter" name="mSplitter">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<widget class="QFrame" name="mListFrame">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QListWidget" name="mList">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>58</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>160</width>
<height>16777215</height>
</size>
</property>
<item>
<property name="text">
<string>Browser</string>
</property>
<property name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/mActionFileOpen.svg</normaloff>:/images/themes/default/mActionFileOpen.svg</iconset>
</property>
</item>
</widget>
</item>
</layout>
</widget>
<widget class="QFrame" name="mDialogsFrame">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QStackedWidget" name="mStackedWidget">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="currentIndex">
<number>-1</number>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</widget>
<resources>
<include location="../../images/images.qrc"/>
</resources>
<connections/>
</ui>

0 comments on commit b2dea8e

Please sign in to comment.
You can’t perform that action at this time.