Skip to content

Commit 4ed28f3

Browse files
author
jef
committedOct 6, 2009
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@11762 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 3d802f8 commit 4ed28f3

37 files changed

+884
-1078
lines changed
 

‎python/core/qgsdataprovider.sip

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class QgsDataProvider : QObject
6464
* that can be used by the data provider to create a subset.
6565
* Must be implemented in the dataprovider.
6666
*/
67-
virtual void setSubsetString(QString subset);
67+
virtual bool setSubsetString(QString subset);
6868

6969

7070
/**

‎python/core/qgsvectordataprovider.sip

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,11 @@ class QgsVectorDataProvider : QgsDataProvider
141141
* Return unique values of an attribute
142142
* @param index the index of the attribute
143143
* @param values reference to the list to fill
144+
* @param limit maximum number of values to return (added in 1.4)
144145
*
145146
* Default implementation simply iterates the features
146147
*/
147-
virtual void uniqueValues(int index, QList<QVariant> &uniqueValues /Out/);
148+
virtual void uniqueValues(int index, QList<QVariant> &uniqueValues /Out/, int limit = -1);
148149

149150
/**Returns the possible enum values of an attribute. Returns an empty stringlist if a provider does not support enum types
150151
or if the given attribute is not an enum type.

‎python/core/qgsvectorlayer.sip

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,9 @@ public:
154154
* @param subset The subset string. This may be the where clause of a sql statement
155155
* or other defintion string specific to the underlying dataprovider
156156
* and data store.
157+
* @return true, when setting the string was successful, false otherwise (added in 1.4)
157158
*/
158-
virtual void setSubsetString(QString subset);
159+
virtual bool setSubsetString(QString subset);
159160

160161
/**
161162
* Get the string (typically sql) used to define a subset of the layer

‎src/app/CMakeLists.txt

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,14 @@ SET(QGIS_APP_SRCS
6363
qgsprojectproperties.cpp
6464
qgsrasterlayerproperties.cpp
6565
qgssearchquerybuilder.cpp
66-
qgsserversourceselect.cpp
66+
qgswmssourceselect.cpp
6767
qgsshortcutsmanager.cpp
6868
qgssinglesymboldialog.cpp
6969
qgssnappingdialog.cpp
7070
qgsundowidget.cpp
7171
qgsuniquevaluedialog.cpp
7272
qgsvectorlayerproperties.cpp
73+
qgsquerybuilder.cpp
7374

7475
composer/qgscomposer.cpp
7576
composer/qgscomposeritemwidget.cpp
@@ -159,14 +160,15 @@ SET (QGIS_APP_MOC_HDRS
159160
qgsprojectproperties.h
160161
qgsrasterlayerproperties.h
161162
qgssearchquerybuilder.h
162-
qgsserversourceselect.h
163+
qgswmssourceselect.h
163164
qgssinglesymboldialog.h
164165
qgssnappingdialog.h
165166
qgsuniquevaluedialog.h
166167
qgsvectorlayerproperties.h
167168
qgsdbtablemodel.h
168169
qgsspatialitetablemodel.h
169170
qgsundowidget.h
171+
qgsquerybuilder.h
170172

171173
composer/qgscomposer.h
172174
composer/qgscomposeritemwidget.h
@@ -182,7 +184,6 @@ SET (QGIS_APP_MOC_HDRS
182184
legend/qgslegendlayer.h
183185
legend/qgslegendlayerfile.h
184186

185-
186187
ogr/qgsopenvectorlayerdialog.h
187188
ogr/qgsnewogrconnection.h
188189

@@ -198,14 +199,12 @@ IF (POSTGRES_FOUND)
198199
ENDIF(HAVE_PGCONFIG)
199200

200201
SET (QGIS_APP_SRCS ${QGIS_APP_SRCS}
201-
qgsdbsourceselect.cpp
202+
qgspgsourceselect.cpp
202203
qgsnewconnection.cpp
203-
qgspgquerybuilder.cpp
204204
)
205205
SET (QGIS_APP_MOC_HDRS ${QGIS_APP_MOC_HDRS}
206-
qgsdbsourceselect.h
206+
qgspgsourceselect.h
207207
qgsnewconnection.h
208-
qgspgquerybuilder.h
209208
)
210209
ENDIF (POSTGRES_FOUND)
211210

‎src/app/main.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -488,12 +488,8 @@ int main( int argc, char *argv[] )
488488
exit( 1 );
489489
}
490490

491-
492-
// myApp.setFont(QFont("helvetica", 11));
493-
494491
QString i18nPath = QgsApplication::i18nPath();
495492

496-
497493
/* Translation file for QGIS.
498494
*/
499495
QSettings mySettings;
@@ -614,12 +610,9 @@ int main( int argc, char *argv[] )
614610
}
615611
#endif
616612

617-
618-
619613
QgisApp *qgis = new QgisApp( mypSplash ); // "QgisApp" used to find canonical instance
620614
qgis->setObjectName( "QgisApp" );
621615

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

651-
652644
/////////////////////////////////////////////////////////////////////
653645
// autoload any file names that were passed in on the command line
654646
/////////////////////////////////////////////////////////////////////
655647
QgsDebugMsg( QString( "Number of files in myFileList: %1" ).arg( myFileList.count() ) );
656648
for ( QStringList::Iterator myIterator = myFileList.begin(); myIterator != myFileList.end(); ++myIterator )
657649
{
658-
659-
660650
QgsDebugMsg( QString( "Trying to load file : %1" ).arg(( *myIterator ) ) );
661651
QString myLayerName = *myIterator;
662652
// don't load anything with a .qgs extension - these are project files

‎src/app/qgisapp.cpp

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@
131131
#include "qgsrasterlayerproperties.h"
132132
#include "qgsrectangle.h"
133133
#include "qgsrenderer.h"
134-
#include "qgsserversourceselect.h"
134+
#include "qgswmssourceselect.h"
135135
#include "qgsshortcutsmanager.h"
136136
#include "qgsundowidget.h"
137137
#include "qgsvectordataprovider.h"
@@ -183,7 +183,7 @@
183183
// Conditional Includes
184184
//
185185
#ifdef HAVE_POSTGRESQL
186-
#include "qgsdbsourceselect.h"
186+
#include "qgspgsourceselect.h"
187187
#endif
188188
#ifdef HAVE_SPATIALITE
189189
#include "qgsspatialitesourceselect.h"
@@ -2586,7 +2586,7 @@ void QgisApp::addDatabaseLayer()
25862586
// only supports postgis layers at present
25872587
// show the postgis dialog
25882588

2589-
QgsDbSourceSelect *dbs = new QgsDbSourceSelect( this );
2589+
QgsPgSourceSelect *dbs = new QgsPgSourceSelect( this );
25902590

25912591
mMapCanvas->freeze();
25922592

@@ -2742,7 +2742,7 @@ void QgisApp::addWmsLayer()
27422742
// Fudge for now
27432743
QgsDebugMsg( "about to addRasterLayer" );
27442744

2745-
QgsServerSourceSelect *wmss = new QgsServerSourceSelect( this );
2745+
QgsWMSSourceSelect *wmss = new QgsWMSSourceSelect( this );
27462746
wmss->exec();
27472747
}
27482748

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

31493149
void QgisApp::newVectorLayer()
31503150
{
3151-
QgsDebugMsg( "++++++++++++++++++++++++++++++++++++++++++" );
3152-
QgsDebugMsg( "newVectorLayer called" );
3153-
QgsDebugMsg( "++++++++++++++++++++++++++++++++++++++++++" );
3154-
31553151
if ( mMapCanvas && mMapCanvas->isDrawing() )
31563152
{
31573153
return;
@@ -3273,9 +3269,6 @@ void QgisApp::newVectorLayer()
32733269
fileNames.append( fileName );
32743270
//todo: the last parameter will change accordingly to layer type
32753271
addVectorLayers( fileNames, enc, "file" );
3276-
QgsDebugMsg( "++++++++++++++++++++++++++++++++++++++++++" );
3277-
QgsDebugMsg( "newVectorLayer done!" );
3278-
QgsDebugMsg( "++++++++++++++++++++++++++++++++++++++++++" );
32793272
}
32803273

32813274
void QgisApp::fileOpen()

‎src/app/qgsdbtablemodel.cpp

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ QgsDbTableModel::~QgsDbTableModel()
3939
void QgsDbTableModel::addTableEntry( QString type, QString schemaName, QString tableName, QString geometryColName, const QStringList &pkCols, QString sql )
4040
{
4141
//is there already a root item with the given scheme Name?
42-
QStandardItem* schemaItem;
43-
QList<QStandardItem*> schemaItems = findItems( schemaName, Qt::MatchExactly, 0 );
42+
QStandardItem *schemaItem;
43+
QList<QStandardItem*> schemaItems = findItems( schemaName, Qt::MatchExactly, dbtmSchema );
4444

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

78-
7978
childItemList.push_back( schemaNameItem );
8079
childItemList.push_back( tableItem );
8180
childItemList.push_back( typeItem );
@@ -87,17 +86,17 @@ void QgsDbTableModel::addTableEntry( QString type, QString schemaName, QString t
8786
++mTableCount;
8887
}
8988

90-
void QgsDbTableModel::setSql( const QModelIndex& index, const QString &sql )
89+
void QgsDbTableModel::setSql( const QModelIndex &index, const QString &sql )
9190
{
9291
if ( !index.isValid() || !index.parent().isValid() )
9392
{
9493
return;
9594
}
9695

9796
//find out schema name and table name
98-
QModelIndex schemaSibling = index.sibling( index.row(), 0 );
99-
QModelIndex tableSibling = index.sibling( index.row(), 1 );
100-
QModelIndex geomSibling = index.sibling( index.row(), 3 );
97+
QModelIndex schemaSibling = index.sibling( index.row(), dbtmSchema );
98+
QModelIndex tableSibling = index.sibling( index.row(), dbtmTable );
99+
QModelIndex geomSibling = index.sibling( index.row(), dbtmGeomCol );
101100

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

111-
QList<QStandardItem*> schemaItems = findItems( schemaName, Qt::MatchExactly, 0 );
110+
QList<QStandardItem*> schemaItems = findItems( schemaName, Qt::MatchExactly, dbtmSchema );
112111
if ( schemaItems.size() < 1 )
113112
{
114113
return;
115114
}
116115

117-
QStandardItem* schemaItem = schemaItems.at( 0 );
116+
QStandardItem* schemaItem = schemaItems.at( dbtmSchema );
118117
int numChildren = schemaItem->rowCount();
119118

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

124123
for ( int i = 0; i < numChildren; ++i )
125124
{
126-
currentChildIndex = indexFromItem( schemaItem->child( i, 0 ) );
125+
currentChildIndex = indexFromItem( schemaItem->child( i, dbtmSchema ) );
127126
if ( !currentChildIndex.isValid() )
128127
{
129128
continue;
130129
}
131-
currentTableIndex = currentChildIndex.sibling( i, 1 );
130+
currentTableIndex = currentChildIndex.sibling( i, dbtmTable );
132131
if ( !currentTableIndex.isValid() )
133132
{
134133
continue;
135134
}
136135

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

161160
//find schema item and table item
162161
QStandardItem* schemaItem;
163-
QList<QStandardItem*> schemaItems = findItems( schema, Qt::MatchExactly, 0 );
162+
QList<QStandardItem*> schemaItems = findItems( schema, Qt::MatchExactly, dbtmSchema );
164163

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

178177
for ( int i = 0; i < numChildren; ++i )
179178
{
180-
currentChildIndex = indexFromItem( schemaItem->child( i, 0 ) );
179+
currentChildIndex = indexFromItem( schemaItem->child( i, dbtmSchema ) );
181180
if ( !currentChildIndex.isValid() )
182181
{
183182
continue;

‎src/app/qgsdbtablemodel.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class QIcon;
2222
/**A model that holds the tables of a database in a hierarchy where the
2323
schemas are the root elements that contain the individual tables as children.
2424
The tables have the following columns: Type, Schema, Tablename, Geometry Column, Sql*/
25-
class QgsDbTableModel: public QStandardItemModel
25+
class QgsDbTableModel : public QStandardItemModel
2626
{
2727
Q_OBJECT
2828
public:

0 commit comments

Comments
 (0)