Skip to content

Commit

Permalink
Rename some static variables for consistency
Browse files Browse the repository at this point in the history
Ensure non-const statics have "s" prefix and const statics
are in all caps
  • Loading branch information
nyalldawson committed Jan 12, 2017
1 parent 3705ff1 commit b7706b3
Show file tree
Hide file tree
Showing 44 changed files with 212 additions and 223 deletions.
4 changes: 2 additions & 2 deletions python/core/symbology-ng/qgsgraduatedsymbolrenderer.sip
Expand Up @@ -76,8 +76,8 @@ class QgsRendererRangeLabelFormat
void setFromDomElement( QDomElement &element );
void saveToDomElement( QDomElement &element );

static int MaxPrecision;
static int MinPrecision;
static const int MaxPrecision;

This comment has been minimized.

Copy link
@m-kuhn

m-kuhn Jan 12, 2017

Member

Shouldn't that be all-caps?

static const int MinPrecision;

};

Expand Down
4 changes: 2 additions & 2 deletions src/analysis/interpolation/DualEdgeTriangulation.cc
Expand Up @@ -487,7 +487,7 @@ int DualEdgeTriangulation::baseEdgeOfTriangle( Point3D* point )

while ( true )
{
if ( runs > nBaseOfRuns )//prevents endless loops
if ( runs > sNumBaseOfRuns )//prevents endless loops
{
// QgsDebugMsg("warning, probable endless loop detected");
return -100;
Expand Down Expand Up @@ -2606,7 +2606,7 @@ bool DualEdgeTriangulation::pointInside( double x, double y )

while ( true )
{
if ( runs > nBaseOfRuns )//prevents endless loops
if ( runs > sNumBaseOfRuns )//prevents endless loops
{
QgsDebugMsg( QString( "warning, instability detected: Point coordinates: %1//%2" ).arg( x ).arg( y ) );
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/analysis/interpolation/DualEdgeTriangulation.h
Expand Up @@ -140,7 +140,7 @@ class ANALYSIS_EXPORT DualEdgeTriangulation: public Triangulation
//! Threshold for the leftOfTest to handle numerical instabilities
//const static double leftOfTresh=0.00001;
//! Security to prevent endless loops in 'baseEdgeOfTriangle'. It there are more iteration then this number, the point will not be inserted
const static int nBaseOfRuns = 300000;
const static int sNumBaseOfRuns = 300000;
//! Returns the number of an edge which points to the point with number 'point' or -1 if there is an error
int baseEdgeOfPoint( int point );
//! Returns the number of a HalfEdge from a triangle in which 'point' is in. If the number -10 is returned, this means, that 'point' is outside the convex hull. If -5 is returned, then numerical problems with the leftOfTest occurred (and the value of the possible edge is stored in the variable 'mUnstableEdge'. -20 means, that the inserted point is exactly on an edge (the number is stored in the variable 'mEdgeWithPoint'). -25 means, that the point is already in the triangulation (the number of the point is stored in the member 'mTwiceInsPoint'. If -100 is returned, this means that something else went wrong
Expand Down
20 changes: 9 additions & 11 deletions src/app/qgsdecorationnortharrow.cpp
Expand Up @@ -42,8 +42,6 @@ email : tim@linfiniti.com
#include <cmath>
#include <cassert>


const double QgsDecorationNorthArrow::PI = 3.14159265358979323846;
// const double QgsNorthArrowPlugin::DEG2RAD = 0.0174532925199433;
const double QgsDecorationNorthArrow::TOL = 1e-8;

Expand Down Expand Up @@ -124,7 +122,7 @@ void QgsDecorationNorthArrow::render( QPainter * theQPainter )
if ( mAutomatic )
calculateNorthDirection();

double myRadiansDouble = mRotationInt * PI / 180.0;
double myRadiansDouble = mRotationInt * M_PI / 180.0;
int xShift = static_cast<int>((
( centerXDouble * cos( myRadiansDouble ) ) +
( centerYDouble * sin( myRadiansDouble ) )
Expand Down Expand Up @@ -266,8 +264,8 @@ bool QgsDecorationNorthArrow::calculateNorthDirection()
double angle = 0.0;

// convert to radians for the equations below
p1.multiply( PI / 180.0 );
p2.multiply( PI / 180.0 );
p1.multiply( M_PI / 180.0 );
p2.multiply( M_PI / 180.0 );

double y = sin( p2.x() - p1.x() ) * cos( p2.y() );
double x = cos( p1.y() ) * sin( p2.y() ) -
Expand All @@ -282,25 +280,25 @@ bool QgsDecorationNorthArrow::calculateNorthDirection()
if ( x > 0.0 && ( y / x ) > TOL )
angle = atan( y / x );
else if ( x < 0.0 && ( y / x ) < -TOL )
angle = PI - atan( -y / x );
angle = M_PI - atan( -y / x );
else
angle = 0.5 * PI;
angle = 0.5 * M_PI;
}
else if ( y < 0.0 )
{
if ( x > 0.0 && ( y / x ) < -TOL )
angle = -atan( -y / x );
else if ( x < 0.0 && ( y / x ) > TOL )
angle = atan( y / x ) - PI;
angle = atan( y / x ) - M_PI;
else
angle = 1.5 * PI;
angle = 1.5 * M_PI;
}
else
{
if ( x > TOL )
angle = 0.0;
else if ( x < -TOL )
angle = PI;
angle = M_PI;
else
{
angle = 0.0; // p1 = p2
Expand All @@ -309,7 +307,7 @@ bool QgsDecorationNorthArrow::calculateNorthDirection()
}
// And set the angle of the north arrow. Perhaps do something
// different if goodDirn = false.
mRotationInt = qRound( fmod( 360.0 - angle * 180.0 / PI, 360.0 ) );
mRotationInt = qRound( fmod( 360.0 - angle * 180.0 / M_PI, 360.0 ) );
}
else
{
Expand Down
1 change: 0 additions & 1 deletion src/app/qgsdecorationnortharrow.h
Expand Up @@ -57,7 +57,6 @@ class APP_EXPORT QgsDecorationNorthArrow: public QgsDecorationItem

private:

static const double PI;
// static const double DEG2RAD;
static const double TOL;

Expand Down
2 changes: 1 addition & 1 deletion src/core/auth/qgsauthconfig.cpp
Expand Up @@ -32,7 +32,7 @@ const QString QgsAuthMethodConfig::mConfigSep = QStringLiteral( "|||" );
const QString QgsAuthMethodConfig::mConfigKeySep = QStringLiteral( ":::" );
const QString QgsAuthMethodConfig::mConfigListSep = QStringLiteral( "```" );

const int QgsAuthMethodConfig::mConfigVersion = 1;
const int QgsAuthMethodConfig::sConfigVersion = 1;

// get uniqueConfigId only on save
QgsAuthMethodConfig::QgsAuthMethodConfig( const QString& method, int version )
Expand Down
2 changes: 1 addition & 1 deletion src/core/auth/qgsauthconfig.h
Expand Up @@ -172,7 +172,7 @@ class CORE_EXPORT QgsAuthMethodConfig
static const QString mConfigKeySep;
static const QString mConfigListSep;

static const int mConfigVersion;
static const int sConfigVersion;
};

typedef QHash<QString, QgsAuthMethodConfig> QgsAuthMethodConfigsMap;
Expand Down
24 changes: 12 additions & 12 deletions src/core/dxf/qgsdxfexport.cpp
Expand Up @@ -56,7 +56,7 @@
#define DXF_HANDPLOTSTYLE 0xf

// dxf color palette
int QgsDxfExport::mDxfColors[][3] =
int QgsDxfExport::sDxfColors[][3] =
{
{ 255, 255, 255 },
{ 255, 0, 0 },
Expand Down Expand Up @@ -316,7 +316,7 @@ int QgsDxfExport::mDxfColors[][3] =
{ 255, 255, 255 },
};

const char *QgsDxfExport::mDxfEncodings[][2] =
const char *QgsDxfExport::sDxfEncodings[][2] =
{
{ "ASCII", "" },
{ "8859_1", "ISO-8859-1" },
Expand Down Expand Up @@ -432,7 +432,7 @@ void QgsDxfExport::writeGroup( const QColor& color, int exactMatchCode, int rgbC
int minDistAt = -1;
int minDist = INT_MAX;

for ( int i = 1; i < static_cast< int >( sizeof( mDxfColors ) / sizeof( *mDxfColors ) ) && minDist > 0; ++i )
for ( int i = 1; i < static_cast< int >( sizeof( sDxfColors ) / sizeof( *sDxfColors ) ) && minDist > 0; ++i )
{
int dist = color_distance( color.rgba(), i );
if ( dist >= minDist )
Expand Down Expand Up @@ -3873,7 +3873,7 @@ int QgsDxfExport::closestColorMatch( QRgb pixel )
{
int idx = 0;
int current_distance = INT_MAX;
for ( int i = 1; i < static_cast< int >( sizeof( mDxfColors ) / sizeof( *mDxfColors ) ); ++i )
for ( int i = 1; i < static_cast< int >( sizeof( sDxfColors ) / sizeof( *sDxfColors ) ); ++i )
{
int dist = color_distance( pixel, i );
if ( dist < current_distance )
Expand All @@ -3894,9 +3894,9 @@ int QgsDxfExport::color_distance( QRgb p1, int index )
return 0;
}

double redDiff = qRed( p1 ) - mDxfColors[index][0];
double greenDiff = qGreen( p1 ) - mDxfColors[index][1];
double blueDiff = qBlue( p1 ) - mDxfColors[index][2];
double redDiff = qRed( p1 ) - sDxfColors[index][0];
double greenDiff = qGreen( p1 ) - sDxfColors[index][1];
double blueDiff = qBlue( p1 ) - sDxfColors[index][2];
#if 0
QgsDebugMsg( QString( "color_distance( r:%1 g:%2 b:%3 <=> i:%4 r:%5 g:%6 b:%7 ) => %8" )
.arg( qRed( p1 ) ).arg( qGreen( p1 ) ).arg( qBlue( p1 ) )
Expand Down Expand Up @@ -4211,13 +4211,13 @@ QString QgsDxfExport::dxfEncoding( const QString &name )
continue;

int i;
for ( i = 0; i < static_cast< int >( sizeof( mDxfEncodings ) / sizeof( *mDxfEncodings ) ) && name != mDxfEncodings[i][1]; ++i )
for ( i = 0; i < static_cast< int >( sizeof( sDxfEncodings ) / sizeof( *sDxfEncodings ) ) && name != sDxfEncodings[i][1]; ++i )
;

if ( i == static_cast< int >( sizeof( mDxfEncodings ) / sizeof( *mDxfEncodings ) ) )
if ( i == static_cast< int >( sizeof( sDxfEncodings ) / sizeof( *sDxfEncodings ) ) )
continue;

return mDxfEncodings[i][0];
return sDxfEncodings[i][0];
}

return QString::null;
Expand All @@ -4229,10 +4229,10 @@ QStringList QgsDxfExport::encodings()
Q_FOREACH ( QByteArray codec, QTextCodec::availableCodecs() )
{
int i;
for ( i = 0; i < static_cast< int >( sizeof( mDxfEncodings ) / sizeof( *mDxfEncodings ) ) && strcmp( codec.data(), mDxfEncodings[i][1] ) != 0; ++i )
for ( i = 0; i < static_cast< int >( sizeof( sDxfEncodings ) / sizeof( *sDxfEncodings ) ) && strcmp( codec.data(), sDxfEncodings[i][1] ) != 0; ++i )
;

if ( i < static_cast< int >( sizeof( mDxfEncodings ) / sizeof( *mDxfEncodings ) ) )
if ( i < static_cast< int >( sizeof( sDxfEncodings ) / sizeof( *sDxfEncodings ) ) )
encodings << codec.data();
}
return encodings;
Expand Down
4 changes: 2 additions & 2 deletions src/core/dxf/qgsdxfexport.h
Expand Up @@ -340,8 +340,8 @@ class CORE_EXPORT QgsDxfExport

QTextStream mTextStream;

static int mDxfColors[][3];
static const char *mDxfEncodings[][2];
static int sDxfColors[][3];
static const char *sDxfEncodings[][2];

int mSymbolLayerCounter; //internal counter
int mNextHandleId;
Expand Down
6 changes: 3 additions & 3 deletions src/core/layertree/qgslayertreemodellegendnode.cpp
Expand Up @@ -176,7 +176,7 @@ QSize QgsSymbolLegendNode::minimumIconSize( QgsRenderContext* context ) const
}

if ( mItem.level() != 0 && !( model() && model()->testFlag( QgsLayerTreeModel::ShowLegendAsTree ) ) )
minSz.setWidth( mItem.level() * indentSize + minSz.width() );
minSz.setWidth( mItem.level() * sIndentSize + minSz.width() );

return minSz;
}
Expand Down Expand Up @@ -279,10 +279,10 @@ QVariant QgsSymbolLegendNode::data( int role ) const
else
{
// ident the symbol icon to make it look like a tree structure
QPixmap pix2( pix.width() + mItem.level() * indentSize, pix.height() );
QPixmap pix2( pix.width() + mItem.level() * sIndentSize, pix.height() );
pix2.fill( Qt::transparent );
QPainter p( &pix2 );
p.drawPixmap( mItem.level() * indentSize, 0, pix );
p.drawPixmap( mItem.level() * sIndentSize, 0, pix );
p.end();
mPixmap = pix2;
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/layertree/qgslayertreemodellegendnode.h
Expand Up @@ -225,7 +225,7 @@ class CORE_EXPORT QgsSymbolLegendNode : public QgsLayerTreeModelLegendNode
QSize mIconSize;

// ident the symbol icon to make it look like a tree structure
static const int indentSize = 20;
static const int sIndentSize = 20;

// return a temporary context or null if legendMapViewData are not valid
QgsRenderContext * createTemporaryRenderContext() const;
Expand Down
6 changes: 3 additions & 3 deletions src/core/qgsapplication.cpp
Expand Up @@ -426,10 +426,10 @@ QString QgsApplication::prefixPath()
{
if ( ABISYM( mRunningFromBuildDir ) )
{
static bool once = true;
if ( once )
static bool sOnce = true;
if ( sOnce )
qWarning( "!!! prefix path was requested, but it is not valid - we do not run from installed path !!!" );
once = false;
sOnce = false;
}

return ABISYM( mPrefixPath );
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsconnectionpool.h
Expand Up @@ -55,7 +55,7 @@ class QgsConnectionPoolGroup
{
public:

static const int maxConcurrentConnections;
static const int sMaxConcurrentConnections;

struct Item
{
Expand Down
6 changes: 3 additions & 3 deletions src/core/qgscoordinatereferencesystem.cpp
Expand Up @@ -1121,10 +1121,10 @@ void QgsCoordinateReferenceSystem::setMapUnits()
// do better than that ... (but perhaps ogr should be enhanced to
// do this instead?).

static const double feetToMeter = 0.3048;
static const double smallNum = 1e-3;
static const double FEET_TO_METER = 0.3048;
static const double SMALL_NUM = 1e-3;

if ( qAbs( toMeter - feetToMeter ) < smallNum )
if ( qAbs( toMeter - FEET_TO_METER ) < SMALL_NUM )
unit = QStringLiteral( "Foot" );

QgsDebugMsg( "Projection has linear units of " + unit );
Expand Down
6 changes: 3 additions & 3 deletions src/core/qgsmaprendererjob.cpp
Expand Up @@ -79,7 +79,7 @@ bool QgsMapRendererJob::reprojectToLayerExtent( const QgsMapLayer *ml, const Qgs
// geographic coordinates (usually +/- 180 degrees,
// and is assumed to be so here), and draw each
// extent separately.
static const double splitCoord = 180.0;
static const double SPLIT_COORD = 180.0;

if ( ml->crs().isGeographic() )
{
Expand Down Expand Up @@ -132,8 +132,8 @@ bool QgsMapRendererJob::reprojectToLayerExtent( const QgsMapLayer *ml, const Qgs
// so let's use (-180,180). This hopefully does not add too much overhead. It is
// more straightforward than rendering with two separate extents and more consistent
// for rendering, labeling and caching as everything is rendered just in one go
extent.setXMinimum( -splitCoord );
extent.setXMaximum( splitCoord );
extent.setXMinimum( -SPLIT_COORD );
extent.setXMaximum( SPLIT_COORD );
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/core/qgsmapsettings.cpp
Expand Up @@ -150,8 +150,8 @@ void QgsMapSettings::updateDerived()
double xRange = extent.width() / xMean;
double yRange = extent.height() / yMean;

static const double minProportion = 1e-12;
if ( xRange < minProportion || yRange < minProportion )
static const double MIN_PROPORTION = 1e-12;
if ( xRange < MIN_PROPORTION || yRange < MIN_PROPORTION )
{
mValid = false;
return;
Expand Down
4 changes: 2 additions & 2 deletions src/core/qgsrenderchecker.cpp
Expand Up @@ -28,7 +28,7 @@
#include <QDebug>
#include <QBuffer>

static int renderCounter = 0;
static int sRenderCounter = 0;

QgsRenderChecker::QgsRenderChecker()
: mReport( QLatin1String( "" ) )
Expand Down Expand Up @@ -357,7 +357,7 @@ bool QgsRenderChecker::compareImages( const QString& theTestName,
mRenderedImageFile,
mExpectedImageFile )
.arg( imgWidth ).arg( imgHeight )
.arg( renderCounter++ );
.arg( sRenderCounter++ );

QString prefix;
if ( !mControlPathPrefix.isNull() )
Expand Down
8 changes: 4 additions & 4 deletions src/core/qgsscalecalculator.cpp
Expand Up @@ -118,12 +118,12 @@ double QgsScaleCalculator::calculateGeographicDistance( const QgsRectangle &mapE
const static double rads = ( 4.0 * atan( 1.0 ) ) / 180.0;
double a = pow( cos( lat * rads ), 2 );
double c = 2.0 * atan2( sqrt( a ), sqrt( 1.0 - a ) );
const static double ra = 6378000; // [m]
const static double RA = 6378000; // [m]
// The eccentricity. This comes from sqrt(1.0 - rb*rb/(ra*ra)) with rb set
// to 6357000 m.
const static double e = 0.0810820288;
double radius = ra * ( 1.0 - e * e ) /
pow( 1.0 - e * e * sin( lat * rads ) * sin( lat * rads ), 1.5 );
const static double E = 0.0810820288;
double radius = RA * ( 1.0 - E * E ) /
pow( 1.0 - E * E * sin( lat * rads ) * sin( lat * rads ), 1.5 );
double meters = ( mapExtent.xMaximum() - mapExtent.xMinimum() ) / 180.0 * radius * c;

QgsDebugMsg( "Distance across map extent (m): " + QString::number( meters ) );
Expand Down
8 changes: 4 additions & 4 deletions src/core/qgsvectorlayerundocommand.cpp
Expand Up @@ -28,17 +28,17 @@
QgsVectorLayerUndoCommandAddFeature::QgsVectorLayerUndoCommandAddFeature( QgsVectorLayerEditBuffer* buffer, QgsFeature& f )
: QgsVectorLayerUndoCommand( buffer )
{
static int addedIdLowWaterMark = -1;
static int sAddedIdLowWaterMark = -1;

//assign a temporary id to the feature (use negative numbers)
addedIdLowWaterMark--;
sAddedIdLowWaterMark--;

QgsDebugMsgLevel( "Assigned feature id " + QString::number( addedIdLowWaterMark ), 4 );
QgsDebugMsgLevel( "Assigned feature id " + QString::number( sAddedIdLowWaterMark ), 4 );

// Force a feature ID (to keep other functions in QGIS happy,
// providers will use their own new feature ID when we commit the new feature)
// and add to the known added features.
f.setId( addedIdLowWaterMark );
f.setId( sAddedIdLowWaterMark );

mFeature = f;
}
Expand Down
4 changes: 2 additions & 2 deletions src/core/symbology-ng/qgsgraduatedsymbolrenderer.cpp
Expand Up @@ -176,8 +176,8 @@ void QgsRendererRange::toSld( QDomDocument &doc, QDomElement &element, QgsString

///////////

int QgsRendererRangeLabelFormat::MaxPrecision = 15;
int QgsRendererRangeLabelFormat::MinPrecision = -6;
const int QgsRendererRangeLabelFormat::MaxPrecision = 15;
const int QgsRendererRangeLabelFormat::MinPrecision = -6;

QgsRendererRangeLabelFormat::QgsRendererRangeLabelFormat()
: mFormat( QStringLiteral( " %1 - %2 " ) )
Expand Down

2 comments on commit b7706b3

@m-kuhn
Copy link
Member

@m-kuhn m-kuhn commented on b7706b3 Jan 12, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I got something wrong, I find a couple of static const changes in here that are not in all-caps

@nyalldawson
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No - you're right. This needs more work.

Please sign in to comment.