Skip to content
Permalink
Browse files
[dxf] use struct instead of QPair for addLayers (#6323)
fix #11790
  • Loading branch information
3nids committed Feb 12, 2018
1 parent 6698fb8 commit c2baf1b
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 22 deletions.
@@ -21,6 +21,22 @@ class QgsDxfExport
#include <qgsdxfexport.h>
%End
public:
struct DxfLayer
{
DxfLayer( QgsVectorLayer *vl, int layerOutputAttributeIndex = -1 );

QgsVectorLayer *layer() const;
%Docstring
Return the layer
%End

int layerOutputAttributeIndex() const;
%Docstring
Return the attribute index used to split into multiple layers.
The attribute value is used for layer names.
%End
};

enum SymbologyExport
{
NoSymbology, //export only data
@@ -42,7 +58,7 @@ class QgsDxfExport
* @param layers list of layers and corresponding attribute indexes that determine the layer name (-1 for original layer name or title)
* @see setLayerTitleAsName
*/
void addLayers( const QList< QPair<QgsVectorLayer *, int > > &layers );
void addLayers( const QList< QgsDxfExport::DxfLayer > &layers );

/**
* Export to a dxf file in the given encoding
@@ -1267,15 +1267,15 @@ int main( int argc, char *argv[] )
dxfExport.setExtent( dxfExtent );

QStringList layerIds;
QList< QPair<QgsVectorLayer *, int > > layers;
QList< QgsDxfExport::DxfLayer > layers;
if ( !dxfPreset.isEmpty() )
{
Q_FOREACH ( const QString& layer, QgsProject::instance()->visibilityPresetCollection()->presetVisibleLayers( dxfPreset ) )
{
QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( QgsMapLayerRegistry::instance()->mapLayer( layer ) );
if ( !vl )
continue;
layers << qMakePair<QgsVectorLayer *, int>( vl, -1 );
layers << QgsDxfExport::DxfLayer( vl );
layerIds << vl->id();
}
}
@@ -1286,7 +1286,7 @@ int main( int argc, char *argv[] )
QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( ml );
if ( !vl )
continue;
layers << qMakePair<QgsVectorLayer *, int>( vl, -1 );
layers << QgsDxfExport::DxfLayer( vl );
layerIds << vl->id();
}
}
@@ -278,9 +278,9 @@ bool QgsVectorLayerAndAttributeModel::setData( const QModelIndex &index, const Q
}


QList< QPair<QgsVectorLayer *, int> > QgsVectorLayerAndAttributeModel::layers() const
QList< QgsDxfExport::DxfLayer > QgsVectorLayerAndAttributeModel::layers() const
{
QList< QPair<QgsVectorLayer *, int> > layers;
QList< QgsDxfExport::DxfLayer > layers;
QHash< QString, int > layerIdx;

Q_FOREACH ( const QModelIndex &idx, mCheckedLeafs )
@@ -295,7 +295,7 @@ QList< QPair<QgsVectorLayer *, int> > QgsVectorLayerAndAttributeModel::layers()
if ( !layerIdx.contains( vl->id() ) )
{
layerIdx.insert( vl->id(), layers.size() );
layers << qMakePair<QgsVectorLayer *, int>( vl, mAttributeIdx.value( vl, -1 ) );
layers << QgsDxfExport::DxfLayer( vl, mAttributeIdx.value( vl, -1 ) );
}
}
}
@@ -306,14 +306,14 @@ QList< QPair<QgsVectorLayer *, int> > QgsVectorLayerAndAttributeModel::layers()
if ( !layerIdx.contains( vl->id() ) )
{
layerIdx.insert( vl->id(), layers.size() );
layers << qMakePair<QgsVectorLayer *, int>( vl, mAttributeIdx.value( vl, -1 ) );
layers << QgsDxfExport::DxfLayer( vl, mAttributeIdx.value( vl, -1 ) );
}
}
}

QgsLayerTreeMapCanvasBridge* bridge = QgisApp::instance()->layerTreeCanvasBridge();
QStringList inDrawingOrder = bridge->hasCustomLayerOrder() ? bridge->customLayerOrder() : bridge->defaultLayerOrder();
QList< QPair<QgsVectorLayer *, int> > layersInROrder;
QList< QgsDxfExport::DxfLayer > layersInROrder;

for ( int i = inDrawingOrder.size() - 1; i >= 0; i-- )
{
@@ -530,7 +530,7 @@ void QgsDxfExportDialog::unSelectAll()
}


QList< QPair<QgsVectorLayer *, int> > QgsDxfExportDialog::layers() const
QList< QgsDxfExport::DxfLayer > QgsDxfExportDialog::layers() const
{
const QgsVectorLayerAndAttributeModel *model = dynamic_cast< const QgsVectorLayerAndAttributeModel *>( mTreeView->model() );
Q_ASSERT( model );
@@ -54,7 +54,7 @@ class QgsVectorLayerAndAttributeModel : public QgsLayerTreeModel
Qt::ItemFlags flags( const QModelIndex &index ) const override;
bool setData( const QModelIndex &index, const QVariant &value, int role = Qt::EditRole ) override;

QList< QPair<QgsVectorLayer *, int> > layers() const;
QList< QgsDxfExport::DxfLayer > layers() const;

QgsVectorLayer *vectorLayer( const QModelIndex &index ) const;
int attributeIndex( const QgsVectorLayer *vl ) const;
@@ -80,7 +80,7 @@ class QgsDxfExportDialog : public QDialog, private Ui::QgsDxfExportDialogBase
QgsDxfExportDialog( QWidget * parent = nullptr, Qt::WindowFlags f = nullptr );
~QgsDxfExportDialog();

QList< QPair<QgsVectorLayer *, int> > layers() const;
QList< QgsDxfExport::DxfLayer > layers() const;

double symbologyScale() const;
QgsDxfExport::SymbologyExport symbologyMode() const;
@@ -406,18 +406,18 @@ void QgsDxfExport::setMapSettings( const QgsMapSettings &settings )
mMapSettings = settings;
}

void QgsDxfExport::addLayers( const QList< QPair< QgsVectorLayer *, int > > &layers )
void QgsDxfExport::addLayers( const QList<DxfLayer> &layers )
{
QStringList layerList;

mLayerNameAttribute.clear();

QList< QPair< QgsVectorLayer*, int > >::const_iterator layerIt = layers.constBegin();
QList< DxfLayer >::const_iterator layerIt = layers.constBegin();
for ( ; layerIt != layers.constEnd(); ++layerIt )
{
layerList << layerIt->first->id();
if ( layerIt->second >= 0 )
mLayerNameAttribute.insert( layerIt->first->id(), layerIt->second );
layerList << layerIt->layer()->id();
if ( layerIt->layerOutputAttributeIndex() >= 0 )
mLayerNameAttribute.insert( layerIt->layer()->id(), layerIt->layerOutputAttributeIndex() );
}

mMapSettings.setLayers( layerList );
@@ -43,6 +43,25 @@ namespace pal
class CORE_EXPORT QgsDxfExport
{
public:

/**
* Layers and optional attribute index to split
* into multiple layers using attribute value as layer name.
*/
struct DxfLayer
{
DxfLayer( QgsVectorLayer *vl, int layerOutputAttributeIndex = -1 )
: mLayer( vl )
, mLayerOutputAttributeIndex( layerOutputAttributeIndex )
{}

QgsVectorLayer *layer() const {return mLayer;}
int layerOutputAttributeIndex() const {return mLayerOutputAttributeIndex;}

QgsVectorLayer *mLayer;
int mLayerOutputAttributeIndex;
};

enum SymbologyExport
{
NoSymbology = 0, //export only data
@@ -66,7 +85,7 @@ class CORE_EXPORT QgsDxfExport
* @param layers list of layers and corresponding attribute indexes that determine the layer name (-1 for original layer name or title)
* @see setLayerTitleAsName
*/
void addLayers( const QList< QPair<QgsVectorLayer *, int > > &layers );
void addLayers( const QList< QgsDxfExport::DxfLayer > &layers );

/**
* Export to a dxf file in the given encoding
@@ -1519,7 +1519,7 @@ void QgsWMSServer::getMapAsDxf()
QMap<QString, QString > formatOptionsMap;
readFormatOptions( formatOptionsMap );

QList< QPair<QgsVectorLayer *, int > > layers;
QList< QgsDxfExport::DxfLayer > layers;
readDxfLayerSettings( layers, formatOptionsMap );
dxf.addLayers( layers );

@@ -3566,7 +3566,7 @@ void QgsWMSServer::readFormatOptions( QMap<QString, QString>& formatOptions ) co
}
}

void QgsWMSServer::readDxfLayerSettings( QList< QPair<QgsVectorLayer *, int > >& layers, const QMap<QString, QString>& formatOptionsMap ) const
void QgsWMSServer::readDxfLayerSettings( QList< QgsDxfExport::DxfLayer >& layers, const QMap<QString, QString>& formatOptionsMap ) const
{
layers.clear();

@@ -3624,7 +3624,7 @@ void QgsWMSServer::readDxfLayerSettings( QList< QPair<QgsVectorLayer *, int > >&
continue;
}

layers.append( qMakePair( vlayer, layerAttribute ) );
layers.append( QgsDxfExport::DxfLayer( vlayer, layerAttribute ) );
}
}
}
@@ -20,6 +20,7 @@

#include "qgsowsserver.h"
#include "qgswmsconfigparser.h"
#include "qgsdxfexport.h"
#include <QDomDocument>
#include <QMap>
#include <QPair>
@@ -281,7 +282,7 @@ class QgsWMSServer: public QgsOWSServer

/** Reads and extracts the different options in the FORMAT_OPTIONS parameter*/
void readFormatOptions( QMap<QString, QString>& formatOptions ) const;
void readDxfLayerSettings( QList< QPair<QgsVectorLayer *, int > >& layers, const QMap<QString, QString>& formatOptionsMap ) const;
void readDxfLayerSettings( QList< QgsDxfExport::DxfLayer >& layers, const QMap<QString, QString>& formatOptionsMap ) const;
};

#endif

0 comments on commit c2baf1b

Please sign in to comment.