void TestQgsFields::indexFromName() { QgsFields fields; QgsField field( QString( "testfield" ) ); fields.append( field ); QgsField field2( QString( "testfield2" ) ); fields.append( field2 ); QgsField field3( QString( "testfield3" ) ); fields.append( field3 ); QCOMPARE( fields.indexFromName( QString( "bad" ) ), -1 ); QCOMPARE( fields.fieldNameIndex( QString( "bad" ) ), -1 ); QCOMPARE( fields.indexFromName( QString( "testfield" ) ), 0 ); QCOMPARE( fields.fieldNameIndex( QString( "testfield" ) ), 0 ); QCOMPARE( fields.indexFromName( QString( "testfield3" ) ), 2 ); QCOMPARE( fields.fieldNameIndex( QString( "testfield3" ) ), 2 ); //indexFromName is case sensitive, fieldNameIndex isn't QCOMPARE( fields.indexFromName( QString( "teStFiEld2" ) ), -1 ); QCOMPARE( fields.fieldNameIndex( QString( "teStFiEld2" ) ), 1 ); //test that fieldNameIndex prefers exact case matches over case insensitive matches QgsField sameNameDifferentCase( QString( "teStFielD" ) ); fields.append( sameNameDifferentCase ); QCOMPARE( fields.fieldNameIndex( QString( "teStFielD" ) ), 3 ); }
void QgsGraduatedSymbolRendererV2::startRender( QgsRenderContext& context, const QgsFields& fields ) { // find out classification attribute index from name mAttrNum = fields.fieldNameIndex( mAttrName ); if ( mAttrNum == -1 ) { mExpression.reset( new QgsExpression( mAttrName ) ); mExpression->prepare( fields ); } QgsRangeList::iterator it = mRanges.begin(); for ( ; it != mRanges.end(); ++it ) { it->symbol()->startRender( context, &fields ); if ( mRotation.data() || mSizeScale.data() ) { QgsSymbolV2* tempSymbol = it->symbol()->clone(); tempSymbol->setRenderHints(( mRotation.data() ? QgsSymbolV2::DataDefinedRotation : 0 ) | ( mSizeScale.data() ? QgsSymbolV2::DataDefinedSizeScale : 0 ) ); tempSymbol->startRender( context, &fields ); mTempSymbols[ it->symbol()] = tempSymbol; } } }
void QgsPointDisplacementRenderer::startRender( QgsRenderContext& context, const QgsFields& fields ) { mRenderer->startRender( context, fields ); mDisplacementGroups.clear(); mGroupIndex.clear(); mSpatialIndex = new QgsSpatialIndex; mSelectedFeatures.clear(); if ( mLabelAttributeName.isEmpty() ) { mLabelIndex = -1; } else { mLabelIndex = fields.fieldNameIndex( mLabelAttributeName ); } if ( mMaxLabelScaleDenominator > 0 && context.rendererScale() > mMaxLabelScaleDenominator ) { mDrawLabels = false; } else { mDrawLabels = true; } if ( mCenterSymbol ) { mCenterSymbol->startRender( context, &fields ); } return; }
void QgsCategorizedSymbolRendererV2::startRender( QgsRenderContext& context, const QgsFields& fields ) { // make sure that the hash table is up to date rebuildHash(); // find out classification attribute index from name mAttrNum = fields.fieldNameIndex( mAttrName ); if ( mAttrNum == -1 ) { mExpression.reset( new QgsExpression( mAttrName ) ); mExpression->prepare( fields ); } QgsCategoryList::iterator it = mCategories.begin(); for ( ; it != mCategories.end(); ++it ) { it->symbol()->startRender( context, &fields ); if ( mRotation.data() || mSizeScale.data() ) { QgsSymbolV2* tempSymbol = it->symbol()->clone(); tempSymbol->setRenderHints(( mRotation.data() ? QgsSymbolV2::DataDefinedRotation : 0 ) | ( mSizeScale.data() ? QgsSymbolV2::DataDefinedSizeScale : 0 ) ); tempSymbol->startRender( context, &fields ); mTempSymbols[ it->value().toString()] = tempSymbol; } } }
void QgsCategorizedSymbolRendererV2::startRender( QgsRenderContext& context, const QgsFields& fields ) { mCounting = context.rendererScale() == 0.0; // make sure that the hash table is up to date rebuildHash(); // find out classification attribute index from name mAttrNum = fields.fieldNameIndex( mAttrName ); if ( mAttrNum == -1 ) { mExpression.reset( new QgsExpression( mAttrName ) ); mExpression->prepare( &context.expressionContext() ); } Q_FOREACH ( const QgsRendererCategoryV2& cat, mCategories ) { cat.symbol()->startRender( context, &fields ); if ( mRotation.data() || mSizeScale.data() ) { QgsSymbolV2* tempSymbol = cat.symbol()->clone(); tempSymbol->setRenderHints(( mRotation.data() ? QgsSymbolV2::DataDefinedRotation : 0 ) | ( mSizeScale.data() ? QgsSymbolV2::DataDefinedSizeScale : 0 ) ); tempSymbol->startRender( context, &fields ); mTempSymbols[ cat.symbol()] = tempSymbol; } }
void TestQgsFields::indexFromName() { QgsFields fields; QgsField field( QString( "testfield" ) ); fields.append( field ); QgsField field2( QString( "testfield2" ) ); fields.append( field2 ); QgsField field3( QString( "testfield3" ) ); fields.append( field3 ); QCOMPARE( fields.indexFromName( QString( "bad" ) ), -1 ); QCOMPARE( fields.fieldNameIndex( QString( "bad" ) ), -1 ); QCOMPARE( fields.indexFromName( QString( "testfield" ) ), 0 ); QCOMPARE( fields.fieldNameIndex( QString( "testfield" ) ), 0 ); QCOMPARE( fields.indexFromName( QString( "testfield3" ) ), 2 ); QCOMPARE( fields.fieldNameIndex( QString( "testfield3" ) ), 2 ); //indexFromName is case sensitive, fieldNameIndex isn't QCOMPARE( fields.indexFromName( QString( "teStFiEld2" ) ), -1 ); QCOMPARE( fields.fieldNameIndex( QString( "teStFiEld2" ) ), 1 ); }
void QgsAttributeTableConfig::update( const QgsFields& fields ) { QStringList columns; bool containsActionColumn = false; for ( int i = mColumns.count() - 1; i >= 0; --i ) { const ColumnConfig& column = mColumns.at( i ); if ( column.type == Field ) { if ( fields.fieldNameIndex( column.name ) == -1 ) { mColumns.remove( i ); } else { columns.append( column.name ); } } else if ( column.type == Action ) { containsActionColumn = true; } } Q_FOREACH ( const QgsField& field, fields ) { if ( !columns.contains( field.name() ) ) { ColumnConfig newColumn; newColumn.hidden = false; newColumn.type = Field; newColumn.name = field.name(); mColumns.append( newColumn ); } } if ( !containsActionColumn ) { ColumnConfig actionConfig; actionConfig.type = Action; actionConfig.hidden = true; mColumns.append( actionConfig ); } }
void QgsHeatmapRenderer::startRender( QgsRenderContext& context, const QgsFields& fields ) { Q_UNUSED( fields ); if ( !context.painter() ) { return; } // find out classification attribute index from name mWeightAttrNum = fields.fieldNameIndex( mWeightExpressionString ); if ( mWeightAttrNum == -1 ) { mWeightExpression.reset( new QgsExpression( mWeightExpressionString ) ); mWeightExpression->prepare( fields ); } initializeValues( context ); }
void QgsVectorFieldSymbolLayer::startRender( QgsSymbolRenderContext& context ) { if ( mLineSymbol ) { mLineSymbol->startRender( context.renderContext(), context.fields() ); } QgsFields fields = context.fields(); if ( !fields.isEmpty() ) { mXIndex = fields.fieldNameIndex( mXAttribute ); mYIndex = fields.fieldNameIndex( mYAttribute ); } else { mXIndex = -1; mYIndex = -1; } }