Skip to content

Commit

Permalink
Add enum to vector file writer describing the type of symbology export
Browse files Browse the repository at this point in the history
  • Loading branch information
mhugent committed Dec 13, 2012
1 parent ac2e77c commit c5010df
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
13 changes: 8 additions & 5 deletions src/core/qgsvectorfilewriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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;
Expand All @@ -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 )
{
Expand Down
20 changes: 16 additions & 4 deletions src/core/qgsvectorfilewriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 */
Expand All @@ -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*/
Expand Down Expand Up @@ -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 );
Expand All @@ -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 );
Expand Down

0 comments on commit c5010df

Please sign in to comment.