Skip to content
Permalink
Browse files

[attribute table] fix long UI freeze when resizing columns for large …

…filtered datasets (#6341)
  • Loading branch information
nirvn committed Feb 14, 2018
1 parent a817d0e commit 543e4f0dd1135a13cd700bb1f9ab57a906a0ce3a
@@ -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;
@@ -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;
@@ -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.
*/
@@ -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
@@ -109,6 +109,39 @@ def testColumnHidden(self):
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

0 comments on commit 543e4f0

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