Skip to content

Commit

Permalink
Address snapping config UX problems
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Oct 25, 2016
1 parent f8bae67 commit a43f8a3
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
3 changes: 1 addition & 2 deletions src/app/qgisapp.cpp
Expand Up @@ -823,9 +823,8 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipVersionCh
QDialog* dialog = new QDialog( this );
dialog->setWindowTitle( tr( "Project snapping settings" ) );
QVBoxLayout* layout = new QVBoxLayout( dialog );
QDialogButtonBox* button = new QDialogButtonBox( QDialogButtonBox::Close );
layout->addWidget( mSnappingDialogWidget );
layout->addWidget( button );
layout->setMargin( 0 );
mSnappingDialogContainer = dialog;
}
endProfile();
Expand Down
23 changes: 20 additions & 3 deletions src/app/qgssnappingwidget.cpp
Expand Up @@ -201,12 +201,15 @@ QgsSnappingWidget::QgsSnappingWidget( QgsProject* project, QgsMapCanvas* canvas,
mLayerTreeView = new QTreeView();
QgsSnappingLayerTreeModel* model = new QgsSnappingLayerTreeModel( mProject, this );
model->setLayerTreeModel( new QgsLayerTreeModel( QgsProject::instance()->layerTreeRoot(), model ) );

connect( model, &QgsSnappingLayerTreeModel::rowsInserted, this, &QgsSnappingWidget::onSnappingTreeLayersChanged );
connect( model, &QgsSnappingLayerTreeModel::modelReset, this, &QgsSnappingWidget::onSnappingTreeLayersChanged );
connect( model, &QgsSnappingLayerTreeModel::rowsRemoved, this, &QgsSnappingWidget::onSnappingTreeLayersChanged );

// model->setFlags( 0 );
mLayerTreeView->setModel( model );
mLayerTreeView->resizeColumnToContents( 0 );
mLayerTreeView->header()->show();
mLayerTreeView->header()->setSectionResizeMode( QHeaderView::ResizeToContents );
mLayerTreeView->header()->setSectionResizeMode( QHeaderView::Interactive );
mLayerTreeView->setSelectionMode( QAbstractItemView::NoSelection );

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


// Slightly modify the config so the settings changed code doesn't early exit
mConfig = project->snappingConfig();
mConfig.setEnabled( !mConfig.enabled() );
projectSnapSettingsChanged();

// modeChanged determines if widget are visible or not based on mode
modeChanged();
updateToleranceDecimals();

restoreGeometry( QSettings().value( "/Windows/SnappingWidget/geometry" ).toByteArray() );
}

QgsSnappingWidget::~QgsSnappingWidget()
Expand All @@ -252,7 +263,7 @@ void QgsSnappingWidget::projectSnapSettingsChanged()

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

if ( config.mode() == QgsSnappingConfig::AllLayers && mModeButton->defaultAction() != mActiveLayerAction )
if ( config.mode() == QgsSnappingConfig::AllLayers && mModeButton->defaultAction() != mAllLayersAction )
{
mModeButton->setDefaultAction( mAllLayersAction );
modeChanged();
Expand Down Expand Up @@ -351,6 +362,12 @@ void QgsSnappingWidget::enableIntersectionSnapping( bool enabled )
mProject->setSnappingConfig( mConfig );
}

void QgsSnappingWidget::onSnappingTreeLayersChanged()
{
mLayerTreeView->resizeColumnToContents( 0 );
QTimer::singleShot( 0, mLayerTreeView, &QTreeView::expandAll );
}

void QgsSnappingWidget::modeButtonTriggered( QAction* action )
{
if ( action != mModeButton->defaultAction() )
Expand Down
2 changes: 2 additions & 0 deletions src/app/qgssnappingwidget.h
Expand Up @@ -91,6 +91,8 @@ class APP_EXPORT QgsSnappingWidget : public QWidget
//! number of decimals of the tolerance spin box depends on map units
void updateToleranceDecimals();

void onSnappingTreeLayersChanged();

private:
enum DisplayMode
{
Expand Down
1 change: 1 addition & 0 deletions src/core/qgsproject.cpp
Expand Up @@ -451,6 +451,7 @@ void QgsProject::clear()
mEmbeddedLayers.clear();
mRelationManager->clear();
mSnappingConfig.reset();
emit snappingConfigChanged();

mMapThemeCollection.reset( new QgsMapThemeCollection() );
emit mapThemeCollectionChanged();
Expand Down

0 comments on commit a43f8a3

Please sign in to comment.