Skip to content

Commit 14db137

Browse files
committed
Resurrect dedicated action to create virtual layers in main window
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
1 parent e4df72e commit 14db137

File tree

5 files changed

+179
-2
lines changed

5 files changed

+179
-2
lines changed

images/images.qrc

+1
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,7 @@
744744
<file>themes/default/mIconFieldBool.svg</file>
745745
<file>themes/default/mIconDataDefineColor.svg</file>
746746
<file>themes/default/mIconDataDefineColorOn.svg</file>
747+
<file>themes/default/mActionNewVirtualLayer.svg</file>
747748
</qresource>
748749
<qresource prefix="/images/tips">
749750
<file alias="symbol_levels.png">qgis_tips/symbol_levels.png</file>
Loading

src/app/qgisapp.cpp

+8-2
Original file line numberDiff line numberDiff line change
@@ -2203,6 +2203,7 @@ void QgisApp::createActions()
22032203
connect( mActionNewSpatiaLiteLayer, &QAction::triggered, this, &QgisApp::newSpatialiteLayer );
22042204
connect( mActionNewGeoPackageLayer, &QAction::triggered, this, &QgisApp::newGeoPackageLayer );
22052205
connect( mActionNewMemoryLayer, &QAction::triggered, this, &QgisApp::newMemoryLayer );
2206+
connect( mActionNewVirtualLayer, &QAction::triggered, this, &QgisApp::addVirtualLayer );
22062207
connect( mActionShowRasterCalculator, &QAction::triggered, this, &QgisApp::showRasterCalculator );
22072208
connect( mActionShowMeshCalculator, &QAction::triggered, this, &QgisApp::showMeshCalculator );
22082209
connect( mActionShowAlignRasterTool, &QAction::triggered, this, &QgisApp::showAlignRasterTool );
@@ -5316,15 +5317,15 @@ void QgisApp::addDatabaseLayers( QStringList const &layerPathList, QString const
53165317

53175318
void QgisApp::addVirtualLayer()
53185319
{
5319-
// show the Delimited text dialog
5320+
// show the virtual layer dialog
53205321
QDialog *dts = dynamic_cast<QDialog *>( QgsProviderRegistry::instance()->createSelectionWidget( QStringLiteral( "virtual" ), this ) );
53215322
if ( !dts )
53225323
{
53235324
QMessageBox::warning( this, tr( "Add Virtual Layer" ), tr( "Cannot get virtual layer select dialog from provider." ) );
53245325
return;
53255326
}
53265327
connect( dts, SIGNAL( addVectorLayer( QString, QString, QString ) ),
5327-
this, SLOT( addSelectedVectorLayer( QString, QString, QString ) ) );
5328+
this, SLOT( onVirtualLayerAdded( QString, QString ) ) );
53285329
connect( dts, SIGNAL( replaceVectorLayer( QString, QString, QString, QString ) ),
53295330
this, SLOT( replaceSelectedVectorLayer( QString, QString, QString, QString ) ) );
53305331
dts->exec();
@@ -12137,6 +12138,11 @@ int QgisApp::addDatabaseToolBarIcon( QAction *qAction )
1213712138
return 0;
1213812139
}
1213912140

12141+
void QgisApp::onVirtualLayerAdded( const QString &uri, const QString &layerName )
12142+
{
12143+
addVectorLayer( uri, layerName, QStringLiteral( "virtual" ) );
12144+
}
12145+
1214012146
QAction *QgisApp::addDatabaseToolBarWidget( QWidget *widget )
1214112147
{
1214212148
return mDatabaseToolBar->addWidget( widget );

src/app/qgisapp.h

+2
Original file line numberDiff line numberDiff line change
@@ -1244,6 +1244,8 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
12441244
//! Add an icon to the Database toolbar
12451245
int addDatabaseToolBarIcon( QAction *qAction );
12461246

1247+
void onVirtualLayerAdded( const QString &uri, const QString &layerName );
1248+
12471249
/**
12481250
* Add a widget to the database toolbar.
12491251
* To remove this widget again, call removeDatabaseToolBarIcon()

src/ui/qgisapp.ui

+16
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,8 @@
164164
<addaction name="mActionNewVectorLayer"/>
165165
<addaction name="mActionNewSpatiaLiteLayer"/>
166166
<addaction name="mActionNewMemoryLayer"/>
167+
<addaction name="separator"/>
168+
<addaction name="mActionNewVirtualLayer"/>
167169
</widget>
168170
<widget class="QMenu" name="mAddLayerMenu">
169171
<property name="title">
@@ -683,6 +685,8 @@
683685
<addaction name="mActionNewVectorLayer"/>
684686
<addaction name="mActionNewSpatiaLiteLayer"/>
685687
<addaction name="mActionNewMemoryLayer"/>
688+
<addaction name="separator"/>
689+
<addaction name="mActionNewVirtualLayer"/>
686690
</widget>
687691
<widget class="QToolBar" name="mShapeDigitizeToolBar">
688692
<property name="windowTitle">
@@ -3171,6 +3175,18 @@ Acts on currently active editable layer</string>
31713175
<string>Add Mesh Layer...</string>
31723176
</property>
31733177
</action>
3178+
<action name="mActionNewVirtualLayer">
3179+
<property name="icon">
3180+
<iconset resource="../../images/images.qrc">
3181+
<normaloff>:/images/themes/default/mActionNewVirtualLayer.svg</normaloff>:/images/themes/default/mActionNewVirtualLayer.svg</iconset>
3182+
</property>
3183+
<property name="text">
3184+
<string>New Virtual Layer…</string>
3185+
</property>
3186+
<property name="toolTip">
3187+
<string>New Virtual Layer</string>
3188+
</property>
3189+
</action>
31743190
</widget>
31753191
<resources>
31763192
<include location="../../images/images.qrc"/>

0 commit comments

Comments
 (0)