Skip to content
Permalink
Browse files

Setting field for QgsFieldComboBox should be case-insensitive

  • Loading branch information
nyalldawson committed Sep 22, 2017
1 parent c5b9fa2 commit b4a798e89212631807e22041b3ad277056e15d99
Showing with 25 additions and 1 deletion.
  1. +1 −1 src/core/qgsfieldmodel.cpp
  2. +24 −0 tests/src/python/test_qgsfieldmodel.py
@@ -47,7 +47,7 @@ QModelIndex QgsFieldModel::indexFromName( const QString &fieldName )
if ( mAllowEmpty && fieldName.isEmpty() )
return index( 0, 0 );

int r = mFields.indexFromName( fldName );
int r = mFields.lookupField( fldName );
if ( r >= 0 )
{
if ( mAllowEmpty )
@@ -69,6 +69,28 @@ def testIndexFromName(self):
i = m.indexFromName('not a field')
self.assertFalse(i.isValid())

# test with alias
i = m.indexFromName('text field')
self.assertFalse(i.isValid())
l.setFieldAlias(0, 'text field')
i = m.indexFromName('text field')
self.assertTrue(i.isValid())
self.assertEqual(i.row(), 0)
i = m.indexFromName('int field')
self.assertFalse(i.isValid())
l.setFieldAlias(1, 'int field')
i = m.indexFromName('int field')
self.assertTrue(i.isValid())
self.assertEqual(i.row(), 1)

# should be case insensitive
i = m.indexFromName('FLDTXT')
self.assertTrue(i.isValid())
self.assertEqual(i.row(), 0)
i = m.indexFromName('FLDINT')
self.assertTrue(i.isValid())
self.assertEqual(i.row(), 1)

# try with expression
m.setAllowExpression(True)
i = m.indexFromName('not a field')
@@ -90,6 +112,8 @@ def testIndexFromName(self):
self.assertEqual(m.indexFromName('fldtxt').row(), 1)
self.assertEqual(m.indexFromName('fldint').row(), 2)
self.assertEqual(m.indexFromName('not a field').row(), 3)
self.assertEqual(m.indexFromName('FLDTXT').row(), 1)
self.assertEqual(m.indexFromName('FLDINT').row(), 2)

def testIsField(self):
l, m = create_model()

0 comments on commit b4a798e

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