Skip to content
Permalink
Browse files

Add option for grid snap tolerance, move selection tolerance spin box…

… to new section (fix #8214)
  • Loading branch information
nyalldawson committed Sep 25, 2013
1 parent 64885d9 commit d7db4a53cb2c0930c13319c13b5c186645a01aef
@@ -108,6 +108,7 @@ QgsCompositionWidget::QgsCompositionWidget( QWidget* parent, QgsComposition* c )
}

mSelectionToleranceSpinBox->setValue( mComposition->selectionTolerance() );
mGridToleranceSpinBox->setValue( mComposition->snapGridTolerance() );
}
blockSignals( false );
}
@@ -561,6 +562,14 @@ void QgsCompositionWidget::on_mGridStyleComboBox_currentIndexChanged( const QStr
}
}

void QgsCompositionWidget::on_mGridToleranceSpinBox_valueChanged( double d )
{
if ( mComposition )
{
mComposition->setSnapGridTolerance( d );
}
}

void QgsCompositionWidget::on_mSelectionToleranceSpinBox_valueChanged( double d )
{
if ( mComposition )
@@ -601,6 +610,7 @@ void QgsCompositionWidget::blockSignals( bool block )
mOffsetYSpinBox->blockSignals( block );
mGridColorButton->blockSignals( block );
mGridStyleComboBox->blockSignals( block );
mGridToleranceSpinBox->blockSignals( block );
mSelectionToleranceSpinBox->blockSignals( block );
mAlignmentSnapGroupCheckBox->blockSignals( block );
mAlignmentToleranceSpinBox->blockSignals( block );
@@ -59,6 +59,7 @@ class QgsCompositionWidget: public QWidget, private Ui::QgsCompositionWidgetBase
void on_mOffsetYSpinBox_valueChanged( double d );
void on_mGridColorButton_colorChanged( const QColor &newColor );
void on_mGridStyleComboBox_currentIndexChanged( const QString& text );
void on_mGridToleranceSpinBox_valueChanged( double d );
void on_mSelectionToleranceSpinBox_valueChanged( double d );
void on_mAlignmentSnapGroupCheckBox_toggled( bool state );
void on_mAlignmentToleranceSpinBox_valueChanged( double d );
@@ -60,6 +60,7 @@ QgsComposition::QgsComposition( QgsMapRenderer* mapRenderer )
, mSelectionTolerance( 0.0 )
, mSnapToGrid( false )
, mSnapGridResolution( 10.0 )
, mSnapGridTolerance( 2 )
, mSnapGridOffsetX( 0.0 )
, mSnapGridOffsetY( 0.0 )
, mAlignmentSnap( true )
@@ -89,6 +90,7 @@ QgsComposition::QgsComposition()
mSelectionTolerance( 0.0 ),
mSnapToGrid( false ),
mSnapGridResolution( 10.0 ),
mSnapGridTolerance( 2 ),
mSnapGridOffsetX( 0.0 ),
mSnapGridOffsetY( 0.0 ),
mAlignmentSnap( true ),
@@ -405,6 +407,7 @@ bool QgsComposition::writeXML( QDomElement& composerElem, QDomDocument& doc )
compositionElem.setAttribute( "snapping", "0" );
}
compositionElem.setAttribute( "snapGridResolution", QString::number( mSnapGridResolution ) );
compositionElem.setAttribute( "snapGridTolerance", QString::number( mSnapGridTolerance ) );
compositionElem.setAttribute( "snapGridOffsetX", QString::number( mSnapGridOffsetX ) );
compositionElem.setAttribute( "snapGridOffsetY", QString::number( mSnapGridOffsetY ) );

@@ -493,6 +496,7 @@ bool QgsComposition::readXML( const QDomElement& compositionElem, const QDomDocu
mSnapToGrid = true;
}
mSnapGridResolution = compositionElem.attribute( "snapGridResolution" ).toDouble();
mSnapGridTolerance = compositionElem.attribute( "snapGridTolerance", "2.0" ).toDouble();
mSnapGridOffsetX = compositionElem.attribute( "snapGridOffsetX" ).toDouble();
mSnapGridOffsetY = compositionElem.attribute( "snapGridOffsetY" ).toDouble();

@@ -1213,7 +1217,21 @@ QPointF QgsComposition::snapPointToGrid( const QPointF& scenePoint ) const
int xRatio = ( int )(( scenePoint.x() - mSnapGridOffsetX ) / mSnapGridResolution + 0.5 );
int yRatio = ( int )(( yPage - mSnapGridOffsetY ) / mSnapGridResolution + 0.5 );

return QPointF( xRatio * mSnapGridResolution + mSnapGridOffsetX, yRatio * mSnapGridResolution + mSnapGridOffsetY + yOffset );
double xSnapped = xRatio * mSnapGridResolution + mSnapGridOffsetX;
double ySnapped = yRatio * mSnapGridResolution + mSnapGridOffsetY + yOffset;

if ( abs( xSnapped - scenePoint.x() ) > mSnapGridTolerance )
{
//snap distance is outside of tolerance
xSnapped = scenePoint.x();
}
if ( abs( ySnapped - scenePoint.y() ) > mSnapGridTolerance )
{
//snap distance is outside of tolerance
ySnapped = scenePoint.y();
}

return QPointF( xSnapped, ySnapped );
}

QPointF QgsComposition::alignItem( const QgsComposerItem* item, double& alignX, double& alignY, double dx, double dy )
@@ -1474,6 +1492,12 @@ void QgsComposition::setSnapGridResolution( double r )
saveSettings();
}

void QgsComposition::setSnapGridTolerance( double tolerance )
{
mSnapGridTolerance = tolerance;
saveSettings();
}

void QgsComposition::setSnapGridOffsetX( double offset )
{
mSnapGridOffsetX = offset;
@@ -107,6 +107,9 @@ class CORE_EXPORT QgsComposition : public QGraphicsScene
void setSnapGridResolution( double r );
double snapGridResolution() const {return mSnapGridResolution;}

void setSnapGridTolerance( double tolerance );
double snapGridTolerance() const {return mSnapGridTolerance;}

void setSnapGridOffsetX( double offset );
double snapGridOffsetX() const {return mSnapGridOffsetX;}

@@ -407,6 +410,7 @@ class CORE_EXPORT QgsComposition : public QGraphicsScene
/**Parameters for snap to grid function*/
bool mSnapToGrid;
double mSnapGridResolution;
double mSnapGridTolerance;
double mSnapGridOffsetX;
double mSnapGridOffsetY;
QPen mGridPen;
@@ -285,6 +285,38 @@
</layout>
</widget>
</item>
<item>
<widget class="QgsCollapsibleGroupBoxBasic" name="generalSettingsGroupBox">
<property name="title">
<string>General settings</string>
</property>
<property name="collapsed" stdset="0">
<bool>false</bool>
</property>
<layout class="QFormLayout" name="formLayout_2">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
</property>
<property name="labelAlignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
<item row="0" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Selection tolerance</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QDoubleSpinBox" name="mSelectionToleranceSpinBox">
<property name="suffix">
<string> mm</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QgsCollapsibleGroupBoxBasic" name="mSnapToGridGroupCheckBox">
<property name="title">
@@ -395,21 +427,24 @@
<item row="4" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Selection tolerance</string>
<string>Tolerance</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QDoubleSpinBox" name="mSelectionToleranceSpinBox">
<widget class="QDoubleSpinBox" name="mGridToleranceSpinBox">
<property name="prefix">
<string/>
</property>
<property name="suffix">
<string> mm</string>
</property>
<property name="value">
<double>2.000000000000000</double>
</property>
</widget>
</item>
</layout>

0 comments on commit d7db4a5

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