Skip to content

Commit

Permalink
Resurrect dedicated action to create virtual layers in main window
Browse files Browse the repository at this point in the history
This was removed when the data source manager was created, but
new virtual layers are a "creation" action, so it belongs alongside
the other "Create" actions like new shapefile, new gpkg, etc

It "feels" more natural then using the open data source dialog
to create a new virtual layer
  • Loading branch information
nyalldawson committed Feb 6, 2019
1 parent e4df72e commit 14db137
Show file tree
Hide file tree
Showing 5 changed files with 179 additions and 2 deletions.
1 change: 1 addition & 0 deletions images/images.qrc
Expand Up @@ -744,6 +744,7 @@
<file>themes/default/mIconFieldBool.svg</file>
<file>themes/default/mIconDataDefineColor.svg</file>
<file>themes/default/mIconDataDefineColorOn.svg</file>
<file>themes/default/mActionNewVirtualLayer.svg</file>
</qresource>
<qresource prefix="/images/tips">
<file alias="symbol_levels.png">qgis_tips/symbol_levels.png</file>
Expand Down
152 changes: 152 additions & 0 deletions images/themes/default/mActionNewVirtualLayer.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 8 additions & 2 deletions src/app/qgisapp.cpp
Expand Up @@ -2203,6 +2203,7 @@ void QgisApp::createActions()
connect( mActionNewSpatiaLiteLayer, &QAction::triggered, this, &QgisApp::newSpatialiteLayer );
connect( mActionNewGeoPackageLayer, &QAction::triggered, this, &QgisApp::newGeoPackageLayer );
connect( mActionNewMemoryLayer, &QAction::triggered, this, &QgisApp::newMemoryLayer );
connect( mActionNewVirtualLayer, &QAction::triggered, this, &QgisApp::addVirtualLayer );
connect( mActionShowRasterCalculator, &QAction::triggered, this, &QgisApp::showRasterCalculator );
connect( mActionShowMeshCalculator, &QAction::triggered, this, &QgisApp::showMeshCalculator );
connect( mActionShowAlignRasterTool, &QAction::triggered, this, &QgisApp::showAlignRasterTool );
Expand Down Expand Up @@ -5316,15 +5317,15 @@ void QgisApp::addDatabaseLayers( QStringList const &layerPathList, QString const

void QgisApp::addVirtualLayer()
{
// show the Delimited text dialog
// show the virtual layer dialog
QDialog *dts = dynamic_cast<QDialog *>( QgsProviderRegistry::instance()->createSelectionWidget( QStringLiteral( "virtual" ), this ) );
if ( !dts )
{
QMessageBox::warning( this, tr( "Add Virtual Layer" ), tr( "Cannot get virtual layer select dialog from provider." ) );
return;
}
connect( dts, SIGNAL( addVectorLayer( QString, QString, QString ) ),
this, SLOT( addSelectedVectorLayer( QString, QString, QString ) ) );
this, SLOT( onVirtualLayerAdded( QString, QString ) ) );
connect( dts, SIGNAL( replaceVectorLayer( QString, QString, QString, QString ) ),
this, SLOT( replaceSelectedVectorLayer( QString, QString, QString, QString ) ) );
dts->exec();
Expand Down Expand Up @@ -12137,6 +12138,11 @@ int QgisApp::addDatabaseToolBarIcon( QAction *qAction )
return 0;
}

void QgisApp::onVirtualLayerAdded( const QString &uri, const QString &layerName )
{
addVectorLayer( uri, layerName, QStringLiteral( "virtual" ) );
}

QAction *QgisApp::addDatabaseToolBarWidget( QWidget *widget )
{
return mDatabaseToolBar->addWidget( widget );
Expand Down
2 changes: 2 additions & 0 deletions src/app/qgisapp.h
Expand Up @@ -1244,6 +1244,8 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
//! Add an icon to the Database toolbar
int addDatabaseToolBarIcon( QAction *qAction );

void onVirtualLayerAdded( const QString &uri, const QString &layerName );

/**
* Add a widget to the database toolbar.
* To remove this widget again, call removeDatabaseToolBarIcon()
Expand Down
16 changes: 16 additions & 0 deletions src/ui/qgisapp.ui
Expand Up @@ -164,6 +164,8 @@
<addaction name="mActionNewVectorLayer"/>
<addaction name="mActionNewSpatiaLiteLayer"/>
<addaction name="mActionNewMemoryLayer"/>
<addaction name="separator"/>
<addaction name="mActionNewVirtualLayer"/>
</widget>
<widget class="QMenu" name="mAddLayerMenu">
<property name="title">
Expand Down Expand Up @@ -683,6 +685,8 @@
<addaction name="mActionNewVectorLayer"/>
<addaction name="mActionNewSpatiaLiteLayer"/>
<addaction name="mActionNewMemoryLayer"/>
<addaction name="separator"/>
<addaction name="mActionNewVirtualLayer"/>
</widget>
<widget class="QToolBar" name="mShapeDigitizeToolBar">
<property name="windowTitle">
Expand Down Expand Up @@ -3171,6 +3175,18 @@ Acts on currently active editable layer</string>
<string>Add Mesh Layer...</string>
</property>
</action>
<action name="mActionNewVirtualLayer">
<property name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/mActionNewVirtualLayer.svg</normaloff>:/images/themes/default/mActionNewVirtualLayer.svg</iconset>
</property>
<property name="text">
<string>New Virtual Layer…</string>
</property>
<property name="toolTip">
<string>New Virtual Layer</string>
</property>
</action>
</widget>
<resources>
<include location="../../images/images.qrc"/>
Expand Down

0 comments on commit 14db137

Please sign in to comment.