Skip to content
Permalink
Browse files

Defer resizing columns in snapping widget until the widget is actuall…

…y visible

Otherwise this can cause a HUGE amount of unnecessary work when adding a large number
of layers (or layers with a large number of legend nodes) to a project

(cherry picked from commit 1fc6062)
  • Loading branch information
nyalldawson committed Dec 21, 2020
1 parent 0befc29 commit 17bd6dac1bc3a48d6ede55dc658a8329a86638e8
Showing with 28 additions and 3 deletions.
  1. +24 −3 src/app/qgssnappingwidget.cpp
  2. +4 −0 src/app/qgssnappingwidget.h
@@ -88,6 +88,8 @@ QgsSnappingWidget::QgsSnappingWidget( QgsProject *project, QgsMapCanvas *canvas,
mLayerTreeView = new QTreeView();
QgsSnappingLayerTreeModel *model = new QgsSnappingLayerTreeModel( mProject, mCanvas, this );
model->setLayerTreeModel( new QgsLayerTreeModel( mProject->layerTreeRoot(), model ) );
mLayerTreeView->installEventFilter( this );

// connections
connect( model, &QgsSnappingLayerTreeModel::rowsInserted, this, &QgsSnappingWidget::onSnappingTreeLayersChanged );
connect( model, &QgsSnappingLayerTreeModel::modelReset, this, &QgsSnappingWidget::onSnappingTreeLayersChanged );
@@ -639,8 +641,16 @@ void QgsSnappingWidget::enableSelfSnapping( bool enabled )

void QgsSnappingWidget::onSnappingTreeLayersChanged()
{
mLayerTreeView->expandAll();
mLayerTreeView->resizeColumnToContents( 0 );
if ( mLayerTreeView->isVisible() )
{
mLayerTreeView->expandAll();
mLayerTreeView->resizeColumnToContents( 0 );
mRequireLayerTreeViewUpdate = false;
}
else
{
mRequireLayerTreeViewUpdate = true;
}
}

void QgsSnappingWidget::avoidIntersectionsModeButtonTriggered( QAction *action )
@@ -818,7 +828,18 @@ void QgsSnappingWidget::setConfig( const QgsSnappingConfig &config )
mConfig = config;
}


bool QgsSnappingWidget::eventFilter( QObject *watched, QEvent *event )
{
if ( watched == mLayerTreeView && event->type() == QEvent::Show )
{
if ( mRequireLayerTreeViewUpdate )
{
mLayerTreeView->expandAll();
mLayerTreeView->resizeColumnToContents( 0 );
}
}
return QWidget::eventFilter( watched, event );
}

void QgsSnappingWidget::cleanGroup( QgsLayerTreeNode *node )
{
@@ -87,6 +87,8 @@ class APP_EXPORT QgsSnappingWidget : public QWidget
//! Returns spin box used to set offset for tracing
QgsDoubleSpinBox *tracingOffsetSpinBox() { return mTracingOffsetSpinBox; }

bool eventFilter( QObject *watched, QEvent *event ) override;

signals:
void snappingConfigChanged();

@@ -179,6 +181,8 @@ class APP_EXPORT QgsSnappingWidget : public QWidget
QWidget *mAdvancedConfigWidget = nullptr;
QgsFloatingWidget *mAdvancedConfigContainer = nullptr;

bool mRequireLayerTreeViewUpdate = false;

void cleanGroup( QgsLayerTreeNode *node );
};

0 comments on commit 17bd6da

Please sign in to comment.
You can’t perform that action at this time.