Skip to content

Commit

Permalink
identify and other map tools changed to use search radius in mm
Browse files Browse the repository at this point in the history
  • Loading branch information
blazek committed Mar 26, 2014
1 parent f68e47f commit aefc892
Show file tree
Hide file tree
Showing 12 changed files with 79 additions and 44 deletions.
9 changes: 1 addition & 8 deletions src/app/qgsmaptoolfeatureaction.cpp
Expand Up @@ -103,13 +103,6 @@ bool QgsMapToolFeatureAction::doAction( QgsVectorLayer *layer, int x, int y )

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

// load identify radius from settings
QSettings settings;
double identifyValue = settings.value( "/Map/identifyRadius", QGis::DEFAULT_IDENTIFY_RADIUS ).toDouble();

if ( identifyValue <= 0.0 )
identifyValue = QGis::DEFAULT_IDENTIFY_RADIUS;

QgsFeatureList featList;

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

QgsRectangle r;
r.setXMinimum( point.x() - searchRadius );
Expand Down
8 changes: 4 additions & 4 deletions src/app/qgsoptions.cpp
Expand Up @@ -113,11 +113,11 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WFlags fl ) :
int identifyMode = settings.value( "/Map/identifyMode", 0 ).toInt();
cmbIdentifyMode->setCurrentIndex( cmbIdentifyMode->findData( identifyMode ) );
cbxAutoFeatureForm->setChecked( settings.value( "/Map/identifyAutoFeatureForm", false ).toBool() );
double identifyValue = settings.value( "/Map/identifyRadius", QGis::DEFAULT_IDENTIFY_RADIUS ).toDouble();
double identifyValue = settings.value( "/Map/searchRadiusMM", QGis::DEFAULT_SEARCH_RADIUS_MM ).toDouble();
QgsDebugMsg( QString( "Standard Identify radius setting read from settings file: %1" ).arg( identifyValue ) );
if ( identifyValue <= 0.0 )
identifyValue = QGis::DEFAULT_IDENTIFY_RADIUS;
spinBoxIdentifyValue->setMinimum( 0.01 );
identifyValue = QGis::DEFAULT_SEARCH_RADIUS_MM;
spinBoxIdentifyValue->setMinimum( 0.0 );
spinBoxIdentifyValue->setValue( identifyValue );
QColor highlightColor = QColor( settings.value( "/Map/identify/highlight/color", "#ff0000" ).toString() );
int highlightAlpha = settings.value( "/Map/identify/highlight/colorAlpha", "63" ).toInt();
Expand Down Expand Up @@ -1045,7 +1045,7 @@ void QgsOptions::saveOptions()
//general settings
settings.setValue( "/Map/identifyMode", cmbIdentifyMode->itemData( cmbIdentifyMode->currentIndex() ).toInt() );
settings.setValue( "/Map/identifyAutoFeatureForm", cbxAutoFeatureForm->isChecked() );
settings.setValue( "/Map/identifyRadius", spinBoxIdentifyValue->value() );
settings.setValue( "/Map/searchRadiusMM", spinBoxIdentifyValue->value() );
settings.setValue( "/Map/identify/highlight/color", mIdentifyHighlightColorButton->color().name() );
settings.setValue( "/Map/identify/highlight/colorAlpha", mIdentifyHighlightColorButton->color().alpha() );
settings.setValue( "/Map/identify/highlight/buffer", mIdentifyHighlightBufferSpinBox->value() );
Expand Down
1 change: 1 addition & 0 deletions src/core/qgis.cpp
Expand Up @@ -72,6 +72,7 @@ const CORE_EXPORT QString GEO_EPSG_CRS_AUTHID = "EPSG:4326";
const CORE_EXPORT QString GEO_NONE = "NONE";

const double QGis::DEFAULT_IDENTIFY_RADIUS = 0.5;
const double QGis::DEFAULT_SEARCH_RADIUS_MM = 2.;

//! Default threshold between map coordinates and device coordinates for map2pixel simplification
const float QGis::DEFAULT_MAPTOPIXEL_THRESHOLD = 1.0f;
Expand Down
18 changes: 12 additions & 6 deletions src/core/qgis.h
Expand Up @@ -264,8 +264,14 @@ class CORE_EXPORT QGis
ProviderCountCalcEvent
};

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

/** Identify search radius in mm
* @note added in 2.3 */
static const double DEFAULT_SEARCH_RADIUS_MM;

//! Default threshold between map coordinates and device coordinates for map2pixel simplification
static const float DEFAULT_MAPTOPIXEL_THRESHOLD;

Expand Down Expand Up @@ -406,16 +412,16 @@ typedef unsigned long long qgssize;

#if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) || defined(__clang__)
#define Q_NOWARN_DEPRECATED_PUSH \
_Pragma("GCC diagnostic push") \
_Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
_Pragma("GCC diagnostic push") \
_Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
#define Q_NOWARN_DEPRECATED_POP \
_Pragma("GCC diagnostic pop")
_Pragma("GCC diagnostic pop")
#elif defined(_MSC_VER)
#define Q_NOWARN_DEPRECATED_PUSH \
__pragma(warning(push)) \
__pragma(warning(disable:4996))
__pragma(warning(push)) \
__pragma(warning(disable:4996))
#define Q_NOWARN_DEPRECATED_POP \
__pragma(warning(pop))
__pragma(warning(pop))
#else
#define Q_NOWARN_DEPRECATED_PUSH
#define Q_NOWARN_DEPRECATED_POP
Expand Down
5 changes: 2 additions & 3 deletions src/gui/qgsformannotationitem.cpp
Expand Up @@ -21,6 +21,7 @@
#include "qgslogger.h"
#include "qgsmapcanvas.h"
#include "qgsmaplayerregistry.h"
#include "qgsmaptool.h"
#include "qgsvectorlayer.h"
#include <QDomElement>
#include <QDir>
Expand Down Expand Up @@ -225,9 +226,7 @@ void QgsFormAnnotationItem::setFeatureForMapPosition()
return;
}

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

Expand Down
4 changes: 2 additions & 2 deletions src/gui/qgshtmlannotationitem.cpp
Expand Up @@ -21,6 +21,7 @@
#include "qgslogger.h"
#include "qgsmapcanvas.h"
#include "qgsmaplayerregistry.h"
#include "qgsmaptool.h"
#include "qgsvectorlayer.h"
#include "qgsexpression.h"

Expand Down Expand Up @@ -189,8 +190,7 @@ void QgsHtmlAnnotationItem::setFeatureForMapPosition()
}

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

Expand Down
8 changes: 2 additions & 6 deletions src/gui/qgsmaptip.cpp
Expand Up @@ -14,6 +14,7 @@
***************************************************************************/
// QGIS includes
#include "qgsmapcanvas.h"
#include "qgsmaptool.h"
#include "qgsvectorlayer.h"
#include "qgsexpression.h"
#include "qgslogger.h"
Expand Down Expand Up @@ -78,12 +79,7 @@ QString QgsMapTip::fetchFeature( QgsMapLayer *layer, QgsPoint &mapPosition, QgsM
if ( !vlayer )
return "";

// Get the setting for the search radius from user preferences, if it exists
QSettings settings;
double identifyValue = settings.value( "/Map/identifyRadius", QGis::DEFAULT_IDENTIFY_RADIUS ).toDouble();

// create the search rectangle
double searchRadius = mpMapCanvas->extent().width() * ( identifyValue / 100.0 );
double searchRadius = QgsMapTool::searchRadiusMU( mpMapCanvas );

QgsRectangle r;
r.setXMinimum( mapPosition.x() - searchRadius );
Expand Down
29 changes: 29 additions & 0 deletions src/gui/qgsmaptool.cpp
Expand Up @@ -18,6 +18,7 @@
#include "qgsmapcanvas.h"
#include "qgsmaptopixel.h"
#include "qgsmaprenderer.h"
#include "qgsrendercontext.h"
#include <QAction>
#include <QAbstractButton>

Expand Down Expand Up @@ -182,3 +183,31 @@ QgsMapCanvas* QgsMapTool::canvas()
{
return mCanvas;
}

double QgsMapTool::searchRadiusMM()
{
QSettings settings;
double radius = settings.value( "/Map/searchRadiusMM", QGis::DEFAULT_SEARCH_RADIUS_MM ).toDouble();

if ( radius > 0 )
{
return radius;
}
return QGis::DEFAULT_SEARCH_RADIUS_MM;
}

double QgsMapTool::searchRadiusMU( const QgsRenderContext& context )
{
return searchRadiusMM() * context.scaleFactor() * context.mapToPixel().mapUnitsPerPixel();
}

double QgsMapTool::searchRadiusMU( QgsMapCanvas * canvas )
{
if ( !canvas )
{
return 0;
}
QgsMapSettings mapSettings = canvas->mapSettings();
QgsRenderContext context = QgsRenderContext::fromMapSettings( mapSettings );
return searchRadiusMU( context );
}
17 changes: 17 additions & 0 deletions src/gui/qgsmaptool.h
Expand Up @@ -29,6 +29,7 @@

class QgsMapLayer;
class QgsMapCanvas;
class QgsRenderContext;
class QKeyEvent;
class QMouseEvent;
class QWheelEvent;
Expand Down Expand Up @@ -129,6 +130,22 @@ class GUI_EXPORT QgsMapTool : public QObject
//! @note added in 2.3
QString toolName() { return mToolName; }

/** Get search radius in mm. Used by identify, tip etc.
* The values is currently set in identify tool options (move somewhere else?)
* and defaults to QGis::DEFAULT_SEARCH_RADIUS_MM.
* @note added in 2.3 */
static double searchRadiusMM();

/** Get search radius in map units for given context. Used by identify, tip etc.
* The values is calculated from searchRadiusMM().
* @note added in 2.3 */
static double searchRadiusMU( const QgsRenderContext& context );

/** Get search radius in map units for given canvas. Used by identify, tip etc.
* The values is calculated from searchRadiusMM().
* @note added in 2.3 */
static double searchRadiusMU( QgsMapCanvas * canvas );

signals:
//! emit a message
void messageEmitted( QString message, QgsMessageBar::MessageLevel = QgsMessageBar::INFO );
Expand Down
9 changes: 1 addition & 8 deletions src/gui/qgsmaptoolidentify.cpp
Expand Up @@ -265,13 +265,6 @@ bool QgsMapToolIdentify::identifyVectorLayer( QList<IdentifyResult> *results, Qg

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

// load identify radius from settings
QSettings settings;
double identifyValue = settings.value( "/Map/identifyRadius", QGis::DEFAULT_IDENTIFY_RADIUS ).toDouble();

if ( identifyValue <= 0.0 )
identifyValue = QGis::DEFAULT_IDENTIFY_RADIUS;

int featureCount = 0;

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

QgsRectangle r;
r.setXMinimum( point.x() - searchRadius );
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/evis/idtool/eviseventidtool.cpp
Expand Up @@ -28,6 +28,7 @@

#include "qgscursors.h"
#include "qgsmaptopixel.h"
#include "qgsmaptool.h"
#include "qgsvectorlayer.h"
#include "qgsvectordataprovider.h"

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

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

QgsRectangle myRectangle;
myRectangle.setXMinimum( thePoint.x( ) - searchWidth );
Expand Down
12 changes: 6 additions & 6 deletions src/ui/qgsoptionsbase.ui
Expand Up @@ -248,7 +248,7 @@
<item>
<widget class="QStackedWidget" name="mOptionsStackedWidget">
<property name="currentIndex">
<number>0</number>
<number>5</number>
</property>
<widget class="QWidget" name="mOptionsPageGeneral">
<layout class="QVBoxLayout" name="verticalLayout_3">
Expand Down Expand Up @@ -931,7 +931,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>610</width>
<width>630</width>
<height>867</height>
</rect>
</property>
Expand Down Expand Up @@ -1604,7 +1604,7 @@
<x>0</x>
<y>0</y>
<width>669</width>
<height>744</height>
<height>724</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_29">
Expand Down Expand Up @@ -2602,16 +2602,16 @@
<item>
<widget class="QDoubleSpinBox" name="spinBoxIdentifyValue">
<property name="suffix">
<string> %</string>
<string> mm</string>
</property>
<property name="maximum">
<double>100.000000000000000</double>
</property>
<property name="singleStep">
<double>0.010000000000000</double>
<double>1.000000000000000</double>
</property>
<property name="value">
<double>5.000000000000000</double>
<double>2.000000000000000</double>
</property>
</widget>
</item>
Expand Down

0 comments on commit aefc892

Please sign in to comment.