Skip to content

Commit 9e04940

Browse files
author
jef
committed
grass plugin update:
- update ogr uri support - fix whereoption support git-svn-id: http://svn.osgeo.org/qgis/trunk@11765 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent d16226b commit 9e04940

File tree

1 file changed

+49
-11
lines changed

1 file changed

+49
-11
lines changed

src/plugins/grass/qgsgrassmodule.cpp

+49-11
Original file line numberDiff line numberDiff line change
@@ -2646,7 +2646,7 @@ QgsGrassModuleGdalInput::QgsGrassModuleGdalInput(
26462646
}
26472647

26482648
// Read "whereoption" if defined
2649-
opt = qdesc.attribute( "where" );
2649+
opt = qdesc.attribute( "whereoption" );
26502650
if ( !opt.isNull() )
26512651
{
26522652
QDomNode optNode = QgsGrassModule::nodeByKey( gdesc, opt );
@@ -2697,6 +2697,7 @@ void QgsGrassModuleGdalInput::updateQgisLayers()
26972697
{
26982698
mUri.push_back( QString() );
26992699
mOgrLayers.push_back( QString() );
2700+
mOgrWheres.push_back( QString() );
27002701
mLayerComboBox->addItem( tr( "Select a layer" ), QVariant() );
27012702
}
27022703

@@ -2709,9 +2710,11 @@ void QgsGrassModuleGdalInput::updateQgisLayers()
27092710

27102711
if ( mType == Ogr && layer->type() == QgsMapLayer::VectorLayer )
27112712
{
2712-
QgsVectorLayer *vector = ( QgsVectorLayer* )layer;
2713-
if ( vector->providerType() != "ogr"
2714-
&& vector->providerType() != "postgres" ) continue;
2713+
QgsVectorLayer *vector = dynamic_cast<QgsVectorLayer*>( layer );
2714+
if ( !vector ||
2715+
( vector->providerType() != "ogr" && vector->providerType() != "postgres" )
2716+
)
2717+
continue;
27152718

27162719
QgsDataProvider *provider = vector->dataProvider();
27172720

@@ -2732,10 +2735,45 @@ void QgsGrassModuleGdalInput::updateQgisLayers()
27322735
ogrLayer += dsUri.table();
27332736
ogrWhere = dsUri.sql();
27342737
}
2735-
else
2738+
else if ( vector->providerType() == "ogr" )
27362739
{
2737-
uri = provider->dataSourceUri();
2738-
ogrLayer = "";
2740+
QStringList items = provider->dataSourceUri().split( "|" );
2741+
2742+
if ( items.size() > 1 )
2743+
{
2744+
uri = items[0];
2745+
2746+
ogrLayer = "";
2747+
ogrWhere = "";
2748+
2749+
for ( int i = 1; i < items.size(); i++ )
2750+
{
2751+
QStringList args = items[i].split( "=" );
2752+
2753+
if ( args.size() != 2 )
2754+
continue;
2755+
2756+
if ( args[0] == "layername" && args[0] == "layerid" )
2757+
{
2758+
ogrLayer = args[1];
2759+
}
2760+
else if ( args[0] == "subset" )
2761+
{
2762+
ogrWhere = args[1];
2763+
}
2764+
}
2765+
2766+
if ( uri.endsWith( ".shp", Qt::CaseInsensitive ) )
2767+
{
2768+
ogrLayer = "";
2769+
}
2770+
}
2771+
else
2772+
{
2773+
uri = items[0];
2774+
ogrLayer = "";
2775+
ogrWhere = "";
2776+
}
27392777
}
27402778

27412779
QgsDebugMsg( "uri = " + uri );
@@ -2804,11 +2842,11 @@ QStringList QgsGrassModuleGdalInput::options()
28042842
}
28052843
#endif //GDAL_VERSION_NUM
28062844
list.push_back( opt );
2845+
}
28072846

2808-
if ( !mOgrWhereOption.isNull() && mOgrWheres[current].length() > 0 )
2809-
{
2810-
list.push_back( mOgrWhereOption + "=" + mOgrWheres[current] );
2811-
}
2847+
if ( !mOgrWhereOption.isNull() && mOgrWheres[current].length() > 0 )
2848+
{
2849+
list.push_back( mOgrWhereOption + "=" + mOgrWheres[current] );
28122850
}
28132851

28142852
return list;

0 commit comments

Comments
 (0)