25
25
#include < QSettings>
26
26
27
27
QgsComposition::QgsComposition ( QgsMapRenderer* mapRenderer ):
28
- QGraphicsScene( 0 ), mMapRenderer( mapRenderer ), mPlotStyle( QgsComposition::Preview ), mPaperItem( 0 ), mPrintAsRaster( false ), mSnapToGrid( false ),
29
- mSnapGridResolution( 0.0 ), mSnapGridOffsetX( 0.0 ), mSnapGridOffsetY( 0.0 ), mActiveCommand( 0 )
28
+ QGraphicsScene( 0 ), mMapRenderer( mapRenderer ), mPlotStyle( QgsComposition::Preview ), mPaperItem( 0 ), mPrintAsRaster( false ), mSelectionTolerance( 0.0 ),
29
+ mSnapToGrid( false ), mSnapGridResolution( 0.0 ), mSnapGridOffsetX( 0.0 ), mSnapGridOffsetY( 0.0 ), mActiveCommand( 0 )
30
30
{
31
31
setBackgroundBrush ( Qt::gray );
32
32
@@ -36,14 +36,14 @@ QgsComposition::QgsComposition( QgsMapRenderer* mapRenderer ):
36
36
addItem ( mPaperItem );
37
37
mPaperItem ->setZValue ( 0 );
38
38
mPrintResolution = 300 ; // hardcoded default
39
- loadGridAppearanceSettings ();
39
+ loadSettings ();
40
40
}
41
41
42
42
QgsComposition::QgsComposition ():
43
43
QGraphicsScene( 0 ), mMapRenderer( 0 ), mPlotStyle( QgsComposition::Preview ), mPaperItem( 0 ), mPrintAsRaster( false ),
44
- mSnapToGrid( false ), mSnapGridResolution( 0.0 ), mSnapGridOffsetX( 0.0 ), mSnapGridOffsetY( 0.0 ), mActiveCommand( 0 )
44
+ mSelectionTolerance( 0.0 ), mSnapToGrid( false ), mSnapGridResolution( 0.0 ), mSnapGridOffsetX( 0.0 ), mSnapGridOffsetY( 0.0 ), mActiveCommand( 0 )
45
45
{
46
- loadGridAppearanceSettings ();
46
+ loadSettings ();
47
47
}
48
48
49
49
QgsComposition::~QgsComposition ()
@@ -77,7 +77,16 @@ double QgsComposition::paperWidth() const
77
77
78
78
QgsComposerItem* QgsComposition::composerItemAt ( const QPointF & position )
79
79
{
80
- QList<QGraphicsItem *> itemList = items ( position );
80
+ QList<QGraphicsItem*> itemList;
81
+ if ( mSelectionTolerance <= 0.0 )
82
+ {
83
+ itemList = items ( position );
84
+ }
85
+ else
86
+ {
87
+ itemList = items ( QRectF ( position.x () - mSelectionTolerance , position.y () - mSelectionTolerance , 2 * mSelectionTolerance , 2 * mSelectionTolerance ),
88
+ Qt::IntersectsItemShape, Qt::DescendingOrder );
89
+ }
81
90
QList<QGraphicsItem *>::iterator itemIt = itemList.begin ();
82
91
83
92
for ( ; itemIt != itemList.end (); ++itemIt )
@@ -663,6 +672,7 @@ void QgsComposition::setSnapToGridEnabled( bool b )
663
672
{
664
673
mPaperItem ->update ();
665
674
}
675
+ saveSettings ();
666
676
}
667
677
668
678
void QgsComposition::setSnapGridResolution ( double r )
@@ -672,6 +682,7 @@ void QgsComposition::setSnapGridResolution( double r )
672
682
{
673
683
mPaperItem ->update ();
674
684
}
685
+ saveSettings ();
675
686
}
676
687
677
688
void QgsComposition::setSnapGridOffsetX ( double offset )
@@ -681,6 +692,7 @@ void QgsComposition::setSnapGridOffsetX( double offset )
681
692
{
682
693
mPaperItem ->update ();
683
694
}
695
+ saveSettings ();
684
696
}
685
697
686
698
void QgsComposition::setSnapGridOffsetY ( double offset )
@@ -690,6 +702,7 @@ void QgsComposition::setSnapGridOffsetY( double offset )
690
702
{
691
703
mPaperItem ->update ();
692
704
}
705
+ saveSettings ();
693
706
}
694
707
695
708
void QgsComposition::setGridPen ( const QPen& p )
@@ -699,7 +712,7 @@ void QgsComposition::setGridPen( const QPen& p )
699
712
{
700
713
mPaperItem ->update ();
701
714
}
702
- saveGridAppearanceSettings ();
715
+ saveSettings ();
703
716
}
704
717
705
718
void QgsComposition::setGridStyle ( GridStyle s )
@@ -709,10 +722,16 @@ void QgsComposition::setGridStyle( GridStyle s )
709
722
{
710
723
mPaperItem ->update ();
711
724
}
712
- saveGridAppearanceSettings ();
725
+ saveSettings ();
726
+ }
727
+
728
+ void QgsComposition::setSelectionTolerance ( double tol )
729
+ {
730
+ mSelectionTolerance = tol;
731
+ saveSettings ();
713
732
}
714
733
715
- void QgsComposition::loadGridAppearanceSettings ()
734
+ void QgsComposition::loadSettings ()
716
735
{
717
736
// read grid style, grid color and pen width from settings
718
737
QSettings s;
@@ -742,9 +761,11 @@ void QgsComposition::loadGridAppearanceSettings()
742
761
{
743
762
mGridStyle = Solid;
744
763
}
764
+
765
+ mSelectionTolerance = s.value ( " /qgis/composerSelectionTolerance" , 0.0 ).toDouble ();
745
766
}
746
767
747
- void QgsComposition::saveGridAppearanceSettings ()
768
+ void QgsComposition::saveSettings ()
748
769
{
749
770
// store grid appearance settings
750
771
QSettings s;
@@ -765,6 +786,9 @@ void QgsComposition::saveGridAppearanceSettings()
765
786
{
766
787
s.setValue ( " /qgis/composerGridStyle" , " Crosses" );
767
788
}
789
+
790
+ // store also selection tolerance
791
+ s.setValue ( " /qgis/composerSelectionTolerance" , mSelectionTolerance );
768
792
}
769
793
770
794
void QgsComposition::beginCommand ( QgsComposerItem* item, const QString& commandText, QgsComposerMergeCommand::Context c )
0 commit comments