Skip to content
Permalink
Browse files

Add autocompletion to the virtual layer SQL editor

  • Loading branch information
mhugo committed Jan 5, 2016
1 parent 8bbdff4 commit 0eb6ccaf51d253cbf8424fb987ca910190227a72
@@ -2,6 +2,8 @@
########################################################
# Files

QT4_ADD_RESOURCES(QGIS_VLAYER_SQL_FUNCTIONS_RCC sqlfunctionslist.qrc)

QT4_WRAP_CPP(vlayer_provider_MOC_SRCS
qgsvirtuallayerprovider.h
qgsslottofunction.h
@@ -13,6 +15,7 @@ QT4_WRAP_UI(vlayer_provider_UI_H qgsvirtuallayersourceselectbase.ui)
SET(QGIS_VLAYER_PROVIDER_SRCS
${vlayer_provider_MOC_SRCS}
${vlayer_provider_UI_H}
${QGIS_VLAYER_SQL_FUNCTIONS_RCC}
qgsvirtuallayerprovider.cpp
qgsvirtuallayerfeatureiterator.cpp
qgsvirtuallayerblob.cpp
@@ -21,11 +21,13 @@ email : hugo dot mercier at oslandia dot com
#include <layertree/qgslayertreeview.h>
#include <qgsvectorlayer.h>
#include <qgsvectordataprovider.h>
#include <qgsmaplayerregistry.h>
#include <qgsgenericprojectionselector.h>

#include <QUrl>
#include <Qsci/qscilexer.h>
#include <QMessageBox>
#include <QTextStream>

QgsVirtualLayerSourceSelect::QgsVirtualLayerSourceSelect( QWidget* parent, Qt::WindowFlags fl )
: QDialog( parent, fl )
@@ -73,6 +75,38 @@ QgsVirtualLayerSourceSelect::QgsVirtualLayerSourceSelect( QWidget* parent, Qt::W
}
}
}

// configure auto completion with SQL functions
QsciAPIs* apis = new QsciAPIs( mQueryEdit->lexer() );

Q_INIT_RESOURCE( sqlfunctionslist );
QFile fFile( ":/sqlfunctions/list.txt" );
if ( fFile.open( QIODevice::ReadOnly ) )
{
QTextStream in( &fFile );
while ( !in.atEnd() )
{
apis->add( in.readLine().toLower() + "()" );
}
fFile.close();
}

// configure auto completion with table and column names
foreach ( QgsMapLayer* l, QgsMapLayerRegistry::instance()->mapLayers().values() )
{
if ( l->type() == QgsMapLayer::VectorLayer )
{
apis->add( l->name() );
QgsVectorLayer* vl = static_cast<QgsVectorLayer*>( l );
foreach ( const QgsField& f, vl->fields().toList() )
{
apis->add( f.name() );
}
}
}

apis->prepare();
mQueryEdit->lexer()->setAPIs( apis );
}

QgsVirtualLayerSourceSelect::~QgsVirtualLayerSourceSelect()
@@ -0,0 +1,60 @@
MakePoint
BuildMbr
ST_MinX
ST_MinY
ST_MaxX
ST_MaxY
ST_GeomFromText
ST_AsText
ST_AsBinary
ST_Dimension
ST_GeometryType
ST_Srid
ST_SetSrid
ST_isEmpty
ST_isSimple
ST_isValid
ST_Boundary
ST_Envelope
ST_X
ST_Y
ST_StartPoint
ST_EndPoint
ST_Length
ST_isClosed
ST_isRing
ST_Simplify
ST_NumPoints
ST_PointN
ST_Centroid
ST_PointOnSurface
ST_Area
ST_ExteriorRing
ST_InteriorRingN
ST_NumGeometries
ST_GeometryN
MbrEqual
MbrDisjoint
MbrTouches
MbrWithin
MbrOverlaps
MbrIntersects
MbrContains
ST_Equals
ST_Disjoint
ST_Touches
ST_Within
ST_Overlaps
ST_Crosses
ST_Intersects
ST_Contains
ST_Relate
ST_Distance
ST_Intersection
ST_Difference
ST_Union
ST_SymDifference
ST_Buffer
ST_ConvexHull
ST_Transform

@@ -0,0 +1,5 @@
<RCC>
<qresource prefix="/sqlfunctions">
<file alias="list.txt">qgsvirtuallayersqlfunctions.txt</file>
</qresource>
</RCC>

0 comments on commit 0eb6cca

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