Skip to content
Permalink
Browse files

More coverity fixes

  • Loading branch information
nyalldawson committed Feb 10, 2015
1 parent dc156c8 commit a7f774037a8e500db55a16179a017fa2ff7f95d6
@@ -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();
@@ -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 );

@@ -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
@@ -24,6 +24,8 @@

QgsMapToolMoveLabel::QgsMapToolMoveLabel( QgsMapCanvas* canvas )
: QgsMapToolLabel( canvas )
, mClickOffsetX( 0 )
, mClickOffsetY( 0 )
{
mToolName = tr( "Move label" );
}
@@ -194,6 +194,9 @@ void QgsMergeAttributesDialog::comboValueChanged( const QString &text )
return;
}
int column = findComboColumn( senderComboBox );
if ( column < 0 )
return;

refreshMergedValue( column );
}

@@ -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 );
@@ -39,6 +39,7 @@ extern "C"

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

QgsCoordinateTransform::QgsCoordinateTransform( const QgsCoordinateReferenceSystem& source, const QgsCoordinateReferenceSystem& dest )
: QObject()
, mShortCircuit( false )
, mInitialisedFlag( false )
, mSourceProjection( 0 )
, mDestinationProjection( 0 )
@@ -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
@@ -24,6 +24,7 @@ const QString QgsFeatureRequest::AllAttributes = QString( "#!allattributes!#" );

QgsFeatureRequest::QgsFeatureRequest()
: mFilter( FilterNone )
, mFilterFid( -1 )
, mFilterExpression( 0 )
, mFlags( 0 )
{
@@ -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 );
}
@@ -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;
@@ -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; }

@@ -261,6 +261,7 @@ class CORE_EXPORT QgsFields

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

};


@@ -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;
}

@@ -47,6 +47,7 @@ QgsMessageOutput::~QgsMessageOutput()

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

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

@@ -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 )
{
}
@@ -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;
@@ -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 ) )
@@ -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 == "_" )
{
@@ -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 );
@@ -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 ) );

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

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

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

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

fillFieldValues( fieldIndex, 10 );
}

@@ -48,6 +48,7 @@ class GUI_EXPORT QgsIdentifyMenu : public QMenu
, mAllResults( false )
, mIsExternalAction( false )
, mLayer( NULL )
, mFeatureId( 0 )
, mLevel( LayerLevel )
, mMapLayerAction( NULL )
{}
@@ -57,6 +58,7 @@ class GUI_EXPORT QgsIdentifyMenu : public QMenu
, mAllResults( layer == 0 )
, mIsExternalAction( mapLayerAction != 0 )
, mLayer( layer )
, mFeatureId( 0 )
, mLevel( LayerLevel )
, mMapLayerAction( mapLayerAction )
{}
@@ -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() )
@@ -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 );
@@ -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 );
@@ -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 ) );

0 comments on commit a7f7740

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