Skip to content

Commit 5996014

Browse files
committed
dxf export dialog: fix select and unselect all (fixes #11987)
1 parent c3488f4 commit 5996014

File tree

2 files changed

+48
-6
lines changed

2 files changed

+48
-6
lines changed

src/app/qgsdxfexportdialog.cpp

+44-6
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ void QgsVectorLayerAndAttributeModel::applyVisibilityPreset( const QString &name
315315

316316
void QgsVectorLayerAndAttributeModel::applyVisibility( QSet<QString> &visibleLayers, QgsLayerTreeNode *node )
317317
{
318-
QgsLayerTreeGroup *group = QgsLayerTree::toGroup( node );
318+
QgsLayerTreeGroup *group = QgsLayerTree::isGroup( node ) ? QgsLayerTree::toGroup( node ) : 0;
319319
if ( !group )
320320
return;
321321

@@ -336,6 +336,41 @@ void QgsVectorLayerAndAttributeModel::applyVisibility( QSet<QString> &visibleLay
336336
}
337337
}
338338

339+
void QgsVectorLayerAndAttributeModel::retrieveAllLayers( QgsLayerTreeNode *node, QSet<QString> &set )
340+
{
341+
if ( QgsLayerTree::isLayer( node ) )
342+
{
343+
set << QgsLayerTree::toLayer( node )->layer()->id();
344+
}
345+
else if ( QgsLayerTree::isGroup( node ) )
346+
{
347+
foreach ( QgsLayerTreeNode *child, QgsLayerTree::toGroup( node )->children() )
348+
{
349+
retrieveAllLayers( child, set );
350+
}
351+
}
352+
}
353+
354+
void QgsVectorLayerAndAttributeModel::selectAll()
355+
{
356+
mCheckedLeafs.clear();
357+
358+
QSet<QString> allLayers;
359+
retrieveAllLayers( rootGroup(), allLayers );
360+
applyVisibility( allLayers, rootGroup() );
361+
362+
emit dataChanged( QModelIndex(), QModelIndex() );
363+
}
364+
365+
void QgsVectorLayerAndAttributeModel::unSelectAll()
366+
{
367+
mCheckedLeafs.clear();
368+
369+
applyVisibility( QSet<QString>(), rootGroup() );
370+
371+
emit dataChanged( QModelIndex(), QModelIndex() );
372+
}
373+
339374
QgsDxfExportDialog::QgsDxfExportDialog( QWidget *parent, Qt::WindowFlags f )
340375
: QDialog( parent, f )
341376
{
@@ -392,7 +427,7 @@ void QgsDxfExportDialog::on_mVisibilityPresets_currentIndexChanged( int index )
392427

393428
void QgsDxfExportDialog::cleanGroup( QgsLayerTreeNode *node )
394429
{
395-
QgsLayerTreeGroup *group = QgsLayerTree::toGroup( node );
430+
QgsLayerTreeGroup *group = QgsLayerTree::isGroup( node ) ? QgsLayerTree::toGroup( node ) : 0;
396431
if ( !group )
397432
return;
398433

@@ -418,13 +453,16 @@ void QgsDxfExportDialog::cleanGroup( QgsLayerTreeNode *node )
418453

419454
void QgsDxfExportDialog::selectAll()
420455
{
421-
mTreeView->selectAll();
456+
QgsVectorLayerAndAttributeModel *model = dynamic_cast< QgsVectorLayerAndAttributeModel *>( mTreeView->model() );
457+
Q_ASSERT( model );
458+
model->selectAll();
422459
}
423460

424-
425461
void QgsDxfExportDialog::unSelectAll()
426462
{
427-
mTreeView->clearSelection();
463+
QgsVectorLayerAndAttributeModel *model = dynamic_cast< QgsVectorLayerAndAttributeModel *>( mTreeView->model() );
464+
Q_ASSERT( model );
465+
model->unSelectAll();
428466
}
429467

430468

@@ -438,7 +476,7 @@ QList< QPair<QgsVectorLayer *, int> > QgsDxfExportDialog::layers() const
438476

439477
double QgsDxfExportDialog::symbologyScale() const
440478
{
441-
double scale = 1/mScaleWidget->scale();
479+
double scale = 1 / mScaleWidget->scale();
442480
if ( qgsDoubleNear( scale, 0.0 ) )
443481
{
444482
return 1.0;

src/app/qgsdxfexportdialog.h

+4
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,15 @@ class QgsVectorLayerAndAttributeModel : public QgsLayerTreeModel
6060

6161
void applyVisibilityPreset( const QString &name );
6262

63+
void selectAll();
64+
void unSelectAll();
65+
6366
private:
6467
QHash<const QgsVectorLayer *, int> mAttributeIdx;
6568
QSet<QModelIndex> mCheckedLeafs;
6669

6770
void applyVisibility( QSet<QString> &visibleLayers, QgsLayerTreeNode *node );
71+
void retrieveAllLayers( QgsLayerTreeNode *node, QSet<QString> &layers );
6872
};
6973

7074

0 commit comments

Comments
 (0)