Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
dxf export dialog: fix select and unselect all (fixes #11987)
  • Loading branch information
jef-n committed Jan 14, 2015
1 parent c3488f4 commit 5996014
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 6 deletions.
50 changes: 44 additions & 6 deletions src/app/qgsdxfexportdialog.cpp
Expand Up @@ -315,7 +315,7 @@ void QgsVectorLayerAndAttributeModel::applyVisibilityPreset( const QString &name

void QgsVectorLayerAndAttributeModel::applyVisibility( QSet<QString> &visibleLayers, QgsLayerTreeNode *node )
{
QgsLayerTreeGroup *group = QgsLayerTree::toGroup( node );
QgsLayerTreeGroup *group = QgsLayerTree::isGroup( node ) ? QgsLayerTree::toGroup( node ) : 0;
if ( !group )
return;

Expand All @@ -336,6 +336,41 @@ void QgsVectorLayerAndAttributeModel::applyVisibility( QSet<QString> &visibleLay
}
}

void QgsVectorLayerAndAttributeModel::retrieveAllLayers( QgsLayerTreeNode *node, QSet<QString> &set )
{
if ( QgsLayerTree::isLayer( node ) )
{
set << QgsLayerTree::toLayer( node )->layer()->id();
}
else if ( QgsLayerTree::isGroup( node ) )
{
foreach ( QgsLayerTreeNode *child, QgsLayerTree::toGroup( node )->children() )
{
retrieveAllLayers( child, set );
}
}
}

void QgsVectorLayerAndAttributeModel::selectAll()
{
mCheckedLeafs.clear();

QSet<QString> allLayers;
retrieveAllLayers( rootGroup(), allLayers );
applyVisibility( allLayers, rootGroup() );

emit dataChanged( QModelIndex(), QModelIndex() );
}

void QgsVectorLayerAndAttributeModel::unSelectAll()
{
mCheckedLeafs.clear();

applyVisibility( QSet<QString>(), rootGroup() );

emit dataChanged( QModelIndex(), QModelIndex() );
}

QgsDxfExportDialog::QgsDxfExportDialog( QWidget *parent, Qt::WindowFlags f )
: QDialog( parent, f )
{
Expand Down Expand Up @@ -392,7 +427,7 @@ void QgsDxfExportDialog::on_mVisibilityPresets_currentIndexChanged( int index )

void QgsDxfExportDialog::cleanGroup( QgsLayerTreeNode *node )
{
QgsLayerTreeGroup *group = QgsLayerTree::toGroup( node );
QgsLayerTreeGroup *group = QgsLayerTree::isGroup( node ) ? QgsLayerTree::toGroup( node ) : 0;
if ( !group )
return;

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

void QgsDxfExportDialog::selectAll()
{
mTreeView->selectAll();
QgsVectorLayerAndAttributeModel *model = dynamic_cast< QgsVectorLayerAndAttributeModel *>( mTreeView->model() );
Q_ASSERT( model );
model->selectAll();
}


void QgsDxfExportDialog::unSelectAll()
{
mTreeView->clearSelection();
QgsVectorLayerAndAttributeModel *model = dynamic_cast< QgsVectorLayerAndAttributeModel *>( mTreeView->model() );
Q_ASSERT( model );
model->unSelectAll();
}


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

double QgsDxfExportDialog::symbologyScale() const
{
double scale = 1/mScaleWidget->scale();
double scale = 1 / mScaleWidget->scale();
if ( qgsDoubleNear( scale, 0.0 ) )
{
return 1.0;
Expand Down
4 changes: 4 additions & 0 deletions src/app/qgsdxfexportdialog.h
Expand Up @@ -60,11 +60,15 @@ class QgsVectorLayerAndAttributeModel : public QgsLayerTreeModel

void applyVisibilityPreset( const QString &name );

void selectAll();
void unSelectAll();

private:
QHash<const QgsVectorLayer *, int> mAttributeIdx;
QSet<QModelIndex> mCheckedLeafs;

void applyVisibility( QSet<QString> &visibleLayers, QgsLayerTreeNode *node );
void retrieveAllLayers( QgsLayerTreeNode *node, QSet<QString> &layers );
};


Expand Down

1 comment on commit 5996014

@3nids
Copy link
Member

@3nids 3nids commented on 5996014 Jan 15, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!

Please sign in to comment.