[attribute table] fix long UI freeze when resizing columns for large filtered datasets (#6341)

This commit is contained in:
Mathieu Pellerin 2018-02-14 21:25:43 +07:00 committed by GitHub
parent a817d0e8fb
commit 543e4f0dd1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 70 additions and 1 deletions

View File

@ -179,6 +179,12 @@ Get the sort order
Set the sort order
.. versionadded:: 2.16
%End
bool hasSameColumns( const QgsAttributeTableConfig &other ) const;
%Docstring
Compare this configuration's columns name, type, and order to ``other``.
The column's width is not considered.
%End
bool operator!= ( const QgsAttributeTableConfig &other ) const;

View File

@ -283,6 +283,25 @@ void QgsAttributeTableConfig::writeXml( QDomNode &node ) const
node.appendChild( configElement );
}
bool QgsAttributeTableConfig::hasSameColumns( const QgsAttributeTableConfig &other ) const
{
if ( columns().size() == other.columns().size() )
{
for ( int i = 0; i < columns().size(); i++ )
{
if ( columns().at( i ).name != other.columns().at( i ).name ||
columns().at( i ).type != other.columns().at( i ).type ||
columns().at( i ).hidden != other.columns().at( i ).hidden )
{
return false;
}
}
return true;
}
return false;
}
bool QgsAttributeTableConfig::ColumnConfig::operator== ( const ColumnConfig &other ) const
{
return type == other.type && name == other.name && hidden == other.hidden && width == other.width;

View File

@ -190,6 +190,12 @@ class CORE_EXPORT QgsAttributeTableConfig
*/
void setSortOrder( Qt::SortOrder sortOrder );
/**
* Compare this configuration's columns name, type, and order to \a other.
* The column's width is not considered.
*/
bool hasSameColumns( const QgsAttributeTableConfig &other ) const;
/**
* Compare this configuration to other.
*/

View File

@ -131,11 +131,16 @@ int QgsAttributeTableFilterModel::columnCount( const QModelIndex &parent ) const
void QgsAttributeTableFilterModel::setAttributeTableConfig( const QgsAttributeTableConfig &config )
{
QgsAttributeTableConfig oldConfig = mConfig;
mConfig = config;
mConfig.update( layer()->fields() );
QVector<int> newColumnMapping;
if ( mConfig.hasSameColumns( oldConfig ) )
{
return;
}
QVector<int> newColumnMapping;
Q_FOREACH ( const QgsAttributeTableConfig::ColumnConfig &columnConfig, mConfig.columns() )
{
// Hidden? Forget about this column

View File

@ -109,6 +109,39 @@ class TestQgsAttributeTableConfig(unittest.TestCase):
self.assertFalse(config.columnHidden(0))
self.assertTrue(config.columnHidden(1))
def testSameColumns(self):
""" test hasSameColumns() check """
config = QgsAttributeTableConfig()
c1 = QgsAttributeTableConfig.ColumnConfig()
c1.name = 'test'
c1.hidden = False
c1.width = 100
c2 = QgsAttributeTableConfig.ColumnConfig()
c2.name = 'test2'
c2.hidden = False
c2.width = 120
config.setColumns([c1, c2])
config2 = QgsAttributeTableConfig()
config2.setColumns([c1, c2])
self.assertTrue(config.hasSameColumns(config2))
c1.width = 200
config2.setColumns([c1, c2])
self.assertTrue(config.hasSameColumns(config2))
c1.hidden = True
config2.setColumns([c1, c2])
self.assertFalse(config.hasSameColumns(config2))
config2.setColumns([c2, c1])
self.assertFalse(config.hasSameColumns(config2))
c2.name = 'test3'
config2.setColumns([c1, c2])
self.assertFalse(config.hasSameColumns(config2))
def testMapVisibleColumn(self):
pass