@@ -412,74 +412,30 @@ void QgsPgSourceSelect::populateConnectionList()
412
412
cmbConnections->setDisabled ( cmbConnections->count () == 0 );
413
413
}
414
414
415
- QString QgsPgSourceSelect::layerURI ( const QModelIndex &index )
416
- {
417
- QGis::GeometryType geomType = ( QGis::GeometryType ) mTableModel .itemFromIndex ( index.sibling ( index.row (), QgsPgTableModel::dbtmType ) )->data ( Qt::UserRole + 2 ).toInt ();
418
- if ( geomType == QGis::UnknownGeometry )
419
- // no geometry type selected
420
- return QString::null;
421
-
422
- QStandardItem *pkItem = mTableModel .itemFromIndex ( index.sibling ( index.row (), QgsPgTableModel::dbtmPkCol ) );
423
- QString pkColumnName = pkItem->data ( Qt::UserRole + 2 ).toString ();
424
-
425
- if ( pkItem->data ( Qt::UserRole + 1 ).toStringList ().size () > 0 && pkColumnName.isEmpty () )
426
- // no primary key for view selected
427
- return QString::null;
428
-
429
- QString schemaName = index.sibling ( index.row (), QgsPgTableModel::dbtmSchema ).data ( Qt::DisplayRole ).toString ();
430
- QString tableName = index.sibling ( index.row (), QgsPgTableModel::dbtmTable ).data ( Qt::DisplayRole ).toString ();
431
- QString geomColumnName = index.sibling ( index.row (), QgsPgTableModel::dbtmGeomCol ).data ( Qt::DisplayRole ).toString ();
432
-
433
- QString srid = index.sibling ( index.row (), QgsPgTableModel::dbtmSrid ).data ( Qt::DisplayRole ).toString ();
434
- bool ok;
435
- srid.toInt ( &ok );
436
- if ( !ok )
437
- return QString::null;
438
-
439
- bool selectAtId = mTableModel .itemFromIndex ( index.sibling ( index.row (), QgsPgTableModel::dbtmSelectAtId ) )->checkState () == Qt::Checked;
440
- QString sql = index.sibling ( index.row (), QgsPgTableModel::dbtmSql ).data ( Qt::DisplayRole ).toString ();
441
-
442
- QgsDataSourceURI uri ( m_connInfo );
443
- uri.setDataSource ( schemaName, tableName, geomType != QGis::NoGeometry ? geomColumnName : QString::null, sql, pkColumnName );
444
- uri.setUseEstimatedMetadata ( mUseEstimatedMetadata );
445
- uri.setGeometryType ( geomType );
446
- uri.setSrid ( srid );
447
- uri.disableSelectAtId ( !selectAtId );
448
-
449
- return uri.uri ();
450
- }
451
-
452
415
// Slot for performing action when the Add button is clicked
453
416
void QgsPgSourceSelect::addTables ()
454
417
{
455
- m_selectedTables .clear ();
418
+ mSelectedTables .clear ();
456
419
457
- QItemSelection selection = mTablesTreeView ->selectionModel ()->selection ();
458
- QModelIndexList selectedIndices = selection.indexes ();
459
- QModelIndexList::const_iterator selected_it = selectedIndices.constBegin ();
460
- for ( ; selected_it != selectedIndices.constEnd (); ++selected_it )
420
+ foreach ( QModelIndex idx, mTablesTreeView ->selectionModel ()->selection ().indexes () )
461
421
{
462
- if ( !selected_it->parent ().isValid () || selected_it->column () > 0 )
463
- {
464
- // top level items only contain the schema names
422
+ if ( idx.column () != QgsPgTableModel::dbtmTable )
465
423
continue ;
466
- }
467
424
468
- QModelIndex index = mProxyModel .mapToSource ( *selected_it );
469
- QString uri = layerURI ( index );
425
+ QString uri = mTableModel .layerURI ( mProxyModel .mapToSource ( idx ), mConnInfo , mUseEstimatedMetadata );
470
426
if ( uri.isNull () )
471
427
continue ;
472
428
473
- m_selectedTables << uri;
429
+ mSelectedTables << uri;
474
430
}
475
431
476
- if ( m_selectedTables .empty () )
432
+ if ( mSelectedTables .empty () )
477
433
{
478
434
QMessageBox::information ( this , tr ( " Select Table" ), tr ( " You must select a table in order to add a layer." ) );
479
435
}
480
436
else
481
437
{
482
- emit addDatabaseLayers ( m_selectedTables , " postgres" );
438
+ emit addDatabaseLayers ( mSelectedTables , " postgres" );
483
439
accept ();
484
440
}
485
441
}
@@ -502,7 +458,7 @@ void QgsPgSourceSelect::on_btnConnect_clicked()
502
458
503
459
QgsDebugMsg ( " Connection info: " + uri.connectionInfo () );
504
460
505
- m_connInfo = uri.connectionInfo ();
461
+ mConnInfo = uri.connectionInfo ();
506
462
mUseEstimatedMetadata = uri.useEstimatedMetadata ();
507
463
508
464
QgsPostgresConn *conn = QgsPostgresConn::connectDb ( uri.connectionInfo (), true );
@@ -596,12 +552,12 @@ void QgsPgSourceSelect::columnThreadFinished()
596
552
597
553
QStringList QgsPgSourceSelect::selectedTables ()
598
554
{
599
- return m_selectedTables ;
555
+ return mSelectedTables ;
600
556
}
601
557
602
558
QString QgsPgSourceSelect::connectionInfo ()
603
559
{
604
- return m_connInfo ;
560
+ return mConnInfo ;
605
561
}
606
562
607
563
void QgsPgSourceSelect::setSql ( const QModelIndex &index )
@@ -615,7 +571,7 @@ void QgsPgSourceSelect::setSql( const QModelIndex &index )
615
571
QModelIndex idx = mProxyModel .mapToSource ( index );
616
572
QString tableName = mTableModel .itemFromIndex ( idx.sibling ( idx.row (), QgsPgTableModel::dbtmTable ) )->text ();
617
573
618
- QgsVectorLayer *vlayer = new QgsVectorLayer ( layerURI ( idx ), tableName, " postgres" );
574
+ QgsVectorLayer *vlayer = new QgsVectorLayer ( mTableModel . layerURI ( idx, mConnInfo , mUseEstimatedMetadata ), tableName, " postgres" );
619
575
620
576
if ( !vlayer->isValid () )
621
577
{
@@ -639,7 +595,7 @@ void QgsPgSourceSelect::addSearchGeometryColumn( QgsPostgresLayerProperty layerP
639
595
// store the column details and do the query in a thread
640
596
if ( !mColumnTypeThread )
641
597
{
642
- QgsPostgresConn *conn = QgsPostgresConn::connectDb ( m_connInfo , true /* readonly */ );
598
+ QgsPostgresConn *conn = QgsPostgresConn::connectDb ( mConnInfo , true /* readonly */ );
643
599
if ( conn )
644
600
{
645
601
0 commit comments