Skip to content

Commit c2baf1b

Browse files
authoredFeb 12, 2018
[dxf] use struct instead of QPair for addLayers (#6323)
fix #11790
1 parent 6698fb8 commit c2baf1b

File tree

8 files changed

+58
-22
lines changed

8 files changed

+58
-22
lines changed
 

‎python/core/dxf/qgsdxfexport.sip

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,22 @@ class QgsDxfExport
2121
#include <qgsdxfexport.h>
2222
%End
2323
public:
24+
struct DxfLayer
25+
{
26+
DxfLayer( QgsVectorLayer *vl, int layerOutputAttributeIndex = -1 );
27+
28+
QgsVectorLayer *layer() const;
29+
%Docstring
30+
Return the layer
31+
%End
32+
33+
int layerOutputAttributeIndex() const;
34+
%Docstring
35+
Return the attribute index used to split into multiple layers.
36+
The attribute value is used for layer names.
37+
%End
38+
};
39+
2440
enum SymbologyExport
2541
{
2642
NoSymbology, //export only data
@@ -42,7 +58,7 @@ class QgsDxfExport
4258
* @param layers list of layers and corresponding attribute indexes that determine the layer name (-1 for original layer name or title)
4359
* @see setLayerTitleAsName
4460
*/
45-
void addLayers( const QList< QPair<QgsVectorLayer *, int > > &layers );
61+
void addLayers( const QList< QgsDxfExport::DxfLayer > &layers );
4662

4763
/**
4864
* Export to a dxf file in the given encoding

‎src/app/main.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1267,15 +1267,15 @@ int main( int argc, char *argv[] )
12671267
dxfExport.setExtent( dxfExtent );
12681268

12691269
QStringList layerIds;
1270-
QList< QPair<QgsVectorLayer *, int > > layers;
1270+
QList< QgsDxfExport::DxfLayer > layers;
12711271
if ( !dxfPreset.isEmpty() )
12721272
{
12731273
Q_FOREACH ( const QString& layer, QgsProject::instance()->visibilityPresetCollection()->presetVisibleLayers( dxfPreset ) )
12741274
{
12751275
QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( QgsMapLayerRegistry::instance()->mapLayer( layer ) );
12761276
if ( !vl )
12771277
continue;
1278-
layers << qMakePair<QgsVectorLayer *, int>( vl, -1 );
1278+
layers << QgsDxfExport::DxfLayer( vl );
12791279
layerIds << vl->id();
12801280
}
12811281
}
@@ -1286,7 +1286,7 @@ int main( int argc, char *argv[] )
12861286
QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( ml );
12871287
if ( !vl )
12881288
continue;
1289-
layers << qMakePair<QgsVectorLayer *, int>( vl, -1 );
1289+
layers << QgsDxfExport::DxfLayer( vl );
12901290
layerIds << vl->id();
12911291
}
12921292
}

‎src/app/qgsdxfexportdialog.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -278,9 +278,9 @@ bool QgsVectorLayerAndAttributeModel::setData( const QModelIndex &index, const Q
278278
}
279279

280280

281-
QList< QPair<QgsVectorLayer *, int> > QgsVectorLayerAndAttributeModel::layers() const
281+
QList< QgsDxfExport::DxfLayer > QgsVectorLayerAndAttributeModel::layers() const
282282
{
283-
QList< QPair<QgsVectorLayer *, int> > layers;
283+
QList< QgsDxfExport::DxfLayer > layers;
284284
QHash< QString, int > layerIdx;
285285

286286
Q_FOREACH ( const QModelIndex &idx, mCheckedLeafs )
@@ -295,7 +295,7 @@ QList< QPair<QgsVectorLayer *, int> > QgsVectorLayerAndAttributeModel::layers()
295295
if ( !layerIdx.contains( vl->id() ) )
296296
{
297297
layerIdx.insert( vl->id(), layers.size() );
298-
layers << qMakePair<QgsVectorLayer *, int>( vl, mAttributeIdx.value( vl, -1 ) );
298+
layers << QgsDxfExport::DxfLayer( vl, mAttributeIdx.value( vl, -1 ) );
299299
}
300300
}
301301
}
@@ -306,14 +306,14 @@ QList< QPair<QgsVectorLayer *, int> > QgsVectorLayerAndAttributeModel::layers()
306306
if ( !layerIdx.contains( vl->id() ) )
307307
{
308308
layerIdx.insert( vl->id(), layers.size() );
309-
layers << qMakePair<QgsVectorLayer *, int>( vl, mAttributeIdx.value( vl, -1 ) );
309+
layers << QgsDxfExport::DxfLayer( vl, mAttributeIdx.value( vl, -1 ) );
310310
}
311311
}
312312
}
313313

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

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

532532

533-
QList< QPair<QgsVectorLayer *, int> > QgsDxfExportDialog::layers() const
533+
QList< QgsDxfExport::DxfLayer > QgsDxfExportDialog::layers() const
534534
{
535535
const QgsVectorLayerAndAttributeModel *model = dynamic_cast< const QgsVectorLayerAndAttributeModel *>( mTreeView->model() );
536536
Q_ASSERT( model );

‎src/app/qgsdxfexportdialog.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class QgsVectorLayerAndAttributeModel : public QgsLayerTreeModel
5454
Qt::ItemFlags flags( const QModelIndex &index ) const override;
5555
bool setData( const QModelIndex &index, const QVariant &value, int role = Qt::EditRole ) override;
5656

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

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

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

8585
double symbologyScale() const;
8686
QgsDxfExport::SymbologyExport symbologyMode() const;

‎src/core/dxf/qgsdxfexport.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -406,18 +406,18 @@ void QgsDxfExport::setMapSettings( const QgsMapSettings &settings )
406406
mMapSettings = settings;
407407
}
408408

409-
void QgsDxfExport::addLayers( const QList< QPair< QgsVectorLayer *, int > > &layers )
409+
void QgsDxfExport::addLayers( const QList<DxfLayer> &layers )
410410
{
411411
QStringList layerList;
412412

413413
mLayerNameAttribute.clear();
414414

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

423423
mMapSettings.setLayers( layerList );

‎src/core/dxf/qgsdxfexport.h

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,25 @@ namespace pal
4343
class CORE_EXPORT QgsDxfExport
4444
{
4545
public:
46+
47+
/**
48+
* Layers and optional attribute index to split
49+
* into multiple layers using attribute value as layer name.
50+
*/
51+
struct DxfLayer
52+
{
53+
DxfLayer( QgsVectorLayer *vl, int layerOutputAttributeIndex = -1 )
54+
: mLayer( vl )
55+
, mLayerOutputAttributeIndex( layerOutputAttributeIndex )
56+
{}
57+
58+
QgsVectorLayer *layer() const {return mLayer;}
59+
int layerOutputAttributeIndex() const {return mLayerOutputAttributeIndex;}
60+
61+
QgsVectorLayer *mLayer;
62+
int mLayerOutputAttributeIndex;
63+
};
64+
4665
enum SymbologyExport
4766
{
4867
NoSymbology = 0, //export only data
@@ -66,7 +85,7 @@ class CORE_EXPORT QgsDxfExport
6685
* @param layers list of layers and corresponding attribute indexes that determine the layer name (-1 for original layer name or title)
6786
* @see setLayerTitleAsName
6887
*/
69-
void addLayers( const QList< QPair<QgsVectorLayer *, int > > &layers );
88+
void addLayers( const QList< QgsDxfExport::DxfLayer > &layers );
7089

7190
/**
7291
* Export to a dxf file in the given encoding

‎src/server/qgswmsserver.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1519,7 +1519,7 @@ void QgsWMSServer::getMapAsDxf()
15191519
QMap<QString, QString > formatOptionsMap;
15201520
readFormatOptions( formatOptionsMap );
15211521

1522-
QList< QPair<QgsVectorLayer *, int > > layers;
1522+
QList< QgsDxfExport::DxfLayer > layers;
15231523
readDxfLayerSettings( layers, formatOptionsMap );
15241524
dxf.addLayers( layers );
15251525

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

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

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

3627-
layers.append( qMakePair( vlayer, layerAttribute ) );
3627+
layers.append( QgsDxfExport::DxfLayer( vlayer, layerAttribute ) );
36283628
}
36293629
}
36303630
}

‎src/server/qgswmsserver.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
#include "qgsowsserver.h"
2222
#include "qgswmsconfigparser.h"
23+
#include "qgsdxfexport.h"
2324
#include <QDomDocument>
2425
#include <QMap>
2526
#include <QPair>
@@ -281,7 +282,7 @@ class QgsWMSServer: public QgsOWSServer
281282

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

287288
#endif

0 commit comments

Comments
 (0)
Please sign in to comment.