More coverity fixes

This commit is contained in:
Nyall Dawson 2015-02-10 17:37:17 +11:00
parent dc156c8d79
commit a7f774037a
31 changed files with 114 additions and 44 deletions

View File

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

View File

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

View File

@ -24,6 +24,8 @@
QgsMapToolMoveLabel::QgsMapToolMoveLabel( QgsMapCanvas* canvas )
: QgsMapToolLabel( canvas )
, mClickOffsetX( 0 )
, mClickOffsetY( 0 )
{
mToolName = tr( "Move label" );
}

View File

@ -194,6 +194,9 @@ void QgsMergeAttributesDialog::comboValueChanged( const QString &text )
return;
}
int column = findComboColumn( senderComboBox );
if ( column < 0 )
return;
refreshMergedValue( column );
}

View File

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

View File

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

View File

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

View File

@ -24,6 +24,7 @@ const QString QgsFeatureRequest::AllAttributes = QString( "#!allattributes!#" );
QgsFeatureRequest::QgsFeatureRequest()
: mFilter( FilterNone )
, mFilterFid( -1 )
, mFilterExpression( 0 )
, mFlags( 0 )
{

View File

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

View File

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

View File

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

View File

@ -47,6 +47,7 @@ QgsMessageOutput::~QgsMessageOutput()
QgsMessageOutputConsole::QgsMessageOutputConsole()
: mMessage( "" )
, mMsgType( MessageText )
{
}

View File

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

View File

@ -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 )
{
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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 )
{}

View File

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

View File

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

View File

@ -281,6 +281,18 @@ QgsGraph* RgShortestPathWidget::getPath( QgsPoint& p1, QgsPoint& p2 )
QgsGraph *graph = builder.graph();
int startVertexIdx = graph->findVertex( p1 );
if ( startVertexIdx < 0 )
{
mPlugin->iface()->messageBar()->pushMessage(
tr( "Cannot calculate path" ),
tr( "Could not find start vertex. Please check your input data." ),
QgsMessageBar::WARNING,
mPlugin->iface()->messageTimeout()
);
delete graph;
return NULL;
}
int criterionNum = 0;
if ( mCriterionName->currentIndex() > 0 )
@ -328,6 +340,9 @@ void RgShortestPathWidget::findingPath()
QList< QgsPoint > p;
while ( startVertexIdx != stopVertexIdx )
{
if ( stopVertexIdx < 0 )
break;
QgsGraphArcIdList l = path->vertex( stopVertexIdx ).inArc();
if ( l.empty() )
break;
@ -399,6 +414,9 @@ void RgShortestPathWidget::exportPath()
QgsPolyline p;
while ( startVertexIdx != stopVertexIdx )
{
if ( stopVertexIdx < 0 )
break;
QgsGraphArcIdList l = path->vertex( stopVertexIdx ).inArc();
if ( l.empty() )
break;

View File

@ -62,7 +62,7 @@ class QgsMssqlConnectionItem : public QgsDataCollectionItem
virtual bool handleDrop( const QMimeData * data, Qt::DropAction action ) override;
void refresh() override;
QString connInfo() const { return mConnInfo; };
QString connInfo() const { return mConnInfo; }
signals:
void addGeometryColumn( QgsMssqlLayerProperty );
@ -98,7 +98,7 @@ class QgsMssqlSchemaItem : public QgsDataCollectionItem
QVector<QgsDataItem*> createChildren() override;
QgsMssqlLayerItem* addLayer( QgsMssqlLayerProperty layerProperty, bool refresh );
void refresh() override {}; // do not refresh directly
void refresh() override {} // do not refresh directly
void addLayers( QgsDataItem* newLayers );
};
@ -113,7 +113,6 @@ class QgsMssqlLayerItem : public QgsLayerItem
QString createUri();
QgsMssqlLayerItem* createClone();
bool Used;
private:
QgsMssqlLayerProperty mLayerProperty;

View File

@ -5341,13 +5341,11 @@ QGISEXTERN bool saveStyle( const QString& uri, const QString& qmlStyle, const QS
return false;
}
bool saved = ( SQLITE_OK == ret ) ? true : false;
if ( NULL != errMsg )
sqlite3_free( errMsg );
QgsSqliteHandle::closeDb( handle );
return saved;
return true;
}

View File

@ -79,6 +79,7 @@ QgsWcsCapabilities::QgsWcsCapabilities()
: mCapabilities()
, mCapabilitiesReply( NULL )
, mCoverageCount( 0 )
, mCacheLoadControl( QNetworkRequest::PreferNetwork )
{
}

View File

@ -213,7 +213,7 @@ QgsRasterLayer* QgsRemoteOWSBuilder::wmsLayerFromUrl( const QString& url, const
uri.setParam( "crs", crs );
uri.setParam( "layers", layerList );
uri.setParam( "styles", styleList );
result = new QgsRasterLayer( uri.encodedUri(), "", "wms" );
result = new QgsRasterLayer( uri.encodedUri(), "", QString( "wms" ) );
if ( !result->isValid() )
{
return 0;