Skip to content

Commit

Permalink
More coverity fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Feb 10, 2015
1 parent dc156c8 commit a7f7740
Show file tree
Hide file tree
Showing 31 changed files with 114 additions and 44 deletions.
9 changes: 8 additions & 1 deletion src/app/qgsattributetabledialog.cpp
Expand Up @@ -287,7 +287,11 @@ void QgsAttributeTableDialog::columnBoxInit()

foreach ( const QgsField field, fields )
{
if ( mLayer->editorWidgetV2( mLayer->fieldNameIndex( field.name() ) ) != "Hidden" )
int idx = mLayer->fieldNameIndex( field.name() );
if ( idx < 0 )
continue;

if ( mLayer->editorWidgetV2( idx ) != "Hidden" )
{
QIcon icon = QgsApplication::getThemeIcon( "/mActionNewAttribute.png" );
QString text = field.name();
Expand Down Expand Up @@ -650,6 +654,9 @@ void QgsAttributeTableDialog::filterQueryChanged( const QString& query )

const QgsFields& flds = mLayer->pendingFields();
int fldIndex = mLayer->fieldNameIndex( fieldName );
if ( fldIndex < 0 )
return;

QVariant::Type fldType = flds[fldIndex].type();
bool numeric = ( fldType == QVariant::Int || fldType == QVariant::Double );

Expand Down
3 changes: 3 additions & 0 deletions src/app/qgsfieldsproperties.cpp
Expand Up @@ -550,6 +550,9 @@ void QgsFieldsProperties::on_mDeleteAttributeButton_clicked()
if ( item->column() == 0 )
{
int idx = mIndexedWidgets.indexOf( item );
if ( idx < 0 )
continue;

if ( mLayer->pendingFields().fieldOrigin( idx ) == QgsFields::OriginExpression )
expressionFields << idx;
else
Expand Down
2 changes: 2 additions & 0 deletions src/app/qgsmaptoolmovelabel.cpp
Expand Up @@ -24,6 +24,8 @@

QgsMapToolMoveLabel::QgsMapToolMoveLabel( QgsMapCanvas* canvas )
: QgsMapToolLabel( canvas )
, mClickOffsetX( 0 )
, mClickOffsetY( 0 )
{
mToolName = tr( "Move label" );
}
Expand Down
3 changes: 3 additions & 0 deletions src/app/qgsmergeattributesdialog.cpp
Expand Up @@ -194,6 +194,9 @@ void QgsMergeAttributesDialog::comboValueChanged( const QString &text )
return;
}
int column = findComboColumn( senderComboBox );
if ( column < 0 )
return;

refreshMergedValue( column );
}

Expand Down
2 changes: 1 addition & 1 deletion src/core/layertree/qgslayertreemodellegendnode.cpp
Expand Up @@ -476,7 +476,7 @@ QSizeF QgsRasterSymbolLegendNode::drawSymbol( const QgsLegendSettings& settings,
if ( QgsRasterLayer* rasterLayer = dynamic_cast<QgsRasterLayer*>( layerNode()->layer() ) )
{
if ( QgsRasterRenderer* rasterRenderer = rasterLayer->renderer() )
itemColor.setAlpha( rasterRenderer ? rasterRenderer->opacity() * 255.0 : 255 );
itemColor.setAlpha( rasterRenderer->opacity() * 255.0 );
}

ctx->painter->setBrush( itemColor );
Expand Down
2 changes: 2 additions & 0 deletions src/core/qgscoordinatetransform.cpp
Expand Up @@ -39,6 +39,7 @@ extern "C"

QgsCoordinateTransform::QgsCoordinateTransform()
: QObject()
, mShortCircuit( false )
, mInitialisedFlag( false )
, mSourceProjection( 0 )
, mDestinationProjection( 0 )
Expand All @@ -50,6 +51,7 @@ QgsCoordinateTransform::QgsCoordinateTransform()

QgsCoordinateTransform::QgsCoordinateTransform( const QgsCoordinateReferenceSystem& source, const QgsCoordinateReferenceSystem& dest )
: QObject()
, mShortCircuit( false )
, mInitialisedFlag( false )
, mSourceProjection( 0 )
, mDestinationProjection( 0 )
Expand Down
4 changes: 2 additions & 2 deletions src/core/qgscoordinatetransform.h
Expand Up @@ -200,12 +200,12 @@ class CORE_EXPORT QgsCoordinateTransform : public QObject
* Flag to indicate whether the coordinate systems have been initialised
* @return true if initialised, otherwise false
*/
bool isInitialised() const {return mInitialisedFlag;};
bool isInitialised() const {return mInitialisedFlag;}

/*! See if the transform short circuits because src and dest are equivalent
* @return bool True if it short circuits
*/
bool isShortCircuited() {return mShortCircuit;};
bool isShortCircuited() {return mShortCircuit;}

/*! Change the destination coordinate system by passing it a qgis srsid
* A QGIS srsid is a unique key value to an entry on the tbl_srs in the
Expand Down
1 change: 1 addition & 0 deletions src/core/qgsfeaturerequest.cpp
Expand Up @@ -24,6 +24,7 @@ const QString QgsFeatureRequest::AllAttributes = QString( "#!allattributes!#" );

QgsFeatureRequest::QgsFeatureRequest()
: mFilter( FilterNone )
, mFilterFid( -1 )
, mFilterExpression( 0 )
, mFlags( 0 )
{
Expand Down
11 changes: 11 additions & 0 deletions src/core/qgsfield.cpp
Expand Up @@ -185,6 +185,9 @@ bool QgsFields::appendExpressionField( const QgsField& field, int originIndex )

void QgsFields::remove( int fieldIdx )
{
if ( !exists( fieldIdx ) )
return;

mNameToIndex.remove( mFields[fieldIdx].field.name() );
mFields.remove( fieldIdx );
}
Expand All @@ -197,6 +200,14 @@ void QgsFields::extend( const QgsFields& other )
}
}

QgsFields::FieldOrigin QgsFields::fieldOrigin( int fieldIdx ) const
{
if ( !exists( fieldIdx ) )
return OriginUnknown;

return mFields[fieldIdx].origin;
}

QList<QgsField> QgsFields::toList() const
{
QList<QgsField> lst;
Expand Down
3 changes: 2 additions & 1 deletion src/core/qgsfield.h
Expand Up @@ -231,7 +231,7 @@ class CORE_EXPORT QgsFields
const QgsField& field( const QString& name ) const { return mFields[ indexFromName( name )].field; }

//! Get field's origin (value from an enumeration)
FieldOrigin fieldOrigin( int fieldIdx ) const { return mFields[fieldIdx].origin; }
FieldOrigin fieldOrigin( int fieldIdx ) const;
//! Get field's origin index (its meaning is specific to each type of origin)
int fieldOriginIndex( int fieldIdx ) const { return mFields[fieldIdx].originIndex; }

Expand Down Expand Up @@ -261,6 +261,7 @@ class CORE_EXPORT QgsFields

//! map for quick resolution of name to index
QHash<QString, int> mNameToIndex;

};


Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsmaprenderer.cpp
Expand Up @@ -175,7 +175,7 @@ void QgsMapRenderer::adjustExtentToSize()
if ( !myWidth || !myHeight )
{
mScale = 1.0;
newCoordXForm.setParameters( 0, 0, 0, 0 );
newCoordXForm.setParameters( 1, 0, 0, 0 );
return;
}

Expand Down
1 change: 1 addition & 0 deletions src/core/qgsmessageoutput.cpp
Expand Up @@ -47,6 +47,7 @@ QgsMessageOutput::~QgsMessageOutput()

QgsMessageOutputConsole::QgsMessageOutputConsole()
: mMessage( "" )
, mMsgType( MessageText )
{
}

Expand Down
3 changes: 3 additions & 0 deletions src/core/qgsvectorlayer.cpp
Expand Up @@ -2091,6 +2091,9 @@ void QgsVectorLayer::addAttributeEditorWidget( QgsAttributeEditorElement* data )

const QString QgsVectorLayer::editorWidgetV2( int fieldIdx ) const
{
if ( fieldIdx < 0 || fieldIdx >= mUpdatedFields.count() )
return "TextEdit";

return mEditorWidgetV2Types.value( mUpdatedFields[fieldIdx].name(), "TextEdit" );
}

Expand Down
3 changes: 3 additions & 0 deletions src/core/raster/qgshuesaturationfilter.cpp
Expand Up @@ -25,9 +25,12 @@
QgsHueSaturationFilter::QgsHueSaturationFilter( QgsRasterInterface* input )
: QgsRasterInterface( input ),
mSaturation( 0 ),
mSaturationScale( 1 ),
mGrayscaleMode( QgsHueSaturationFilter::GrayscaleOff ),
mColorizeOn( false ),
mColorizeColor( QColor::fromRgb( 255, 128, 128 ) ),
mColorizeH( 0 ),
mColorizeS( 50 ),
mColorizeStrength( 100 )
{
}
Expand Down
1 change: 1 addition & 0 deletions src/core/raster/qgsrasterblock.cpp
Expand Up @@ -261,6 +261,7 @@ QGis::DataType QgsRasterBlock::typeWithNoDataValue( QGis::DataType dataType, dou
case QGis::Float64:
*noDataValue = std::numeric_limits<double>::max() * -1.0;
newDataType = QGis::Float64;
break;
default:
QgsDebugMsg( QString( "Unknow data type %1" ).arg( dataType ) );
return QGis::UnknownDataType;
Expand Down
31 changes: 7 additions & 24 deletions src/core/symbology-ng/qgscptcityarchive.cpp
Expand Up @@ -984,7 +984,7 @@ QMap< QString, QStringList > QgsCptCityDirectoryItem::rampsMap()
curName = schemeName;
curVariant = "";

// stupid code to find if name ends with 1-3 digit number - should use regexp
// find if name ends with 1-3 digit number
// TODO need to detect if ends with b/c also
if ( schemeName.length() > 1 && schemeName.endsWith( "a" ) && ! listVariant.isEmpty() &&
(( prevName + listVariant.last() + "a" ) == curName ) )
Expand All @@ -994,32 +994,15 @@ QMap< QString, QStringList > QgsCptCityDirectoryItem::rampsMap()
}
else
{
num = schemeName.right( 3 ).toInt( &ok );
Q_UNUSED( num );
if ( ok )
QRegExp rxVariant( "^(.*[^\\d])(\\d{1,3})$" );
int pos = rxVariant.indexIn( schemeName );
if ( pos > -1 )
{
curName = schemeName.left( schemeName.size() - 3 );
curVariant = schemeName.right( 3 );
}
else
{
num = schemeName.right( 2 ).toInt( &ok );
if ( ok )
{
curName = schemeName.left( schemeName.size() - 2 );
curVariant = schemeName.right( 2 );
}
else
{
num = schemeName.right( 1 ).toInt( &ok );
if ( ok )
{
curName = schemeName.left( schemeName.size() - 1 );
curVariant = schemeName.right( 1 );
}
}
curName = rxVariant.cap( 1 );
curVariant = rxVariant.cap( 2 );
}
}

curSep = curName.right( 1 );
if ( curSep == "-" || curSep == "_" )
{
Expand Down
9 changes: 8 additions & 1 deletion src/core/symbology-ng/qgsfillsymbollayerv2.cpp
Expand Up @@ -1437,7 +1437,14 @@ void QgsShapeburstFillSymbolLayerV2::dtArrayToQImage( double * array, QImage *im
squaredVal = array[idx];

//scale result to fit in the range [0, 1]
pixVal = squaredVal > 0 ? qMin(( sqrt( squaredVal ) / maxDistanceValue ), 1.0 ) : 0;
if ( maxDistanceValue > 0 )
{
pixVal = squaredVal > 0 ? qMin(( sqrt( squaredVal ) / maxDistanceValue ), 1.0 ) : 0;
}
else
{
pixVal = 1.0;
}

//convert value to color from ramp
pixColor = ramp->color( pixVal );
Expand Down
5 changes: 5 additions & 0 deletions src/core/symbology-ng/qgsheatmaprenderer.cpp
Expand Up @@ -31,12 +31,17 @@

QgsHeatmapRenderer::QgsHeatmapRenderer( )
: QgsFeatureRendererV2( "heatmapRenderer" )
, mCalculatedMaxValue( 0 )
, mRadius( 10 )
, mRadiusPixels( 0 )
, mRadiusSquared( 0 )
, mRadiusUnit( QgsSymbolV2::MM )
, mWeightAttrNum( -1 )
, mGradientRamp( 0 )
, mInvertRamp( false )
, mExplicitMax( 0.0 )
, mRenderQuality( 1 )
, mFeaturesRendered( 0 )
{
mGradientRamp = new QgsVectorGradientColorRampV2( QColor( 255, 255, 255 ), QColor( 0, 0, 0 ) );

Expand Down
6 changes: 5 additions & 1 deletion src/gui/attributetable/qgsdualview.cpp
Expand Up @@ -154,7 +154,11 @@ void QgsDualView::columnBoxInit()

Q_FOREACH ( const QgsField& field, fields )
{
if ( mLayerCache->layer()->editorWidgetV2( mLayerCache->layer()->fieldNameIndex( field.name() ) ) != "Hidden" )
int fieldIndex = mLayerCache->layer()->fieldNameIndex( field.name() );
if ( fieldIndex == -1 )
continue;

if ( mLayerCache->layer()->editorWidgetV2( fieldIndex ) != "Hidden" )
{
QIcon icon = QgsApplication::getThemeIcon( "/mActionNewAttribute.png" );
QString text = field.name();
Expand Down
3 changes: 3 additions & 0 deletions src/gui/qgsattributeform.cpp
Expand Up @@ -421,6 +421,9 @@ void QgsAttributeForm::init()
Q_FOREACH ( const QgsField& field, mLayer->pendingFields().toList() )
{
int idx = mLayer->fieldNameIndex( field.name() );
if ( idx < 0 )
continue;

//show attribute alias if available
QString fieldName = mLayer->attributeDisplayName( idx );

Expand Down
3 changes: 3 additions & 0 deletions src/gui/qgscomposerruler.cpp
Expand Up @@ -234,6 +234,9 @@ void QgsComposerRuler::drawRotatedText( QPainter *painter, QPointF pos, const QS

void QgsComposerRuler::drawSmallDivisions( QPainter *painter, double startPos, int numDivisions, double rulerScale, double maxPos )
{
if ( numDivisions == 0 )
return;

//draw small divisions starting at startPos (in mm)
double smallMarkerPos = startPos;
double smallDivisionSpacing = rulerScale / numDivisions;
Expand Down
2 changes: 2 additions & 0 deletions src/gui/qgscomposerview.cpp
Expand Up @@ -49,6 +49,8 @@

QgsComposerView::QgsComposerView( QWidget* parent, const char* name, Qt::WindowFlags f )
: QGraphicsView( parent )
, mCurrentTool( Select )
, mPreviousTool( Select )
, mRubberBandItem( 0 )
, mRubberBandLineItem( 0 )
, mMoveContentItem( 0 )
Expand Down
5 changes: 5 additions & 0 deletions src/gui/qgsexpressionbuilderwidget.cpp
Expand Up @@ -274,6 +274,10 @@ void QgsExpressionBuilderWidget::fillFieldValues( int fieldIndex, int countLimit

// TODO We should thread this so that we don't hold the user up if the layer is massive.
mValueListWidget->clear();

if ( fieldIndex < 0 )
return;

mValueListWidget->setUpdatesEnabled( false );
mValueListWidget->blockSignals( true );

Expand Down Expand Up @@ -566,6 +570,7 @@ void QgsExpressionBuilderWidget::loadSampleValues()

mValueGroupBox->show();
int fieldIndex = mLayer->fieldNameIndex( item->text() );

fillFieldValues( fieldIndex, 10 );
}

Expand Down
2 changes: 2 additions & 0 deletions src/gui/qgsidentifymenu.h
Expand Up @@ -48,6 +48,7 @@ class GUI_EXPORT QgsIdentifyMenu : public QMenu
, mAllResults( false )
, mIsExternalAction( false )
, mLayer( NULL )
, mFeatureId( 0 )
, mLevel( LayerLevel )
, mMapLayerAction( NULL )
{}
Expand All @@ -57,6 +58,7 @@ class GUI_EXPORT QgsIdentifyMenu : public QMenu
, mAllResults( layer == 0 )
, mIsExternalAction( mapLayerAction != 0 )
, mLayer( layer )
, mFeatureId( 0 )
, mLevel( LayerLevel )
, mMapLayerAction( mapLayerAction )
{}
Expand Down
6 changes: 4 additions & 2 deletions src/gui/symbology-ng/qgsrulebasedrendererv2widget.cpp
Expand Up @@ -581,8 +581,10 @@ QgsRendererRulePropsDialog::QgsRendererRulePropsDialog( QgsRuleBasedRendererV2::
{
groupScale->setChecked( true );
// caution: rule uses scale denom, scale widget uses true scales
mScaleRangeWidget->setMaximumScale( 1.0 / rule->scaleMinDenom() );
mScaleRangeWidget->setMinimumScale( 1.0 / rule->scaleMaxDenom() );
if ( rule->scaleMinDenom() > 0 )
mScaleRangeWidget->setMaximumScale( 1.0 / rule->scaleMinDenom() );
if ( rule->scaleMaxDenom() > 0 )
mScaleRangeWidget->setMinimumScale( 1.0 / rule->scaleMaxDenom() );
}

if ( mRule->symbol() )
Expand Down
6 changes: 3 additions & 3 deletions src/plugins/heatmap/heatmap.cpp
Expand Up @@ -444,7 +444,7 @@ double Heatmap::quarticKernel( const double distance, const int bandwidth, const
case Heatmap::Scaled:
{
// Normalizing constant
double k = outputType == Heatmap::Scaled ? 116. / ( 5. * M_PI * pow(( double )bandwidth, 2 ) ) : 1.0;
double k = 116. / ( 5. * M_PI * pow(( double )bandwidth, 2 ) );

// Derived from Wand and Jones (1995), p. 175
return k * ( 15. / 16. ) * pow( 1. - pow( distance / ( double )bandwidth, 2 ), 2 );
Expand All @@ -461,7 +461,7 @@ double Heatmap::triweightKernel( const double distance, const int bandwidth, con
case Heatmap::Scaled:
{
// Normalizing constant
double k = outputType == Heatmap::Scaled ? 128. / ( 35. * M_PI * pow(( double )bandwidth, 2 ) ) : 1.0;
double k = 128. / ( 35. * M_PI * pow(( double )bandwidth, 2 ) );

// Derived from Wand and Jones (1995), p. 175
return k * ( 35. / 32. ) * pow( 1. - pow( distance / ( double )bandwidth, 2 ), 3 );
Expand All @@ -478,7 +478,7 @@ double Heatmap::epanechnikovKernel( const double distance, const int bandwidth,
case Heatmap::Scaled:
{
// Normalizing constant
double k = outputType == Heatmap::Scaled ? 8. / ( 3. * M_PI * pow(( double )bandwidth, 2 ) ) : 1.0;
double k = 8. / ( 3. * M_PI * pow(( double )bandwidth, 2 ) );

// Derived from Wand and Jones (1995), p. 175
return k * ( 3. / 4. ) * ( 1. - pow( distance / ( double )bandwidth, 2 ) );
Expand Down

0 comments on commit a7f7740

Please sign in to comment.