Skip to content
Permalink
Browse files
[FEATURE]: allow item selection tolerance in composer (default is 0)
  • Loading branch information
mhugent committed Nov 25, 2011
1 parent 34f4ab6 commit e386ae49021356f2b6f2a6e1445ffe103ab14c4b
@@ -79,6 +79,9 @@ class QgsComposition: QGraphicsScene
bool printAsRaster() const;
void setPrintAsRaster(bool enabled);

double selectionTolerance() const;
void setSelectionTolerance( double tol );

/**Returns pointer to map renderer of qgis map canvas*/
QgsMapRenderer* mapRenderer();

@@ -91,6 +91,8 @@ QgsCompositionWidget::QgsCompositionWidget( QWidget* parent, QgsComposition* c )
{
mGridStyleComboBox->setCurrentIndex( 2 );
}

mSelectionToleranceSpinBox->setValue( mComposition->selectionTolerance() );
}
blockSignals( false );
}
@@ -503,6 +505,14 @@ void QgsCompositionWidget::on_mPenWidthSpinBox_valueChanged( double d )
}
}

void QgsCompositionWidget::on_mSelectionToleranceSpinBox_valueChanged( double d )
{
if ( mComposition )
{
mComposition->setSelectionTolerance( d );
}
}

void QgsCompositionWidget::blockSignals( bool block )
{
mPaperSizeComboBox->blockSignals( block );
@@ -519,4 +529,5 @@ void QgsCompositionWidget::blockSignals( bool block )
mPenWidthSpinBox->blockSignals( block );
mGridColorButton->blockSignals( block );
mGridStyleComboBox->blockSignals( block );
mSelectionToleranceSpinBox->blockSignals( block );
}
@@ -55,6 +55,8 @@ class QgsCompositionWidget: public QWidget, private Ui::QgsCompositionWidgetBase
void on_mGridColorButton_clicked();
void on_mGridStyleComboBox_currentIndexChanged( const QString& text );
void on_mPenWidthSpinBox_valueChanged( double d );
void on_mSelectionToleranceSpinBox_valueChanged( double d );

/**Sets GUI elements to width/height from composition*/
void displayCompositionWidthHeight();

@@ -296,6 +296,11 @@ void QgsComposerItem::mouseMoveEvent( QGraphicsSceneMouseEvent * event )
return;
}

if ( !isSelected() )
{
return;
}

if ( mBoundingResizeRectangle )
{
double diffX = event->lastScenePos().x() - mLastMouseEventPos.x();
@@ -313,6 +318,11 @@ void QgsComposerItem::mousePressEvent( QGraphicsSceneMouseEvent * event )
return;
}

if ( !isSelected() )
{
return;
}

//set current position and type of mouse move action
mMouseMoveStartPos = event->lastScenePos();
mLastMouseEventPos = event->lastScenePos();
@@ -347,6 +357,11 @@ void QgsComposerItem::mouseReleaseEvent( QGraphicsSceneMouseEvent * event )
return;
}

if ( !isSelected() )
{
return;
}

//delete frame rectangle
if ( mBoundingResizeRectangle )
{
@@ -728,6 +743,10 @@ void QgsComposerItem::hoverMoveEvent( QGraphicsSceneHoverEvent * event )
{
setCursor( cursorForPosition( event->pos() ) );
}
else
{
setCursor( Qt::ArrowCursor );
}
}

void QgsComposerItem::drawText( QPainter* p, double x, double y, const QString& text, const QFont& font ) const
@@ -25,8 +25,8 @@
#include <QSettings>

QgsComposition::QgsComposition( QgsMapRenderer* mapRenderer ):
QGraphicsScene( 0 ), mMapRenderer( mapRenderer ), mPlotStyle( QgsComposition::Preview ), mPaperItem( 0 ), mPrintAsRaster( false ), mSnapToGrid( false ),
mSnapGridResolution( 0.0 ), mSnapGridOffsetX( 0.0 ), mSnapGridOffsetY( 0.0 ), mActiveCommand( 0 )
QGraphicsScene( 0 ), mMapRenderer( mapRenderer ), mPlotStyle( QgsComposition::Preview ), mPaperItem( 0 ), mPrintAsRaster( false ), mSelectionTolerance( 0.0 ),
mSnapToGrid( false ), mSnapGridResolution( 0.0 ), mSnapGridOffsetX( 0.0 ), mSnapGridOffsetY( 0.0 ), mActiveCommand( 0 )
{
setBackgroundBrush( Qt::gray );

@@ -36,14 +36,14 @@ QgsComposition::QgsComposition( QgsMapRenderer* mapRenderer ):
addItem( mPaperItem );
mPaperItem->setZValue( 0 );
mPrintResolution = 300; //hardcoded default
loadGridAppearanceSettings();
loadSettings();
}

QgsComposition::QgsComposition():
QGraphicsScene( 0 ), mMapRenderer( 0 ), mPlotStyle( QgsComposition::Preview ), mPaperItem( 0 ), mPrintAsRaster( false ),
mSnapToGrid( false ), mSnapGridResolution( 0.0 ), mSnapGridOffsetX( 0.0 ), mSnapGridOffsetY( 0.0 ), mActiveCommand( 0 )
mSelectionTolerance( 0.0 ), mSnapToGrid( false ), mSnapGridResolution( 0.0 ), mSnapGridOffsetX( 0.0 ), mSnapGridOffsetY( 0.0 ), mActiveCommand( 0 )
{
loadGridAppearanceSettings();
loadSettings();
}

QgsComposition::~QgsComposition()
@@ -77,7 +77,16 @@ double QgsComposition::paperWidth() const

QgsComposerItem* QgsComposition::composerItemAt( const QPointF & position )
{
QList<QGraphicsItem *> itemList = items( position );
QList<QGraphicsItem*> itemList;
if ( mSelectionTolerance <= 0.0 )
{
itemList = items( position );
}
else
{
itemList = items( QRectF( position.x() - mSelectionTolerance, position.y() - mSelectionTolerance, 2 * mSelectionTolerance, 2 * mSelectionTolerance ),
Qt::IntersectsItemShape, Qt::DescendingOrder );
}
QList<QGraphicsItem *>::iterator itemIt = itemList.begin();

for ( ; itemIt != itemList.end(); ++itemIt )
@@ -663,6 +672,7 @@ void QgsComposition::setSnapToGridEnabled( bool b )
{
mPaperItem->update();
}
saveSettings();
}

void QgsComposition::setSnapGridResolution( double r )
@@ -672,6 +682,7 @@ void QgsComposition::setSnapGridResolution( double r )
{
mPaperItem->update();
}
saveSettings();
}

void QgsComposition::setSnapGridOffsetX( double offset )
@@ -681,6 +692,7 @@ void QgsComposition::setSnapGridOffsetX( double offset )
{
mPaperItem->update();
}
saveSettings();
}

void QgsComposition::setSnapGridOffsetY( double offset )
@@ -690,6 +702,7 @@ void QgsComposition::setSnapGridOffsetY( double offset )
{
mPaperItem->update();
}
saveSettings();
}

void QgsComposition::setGridPen( const QPen& p )
@@ -699,7 +712,7 @@ void QgsComposition::setGridPen( const QPen& p )
{
mPaperItem->update();
}
saveGridAppearanceSettings();
saveSettings();
}

void QgsComposition::setGridStyle( GridStyle s )
@@ -709,10 +722,16 @@ void QgsComposition::setGridStyle( GridStyle s )
{
mPaperItem->update();
}
saveGridAppearanceSettings();
saveSettings();
}

void QgsComposition::setSelectionTolerance( double tol )
{
mSelectionTolerance = tol;
saveSettings();
}

void QgsComposition::loadGridAppearanceSettings()
void QgsComposition::loadSettings()
{
//read grid style, grid color and pen width from settings
QSettings s;
@@ -742,9 +761,11 @@ void QgsComposition::loadGridAppearanceSettings()
{
mGridStyle = Solid;
}

mSelectionTolerance = s.value( "/qgis/composerSelectionTolerance", 0.0 ).toDouble();
}

void QgsComposition::saveGridAppearanceSettings()
void QgsComposition::saveSettings()
{
//store grid appearance settings
QSettings s;
@@ -765,6 +786,9 @@ void QgsComposition::saveGridAppearanceSettings()
{
s.setValue( "/qgis/composerGridStyle", "Crosses" );
}

//store also selection tolerance
s.setValue( "/qgis/composerSelectionTolerance", mSelectionTolerance );
}

void QgsComposition::beginCommand( QgsComposerItem* item, const QString& commandText, QgsComposerMergeCommand::Context c )
@@ -109,6 +109,9 @@ class CORE_EXPORT QgsComposition: public QGraphicsScene
bool printAsRaster() const {return mPrintAsRaster;}
void setPrintAsRaster( bool enabled ) { mPrintAsRaster = enabled; }

double selectionTolerance() const { return mSelectionTolerance; }
void setSelectionTolerance( double tol );

/**Returns pointer to map renderer of qgis map canvas*/
QgsMapRenderer* mapRenderer() {return mMapRenderer;}

@@ -186,6 +189,9 @@ class CORE_EXPORT QgsComposition: public QGraphicsScene
/**Flag if map should be printed as a raster (via QImage). False by default*/
bool mPrintAsRaster;

/**Distance tolerance for item selection (in mm)*/
double mSelectionTolerance;

/**Parameters for snap to grid function*/
bool mSnapToGrid;
double mSnapGridResolution;
@@ -207,8 +213,8 @@ class CORE_EXPORT QgsComposition: public QGraphicsScene
@return 0 in case of success*/
int boundingRectOfSelectedItems( QRectF& bRect );

void loadGridAppearanceSettings();
void saveGridAppearanceSettings();
void loadSettings();
void saveSettings();

signals:
void paperSizeChanged();
@@ -32,8 +32,8 @@
<property name="geometry">
<rect>
<x>0</x>
<y>-11</y>
<width>397</width>
<y>0</y>
<width>395</width>
<height>579</height>
</rect>
</property>
@@ -281,6 +281,13 @@
<item row="8" column="0">
<widget class="QComboBox" name="mGridStyleComboBox"/>
</item>
<item row="9" column="0">
<widget class="QDoubleSpinBox" name="mSelectionToleranceSpinBox">
<property name="prefix">
<string>Selection tolerance (mm) </string>
</property>
</widget>
</item>
</layout>
</widget>
</item>

0 comments on commit e386ae4

Please sign in to comment.