Skip to content

Commit

Permalink
Add option for grid snap tolerance, move selection tolerance spin box…
Browse files Browse the repository at this point in the history
… to new section (fix #8214)
  • Loading branch information
nyalldawson committed Sep 26, 2013
1 parent 64885d9 commit d7db4a5
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 3 deletions.
10 changes: 10 additions & 0 deletions src/app/composer/qgscompositionwidget.cpp
Expand Up @@ -108,6 +108,7 @@ QgsCompositionWidget::QgsCompositionWidget( QWidget* parent, QgsComposition* c )
}

mSelectionToleranceSpinBox->setValue( mComposition->selectionTolerance() );
mGridToleranceSpinBox->setValue( mComposition->snapGridTolerance() );
}
blockSignals( false );
}
Expand Down Expand Up @@ -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 )
Expand Down Expand Up @@ -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 );
Expand Down
1 change: 1 addition & 0 deletions src/app/composer/qgscompositionwidget.h
Expand Up @@ -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 );
Expand Down
26 changes: 25 additions & 1 deletion src/core/composer/qgscomposition.cpp
Expand Up @@ -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 )
Expand Down Expand Up @@ -89,6 +90,7 @@ QgsComposition::QgsComposition()
mSelectionTolerance( 0.0 ),
mSnapToGrid( false ),
mSnapGridResolution( 10.0 ),
mSnapGridTolerance( 2 ),
mSnapGridOffsetX( 0.0 ),
mSnapGridOffsetY( 0.0 ),
mAlignmentSnap( true ),
Expand Down Expand Up @@ -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 ) );

Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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 )
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions src/core/composer/qgscomposition.h
Expand Up @@ -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;}

Expand Down Expand Up @@ -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;
Expand Down
39 changes: 37 additions & 2 deletions src/ui/qgscompositionwidgetbase.ui
Expand Up @@ -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">
Expand Down Expand Up @@ -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>
Expand Down

0 comments on commit d7db4a5

Please sign in to comment.