Skip to content

Commit

Permalink
wider support for vector layer queries:
Browse files Browse the repository at this point in the history
- add query support for OGR and spatialite layers (additional to postgres)
- QgsDataProvider::setSubsetString() now returns if the query is successful.
- add optional parameter to limit number of values returned from QgsVectorDataProvider::uniqueValues() 
- rename QgsDbSourceSelect to QgsPgSourceSelect, use QgsVectorLayer for layer queries and make it wider
- QgsDataSourceURI: improve quoting
- fix relative path support for SpatiaLite on windows
- rename QgsPgQueryBuilder to QgsQueryBuilder and use QgsVectorLayer for
  queries instead of postgres

cleanups:
- rename QgsServerSourceSelect to QgsWMSSourceSelect



git-svn-id: http://svn.osgeo.org/qgis/trunk@11762 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Oct 6, 2009
1 parent 3d802f8 commit 4ed28f3
Show file tree
Hide file tree
Showing 37 changed files with 884 additions and 1,078 deletions.
2 changes: 1 addition & 1 deletion python/core/qgsdataprovider.sip
Expand Up @@ -64,7 +64,7 @@ class QgsDataProvider : QObject
* that can be used by the data provider to create a subset.
* Must be implemented in the dataprovider.
*/
virtual void setSubsetString(QString subset);
virtual bool setSubsetString(QString subset);


/**
Expand Down
3 changes: 2 additions & 1 deletion python/core/qgsvectordataprovider.sip
Expand Up @@ -141,10 +141,11 @@ class QgsVectorDataProvider : QgsDataProvider
* Return unique values of an attribute
* @param index the index of the attribute
* @param values reference to the list to fill
* @param limit maximum number of values to return (added in 1.4)
*
* Default implementation simply iterates the features
*/
virtual void uniqueValues(int index, QList<QVariant> &uniqueValues /Out/);
virtual void uniqueValues(int index, QList<QVariant> &uniqueValues /Out/, int limit = -1);

/**Returns the possible enum values of an attribute. Returns an empty stringlist if a provider does not support enum types
or if the given attribute is not an enum type.
Expand Down
3 changes: 2 additions & 1 deletion python/core/qgsvectorlayer.sip
Expand Up @@ -154,8 +154,9 @@ public:
* @param subset The subset string. This may be the where clause of a sql statement
* or other defintion string specific to the underlying dataprovider
* and data store.
* @return true, when setting the string was successful, false otherwise (added in 1.4)
*/
virtual void setSubsetString(QString subset);
virtual bool setSubsetString(QString subset);

/**
* Get the string (typically sql) used to define a subset of the layer
Expand Down
13 changes: 6 additions & 7 deletions src/app/CMakeLists.txt
Expand Up @@ -63,13 +63,14 @@ SET(QGIS_APP_SRCS
qgsprojectproperties.cpp
qgsrasterlayerproperties.cpp
qgssearchquerybuilder.cpp
qgsserversourceselect.cpp
qgswmssourceselect.cpp
qgsshortcutsmanager.cpp
qgssinglesymboldialog.cpp
qgssnappingdialog.cpp
qgsundowidget.cpp
qgsuniquevaluedialog.cpp
qgsvectorlayerproperties.cpp
qgsquerybuilder.cpp

composer/qgscomposer.cpp
composer/qgscomposeritemwidget.cpp
Expand Down Expand Up @@ -159,14 +160,15 @@ SET (QGIS_APP_MOC_HDRS
qgsprojectproperties.h
qgsrasterlayerproperties.h
qgssearchquerybuilder.h
qgsserversourceselect.h
qgswmssourceselect.h
qgssinglesymboldialog.h
qgssnappingdialog.h
qgsuniquevaluedialog.h
qgsvectorlayerproperties.h
qgsdbtablemodel.h
qgsspatialitetablemodel.h
qgsundowidget.h
qgsquerybuilder.h

composer/qgscomposer.h
composer/qgscomposeritemwidget.h
Expand All @@ -182,7 +184,6 @@ SET (QGIS_APP_MOC_HDRS
legend/qgslegendlayer.h
legend/qgslegendlayerfile.h


ogr/qgsopenvectorlayerdialog.h
ogr/qgsnewogrconnection.h

Expand All @@ -198,14 +199,12 @@ IF (POSTGRES_FOUND)
ENDIF(HAVE_PGCONFIG)

SET (QGIS_APP_SRCS ${QGIS_APP_SRCS}
qgsdbsourceselect.cpp
qgspgsourceselect.cpp
qgsnewconnection.cpp
qgspgquerybuilder.cpp
)
SET (QGIS_APP_MOC_HDRS ${QGIS_APP_MOC_HDRS}
qgsdbsourceselect.h
qgspgsourceselect.h
qgsnewconnection.h
qgspgquerybuilder.h
)
ENDIF (POSTGRES_FOUND)

Expand Down
10 changes: 0 additions & 10 deletions src/app/main.cpp
Expand Up @@ -488,12 +488,8 @@ int main( int argc, char *argv[] )
exit( 1 );
}


// myApp.setFont(QFont("helvetica", 11));

QString i18nPath = QgsApplication::i18nPath();


/* Translation file for QGIS.
*/
QSettings mySettings;
Expand Down Expand Up @@ -614,12 +610,9 @@ int main( int argc, char *argv[] )
}
#endif



QgisApp *qgis = new QgisApp( mypSplash ); // "QgisApp" used to find canonical instance
qgis->setObjectName( "QgisApp" );


/////////////////////////////////////////////////////////////////////
// If no --project was specified, parse the args to look for a //
// .qgs file and set myProjectFileName to it. This allows loading //
Expand Down Expand Up @@ -648,15 +641,12 @@ int main( int argc, char *argv[] )
qgis->openProject( myProjectFileName );
}


/////////////////////////////////////////////////////////////////////
// autoload any file names that were passed in on the command line
/////////////////////////////////////////////////////////////////////
QgsDebugMsg( QString( "Number of files in myFileList: %1" ).arg( myFileList.count() ) );
for ( QStringList::Iterator myIterator = myFileList.begin(); myIterator != myFileList.end(); ++myIterator )
{


QgsDebugMsg( QString( "Trying to load file : %1" ).arg(( *myIterator ) ) );
QString myLayerName = *myIterator;
// don't load anything with a .qgs extension - these are project files
Expand Down
15 changes: 4 additions & 11 deletions src/app/qgisapp.cpp
Expand Up @@ -131,7 +131,7 @@
#include "qgsrasterlayerproperties.h"
#include "qgsrectangle.h"
#include "qgsrenderer.h"
#include "qgsserversourceselect.h"
#include "qgswmssourceselect.h"
#include "qgsshortcutsmanager.h"
#include "qgsundowidget.h"
#include "qgsvectordataprovider.h"
Expand Down Expand Up @@ -183,7 +183,7 @@
// Conditional Includes
//
#ifdef HAVE_POSTGRESQL
#include "qgsdbsourceselect.h"
#include "qgspgsourceselect.h"
#endif
#ifdef HAVE_SPATIALITE
#include "qgsspatialitesourceselect.h"
Expand Down Expand Up @@ -2586,7 +2586,7 @@ void QgisApp::addDatabaseLayer()
// only supports postgis layers at present
// show the postgis dialog

QgsDbSourceSelect *dbs = new QgsDbSourceSelect( this );
QgsPgSourceSelect *dbs = new QgsPgSourceSelect( this );

mMapCanvas->freeze();

Expand Down Expand Up @@ -2742,7 +2742,7 @@ void QgisApp::addWmsLayer()
// Fudge for now
QgsDebugMsg( "about to addRasterLayer" );

QgsServerSourceSelect *wmss = new QgsServerSourceSelect( this );
QgsWMSSourceSelect *wmss = new QgsWMSSourceSelect( this );
wmss->exec();
}

Expand Down Expand Up @@ -3148,10 +3148,6 @@ void QgisApp::fileNew( bool thePromptToSaveFlag )

void QgisApp::newVectorLayer()
{
QgsDebugMsg( "++++++++++++++++++++++++++++++++++++++++++" );
QgsDebugMsg( "newVectorLayer called" );
QgsDebugMsg( "++++++++++++++++++++++++++++++++++++++++++" );

if ( mMapCanvas && mMapCanvas->isDrawing() )
{
return;
Expand Down Expand Up @@ -3273,9 +3269,6 @@ void QgisApp::newVectorLayer()
fileNames.append( fileName );
//todo: the last parameter will change accordingly to layer type
addVectorLayers( fileNames, enc, "file" );
QgsDebugMsg( "++++++++++++++++++++++++++++++++++++++++++" );
QgsDebugMsg( "newVectorLayer done!" );
QgsDebugMsg( "++++++++++++++++++++++++++++++++++++++++++" );
}

void QgisApp::fileOpen()
Expand Down
29 changes: 14 additions & 15 deletions src/app/qgsdbtablemodel.cpp
Expand Up @@ -39,13 +39,13 @@ QgsDbTableModel::~QgsDbTableModel()
void QgsDbTableModel::addTableEntry( QString type, QString schemaName, QString tableName, QString geometryColName, const QStringList &pkCols, QString sql )
{
//is there already a root item with the given scheme Name?
QStandardItem* schemaItem;
QList<QStandardItem*> schemaItems = findItems( schemaName, Qt::MatchExactly, 0 );
QStandardItem *schemaItem;
QList<QStandardItem*> schemaItems = findItems( schemaName, Qt::MatchExactly, dbtmSchema );

//there is already an item for this schema
if ( schemaItems.size() > 0 )
{
schemaItem = schemaItems.at( 0 );
schemaItem = schemaItems.at( dbtmSchema );
}
else //create a new toplevel item for this schema
{
Expand Down Expand Up @@ -75,7 +75,6 @@ void QgsDbTableModel::addTableEntry( QString type, QString schemaName, QString t
QStandardItem* sqlItem = new QStandardItem( sql );
sqlItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable );


childItemList.push_back( schemaNameItem );
childItemList.push_back( tableItem );
childItemList.push_back( typeItem );
Expand All @@ -87,17 +86,17 @@ void QgsDbTableModel::addTableEntry( QString type, QString schemaName, QString t
++mTableCount;
}

void QgsDbTableModel::setSql( const QModelIndex& index, const QString &sql )
void QgsDbTableModel::setSql( const QModelIndex &index, const QString &sql )
{
if ( !index.isValid() || !index.parent().isValid() )
{
return;
}

//find out schema name and table name
QModelIndex schemaSibling = index.sibling( index.row(), 0 );
QModelIndex tableSibling = index.sibling( index.row(), 1 );
QModelIndex geomSibling = index.sibling( index.row(), 3 );
QModelIndex schemaSibling = index.sibling( index.row(), dbtmSchema );
QModelIndex tableSibling = index.sibling( index.row(), dbtmTable );
QModelIndex geomSibling = index.sibling( index.row(), dbtmGeomCol );

if ( !schemaSibling.isValid() || !tableSibling.isValid() || !geomSibling.isValid() )
{
Expand All @@ -108,13 +107,13 @@ void QgsDbTableModel::setSql( const QModelIndex& index, const QString &sql )
QString tableName = itemFromIndex( tableSibling )->text();
QString geomName = itemFromIndex( geomSibling )->text();

QList<QStandardItem*> schemaItems = findItems( schemaName, Qt::MatchExactly, 0 );
QList<QStandardItem*> schemaItems = findItems( schemaName, Qt::MatchExactly, dbtmSchema );
if ( schemaItems.size() < 1 )
{
return;
}

QStandardItem* schemaItem = schemaItems.at( 0 );
QStandardItem* schemaItem = schemaItems.at( dbtmSchema );
int numChildren = schemaItem->rowCount();

QModelIndex currentChildIndex;
Expand All @@ -123,18 +122,18 @@ void QgsDbTableModel::setSql( const QModelIndex& index, const QString &sql )

for ( int i = 0; i < numChildren; ++i )
{
currentChildIndex = indexFromItem( schemaItem->child( i, 0 ) );
currentChildIndex = indexFromItem( schemaItem->child( i, dbtmSchema ) );
if ( !currentChildIndex.isValid() )
{
continue;
}
currentTableIndex = currentChildIndex.sibling( i, 1 );
currentTableIndex = currentChildIndex.sibling( i, dbtmTable );
if ( !currentTableIndex.isValid() )
{
continue;
}

currentGeomIndex = currentChildIndex.sibling( i, 3 );
currentGeomIndex = currentChildIndex.sibling( i, dbtmGeomCol );
if ( !currentGeomIndex.isValid() )
{
continue;
Expand All @@ -160,7 +159,7 @@ void QgsDbTableModel::setGeometryTypesForTable( const QString& schema, const QSt

//find schema item and table item
QStandardItem* schemaItem;
QList<QStandardItem*> schemaItems = findItems( schema, Qt::MatchExactly, 0 );
QList<QStandardItem*> schemaItems = findItems( schema, Qt::MatchExactly, dbtmSchema );

if ( schemaItems.size() < 1 )
{
Expand All @@ -177,7 +176,7 @@ void QgsDbTableModel::setGeometryTypesForTable( const QString& schema, const QSt

for ( int i = 0; i < numChildren; ++i )
{
currentChildIndex = indexFromItem( schemaItem->child( i, 0 ) );
currentChildIndex = indexFromItem( schemaItem->child( i, dbtmSchema ) );
if ( !currentChildIndex.isValid() )
{
continue;
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsdbtablemodel.h
Expand Up @@ -22,7 +22,7 @@ class QIcon;
/**A model that holds the tables of a database in a hierarchy where the
schemas are the root elements that contain the individual tables as children.
The tables have the following columns: Type, Schema, Tablename, Geometry Column, Sql*/
class QgsDbTableModel: public QStandardItemModel
class QgsDbTableModel : public QStandardItemModel
{
Q_OBJECT
public:
Expand Down

0 comments on commit 4ed28f3

Please sign in to comment.