A bit of const-correctness and new convenience methods for edit tools

This commit is contained in:
Martin Dobias 2017-02-24 11:25:15 +08:00
parent 90ae728294
commit fd616ae94e
14 changed files with 98 additions and 56 deletions

View File

@ -26,7 +26,7 @@ class QgsDatumTransformStore
* @returns transformation associated with layer, or an invalid QgsCoordinateTransform
* if no transform is associated with the layer
*/
QgsCoordinateTransform transformation( QgsMapLayer* layer ) const;
QgsCoordinateTransform transformation( const QgsMapLayer* layer ) const;
void readXml( const QDomNode& parentNode );

View File

@ -177,54 +177,54 @@ class QgsMapSettings
* @param referenceExtent A reference extent based on which to perform the computation. If not specified, the layer extent is used
* @note added in QGIS 2.12
*/
double layerToMapUnits( QgsMapLayer* layer, const QgsRectangle& referenceExtent = QgsRectangle() ) const;
double layerToMapUnits( const QgsMapLayer* layer, const QgsRectangle& referenceExtent = QgsRectangle() ) const;
/**
* @brief transform bounding box from layer's CRS to output CRS
* @see layerToMapCoordinates( QgsMapLayer* layer, QgsRectangle rect ) if you want to transform a rectangle
* @return a bounding box (aligned rectangle) containing the transformed extent
*/
QgsRectangle layerExtentToOutputExtent( QgsMapLayer* layer, QgsRectangle extent ) const;
QgsRectangle layerExtentToOutputExtent( const QgsMapLayer* layer, QgsRectangle extent ) const;
/**
* @brief transform bounding box from output CRS to layer's CRS
* @see mapToLayerCoordinates( QgsMapLayer* layer,QgsRectangle rect ) if you want to transform a rectangle
* @return a bounding box (aligned rectangle) containing the transformed extent
*/
QgsRectangle outputExtentToLayerExtent( QgsMapLayer* layer, QgsRectangle extent ) const;
QgsRectangle outputExtentToLayerExtent( const QgsMapLayer* layer, QgsRectangle extent ) const;
/**
* @brief transform point coordinates from layer's CRS to output CRS
* @return the transformed point
*/
QgsPoint layerToMapCoordinates( QgsMapLayer* layer, QgsPoint point ) const;
QgsPoint layerToMapCoordinates( const QgsMapLayer* layer, QgsPoint point ) const;
/**
* @brief transform rectangle from layer's CRS to output CRS
* @see layerExtentToOutputExtent() if you want to transform a bounding box
* @return the transformed rectangle
*/
QgsRectangle layerToMapCoordinates( QgsMapLayer* layer, QgsRectangle rect ) const;
QgsRectangle layerToMapCoordinates( const QgsMapLayer* layer, QgsRectangle rect ) const;
/**
* @brief transform point coordinates from output CRS to layer's CRS
* @return the transformed point
*/
QgsPoint mapToLayerCoordinates( QgsMapLayer* layer, QgsPoint point ) const;
QgsPoint mapToLayerCoordinates( const QgsMapLayer* layer, QgsPoint point ) const;
/**
* @brief transform rectangle from output CRS to layer's CRS
* @see outputExtentToLayerExtent() if you want to transform a bounding box
* @return the transformed rectangle
*/
QgsRectangle mapToLayerCoordinates( QgsMapLayer* layer, QgsRectangle rect ) const;
QgsRectangle mapToLayerCoordinates( const QgsMapLayer* layer, QgsRectangle rect ) const;
/**
* @brief Return coordinate transform from layer's CRS to destination CRS
* @param layer
* @return transform - may be invalid if the transform is not needed
*/
QgsCoordinateTransform layerTransform( QgsMapLayer *layer ) const;
QgsCoordinateTransform layerTransform( const QgsMapLayer *layer ) const;
//! returns current extent of layer set
QgsRectangle fullExtent() const;

View File

@ -96,6 +96,8 @@ class QgsPointLocator : QObject
//! Only for a valid edge match - obtain endpoints of the edge
void edgePoints( QgsPoint& pt1 /Out/, QgsPoint& pt2 /Out/ ) const;
bool operator==( const QgsPointLocator::Match& other ) const;
};
typedef QList<QgsPointLocator::Match> MatchList;

View File

@ -144,20 +144,20 @@ class QgsMapTool : QObject
QgsPoint toMapCoordinates( QPoint point );
//! transformation from screen coordinates to layer's coordinates
QgsPoint toLayerCoordinates( QgsMapLayer* layer, QPoint point );
QgsPoint toLayerCoordinates( const QgsMapLayer* layer, QPoint point );
//! transformation from map coordinates to layer's coordinates
QgsPoint toLayerCoordinates( QgsMapLayer* layer, const QgsPoint& point );
QgsPoint toLayerCoordinates( const QgsMapLayer* layer, const QgsPoint& point );
//!transformation from layer's coordinates to map coordinates (which is different in case reprojection is used)
QgsPoint toMapCoordinates( QgsMapLayer* layer, const QgsPoint& point );
QgsPoint toMapCoordinates( const QgsMapLayer* layer, const QgsPoint& point );
//!transformation from layer's coordinates to map coordinates (which is different in case reprojection is used)
//! @note available in python bindings as toMapCoordinatesV2
QgsPointV2 toMapCoordinates( QgsMapLayer* layer, const QgsPointV2 &point ) /PyName=toMapCoordinatesV2/;
QgsPointV2 toMapCoordinates( const QgsMapLayer* layer, const QgsPointV2 &point ) /PyName=toMapCoordinatesV2/;
//! trnasformation of the rect from map coordinates to layer's coordinates
QgsRectangle toLayerCoordinates( QgsMapLayer* layer, const QgsRectangle& rect );
QgsRectangle toLayerCoordinates( const QgsMapLayer* layer, const QgsRectangle& rect );
//! transformation from map coordinates to screen coordinates
QPoint toCanvasCoordinates( const QgsPoint& point );

View File

@ -30,6 +30,10 @@ class QgsMapToolEdit: QgsMapTool
double defaultZValue() const;
protected:
static QColor digitizingStrokeColor();
static int digitizingStrokeWidth();
static QColor digitizingFillColor();
/** Creates a rubber band with the color/line width from
* the QGIS settings. The caller takes ownership of the
* returned object

View File

@ -50,7 +50,7 @@ bool QgsDatumTransformStore::hasEntryForLayer( QgsMapLayer* layer ) const
return mEntries.contains( layer->id() );
}
QgsCoordinateTransform QgsDatumTransformStore::transformation( QgsMapLayer* layer ) const
QgsCoordinateTransform QgsDatumTransformStore::transformation( const QgsMapLayer* layer ) const
{
if ( !layer )
return QgsCoordinateTransform();

View File

@ -48,7 +48,7 @@ class CORE_EXPORT QgsDatumTransformStore
* @returns transformation associated with layer, or an invalid QgsCoordinateTransform
* if no transform is associated with the layer
*/
QgsCoordinateTransform transformation( QgsMapLayer* layer ) const;
QgsCoordinateTransform transformation( const QgsMapLayer* layer ) const;
void readXml( const QDomNode& parentNode );

View File

@ -377,13 +377,13 @@ double QgsMapSettings::scale() const
}
QgsCoordinateTransform QgsMapSettings::layerTransform( QgsMapLayer *layer ) const
QgsCoordinateTransform QgsMapSettings::layerTransform( const QgsMapLayer *layer ) const
{
return mDatumTransformStore.transformation( layer );
}
double QgsMapSettings::layerToMapUnits( QgsMapLayer *layer, const QgsRectangle& referenceExtent ) const
double QgsMapSettings::layerToMapUnits( const QgsMapLayer *layer, const QgsRectangle& referenceExtent ) const
{
QgsRectangle extent = referenceExtent.isEmpty() ? layer->extent() : referenceExtent;
QgsPoint l1( extent.xMinimum(), extent.yMinimum() );
@ -396,7 +396,7 @@ double QgsMapSettings::layerToMapUnits( QgsMapLayer *layer, const QgsRectangle&
}
QgsRectangle QgsMapSettings::layerExtentToOutputExtent( QgsMapLayer* layer, QgsRectangle extent ) const
QgsRectangle QgsMapSettings::layerExtentToOutputExtent( const QgsMapLayer* layer, QgsRectangle extent ) const
{
if ( hasCrsTransformEnabled() )
{
@ -423,7 +423,7 @@ QgsRectangle QgsMapSettings::layerExtentToOutputExtent( QgsMapLayer* layer, QgsR
}
QgsRectangle QgsMapSettings::outputExtentToLayerExtent( QgsMapLayer* layer, QgsRectangle extent ) const
QgsRectangle QgsMapSettings::outputExtentToLayerExtent( const QgsMapLayer* layer, QgsRectangle extent ) const
{
if ( hasCrsTransformEnabled() )
{
@ -450,7 +450,7 @@ QgsRectangle QgsMapSettings::outputExtentToLayerExtent( QgsMapLayer* layer, QgsR
}
QgsPoint QgsMapSettings::layerToMapCoordinates( QgsMapLayer* layer, QgsPoint point ) const
QgsPoint QgsMapSettings::layerToMapCoordinates( const QgsMapLayer* layer, QgsPoint point ) const
{
if ( hasCrsTransformEnabled() )
{
@ -473,7 +473,7 @@ QgsPoint QgsMapSettings::layerToMapCoordinates( QgsMapLayer* layer, QgsPoint poi
}
QgsRectangle QgsMapSettings::layerToMapCoordinates( QgsMapLayer* layer, QgsRectangle rect ) const
QgsRectangle QgsMapSettings::layerToMapCoordinates( const QgsMapLayer* layer, QgsRectangle rect ) const
{
if ( hasCrsTransformEnabled() )
{
@ -496,7 +496,7 @@ QgsRectangle QgsMapSettings::layerToMapCoordinates( QgsMapLayer* layer, QgsRecta
}
QgsPoint QgsMapSettings::mapToLayerCoordinates( QgsMapLayer* layer, QgsPoint point ) const
QgsPoint QgsMapSettings::mapToLayerCoordinates( const QgsMapLayer* layer, QgsPoint point ) const
{
if ( hasCrsTransformEnabled() )
{
@ -519,7 +519,7 @@ QgsPoint QgsMapSettings::mapToLayerCoordinates( QgsMapLayer* layer, QgsPoint poi
}
QgsRectangle QgsMapSettings::mapToLayerCoordinates( QgsMapLayer* layer, QgsRectangle rect ) const
QgsRectangle QgsMapSettings::mapToLayerCoordinates( const QgsMapLayer* layer, QgsRectangle rect ) const
{
if ( hasCrsTransformEnabled() )
{

View File

@ -228,54 +228,54 @@ class CORE_EXPORT QgsMapSettings
* @param referenceExtent A reference extent based on which to perform the computation. If not specified, the layer extent is used
* @note added in QGIS 2.12
*/
double layerToMapUnits( QgsMapLayer* layer, const QgsRectangle& referenceExtent = QgsRectangle() ) const;
double layerToMapUnits( const QgsMapLayer* layer, const QgsRectangle& referenceExtent = QgsRectangle() ) const;
/**
* @brief transform bounding box from layer's CRS to output CRS
* @see layerToMapCoordinates( QgsMapLayer* layer, QgsRectangle rect ) if you want to transform a rectangle
* @return a bounding box (aligned rectangle) containing the transformed extent
*/
QgsRectangle layerExtentToOutputExtent( QgsMapLayer* layer, QgsRectangle extent ) const;
QgsRectangle layerExtentToOutputExtent( const QgsMapLayer* layer, QgsRectangle extent ) const;
/**
* @brief transform bounding box from output CRS to layer's CRS
* @see mapToLayerCoordinates( QgsMapLayer* layer,QgsRectangle rect ) if you want to transform a rectangle
* @return a bounding box (aligned rectangle) containing the transformed extent
*/
QgsRectangle outputExtentToLayerExtent( QgsMapLayer* layer, QgsRectangle extent ) const;
QgsRectangle outputExtentToLayerExtent( const QgsMapLayer* layer, QgsRectangle extent ) const;
/**
* @brief transform point coordinates from layer's CRS to output CRS
* @return the transformed point
*/
QgsPoint layerToMapCoordinates( QgsMapLayer* layer, QgsPoint point ) const;
QgsPoint layerToMapCoordinates( const QgsMapLayer* layer, QgsPoint point ) const;
/**
* @brief transform rectangle from layer's CRS to output CRS
* @see layerExtentToOutputExtent() if you want to transform a bounding box
* @return the transformed rectangle
*/
QgsRectangle layerToMapCoordinates( QgsMapLayer* layer, QgsRectangle rect ) const;
QgsRectangle layerToMapCoordinates( const QgsMapLayer* layer, QgsRectangle rect ) const;
/**
* @brief transform point coordinates from output CRS to layer's CRS
* @return the transformed point
*/
QgsPoint mapToLayerCoordinates( QgsMapLayer* layer, QgsPoint point ) const;
QgsPoint mapToLayerCoordinates( const QgsMapLayer* layer, QgsPoint point ) const;
/**
* @brief transform rectangle from output CRS to layer's CRS
* @see outputExtentToLayerExtent() if you want to transform a bounding box
* @return the transformed rectangle
*/
QgsRectangle mapToLayerCoordinates( QgsMapLayer* layer, QgsRectangle rect ) const;
QgsRectangle mapToLayerCoordinates( const QgsMapLayer* layer, QgsRectangle rect ) const;
/**
* @brief Return coordinate transform from layer's CRS to destination CRS
* @param layer
* @return transform - may be invalid if the transform is not needed
*/
QgsCoordinateTransform layerTransform( QgsMapLayer *layer ) const;
QgsCoordinateTransform layerTransform( const QgsMapLayer *layer ) const;
//! returns current extent of layer set
QgsRectangle fullExtent() const;

View File

@ -160,6 +160,17 @@ class CORE_EXPORT QgsPointLocator : public QObject
pt2 = mEdgePoints[1];
}
bool operator==( const Match& other ) const
{
return mType == other.mType &&
mDist == other.mDist &&
mPoint == other.mPoint &&
mLayer == other.mLayer &&
mFid == other.mFid &&
mVertexIndex == other.mVertexIndex &&
mEdgePoints == other.mEdgePoints;
}
protected:
Type mType;
double mDist;

View File

@ -43,30 +43,30 @@ QgsPoint QgsMapTool::toMapCoordinates( QPoint point )
return mCanvas->getCoordinateTransform()->toMapCoordinates( point );
}
QgsPointV2 QgsMapTool::toMapCoordinates( QgsMapLayer* layer, const QgsPointV2& point )
QgsPointV2 QgsMapTool::toMapCoordinates( const QgsMapLayer* layer, const QgsPointV2& point )
{
QgsPoint result = mCanvas->mapSettings().layerToMapCoordinates( layer, QgsPoint( point.x(), point.y() ) );
return QgsPointV2( result.x(), result.y() );
}
QgsPoint QgsMapTool::toLayerCoordinates( QgsMapLayer* layer, QPoint point )
QgsPoint QgsMapTool::toLayerCoordinates( const QgsMapLayer* layer, QPoint point )
{
QgsPoint pt = toMapCoordinates( point );
return toLayerCoordinates( layer, pt );
}
QgsPoint QgsMapTool::toLayerCoordinates( QgsMapLayer* layer, const QgsPoint& point )
QgsPoint QgsMapTool::toLayerCoordinates( const QgsMapLayer* layer, const QgsPoint& point )
{
return mCanvas->mapSettings().mapToLayerCoordinates( layer, point );
}
QgsPoint QgsMapTool::toMapCoordinates( QgsMapLayer* layer, const QgsPoint& point )
QgsPoint QgsMapTool::toMapCoordinates( const QgsMapLayer* layer, const QgsPoint& point )
{
return mCanvas->mapSettings().layerToMapCoordinates( layer, point );
}
QgsRectangle QgsMapTool::toLayerCoordinates( QgsMapLayer* layer, const QgsRectangle& rect )
QgsRectangle QgsMapTool::toLayerCoordinates( const QgsMapLayer* layer, const QgsRectangle& rect )
{
return mCanvas->mapSettings().mapToLayerCoordinates( layer, rect );
}

View File

@ -170,20 +170,20 @@ class GUI_EXPORT QgsMapTool : public QObject
QgsPoint toMapCoordinates( QPoint point );
//! transformation from screen coordinates to layer's coordinates
QgsPoint toLayerCoordinates( QgsMapLayer* layer, QPoint point );
QgsPoint toLayerCoordinates( const QgsMapLayer* layer, QPoint point );
//! transformation from map coordinates to layer's coordinates
QgsPoint toLayerCoordinates( QgsMapLayer* layer, const QgsPoint& point );
QgsPoint toLayerCoordinates( const QgsMapLayer* layer, const QgsPoint& point );
//!transformation from layer's coordinates to map coordinates (which is different in case reprojection is used)
QgsPoint toMapCoordinates( QgsMapLayer* layer, const QgsPoint& point );
QgsPoint toMapCoordinates( const QgsMapLayer* layer, const QgsPoint& point );
//!transformation from layer's coordinates to map coordinates (which is different in case reprojection is used)
//! @note available in python bindings as toMapCoordinatesV2
QgsPointV2 toMapCoordinates( QgsMapLayer* layer, const QgsPointV2 &point );
QgsPointV2 toMapCoordinates( const QgsMapLayer* layer, const QgsPointV2 &point );
//! trnasformation of the rect from map coordinates to layer's coordinates
QgsRectangle toLayerCoordinates( QgsMapLayer* layer, const QgsRectangle& rect );
QgsRectangle toLayerCoordinates( const QgsMapLayer* layer, const QgsRectangle& rect );
//! transformation from map coordinates to screen coordinates
QPoint toCanvasCoordinates( const QgsPoint& point );

View File

@ -34,34 +34,52 @@ double QgsMapToolEdit::defaultZValue() const
return QSettings().value( QStringLiteral( "/qgis/digitizing/default_z_value" ), Qgis::DEFAULT_Z_COORDINATE ).toDouble();
}
QgsRubberBand* QgsMapToolEdit::createRubberBand( QgsWkbTypes::GeometryType geometryType, bool alternativeBand )
QColor QgsMapToolEdit::digitizingStrokeColor()
{
QSettings settings;
QgsRubberBand* rb = new QgsRubberBand( mCanvas, geometryType );
rb->setWidth( settings.value( QStringLiteral( "/qgis/digitizing/line_width" ), 1 ).toInt() );
QColor color(
settings.value( QStringLiteral( "/qgis/digitizing/line_color_red" ), 255 ).toInt(),
settings.value( QStringLiteral( "/qgis/digitizing/line_color_green" ), 0 ).toInt(),
settings.value( QStringLiteral( "/qgis/digitizing/line_color_blue" ), 0 ).toInt() );
double myAlpha = settings.value( QStringLiteral( "/qgis/digitizing/line_color_alpha" ), 200 ).toInt() / 255.0;
if ( alternativeBand )
{
myAlpha = myAlpha * settings.value( QStringLiteral( "/qgis/digitizing/line_color_alpha_scale" ), 0.75 ).toDouble();
rb->setLineStyle( Qt::DotLine );
}
if ( geometryType == QgsWkbTypes::PolygonGeometry )
{
color.setAlphaF( myAlpha );
}
color.setAlphaF( myAlpha );
rb->setColor( color );
return color;
}
int QgsMapToolEdit::digitizingStrokeWidth()
{
QSettings settings;
return settings.value( QStringLiteral( "/qgis/digitizing/line_width" ), 1 ).toInt();
}
QColor QgsMapToolEdit::digitizingFillColor()
{
QSettings settings;
QColor fillColor(
settings.value( QStringLiteral( "/qgis/digitizing/fill_color_red" ), 255 ).toInt(),
settings.value( QStringLiteral( "/qgis/digitizing/fill_color_green" ), 0 ).toInt(),
settings.value( QStringLiteral( "/qgis/digitizing/fill_color_blue" ), 0 ).toInt() );
myAlpha = settings.value( QStringLiteral( "/qgis/digitizing/fill_color_alpha" ), 30 ).toInt() / 255.0 ;
double myAlpha = settings.value( QStringLiteral( "/qgis/digitizing/fill_color_alpha" ), 30 ).toInt() / 255.0 ;
fillColor.setAlphaF( myAlpha );
return fillColor;
}
QgsRubberBand* QgsMapToolEdit::createRubberBand( QgsWkbTypes::GeometryType geometryType, bool alternativeBand )
{
QSettings settings;
QgsRubberBand* rb = new QgsRubberBand( mCanvas, geometryType );
rb->setWidth( digitizingStrokeWidth() );
QColor color = digitizingStrokeColor();
if ( alternativeBand )
{
double alphaScale = settings.value( QStringLiteral( "/qgis/digitizing/line_color_alpha_scale" ), 0.75 ).toDouble();
color.setAlphaF( color.alphaF() * alphaScale );
rb->setLineStyle( Qt::DotLine );
}
rb->setStrokeColor( color );
QColor fillColor = digitizingFillColor();
rb->setFillColor( fillColor );
rb->show();

View File

@ -45,6 +45,13 @@ class GUI_EXPORT QgsMapToolEdit: public QgsMapTool
protected:
//! Returns stroke color for rubber bands (from global settings)
static QColor digitizingStrokeColor();
//! Returns stroke width for rubber bands (from global settings)
static int digitizingStrokeWidth();
//! Returns fill color for rubber bands (from global settings)
static QColor digitizingFillColor();
/** Creates a rubber band with the color/line width from
* the QGIS settings. The caller takes ownership of the
* returned object