Skip to content

Commit aefc892

Browse files
committedMar 26, 2014
identify and other map tools changed to use search radius in mm
1 parent f68e47f commit aefc892

12 files changed

+79
-44
lines changed
 

‎src/app/qgsmaptoolfeatureaction.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,6 @@ bool QgsMapToolFeatureAction::doAction( QgsVectorLayer *layer, int x, int y )
103103

104104
QgsPoint point = mCanvas->getCoordinateTransform()->toMapCoordinates( x, y );
105105

106-
// load identify radius from settings
107-
QSettings settings;
108-
double identifyValue = settings.value( "/Map/identifyRadius", QGis::DEFAULT_IDENTIFY_RADIUS ).toDouble();
109-
110-
if ( identifyValue <= 0.0 )
111-
identifyValue = QGis::DEFAULT_IDENTIFY_RADIUS;
112-
113106
QgsFeatureList featList;
114107

115108
// toLayerCoordinates will throw an exception for an 'invalid' point.
@@ -118,7 +111,7 @@ bool QgsMapToolFeatureAction::doAction( QgsVectorLayer *layer, int x, int y )
118111
try
119112
{
120113
// create the search rectangle
121-
double searchRadius = mCanvas->extent().width() * ( identifyValue / 100.0 );
114+
double searchRadius = searchRadiusMU( mCanvas );
122115

123116
QgsRectangle r;
124117
r.setXMinimum( point.x() - searchRadius );

‎src/app/qgsoptions.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,11 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WFlags fl ) :
113113
int identifyMode = settings.value( "/Map/identifyMode", 0 ).toInt();
114114
cmbIdentifyMode->setCurrentIndex( cmbIdentifyMode->findData( identifyMode ) );
115115
cbxAutoFeatureForm->setChecked( settings.value( "/Map/identifyAutoFeatureForm", false ).toBool() );
116-
double identifyValue = settings.value( "/Map/identifyRadius", QGis::DEFAULT_IDENTIFY_RADIUS ).toDouble();
116+
double identifyValue = settings.value( "/Map/searchRadiusMM", QGis::DEFAULT_SEARCH_RADIUS_MM ).toDouble();
117117
QgsDebugMsg( QString( "Standard Identify radius setting read from settings file: %1" ).arg( identifyValue ) );
118118
if ( identifyValue <= 0.0 )
119-
identifyValue = QGis::DEFAULT_IDENTIFY_RADIUS;
120-
spinBoxIdentifyValue->setMinimum( 0.01 );
119+
identifyValue = QGis::DEFAULT_SEARCH_RADIUS_MM;
120+
spinBoxIdentifyValue->setMinimum( 0.0 );
121121
spinBoxIdentifyValue->setValue( identifyValue );
122122
QColor highlightColor = QColor( settings.value( "/Map/identify/highlight/color", "#ff0000" ).toString() );
123123
int highlightAlpha = settings.value( "/Map/identify/highlight/colorAlpha", "63" ).toInt();
@@ -1045,7 +1045,7 @@ void QgsOptions::saveOptions()
10451045
//general settings
10461046
settings.setValue( "/Map/identifyMode", cmbIdentifyMode->itemData( cmbIdentifyMode->currentIndex() ).toInt() );
10471047
settings.setValue( "/Map/identifyAutoFeatureForm", cbxAutoFeatureForm->isChecked() );
1048-
settings.setValue( "/Map/identifyRadius", spinBoxIdentifyValue->value() );
1048+
settings.setValue( "/Map/searchRadiusMM", spinBoxIdentifyValue->value() );
10491049
settings.setValue( "/Map/identify/highlight/color", mIdentifyHighlightColorButton->color().name() );
10501050
settings.setValue( "/Map/identify/highlight/colorAlpha", mIdentifyHighlightColorButton->color().alpha() );
10511051
settings.setValue( "/Map/identify/highlight/buffer", mIdentifyHighlightBufferSpinBox->value() );

‎src/core/qgis.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ const CORE_EXPORT QString GEO_EPSG_CRS_AUTHID = "EPSG:4326";
7272
const CORE_EXPORT QString GEO_NONE = "NONE";
7373

7474
const double QGis::DEFAULT_IDENTIFY_RADIUS = 0.5;
75+
const double QGis::DEFAULT_SEARCH_RADIUS_MM = 2.;
7576

7677
//! Default threshold between map coordinates and device coordinates for map2pixel simplification
7778
const float QGis::DEFAULT_MAPTOPIXEL_THRESHOLD = 1.0f;

‎src/core/qgis.h

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -264,8 +264,14 @@ class CORE_EXPORT QGis
264264
ProviderCountCalcEvent
265265
};
266266

267+
/** Old search radius in % of canvas width
268+
* @deprecated since 2.3, use DEFAULT_SEARCH_RADIUS_MM */
267269
static const double DEFAULT_IDENTIFY_RADIUS;
268270

271+
/** Identify search radius in mm
272+
* @note added in 2.3 */
273+
static const double DEFAULT_SEARCH_RADIUS_MM;
274+
269275
//! Default threshold between map coordinates and device coordinates for map2pixel simplification
270276
static const float DEFAULT_MAPTOPIXEL_THRESHOLD;
271277

@@ -406,16 +412,16 @@ typedef unsigned long long qgssize;
406412

407413
#if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) || defined(__clang__)
408414
#define Q_NOWARN_DEPRECATED_PUSH \
409-
_Pragma("GCC diagnostic push") \
410-
_Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
415+
_Pragma("GCC diagnostic push") \
416+
_Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
411417
#define Q_NOWARN_DEPRECATED_POP \
412-
_Pragma("GCC diagnostic pop")
418+
_Pragma("GCC diagnostic pop")
413419
#elif defined(_MSC_VER)
414420
#define Q_NOWARN_DEPRECATED_PUSH \
415-
__pragma(warning(push)) \
416-
__pragma(warning(disable:4996))
421+
__pragma(warning(push)) \
422+
__pragma(warning(disable:4996))
417423
#define Q_NOWARN_DEPRECATED_POP \
418-
__pragma(warning(pop))
424+
__pragma(warning(pop))
419425
#else
420426
#define Q_NOWARN_DEPRECATED_PUSH
421427
#define Q_NOWARN_DEPRECATED_POP

‎src/gui/qgsformannotationitem.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "qgslogger.h"
2222
#include "qgsmapcanvas.h"
2323
#include "qgsmaplayerregistry.h"
24+
#include "qgsmaptool.h"
2425
#include "qgsvectorlayer.h"
2526
#include <QDomElement>
2627
#include <QDir>
@@ -225,9 +226,7 @@ void QgsFormAnnotationItem::setFeatureForMapPosition()
225226
return;
226227
}
227228

228-
QSettings settings;
229-
double identifyValue = settings.value( "/Map/identifyRadius", QGis::DEFAULT_IDENTIFY_RADIUS ).toDouble();
230-
double halfIdentifyWidth = mMapCanvas->extent().width() / 100 / 2 * identifyValue;
229+
double halfIdentifyWidth = QgsMapTool::searchRadiusMU( mMapCanvas );
231230
QgsRectangle searchRect( mMapPosition.x() - halfIdentifyWidth, mMapPosition.y() - halfIdentifyWidth,
232231
mMapPosition.x() + halfIdentifyWidth, mMapPosition.y() + halfIdentifyWidth );
233232

‎src/gui/qgshtmlannotationitem.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "qgslogger.h"
2222
#include "qgsmapcanvas.h"
2323
#include "qgsmaplayerregistry.h"
24+
#include "qgsmaptool.h"
2425
#include "qgsvectorlayer.h"
2526
#include "qgsexpression.h"
2627

@@ -189,8 +190,7 @@ void QgsHtmlAnnotationItem::setFeatureForMapPosition()
189190
}
190191

191192
QSettings settings;
192-
double identifyValue = settings.value( "/Map/identifyRadius", QGis::DEFAULT_IDENTIFY_RADIUS ).toDouble();
193-
double halfIdentifyWidth = mMapCanvas->extent().width() / 100 / 2 * identifyValue;
193+
double halfIdentifyWidth = QgsMapTool::searchRadiusMU( mMapCanvas );
194194
QgsRectangle searchRect( mMapPosition.x() - halfIdentifyWidth, mMapPosition.y() - halfIdentifyWidth,
195195
mMapPosition.x() + halfIdentifyWidth, mMapPosition.y() + halfIdentifyWidth );
196196

‎src/gui/qgsmaptip.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
***************************************************************************/
1515
// QGIS includes
1616
#include "qgsmapcanvas.h"
17+
#include "qgsmaptool.h"
1718
#include "qgsvectorlayer.h"
1819
#include "qgsexpression.h"
1920
#include "qgslogger.h"
@@ -78,12 +79,7 @@ QString QgsMapTip::fetchFeature( QgsMapLayer *layer, QgsPoint &mapPosition, QgsM
7879
if ( !vlayer )
7980
return "";
8081

81-
// Get the setting for the search radius from user preferences, if it exists
82-
QSettings settings;
83-
double identifyValue = settings.value( "/Map/identifyRadius", QGis::DEFAULT_IDENTIFY_RADIUS ).toDouble();
84-
85-
// create the search rectangle
86-
double searchRadius = mpMapCanvas->extent().width() * ( identifyValue / 100.0 );
82+
double searchRadius = QgsMapTool::searchRadiusMU( mpMapCanvas );
8783

8884
QgsRectangle r;
8985
r.setXMinimum( mapPosition.x() - searchRadius );

‎src/gui/qgsmaptool.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "qgsmapcanvas.h"
1919
#include "qgsmaptopixel.h"
2020
#include "qgsmaprenderer.h"
21+
#include "qgsrendercontext.h"
2122
#include <QAction>
2223
#include <QAbstractButton>
2324

@@ -182,3 +183,31 @@ QgsMapCanvas* QgsMapTool::canvas()
182183
{
183184
return mCanvas;
184185
}
186+
187+
double QgsMapTool::searchRadiusMM()
188+
{
189+
QSettings settings;
190+
double radius = settings.value( "/Map/searchRadiusMM", QGis::DEFAULT_SEARCH_RADIUS_MM ).toDouble();
191+
192+
if ( radius > 0 )
193+
{
194+
return radius;
195+
}
196+
return QGis::DEFAULT_SEARCH_RADIUS_MM;
197+
}
198+
199+
double QgsMapTool::searchRadiusMU( const QgsRenderContext& context )
200+
{
201+
return searchRadiusMM() * context.scaleFactor() * context.mapToPixel().mapUnitsPerPixel();
202+
}
203+
204+
double QgsMapTool::searchRadiusMU( QgsMapCanvas * canvas )
205+
{
206+
if ( !canvas )
207+
{
208+
return 0;
209+
}
210+
QgsMapSettings mapSettings = canvas->mapSettings();
211+
QgsRenderContext context = QgsRenderContext::fromMapSettings( mapSettings );
212+
return searchRadiusMU( context );
213+
}

‎src/gui/qgsmaptool.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
class QgsMapLayer;
3131
class QgsMapCanvas;
32+
class QgsRenderContext;
3233
class QKeyEvent;
3334
class QMouseEvent;
3435
class QWheelEvent;
@@ -129,6 +130,22 @@ class GUI_EXPORT QgsMapTool : public QObject
129130
//! @note added in 2.3
130131
QString toolName() { return mToolName; }
131132

133+
/** Get search radius in mm. Used by identify, tip etc.
134+
* The values is currently set in identify tool options (move somewhere else?)
135+
* and defaults to QGis::DEFAULT_SEARCH_RADIUS_MM.
136+
* @note added in 2.3 */
137+
static double searchRadiusMM();
138+
139+
/** Get search radius in map units for given context. Used by identify, tip etc.
140+
* The values is calculated from searchRadiusMM().
141+
* @note added in 2.3 */
142+
static double searchRadiusMU( const QgsRenderContext& context );
143+
144+
/** Get search radius in map units for given canvas. Used by identify, tip etc.
145+
* The values is calculated from searchRadiusMM().
146+
* @note added in 2.3 */
147+
static double searchRadiusMU( QgsMapCanvas * canvas );
148+
132149
signals:
133150
//! emit a message
134151
void messageEmitted( QString message, QgsMessageBar::MessageLevel = QgsMessageBar::INFO );

‎src/gui/qgsmaptoolidentify.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -265,13 +265,6 @@ bool QgsMapToolIdentify::identifyVectorLayer( QList<IdentifyResult> *results, Qg
265265

266266
commonDerivedAttributes.insert( tr( "(clicked coordinate)" ), point.toString() );
267267

268-
// load identify radius from settings
269-
QSettings settings;
270-
double identifyValue = settings.value( "/Map/identifyRadius", QGis::DEFAULT_IDENTIFY_RADIUS ).toDouble();
271-
272-
if ( identifyValue <= 0.0 )
273-
identifyValue = QGis::DEFAULT_IDENTIFY_RADIUS;
274-
275268
int featureCount = 0;
276269

277270
QgsFeatureList featureList;
@@ -282,7 +275,7 @@ bool QgsMapToolIdentify::identifyVectorLayer( QList<IdentifyResult> *results, Qg
282275
try
283276
{
284277
// create the search rectangle
285-
double searchRadius = mCanvas->extent().width() * ( identifyValue / 100.0 );
278+
double searchRadius = searchRadiusMU( mCanvas );
286279

287280
QgsRectangle r;
288281
r.setXMinimum( point.x() - searchRadius );

‎src/plugins/evis/idtool/eviseventidtool.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
#include "qgscursors.h"
3030
#include "qgsmaptopixel.h"
31+
#include "qgsmaptool.h"
3132
#include "qgsvectorlayer.h"
3233
#include "qgsvectordataprovider.h"
3334

@@ -94,7 +95,7 @@ void eVisEventIdTool::select( QgsPoint thePoint )
9495
QgsVectorLayer* myLayer = ( QgsVectorLayer* )mCanvas->currentLayer( );
9596

9697
// create the search rectangle. this was modeled after the QgsMapIdentifyTool in core QGIS application
97-
double searchWidth = mCanvas->extent( ).width( ) * (( double )QGis::DEFAULT_IDENTIFY_RADIUS / 100.0 );
98+
double searchWidth = QgsMapTool::searchRadiusMU( mCanvas );
9899

99100
QgsRectangle myRectangle;
100101
myRectangle.setXMinimum( thePoint.x( ) - searchWidth );

‎src/ui/qgsoptionsbase.ui

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@
248248
<item>
249249
<widget class="QStackedWidget" name="mOptionsStackedWidget">
250250
<property name="currentIndex">
251-
<number>0</number>
251+
<number>5</number>
252252
</property>
253253
<widget class="QWidget" name="mOptionsPageGeneral">
254254
<layout class="QVBoxLayout" name="verticalLayout_3">
@@ -931,7 +931,7 @@
931931
<rect>
932932
<x>0</x>
933933
<y>0</y>
934-
<width>610</width>
934+
<width>630</width>
935935
<height>867</height>
936936
</rect>
937937
</property>
@@ -1604,7 +1604,7 @@
16041604
<x>0</x>
16051605
<y>0</y>
16061606
<width>669</width>
1607-
<height>744</height>
1607+
<height>724</height>
16081608
</rect>
16091609
</property>
16101610
<layout class="QVBoxLayout" name="verticalLayout_29">
@@ -2602,16 +2602,16 @@
26022602
<item>
26032603
<widget class="QDoubleSpinBox" name="spinBoxIdentifyValue">
26042604
<property name="suffix">
2605-
<string> %</string>
2605+
<string> mm</string>
26062606
</property>
26072607
<property name="maximum">
26082608
<double>100.000000000000000</double>
26092609
</property>
26102610
<property name="singleStep">
2611-
<double>0.010000000000000</double>
2611+
<double>1.000000000000000</double>
26122612
</property>
26132613
<property name="value">
2614-
<double>5.000000000000000</double>
2614+
<double>2.000000000000000</double>
26152615
</property>
26162616
</widget>
26172617
</item>

0 commit comments

Comments
 (0)
Please sign in to comment.