Skip to content
Permalink
Browse files
wider support for vector layer queries:
- 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/qgis@11762 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Oct 6, 2009
1 parent 250fafb commit 6ef2f342a8db2b5af4907460245d6a0fcf5cf5ce
Showing with 884 additions and 1,078 deletions.
  1. +1 −1 python/core/qgsdataprovider.sip
  2. +2 −1 python/core/qgsvectordataprovider.sip
  3. +2 −1 python/core/qgsvectorlayer.sip
  4. +6 −7 src/app/CMakeLists.txt
  5. +0 −10 src/app/main.cpp
  6. +4 −11 src/app/qgisapp.cpp
  7. +14 −15 src/app/qgsdbtablemodel.cpp
  8. +1 −1 src/app/qgsdbtablemodel.h
  9. +0 −476 src/app/qgspgquerybuilder.cpp
  10. +97 −151 src/app/{qgsdbsourceselect.cpp → qgspgsourceselect.cpp}
  11. +25 −21 src/app/{qgsdbsourceselect.h → qgspgsourceselect.h}
  12. +301 −0 src/app/qgsquerybuilder.cpp
  13. +23 −41 src/app/{qgspgquerybuilder.h → qgsquerybuilder.h}
  14. +2 −2 src/app/qgssearchquerybuilder.h
  15. +9 −28 src/app/qgsspatialitesourceselect.cpp
  16. +1 −1 src/app/qgsspatialitesourceselect.h
  17. +28 −50 src/app/qgsvectorlayerproperties.cpp
  18. +40 −40 src/app/{qgsserversourceselect.cpp → qgswmssourceselect.cpp}
  19. +7 −7 src/app/{qgsserversourceselect.h → qgswmssourceselect.h}
  20. +3 −6 src/core/qgsdataprovider.h
  21. +32 −12 src/core/qgsdatasourceuri.cpp
  22. +1 −0 src/core/qgsdatasourceuri.h
  23. +4 −1 src/core/qgsvectordataprovider.cpp
  24. +3 −3 src/core/qgsvectordataprovider.h
  25. +6 −3 src/core/qgsvectorlayer.cpp
  26. +2 −1 src/core/qgsvectorlayer.h
  27. +0 −4 src/gui/qgsmapcanvas.cpp
  28. +6 −10 src/plugins/CMakeLists.txt
  29. +152 −61 src/providers/ogr/qgsogrprovider.cpp
  30. +20 −1 src/providers/ogr/qgsogrprovider.h
  31. +15 −8 src/providers/postgres/qgspostgresprovider.cpp
  32. +2 −2 src/providers/postgres/qgspostgresprovider.h
  33. +60 −88 src/providers/spatialite/qgsspatialiteprovider.cpp
  34. +4 −3 src/providers/spatialite/qgsspatialiteprovider.h
  35. +4 −4 src/ui/{qgsdbsourceselectbase.ui → qgspgsourceselectbase.ui}
  36. +5 −5 src/ui/{qgspgquerybuilderbase.ui → qgsquerybuilderbase.ui}
  37. +2 −2 src/ui/{qgsserversourceselectbase.ui → qgswmssourceselectbase.ui}
@@ -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);


/**
@@ -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.
@@ -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
@@ -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
@@ -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
@@ -182,7 +184,6 @@ SET (QGIS_APP_MOC_HDRS
legend/qgslegendlayer.h
legend/qgslegendlayerfile.h


ogr/qgsopenvectorlayerdialog.h
ogr/qgsnewogrconnection.h

@@ -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)

@@ -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;
@@ -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 //
@@ -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
@@ -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"
@@ -183,7 +183,7 @@
// Conditional Includes
//
#ifdef HAVE_POSTGRESQL
#include "qgsdbsourceselect.h"
#include "qgspgsourceselect.h"
#endif
#ifdef HAVE_SPATIALITE
#include "qgsspatialitesourceselect.h"
@@ -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();

@@ -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();
}

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

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

if ( mMapCanvas && mMapCanvas->isDrawing() )
{
return;
@@ -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()
@@ -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
{
@@ -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 );
@@ -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() )
{
@@ -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;
@@ -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;
@@ -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 )
{
@@ -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;
@@ -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:
Loading

0 comments on commit 6ef2f34

Please sign in to comment.