[QGIS Commit] r11767 - in trunk/qgis: i18n src/app src/providers/postgres

svn_qgis at osgeo.org svn_qgis at osgeo.org
Thu Oct 8 07:53:10 EDT 2009


Author: jef
Date: 2009-10-08 07:53:09 -0400 (Thu, 08 Oct 2009)
New Revision: 11767

Modified:
   trunk/qgis/i18n/qgis_de.ts
   trunk/qgis/src/app/qgsdbtablemodel.cpp
   trunk/qgis/src/app/qgspgsourceselect.cpp
   trunk/qgis/src/app/qgspgsourceselect.h
   trunk/qgis/src/app/qgsquerybuilder.cpp
   trunk/qgis/src/providers/postgres/qgspostgresprovider.cpp
Log:
postgres fixes:
- allow editing of where clause in database selection dialog
- don't open query builder with invalid layer
- reallow oid type as primary key type
- preset where clause with current one in query builder
- actually show error message when QgsPostgresProvider::getGeometryDetails() fails



Modified: trunk/qgis/i18n/qgis_de.ts
===================================================================
--- trunk/qgis/i18n/qgis_de.ts	2009-10-07 17:47:34 UTC (rev 11766)
+++ trunk/qgis/i18n/qgis_de.ts	2009-10-08 11:53:09 UTC (rev 11767)
@@ -17347,7 +17347,7 @@
     <message>
         <location filename="../src/providers/postgres/qgspostgresprovider.cpp" line="2899"/>
         <source>Unable to get feature type and srid</source>
-        <translation>Kann den Fearture-Typ und die SRID nicht ermitteln</translation>
+        <translation>Kann den Objekttyp und die SRID nicht ermitteln</translation>
     </message>
     <message>
         <location filename="../src/providers/postgres/qgspostgresprovider.cpp" line="2188"/>

Modified: trunk/qgis/src/app/qgsdbtablemodel.cpp
===================================================================
--- trunk/qgis/src/app/qgsdbtablemodel.cpp	2009-10-07 17:47:34 UTC (rev 11766)
+++ trunk/qgis/src/app/qgsdbtablemodel.cpp	2009-10-08 11:53:09 UTC (rev 11767)
@@ -73,7 +73,7 @@
   pkItem->setData( pkCols );
   pkItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable );
   QStandardItem* sqlItem = new QStandardItem( sql );
-  sqlItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
+  sqlItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable );
 
   childItemList.push_back( schemaNameItem );
   childItemList.push_back( tableItem );

Modified: trunk/qgis/src/app/qgspgsourceselect.cpp
===================================================================
--- trunk/qgis/src/app/qgspgsourceselect.cpp	2009-10-07 17:47:34 UTC (rev 11766)
+++ trunk/qgis/src/app/qgspgsourceselect.cpp	2009-10-08 11:53:09 UTC (rev 11767)
@@ -67,7 +67,7 @@
 
   mTablesTreeView->setEditTriggers( QAbstractItemView::CurrentChanged );
 
-  mTablesTreeView->setItemDelegateForColumn( QgsDbTableModel::dbtmPkCol, new QgsPgSourceSelectDelegate( this ) );
+  mTablesTreeView->setItemDelegate( new QgsPgSourceSelectDelegate( this ) );
 
   QSettings settings;
   mTablesTreeView->setSelectionMode( settings.value( "/qgis/addPostgisDC", false ).toBool() ?
@@ -325,9 +325,9 @@
   }
 
   uri += QString( " table=\"%1\".\"%2\" (%3) sql=%4" )
-               .arg( schemaName ).arg( tableName )
-               .arg( geomColumnName )
-               .arg( sql );
+         .arg( schemaName ).arg( tableName )
+         .arg( geomColumnName )
+         .arg( sql );
 
   return uri;
 }
@@ -341,7 +341,7 @@
   QModelIndexList::const_iterator selected_it = selectedIndices.constBegin();
   for ( ; selected_it != selectedIndices.constEnd(); ++selected_it )
   {
-    if ( !selected_it->parent().isValid() || selected_it->column()>0 )
+    if ( !selected_it->parent().isValid() || selected_it->column() > 0 )
     {
       //top level items only contain the schema names
       continue;
@@ -501,18 +501,23 @@
 
 void QgsPgSourceSelect::setSql( const QModelIndex &index )
 {
-  QgsDebugMsg( QString("%1,%2").arg( index.row() ).arg( index.column() ) );
   if ( !index.parent().isValid() )
   {
     QgsDebugMsg( "schema item found" );
     return;
   }
- 
+
   QgsVectorLayer *vlayer = new QgsVectorLayer( layerURI( mProxyModel.mapToSource( index ) ), "querybuilder", "postgres" );
 
+  if ( !vlayer->isValid() )
+  {
+    delete vlayer;
+    return;
+  }
+
   // create a query builder object
   QgsQueryBuilder *gb = new QgsQueryBuilder( vlayer, this );
-  if( gb->exec() )
+  if ( gb->exec() )
   {
     mTableModel.setSql( mProxyModel.mapToSource( index ), gb->sql() );
   }
@@ -537,7 +542,7 @@
   QStringList cols;
   cols << QString::null;
 
-  QString sql = QString( "select attname from pg_attribute join pg_type on atttypid=pg_type.oid WHERE pg_type.typname='int4' AND attrelid=regclass('\"%1\".\"%2\"')" ).arg( schemaName ).arg( viewName );
+  QString sql = QString( "select attname from pg_attribute join pg_type on atttypid=pg_type.oid WHERE pg_type.typname IN ('int4','oid') AND attrelid=regclass('\"%1\".\"%2\"')" ).arg( schemaName ).arg( viewName );
   QgsDebugMsg( sql );
   PGresult *colRes = PQexec( pg, sql.toUtf8() );
 
@@ -614,7 +619,7 @@
           as = type = "WAITING";
         }
 
-        mTableModel.addTableEntry( type, schemaName, tableName, column, relkind=="v" ? pkCandidates( pg, schemaName, tableName ) : QStringList(), "" );
+        mTableModel.addTableEntry( type, schemaName, tableName, column, relkind == "v" ? pkCandidates( pg, schemaName, tableName ) : QStringList(), "" );
         n++;
       }
     }
@@ -694,7 +699,7 @@
 
         addSearchGeometryColumn( schema, table, column );
         //details.push_back(geomPair(fullDescription(schema, table, column, "WAITING"), "WAITING"));
-        mTableModel.addTableEntry( "Waiting", schema, table, column, relkind=="v" ? pkCandidates( pg, schema, table ) : QStringList(), "" );
+        mTableModel.addTableEntry( "Waiting", schema, table, column, relkind == "v" ? pkCandidates( pg, schema, table ) : QStringList(), "" );
         n++;
       }
     }

Modified: trunk/qgis/src/app/qgspgsourceselect.h
===================================================================
--- trunk/qgis/src/app/qgspgsourceselect.h	2009-10-07 17:47:34 UTC (rev 11766)
+++ trunk/qgis/src/app/qgspgsourceselect.h	2009-10-08 11:53:09 UTC (rev 11767)
@@ -1,5 +1,5 @@
 /***************************************************************************
-                          qgdbsourceselect.h  -  description
+                          qgpgsourceselect.h  -  description
                              -------------------
     begin                : Sat Jun 22 2002
     copyright            : (C) 2002 by Gary E.Sherman
@@ -53,13 +53,25 @@
       const QStyleOptionViewItem &option,
       const QModelIndex &index ) const
     {
-      QStringList values = index.data( Qt::UserRole + 1 ).toStringList();
+      if ( index.column() == QgsDbTableModel::dbtmSql )
+      {
+        QLineEdit *le = new QLineEdit( parent );
+        le->setText( index.data( Qt::DisplayRole ).toString() );
+        return le;
+      }
 
-      if( values.size()> 0 )
+
+      if ( index.column() == QgsDbTableModel::dbtmPkCol )
       {
-        QComboBox *cb = new QComboBox( parent );
-        cb->addItems( values );
-        return cb;
+        QStringList values = index.data( Qt::UserRole + 1 ).toStringList();
+
+        if ( values.size() > 0 )
+        {
+          QComboBox *cb = new QComboBox( parent );
+          cb->addItems( values );
+          cb->setCurrentIndex( cb->findText( index.data( Qt::DisplayRole ).toString() ) );
+          return cb;
+        }
       }
 
       return NULL;
@@ -68,9 +80,12 @@
     void setModelData( QWidget *editor, QAbstractItemModel *model, const QModelIndex &index ) const
     {
       QComboBox *cb = dynamic_cast<QComboBox *>( editor );
-      if ( !cb )
-        return;
-      model->setData( index, cb->currentText() );
+      if ( cb )
+        model->setData( index, cb->currentText() );
+
+      QLineEdit *le = dynamic_cast<QLineEdit *>( editor );
+      if ( le )
+        model->setData( index, le->text() );
     }
 };
 

Modified: trunk/qgis/src/app/qgsquerybuilder.cpp
===================================================================
--- trunk/qgis/src/app/qgsquerybuilder.cpp	2009-10-07 17:47:34 UTC (rev 11766)
+++ trunk/qgis/src/app/qgsquerybuilder.cpp	2009-10-08 11:53:09 UTC (rev 11767)
@@ -39,6 +39,8 @@
   mOrigSubsetString = layer->subsetString();
 
   lblDataUri->setText( layer->publicSource() );
+  txtSQL->setText( mOrigSubsetString );
+
   populateFields();
 }
 

Modified: trunk/qgis/src/providers/postgres/qgspostgresprovider.cpp
===================================================================
--- trunk/qgis/src/providers/postgres/qgspostgresprovider.cpp	2009-10-07 17:47:34 UTC (rev 11766)
+++ trunk/qgis/src/providers/postgres/qgspostgresprovider.cpp	2009-10-08 11:53:09 UTC (rev 11767)
@@ -1054,11 +1054,16 @@
 
         Result result = connectionRO->PQexec( sql );
 
-        if ( PQresultStatus( result ) != PGRES_TUPLES_OK ||
-             PQntuples( result ) != 1 ||
-             QString( PQgetvalue( result, 0, 0 ) ) != "int4" ||
-             !uniqueData( mSchemaName, mTableName, primaryKey ) )
+        QString type;
+        if ( PQresultStatus( result ) == PGRES_TUPLES_OK &&
+             PQntuples( result ) == 1 )
         {
+          type = PQgetvalue( result, 0, 0 );
+        }
+
+        if (( type != "int4" && type != "oid" ) ||
+            !uniqueData( mSchemaName, mTableName, primaryKey ) )
+        {
           primaryKey = "";
         }
       }
@@ -2901,8 +2906,10 @@
   }
   else // something went wrong...
   {
-    log.prepend( tr( "Qgis was unable to determine the type and srid of column %1 in %2. The database communication log was:\n" )
-                 .arg( geometryColumn ).arg( mSchemaTableName ) );
+    log.prepend( tr( "Qgis was unable to determine the type and srid of column %1 in %2. The database communication log was:\n%3" )
+                 .arg( geometryColumn )
+                 .arg( mSchemaTableName )
+                 .arg( QString::fromUtf8( PQresultErrorMessage( result ) ) ) );
     showMessageBox( tr( "Unable to get feature type and srid" ), log );
   }
 



More information about the QGIS-commit mailing list