Skip to content

Commit a43f8a3

Browse files
committedOct 25, 2016
Address snapping config UX problems
See #3617 (comment)
1 parent f8bae67 commit a43f8a3

File tree

4 files changed

+24
-5
lines changed

4 files changed

+24
-5
lines changed
 

‎src/app/qgisapp.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -823,9 +823,8 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipVersionCh
823823
QDialog* dialog = new QDialog( this );
824824
dialog->setWindowTitle( tr( "Project snapping settings" ) );
825825
QVBoxLayout* layout = new QVBoxLayout( dialog );
826-
QDialogButtonBox* button = new QDialogButtonBox( QDialogButtonBox::Close );
827826
layout->addWidget( mSnappingDialogWidget );
828-
layout->addWidget( button );
827+
layout->setMargin( 0 );
829828
mSnappingDialogContainer = dialog;
830829
}
831830
endProfile();

‎src/app/qgssnappingwidget.cpp

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,12 +201,15 @@ QgsSnappingWidget::QgsSnappingWidget( QgsProject* project, QgsMapCanvas* canvas,
201201
mLayerTreeView = new QTreeView();
202202
QgsSnappingLayerTreeModel* model = new QgsSnappingLayerTreeModel( mProject, this );
203203
model->setLayerTreeModel( new QgsLayerTreeModel( QgsProject::instance()->layerTreeRoot(), model ) );
204+
205+
connect( model, &QgsSnappingLayerTreeModel::rowsInserted, this, &QgsSnappingWidget::onSnappingTreeLayersChanged );
206+
connect( model, &QgsSnappingLayerTreeModel::modelReset, this, &QgsSnappingWidget::onSnappingTreeLayersChanged );
207+
connect( model, &QgsSnappingLayerTreeModel::rowsRemoved, this, &QgsSnappingWidget::onSnappingTreeLayersChanged );
208+
204209
// model->setFlags( 0 );
205210
mLayerTreeView->setModel( model );
206211
mLayerTreeView->resizeColumnToContents( 0 );
207212
mLayerTreeView->header()->show();
208-
mLayerTreeView->header()->setSectionResizeMode( QHeaderView::ResizeToContents );
209-
mLayerTreeView->header()->setSectionResizeMode( QHeaderView::Interactive );
210213
mLayerTreeView->setSelectionMode( QAbstractItemView::NoSelection );
211214

212215
// item delegates
@@ -230,9 +233,17 @@ QgsSnappingWidget::QgsSnappingWidget( QgsProject* project, QgsMapCanvas* canvas,
230233
connect( project, &QgsProject::topologicalEditingChanged, this, &QgsSnappingWidget::projectTopologicalEditingChanged );
231234
connect( mCanvas, SIGNAL( mapUnitsChanged() ), this, SLOT( updateToleranceDecimals() ) );
232235

236+
237+
// Slightly modify the config so the settings changed code doesn't early exit
238+
mConfig = project->snappingConfig();
239+
mConfig.setEnabled( !mConfig.enabled() );
240+
projectSnapSettingsChanged();
241+
233242
// modeChanged determines if widget are visible or not based on mode
234243
modeChanged();
235244
updateToleranceDecimals();
245+
246+
restoreGeometry( QSettings().value( "/Windows/SnappingWidget/geometry" ).toByteArray() );
236247
}
237248

238249
QgsSnappingWidget::~QgsSnappingWidget()
@@ -252,7 +263,7 @@ void QgsSnappingWidget::projectSnapSettingsChanged()
252263

253264
mEnabledAction->setChecked( config.enabled() );
254265

255-
if ( config.mode() == QgsSnappingConfig::AllLayers && mModeButton->defaultAction() != mActiveLayerAction )
266+
if ( config.mode() == QgsSnappingConfig::AllLayers && mModeButton->defaultAction() != mAllLayersAction )
256267
{
257268
mModeButton->setDefaultAction( mAllLayersAction );
258269
modeChanged();
@@ -351,6 +362,12 @@ void QgsSnappingWidget::enableIntersectionSnapping( bool enabled )
351362
mProject->setSnappingConfig( mConfig );
352363
}
353364

365+
void QgsSnappingWidget::onSnappingTreeLayersChanged()
366+
{
367+
mLayerTreeView->resizeColumnToContents( 0 );
368+
QTimer::singleShot( 0, mLayerTreeView, &QTreeView::expandAll );
369+
}
370+
354371
void QgsSnappingWidget::modeButtonTriggered( QAction* action )
355372
{
356373
if ( action != mModeButton->defaultAction() )

‎src/app/qgssnappingwidget.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ class APP_EXPORT QgsSnappingWidget : public QWidget
9191
//! number of decimals of the tolerance spin box depends on map units
9292
void updateToleranceDecimals();
9393

94+
void onSnappingTreeLayersChanged();
95+
9496
private:
9597
enum DisplayMode
9698
{

‎src/core/qgsproject.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,7 @@ void QgsProject::clear()
451451
mEmbeddedLayers.clear();
452452
mRelationManager->clear();
453453
mSnappingConfig.reset();
454+
emit snappingConfigChanged();
454455

455456
mMapThemeCollection.reset( new QgsMapThemeCollection() );
456457
emit mapThemeCollectionChanged();

0 commit comments

Comments
 (0)
Please sign in to comment.