Skip to content
Permalink
Browse files

attribute table: show progress only every 5s

  • Loading branch information
jef-n committed Jan 17, 2012
1 parent 2e7867a commit 0c9e60fb6906e2a7c80f8c3dd5aa732f7d08fac6
@@ -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();
@@ -54,22 +54,32 @@ void QgsAttributeTableMemoryModel::loadLayer()
else
mFeatureMap.reserve( mLayer->selectedFeatureCount() );

int n = 0;
int i = 0;

QTime t;
t.start();

QgsFeature f;
while ( mLayer->nextFeature( f ) )
{
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();
@@ -247,17 +247,27 @@ 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 );
foreach( QgsFeatureId fid, mLayer->selectedFeaturesIds() )
{
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();
}
@@ -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()
@@ -50,9 +50,6 @@ class GUI_EXPORT QgsAttributeTableView : public QTableView

void contextMenuEvent( QContextMenuEvent* );

public slots:
void setFilterModel();

signals:
void willShowContextMenu( QMenu* menu, QModelIndex atIndex );

0 comments on commit 0c9e60f

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