Skip to content
Permalink
Browse files

Merge branch 'snap_interface'

  • Loading branch information
mhugent committed Jun 20, 2012
2 parents b86498a + 6188322 commit 2ef84ccce927f375c5f653976d631a6050bc7587
Showing with 185 additions and 2 deletions.
  1. +10 −0 python/core/qgsproject.sip
  2. +16 −2 src/app/qgssnappingdialog.cpp
  3. +3 −0 src/app/qgssnappingdialog.h
  4. +137 −0 src/core/qgsproject.cpp
  5. +19 −0 src/core/qgsproject.h
@@ -240,6 +240,14 @@ public:
@note added in 1.4 */
void setBadLayerHandler( QgsProjectBadLayerHandler* handler );

void setSnapSettingsForLayer( const QString& layerId, bool enabled, QgsSnapper::SnappingType type, QgsTolerance::UnitType unit, double tolerance, bool avoidIntersection );

bool snapSettingsForLayer( const QString& layerId, bool& enabled /Out/, QgsSnapper::SnappingType& type /Out/, QgsTolerance::UnitType& units /Out/, double& tolerance /Out/,
bool& avoidIntersection /Out/ );

void setTopologicalEditing( bool enabled );
bool topologicalEditing() const;

protected:

/** Set error message from read/write operation
@@ -258,6 +266,8 @@ public:
//! emitted when project is being written
void writeProject(QDomDocument &);

void snapSettingsChanged();

private:

QgsProject(); // private 'cause it's a singleton
@@ -73,7 +73,7 @@ QgsSnappingDialog::QgsSnappingDialog( QWidget* parent, QgsMapCanvas* canvas ): Q
connect( QgsMapLayerRegistry::instance(), SIGNAL( layersWillBeRemoved( QStringList ) ), this, SLOT( layersWillBeRemoved( QStringList ) ) );
connect( cbxEnableTopologicalEditingCheckBox, SIGNAL( stateChanged( int ) ), this, SLOT( on_cbxEnableTopologicalEditingCheckBox_stateChanged( int ) ) );

mLayerTreeWidget->clear();
reload();

QMap< QString, QgsMapLayer *> mapLayers = QgsMapLayerRegistry::instance()->mapLayers();
QMap< QString, QgsMapLayer *>::iterator it;
@@ -90,7 +90,7 @@ QgsSnappingDialog::QgsSnappingDialog( QWidget* parent, QgsMapCanvas* canvas ): Q
mLayerTreeWidget->resizeColumnToContents( 4 );
mLayerTreeWidget->setSortingEnabled( true );

setTopologicalEditingState();
connect( QgsProject::instance(), SIGNAL( snapSettingsChanged() ), this, SLOT( reload() ) );
}

QgsSnappingDialog::QgsSnappingDialog()
@@ -101,6 +101,20 @@ QgsSnappingDialog::~QgsSnappingDialog()
{
}

void QgsSnappingDialog::reload()
{
mLayerTreeWidget->clear();

QMap< QString, QgsMapLayer *> mapLayers = QgsMapLayerRegistry::instance()->mapLayers();
QMap< QString, QgsMapLayer *>::iterator it;
for ( it = mapLayers.begin(); it != mapLayers.end() ; ++it )
{
addLayer( it.value() );
}

setTopologicalEditingState();
}

void QgsSnappingDialog::on_cbxEnableTopologicalEditingCheckBox_stateChanged( int state )
{
int topologicalEditingEnabled = ( state == Qt::Checked ) ? 1 : 0;
@@ -67,6 +67,9 @@ class QgsSnappingDialog: public QDialog, private Ui::QgsSnappingDialogBase
*/
void closeEvent( QCloseEvent* event );

private slots:
void reload();


private:
/**Default constructor forbidden*/
@@ -1621,7 +1621,144 @@ bool QgsProject::createEmbeddedLayer( const QString& layerId, const QString& pro
return false;
}

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();
}

bool QgsProject::snapSettingsForLayer( const QString& layerId, bool& enabled, QgsSnapper::SnappingType &type, QgsTolerance::UnitType& units, double& tolerance,
bool& avoidIntersection ) const
{
QStringList layerIdList, enabledList, snapTypeList, toleranceUnitList, toleranceList, avoidIntersectionList;
snapSettings( layerIdList, enabledList, snapTypeList, toleranceUnitList, toleranceList, avoidIntersectionList );
int idx = layerIdList.indexOf( layerId );
if ( idx == -1 )
{
return false;
}

//make sure all lists are long enough
int minListEntries = idx + 1;
if ( layerIdList.size() < minListEntries || enabledList.size() < minListEntries || snapTypeList.size() < minListEntries ||
toleranceUnitList.size() < minListEntries || toleranceList.size() < minListEntries )
{
return false;
}

//enabled
enabled = enabledList.at( idx ) == "enabled";

//snap type
QString snapType = snapTypeList.at( idx );
if ( snapType == "to_segment" )
{
type = QgsSnapper::SnapToSegment;
}
else if ( snapType == "to_vertex_and_segment" )
{
type = QgsSnapper::SnapToVertexAndSegment;
}
else //to vertex
{
type = QgsSnapper::SnapToVertex;
}

//units
if ( toleranceUnitList.at( idx ) == "1" )
{
units = QgsTolerance::Pixels;
}
else
{
units = QgsTolerance::MapUnits;
}

//tolerance
tolerance = toleranceList.at( idx ).toDouble();

//avoid intersection
avoidIntersection = ( avoidIntersectionList.indexOf( layerId ) != -1 );

return true;
}

void QgsProject::snapSettings( QStringList& layerIdList, QStringList& enabledList, QStringList& snapTypeList, QStringList& toleranceUnitList, QStringList& toleranceList,
QStringList& avoidIntersectionList ) const
{
layerIdList = readListEntry( "Digitizing", "/LayerSnappingList" );
enabledList = readListEntry( "Digitizing", "/LayerSnappingEnabledList" );
toleranceList = readListEntry( "Digitizing", "/LayerSnappingToleranceList" );
toleranceUnitList = readListEntry( "Digitizing", "/LayerSnappingToleranceUnitList" );
snapTypeList = readListEntry( "Digitizing", "/LayerSnapToList" );
avoidIntersectionList = readListEntry( "Digitizing", "/AvoidIntersectionsList" );
}

void QgsProject::setTopologicalEditing( bool enabled )
{
QgsProject::instance()->writeEntry( "Digitizing", "/TopologicalEditing", ( enabled ? 1 : 0 ) );
emit snapSettingsChanged();
}

bool QgsProject::topologicalEditing() const
{
return ( QgsProject::instance()->readNumEntry( "Digitizing", "/TopologicalEditing", 0 ) > 0 );
}

void QgsProjectBadLayerDefaultHandler::handleBadLayers( QList<QDomNode> /*layers*/, QDomDocument /*projectDom*/ )
{
// just ignore any bad layers
}


@@ -28,6 +28,10 @@
#include <QObject>
#include <QPair>

//for the snap settings
#include "qgssnapper.h"
#include "qgstolerance.h"

//#include <QDomDocument>

class QFileInfo;
@@ -286,6 +290,16 @@ class CORE_EXPORT QgsProject : public QObject
bool createEmbeddedLayer( const QString& layerId, const QString& projectFilePath, QList<QDomNode>& brokenNodes,
QList< QPair< QgsVectorLayer*, QDomElement > >& vectorLayerList, bool saveFlag = true );

//convenience interface for querying / modifying the project snap settings per layer
void setSnapSettingsForLayer( const QString& layerId, bool enabled, QgsSnapper::SnappingType type, QgsTolerance::UnitType unit, double tolerance,
bool avoidIntersection );

bool snapSettingsForLayer( const QString& layerId, bool& enabled, QgsSnapper::SnappingType& type, QgsTolerance::UnitType& units, double& tolerance,
bool& avoidIntersection ) const;

void setTopologicalEditing( bool enabled );
bool topologicalEditing() const;

protected:

/** Set error message from read/write operation
@@ -315,6 +329,8 @@ class CORE_EXPORT QgsProject : public QObject
// @param n number of layers
void layerLoaded( int i, int n );

void snapSettingsChanged();

private:

QgsProject(); // private 'cause it's a singleton
@@ -339,6 +355,9 @@ class CORE_EXPORT QgsProject : public QObject
If the project file path is empty, QgsProject is going to ignore the layer for saving (e.g. because it is part and managed by an embedded group)*/
QHash< QString, QPair< QString, bool> > mEmbeddedLayers;

void snapSettings( QStringList& layerIdList, QStringList& enabledList, QStringList& snapTypeList, QStringList& snapUnitList, QStringList& toleranceUnitList,
QStringList& avoidIntersectionList ) const;

}; // QgsProject


0 comments on commit 2ef84cc

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