77
77
#include " qgsmaplayer.h"
78
78
#include " qgsvectorlayer.h"
79
79
#include < qgsrasterlayer.h>
80
+ #include " qgsdatasourceuri.h"
80
81
#include " qgsdataprovider.h"
81
82
#include " qgsfield.h"
82
83
#include " qgsfeature.h"
@@ -2122,7 +2123,7 @@ QgsGrassModuleGdalInput::QgsGrassModuleGdalInput (
2122
2123
QString tit;
2123
2124
if ( mDescription .isEmpty () )
2124
2125
{
2125
- tit = " OGR/GDAL Input" ;
2126
+ tit = " OGR/PostGIS/ GDAL Input" ;
2126
2127
}
2127
2128
else
2128
2129
{
@@ -2189,14 +2190,46 @@ void QgsGrassModuleGdalInput::updateQgisLayers()
2189
2190
if ( mType == Ogr && layer->type () == QgsMapLayer::VECTOR )
2190
2191
{
2191
2192
QgsVectorLayer *vector = (QgsVectorLayer*)layer;
2192
- if ( vector->providerType () != " ogr" ) continue ;
2193
+ if ( vector->providerType () != " ogr"
2194
+ && vector->providerType () != " postgres" ) continue ;
2193
2195
2194
2196
QgsDataProvider *provider = vector->getDataProvider ();
2195
- QString uri = provider->getDataSourceUri ();
2197
+
2198
+ QString uri;
2199
+ QString ogrLayer;
2200
+ if ( vector->providerType () == " postgres" )
2201
+ {
2202
+ // Construct OGR DSN
2203
+ QgsDataSourceURI *dsUri = provider->getURI ();
2204
+ uri = " PG:host=" + dsUri->host
2205
+ + " dbname=" + dsUri->database ;
2206
+
2207
+ if ( dsUri->port .length () > 0 )
2208
+ uri += " port=" + dsUri->port ;
2209
+
2210
+ if ( dsUri->username .length () > 0 )
2211
+ uri += " user=" + dsUri->username ;
2212
+
2213
+ if ( dsUri->password .length () > 0 )
2214
+ uri += " password=" + dsUri->password ;
2215
+
2216
+ ogrLayer = dsUri->schema + " ." + dsUri->table ;
2217
+ }
2218
+ else
2219
+ {
2220
+ uri = provider->getDataSourceUri ();
2221
+ ogrLayer = " " ;
2222
+ }
2223
+
2224
+ std::cerr << " uri = " << uri.ascii () << std::endl;
2225
+ std::cerr << " ogrLayer = " << ogrLayer.ascii () << std::endl;
2196
2226
2197
2227
mLayerComboBox ->insertItem ( layer->name () );
2198
2228
if ( layer->name () == current ) mLayerComboBox ->setCurrentText ( current );
2229
+
2199
2230
mUri .push_back ( uri );
2231
+
2232
+ mOgrLayers .push_back ( ogrLayer );
2200
2233
}
2201
2234
else if ( mType == Gdal && layer->type () == QgsMapLayer::RASTER )
2202
2235
{
@@ -2216,22 +2249,54 @@ QStringList QgsGrassModuleGdalInput::options()
2216
2249
2217
2250
QString opt (mKey + " =" );
2218
2251
2219
- if ( current < mUri .size () ) {
2252
+ if ( current >= 0 && current < mUri .size () ) {
2220
2253
opt.append ( mUri [current] );
2221
2254
}
2222
2255
list.push_back ( opt );
2223
2256
2224
- // TODO
2225
- /*
2226
- if ( !mOgrLayerOption.isNull() )
2257
+ if ( !mOgrLayerOption .isNull () && mOgrLayers [current].length () > 0 )
2227
2258
{
2228
- opt = mOgrLayerOption + "=" ;
2259
+ opt = mOgrLayerOption + " =" ;
2260
+
2261
+ // OGR does not support schemas !!!
2262
+ if ( current >=0 && current < mUri .size () ) {
2263
+ QStringList l = mOgrLayers [current].split (" ." );
2264
+ opt += l.at (1 );
2265
+
2266
+ // Currently only PostGIS is using layer
2267
+ // -> layer -> PostGIS -> warning
2268
+ if ( mOgrLayers [current].length () > 0 )
2269
+ {
2270
+ QMessageBox::warning ( 0 , " Warning" ,
2271
+ " PostGIS driver in OGR does not support schemas!<br>"
2272
+ " Only the table name will be used.<br>"
2273
+ " It can result in wrong input if more tables of the same name<br>"
2274
+ " are present in the database." );
2275
+ }
2276
+ }
2277
+
2229
2278
list.push_back ( opt );
2230
2279
}
2231
- */
2280
+
2232
2281
return list;
2233
2282
}
2234
2283
2284
+ QString QgsGrassModuleGdalInput::ready ()
2285
+ {
2286
+ #ifdef QGISDEBUG
2287
+ std::cerr << " QgsGrassModuleGdalInput::ready()" << std::endl;
2288
+ #endif
2289
+
2290
+ QString error;
2291
+
2292
+ std::cerr << " count = " << mLayerComboBox ->count () << std::endl;
2293
+ if ( mLayerComboBox ->count () == 0 )
2294
+ {
2295
+ error.append ( title () + " : no input" );
2296
+ }
2297
+ return error;
2298
+ }
2299
+
2235
2300
QgsGrassModuleGdalInput::~QgsGrassModuleGdalInput ()
2236
2301
{
2237
2302
}
0 commit comments