Skip to content

Commit 543e4f0

Browse files
authoredFeb 14, 2018
[attribute table] fix long UI freeze when resizing columns for large filtered datasets (#6341)
1 parent a817d0e commit 543e4f0

File tree

5 files changed

+70
-1
lines changed

5 files changed

+70
-1
lines changed
 

‎python/core/qgsattributetableconfig.sip.in

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,12 @@ Get the sort order
179179
Set the sort order
180180

181181
.. versionadded:: 2.16
182+
%End
183+
184+
bool hasSameColumns( const QgsAttributeTableConfig &other ) const;
185+
%Docstring
186+
Compare this configuration's columns name, type, and order to ``other``.
187+
The column's width is not considered.
182188
%End
183189

184190
bool operator!= ( const QgsAttributeTableConfig &other ) const;

‎src/core/qgsattributetableconfig.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,25 @@ void QgsAttributeTableConfig::writeXml( QDomNode &node ) const
283283
node.appendChild( configElement );
284284
}
285285

286+
bool QgsAttributeTableConfig::hasSameColumns( const QgsAttributeTableConfig &other ) const
287+
{
288+
if ( columns().size() == other.columns().size() )
289+
{
290+
for ( int i = 0; i < columns().size(); i++ )
291+
{
292+
if ( columns().at( i ).name != other.columns().at( i ).name ||
293+
columns().at( i ).type != other.columns().at( i ).type ||
294+
columns().at( i ).hidden != other.columns().at( i ).hidden )
295+
{
296+
return false;
297+
}
298+
}
299+
return true;
300+
}
301+
302+
return false;
303+
}
304+
286305
bool QgsAttributeTableConfig::ColumnConfig::operator== ( const ColumnConfig &other ) const
287306
{
288307
return type == other.type && name == other.name && hidden == other.hidden && width == other.width;

‎src/core/qgsattributetableconfig.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,12 @@ class CORE_EXPORT QgsAttributeTableConfig
190190
*/
191191
void setSortOrder( Qt::SortOrder sortOrder );
192192

193+
/**
194+
* Compare this configuration's columns name, type, and order to \a other.
195+
* The column's width is not considered.
196+
*/
197+
bool hasSameColumns( const QgsAttributeTableConfig &other ) const;
198+
193199
/**
194200
* Compare this configuration to other.
195201
*/

‎src/gui/attributetable/qgsattributetablefiltermodel.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,16 @@ int QgsAttributeTableFilterModel::columnCount( const QModelIndex &parent ) const
131131

132132
void QgsAttributeTableFilterModel::setAttributeTableConfig( const QgsAttributeTableConfig &config )
133133
{
134+
QgsAttributeTableConfig oldConfig = mConfig;
134135
mConfig = config;
135136
mConfig.update( layer()->fields() );
136137

137-
QVector<int> newColumnMapping;
138+
if ( mConfig.hasSameColumns( oldConfig ) )
139+
{
140+
return;
141+
}
138142

143+
QVector<int> newColumnMapping;
139144
Q_FOREACH ( const QgsAttributeTableConfig::ColumnConfig &columnConfig, mConfig.columns() )
140145
{
141146
// Hidden? Forget about this column

‎tests/src/python/test_qgsattributetableconfig.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,39 @@ def testColumnHidden(self):
109109
self.assertFalse(config.columnHidden(0))
110110
self.assertTrue(config.columnHidden(1))
111111

112+
def testSameColumns(self):
113+
""" test hasSameColumns() check """
114+
115+
config = QgsAttributeTableConfig()
116+
c1 = QgsAttributeTableConfig.ColumnConfig()
117+
c1.name = 'test'
118+
c1.hidden = False
119+
c1.width = 100
120+
c2 = QgsAttributeTableConfig.ColumnConfig()
121+
c2.name = 'test2'
122+
c2.hidden = False
123+
c2.width = 120
124+
config.setColumns([c1, c2])
125+
config2 = QgsAttributeTableConfig()
126+
127+
config2.setColumns([c1, c2])
128+
self.assertTrue(config.hasSameColumns(config2))
129+
130+
c1.width = 200
131+
config2.setColumns([c1, c2])
132+
self.assertTrue(config.hasSameColumns(config2))
133+
134+
c1.hidden = True
135+
config2.setColumns([c1, c2])
136+
self.assertFalse(config.hasSameColumns(config2))
137+
138+
config2.setColumns([c2, c1])
139+
self.assertFalse(config.hasSameColumns(config2))
140+
141+
c2.name = 'test3'
142+
config2.setColumns([c1, c2])
143+
self.assertFalse(config.hasSameColumns(config2))
144+
112145
def testMapVisibleColumn(self):
113146
pass
114147

0 commit comments

Comments
 (0)
Please sign in to comment.