Skip to content
Permalink
Browse files

fix support for multigeometries in postgres and mssql provider

  • Loading branch information
jef-n committed Mar 25, 2012
1 parent dcd8685 commit 494561167d9dec75db173c521051840a84879b6c
@@ -27,7 +27,7 @@ QgsDataSourceURI::QgsDataSourceURI()
, mKeyColumn( "" )
, mUseEstimatedMetadata( false )
, mSelectAtIdDisabled( false )
, mGeometryType( QGis::UnknownGeometry )
, mWkbType( QGis::WKBUnknown )
{
// do nothing
}
@@ -37,7 +37,7 @@ QgsDataSourceURI::QgsDataSourceURI( QString uri )
, mKeyColumn( "" )
, mUseEstimatedMetadata( false )
, mSelectAtIdDisabled( false )
, mGeometryType( QGis::UnknownGeometry )
, mWkbType( QGis::WKBUnknown )
{
int i = 0;
while ( i < uri.length() )
@@ -134,19 +134,31 @@ QgsDataSourceURI::QgsDataSourceURI( QString uri )
QString geomTypeUpper = pval.toUpper();
if ( geomTypeUpper == "POINT" )
{
mGeometryType = QGis::Point;
mWkbType = QGis::WKBPoint;
}
else if ( geomTypeUpper == "LINE" )
else if ( geomTypeUpper == "LINESTRING" || geomTypeUpper == "LINE" )
{
mGeometryType = QGis::Line;
mWkbType = QGis::WKBLineString;
}
else if ( geomTypeUpper == "POLYGON" )
{
mGeometryType = QGis::Polygon;
mWkbType = QGis::WKBPolygon;
}
else if ( geomTypeUpper == "MULTIPOINT" )
{
mWkbType = QGis::WKBMultiPoint;
}
else if ( geomTypeUpper == "MULTLINESTRING" )
{
mWkbType = QGis::WKBMultiLineString;
}
else if ( geomTypeUpper == "MULTIPOLYGON" )
{
mWkbType = QGis::WKBMultiPolygon;
}
else
{
mGeometryType = QGis::UnknownGeometry;
mWkbType = QGis::WKBUnknown;
}
}
else if ( pname == "selectatid" )
@@ -514,9 +526,52 @@ QString QgsDataSourceURI::uri() const
theUri += QString( " srid=%1" ).arg( mSrid );
}

if ( mGeometryType != QGis::UnknownGeometry && mGeometryType != QGis::NoGeometry )
if ( mWkbType != QGis::WKBUnknown && mWkbType != QGis::WKBNoGeometry )
{
theUri += QString( " type=%1" ).arg( QGis::qgisVectorGeometryType[mGeometryType] );
theUri += " type=";

switch( mWkbType )
{
case QGis::WKBPoint:
theUri += "POINT";
break;
case QGis::WKBLineString:
theUri += "LINESTRING";
break;
case QGis::WKBPolygon:
theUri += "POLYGON";
break;
case QGis::WKBMultiPoint:
theUri += "MULTIPOINT";
break;
case QGis::WKBMultiLineString:
theUri += "MULTILINESTRING";
break;
case QGis::WKBMultiPolygon:
theUri += "MULTIPOLYGON";
break;
case QGis::WKBPoint25D:
theUri += "POINTM";
break;
case QGis::WKBLineString25D:
theUri += "LINESTRINGM";
break;
case QGis::WKBPolygon25D:
theUri += "POLYGONM";
break;
case QGis::WKBMultiPoint25D:
theUri += "MULTIPOINTM";
break;
case QGis::WKBMultiLineString25D:
theUri += "MULTILINESTRINGM";
break;
case QGis::WKBMultiPolygon25D:
theUri += "MULTIPOLYGONM";
break;
case QGis::WKBUnknown:
case QGis::WKBNoGeometry:
break;
}
}

if ( mSelectAtIdDisabled )
@@ -589,14 +644,14 @@ void QgsDataSourceURI::setDatabase( const QString &database )
mDatabase = database;
}

QGis::GeometryType QgsDataSourceURI::geometryType() const
QGis::WkbType QgsDataSourceURI::wkbType() const
{
return mGeometryType;
return mWkbType;
}

void QgsDataSourceURI::setGeometryType( QGis::GeometryType geometryType )
void QgsDataSourceURI::setWkbType( QGis::WkbType wkbType )
{
mGeometryType = geometryType;
mWkbType = wkbType;
}

QString QgsDataSourceURI::srid() const
@@ -118,8 +118,8 @@ class CORE_EXPORT QgsDataSourceURI
void setKeyColumn( QString column );

// added in 1.9
QGis::GeometryType geometryType() const;
void setGeometryType( QGis::GeometryType type );
QGis::WkbType wkbType() const;
void setWkbType( QGis::WkbType type );

QString srid() const;
void setSrid( QString srid );
@@ -160,7 +160,7 @@ class CORE_EXPORT QgsDataSourceURI
//! Disable SelectAtId capability (eg. to trigger the attribute table memory model for expensive views)
bool mSelectAtIdDisabled;
//! geometry type (or QGis::WKBUnknown if not specified)
QGis::GeometryType mGeometryType;
QGis::WkbType mWkbType;
//! SRID or a null string if not specified
QString mSrid;
};
@@ -264,8 +264,8 @@ void QgsMssqlConnectionItem::setLayerType( QgsMssqlLayerProperty layerProperty )

for ( int i = 0 ; i < typeList.size(); i++ )
{
QGis::GeometryType geomType = QgsMssqlTableModel::geomTypeFromMssql( typeList[i] );
if ( geomType == QGis::UnknownGeometry )
QGis::WkbType wkbType = QgsMssqlTableModel::wkbTypeFromMssql( typeList[i] );
if ( wkbType == QGis::WKBUnknown )
{
QgsDebugMsg( QString( "unsupported geometry type:%1" ).arg( typeList[i] ) );
continue;
@@ -420,7 +420,7 @@ QString QgsMssqlLayerItem::createUri()
QgsDataSourceURI uri = QgsDataSourceURI( connItem->connInfo() );
uri.setDataSource( mLayerProperty.schemaName, mLayerProperty.tableName, mLayerProperty.geometryColName, mLayerProperty.sql, pkColName );
uri.setSrid( mLayerProperty.srid );
uri.setGeometryType( QgsMssqlTableModel::geomTypeFromMssql( mLayerProperty.type ) );
uri.setWkbType( QgsMssqlTableModel::wkbTypeFromMssql( mLayerProperty.type ) );
QgsDebugMsg( QString( "layer uri: %1" ).arg( uri.uri() ) );
return uri.uri();
}
@@ -459,19 +459,28 @@ void QgsMssqlSchemaItem::addLayers( QgsDataItem* newLayers )

QgsMssqlLayerItem* QgsMssqlSchemaItem::addLayer( QgsMssqlLayerProperty layerProperty, bool refresh )
{
QGis::GeometryType geomType = QgsMssqlTableModel::geomTypeFromMssql( layerProperty.type );
QString tip = tr( "%1 as %2 in %3" ).arg( layerProperty.geometryColName ).arg( QgsMssqlTableModel::displayStringForGeomType( geomType ) ).arg( layerProperty.srid );
QGis::WkbType wkbType = QgsMssqlTableModel::wkbTypeFromMssql( layerProperty.type );
QString tip = tr( "%1 as %2 in %3" ).arg( layerProperty.geometryColName ).arg( QgsMssqlTableModel::displayStringForWkbType( wkbType ) ).arg( layerProperty.srid );

QgsLayerItem::LayerType layerType;
switch ( geomType )
switch ( wkbType )
{
case QGis::Point:
case QGis::WKBPoint:
case QGis::WKBPoint25D:
case QGis::WKBMultiPoint:
case QGis::WKBMultiPoint25D:
layerType = QgsLayerItem::Point;
break;
case QGis::Line:
case QGis::WKBLineString:
case QGis::WKBLineString25D:
case QGis::WKBMultiLineString:
case QGis::WKBMultiLineString25D:
layerType = QgsLayerItem::Line;
break;
case QGis::Polygon:
case QGis::WKBPolygon:
case QGis::WKBPolygon25D:
case QGis::WKBMultiPolygon:
case QGis::WKBMultiPolygon25D:
layerType = QgsLayerItem::Polygon;
break;
default:
@@ -52,14 +52,17 @@ QWidget *QgsMssqlSourceSelectDelegate::createEditor( QWidget *parent, const QSty
if ( index.column() == QgsMssqlTableModel::dbtmType && index.data( Qt::UserRole + 1 ).toBool() )
{
QComboBox *cb = new QComboBox( parent );
foreach( QGis::GeometryType type,
QList<QGis::GeometryType>()
<< QGis::Point
<< QGis::Line
<< QGis::Polygon
<< QGis::NoGeometry )
foreach( QGis::WkbType type,
QList<QGis::WkbType>()
<< QGis::WKBPoint
<< QGis::WKBLineString
<< QGis::WKBPolygon
<< QGis::WKBMultiPoint
<< QGis::WKBMultiLineString
<< QGis::WKBMultiPolygon
<< QGis::WKBNoGeometry )
{
cb->addItem( QgsMssqlTableModel::iconForGeomType( type ), QgsMssqlTableModel::displayStringForGeomType( type ), type );
cb->addItem( QgsMssqlTableModel::iconForWkbType( type ), QgsMssqlTableModel::displayStringForWkbType( type ), type );
}
cb->setCurrentIndex( cb->findData( index.data( Qt::UserRole + 2 ).toInt() ) );
return cb;
@@ -96,10 +99,10 @@ void QgsMssqlSourceSelectDelegate::setModelData( QWidget *editor, QAbstractItemM
{
if ( index.column() == QgsMssqlTableModel::dbtmType )
{
QGis::GeometryType type = ( QGis::GeometryType ) cb->itemData( cb->currentIndex() ).toInt();
QGis::WkbType type = ( QGis::WkbType ) cb->itemData( cb->currentIndex() ).toInt();

model->setData( index, QgsMssqlTableModel::iconForGeomType( type ), Qt::DecorationRole );
model->setData( index, type != QGis::UnknownGeometry ? QgsMssqlTableModel::displayStringForGeomType( type ) : tr( "Select..." ) );
model->setData( index, QgsMssqlTableModel::iconForWkbType( type ), Qt::DecorationRole );
model->setData( index, type != QGis::WKBUnknown ? QgsMssqlTableModel::displayStringForWkbType( type ) : tr( "Select..." ) );
model->setData( index, type, Qt::UserRole + 2 );
}
else if ( index.column() == QgsMssqlTableModel::dbtmPkCol )
@@ -811,4 +814,4 @@ void QgsMssqlGeomColumnTypeThread::run()
// Now tell the layer list dialog box...
emit setLayerType( layerProperty );
}
}
}

0 comments on commit 4945611

Please sign in to comment.
You can’t perform that action at this time.