Skip to content
Permalink
Browse files

Merge pull request #2915 from mhugo/fix_vlayers

Various fixes for virtual layers
  • Loading branch information
Hugo Mercier
Hugo Mercier committed Mar 24, 2016
2 parents 15b3600 + 7dbc0bf commit 140b51728a6ead04bd5b91dd039a40aef89dbb2e
@@ -26,7 +26,7 @@
from ..plugin import DbError

from PyQt.QtCore import QUrl, QTime, QTemporaryFile
from qgis.core import QGis, QgsVectorLayer
from qgis.core import QGis, QgsVectorLayer, QgsWKBTypes


class LTableDataModel(TableDataModel):
@@ -46,7 +46,13 @@ def __init__(self, table, parent=None):
# populate self.resdata
self.resdata = []
for f in self.layer.getFeatures():
self.resdata.append(f.attributes())
a = f.attributes()
# add the geometry type
if f.geometry():
a.append(QgsWKBTypes.displayString(QGis.fromOldWkbType(f.geometry().wkbType())))
else:
a.append('None')
self.resdata.append(a)

self.fetchedFrom = 0
self.fetchedCount = len(self.resdata)
@@ -249,6 +249,11 @@ QMenu* QgsAppLayerTreeViewMenuProvider::createContextMenu()

if ( mView->selectedNodes( true ).count() >= 2 )
menu->addAction( actions->actionGroupSelected( menu ) );

if ( layer && layer->type() == QgsMapLayer::VectorLayer && static_cast<QgsVectorLayer*>( layer )->providerType() == "virtual" )
{
menu->addAction( tr( "Edit virtual layer settings" ), QgisApp::instance(), SLOT( addVirtualLayer() ) );
}
}

}
@@ -237,7 +237,7 @@ bool QgsVirtualLayerProvider::createIt()
continue;

const QgsVectorLayer* vl = static_cast<const QgsVectorLayer*>( l );
if (( vl->name() == tname ) || ( vl->id() == tname ) )
if (( vl->name() == tname ) || ( vl->name().toLower() == tname.toLower() ) || ( vl->id() == tname ) )
{
mDefinition.addSource( tname, vl->id() );
found = true;
@@ -50,12 +50,16 @@
<property name="title">
<string>Embedded layers</string>
</property>
<property name="collapsed">
<bool>true</bool>
<property name="collapsed" stdset="0">
<bool>false</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<widget class="QTableWidget" name="mLayersTable">
<property name="toolTip">
<string>Embedded layers can be added to have SQL queries with layers that are independent from layers loaded by the current QGIS project.
In particular, saving a virtual layer with embedded layers to a QLR file can be done to reuse its definition in another project.</string>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::SingleSelection</enum>
</property>
@@ -161,9 +165,8 @@
<item>
<widget class="QgsCodeEditorSQL" name="mQueryEdit" native="true">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;This is the SQL query editor.&lt;/p&gt;&lt;p&gt;Virtual layers rely on SQLite and Spatialite. Any functions from SQLite or Spatialite can then be used in the query.&lt;/p&gt;&lt;p&gt;&lt;span style=&quot; font-weight:600;&quot;&gt;Special comments:&lt;/span&gt;&lt;/p&gt;&lt;p&gt;Because it is not always possible to autodetect the data type of each column in a query, special comments can be used in the query to force a specific type.&lt;/p&gt;&lt;p&gt;Special comments must be placed on the right of a column name and have the form &lt;tt&gt;/*:type*/&lt;/tt&gt; where type can be any of &lt;span style=&quot; font-style:italic;&quot;&gt;int&lt;/span&gt;, &lt;span style=&quot; font-style:italic;&quot;&gt;real&lt;/span&gt; or &lt;span style=&quot; font-style:italic;&quot;&gt;text&lt;/span&gt;. They can also be used to specify the type and SRID of the geometry column with the following syntax: &lt;tt&gt;/*:gtype:srid*/&lt;/tt&gt; where &lt;span style=&quot; font-style:italic;&quot;&gt;gtype&lt;/span&gt; can be &lt;span style=&quot; font-style:italic;&quot;&gt;point&lt;/span&gt;, &lt;span style=&quot; font-style:italic;&quot;&gt;linestring&lt;/span&gt; or &lt;span style=&quot; font-style:italic;&quot;&gt;polygon&lt;/span&gt; (with an optional &lt;span style=&quot; font-style:italic;&quot;&gt;multi&lt;/span&gt; prefix) and &lt;span style=&quot; font-style:italic;&quot;&gt;srid&lt;/span&gt; is an integer identifier.&lt;/p&gt;&lt;p&gt;Example:&lt;/p&gt;&lt;p&gt;&lt;tt&gt;SELECT id + 1 as id /*:int*/, ST_Centroid(geometry) as geom /*:point:4326*/ FROM tab&lt;/tt&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;This is the SQL query editor. You can edit here an SQL query refering to any existing vector layers or embedded layers.&lt;/p&gt;&lt;p&gt;Virtual layers rely on SQLite and Spatialite. Any functions from SQLite or Spatialite can then be used in the query. To add or access geometries of a table, you can use &quot;tablename.geometry&quot;, regardless of original geometry column's name.&lt;/p&gt;&lt;p&gt;&lt;span style=&quot; font-weight:600;&quot;&gt;Special comments:&lt;/span&gt;&lt;/p&gt;&lt;p&gt;Because it is not always possible to autodetect the data type of each column in a query, special comments can be used in the query to force a specific type.&lt;/p&gt;&lt;p&gt;Special comments must be placed on the right of a column name and have the form &lt;tt&gt;/*:type*/&lt;/tt&gt; where type can be any of &lt;span style=&quot; font-style:italic;&quot;&gt;int&lt;/span&gt;, &lt;span style=&quot; font-style:italic;&quot;&gt;real&lt;/span&gt; or &lt;span style=&quot; font-style:italic;&quot;&gt;text&lt;/span&gt;. They can also be used to specify the type and SRID of the geometry column with the following syntax: &lt;tt&gt;/*:gtype:srid*/&lt;/tt&gt; where &lt;span style=&quot; font-style:italic;&quot;&gt;gtype&lt;/span&gt; can be &lt;span style=&quot; font-style:italic;&quot;&gt;point&lt;/span&gt;, &lt;span style=&quot; font-style:italic;&quot;&gt;linestring&lt;/span&gt; or &lt;span style=&quot; font-style:italic;&quot;&gt;polygon&lt;/span&gt; (with an optional &lt;span style=&quot; font-style:italic;&quot;&gt;multi&lt;/span&gt; prefix) and &lt;span style=&quot; font-style:italic;&quot;&gt;srid&lt;/span&gt; is an integer identifier.&lt;/p&gt;&lt;p&gt;Example:&lt;/p&gt;&lt;p&gt;&lt;tt&gt;SELECT id + 1 as id /*:int*/, ST_Centroid(geometry) as geom /*:point:4326*/ FROM tab&lt;/tt&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<zorder>mEmbeddedlLayersGroup</zorder>
</widget>
</item>
</layout>
@@ -195,7 +198,7 @@
<property name="title">
<string>Geometry</string>
</property>
<property name="collapsed">
<property name="collapsed" stdset="0">
<bool>true</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
@@ -2233,10 +2233,10 @@ Acts on currently active editable layer</string>
<normaloff>:/images/themes/default/mActionAddVirtualLayer.svg</normaloff>:/images/themes/default/mActionAddVirtualLayer.svg</iconset>
</property>
<property name="text">
<string>Add Virtual Layer...</string>
<string>Add/Edit Virtual Layer...</string>
</property>
<property name="toolTip">
<string>Add Virtual Layer</string>
<string>Add/Edit Virtual Layer</string>
</property>
</action>
<action name="mActionPasteAsNewVector">

0 comments on commit 140b517

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