Skip to content
Permalink
Browse files

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

  • Loading branch information
wonder-sk committed Feb 24, 2017
1 parent 90ae728 commit fd616ae94effd12eace2c345564354d8fb1c93fc
@@ -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 );

@@ -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;
@@ -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;
@@ -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 );
@@ -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
@@ -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();
@@ -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 );

@@ -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() )
{
@@ -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;
@@ -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;
@@ -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 );
}
@@ -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 );

0 comments on commit fd616ae

Please sign in to comment.
You can’t perform that action at this time.