Skip to content
Permalink
Browse files
Add enum to vector file writer describing the type of symbology export
  • Loading branch information
mhugent committed Dec 13, 2012
1 parent ac2e77c commit c5010dfe8c6798a61a4722dc63b933d07d945cc6
Showing with 24 additions and 9 deletions.
  1. +8 −5 src/core/qgsvectorfilewriter.cpp
  2. +16 −4 src/core/qgsvectorfilewriter.h
@@ -63,13 +63,14 @@ QgsVectorFileWriter::QgsVectorFileWriter(
const QString& driverName,
const QStringList &datasourceOptions,
const QStringList &layerOptions,
QString *newFilename
QString *newFilename,
SymbologyExport symbologyExport
)
: mDS( NULL )
, mLayer( NULL )
, mGeom( NULL )
, mError( NoError )
, mExportFeatureStyle( true )
, mSymbologyExport( symbologyExport )
{
QString vectorFileName = theVectorFileName;
QString fileEncoding = theFileEncoding;
@@ -568,7 +569,7 @@ bool QgsVectorFileWriter::addFeature( QgsFeature& feature, QgsFeatureRendererV2*
}

//add OGR feature style type
if ( mExportFeatureStyle && renderer )
if ( mSymbologyExport != NoSymbology && renderer )
{
//concatenate ogr styles of all symbols
QgsSymbolV2List symbols = renderer->symbolsForFeature( feature );
@@ -650,7 +651,8 @@ QgsVectorFileWriter::writeAsVectorFormat( QgsVectorLayer* layer,
const QStringList &datasourceOptions,
const QStringList &layerOptions,
bool skipAttributeCreation,
QString *newFilename )
QString *newFilename,
SymbologyExport symbologyExport )
{
QgsDebugMsg( "fileName = " + fileName );
const QgsCoordinateReferenceSystem* outputCRS;
@@ -674,7 +676,8 @@ QgsVectorFileWriter::writeAsVectorFormat( QgsVectorLayer* layer,
outputCRS = &layer->crs();
}
QgsVectorFileWriter* writer =
new QgsVectorFileWriter( fileName, fileEncoding, skipAttributeCreation ? QgsFieldMap() : layer->pendingFields(), layer->wkbType(), outputCRS, driverName, datasourceOptions, layerOptions, newFilename );
new QgsVectorFileWriter( fileName, fileEncoding, skipAttributeCreation ? QgsFieldMap() : layer->pendingFields(), layer->wkbType(),
outputCRS, driverName, datasourceOptions, layerOptions, newFilename, symbologyExport );

if ( newFilename )
{
@@ -56,6 +56,14 @@ class CORE_EXPORT QgsVectorFileWriter
ErrInvalidLayer, // added in 2.0
};

//added in 2.0
enum SymbologyExport
{
NoSymbology = 0, //export only data
FeatureSymbology, //Keeps the number of features and export symbology per feature
SymbolLayerSymbology //Exports one feature per symbol layer (considering symbol levels)
};

/** Write contents of vector layer to a shapefile
@deprecated Use writeAsVectorFormat instead*/
Q_DECL_DEPRECATED static WriterError writeAsShapefile( QgsVectorLayer* layer,
@@ -93,7 +101,8 @@ class CORE_EXPORT QgsVectorFileWriter
const QStringList &datasourceOptions = QStringList(), // added in 1.6
const QStringList &layerOptions = QStringList(), // added in 1.6
bool skipAttributeCreation = false, // added in 1.6
QString *newFilename = 0 // added in 1.9
QString *newFilename = 0, // added in 1.9
SymbologyExport symbologyExport = NoSymbology //added in 2.0
);

/** create shapefile and initialize it */
@@ -105,7 +114,8 @@ class CORE_EXPORT QgsVectorFileWriter
const QString& driverName = "ESRI Shapefile",
const QStringList &datasourceOptions = QStringList(), // added in 1.6
const QStringList &layerOptions = QStringList(), // added in 1.6
QString *newFilename = 0 // added in 1.9
QString *newFilename = 0, // added in 1.9
SymbologyExport symbologyExport = NoSymbology//added in 2.0
);

/**Returns map with format filter string as key and OGR format key as value*/
@@ -146,6 +156,9 @@ class CORE_EXPORT QgsVectorFileWriter
*/
static bool deleteShapeFile( QString theFileName );

SymbologyExport symbologyExport() const { return mSymbologyExport; }
void setSymbologyExport( SymbologyExport symExport ) { mSymbologyExport = symExport; }

protected:
//! @note not available in python bindings
OGRGeometryH createEmptyGeometry( QGis::WkbType wkbType );
@@ -168,8 +181,7 @@ class CORE_EXPORT QgsVectorFileWriter
/** map attribute indizes to OGR field indexes */
QMap<int, int> mAttrIdxToOgrIdx;

/** flag if OGR feature type style should be exported*/
bool mExportFeatureStyle;
SymbologyExport mSymbologyExport;

private:
static bool driverMetadata( QString driverName, QString &longName, QString &trLongName, QString &glob, QString &ext );

0 comments on commit c5010df

Please sign in to comment.