attribute table: show progress only every 5s

This commit is contained in:
Juergen E. Fischer 2012-01-17 14:50:14 +01:00
parent 2e7867a14e
commit 0c9e60fb69
5 changed files with 46 additions and 34 deletions

View File

@ -831,13 +831,9 @@ void QgsAttributeTableDialog::progress( int i, bool &cancel )
}
mProgress->setValue( i );
mProgress->setLabelText( tr( "%1 features loaded." ).arg( i ) );
if ( i > 0 && i % 5000 == 0 )
{
mProgress->setLabelText( tr( "%1 features loaded." ).arg( i ) );
}
if ( !mProgress->isVisible() && mStarted.elapsed() > mProgress->minimumDuration()*5 / 4 )
if ( !mProgress->isVisible() && mStarted.elapsed() > mProgress->minimumDuration()* 5 / 4 )
{
// for some reason this is sometimes necessary
mProgress->show();

24
src/gui/attributetable/qgsattributetablememorymodel.cpp Normal file → Executable file
View File

@ -54,7 +54,10 @@ void QgsAttributeTableMemoryModel::loadLayer()
else
mFeatureMap.reserve( mLayer->selectedFeatureCount() );
int n = 0;
int i = 0;
QTime t;
t.start();
QgsFeature f;
while ( mLayer->nextFeature( f ) )
@ -62,14 +65,21 @@ void QgsAttributeTableMemoryModel::loadLayer()
if ( behaviour == 1 && !mLayer->selectedFeaturesIds().contains( f.id() ) )
continue;
mIdRowMap.insert( f.id(), n );
mRowIdMap.insert( n, f.id() );
mIdRowMap.insert( f.id(), i );
mRowIdMap.insert( i, f.id() );
mFeatureMap.insert( f.id(), f );
bool cancel = false;
emit progress( n++, cancel );
if ( cancel )
break;
i++;
if ( t.elapsed() > 5000 )
{
bool cancel = false;
emit progress( i, cancel );
if ( cancel )
break;
t.restart();
}
}
emit finished();

31
src/gui/attributetable/qgsattributetablemodel.cpp Normal file → Executable file
View File

@ -247,6 +247,9 @@ void QgsAttributeTableModel::loadLayer()
int behaviour = settings.value( "/qgis/attributeTableBehaviour", 0 ).toInt();
int i = 0;
QTime t;
t.start();
if ( behaviour == 1 )
{
beginInsertRows( QModelIndex(), 0, mLayer->selectedFeatureCount() - 1 );
@ -254,10 +257,17 @@ void QgsAttributeTableModel::loadLayer()
{
featureAdded( fid, false );
bool cancel = false;
emit progress( i++, cancel );
if ( cancel )
break;
i++;
if ( t.elapsed() > 5000 )
{
bool cancel = false;
emit progress( i, cancel );
if ( cancel )
break;
t.restart();
}
}
emit finished();
endInsertRows();
@ -278,10 +288,15 @@ void QgsAttributeTableModel::loadLayer()
{
featureAdded( f.id() );
bool cancel = false;
emit progress( i, cancel );
if ( cancel )
break;
if ( t.elapsed() > 5000 )
{
bool cancel = false;
emit progress( i, cancel );
if ( cancel )
break;
t.restart();
}
}
emit finished();
}

14
src/gui/attributetable/qgsattributetableview.cpp Normal file → Executable file
View File

@ -74,22 +74,16 @@ void QgsAttributeTableView::setCanvasAndLayer( QgsMapCanvas *canvas, QgsVectorLa
mModel = new QgsAttributeTableMemoryModel( canvas, layer );
}
connect( mModel, SIGNAL( finished() ), this, SLOT( setFilterModel() ) );
connect( mModel, SIGNAL( progress(int, bool&) ), this, SIGNAL( progress(int, bool&) ) );
connect( mModel, SIGNAL( progress( int, bool& ) ), this, SIGNAL( progress( int, bool& ) ) );
connect( mModel, SIGNAL( finished() ), this, SIGNAL( finished() ) );
mModel->loadLayer();
delete oldModel;
delete filterModel;
}
void QgsAttributeTableView::setFilterModel()
{
disconnect( mModel, SIGNAL( finished() ), this, SLOT( setFilterModel() ) );
mFilterModel = new QgsAttributeTableFilterModel( mModel->layer() );
mFilterModel->setSourceModel( mModel );
setModel( mFilterModel );
delete oldModel;
delete filterModel;
}
QgsAttributeTableView::~QgsAttributeTableView()

View File

@ -50,9 +50,6 @@ class GUI_EXPORT QgsAttributeTableView : public QTableView
void contextMenuEvent( QContextMenuEvent* );
public slots:
void setFilterModel();
signals:
void willShowContextMenu( QMenu* menu, QModelIndex atIndex );