void QgsSnappingDialog::apply() { QStringList layerIdList; QStringList snapToList; QStringList toleranceList; QStringList enabledList; QStringList toleranceUnitList; QStringList avoidIntersectionList; for ( int i = 0; i < mLayerTreeWidget->topLevelItemCount(); ++i ) { QTreeWidgetItem *currentItem = mLayerTreeWidget->topLevelItem( i ); if ( !currentItem ) { continue; } layerIdList << currentItem->data( 0, Qt::UserRole ).toString(); enabledList << ( qobject_cast<QCheckBox*>( mLayerTreeWidget->itemWidget( currentItem, 0 ) )->isChecked() ? "enabled" : "disabled" ); QString snapToItemText = qobject_cast<QComboBox*>( mLayerTreeWidget->itemWidget( currentItem, 2 ) )->currentText(); if ( snapToItemText == tr( "to vertex" ) ) { snapToList << "to_vertex"; } else if ( snapToItemText == tr( "to segment" ) ) { snapToList << "to_segment"; } else //to vertex and segment { snapToList << "to_vertex_and_segment"; } toleranceList << QString::number( qobject_cast<QDoubleSpinBox*>( mLayerTreeWidget->itemWidget( currentItem, 3 ) )->value(), 'f' ); toleranceUnitList << QString::number( qobject_cast<QComboBox*>( mLayerTreeWidget->itemWidget( currentItem, 4 ) )->currentIndex() ); QCheckBox *cbxAvoidIntersection = qobject_cast<QCheckBox*>( mLayerTreeWidget->itemWidget( currentItem, 5 ) ); if ( cbxAvoidIntersection && cbxAvoidIntersection->isChecked() ) { avoidIntersectionList << currentItem->data( 0, Qt::UserRole ).toString(); } } QgsProject::instance()->writeEntry( "Digitizing", "/LayerSnappingList", layerIdList ); QgsProject::instance()->writeEntry( "Digitizing", "/LayerSnapToList", snapToList ); QgsProject::instance()->writeEntry( "Digitizing", "/LayerSnappingToleranceList", toleranceList ); QgsProject::instance()->writeEntry( "Digitizing", "/LayerSnappingToleranceUnitList", toleranceUnitList ); QgsProject::instance()->writeEntry( "Digitizing", "/LayerSnappingEnabledList", enabledList ); QgsProject::instance()->writeEntry( "Digitizing", "/AvoidIntersectionsList", avoidIntersectionList ); disconnect( QgsProject::instance(), SIGNAL( snapSettingsChanged() ), this, SLOT( reload() ) ); connect( this, SIGNAL( snapSettingsChanged() ), QgsProject::instance(), SIGNAL( snapSettingsChanged() ) ); emit snapSettingsChanged(); disconnect( this, SIGNAL( snapSettingsChanged() ), QgsProject::instance(), SIGNAL( snapSettingsChanged() ) ); connect( QgsProject::instance(), SIGNAL( snapSettingsChanged() ), this, SLOT( reload() ) ); }
void QgsProject::setSnapSettingsForLayer( const QString& layerId, bool enabled, QgsSnapper::SnappingType type, QgsTolerance::UnitType unit, double tolerance, bool avoidIntersection ) { QStringList layerIdList, enabledList, snapTypeList, toleranceUnitList, toleranceList, avoidIntersectionList; snapSettings( layerIdList, enabledList, snapTypeList, toleranceUnitList, toleranceList, avoidIntersectionList ); int idx = layerIdList.indexOf( layerId ); if ( idx != -1 ) { layerIdList.removeAt( idx ); enabledList.removeAt( idx ); snapTypeList.removeAt( idx ); toleranceUnitList.removeAt( idx ); toleranceList.removeAt( idx ); avoidIntersectionList.removeOne( layerId ); } layerIdList.append( layerId ); //enabled enabledList.append( enabled ? "enabled" : "disabled" ); //snap type QString typeString; if ( type == QgsSnapper::SnapToSegment ) { typeString = "to_segment"; } else if ( type == QgsSnapper::SnapToVertexAndSegment ) { typeString = "to_vertex_and_segment"; } else { typeString = "to_vertex"; } snapTypeList.append( typeString ); //units toleranceUnitList.append( unit == QgsTolerance::Pixels ? "1" : "0" ); //tolerance toleranceList.append( QString::number( tolerance ) ); //avoid intersection if ( avoidIntersection ) { avoidIntersectionList.append( layerId ); } writeEntry( "Digitizing", "/LayerSnappingList", layerIdList ); writeEntry( "Digitizing", "/LayerSnappingEnabledList", enabledList ); writeEntry( "Digitizing", "/LayerSnappingToleranceList", toleranceList ); writeEntry( "Digitizing", "/LayerSnappingToleranceUnitList", toleranceUnitList ); writeEntry( "Digitizing", "/LayerSnapToList", snapTypeList ); writeEntry( "Digitizing", "/AvoidIntersectionsList", avoidIntersectionList ); emit snapSettingsChanged(); }
QgsSnappingDialog::QgsSnappingDialog( QWidget* parent, QgsMapCanvas* canvas ) : QDialog( parent ) , mMapCanvas( canvas ) , mDock( 0 ) { setupUi( this ); QSettings myQsettings; bool myDockFlag = myQsettings.value( "/qgis/dockSnapping", false ).toBool(); if ( myDockFlag ) { mDock = new QgsSnappingDock( tr( "Snapping and Digitizing Options" ), QgisApp::instance() ); mDock->setAllowedAreas( Qt::BottomDockWidgetArea | Qt::TopDockWidgetArea ); mDock->setWidget( this ); connect( this, SIGNAL( destroyed() ), mDock, SLOT( close() ) ); QgisApp::instance()->addDockWidget( Qt::BottomDockWidgetArea, mDock ); mButtonBox->setVisible( false ); } else { connect( mButtonBox, SIGNAL( accepted() ), this, SLOT( apply() ) ); connect( mButtonBox->button( QDialogButtonBox::Apply ), SIGNAL( clicked() ), this, SLOT( apply() ) ); } connect( QgsMapLayerRegistry::instance(), SIGNAL( layersAdded( QList<QgsMapLayer * > ) ), this, SLOT( addLayers( QList<QgsMapLayer * > ) ) ); connect( QgsMapLayerRegistry::instance(), SIGNAL( layersWillBeRemoved( QStringList ) ), this, SLOT( layersWillBeRemoved( QStringList ) ) ); connect( cbxEnableTopologicalEditingCheckBox, SIGNAL( stateChanged( int ) ), this, SLOT( on_cbxEnableTopologicalEditingCheckBox_stateChanged( int ) ) ); connect( cbxEnableIntersectionSnappingCheckBox, SIGNAL( stateChanged( int ) ), this, SLOT( on_cbxEnableIntersectionSnappingCheckBox_stateChanged( int ) ) ); reload(); QMap< QString, QgsMapLayer *> mapLayers = QgsMapLayerRegistry::instance()->mapLayers(); QMap< QString, QgsMapLayer *>::iterator it; for ( it = mapLayers.begin(); it != mapLayers.end() ; ++it ) { addLayer( it.value() ); } mLayerTreeWidget->setHeaderLabels( QStringList() << "" ); mLayerTreeWidget->resizeColumnToContents( 0 ); mLayerTreeWidget->setColumnWidth( 1, 200 ); //hardcoded for now mLayerTreeWidget->setColumnWidth( 2, 200 ); //hardcoded for now mLayerTreeWidget->resizeColumnToContents( 3 ); mLayerTreeWidget->resizeColumnToContents( 4 ); mLayerTreeWidget->setSortingEnabled( true ); connect( QgsProject::instance(), SIGNAL( snapSettingsChanged() ), this, SLOT( reload() ) ); }
void QgsProject::setTopologicalEditing( bool enabled ) { QgsProject::instance()->writeEntry( "Digitizing", "/TopologicalEditing", ( enabled ? 1 : 0 ) ); emit snapSettingsChanged(); }