Skip to content
Permalink
Browse files
memory provider: add more native types (fixes #9371)
  • Loading branch information
jef-n committed Feb 5, 2014
1 parent fe05619 commit 22346cd3c7c4c670a26ae1e606f8b0a6d9a0a0a4
Showing with 55 additions and 17 deletions.
  1. +26 −14 src/app/qgisapp.cpp
  2. +11 −2 src/core/qgsvectordataprovider.cpp
  3. +18 −1 src/providers/memory/qgsmemoryprovider.cpp
@@ -5778,19 +5778,22 @@ void QgisApp::editPaste( QgsMapLayer *destinationLayer )

void QgisApp::pasteAsNewVector()
{
if ( mMapCanvas && mMapCanvas->isDrawing() ) return;
if ( mMapCanvas && mMapCanvas->isDrawing() )
return;

QgsVectorLayer * layer = pasteToNewMemoryVector();
if ( !layer ) return;
QgsVectorLayer *layer = pasteToNewMemoryVector();
if ( !layer )
return;

saveAsVectorFileGeneral( false, layer, false );

delete layer;
}

QgsVectorLayer * QgisApp::pasteAsNewMemoryVector( const QString & theLayerName )
QgsVectorLayer *QgisApp::pasteAsNewMemoryVector( const QString & theLayerName )
{
if ( mMapCanvas && mMapCanvas->isDrawing() ) return 0;
if ( mMapCanvas && mMapCanvas->isDrawing() )
return 0;

QString layerName = theLayerName;

@@ -5801,16 +5804,18 @@ QgsVectorLayer * QgisApp::pasteAsNewMemoryVector( const QString & theLayerName )
layerName = QInputDialog::getText( this, tr( "New memory layer name" ),
tr( "Layer name" ), QLineEdit::Normal,
defaultName, &ok );
if ( !ok ) return 0;
if ( !ok )
return 0;

if ( layerName.isEmpty() )
{
layerName = defaultName;
}
}

QgsVectorLayer * layer = pasteToNewMemoryVector();
if ( !layer ) return 0;
QgsVectorLayer *layer = pasteToNewMemoryVector();
if ( !layer )
return 0;

layer->setLayerName( layerName );

@@ -5826,18 +5831,22 @@ QgsVectorLayer * QgisApp::pasteAsNewMemoryVector( const QString & theLayerName )
return layer;
}

QgsVectorLayer * QgisApp::pasteToNewMemoryVector()
QgsVectorLayer *QgisApp::pasteToNewMemoryVector()
{
// Decide geometry type from features, switch to multi type if at least one multi is found
QMap<QGis::WkbType, int> typeCounts;
QgsFeatureList features = clipboard()->copyOf();
for ( int i = 0; i < features.size(); i++ )
{
QgsFeature &feature = features[i];
if ( !feature.geometry() ) continue;
if ( !feature.geometry() )
continue;

QGis::WkbType type = QGis::flatType( feature.geometry()->wkbType() );

if ( type == QGis::WKBUnknown || type == QGis::WKBNoGeometry ) continue;
if ( type == QGis::WKBUnknown || type == QGis::WKBNoGeometry )
continue;

if ( QGis::isSingleType( type ) )
{
if ( typeCounts.contains( QGis::multiType( type ) ) )
@@ -5888,7 +5897,7 @@ QgsVectorLayer * QgisApp::pasteToNewMemoryVector()
return 0;
}

QgsVectorLayer * layer = new QgsVectorLayer( typeName, "pasted_features", "memory" );
QgsVectorLayer *layer = new QgsVectorLayer( typeName, "pasted_features", "memory" );

if ( !layer->isValid() || !layer->dataProvider() )
{
@@ -5917,9 +5926,12 @@ QgsVectorLayer * QgisApp::pasteToNewMemoryVector()
for ( int i = 0; i < features.size(); i++ )
{
QgsFeature &feature = features[i];
if ( !feature.geometry() ) continue;
if ( !feature.geometry() )
continue;

QGis::WkbType type = QGis::flatType( feature.geometry()->wkbType() );
if ( type == QGis::WKBUnknown || type == QGis::WKBNoGeometry ) continue;
if ( type == QGis::WKBUnknown || type == QGis::WKBNoGeometry )
continue;

if ( QGis::singleType( wkbType ) != QGis::singleType( type ) )
{
@@ -257,10 +257,19 @@ const QList< QgsVectorDataProvider::NativeType > &QgsVectorDataProvider::nativeT
bool QgsVectorDataProvider::supportedType( const QgsField &field ) const
{
int i;
QgsDebugMsgLevel( QString( "field name = %1 type = %2 length = %3 precision = %4" ).arg( field.name() ).arg( QVariant::typeToName( field.type() ) ).arg( field.length() ).arg( field.precision() ), 2 );
QgsDebugMsgLevel( QString( "field name = %1 type = %2 length = %3 precision = %4" )
.arg( field.name() )
.arg( QVariant::typeToName( field.type() ) )
.arg( field.length() )
.arg( field.precision() ), 2 );
for ( i = 0; i < mNativeTypes.size(); i++ )
{
QgsDebugMsgLevel( QString( "native field type = %1 min length = %2 max length = %3 min precision = %4 max precision = %5" ).arg( QVariant::typeToName( mNativeTypes[i].mType ) ).arg( mNativeTypes[i].mMinLen ).arg( mNativeTypes[i].mMaxLen ).arg( mNativeTypes[i].mMinPrec ).arg( mNativeTypes[i].mMaxPrec ), 2 );
QgsDebugMsgLevel( QString( "native field type = %1 min length = %2 max length = %3 min precision = %4 max precision = %5" )
.arg( QVariant::typeToName( mNativeTypes[i].mType ) )
.arg( mNativeTypes[i].mMinLen )
.arg( mNativeTypes[i].mMaxLen )
.arg( mNativeTypes[i].mMinPrec )
.arg( mNativeTypes[i].mMaxPrec ), 2 );
if ( field.type() == mNativeTypes[i].mType &&
field.length() >= mNativeTypes[i].mMinLen && field.length() <= mNativeTypes[i].mMaxLen &&
field.precision() >= mNativeTypes[i].mMinPrec && field.precision() <= mNativeTypes[i].mMaxPrec )
@@ -81,7 +81,23 @@ QgsMemoryProvider::QgsMemoryProvider( QString uri )
// So the limits set here are not correct but enable use of data from Shapefiles.
<< QgsVectorDataProvider::NativeType( tr( "Decimal number (real)" ), "double", QVariant::Double, 0, 32, 0, 30 )
<< QgsVectorDataProvider::NativeType( tr( "Text (string)" ), "string", QVariant::String, 0, 255 )
<< QgsVectorDataProvider::NativeType( tr( "Date" ), "date", QVariant::Date, 0, 10 )

// date type
<< QgsVectorDataProvider::NativeType( tr( "Date" ), "date", QVariant::Date, -1, -1, -1, -1 )

// integer types
<< QgsVectorDataProvider::NativeType( tr( "Whole number (smallint - 16bit)" ), "int2", QVariant::Int, -1, -1, 0, 0 )
<< QgsVectorDataProvider::NativeType( tr( "Whole number (integer - 32bit)" ), "int4", QVariant::Int, -1, -1, 0, 0 )
<< QgsVectorDataProvider::NativeType( tr( "Whole number (integer - 64bit)" ), "int8", QVariant::LongLong, -1, -1, 0, 0 )
<< QgsVectorDataProvider::NativeType( tr( "Decimal number (numeric)" ), "numeric", QVariant::Double, 1, 20, 0, 20 )
<< QgsVectorDataProvider::NativeType( tr( "Decimal number (decimal)" ), "decimal", QVariant::Double, 1, 20, 0, 20 )

// floating point
<< QgsVectorDataProvider::NativeType( tr( "Decimal number (real)" ), "real", QVariant::Double, -1, -1, -1, -1 )
<< QgsVectorDataProvider::NativeType( tr( "Decimal number (double)" ), "double precision", QVariant::Double, -1, -1, -1, -1 )

// string types
<< QgsVectorDataProvider::NativeType( tr( "Text, unlimited length (text)" ), "text", QVariant::String, -1, -1, -1, -1 )
;

if ( url.hasQueryItem( "field" ) )
@@ -329,6 +345,7 @@ bool QgsMemoryProvider::addAttributes( const QList<QgsField> &attributes )
case QVariant::Double:
case QVariant::String:
case QVariant::Date:
case QVariant::LongLong:
break;
default:
QgsDebugMsg( "Field type not supported: " + it->typeName() );

0 comments on commit 22346cd

Please sign in to comment.