@@ -120,14 +120,18 @@ QgsPgSourceSelect::QgsPgSourceSelect( QWidget *parent, Qt::WFlags fl, bool manag
120
120
: QDialog( parent, fl )
121
121
, mManagerMode( managerMode )
122
122
, mEmbeddedMode( embeddedMode )
123
- , mColumnTypeThread( NULL )
123
+ , mColumnTypeThread( 0 )
124
124
{
125
125
setupUi ( this );
126
126
127
127
if ( mEmbeddedMode )
128
128
{
129
129
buttonBox->button ( QDialogButtonBox::Close )->hide ();
130
130
}
131
+ else
132
+ {
133
+ setWindowTitle ( tr ( " Add PostGIS Table(s)" ) );
134
+ }
131
135
132
136
mAddButton = new QPushButton ( tr ( " &Add" ) );
133
137
mAddButton ->setEnabled ( false );
@@ -352,7 +356,7 @@ void QgsPgSourceSelect::on_mSearchModeComboBox_currentIndexChanged( const QStrin
352
356
void QgsPgSourceSelect::setLayerType ( QgsPostgresLayerProperty layerProperty )
353
357
{
354
358
QgsDebugMsg ( " entering." );
355
- mTableModel .setGeometryTypesForTable ( layerProperty );
359
+ mTableModel .addTableEntry ( layerProperty );
356
360
}
357
361
358
362
QgsPgSourceSelect::~QgsPgSourceSelect ()
@@ -437,80 +441,21 @@ void QgsPgSourceSelect::on_btnConnect_clicked()
437
441
mConnInfo = uri.connectionInfo ();
438
442
mUseEstimatedMetadata = uri.useEstimatedMetadata ();
439
443
440
- QgsPostgresConn *conn = QgsPostgresConn::connectDb ( uri.connectionInfo (), true );
441
- if ( conn )
442
- {
443
- QApplication::setOverrideCursor ( Qt::WaitCursor );
444
-
445
- bool searchPublicOnly = QgsPostgresConn::publicSchemaOnly ( cmbConnections->currentText () );
446
- bool searchGeometryColumnsOnly = QgsPostgresConn::geometryColumnsOnly ( cmbConnections->currentText () );
447
- bool dontResolveType = QgsPostgresConn::dontResolveType ( cmbConnections->currentText () );
448
- bool allowGeometrylessTables = cbxAllowGeometrylessTables->isChecked ();
449
-
450
- emit progressMessage ( tr ( " Retrieving tables from %1..." ).arg ( cmbConnections->currentText () ) );
451
-
452
- QVector<QgsPostgresLayerProperty> layers;
453
- if ( conn->supportedLayers ( layers, searchGeometryColumnsOnly, searchPublicOnly, allowGeometrylessTables ) )
454
- {
455
- // Add the supported layers to the table
456
- foreach ( QgsPostgresLayerProperty layer, layers )
457
- {
458
- QString type = layer.type ;
459
- QString srid = layer.srid ;
460
- if ( !layer.geometryColName .isNull () )
461
- {
462
- if ( QgsPostgresConn::wkbTypeFromPostgis ( type ) == QGis::WKBUnknown || srid.isEmpty () )
463
- {
464
- if ( dontResolveType )
465
- {
466
- QgsDebugMsg ( QString ( " skipping column %1.%2 without type constraint" ).arg ( layer.schemaName ).arg ( layer.tableName ) );
467
- continue ;
468
- }
469
-
470
- addSearchGeometryColumn ( layer );
471
- type = " " ;
472
- srid = " " ;
473
- }
474
- }
475
- QgsDebugMsg ( QString ( " adding table %1.%2" ).arg ( layer.schemaName ).arg ( layer.tableName ) );
476
-
477
- layer.type = type;
478
- layer.srid = srid;
479
- mTableModel .addTableEntry ( layer );
480
- }
481
-
482
- if ( mColumnTypeThread )
483
- {
484
- btnConnect->setText ( tr ( " Stop" ) );
485
- mColumnTypeThread ->start ();
486
- }
487
- }
444
+ QApplication::setOverrideCursor ( Qt::BusyCursor );
488
445
489
- // if we have only one schema item, expand it by default
490
- int numTopLevelItems = mTableModel .invisibleRootItem ()->rowCount ();
491
- if ( numTopLevelItems < 2 || mTableModel .tableCount () < 20 )
492
- {
493
- // expand all the toplevel items
494
- for ( int i = 0 ; i < numTopLevelItems; ++i )
495
- {
496
- mTablesTreeView ->expand ( mProxyModel .mapFromSource ( mTableModel .indexFromItem ( mTableModel .invisibleRootItem ()->child ( i ) ) ) );
497
- }
498
- }
446
+ mColumnTypeThread = new QgsGeomColumnTypeThread ( cmbConnections->currentText (), mUseEstimatedMetadata , cbxAllowGeometrylessTables->isChecked () );
499
447
500
- conn->disconnect ();
448
+ connect ( mColumnTypeThread , SIGNAL ( setLayerType ( QgsPostgresLayerProperty ) ),
449
+ this , SLOT ( setLayerType ( QgsPostgresLayerProperty ) ) );
450
+ connect ( mColumnTypeThread , SIGNAL ( finished () ),
451
+ this , SLOT ( columnThreadFinished () ) );
452
+ connect ( mColumnTypeThread , SIGNAL ( progress ( int , int ) ),
453
+ this , SIGNAL ( progress ( int , int ) ) );
454
+ connect ( mColumnTypeThread , SIGNAL ( progressMessage ( QString ) ),
455
+ this , SIGNAL ( progressMessage ( QString ) ) );
501
456
502
- if ( !mColumnTypeThread )
503
- {
504
- finishList ();
505
- }
506
- }
507
- else
508
- {
509
- // Let user know we couldn't initialise the Postgres/PostGIS provider
510
- QMessageBox::warning ( this ,
511
- tr ( " Postgres/PostGIS Provider" ),
512
- tr ( " Could not open the Postgres/PostGIS Provider.\n Check message log for possible errors." ) );
513
- }
457
+ btnConnect->setText ( tr ( " Stop" ) );
458
+ mColumnTypeThread ->start ();
514
459
}
515
460
516
461
void QgsPgSourceSelect::finishList ()
@@ -527,15 +472,6 @@ void QgsPgSourceSelect::finishList()
527
472
528
473
mTablesTreeView ->sortByColumn ( QgsPgTableModel::dbtmTable, Qt::AscendingOrder );
529
474
mTablesTreeView ->sortByColumn ( QgsPgTableModel::dbtmSchema, Qt::AscendingOrder );
530
-
531
- emit progress ( 0 , 0 );
532
- emit progressMessage ( tr ( " Table retrieval finished." ) );
533
-
534
- if ( mTablesTreeView ->model ()->rowCount () == 0 )
535
- QMessageBox::information ( this ,
536
- tr ( " Postgres/PostGIS Provider" ),
537
- tr ( " No accessible tables or views found.\n Check the message log for possible errors." ) );
538
-
539
475
}
540
476
541
477
void QgsPgSourceSelect::columnThreadFinished ()
@@ -568,8 +504,14 @@ void QgsPgSourceSelect::setSql( const QModelIndex &index )
568
504
QModelIndex idx = mProxyModel .mapToSource ( index );
569
505
QString tableName = mTableModel .itemFromIndex ( idx.sibling ( idx.row (), QgsPgTableModel::dbtmTable ) )->text ();
570
506
571
- QgsVectorLayer *vlayer = new QgsVectorLayer ( mTableModel .layerURI ( idx, mConnInfo , mUseEstimatedMetadata ), tableName, " postgres" );
507
+ QString uri = mTableModel .layerURI ( idx, mConnInfo , mUseEstimatedMetadata );
508
+ if ( uri.isNull () )
509
+ {
510
+ QgsDebugMsg ( " no uri" );
511
+ return ;
512
+ }
572
513
514
+ QgsVectorLayer *vlayer = new QgsVectorLayer ( uri, tableName, " postgres" );
573
515
if ( !vlayer->isValid () )
574
516
{
575
517
delete vlayer;
@@ -587,33 +529,6 @@ void QgsPgSourceSelect::setSql( const QModelIndex &index )
587
529
delete vlayer;
588
530
}
589
531
590
- void QgsPgSourceSelect::addSearchGeometryColumn ( QgsPostgresLayerProperty layerProperty )
591
- {
592
- // store the column details and do the query in a thread
593
- if ( !mColumnTypeThread )
594
- {
595
- QgsPostgresConn *conn = QgsPostgresConn::connectDb ( mConnInfo , true /* readonly */ );
596
- if ( conn )
597
- {
598
-
599
- mColumnTypeThread = new QgsGeomColumnTypeThread ( conn, mUseEstimatedMetadata );
600
-
601
- connect ( mColumnTypeThread , SIGNAL ( setLayerType ( QgsPostgresLayerProperty ) ),
602
- this , SLOT ( setLayerType ( QgsPostgresLayerProperty ) ) );
603
- connect ( this , SIGNAL ( addGeometryColumn ( QgsPostgresLayerProperty ) ),
604
- mColumnTypeThread , SLOT ( addGeometryColumn ( QgsPostgresLayerProperty ) ) );
605
- connect ( mColumnTypeThread , SIGNAL ( finished () ),
606
- this , SLOT ( columnThreadFinished () ) );
607
- connect ( mColumnTypeThread , SIGNAL ( progress ( int , int ) ),
608
- this , SIGNAL ( progress ( int , int ) ) );
609
- connect ( mColumnTypeThread , SIGNAL ( progressMessage ( QString ) ),
610
- this , SIGNAL ( progressMessage ( QString ) ) );
611
- }
612
- }
613
-
614
- emit addGeometryColumn ( layerProperty );
615
- }
616
-
617
532
QString QgsPgSourceSelect::fullDescription ( QString schema, QString table, QString column, QString type )
618
533
{
619
534
QString full_desc = " " ;
0 commit comments