Skip to content
Permalink
Browse files

Ensure that attribute table config is always initially populated

  • Loading branch information
nyalldawson authored and m-kuhn committed Jun 7, 2016
1 parent e0d6c3f commit 5301a97f8174d0d0929df796b81cc09c3f6c5965
@@ -127,8 +127,6 @@ QgsAttributeTableDialog::QgsAttributeTableDialog( QgsVectorLayer *theLayer, QWid
mMainView->init( mLayer, QgisApp::instance()->mapCanvas(), r, mEditorContext );

QgsAttributeTableConfig config = mLayer->attributeTableConfig();
if ( config.isEmpty() )
config.update( mLayer->fields() );
mMainView->setAttributeTableConfig( config );

// Initialize filter gui elements
@@ -3751,7 +3751,12 @@ void QgsVectorLayer::readSldLabeling( const QDomNode& node )

QgsAttributeTableConfig QgsVectorLayer::attributeTableConfig() const
{
return mAttributeTableConfig;
QgsAttributeTableConfig config = mAttributeTableConfig;

if ( config.isEmpty() )
config.update( fields() );

return config;
}

void QgsVectorLayer::setAttributeTableConfig( const QgsAttributeTableConfig& attributeTableConfig )
@@ -13,6 +13,7 @@ ADD_PYTHON_TEST(PyQgsAnalysis test_qgsanalysis.py)
ADD_PYTHON_TEST(PyQgsApplication test_qgsapplication.py)
ADD_PYTHON_TEST(PyQgsAtlasComposition test_qgsatlascomposition.py)
ADD_PYTHON_TEST(PyQgsAttributeFormEditorWidget test_qgsattributeformeditorwidget.py)
ADD_PYTHON_TEST(PyQgsAttributeTableConfig test_qgsattributetableconfig.py)
ADD_PYTHON_TEST(PyQgsAttributeTableModel test_qgsattributetablemodel.py)
#ADD_PYTHON_TEST(PyQgsAuthenticationSystem test_qgsauthsystem.py)
ADD_PYTHON_TEST(PyQgsBlendModes test_qgsblendmodes.py)
@@ -0,0 +1,51 @@
# -*- coding: utf-8 -*-
"""QGIS Unit tests for QgsAttributeTableConfig.
.. note:: This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
"""
__author__ = 'Nyall Dawson'
__date__ = '07/06/2016'
__copyright__ = 'Copyright 2016, The QGIS Project'
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

import qgis # NOQA

from qgis.core import (QgsAttributeTableConfig,
QgsVectorLayer
)
from qgis.testing import start_app, unittest

start_app()


class TestQgsAttributeTableConfig(unittest.TestCase):

def testLayerConfig(self):
""" test retrieving attribute table config from a layer """

# make a layer
point_layer = QgsVectorLayer("Point?field=fldtxt:string&field=fldint:integer",
"pointlayer", "memory")

# make sure attribute table config is initially populated
config = point_layer.attributeTableConfig()
self.assertFalse(config.isEmpty())
self.assertEqual(config.columns()[0].name, 'fldtxt')
self.assertEqual(config.columns()[1].name, 'fldint')

# try replacing it
config.setColumns([config.columns()[1], config.columns()[0]])
point_layer.setAttributeTableConfig(config)

# and make sure changes were applied
config = point_layer.attributeTableConfig()
self.assertFalse(config.isEmpty())
self.assertEqual(config.columns()[0].name, 'fldint')
self.assertEqual(config.columns()[1].name, 'fldtxt')

if __name__ == '__main__':
unittest.main()

0 comments on commit 5301a97

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