Skip to content
Permalink
Browse files

Coverity fixes

Including a notable bug causing "mean" to be missing from merge
attributes dialog options.
  • Loading branch information
nyalldawson committed Feb 9, 2015
1 parent a1b858b commit e4253721c88da36349d7c34b7d8fbc75f877895b
@@ -81,21 +81,22 @@ void Bezier3D::calcSecDer( float t, Vector3D* v )
v->setY( 0 );
v->setZ( 0 );

if ( mControlPoly->count() < 3 )
int nodes = mControlPoly->count();
if ( nodes < 3 )
{
return;
}

for ( int n = 1; n <= int( mControlPoly->count() - 2 ); n++ )
for ( int n = 1; n <= int( nodes - 2 ); n++ )
{
double bernst = MathUtils::calcBernsteinPoly( mControlPoly->count() - 3, n - 1, t );
double bernst = MathUtils::calcBernsteinPoly( nodes - 3, n - 1, t );
v->setX( v->getX() + (( *mControlPoly )[n+1]->getX() - 2*( *mControlPoly )[n]->getX() + ( *mControlPoly )[n-1]->getX() )*bernst );
v->setY( v->getY() + (( *mControlPoly )[n+1]->getY() - 2*( *mControlPoly )[n]->getY() + ( *mControlPoly )[n-1]->getY() )*bernst );
v->setZ( v->getZ() + (( *mControlPoly )[n+1]->getZ() - 2*( *mControlPoly )[n]->getZ() + ( *mControlPoly )[n-1]->getZ() )*bernst );
}
v->setX( v->getX()*MathUtils::faculty( mControlPoly->count() - 1 ) / MathUtils::faculty( mControlPoly->count() - 3 ) );
v->setY( v->getY()*MathUtils::faculty( mControlPoly->count() - 1 ) / MathUtils::faculty( mControlPoly->count() - 3 ) );
v->setZ( v->getZ()*MathUtils::faculty( mControlPoly->count() - 1 ) / MathUtils::faculty( mControlPoly->count() - 3 ) );
v->setX( v->getX()*MathUtils::faculty( nodes - 1 ) / MathUtils::faculty( nodes - 3 ) );
v->setY( v->getY()*MathUtils::faculty( nodes - 1 ) / MathUtils::faculty( nodes - 3 ) );
v->setZ( v->getZ()*MathUtils::faculty( nodes - 1 ) / MathUtils::faculty( nodes - 3 ) );
}

else
@@ -17,11 +17,53 @@
#include "CloughTocherInterpolator.h"
#include "qgslogger.h"

#include <cmath>
#include <qmath.h>

CloughTocherInterpolator::CloughTocherInterpolator()
: mTIN( 0 )
, mEdgeTolerance( 0.00001 )
, der1X( 0.0 )
, der1Y( 0.0 )
, der2X( 0.0 )
, der2Y( 0.0 )
, der3X( 0.0 )
, der3Y( 0.0 )
{

}

CloughTocherInterpolator::CloughTocherInterpolator( NormVecDecorator* tin )
: mTIN( tin )
, mEdgeTolerance( 0.00001 )
, der1X( 0.0 )
, der1Y( 0.0 )
, der2X( 0.0 )
, der2Y( 0.0 )
, der3X( 0.0 )
, der3Y( 0.0 )
{

}

CloughTocherInterpolator::~CloughTocherInterpolator()
{
//nothing to do
}

void CloughTocherInterpolator::setTriangulation( NormVecDecorator* tin )
{
mTIN = tin;
}

double CloughTocherInterpolator::calcBernsteinPoly( int n, int i, int j, int k, double u, double v, double w )
{
double result = MathUtils::faculty( n ) * MathUtils::power( u, i ) * MathUtils::power( v, j ) * MathUtils::power( w, k ) / ( MathUtils::faculty( i ) * MathUtils::faculty( j ) * MathUtils::faculty( k ) );
if ( i < 0 || j < 0 || k < 0 )
{
QgsDebugMsg( "Invalid parameters for Bernstein poly calculation!" );
return 0;
}

double result = MathUtils::faculty( n ) * qPow( u, i ) * qPow( v, j ) * qPow( w, k ) / ( MathUtils::faculty( i ) * MathUtils::faculty( j ) * MathUtils::faculty( k ) );
return result;
}

@@ -728,8 +770,3 @@ void CloughTocherInterpolator::init( double x, double y )//version which has uni
#endif







@@ -91,27 +91,6 @@ class ANALYSIS_EXPORT CloughTocherInterpolator : public TriangleInterpolator
virtual void setTriangulation( NormVecDecorator* tin );
};


inline CloughTocherInterpolator::CloughTocherInterpolator() : mTIN( 0 ), mEdgeTolerance( 0.00001 )
{

}

inline CloughTocherInterpolator::CloughTocherInterpolator( NormVecDecorator* tin ) : mTIN( tin ), mEdgeTolerance( 0.00001 )
{

}

inline CloughTocherInterpolator::~CloughTocherInterpolator()
{
//nothing to do
}

inline void CloughTocherInterpolator::setTriangulation( NormVecDecorator* tin )
{
mTIN = tin;
}

#endif


@@ -16,6 +16,7 @@

#include "MathUtils.h"
#include "qgslogger.h"
#include <qmath.h>

bool MathUtils::calcBarycentricCoordinates( double x, double y, Point3D* p1, Point3D* p2, Point3D* p3, Point3D* result )
{
@@ -104,7 +105,7 @@ double MathUtils::calcBernsteinPoly( int n, int i, double t )
return 0;
}

return lower( n, i )*power( t, i )*power(( 1 - t ), ( n - i ) );
return lower( n, i )*qPow( t, i )*qPow(( 1 - t ), ( n - i ) );
}

double MathUtils::cFDerBernsteinPoly( int n, int i, double t )
@@ -23,13 +23,23 @@
#include <QProgressDialog>

QgsGridFileWriter::QgsGridFileWriter( QgsInterpolator* i, QString outputPath, QgsRectangle extent, int nCols, int nRows, double cellSizeX, double cellSizeY )
: mInterpolator( i ), mOutputFilePath( outputPath ), mInterpolationExtent( extent ), mNumColumns( nCols ), mNumRows( nRows )
, mCellSizeX( cellSizeX ), mCellSizeY( cellSizeY )
: mInterpolator( i )
, mOutputFilePath( outputPath )
, mInterpolationExtent( extent )
, mNumColumns( nCols )
, mNumRows( nRows )
, mCellSizeX( cellSizeX )
, mCellSizeY( cellSizeY )
{

}

QgsGridFileWriter::QgsGridFileWriter(): mInterpolator( 0 )
QgsGridFileWriter::QgsGridFileWriter()
: mInterpolator( 0 )
, mNumColumns( 0 )
, mNumRows( 0 )
, mCellSizeX( 0 )
, mCellSizeY( 0 )
{

}
@@ -20,12 +20,15 @@
#include "qgsvectorlayer.h"
#include "qgsgeometry.h"

QgsInterpolator::QgsInterpolator( const QList<LayerData>& layerData ): mDataIsCached( false ), mLayerData( layerData )
QgsInterpolator::QgsInterpolator( const QList<LayerData>& layerData )
: mDataIsCached( false )
, mLayerData( layerData )
{

}

QgsInterpolator::QgsInterpolator()
: mDataIsCached( false )
{

}
@@ -83,6 +83,8 @@ int QgsGraph::findVertex( const QgsPoint& pt ) const
}

QgsGraphArc::QgsGraphArc()
: mOut( 0 )
, mIn( 0 )
{

}
@@ -20,6 +20,7 @@ QgsRasterCalcNode::QgsRasterCalcNode()
, mLeft( 0 )
, mRight( 0 )
, mNumber( 0 )
, mOperator( opPLUS ) //not used
{
}

@@ -28,6 +29,7 @@ QgsRasterCalcNode::QgsRasterCalcNode( double number )
, mLeft( 0 )
, mRight( 0 )
, mNumber( number )
, mOperator( opPLUS ) //not used
{
}

@@ -46,6 +48,7 @@ QgsRasterCalcNode::QgsRasterCalcNode( const QString& rasterName )
, mRight( 0 )
, mNumber( 0 )
, mRasterName( rasterName )
, mOperator( opPLUS ) //not used
{
}

@@ -250,6 +250,8 @@ int QgsRasterCalculator::processCalculation( QProgressDialog* p )
}

QgsRasterCalculator::QgsRasterCalculator()
: mNumOutputColumns( 0 )
, mNumOutputRows( 0 )
{
}

@@ -20,7 +20,11 @@

#include <cmath>

QgsRasterMatrix::QgsRasterMatrix(): mColumns( 0 ), mRows( 0 ), mData( 0 )
QgsRasterMatrix::QgsRasterMatrix()
: mColumns( 0 )
, mRows( 0 )
, mData( 0 )
, mNodataValue( -1 )
{
}

@@ -33,8 +33,15 @@
#define TO8F(x) QFile::encodeName( x ).constData()
#endif

QgsRelief::QgsRelief( const QString& inputFile, const QString& outputFile, const QString& outputFormat ): \
mInputFile( inputFile ), mOutputFile( outputFile ), mOutputFormat( outputFormat ), mZFactor( 1.0 )
QgsRelief::QgsRelief( const QString& inputFile, const QString& outputFile, const QString& outputFormat )
: mInputFile( inputFile )
, mOutputFile( outputFile )
, mOutputFormat( outputFormat )
, mCellSizeX( 0.0 )
, mCellSizeY( 0.0 )
, mInputNodataValue( -1 )
, mOutputNodataValue( -1 )
, mZFactor( 1.0 )
{
mSlopeFilter = new QgsSlopeFilter( inputFile, outputFile, outputFormat );
mAspectFilter = new QgsAspectFilter( inputFile, outputFile, outputFormat );
@@ -146,9 +146,8 @@ int QgsTransectSample::createSample( QProgressDialog* pd )
}

//find baseline for strata
bool strataIdOk = true;
QVariant strataId = fet.attribute( mStrataIdAttribute );
QgsGeometry* baselineGeom = findBaselineGeometry( strataIdOk ? strataId : -1 );
QgsGeometry* baselineGeom = findBaselineGeometry( strataId.isValid() ? strataId : -1 );
if ( !baselineGeom )
{
continue;
@@ -43,6 +43,7 @@ QgsZonalStatistics::QgsZonalStatistics( QgsVectorLayer* polygonLayer, const QStr
QgsZonalStatistics::QgsZonalStatistics()
: mRasterBand( 0 )
, mPolygonLayer( 0 )
, mInputNodataValue( -1 )
{

}
@@ -486,7 +486,7 @@ int QgsComposerPictureWidget::addDirectoryToPreview( const QString& path )
QIcon icon( filePath );
listItem->setIcon( icon );
}
else if ( fileIsPixel ) //for pixel formats: create icon from scaled pixmap
else //for pixel formats: create icon from scaled pixmap
{
QPixmap iconPixmap( filePath );
if ( iconPixmap.isNull() )
@@ -498,10 +498,6 @@ int QgsComposerPictureWidget::addDirectoryToPreview( const QString& path )
QIcon icon( scaledPixmap );
listItem->setIcon( icon );
}
else
{
++counter; continue;
}

listItem->setText( "" );
//store the absolute icon file path as user data
@@ -104,12 +104,12 @@ void QgsComposerScaleBarWidget::refreshMapComboBox()
mMapComboBox->addItem( tr( "Map %1" ).arg(( *mapItemIt )->id() ) );
}
}
}

if ( saveCurrentComboText.isEmpty() && mComposerScaleBar->composerMap() )
{
//combo box was not initialised before
mMapComboBox->setCurrentIndex( mMapComboBox->findText( tr( "Map %1" ).arg( mComposerScaleBar->composerMap()->id() ) ) );
if ( saveCurrentComboText.isEmpty() && mComposerScaleBar->composerMap() )
{
//combo box was not initialised before
mMapComboBox->setCurrentIndex( mMapComboBox->findText( tr( "Map %1" ).arg( mComposerScaleBar->composerMap()->id() ) ) );
}
}
if ( mMapComboBox->findText( saveCurrentComboText ) == -1 )
{
@@ -527,6 +527,10 @@ void QgsCompositionWidget::on_mPageStyleButton_clicked()
}

QgsFillSymbolV2* newSymbol = dynamic_cast<QgsFillSymbolV2*>( mComposition->pageStyleSymbol()->clone() );
if ( !newSymbol )
{
newSymbol = new QgsFillSymbolV2();
}
QgsSymbolV2SelectorDialog d( newSymbol, QgsStyleV2::defaultStyle(), coverageLayer );

if ( d.exec() == QDialog::Accepted )
@@ -828,7 +828,7 @@ bool QgsDecorationGrid::getIntervalFromCurrentLayer( double* values )
return false;
}
QgsRasterLayer* rlayer = dynamic_cast<QgsRasterLayer*>( layer );
if ( !rlayer )
if ( !rlayer || rlayer->width() == 0 || rlayer->height() == 0 )
{
QMessageBox::warning( 0, tr( "Error" ), tr( "Invalid raster layer" ) );
return false;
@@ -26,7 +26,7 @@ QgsLabelPreview::QgsLabelPreview( QWidget* parent )

// construct a device-based render context
QgsMapToPixel newCoordXForm;
newCoordXForm.setParameters( 0, 0, 0, 0 );
newCoordXForm.setParameters( 1, 0, 0, 0 );
mContext = new QgsRenderContext();
mContext->setMapToPixel( newCoordXForm );
}
@@ -159,15 +159,12 @@ QComboBox *QgsMergeAttributesDialog::createMergeComboBox( QVariant::Type columnT
newComboBox->addItem( tr( "Maximum" ), "maximum" );
newComboBox->addItem( tr( "Median" ), "median" );
newComboBox->addItem( tr( "Sum" ), "sum" );
newComboBox->addItem( tr( "Mean" ), "mean" );
}
else if ( columnType == QVariant::String )
{
newComboBox->addItem( tr( "Concatenation" ), "concat" );
}
else if ( columnType == QVariant::Double )
{
newComboBox->addItem( tr( "Mean" ), "mean" );
}

newComboBox->addItem( tr( "Skip attribute" ), "skip" );

@@ -21,12 +21,20 @@
#include "qgsproject.h"


QgsAddRemoveMultiFrameCommand::QgsAddRemoveMultiFrameCommand( State s, QgsComposerMultiFrame* multiFrame, QgsComposition* c, const QString& text, QUndoCommand* parent ):
QUndoCommand( text, parent ), mMultiFrame( multiFrame ), mComposition( c ), mState( s ), mFirstRun( true )
QgsAddRemoveMultiFrameCommand::QgsAddRemoveMultiFrameCommand( State s, QgsComposerMultiFrame* multiFrame, QgsComposition* c, const QString& text, QUndoCommand* parent )
: QUndoCommand( text, parent )
, mMultiFrame( multiFrame )
, mComposition( c )
, mState( s )
, mFirstRun( true )
{
}

QgsAddRemoveMultiFrameCommand::QgsAddRemoveMultiFrameCommand(): mMultiFrame( 0 ), mComposition( 0 )
QgsAddRemoveMultiFrameCommand::QgsAddRemoveMultiFrameCommand()
: mMultiFrame( 0 )
, mComposition( 0 )
, mState( Added )
, mFirstRun( true )
{
}

@@ -97,6 +97,7 @@ QgsComposerHtml::QgsComposerHtml()
, mExpressionFeature( 0 )
, mExpressionLayer( 0 )
, mDistanceArea( 0 )
, mEnableUserStylesheet( false )
, mFetcher( 0 )
{
mDistanceArea = new QgsDistanceArea();
@@ -50,6 +50,7 @@ QgsComposerLegend::QgsComposerLegend()
, mLegendModel2( 0 )
, mCustomLayerTree( 0 )
, mComposerMap( 0 )
, mLegendFilterByMap( false )
{

}

0 comments on commit e425372

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