Skip to content
Permalink
Browse files

Merge pull request #2568 from mhugo/vlayers

Add support for virtual layers
  • Loading branch information
mhugo committed Dec 18, 2015
2 parents 13f4081 + 6ffec81 commit 60f246a350e4de894d2e88a85a0adae237b056cd
Showing with 5,305 additions and 2 deletions.
  1. +1 −0 python/core/core.sip
  2. +125 −0 python/core/qgsvirtuallayerdefinition.sip
  3. +1 −0 python/plugins/db_manager/db_plugins/CMakeLists.txt
  4. +7 −0 python/plugins/db_manager/db_plugins/vlayers/CMakeLists.txt
  5. 0 python/plugins/db_manager/db_plugins/vlayers/__init__.py
  6. +430 −0 python/plugins/db_manager/db_plugins/vlayers/connector.py
  7. +111 −0 python/plugins/db_manager/db_plugins/vlayers/data_model.py
  8. +46 −0 python/plugins/db_manager/db_plugins/vlayers/info_model.py
  9. +191 −0 python/plugins/db_manager/db_plugins/vlayers/plugin.py
  10. +5 −0 python/plugins/db_manager/db_plugins/vlayers/resources.qrc
  11. +136 −0 python/plugins/db_manager/db_plugins/vlayers/sql_dictionary.py
  12. +242 −0 python/plugins/db_manager/db_plugins/vlayers/vlayer.svg
  13. +1 −0 src/core/CMakeLists.txt
  14. +250 −0 src/core/qgsvirtuallayerdefinition.cpp
  15. +166 −0 src/core/qgsvirtuallayerdefinition.h
  16. +1 −0 src/providers/CMakeLists.txt
  17. +56 −0 src/providers/virtual/CMakeLists.txt
  18. +25 −0 src/providers/virtual/qgsslottofunction.h
  19. +220 −0 src/providers/virtual/qgsvirtuallayerblob.cpp
  20. +71 −0 src/providers/virtual/qgsvirtuallayerblob.h
  21. +236 −0 src/providers/virtual/qgsvirtuallayerfeatureiterator.cpp
  22. +71 −0 src/providers/virtual/qgsvirtuallayerfeatureiterator.h
  23. +636 −0 src/providers/virtual/qgsvirtuallayerprovider.cpp
  24. +146 −0 src/providers/virtual/qgsvirtuallayerprovider.h
  25. +274 −0 src/providers/virtual/qgsvirtuallayerqueryparser.cpp
  26. +70 −0 src/providers/virtual/qgsvirtuallayerqueryparser.h
  27. +189 −0 src/providers/virtual/qgsvirtuallayersqlitehelper.cpp
  28. +94 −0 src/providers/virtual/qgsvirtuallayersqlitehelper.h
  29. +682 −0 src/providers/virtual/qgsvirtuallayersqlitemodule.cpp
  30. +74 −0 src/providers/virtual/qgsvirtuallayersqlitemodule.h
  31. +2 −1 tests/src/python/CMakeLists.txt
  32. +664 −0 tests/src/python/test_provider_virtual.py
  33. +4 −1 tests/src/python/test_qgssipcoverage.py
  34. +78 −0 tests/src/python/test_qgsvirtuallayerdefinition.py
  35. BIN tests/testdata/shp_latin1.dbf
@@ -141,6 +141,7 @@
%Include qgsvectorlayerfeatureiterator.sip
%Include qgsvisibilitypresetcollection.sip
%Include qgslayerdefinition.sip
%Include qgsvirtuallayerdefinition.sip

%Include auth/qgsauthcertutils.sip
%Include auth/qgsauthconfig.sip
@@ -0,0 +1,125 @@
/**
* Class to manipulate the definition of a virtual layer
*
* It is used to extract parameters from an initial virtual layer definition as well as
* to store the complete, expanded definition once types have been detected.
*/
class QgsVirtualLayerDefinition
{
%TypeHeaderCode
#include <qgsvirtuallayerdefinition.h>
%End
public:
/**
* A SourceLayer is either a reference to a live layer in the registry
* or all the parameters needed to load it (provider key, source, etc.)
*/
class SourceLayer
{
public:
//! Constructor variant to build a live layer reference
SourceLayer( const QString& name, const QString& ref );
//! Constructor variant to build a layer with a provider and a source
SourceLayer( const QString& name, const QString& source, const QString& provider, const QString& encoding );

//! Is it a live layer or not ?
bool isReferenced() const;

//! The reference (id) of the live layer
QString reference() const;

//! Name of the layer
QString name() const;

//! Provider key
QString provider() const;

//! The source url used by the provider to build the layer
QString source() const;

//! Optional encoding for the provider
QString encoding() const;
};

//! Constructor with an optional file path
QgsVirtualLayerDefinition( const QString& filePath = "" );

//! Constructor to build a definition from a QUrl
//! The path part of the URL is extracted as well as the following optional keys:
//! layer_ref=layer_id[:name] represents a live layer referenced by its ID. An optional name can be given
//! layer=provider:source[:name[:encoding]] represents a layer given by its provider key, its source url (URL-encoded).
//! An optional name and encoding can be given
//! geometry=column_name[:type:srid] gives the definition of the geometry column.
//! Type can be either a WKB type code or a string (point, linestring, etc.)
//! srid is an integer
//! uid=column_name is the name of a column with unique integer values.
//! nogeometry is a flag to force the layer to be a non-geometry layer
//! query=sql represents the SQL query. Must be URL-encoded
//! field=column_name:[int|real|text] represents a field with its name and its type
static QgsVirtualLayerDefinition fromUrl( const QUrl& url );

//! Convert the definition into a QUrl
QUrl toUrl() const;

//! Convert into a QString that can be read by the virtual layer provider
QString toString() const;

//! Add a live layer source layer
void addSource( const QString& name, const QString ref );

//! Add a layer with a source, a provider and an encoding
void addSource( const QString& name, const QString source, const QString& provider, const QString& encoding = "" );

//! List of source layers
typedef QList<QgsVirtualLayerDefinition::SourceLayer> SourceLayers;

//! Get access to the source layers
const SourceLayers& sourceLayers() const;

//! Get the SQL query
QString query() const;
//! Set the SQL query
void setQuery( const QString& query );

//! Get the file path. May be empty
QString filePath() const;
//! Set the file path
void setFilePath( const QString& filePath );

//! Get the name of the field with unique identifiers
QString uid() const;
//! Set the name of the field with unique identifiers
void setUid( const QString& uid );

//! Get the name of the geometry field. Empty if no geometry field
QString geometryField() const;
//! Set the name of the geometry field
void setGeometryField( const QString& geometryField );

//! Get the type of the geometry
//! QgsWKBTypes::NoGeometry to hide any geometry
//! QgsWKBTypes::Unknown for unknown types
QgsWKBTypes::Type geometryWkbType() const;
//! Set the type of the geometry
void setGeometryWkbType( QgsWKBTypes::Type t );

//! Get the SRID of the geometry
long geometrySrid() const;
//! Set the SRID of the geometry
void setGeometrySrid( long srid );

//! Get field definitions
const QgsFields& fields() const;
//! Set field definitions
void setFields( const QgsFields& fields );

//! Convenience method to test if a given source layer is part of the definition
bool hasSourceLayer( QString name ) const;

//! Convenience method to test whether the definition has referenced (live) layers
bool hasReferencedLayers() const;

//! Convenient method to test if the geometry is defined (not NoGeometry and not Unknown)
bool hasDefinedGeometry() const;
};

@@ -3,6 +3,7 @@ ADD_SUBDIRECTORY(spatialite)
IF(WITH_ORACLE)
ADD_SUBDIRECTORY(oracle)
ENDIF(WITH_ORACLE)
ADD_SUBDIRECTORY(vlayers)

FILE(GLOB PY_FILES *.py)
PLUGIN_INSTALL(db_manager db_plugins ${PY_FILES})
@@ -0,0 +1,7 @@

FILE(GLOB PY_FILES *.py)

PYQT_ADD_RESOURCES(PYRC_FILES resources.qrc)

PLUGIN_INSTALL(db_manager db_plugins/vlayers ${PY_FILES} ${PYRC_FILES})

No changes.

0 comments on commit 60f246a

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