Skip to content

Commit

Permalink
Make some member functions const, because they can be
Browse files Browse the repository at this point in the history
Also removes the getDefaultInterval() member function from the .h file
because it is not used and doesn't have an implementation.

And makes an argument a const ptr instead of a non-const ptr, because it
is only used in const context.
  • Loading branch information
joto authored and nyalldawson committed Oct 23, 2021
1 parent eb609b1 commit e4b611d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/app/decorations/qgsdecorationgrid.cpp
Expand Up @@ -513,7 +513,7 @@ int QgsDecorationGrid::yGridLines( const QgsMapSettings &mapSettings, QList< QPa
return 0;
}

QgsDecorationGrid::Border QgsDecorationGrid::borderForLineCoord( QPointF point, QPainter *p ) const
QgsDecorationGrid::Border QgsDecorationGrid::borderForLineCoord( QPointF point, const QPainter *p ) const
{
if ( point.x() <= mGridPen.widthF() )
{
Expand Down Expand Up @@ -572,7 +572,7 @@ void QgsDecorationGrid::setDirty( bool dirty )
}
}

bool QgsDecorationGrid::getIntervalFromExtent( double *values, bool useXAxis )
bool QgsDecorationGrid::getIntervalFromExtent( double *values, bool useXAxis ) const
{
// get default interval from current extents
// calculate a default interval that is approx (extent width)/5, adjusted so that it is a rounded number
Expand Down Expand Up @@ -601,7 +601,7 @@ bool QgsDecorationGrid::getIntervalFromExtent( double *values, bool useXAxis )
return true;
}

bool QgsDecorationGrid::getIntervalFromCurrentLayer( double *values )
bool QgsDecorationGrid::getIntervalFromCurrentLayer( double *values ) const
{
// get current layer and make sure it is a raster layer and CRSs match
QgsMapLayer *layer = QgisApp::instance()->mapCanvas()->currentLayer();
Expand Down
10 changes: 4 additions & 6 deletions src/app/decorations/qgsdecorationgrid.h
Expand Up @@ -126,18 +126,16 @@ class APP_EXPORT QgsDecorationGrid: public QgsDecorationItem

//! Sets map unit type
void setMapUnits( QgsUnitTypes::DistanceUnit t ) { mMapUnits = t; }
QgsUnitTypes::DistanceUnit mapUnits() { return mMapUnits; }
QgsUnitTypes::DistanceUnit mapUnits() const { return mMapUnits; }

//! Sets mapUnits value
void setDirty( bool dirty = true );
bool isDirty();

//! Computes interval that is approx. 1/5 of canvas extent
bool getIntervalFromExtent( double *values, bool useXAxis = true );
bool getIntervalFromExtent( double *values, bool useXAxis = true ) const;
//! Computes interval from current raster layer
bool getIntervalFromCurrentLayer( double *values );

double getDefaultInterval( bool useXAxis = true );
bool getIntervalFromCurrentLayer( double *values ) const;

public slots:
//! Sets values on the gui when a project is read or the gui first loaded
Expand Down Expand Up @@ -214,7 +212,7 @@ class APP_EXPORT QgsDecorationGrid: public QgsDecorationItem
int yGridLines( const QgsMapSettings &mapSettings, QList< QPair< qreal, QLineF > > &lines ) const;

//! Returns the item border of a point (in item coordinates)
Border borderForLineCoord( QPointF point, QPainter *p ) const;
Border borderForLineCoord( QPointF point, const QPainter *p ) const;

QgsTextFormat mTextFormat;
};
Expand Down

0 comments on commit e4b611d

Please sign in to comment.