Skip to content

Commit

Permalink
dxf export: export layers only once and in drawing order
Browse files Browse the repository at this point in the history
  • Loading branch information
jef-n committed Oct 24, 2014
1 parent 8d26a95 commit 5f11c33
Showing 1 changed file with 29 additions and 4 deletions.
33 changes: 29 additions & 4 deletions src/app/qgsdxfexportdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@
***************************************************************************/

#include "qgsdxfexportdialog.h"

#include "qgsmaplayer.h"
#include "qgsmaplayerregistry.h"
#include "qgslayertree.h"
#include "qgslayertreegroup.h"
#include "qgsvectorlayer.h"
#include "qgsproject.h"
#include "qgis.h"
#include "qgsfieldcombobox.h"
#include "qgisapp.h"
#include "qgsmapcanvas.h"

#include <QFileDialog>
#include <QPushButton>
Expand Down Expand Up @@ -181,6 +183,7 @@ bool QgsVectorLayerAndAttributeModel::setData( const QModelIndex &index, const Q
QList< QPair<QgsVectorLayer *, int> > QgsVectorLayerAndAttributeModel::layers( const QModelIndexList &selectedIndexes ) const
{
QList< QPair<QgsVectorLayer *, int> > layers;
QHash< QgsMapLayer *, int > layerIdx;

foreach ( const QModelIndex &idx, selectedIndexes )
{
Expand All @@ -191,18 +194,40 @@ QList< QPair<QgsVectorLayer *, int> > QgsVectorLayerAndAttributeModel::layers( c
{
QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( treeLayer->layer() );
Q_ASSERT( vl );
layers << qMakePair<QgsVectorLayer *, int>( vl, mAttributeIdx.value( vl, -1 ) );
if ( !layerIdx.contains( vl ) )
{
layerIdx.insert( vl, layers.size() );
layers << qMakePair<QgsVectorLayer *, int>( vl, mAttributeIdx.value( vl, -1 ) );
}
}
}
else if ( QgsLayerTree::isLayer( node ) )
{
QgsVectorLayer *vl = qobject_cast< QgsVectorLayer *>( QgsLayerTree::toLayer( node )->layer() );
Q_ASSERT( vl );
layers << qMakePair<QgsVectorLayer *, int>( vl, mAttributeIdx.value( vl, -1 ) );
if ( !layerIdx.contains( vl ) )
{
layerIdx.insert( vl, layers.size() );
layers << qMakePair<QgsVectorLayer *, int>( vl, mAttributeIdx.value( vl, -1 ) );
}
}
}

return layers;
QList<QgsMapLayer*> inDrawingOrder = QgisApp::instance()->mapCanvas()->layers();
QList< QPair<QgsVectorLayer *, int> > layersInOrder;

for ( int i = 0; i < inDrawingOrder.size(); i++ )
{
int idx = layerIdx.value( inDrawingOrder[i], -1 );
if ( idx < 0 )
continue;

layersInOrder << layers[idx];
}

Q_ASSERT( layersInOrder.size() == layers.size() );

return layersInOrder;
}


Expand Down

0 comments on commit 5f11c33

Please sign in to comment.