Skip to content

Commit 0c9e60f

Browse files
committedJan 17, 2012
attribute table: show progress only every 5s
1 parent 2e7867a commit 0c9e60f

File tree

5 files changed

+46
-34
lines changed

5 files changed

+46
-34
lines changed
 

‎src/app/qgsattributetabledialog.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -831,13 +831,9 @@ void QgsAttributeTableDialog::progress( int i, bool &cancel )
831831
}
832832

833833
mProgress->setValue( i );
834+
mProgress->setLabelText( tr( "%1 features loaded." ).arg( i ) );
834835

835-
if ( i > 0 && i % 5000 == 0 )
836-
{
837-
mProgress->setLabelText( tr( "%1 features loaded." ).arg( i ) );
838-
}
839-
840-
if ( !mProgress->isVisible() && mStarted.elapsed() > mProgress->minimumDuration()*5 / 4 )
836+
if ( !mProgress->isVisible() && mStarted.elapsed() > mProgress->minimumDuration()* 5 / 4 )
841837
{
842838
// for some reason this is sometimes necessary
843839
mProgress->show();

‎src/gui/attributetable/qgsattributetablememorymodel.cpp

100644100755
Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,22 +54,32 @@ void QgsAttributeTableMemoryModel::loadLayer()
5454
else
5555
mFeatureMap.reserve( mLayer->selectedFeatureCount() );
5656

57-
int n = 0;
57+
int i = 0;
58+
59+
QTime t;
60+
t.start();
5861

5962
QgsFeature f;
6063
while ( mLayer->nextFeature( f ) )
6164
{
6265
if ( behaviour == 1 && !mLayer->selectedFeaturesIds().contains( f.id() ) )
6366
continue;
6467

65-
mIdRowMap.insert( f.id(), n );
66-
mRowIdMap.insert( n, f.id() );
68+
mIdRowMap.insert( f.id(), i );
69+
mRowIdMap.insert( i, f.id() );
6770
mFeatureMap.insert( f.id(), f );
6871

69-
bool cancel = false;
70-
emit progress( n++, cancel );
71-
if ( cancel )
72-
break;
72+
i++;
73+
74+
if ( t.elapsed() > 5000 )
75+
{
76+
bool cancel = false;
77+
emit progress( i, cancel );
78+
if ( cancel )
79+
break;
80+
81+
t.restart();
82+
}
7383
}
7484

7585
emit finished();

‎src/gui/attributetable/qgsattributetablemodel.cpp

100644100755
Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -247,17 +247,27 @@ void QgsAttributeTableModel::loadLayer()
247247
int behaviour = settings.value( "/qgis/attributeTableBehaviour", 0 ).toInt();
248248
int i = 0;
249249

250+
QTime t;
251+
t.start();
252+
250253
if ( behaviour == 1 )
251254
{
252255
beginInsertRows( QModelIndex(), 0, mLayer->selectedFeatureCount() - 1 );
253256
foreach( QgsFeatureId fid, mLayer->selectedFeaturesIds() )
254257
{
255258
featureAdded( fid, false );
256259

257-
bool cancel = false;
258-
emit progress( i++, cancel );
259-
if ( cancel )
260-
break;
260+
i++;
261+
262+
if ( t.elapsed() > 5000 )
263+
{
264+
bool cancel = false;
265+
emit progress( i, cancel );
266+
if ( cancel )
267+
break;
268+
269+
t.restart();
270+
}
261271
}
262272
emit finished();
263273
endInsertRows();
@@ -278,10 +288,15 @@ void QgsAttributeTableModel::loadLayer()
278288
{
279289
featureAdded( f.id() );
280290

281-
bool cancel = false;
282-
emit progress( i, cancel );
283-
if ( cancel )
284-
break;
291+
if ( t.elapsed() > 5000 )
292+
{
293+
bool cancel = false;
294+
emit progress( i, cancel );
295+
if ( cancel )
296+
break;
297+
298+
t.restart();
299+
}
285300
}
286301
emit finished();
287302
}

‎src/gui/attributetable/qgsattributetableview.cpp

100644100755
Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,22 +74,16 @@ void QgsAttributeTableView::setCanvasAndLayer( QgsMapCanvas *canvas, QgsVectorLa
7474
mModel = new QgsAttributeTableMemoryModel( canvas, layer );
7575
}
7676

77-
connect( mModel, SIGNAL( finished() ), this, SLOT( setFilterModel() ) );
78-
79-
connect( mModel, SIGNAL( progress(int, bool&) ), this, SIGNAL( progress(int, bool&) ) );
77+
connect( mModel, SIGNAL( progress( int, bool& ) ), this, SIGNAL( progress( int, bool& ) ) );
8078
connect( mModel, SIGNAL( finished() ), this, SIGNAL( finished() ) );
8179
mModel->loadLayer();
8280

83-
delete oldModel;
84-
delete filterModel;
85-
}
86-
87-
void QgsAttributeTableView::setFilterModel()
88-
{
89-
disconnect( mModel, SIGNAL( finished() ), this, SLOT( setFilterModel() ) );
9081
mFilterModel = new QgsAttributeTableFilterModel( mModel->layer() );
9182
mFilterModel->setSourceModel( mModel );
9283
setModel( mFilterModel );
84+
85+
delete oldModel;
86+
delete filterModel;
9387
}
9488

9589
QgsAttributeTableView::~QgsAttributeTableView()

‎src/gui/attributetable/qgsattributetableview.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,6 @@ class GUI_EXPORT QgsAttributeTableView : public QTableView
5050

5151
void contextMenuEvent( QContextMenuEvent* );
5252

53-
public slots:
54-
void setFilterModel();
55-
5653
signals:
5754
void willShowContextMenu( QMenu* menu, QModelIndex atIndex );
5855

0 commit comments

Comments
 (0)
Please sign in to comment.