Skip to content

Commit

Permalink
validate attribute index in editor widget calls
Browse files Browse the repository at this point in the history
  • Loading branch information
jef-n committed May 28, 2015
1 parent d0bd9a2 commit ecbe0e4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/app/pluginmanager/qgspluginitemdelegate.cpp
Expand Up @@ -69,7 +69,7 @@ void QgsPluginItemDelegate::paint( QPainter *painter, const QStyleOptionViewItem
if ( !iconPixmap.isNull() )
{
int iconSize = pixelsHigh;
painter->drawPixmap( option.rect.left() + 1.2 * pixelsHigh , option.rect.top() + 0.2 * pixelsHigh, iconSize, iconSize, iconPixmap );
painter->drawPixmap( option.rect.left() + 1.2 * pixelsHigh, option.rect.top() + 0.2 * pixelsHigh, iconSize, iconSize, iconPixmap );
}

// Draw the text
Expand Down
27 changes: 21 additions & 6 deletions src/core/qgsvectorlayer.cpp
Expand Up @@ -2124,6 +2124,9 @@ const QString QgsVectorLayer::editorWidgetV2( const QString& fieldName ) const

const QgsEditorWidgetConfig QgsVectorLayer::editorWidgetV2Config( int fieldIdx ) const
{
if ( fieldIdx < 0 || fieldIdx >= mUpdatedFields.count() )
return QgsEditorWidgetConfig();

return mEditorWidgetV2Configs.value( mUpdatedFields[fieldIdx].name() );
}

Expand Down Expand Up @@ -2182,7 +2185,7 @@ bool QgsVectorLayer::deleteAttributes( QList<int> attrs )

qSort( attrs.begin(), attrs.end(), qGreater<int>() );

Q_FOREACH ( int attr, attrs )
Q_FOREACH( int attr, attrs )
{
if ( deleteAttribute( attr ) )
{
Expand Down Expand Up @@ -2622,13 +2625,19 @@ bool QgsVectorLayer::isModified() const

QgsVectorLayer::EditType QgsVectorLayer::editType( int idx )
{
if ( idx < 0 || idx >= mUpdatedFields.count() )
return Hidden;

Q_NOWARN_DEPRECATED_PUSH
return QgsLegacyHelpers::convertEditType( editorWidgetV2( idx ), editorWidgetV2Config( idx ), this, mUpdatedFields[ idx ].name() );
Q_NOWARN_DEPRECATED_POP
}

void QgsVectorLayer::setEditType( int idx, EditType type )
{
if ( idx < 0 || idx >= mUpdatedFields.count() )
return;

QgsEditorWidgetConfig cfg;

Q_NOWARN_DEPRECATED_PUSH
Expand All @@ -2651,11 +2660,17 @@ void QgsVectorLayer::setEditorLayout( EditorLayout editorLayout )

void QgsVectorLayer::setEditorWidgetV2( int attrIdx, const QString& widgetType )
{
if ( attrIdx < 0 || attrIdx >= mUpdatedFields.count() )
return;

mEditorWidgetV2Types[ mUpdatedFields[ attrIdx ].name()] = widgetType;
}

void QgsVectorLayer::setEditorWidgetV2Config( int attrIdx, const QgsEditorWidgetConfig& config )
{
if ( attrIdx < 0 || attrIdx >= mUpdatedFields.count() )
return;

mEditorWidgetV2Configs[ mUpdatedFields[ attrIdx ].name()] = config;
}

Expand Down Expand Up @@ -2940,7 +2955,7 @@ void QgsVectorLayer::uniqueValues( int index, QList<QVariant> &uniqueValues, int
if ( mEditBuffer )
{
QSet<QString> vals;
Q_FOREACH ( const QVariant& v, uniqueValues )
Q_FOREACH( const QVariant& v, uniqueValues )
{
vals << v.toString();
}
Expand Down Expand Up @@ -3748,7 +3763,7 @@ void QgsVectorLayer::invalidateSymbolCountedFlag()

void QgsVectorLayer::onRelationsLoaded()
{
Q_FOREACH ( QgsAttributeEditorElement* elem, mAttributeEditorElements )
Q_FOREACH( QgsAttributeEditorElement* elem, mAttributeEditorElements )
{
if ( elem->type() == QgsAttributeEditorElement::AeTypeContainer )
{
Expand All @@ -3757,7 +3772,7 @@ void QgsVectorLayer::onRelationsLoaded()
continue;

QList<QgsAttributeEditorElement*> relations = cont->findElements( QgsAttributeEditorElement::AeTypeRelation );
Q_FOREACH ( QgsAttributeEditorElement* relElem, relations )
Q_FOREACH( QgsAttributeEditorElement* relElem, relations )
{
QgsAttributeEditorRelation* rel = dynamic_cast< QgsAttributeEditorRelation* >( relElem );
if ( !rel )
Expand Down Expand Up @@ -3826,7 +3841,7 @@ QDomElement QgsAttributeEditorContainer::toDomElement( QDomDocument& doc ) const
QDomElement elem = doc.createElement( "attributeEditorContainer" );
elem.setAttribute( "name", mName );

Q_FOREACH ( QgsAttributeEditorElement* child, mChildren )
Q_FOREACH( QgsAttributeEditorElement* child, mChildren )
{
elem.appendChild( child->toDomElement( doc ) );
}
Expand All @@ -3842,7 +3857,7 @@ QList<QgsAttributeEditorElement*> QgsAttributeEditorContainer::findElements( Qgs
{
QList<QgsAttributeEditorElement*> results;

Q_FOREACH ( QgsAttributeEditorElement* elem, mChildren )
Q_FOREACH( QgsAttributeEditorElement* elem, mChildren )
{
if ( elem->type() == type )
{
Expand Down

0 comments on commit ecbe0e4

Please sign in to comment.